From nobody Wed May 14 22:09:44 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1515528452862986.0216729200441; Tue, 9 Jan 2018 12:07:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E26C8762C; Tue, 9 Jan 2018 20:07:26 +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 6E13E7E47B; Tue, 9 Jan 2018 20:07:24 +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 9341A18033DC; Tue, 9 Jan 2018 20:07:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w09K63oA030561 for ; Tue, 9 Jan 2018 15:06:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id D906E60FB9; Tue, 9 Jan 2018 20:06:03 +0000 (UTC) Received: from unknown4ceb42c824f4.attlocal.net.com (ovpn-116-205.phx2.redhat.com [10.3.116.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9688A7F7F7 for ; Tue, 9 Jan 2018 20:06:03 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 9 Jan 2018 15:05:51 -0500 Message-Id: <20180109200553.22516-3-jferlan@redhat.com> In-Reply-To: <20180109200553.22516-1-jferlan@redhat.com> References: <20180109200553.22516-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] storage: Modify virStorageBackendDiskMakeDataVol logic 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: , MIME-Version: 1.0 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 09 Jan 2018 20:07:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter the logic such that we only add the volume to the pool once we've filled in all the information and cause failure to go to a common error: label. Patches to place the @vol into a few hash tables will soon "require" that at least the keys (name, target.path, and key) be populated with valid data. Signed-off-by: John Ferlan --- src/storage/storage_backend_disk.c | 40 ++++++++++++++++++++++++----------= ---- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_disk.c index 44c135d80..f862a896b 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -61,6 +61,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *tmp, *devpath, *partname; + bool addVol =3D false; =20 /* Prepended path will be same for all partitions, so we can * strip the path to form a reasonable pool-unique name @@ -74,18 +75,16 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr p= ool, /* This is typically a reload/restart/refresh path where * we're discovering the existing partitions for the pool */ + addVol =3D true; if (VIR_ALLOC(vol) < 0) return -1; - if (VIR_STRDUP(vol->name, partname) < 0 || - virStoragePoolObjAddVol(pool, vol) < 0) { - virStorageVolDefFree(vol); - return -1; - } + if (VIR_STRDUP(vol->name, partname) < 0) + goto error; } =20 if (vol->target.path =3D=3D NULL) { if (VIR_STRDUP(devpath, groups[0]) < 0) - return -1; + goto error; =20 /* Now figure out the stable path * @@ -96,7 +95,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, vol->target.path =3D virStorageBackendStablePath(pool, devpath, tr= ue); VIR_FREE(devpath); if (vol->target.path =3D=3D NULL) - return -1; + goto error; } =20 /* Enforce provided vol->name is the same as what parted created. @@ -129,37 +128,37 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr= pool, (tmp =3D strrchr(vol->target.path, 'p'))) memmove(tmp, tmp + 1, strlen(tmp)); } - return -1; + goto error; } =20 if (vol->key =3D=3D NULL) { /* XXX base off a unique key of the underlying disk */ if (VIR_STRDUP(vol->key, vol->target.path) < 0) - return -1; + goto error; } =20 if (vol->source.extents =3D=3D NULL) { if (VIR_ALLOC(vol->source.extents) < 0) - return -1; + goto error; vol->source.nextent =3D 1; =20 if (virStrToLong_ull(groups[3], NULL, 10, &vol->source.extents[0].start) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot parse device start location")); - return -1; + goto error; } =20 if (virStrToLong_ull(groups[4], NULL, 10, &vol->source.extents[0].end) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot parse device end location")); - return -1; + goto error; } =20 if (VIR_STRDUP(vol->source.extents[0].path, def->source.devices[0].path) < 0) - return -1; + goto error; } =20 /* set partition type */ @@ -190,16 +189,22 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr= pool, VIR_STORAGE_VOL_OPEN_DEFAULT | VIR_STORAGE_VOL_OPEN_NOERROR, 0) =3D=3D -1) - return -1; + goto error; vol->target.allocation =3D 0; vol->target.capacity =3D (vol->source.extents[0].end - vol->source.extents[0].start); } else { if (virStorageBackendUpdateVolInfo(vol, false, VIR_STORAGE_VOL_OPEN_DEFAULT, 0= ) < 0) - return -1; + goto error; } =20 + /* Now that we've updated @vol enough, let's add it to the pool + * if it's not already there so that the subsequent pool search + * pool def adjustments will work properly */ + if (addVol && virStoragePoolObjAddVol(pool, vol) < 0) + goto error; + /* Find the extended partition and increase the allocation value */ if (vol->source.partType =3D=3D VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { virStorageVolDefPtr voldef; @@ -217,6 +222,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr = pool, def->capacity =3D vol->source.extents[0].end; =20 return 0; + + error: + if (addVol) + virStorageVolDefFree(vol); + return -1; } =20 static int --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list