|
|
fbe740 |
From 32d58910c9d5a775315a42a76666844927c4dad1 Mon Sep 17 00:00:00 2001
|
|
|
fbe740 |
Message-Id: <32d58910c9d5a775315a42a76666844927c4dad1@dist-git>
|
|
|
fbe740 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
fbe740 |
Date: Wed, 19 Feb 2020 15:10:26 +0100
|
|
|
fbe740 |
Subject: [PATCH] virStorageSourceParseBackingJSONRaw: Parse 'offset' and
|
|
|
fbe740 |
'size' attributes
|
|
|
fbe740 |
MIME-Version: 1.0
|
|
|
fbe740 |
Content-Type: text/plain; charset=UTF-8
|
|
|
fbe740 |
Content-Transfer-Encoding: 8bit
|
|
|
fbe740 |
|
|
|
fbe740 |
If the parsed 'raw' format JSON string has 'offset' or 'size' attributes
|
|
|
fbe740 |
parse them as the format slice.
|
|
|
fbe740 |
|
|
|
fbe740 |
https://bugzilla.redhat.com/show_bug.cgi?id=1791788
|
|
|
fbe740 |
|
|
|
fbe740 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
fbe740 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
fbe740 |
(cherry picked from commit e8a819e87f806e6c6690614c40dbeab0bd2e800e)
|
|
|
fbe740 |
Message-Id: <88f7d393b22949a8d6afdae44f8215aa06e65329.1582120424.git.pkrempa@redhat.com>
|
|
|
fbe740 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
fbe740 |
---
|
|
|
fbe740 |
src/util/virstoragefile.c | 20 ++++++++++++++++++++
|
|
|
fbe740 |
tests/virstoragetest.c | 6 +++++-
|
|
|
fbe740 |
2 files changed, 25 insertions(+), 1 deletion(-)
|
|
|
fbe740 |
|
|
|
fbe740 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
fbe740 |
index 0be4168d6e..fcbc97d96a 100644
|
|
|
fbe740 |
--- a/src/util/virstoragefile.c
|
|
|
fbe740 |
+++ b/src/util/virstoragefile.c
|
|
|
fbe740 |
@@ -3551,8 +3551,28 @@ virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src,
|
|
|
fbe740 |
const char *jsonstr,
|
|
|
fbe740 |
int opaque G_GNUC_UNUSED)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
+ bool has_offset = virJSONValueObjectHasKey(json, "offset");
|
|
|
fbe740 |
+ bool has_size = virJSONValueObjectHasKey(json, "size");
|
|
|
fbe740 |
virJSONValuePtr file;
|
|
|
fbe740 |
|
|
|
fbe740 |
+ if (has_offset || has_size) {
|
|
|
fbe740 |
+ src->sliceStorage = g_new0(virStorageSourceSlice, 1);
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ if (has_offset &&
|
|
|
fbe740 |
+ virJSONValueObjectGetNumberUlong(json, "offset", &src->sliceStorage->offset) < 0) {
|
|
|
fbe740 |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
fbe740 |
+ _("malformed 'offset' property of 'raw' driver"));
|
|
|
fbe740 |
+ return -1;
|
|
|
fbe740 |
+ }
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ if (has_size &&
|
|
|
fbe740 |
+ virJSONValueObjectGetNumberUlong(json, "size", &src->sliceStorage->size) < 0) {
|
|
|
fbe740 |
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
fbe740 |
+ _("malformed 'size' property of 'raw' driver"));
|
|
|
fbe740 |
+ return -1;
|
|
|
fbe740 |
+ }
|
|
|
fbe740 |
+ }
|
|
|
fbe740 |
+
|
|
|
fbe740 |
/* 'raw' is a format driver so it can have protocol driver children */
|
|
|
fbe740 |
if (!(file = virJSONValueObjectGetObject(json, "file"))) {
|
|
|
fbe740 |
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
fbe740 |
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
|
|
|
fbe740 |
index 25d41f0de4..39040bf4cb 100644
|
|
|
fbe740 |
--- a/tests/virstoragetest.c
|
|
|
fbe740 |
+++ b/tests/virstoragetest.c
|
|
|
fbe740 |
@@ -1600,7 +1600,11 @@ mymain(void)
|
|
|
fbe740 |
"\"filename\": \"/tmp/testfle\""
|
|
|
fbe740 |
"}"
|
|
|
fbe740 |
"}",
|
|
|
fbe740 |
- "<source file='/tmp/testfle'/>\n", 0);
|
|
|
fbe740 |
+ "<source file='/tmp/testfle'>\n"
|
|
|
fbe740 |
+ " <slices>\n"
|
|
|
fbe740 |
+ " <slice type='storage' offset='10752' size='4063232'/>\n"
|
|
|
fbe740 |
+ " </slices>\n"
|
|
|
fbe740 |
+ "</source>\n", 0);
|
|
|
fbe740 |
|
|
|
fbe740 |
#endif /* WITH_YAJL */
|
|
|
fbe740 |
|
|
|
fbe740 |
--
|
|
|
fbe740 |
2.25.0
|
|
|
fbe740 |
|