render / rpms / libvirt

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