libvirt/SOURCES/libvirt-storage-Implement-backing-store-support-for-fat-prefix.patch
2021-09-10 11:58:15 +00:00

124 lines
4.8 KiB
Diff

From 32163ac7b599b20c09458170e626784c0c9b4d9c Mon Sep 17 00:00:00 2001
Message-Id: <32163ac7b599b20c09458170e626784c0c9b4d9c@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 24 Mar 2020 16:26:04 +0100
Subject: [PATCH] storage: Implement backing store support for "fat:" prefix
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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>
(cherry picked from commit 5a70f1048fb60b72d5a715d93e963ba07e041e23)
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
Message-Id: <52a96160554678625eea409b7c816de12eeace1a.1585063415.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@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 20579ec7b3..5a7364576a 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -2032,8 +2032,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 2e54620139..5423f0b955 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 ca428f5ca7..a61522965b 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1225,6 +1225,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.26.0