[libvirt] [PATCH 16/18] storage: Move disk->backingChain to the recursive disk->src.backingStore

Peter Krempa pkrempa at redhat.com
Sun Apr 20 22:13:20 UTC 2014


Switch over to storing of the backing chain as a recursive
virStorageSource structure.

This is a string based move. Currently the first element will be present
twice in the backing chain as currently the retrieval function stores
the parent in the newly detected chain. This will be fixed later.
---
 src/conf/domain_conf.c          |  5 ++---
 src/conf/domain_conf.h          |  1 -
 src/qemu/qemu_domain.c          | 20 ++++++++++----------
 src/qemu/qemu_driver.c          | 30 +++++++++++++++---------------
 src/security/security_selinux.c |  2 +-
 src/security/virt-aa-helper.c   |  8 ++++----
 6 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d9c4485..69ca5e7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1190,7 +1190,6 @@ virDomainDiskDefFree(virDomainDiskDefPtr def)
     virStorageSourceClear(&def->src);
     VIR_FREE(def->serial);
     VIR_FREE(def->dst);
-    virStorageSourceFree(def->backingChain);
     VIR_FREE(def->mirror);
     VIR_FREE(def->wwn);
     VIR_FREE(def->vendor);
@@ -18541,7 +18540,7 @@ virDomainSmartcardDefForeach(virDomainDefPtr def,


 /* Call iter(disk, name, depth, opaque) for each element of disk and
- * its backing chain in the pre-populated disk->backingChain.
+ * its backing chain in the pre-populated disk->src.backingStore.
  * ignoreOpenFailure determines whether to warn about a chain that
  * mentions a backing file without also having metadata on that
  * file.  */
@@ -18567,7 +18566,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
         goto cleanup;
     /* XXX: temporarily we need to select the second element of the backing
      * chain to start as the first is the copy of the disk itself. */
-    tmp = disk->backingChain ? disk->backingChain->backingStore : NULL;
+    tmp = disk->src.backingStore ? disk->src.backingStore->backingStore : NULL;
     while (tmp && virStorageIsFile(tmp->path)) {
         if (!ignoreOpenFailure && tmp->backingStoreRaw && !tmp->backingStore) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 56bb8bd..93c5bb3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -605,7 +605,6 @@ struct _virDomainDiskDef {
     char *dst;
     int tray_status; /* enum virDomainDiskTray */
     int removable; /* enum virDomainFeatureState */
-    virStorageSourcePtr backingChain;

     char *mirror;
     int mirrorFormat; /* enum virStorageFileFormat */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b6f9e6a..45ed872 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2239,10 +2239,10 @@ qemuDiskChainCheckBroken(virDomainDiskDefPtr disk)
 {
     char *brokenFile = NULL;

-    if (!virDomainDiskGetSource(disk) || !disk->backingChain)
+    if (!virDomainDiskGetSource(disk) || !disk->src.backingStore)
         return 0;

-    if (virStorageFileChainGetBroken(disk->backingChain, &brokenFile) < 0)
+    if (virStorageFileChainGetBroken(disk->src.backingStore, &brokenFile) < 0)
         return -1;

     if (brokenFile) {
@@ -2408,10 +2408,10 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
         type == VIR_STORAGE_TYPE_VOLUME)
         goto cleanup;

-    if (disk->backingChain) {
+    if (disk->src.backingStore) {
         if (force) {
-            virStorageSourceFree(disk->backingChain);
-            disk->backingChain = NULL;
+            virStorageSourceFree(disk->src.backingStore);
+            disk->src.backingStore = NULL;
         } else {
             goto cleanup;
         }
@@ -2419,11 +2419,11 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,

     qemuDomainGetImageIds(cfg, vm, disk, &uid, &gid);

-    disk->backingChain = virStorageFileGetMetadata(src,
-                                                   virDomainDiskGetFormat(disk),
-                                                   uid, gid,
-                                                   cfg->allowDiskFormatProbing);
-    if (!disk->backingChain)
+    disk->src.backingStore = virStorageFileGetMetadata(src,
+                                                       virDomainDiskGetFormat(disk),
+                                                       uid, gid,
+                                                       cfg->allowDiskFormatProbing);
+    if (!disk->src.backingStore)
         ret = -1;

  cleanup:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 339b231..c0094c1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12022,14 +12022,14 @@ qemuDomainPrepareDiskChainElement(virQEMUDriverPtr driver,
      * temporarily modify the disk in place.  */
     char *origsrc = disk->src.path;
     int origformat = disk->src.format;
-    virStorageSourcePtr origchain = disk->backingChain;
+    virStorageSourcePtr origchain = disk->src.backingStore;
     bool origreadonly = disk->readonly;
     int ret = -1;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

     disk->src.path = (char *) file; /* casting away const is safe here */
     disk->src.format = VIR_STORAGE_FILE_RAW;
-    disk->backingChain = NULL;
+    disk->src.backingStore = NULL;
     disk->readonly = mode == VIR_DISK_CHAIN_READ_ONLY;

     if (mode == VIR_DISK_CHAIN_NO_ACCESS) {
@@ -12054,7 +12054,7 @@ qemuDomainPrepareDiskChainElement(virQEMUDriverPtr driver,
  cleanup:
     disk->src.path = origsrc;
     disk->src.format = origformat;
-    disk->backingChain = origchain;
+    disk->src.backingStore = origchain;
     disk->readonly = origreadonly;
     virObjectUnref(cfg);
     return ret;
@@ -12730,13 +12730,13 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0)
         goto cleanup;

-    /* XXX Here, we know we are about to alter disk->backingChain if
+    /* XXX Here, we know we are about to alter disk->src.backingStore if
      * successful, so we nuke the existing chain so that future commands will
      * recompute it.  Better would be storing the chain ourselves rather than
      * reprobing, but this requires modifying domain_conf and our XML to fully
      * track the chain across libvirtd restarts.  */
-    virStorageSourceFree(disk->backingChain);
-    disk->backingChain = NULL;
+    virStorageSourceFree(disk->src.backingStore);
+    disk->src.backingStore = NULL;

     if (virStorageFileInit(&snap->src) < 0)
         goto cleanup;
@@ -14774,14 +14774,14 @@ qemuDomainBlockPivot(virConnectPtr conn,
      * we know for sure that there is a backing chain.  */
     oldsrc = disk->src.path;
     oldformat = disk->src.format;
-    oldchain = disk->backingChain;
+    oldchain = disk->src.backingStore;
     disk->src.path = disk->mirror;
     disk->src.format = disk->mirrorFormat;
-    disk->backingChain = NULL;
+    disk->src.backingStore = NULL;
     if (qemuDomainDetermineDiskChain(driver, vm, disk, false) < 0) {
         disk->src.path = oldsrc;
         disk->src.format = oldformat;
-        disk->backingChain = oldchain;
+        disk->src.backingStore = oldchain;
         goto cleanup;
     }
     if (disk->mirrorFormat && disk->mirrorFormat != VIR_STORAGE_FILE_RAW &&
@@ -14792,7 +14792,7 @@ qemuDomainBlockPivot(virConnectPtr conn,
                                          disk) < 0)) {
         disk->src.path = oldsrc;
         disk->src.format = oldformat;
-        disk->backingChain = oldchain;
+        disk->src.backingStore = oldchain;
         goto cleanup;
     }

@@ -14823,8 +14823,8 @@ qemuDomainBlockPivot(virConnectPtr conn,
          * success case, there's security labeling to worry about.  */
         disk->src.path = oldsrc;
         disk->src.format = oldformat;
-        virStorageSourceFree(disk->backingChain);
-        disk->backingChain = oldchain;
+        virStorageSourceFree(disk->src.backingStore);
+        disk->src.backingStore = oldchain;
         VIR_FREE(disk->mirror);
     }
     disk->mirrorFormat = VIR_STORAGE_FILE_NONE;
@@ -15134,7 +15134,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm,

     if ((flags & VIR_DOMAIN_BLOCK_REBASE_SHALLOW) &&
         STREQ_NULLABLE(format, "raw") &&
-        disk->backingChain->backingStore->path) {
+        disk->src.backingStore->backingStore->path) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("disk '%s' has backing file, so raw shallow copy "
                          "is not possible"),
@@ -15341,8 +15341,8 @@ qemuDomainBlockCommit(virDomainPtr dom, const char *path, const char *base,

     if (!top) {
         top_canon = disk->src.path;
-        top_meta = disk->backingChain;
-    } else if (!(top_canon = virStorageFileChainLookup(disk->backingChain,
+        top_meta = disk->src.backingStore;
+    } else if (!(top_canon = virStorageFileChainLookup(disk->src.backingStore,
                                                        top, &top_meta,
                                                        &top_parent))) {
         goto endjob;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index bfac11c..19d76fd 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1148,7 +1148,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
      * be tracked in domain XML, at which point labelskip should be a
      * per-file attribute instead of a disk attribute.  */
     if (disk_seclabel && disk_seclabel->labelskip &&
-        !disk->backingChain)
+        !disk->src.backingStore)
         return 0;

     /* Don't restore labels on readoly/shared disks, because
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index da66583..1c89815 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -950,11 +950,11 @@ get_files(vahControl * ctl)
         /* XXX - if we knew the qemu user:group here we could send it in
          *        so that the open could be re-tried as that user:group.
          */
-        if (!disk->backingChain) {
+        if (!disk->src.backingStore) {
             bool probe = ctl->allowDiskFormatProbing;
-            disk->backingChain = virStorageFileGetMetadata(src,
-                                                           virDomainDiskGetFormat(disk),
-                                                           -1, -1, probe);
+            disk->src.backingStore = virStorageFileGetMetadata(src,
+                                                               virDomainDiskGetFormat(disk),
+                                                               -1, -1, probe);
         }

         /* XXX passing ignoreOpenFailure = true to get back to the behavior
-- 
1.9.1




More information about the libvir-list mailing list