]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageSourceParseBackingJSONRaw: Parse 'offset' and 'size' attributes
authorPeter Krempa <pkrempa@redhat.com>
Wed, 5 Feb 2020 17:09:55 +0000 (18:09 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 14 Feb 2020 15:32:21 +0000 (16:32 +0100)
If the parsed 'raw' format JSON string has 'offset' or 'size' attributes
parse them as the format slice.

https://bugzilla.redhat.com/show_bug.cgi?id=1791788

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virstoragefile.c
tests/virstoragetest.c

index 890ec69929a56666ec6edc375b16ca3ed971c625..9347c7ab30bff52dac2bac2bfabaef25a40a85ed 100644 (file)
@@ -3551,8 +3551,28 @@ virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src,
                                     const char *jsonstr,
                                     int opaque G_GNUC_UNUSED)
 {
+    bool has_offset = virJSONValueObjectHasKey(json, "offset");
+    bool has_size = virJSONValueObjectHasKey(json, "size");
     virJSONValuePtr file;
 
+    if (has_offset || has_size) {
+        src->sliceStorage = g_new0(virStorageSourceSlice, 1);
+
+        if (has_offset &&
+            virJSONValueObjectGetNumberUlong(json, "offset", &src->sliceStorage->offset) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("malformed 'offset' property of 'raw' driver"));
+            return -1;
+        }
+
+        if (has_size &&
+            virJSONValueObjectGetNumberUlong(json, "size", &src->sliceStorage->size) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("malformed 'size' property of 'raw' driver"));
+            return -1;
+        }
+    }
+
     /* 'raw' is a format driver so it can have protocol driver children */
     if (!(file = virJSONValueObjectGetObject(json, "file"))) {
         virReportError(VIR_ERR_INVALID_ARG,
index 25d41f0de45509720d69ffc599e80295ae22592e..39040bf4cb1a6d61e52dd84bd52993f3ac99b128 100644 (file)
@@ -1600,7 +1600,11 @@ mymain(void)
                                                 "\"filename\": \"/tmp/testfle\""
                                               "}"
                                   "}",
-                            "<source file='/tmp/testfle'/>\n", 0);
+                            "<source file='/tmp/testfle'>\n"
+                            "  <slices>\n"
+                            "    <slice type='storage' offset='10752' size='4063232'/>\n"
+                            "  </slices>\n"
+                            "</source>\n", 0);
 
 #endif /* WITH_YAJL */