mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
virStorageSourceParseBackingJSONRaw: Parse 'offset' and 'size' attributes
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>
This commit is contained in:
parent
293e7750c9
commit
e8a819e87f
@ -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,
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user