From nobody Wed May 14 05:31:26 2025 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 1524671861975315.6412566092298; Wed, 25 Apr 2018 08:57:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7B30804E3; Wed, 25 Apr 2018 15:57:38 +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 0F4DC7A236; Wed, 25 Apr 2018 15:57:38 +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 A76284CAA0; Wed, 25 Apr 2018 15:57:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3PFqnfr026772 for ; Wed, 25 Apr 2018 11:52:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0356E202323C; Wed, 25 Apr 2018 15:52:49 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 684192023239; Wed, 25 Apr 2018 15:52:48 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 25 Apr 2018 16:52:42 +0100 Message-Id: <20180425155243.23406-6-berrange@redhat.com> In-Reply-To: <20180425155243.23406-1-berrange@redhat.com> References: <20180425155243.23406-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/6] util: refactor storage file checks to allow error reporting 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-Type: text/plain; charset="utf-8" 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 25 Apr 2018 15:57:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The virStorageFileSupportsSecurityDriver and virStorageFileSupportsAccess currently just return a boolean value. This is ok because they don't have any failure scenarios but a subsequent patch is going to introduce potential failure scenario. This changes their return type from a boolean to an int with values -1, 0, 1. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_domain.c | 21 +++++++++------ src/qemu/qemu_driver.c | 6 +++-- src/util/virstoragefile.c | 66 +++++++++++++++++++++++++++++++------------= ---- src/util/virstoragefile.h | 4 +-- 4 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 326c939c85..542e20c5e4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7514,19 +7514,24 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr drive= r, =20 /* skip to the end of the chain if there is any */ while (virStorageSourceHasBacking(src)) { - if (report_broken && - virStorageFileSupportsAccess(src)) { + if (report_broken) { + int rv =3D virStorageFileSupportsAccess(src); =20 - if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0) + if (rv < 0) goto cleanup; =20 - if (virStorageFileAccess(src, F_OK) < 0) { - virStorageFileReportBrokenChain(errno, src, disk->src); + if (rv > 0) { + if (qemuDomainStorageFileInit(driver, vm, src, disk->src) = < 0) + goto cleanup; + + if (virStorageFileAccess(src, F_OK) < 0) { + virStorageFileReportBrokenChain(errno, src, disk->src); + virStorageFileDeinit(src); + goto cleanup; + } + virStorageFileDeinit(src); - goto cleanup; } - - virStorageFileDeinit(src); } src =3D src->backingStore; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 672c5372eb..168a7c9ff3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -308,9 +308,11 @@ qemuSecurityChownCallback(const virStorageSource *src, struct stat sb; int save_errno =3D 0; int ret =3D -1; + int rv; =20 - if (!virStorageFileSupportsSecurityDriver(src)) - return 0; + rv =3D virStorageFileSupportsSecurityDriver(src); + if (rv <=3D 0) + return rv; =20 if (virStorageSourceIsLocalStorage(src)) { /* use direct chmod for local files so that the file doesn't diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index f09035cd4a..da13d51d32 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4098,34 +4098,46 @@ virStorageFileIsInitialized(const virStorageSource = *src) } =20 =20 -static virStorageFileBackendPtr -virStorageFileGetBackendForSupportCheck(const virStorageSource *src) +static int +virStorageFileGetBackendForSupportCheck(const virStorageSource *src, + virStorageFileBackendPtr *backend) { int actualType; =20 - if (!src) - return NULL; =20 - if (src->drv) - return src->drv->backend; + if (!src) { + *backend =3D NULL; + return 0; + } + + if (src->drv) { + *backend =3D src->drv->backend; + return 0; + } =20 actualType =3D virStorageSourceGetActualType(src); =20 - return virStorageFileBackendForTypeInternal(actualType, src->protocol,= false); + *backend =3D virStorageFileBackendForTypeInternal(actualType, src->pro= tocol, false); + return 0; } =20 =20 -static bool +static int virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) { virStorageFileBackendPtr backend; + int ret; =20 - if (!(backend =3D virStorageFileGetBackendForSupportCheck(src))) - return false; + ret =3D virStorageFileGetBackendForSupportCheck(src, &backend); + if (ret < 0) + return -1; + + if (!backend) + return 0; =20 return backend->storageFileGetUniqueIdentifier && - backend->storageFileRead && - backend->storageFileAccess; + backend->storageFileRead && + backend->storageFileAccess ? 1 : 0; } =20 =20 @@ -4137,15 +4149,19 @@ virStorageFileSupportsBackingChainTraversal(virStor= ageSourcePtr src) * Check if a storage file supports operations needed by the security * driver to perform labelling */ -bool +int virStorageFileSupportsSecurityDriver(const virStorageSource *src) { virStorageFileBackendPtr backend; + int ret; =20 - if (!(backend =3D virStorageFileGetBackendForSupportCheck(src))) - return false; + ret =3D virStorageFileGetBackendForSupportCheck(src, &backend); + if (ret < 0) + return -1; + if (backend =3D=3D NULL) + return 0; =20 - return !!backend->storageFileChown; + return backend->storageFileChown ? 1 : 0; } =20 =20 @@ -4157,15 +4173,19 @@ virStorageFileSupportsSecurityDriver(const virStora= geSource *src) * Check if a storage file supports checking if the storage source is acce= ssible * for the given vm. */ -bool +int virStorageFileSupportsAccess(const virStorageSource *src) { virStorageFileBackendPtr backend; + int ret; =20 - if (!(backend =3D virStorageFileGetBackendForSupportCheck(src))) - return false; + ret =3D virStorageFileGetBackendForSupportCheck(src, &backend); + if (ret < 0) + return -1; + if (backend =3D=3D NULL) + return 0; =20 - return !!backend->storageFileAccess; + return backend->storageFileAccess ? 1 : 0; } =20 =20 @@ -4514,14 +4534,16 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, ssize_t headerLen; virStorageSourcePtr backingStore =3D NULL; int backingFormat; + int rv; =20 VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u probe=3D%d", src->path, src->format, (unsigned int)uid, (unsigned int)gid, allow_probe); =20 /* exit if we can't load information about the current image */ - if (!virStorageFileSupportsBackingChainTraversal(src)) - return 0; + rv =3D virStorageFileSupportsBackingChainTraversal(src); + if (rv <=3D 0) + return rv; =20 if (virStorageFileInitAs(src, uid, gid) < 0) return -1; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b92c1c47dd..0909fe212c 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -465,8 +465,8 @@ const char *virStorageFileGetUniqueIdentifier(virStorag= eSourcePtr src); int virStorageFileAccess(virStorageSourcePtr src, int mode); int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid); =20 -bool virStorageFileSupportsSecurityDriver(const virStorageSource *src); -bool virStorageFileSupportsAccess(const virStorageSource *src); +int virStorageFileSupportsSecurityDriver(const virStorageSource *src); +int virStorageFileSupportsAccess(const virStorageSource *src); =20 int virStorageFileGetMetadata(virStorageSourcePtr src, uid_t uid, gid_t gid, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list