From nobody Thu May 2 09:58:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550843173336252.97280462715264; Fri, 22 Feb 2019 05:46:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E11BC062EC3; Fri, 22 Feb 2019 13:46:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7626C60BE7; Fri, 22 Feb 2019 13:46:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 30AE44EE06; Fri, 22 Feb 2019 13:46:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1JGqbca000488 for ; Tue, 19 Feb 2019 11:52:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id E0DF04C4; Tue, 19 Feb 2019 16:52:37 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 68EF7379F for ; Tue, 19 Feb 2019 16:52:37 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 17:52:28 +0100 Message-Id: <20190219165231.24610-2-abologna@redhat.com> In-Reply-To: <20190219165231.24610-1-abologna@redhat.com> References: <20190219165231.24610-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 1/4] util: Make it safe to call virFileWrapperFdClose() multiple times X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 22 Feb 2019 13:46:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We'll want to use this function in the cleanup path soon, and in order to be able to do that we need to make sure we can call it multiple times on the same virFileWrapperFd without side effects. Signed-off-by: Andrea Bolognani --- src/util/virfile.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 271bf5e796..42add5a2cd 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -175,6 +175,7 @@ virFileDirectFdFlag(void) /* Opaque type for managing a wrapper around a fd. For now, * read-write is not supported, just a single direction. */ struct _virFileWrapperFd { + bool closed; /* Whether virFileWrapperFdClose() has been already calle= d */ virCommandPtr cmd; /* Child iohelper process to do the I/O. */ char *err_msg; /* stderr of @cmd */ }; @@ -323,16 +324,21 @@ virFileWrapperFdNew(int *fd ATTRIBUTE_UNUSED, * callers can conditionally create a virFileWrapperFd wrapper but * unconditionally call the cleanup code. To avoid deadlock, only * call this after closing the fd resulting from virFileWrapperFdNew(). + * + * This function can be safely called multiple times on the same @wfd. */ int virFileWrapperFdClose(virFileWrapperFdPtr wfd) { int ret; =20 - if (!wfd) + if (!wfd || wfd->closed) return 0; =20 ret =3D virCommandWait(wfd->cmd, NULL); + + wfd->closed =3D true; + return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 09:58:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550595170919110.18841310390405; Tue, 19 Feb 2019 08:52:50 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56ABD19D32D; Tue, 19 Feb 2019 16:52:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACB0119C58; Tue, 19 Feb 2019 16:52:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9173F3FA45; Tue, 19 Feb 2019 16:52:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1JGqca5000502 for ; Tue, 19 Feb 2019 11:52:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id B2CC04C4; Tue, 19 Feb 2019 16:52:38 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A25653 for ; Tue, 19 Feb 2019 16:52:38 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 17:52:29 +0100 Message-Id: <20190219165231.24610-3-abologna@redhat.com> In-Reply-To: <20190219165231.24610-1-abologna@redhat.com> References: <20190219165231.24610-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 2/4] qemu: Always call virFileWrapperFdClose() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 19 Feb 2019 16:52:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Right now we're reporting errors in virFileWrapperFdFree(), but that's hardly the appropriate place to do so, as free functions are supposed to do nothing more than release allocated resources. We want to move that code back into virFileWrapperFdClose(), but before we can do that we need to make sure the function is actually called every time we're done processing the wrapped file. The cleanup path is the obvious candidate. For two of the users we can just move the call, but for the other two we need to duplicate it instead in order not to alter the existing behavior. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_driver.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5118f4ad42..30f69b339b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3231,6 +3231,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, =20 cleanup: VIR_FORCE_CLOSE(fd); + qemuFileWrapperFDClose(vm, wrapperFd); virFileWrapperFdFree(wrapperFd); virObjectUnref(cfg); =20 @@ -3834,9 +3835,10 @@ doCoreDump(virQEMUDriverPtr driver, =20 cleanup: VIR_FORCE_CLOSE(fd); + qemuFileWrapperFDClose(vm, wrapperFd); + virFileWrapperFdFree(wrapperFd); if (ret !=3D 0) unlink(path); - virFileWrapperFdFree(wrapperFd); VIR_FREE(compressedpath); virObjectUnref(cfg); return ret; @@ -7043,17 +7045,16 @@ qemuDomainRestoreFlags(virConnectPtr conn, =20 ret =3D qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path, false, QEMU_ASYNC_JOB_START); - if (virFileWrapperFdClose(wrapperFd) < 0) - VIR_WARN("Failed to close %s", path); =20 qemuProcessEndJob(driver, vm); =20 cleanup: virDomainDefFree(def); VIR_FORCE_CLOSE(fd); + virFileWrapperFdClose(wrapperFd); + virFileWrapperFdFree(wrapperFd); virQEMUSaveDataFree(data); VIR_FREE(xmlout); - virFileWrapperFdFree(wrapperFd); if (vm && ret < 0) qemuDomainRemoveInactiveJob(driver, vm); virDomainObjEndAPI(&vm); @@ -7318,14 +7319,13 @@ qemuDomainObjRestore(virConnectPtr conn, =20 ret =3D qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path, start_paused, asyncJob); - if (virFileWrapperFdClose(wrapperFd) < 0) - VIR_WARN("Failed to close %s", path); =20 cleanup: virQEMUSaveDataFree(data); VIR_FREE(xmlout); virDomainDefFree(def); VIR_FORCE_CLOSE(fd); + virFileWrapperFdClose(wrapperFd); virFileWrapperFdFree(wrapperFd); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 09:58:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550595169830207.3223864457699; Tue, 19 Feb 2019 08:52:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5498713CEE; Tue, 19 Feb 2019 16:52:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A7015BBCB; Tue, 19 Feb 2019 16:52:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1E7F4181A00B; Tue, 19 Feb 2019 16:52:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1JGqdiN000509 for ; Tue, 19 Feb 2019 11:52:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 855284C4; Tue, 19 Feb 2019 16:52:39 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B88153 for ; Tue, 19 Feb 2019 16:52:38 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 17:52:30 +0100 Message-Id: <20190219165231.24610-4-abologna@redhat.com> In-Reply-To: <20190219165231.24610-1-abologna@redhat.com> References: <20190219165231.24610-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 3/4] util: Move error reporting back to virFileWrapperFdClose() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Feb 2019 16:52:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" virFileWrapperFdFree(), like all free functions, is supposed to only release allocated resources, so error reporting is better suited for virFileWrapperFdClose(). This reverts most of commit b0c3e931804a. Signed-off-by: Andrea Bolognani --- src/util/virfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 42add5a2cd..8e045279f0 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -337,6 +337,9 @@ virFileWrapperFdClose(virFileWrapperFdPtr wfd) =20 ret =3D virCommandWait(wfd->cmd, NULL); =20 + if (wfd->err_msg && *wfd->err_msg) + VIR_WARN("iohelper reports: %s", wfd->err_msg); + wfd->closed =3D true; =20 return ret; @@ -357,9 +360,6 @@ virFileWrapperFdFree(virFileWrapperFdPtr wfd) if (!wfd) return; =20 - if (wfd->err_msg && *wfd->err_msg) - VIR_WARN("iohelper reports: %s", wfd->err_msg); - virCommandAbort(wfd->cmd); =20 VIR_FREE(wfd->err_msg); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 09:58:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550595185941304.840019020795; Tue, 19 Feb 2019 08:53:05 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C888BAD8B5; Tue, 19 Feb 2019 16:53:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96C5161080; Tue, 19 Feb 2019 16:53:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4B51D3FA4A; Tue, 19 Feb 2019 16:53:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1JGqetO000518 for ; Tue, 19 Feb 2019 11:52:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5662553; Tue, 19 Feb 2019 16:52:40 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D25E1379F for ; Tue, 19 Feb 2019 16:52:39 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 19 Feb 2019 17:52:31 +0100 Message-Id: <20190219165231.24610-5-abologna@redhat.com> In-Reply-To: <20190219165231.24610-1-abologna@redhat.com> References: <20190219165231.24610-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 4/4] util: Report error in virFileWrapperFdClose() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Feb 2019 16:53:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" libvirt_iohelper is used internally by the virFileWrapperFd APIs; more specifically, in the QEMU driver we have the doCoreDump() and qemuDomainSaveMemory() helper functions as users, and those in turn end up being called by the implementation of several driver APIs. By calling virReportError() if libvirt_iohelper has failed, we overwrite whatever generic error message QEMU might have raised with the more useful one generated by the helper program. After this commit, the user will be able to see the error directly instead of having to dig in the journal or libvirtd log. https://bugzilla.redhat.com/show_bug.cgi?id=3D1578741 Signed-off-by: Andrea Bolognani --- src/util/virfile.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 8e045279f0..1b61cbd127 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -337,8 +337,12 @@ virFileWrapperFdClose(virFileWrapperFdPtr wfd) =20 ret =3D virCommandWait(wfd->cmd, NULL); =20 + /* If the command used to process IO has produced errors, it's fair + * to assume those will be more relevant to the user than whatever + * eg. QEMU can figure out on its own, so it's okay if we end up + * discarding an existing error */ if (wfd->err_msg && *wfd->err_msg) - VIR_WARN("iohelper reports: %s", wfd->err_msg); + virReportError(VIR_ERR_OPERATION_FAILED, "%s", wfd->err_msg); =20 wfd->closed =3D true; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list