From nobody Wed May 14 05:29:08 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 1524671590460631.1124530976401; Wed, 25 Apr 2018 08:53:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A66AB356DA; Wed, 25 Apr 2018 15:53:08 +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 D44665E697; Wed, 25 Apr 2018 15:53:07 +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 A73544CA9F; Wed, 25 Apr 2018 15:53:06 +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 w3PFqm5e026753 for ; Wed, 25 Apr 2018 11:52:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FDA1202323B; Wed, 25 Apr 2018 15:52:48 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9498D2023239; Wed, 25 Apr 2018 15:52:47 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 25 Apr 2018 16:52:41 +0100 Message-Id: <20180425155243.23406-5-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 4/6] storage: fix virStorageFileGetBackingStoreStr error handling 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 25 Apr 2018 15:53:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The virStorageFileGetBackingStoreStr method has overloaded the NULL return value to indicate both no backing available and a fatal error dealing with it. The caller is thus not able to correctly propagate the error messages. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_driver.c | 15 +++++++++------ src/util/virstoragefile.c | 49 +++++++++++++++++++++++++++++++------------= ---- src/util/virstoragefile.h | 5 +++-- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7484b00e23..672c5372eb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14608,12 +14608,15 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPt= r driver, =20 /* relative backing store paths need to be updated so that relative * block commit still works */ - if (reuse && - (backingStoreStr =3D virStorageFileGetBackingStoreStr(dd->src)= )) { - if (virStorageIsRelative(backingStoreStr)) - VIR_STEAL_PTR(dd->relPath, backingStoreStr); - else - VIR_FREE(backingStoreStr); + if (reuse) { + if (virStorageFileGetBackingStoreStr(dd->src, &backingStoreStr= ) < 0) + goto error; + if (backingStoreStr !=3D NULL) { + if (virStorageIsRelative(backingStoreStr)) + VIR_STEAL_PTR(dd->relPath, backingStoreStr); + else + VIR_FREE(backingStoreStr); + } } =20 /* Note that it's unsafe to assume that the disks in the persistent diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 531540ac91..f09035cd4a 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4357,14 +4357,8 @@ virStorageFileRead(virStorageSourcePtr src, return -1; } =20 - if (!src->drv->backend->storageFileRead) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("storage file reading is not supported for " - "storage type %s (protocol: %s)"), - virStorageTypeToString(src->type), - virStorageNetProtocolTypeToString(src->protocol)); + if (!src->drv->backend->storageFileRead) return -2; - } =20 ret =3D src->drv->backend->storageFileRead(src, offset, len, buf); =20 @@ -4551,8 +4545,15 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr= src, goto cleanup; =20 if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, - &buf)) < 0) + &buf)) < 0) { + if (headerLen =3D=3D -2) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("storage file reading is not supported for " + "storage type %s (protocol: %s)"), + virStorageTypeToString(src->type), + virStorageNetProtocolTypeToString(src->protocol= )); goto cleanup; + } =20 if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFormat) < 0) @@ -4664,24 +4665,36 @@ virStorageFileGetMetadata(virStorageSourcePtr src, * In case when the string can't be retrieved or does not exist NULL is * returned. */ -char * -virStorageFileGetBackingStoreStr(virStorageSourcePtr src) +int +virStorageFileGetBackingStoreStr(virStorageSourcePtr src, + char **backing) { virStorageSourcePtr tmp =3D NULL; char *buf =3D NULL; ssize_t headerLen; - char *ret =3D NULL; + int ret =3D -1; + int rv; + + *backing =3D NULL; =20 /* exit if we can't load information about the current image */ if (!virStorageFileSupportsBackingChainTraversal(src)) - return NULL; + return 0; =20 - if (virStorageFileAccess(src, F_OK) < 0) - return NULL; + rv =3D virStorageFileAccess(src, F_OK); + if (rv =3D=3D -2) + return 0; + if (rv < 0) { + virStorageFileReportBrokenChain(errno, src, src); + return -1; + } =20 if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, - &buf)) < 0) - return NULL; + &buf)) < 0) { + if (headerLen =3D=3D -2) + return 0; + return -1; + } =20 if (!(tmp =3D virStorageSourceCopy(src, false))) goto cleanup; @@ -4689,7 +4702,9 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr = src) if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0) goto cleanup; =20 - VIR_STEAL_PTR(ret, tmp->backingStoreRaw); + VIR_STEAL_PTR(*backing, tmp->backingStoreRaw); + + ret =3D 0; =20 cleanup: VIR_FREE(buf); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index d129e81978..b92c1c47dd 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -474,8 +474,9 @@ int virStorageFileGetMetadata(virStorageSourcePtr src, bool report_broken) ATTRIBUTE_NONNULL(1); =20 -char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src) - ATTRIBUTE_NONNULL(1); +int virStorageFileGetBackingStoreStr(virStorageSourcePtr src, + char **backing) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 void virStorageFileReportBrokenChain(int errcode, virStorageSourcePtr src, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list