]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage file: fill in src->dataFileStore during file probe
authorNikolai Barybin <nikolai.barybin@virtuozzo.com>
Wed, 20 Nov 2024 15:48:42 +0000 (18:48 +0300)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 25 Nov 2024 21:31:18 +0000 (22:31 +0100)
Signed-off-by: Nikolai Barybin <nikolai.barybin@virtuozzo.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/storage_file/storage_source.c

index 2cfe3bc3257afd089507bf3f9aa9a637c97a5582..4612e710b0d0b4c8b5ff30591714af464bca3f6d 100644 (file)
@@ -543,6 +543,39 @@ virStorageSourceNewFromBacking(virStorageSource *parent,
 }
 
 
+/**
+ * virStorageSourceNewFromDataFile:
+ * @parent: storage source parent
+ *
+ * Creates a storage source which describes the data file image of @parent.
+ * Returned storage source format is VIR_STORAGE_FILE_RAW, and, unlike
+ * backing storage creation, readonly flag is copied from @parent.
+ */
+static virStorageSource *
+virStorageSourceNewFromDataFile(virStorageSource *parent)
+{
+    g_autoptr(virStorageSource) dataFile = NULL;
+    int rc;
+
+    if ((rc = virStorageSourceNewFromChild(parent,
+                                           parent->dataFileRaw,
+                                           &dataFile)) < 0)
+        return NULL;
+
+    if (rc == 1) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("can't use data file definition '%1$s'"),
+                       parent->dataFileRaw);
+        return NULL;
+    }
+
+    dataFile->format = VIR_STORAGE_FILE_RAW;
+    dataFile->readonly = parent->readonly;
+
+    return g_steal_pointer(&dataFile);
+}
+
+
 /**
  * @src: disk source definition structure
  * @fd: file descriptor
@@ -1391,6 +1424,14 @@ virStorageSourceGetMetadataRecurse(virStorageSource *src,
         }
     }
 
+    /* The image we're detecting on can have a '<dataStore>' explicitly
+     * configured without a '<backingStore/>' terminator so we must not
+     * overwrite it */
+    if (!src->dataFileStore && src->dataFileRaw) {
+        if (!(src->dataFileStore = virStorageSourceNewFromDataFile(src)))
+            return -1;
+    }
+
     if (src->backingStoreRaw) {
         if ((rv = virStorageSourceNewFromBacking(src, &backingStore)) < 0)
             return -1;