Blame SOURCES/libvirt-virStorageSourceParseBackingJSONRaw-Parse-offset-and-size-attributes.patch

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