From nobody Wed Nov 27 13:02:40 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 1550672751242951.2830507743299; Wed, 20 Feb 2019 06:25:51 -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 BFA6F539DE; Wed, 20 Feb 2019 14:25:47 +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 74F1860BF6; Wed, 20 Feb 2019 14:25:47 +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 35B55181A00A; Wed, 20 Feb 2019 14:25:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1KEPeBB017141 for ; Wed, 20 Feb 2019 09:25:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69C8F5D6AA; Wed, 20 Feb 2019 14:25:40 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCAFF5EE01 for ; Wed, 20 Feb 2019 14:25:39 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 20 Feb 2019 15:24:58 +0100 Message-Id: <20190220142500.9810-3-abologna@redhat.com> In-Reply-To: <20190220142500.9810-1-abologna@redhat.com> References: <20190220142500.9810-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 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.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.27]); Wed, 20 Feb 2019 14:25:49 +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. In a couple of cases we can just move the call, but for the remaining ones we need to duplicate it instead in order not to alter the existing behavior. We do, however, make sure that in all cases a failure to properly close the wrapper results in the overall operation being reported as failed. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_driver.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fe1b7801e9..323c7824be 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3231,6 +3231,8 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, =20 cleanup: VIR_FORCE_CLOSE(fd); + if (qemuFileWrapperFDClose(vm, wrapperFd) < 0) + ret =3D -1; virFileWrapperFdFree(wrapperFd); virObjectUnref(cfg); =20 @@ -3834,9 +3836,11 @@ doCoreDump(virQEMUDriverPtr driver, =20 cleanup: VIR_FORCE_CLOSE(fd); + if (qemuFileWrapperFDClose(vm, wrapperFd) < 0) + ret =3D -1; + virFileWrapperFdFree(wrapperFd); if (ret !=3D 0) unlink(path); - virFileWrapperFdFree(wrapperFd); VIR_FREE(compressedpath); virObjectUnref(cfg); return ret; @@ -7043,17 +7047,17 @@ 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); + if (virFileWrapperFdClose(wrapperFd) < 0) + ret =3D -1; + virFileWrapperFdFree(wrapperFd); virQEMUSaveDataFree(data); VIR_FREE(xmlout); - virFileWrapperFdFree(wrapperFd); if (vm && ret < 0) qemuDomainRemoveInactiveJob(driver, vm); virDomainObjEndAPI(&vm); @@ -7316,14 +7320,14 @@ 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); + if (virFileWrapperFdClose(wrapperFd) < 0) + ret =3D -1; virFileWrapperFdFree(wrapperFd); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list