fbe740
From 32163ac7b599b20c09458170e626784c0c9b4d9c Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <32163ac7b599b20c09458170e626784c0c9b4d9c@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 24 Mar 2020 16:26:04 +0100
fbe740
Subject: [PATCH] storage: Implement backing store support for "fat:" prefix
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
qemublocktest showed that we don't add the "fat:" prefix for directory
fbe740
storage when formatting the backing store string. While it's unlikely to
fbe740
be used it's simple enough to actually implement the support rather than
fbe740
trying to forbid it.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
(cherry picked from commit 5a70f1048fb60b72d5a715d93e963ba07e041e23)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
fbe740
Message-Id: <52a96160554678625eea409b7c816de12eeace1a.1585063415.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_block.c                                    | 7 ++++++-
fbe740
 src/util/virstoragefile.c                                | 9 +++++++++
fbe740
 .../xml2json/dir-fat-cache-srconly.json                  | 2 +-
fbe740
 .../xml2json/dir-fat-floppy-srconly.json                 | 2 +-
fbe740
 .../xml2json/dir-fat-readonly-srconly.json               | 2 +-
fbe740
 tests/virstoragetest.c                                   | 1 +
fbe740
 6 files changed, 19 insertions(+), 4 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
fbe740
index 20579ec7b3..5a7364576a 100644
fbe740
--- a/src/qemu/qemu_block.c
fbe740
+++ b/src/qemu/qemu_block.c
fbe740
@@ -2032,8 +2032,13 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src,
fbe740
     g_autofree char *backingJSON = NULL;
fbe740
 
fbe740
     if (!src->sliceStorage) {
fbe740
-        if (virStorageSourceIsLocalStorage(src))
fbe740
+        if (virStorageSourceIsLocalStorage(src)) {
fbe740
+            if (src->type == VIR_STORAGE_TYPE_DIR &&
fbe740
+                src->format == VIR_STORAGE_FILE_FAT)
fbe740
+                return g_strdup_printf("fat:%s", src->path);
fbe740
+
fbe740
             return g_strdup(src->path);
fbe740
+        }
fbe740
 
fbe740
         /* generate simplified URIs for the easy cases */
fbe740
         if (actualType == VIR_STORAGE_TYPE_NETWORK &&
fbe740
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
fbe740
index 2e54620139..5423f0b955 100644
fbe740
--- a/src/util/virstoragefile.c
fbe740
+++ b/src/util/virstoragefile.c
fbe740
@@ -3922,6 +3922,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
fbe740
                                        virStorageSourcePtr *src)
fbe740
 {
fbe740
     const char *json;
fbe740
+    const char *dirpath;
fbe740
     int rc = 0;
fbe740
     g_autoptr(virStorageSource) def = NULL;
fbe740
 
fbe740
@@ -3935,6 +3936,14 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
fbe740
 
fbe740
         def->path = g_strdup(path);
fbe740
     } else {
fbe740
+        if ((dirpath = STRSKIP(path, "fat:"))) {
fbe740
+            def->type = VIR_STORAGE_TYPE_DIR;
fbe740
+            def->format = VIR_STORAGE_FILE_FAT;
fbe740
+            def->path = g_strdup(dirpath);
fbe740
+            *src = g_steal_pointer(&def;;
fbe740
+            return 0;
fbe740
+        }
fbe740
+
fbe740
         def->type = VIR_STORAGE_TYPE_NETWORK;
fbe740
 
fbe740
         VIR_DEBUG("parsing backing store string: '%s'", path);
fbe740
diff --git a/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json b/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
fbe740
index 8bc58fa033..80f866f08b 100644
fbe740
--- a/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
fbe740
+++ b/tests/qemublocktestdata/xml2json/dir-fat-cache-srconly.json
fbe740
@@ -6,5 +6,5 @@
fbe740
     "floppy": false
fbe740
   }
fbe740
   backing store string:
fbe740
-  /var/somefiles
fbe740
+  fat:/var/somefiles
fbe740
 )
fbe740
diff --git a/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json b/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
fbe740
index 043b796435..6c86f1da06 100644
fbe740
--- a/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
fbe740
+++ b/tests/qemublocktestdata/xml2json/dir-fat-floppy-srconly.json
fbe740
@@ -6,5 +6,5 @@
fbe740
     "floppy": true
fbe740
   }
fbe740
   backing store string:
fbe740
-  /var/somefiles
fbe740
+  fat:/var/somefiles
fbe740
 )
fbe740
diff --git a/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json b/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
fbe740
index 8bc58fa033..80f866f08b 100644
fbe740
--- a/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
fbe740
+++ b/tests/qemublocktestdata/xml2json/dir-fat-readonly-srconly.json
fbe740
@@ -6,5 +6,5 @@
fbe740
     "floppy": false
fbe740
   }
fbe740
   backing store string:
fbe740
-  /var/somefiles
fbe740
+  fat:/var/somefiles
fbe740
 )
fbe740
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
fbe740
index ca428f5ca7..a61522965b 100644
fbe740
--- a/tests/virstoragetest.c
fbe740
+++ b/tests/virstoragetest.c
fbe740
@@ -1225,6 +1225,7 @@ mymain(void)
fbe740
     TEST_BACKING_PARSE_FULL(bck, xml, 0)
fbe740
 
fbe740
     TEST_BACKING_PARSE("path", "<source file='path'/>\n");
fbe740
+    TEST_BACKING_PARSE("fat:/somedir", "<source dir='/somedir'/>\n");
fbe740
     TEST_BACKING_PARSE("://", NULL);
fbe740
     TEST_BACKING_PARSE("http://example.com",
fbe740
                        "<source protocol='http' name=''>\n"
fbe740
-- 
fbe740
2.26.0
fbe740