[PATCH 10/14] storage: Implement backing store support for "fat:" prefix

Peter Krempa pkrempa at redhat.com
Mon Mar 23 18:12:00 UTC 2020


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 at redhat.com>
---
 src/qemu/qemu_block.c                                    | 7 ++++++-
 src/util/virstoragefile.c                                | 9 +++++++++
 .../xml2json/dir-fat-cache-srconly.json                  | 2 +-
 .../xml2json/dir-fat-floppy-srconly.json                 | 2 +-
 .../xml2json/dir-fat-readonly-srconly.json               | 2 +-
 tests/virstoragetest.c                                   | 1 +
 6 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index b7c3ba7530..a44cfeb99c 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -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 &&
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ca39391379..fa04ff74e1 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -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);
diff --git a/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json b/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
index 8bc58fa033..80f866f08b 100644
--- a/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
+++ b/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
@@ -6,5 +6,5 @@
     "floppy": false
   }
   backing store string:
-  /var/somefiles
+  fat:/var/somefiles
 )
diff --git a/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json b/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
index 043b796435..6c86f1da06 100644
--- a/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
+++ b/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
@@ -6,5 +6,5 @@
     "floppy": true
   }
   backing store string:
-  /var/somefiles
+  fat:/var/somefiles
 )
diff --git a/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json b/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
index 8bc58fa033..80f866f08b 100644
--- a/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
+++ b/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
@@ -6,5 +6,5 @@
     "floppy": false
   }
   backing store string:
-  /var/somefiles
+  fat:/var/somefiles
 )
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 547118951e..209d0c37d3 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -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"
-- 
2.24.1




More information about the libvir-list mailing list