forked from rpms/libvirt
144 lines
4.4 KiB
Diff
144 lines
4.4 KiB
Diff
From 6d5174acd7530d554ac2651f3e6a5da9f69fe6e4 Mon Sep 17 00:00:00 2001
|
|
Message-Id: <6d5174acd7530d554ac2651f3e6a5da9f69fe6e4@dist-git>
|
|
From: Peter Krempa <pkrempa@redhat.com>
|
|
Date: Wed, 19 Feb 2020 15:10:20 +0100
|
|
Subject: [PATCH] conf: Implement support for <slices> of disk source
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Implement parsing and formatting of the 'storage' slice.
|
|
|
|
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
(cherry picked from commit bbf5d05cfd003e33600009cac7ea98ef1539dd7c)
|
|
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=1791788
|
|
Message-Id: <d31bb27ae30140c9deb696972ee76a90d7bcc610.1582120424.git.pkrempa@redhat.com>
|
|
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
---
|
|
src/conf/domain_conf.c | 86 ++++++++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 86 insertions(+)
|
|
|
|
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
|
|
index b46b92aecf..5c11f49463 100644
|
|
--- a/src/conf/domain_conf.c
|
|
+++ b/src/conf/domain_conf.c
|
|
@@ -9441,6 +9441,57 @@ virDomainStorageSourceParseBase(const char *type,
|
|
}
|
|
|
|
|
|
+static virStorageSourceSlicePtr
|
|
+virDomainStorageSourceParseSlice(xmlNodePtr node,
|
|
+ xmlXPathContextPtr ctxt)
|
|
+{
|
|
+ VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
|
+ g_autofree char *offset = NULL;
|
|
+ g_autofree char *size = NULL;
|
|
+ g_autofree virStorageSourceSlicePtr ret = g_new0(virStorageSourceSlice, 1);
|
|
+
|
|
+ ctxt->node = node;
|
|
+
|
|
+ if (!(offset = virXPathString("string(./@offset)", ctxt)) ||
|
|
+ !(size = virXPathString("string(./@size)", ctxt))) {
|
|
+ virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
+ _("missing offset or size attribute of slice"));
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ if (virStrToLong_ullp(offset, NULL, 10, &ret->offset) < 0) {
|
|
+ virReportError(VIR_ERR_XML_ERROR,
|
|
+ _("malformed value '%s' of 'offset' attribute of slice"),
|
|
+ offset);
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ if (virStrToLong_ullp(size, NULL, 10, &ret->size) < 0) {
|
|
+ virReportError(VIR_ERR_XML_ERROR,
|
|
+ _("malformed value '%s' of 'size' attribute of slice"),
|
|
+ size);
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ return g_steal_pointer(&ret);
|
|
+}
|
|
+
|
|
+
|
|
+static int
|
|
+virDomainStorageSourceParseSlices(virStorageSourcePtr src,
|
|
+ xmlXPathContextPtr ctxt)
|
|
+{
|
|
+ xmlNodePtr node;
|
|
+
|
|
+ if ((node = virXPathNode("./slices/slice[@type='storage']", ctxt))) {
|
|
+ if (!(src->sliceStorage = virDomainStorageSourceParseSlice(node, ctxt)))
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
/**
|
|
* virDomainStorageSourceParse:
|
|
* @node: XML node pointing to the source element to parse
|
|
@@ -9506,6 +9557,9 @@ virDomainStorageSourceParse(xmlNodePtr node,
|
|
if (virDomainDiskSourcePRParse(node, ctxt, &src->pr) < 0)
|
|
return -1;
|
|
|
|
+ if (virDomainStorageSourceParseSlices(src, ctxt) < 0)
|
|
+ return -1;
|
|
+
|
|
if (virSecurityDeviceLabelDefParseXML(&src->seclabels, &src->nseclabels,
|
|
ctxt, flags) < 0)
|
|
return -1;
|
|
@@ -24226,6 +24280,36 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
|
|
}
|
|
|
|
|
|
+static void
|
|
+virDomainDiskSourceFormatSlice(virBufferPtr buf,
|
|
+ const char *slicetype,
|
|
+ virStorageSourceSlicePtr slice)
|
|
+{
|
|
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
|
+
|
|
+ if (!slice)
|
|
+ return;
|
|
+
|
|
+ virBufferAsprintf(&attrBuf, " type='%s'", slicetype);
|
|
+ virBufferAsprintf(&attrBuf, " offset='%llu'", slice->offset);
|
|
+ virBufferAsprintf(&attrBuf, " size='%llu'", slice->size);
|
|
+
|
|
+ virXMLFormatElement(buf, "slice", &attrBuf, NULL);
|
|
+}
|
|
+
|
|
+
|
|
+static void
|
|
+virDomainDiskSourceFormatSlices(virBufferPtr buf,
|
|
+ virStorageSourcePtr src)
|
|
+{
|
|
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
|
+
|
|
+ virDomainDiskSourceFormatSlice(&childBuf, "storage", src->sliceStorage);
|
|
+
|
|
+ virXMLFormatElement(buf, "slices", NULL, &childBuf);
|
|
+}
|
|
+
|
|
+
|
|
/**
|
|
* virDomainDiskSourceFormat:
|
|
* @buf: output buffer
|
|
@@ -24296,6 +24380,8 @@ virDomainDiskSourceFormat(virBufferPtr buf,
|
|
return -1;
|
|
}
|
|
|
|
+ virDomainDiskSourceFormatSlices(&childBuf, src);
|
|
+
|
|
if (src->type != VIR_STORAGE_TYPE_NETWORK)
|
|
virDomainSourceDefFormatSeclabel(&childBuf, src->nseclabels,
|
|
src->seclabels, flags);
|
|
--
|
|
2.25.0
|
|
|