render / rpms / libvirt

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