]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storagefile: Fill in meta->externalDataStore
authorCole Robinson <crobinso@redhat.com>
Sat, 5 Oct 2019 18:39:32 +0000 (14:39 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 11 Oct 2019 18:25:59 +0000 (14:25 -0400)
Add virStorageSourceNewFromExternalData, similar to
virStorageSourceNewFromBacking and use it to fill in a
virStorageSource for externalDataStore

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
src/util/virstoragefile.c

index 427510bd6a73188712e9b3e28ff4fdf68ae2c595..497ade927e53b5beb8d8260a0226573ec8e75713 100644 (file)
@@ -3800,6 +3800,24 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,
 }
 
 
+static int
+virStorageSourceNewFromExternalData(virStorageSourcePtr parent,
+                                    virStorageSourcePtr *externalDataStore)
+{
+    int rc;
+
+    if ((rc = virStorageSourceNewFromChild(parent,
+                                           parent->externalDataStoreRaw,
+                                           externalDataStore)) < 0)
+        return rc;
+
+    /* qcow2 data_file can only be raw */
+    (*externalDataStore)->format = VIR_STORAGE_FILE_RAW;
+    (*externalDataStore)->readonly = parent->readonly;
+    return rc;
+}
+
+
 /**
  * @src: disk source definition structure
  * @fd: file descriptor
@@ -5008,6 +5026,23 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
     }
 
     VIR_STEAL_PTR(src->backingStore, backingStore);
+
+    if (src->externalDataStoreRaw) {
+        VIR_AUTOUNREF(virStorageSourcePtr) externalDataStore = NULL;
+
+        if ((rv = virStorageSourceNewFromExternalData(src,
+                                                      &externalDataStore)) < 0)
+            goto cleanup;
+
+        if (rv == 1) {
+            /* the file would not be usable for VM usage */
+            ret = 0;
+            goto cleanup;
+        }
+
+        VIR_STEAL_PTR(src->externalDataStore, externalDataStore);
+    }
+
     ret = 0;
 
  cleanup: