Re: [PATCH 15/15] virStorageSourceParseBackingJSONRaw: Parse 'offset' and 'size' attributes

2020-02-06 Thread Ján Tomko

On Thu, Feb 06, 2020 at 08:52:07AM +0100, Peter Krempa wrote:

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 
---
src/util/virstoragefile.c | 20 
tests/virstoragetest.c|  6 +-
2 files changed, 25 insertions(+), 1 deletion(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


[PATCH 15/15] virStorageSourceParseBackingJSONRaw: Parse 'offset' and 'size' attributes

2020-02-05 Thread Peter Krempa
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 
---
 src/util/virstoragefile.c | 20 
 tests/virstoragetest.c|  6 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 30d5a2fe67..802f3d59be 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3540,8 +3540,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->sliceFormat = g_new0(virStorageSourceSlice, 1);
+
+if (has_offset &&
+virJSONValueObjectGetNumberUlong(json, "offset", 
>sliceFormat->offset) < 0) {
+virReportError(VIR_ERR_INVALID_ARG, "%s",
+   _("malformed 'offset' property of 'raw' driver"));
+return -1;
+}
+
+if (has_size &&
+virJSONValueObjectGetNumberUlong(json, "size", 
>sliceFormat->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,
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 25d41f0de4..8dda349b5c 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1600,7 +1600,11 @@ mymain(void)
 "\"filename\": 
\"/tmp/testfle\""
   "}"
   "}",
-"\n", 0);
+"\n"
+"  \n"
+"\n"
+"  \n"
+"\n", 0);

 #endif /* WITH_YAJL */

-- 
2.24.1