From nobody Thu May 15 14:01:53 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 1507836323072976.6830942575549; Thu, 12 Oct 2017 12:25:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEA12C04D2EF; Thu, 12 Oct 2017 19:25:21 +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 AD2C15D6AE; Thu, 12 Oct 2017 19:25:19 +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 63A874ED30; Thu, 12 Oct 2017 19:25:18 +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 v9CJ8E2h001666 for ; Thu, 12 Oct 2017 15:08:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6AF6C5D6A6; Thu, 12 Oct 2017 19:08:14 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77EF26293F; Thu, 12 Oct 2017 19:08:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AEA12C04D2EF Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 12 Oct 2017 21:07:34 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/9] util: storage: Store backing chain index in virStorageSource 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 12 Oct 2017 19:25:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The backing store indexes were not bound to the storage sources in any way. To allow us to bind a given alias to a given storage source we need to save the index in virStorageSource. The backing store ids are now generated when detecting the backing chain. Since we don't re-detect the backing chain after snapshots, the numbering needs to be fixed there. Reviewed-by: Eric Blake --- src/conf/domain_conf.c | 22 +++++++++++++++------- src/qemu/qemu_driver.c | 14 ++++++++++++++ src/storage/storage_source.c | 9 ++++++--- src/util/virstoragefile.c | 1 + src/util/virstoragefile.h | 1 + 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f7c9160b4..45fa57a14 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8269,6 +8269,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, xmlNodePtr source; char *type =3D NULL; char *format =3D NULL; + char *idx =3D NULL; int ret =3D -1; if (!(ctxt->node =3D virXPathNode("./backingStore[*]", ctxt))) { @@ -8279,6 +8280,13 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ct= xt, if (VIR_ALLOC(backingStore) < 0) goto cleanup; + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && + (idx =3D virXMLPropString(ctxt->node, "index")) && + virStrToLong_uip(idx, NULL, 10, &backingStore->id) < 0) { + virReportError(VIR_ERR_XML_ERROR, _("invalid disk index '%s'"), id= x); + goto cleanup; + } + if (!(type =3D virXMLPropString(ctxt->node, "type"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing disk backing store type")); @@ -21898,8 +21906,7 @@ virDomainDiskSourceFormat(virBufferPtr buf, static int virDomainDiskBackingStoreFormat(virBufferPtr buf, virStorageSourcePtr backingStore, - const char *backingStoreRaw, - unsigned int idx) + const char *backingStoreRaw) { const char *type; const char *format; @@ -21926,8 +21933,10 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, "\n", - type, idx); + virBufferAsprintf(buf, "id !=3D 0) + virBufferAsprintf(buf, " index=3D'%u'", backingStore->id); + virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "\n", format); @@ -21935,8 +21944,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) <= 0 || virDomainDiskBackingStoreFormat(buf, backingStore->backingStore, - backingStore->backingStoreRaw, - idx + 1) < 0) + backingStore->backingStoreRaw) < 0) return -1; virBufferAdjustIndent(buf, -2); @@ -22072,7 +22080,7 @@ virDomainDiskDefFormat(virBufferPtr buf, * persistent storage of backing chains is ready. */ if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) && virDomainDiskBackingStoreFormat(buf, def->src->backingStore, - def->src->backingStoreRaw, 1) < 0) + def->src->backingStoreRaw) < 0) return -1; virBufferEscapeString(buf, "\n", def->doma= in_name); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7c6f1674a..0260c40ef 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14442,6 +14442,17 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr= driver, } +static void +qemuDomainSnapshotUpdateDiskSourcesRenumber(virStorageSourcePtr src) +{ + virStorageSourcePtr next; + unsigned int idx =3D 1; + + for (next =3D src->backingStore; next; next =3D next->backingStore) + next->id =3D idx++; +} + + /** * qemuDomainSnapshotUpdateDiskSources: * @dd: snapshot disk data object @@ -14464,6 +14475,9 @@ qemuDomainSnapshotUpdateDiskSources(qemuDomainSnaps= hotDiskDataPtr dd, VIR_STEAL_PTR(dd->src->backingStore, dd->disk->src); VIR_STEAL_PTR(dd->disk->src, dd->src); + /* fix numbering of disks */ + qemuDomainSnapshotUpdateDiskSourcesRenumber(dd->disk->src); + if (dd->persistdisk) { VIR_STEAL_PTR(dd->persistsrc->backingStore, dd->persistdisk->src); VIR_STEAL_PTR(dd->persistdisk->src, dd->persistsrc); diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index bf4762237..864c69928 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -396,7 +396,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr sr= c, uid_t uid, gid_t gid, bool allow_probe, bool report_broken, - virHashTablePtr cycle) + virHashTablePtr cycle, + unsigned int depth) { int ret =3D -1; const char *uniqueName; @@ -474,7 +475,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr sr= c, if ((ret =3D virStorageFileGetMetadataRecurse(backingStore, parent, uid, gid, allow_probe, report_broken, - cycle)) < 0) { + cycle, depth + 1)) < 0) { if (report_broken) goto cleanup; @@ -489,6 +490,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr sr= c, ret =3D 0; cleanup: + if (src->backingStore) + src->backingStore->id =3D depth; VIR_FREE(buf); virStorageFileDeinit(src); virStorageSourceFree(backingStore); @@ -543,7 +546,7 @@ virStorageFileGetMetadata(virStorageSourcePtr src, } ret =3D virStorageFileGetMetadataRecurse(src, src, uid, gid, - allow_probe, report_broken, cyc= le); + allow_probe, report_broken, cyc= le, 1); virHashFree(cycle); return ret; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index dd4494940..2b9f4c892 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2030,6 +2030,7 @@ virStorageSourceCopy(const virStorageSource *src, if (VIR_ALLOC(ret) < 0) return NULL; + ret->id =3D src->id; ret->type =3D src->type; ret->protocol =3D src->protocol; ret->format =3D src->format; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 74dee10f2..d3bafefc3 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -227,6 +227,7 @@ typedef virStorageSource *virStorageSourcePtr; * IMPORTANT: When adding fields to this struct it's also necessary to add * appropriate code to the virStorageSourceCopy deep copy function */ struct _virStorageSource { + unsigned int id; /* backing chain identifier, 0 is unset */ int type; /* virStorageType */ char *path; int protocol; /* virStorageNetProtocol */ --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list