render / rpms / libvirt

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