[libvirt] [PATCH 04/16] conf: Adjust the domain parser to work with mdevs

Erik Skultety eskultet at redhat.com
Mon Feb 6 12:19:46 UTC 2017


As for the parser, the uuid element is optional and a UUID will be
generated automatically if missing unless the device is unmanaged
(default) in which case the element is mandatory, otherwise libvirt
wouldn't have means to identify the device uniquely.

Signed-off-by: Erik Skultety <eskultet at redhat.com>
---
 src/conf/domain_conf.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 38ffc95..f7bdd7a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6326,6 +6326,49 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode,
     return ret;
 }
 
+static int
+virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def,
+                                             xmlXPathContextPtr ctxt)
+{
+    int ret = -1;
+    unsigned char uuid[VIR_UUID_BUFLEN] = {0};
+    char *uuidxml = NULL;
+    xmlNodePtr node = NULL;
+
+    virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev;
+    virPCIDeviceAddressPtr addr = &mdevsrc->addr;
+
+    node = virXPathNode("./source/address", ctxt);
+    if (virPCIDeviceAddressParseXML(node, addr) < 0)
+        return -1;
+
+    uuidxml = virXPathString("string(./source/uuid)", ctxt);
+    if (!uuidxml && !def->managed) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("uuid element is mandatory for unmanaged devices"));
+        goto cleanup;
+    }
+
+    if (uuidxml) {
+        if (virUUIDParse(uuidxml, uuid) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "%s", _("malformed uuid element"));
+            goto cleanup;
+        }
+    } else {
+        if (virUUIDGenerate(uuid)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "%s", _("Failed to generate UUID"));
+            goto cleanup;
+        }
+    }
+
+    virUUIDFormat(uuid, mdevsrc->uuidstr);
+    ret = 0;
+ cleanup:
+    VIR_FREE(uuidxml);
+    return ret;
+}
 
 static int
 virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
@@ -6455,6 +6498,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
             goto error;
         break;
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+        if (virDomainHostdevSubsysMediatedDevDefParseXML(def, ctxt) < 0)
+            goto error;
         break;
 
     default:
-- 
2.10.2




More information about the libvir-list mailing list