render / rpms / libvirt

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