]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Implement backing store support for "fat:" prefix
authorPeter Krempa <pkrempa@redhat.com>
Mon, 23 Mar 2020 15:04:19 +0000 (16:04 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 24 Mar 2020 13:17:47 +0000 (14:17 +0100)
qemublocktest showed that we don't add the "fat:" prefix for directory
storage when formatting the backing store string. While it's unlikely to
be used it's simple enough to actually implement the support rather than
trying to forbid it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_block.c
src/util/virstoragefile.c
tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
tests/virstoragetest.c

index b7c3ba753096345c12740e31435a157887693393..a44cfeb99c1af27d61a1b1184e4e8da336db5491 100644 (file)
@@ -2045,8 +2045,13 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src,
     g_autofree char *backingJSON = NULL;
 
     if (!src->sliceStorage) {
-        if (virStorageSourceIsLocalStorage(src))
+        if (virStorageSourceIsLocalStorage(src)) {
+            if (src->type == VIR_STORAGE_TYPE_DIR &&
+                src->format == VIR_STORAGE_FILE_FAT)
+                return g_strdup_printf("fat:%s", src->path);
+
             return g_strdup(src->path);
+        }
 
         /* generate simplified URIs for the easy cases */
         if (actualType == VIR_STORAGE_TYPE_NETWORK &&
index ca39391379138e78d59d210349868c4af2406b8d..fa04ff74e16c874c554e547e21d8737ba6eba417 100644 (file)
@@ -3922,6 +3922,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
                                        virStorageSourcePtr *src)
 {
     const char *json;
+    const char *dirpath;
     int rc = 0;
     g_autoptr(virStorageSource) def = NULL;
 
@@ -3935,6 +3936,14 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
 
         def->path = g_strdup(path);
     } else {
+        if ((dirpath = STRSKIP(path, "fat:"))) {
+            def->type = VIR_STORAGE_TYPE_DIR;
+            def->format = VIR_STORAGE_FILE_FAT;
+            def->path = g_strdup(dirpath);
+            *src = g_steal_pointer(&def);
+            return 0;
+        }
+
         def->type = VIR_STORAGE_TYPE_NETWORK;
 
         VIR_DEBUG("parsing backing store string: '%s'", path);
index 8bc58fa0330d4a97063b46cd00fdafbadeadd64b..80f866f08b821ead0fa54a6b39bab3291d1c82f1 100644 (file)
@@ -6,5 +6,5 @@
     "floppy": false
   }
   backing store string:
-  /var/somefiles
+  fat:/var/somefiles
 )
index 043b7964359c4b6291f52794f8b8c7e097b954ba..6c86f1da060fd99a68131a897dfe7cd291d9b6a8 100644 (file)
@@ -6,5 +6,5 @@
     "floppy": true
   }
   backing store string:
-  /var/somefiles
+  fat:/var/somefiles
 )
index 8bc58fa0330d4a97063b46cd00fdafbadeadd64b..80f866f08b821ead0fa54a6b39bab3291d1c82f1 100644 (file)
@@ -6,5 +6,5 @@
     "floppy": false
   }
   backing store string:
-  /var/somefiles
+  fat:/var/somefiles
 )
index 547118951e8c3104c23555ea752dc5adb00299dd..209d0c37d316c868e90abbbe48b0a10629fba8cf 100644 (file)
@@ -1226,6 +1226,7 @@ mymain(void)
     TEST_BACKING_PARSE_FULL(bck, xml, 0)
 
     TEST_BACKING_PARSE("path", "<source file='path'/>\n");
+    TEST_BACKING_PARSE("fat:/somedir", "<source dir='/somedir'/>\n");
     TEST_BACKING_PARSE("://", NULL);
     TEST_BACKING_PARSE("http://example.com",
                        "<source protocol='http' name=''>\n"