render / rpms / libvirt

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