[PATCH vf-token 4/8] conf: XML parsing and formatting of vf-token

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch introduces new XML parser/formatter functions for
parsing the vf-token

Signed-off-by: Vivek Kashyap <vivek.kashyap@xxxxxxxxxxxxxxx>
Signed-off-by: Ciara Loftus <ciara.loftus@xxxxxxxxx>
---
 src/conf/device_conf.c   | 49 ++++++++++++++++++++++++++++++++++------
 src/conf/domain_conf.c   |  8 +++++++
 src/libvirt_private.syms |  1 +
 src/util/virpci.c        |  7 ++++++
 src/util/virpci.h        |  2 ++
 5 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index f3d977f2b7..f490aeef9a 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -70,6 +70,21 @@ virZPCIDeviceAddressParseXML(xmlNodePtr node,
     return 0;
 }
 
+
+static int
+virPCIDeviceTokenParseXML(xmlNodePtr node,
+                          virPCIDeviceAddress *addr)
+{
+    if (virXMLPropUUID(node, "uuid", VIR_XML_PROP_NONE,
+                       addr->token.uuid) < 0)
+       return -1;
+
+    addr->token.isSet = 1;
+
+    return 0;
+}
+
+
 void
 virDomainDeviceInfoClear(virDomainDeviceInfo *info)
 {
@@ -200,6 +215,7 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
                             virPCIDeviceAddress *addr)
 {
     xmlNodePtr zpci;
+    xmlNodePtr token;
 
     memset(addr, 0, sizeof(*addr));
 
@@ -231,6 +247,11 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
             return -1;
     }
 
+    if ((token = virXMLNodeGetSubelement(node, "vf-token"))) {
+       if (virPCIDeviceTokenParseXML(token, addr) < 0)
+           return -1;
+    }
+
     return 0;
 }
 
@@ -239,13 +260,27 @@ virPCIDeviceAddressFormat(virBuffer *buf,
                           virPCIDeviceAddress addr,
                           bool includeTypeInAddr)
 {
-    virBufferAsprintf(buf, "<address %sdomain='0x%04x' bus='0x%02x' "
-                      "slot='0x%02x' function='0x%d'/>\n",
-                      includeTypeInAddr ? "type='pci' " : "",
-                      addr.domain,
-                      addr.bus,
-                      addr.slot,
-                      addr.function);
+    g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+    g_auto(virBuffer) tokenBuf = VIR_BUFFER_INIT_CHILD(buf);
+    virBuffer *tb = NULL;
+
+    virBufferAsprintf(&attrBuf, " %sdomain='0x%04x' bus='0x%02x' "
+                  "slot='0x%02x' function='0x%d'",
+                   includeTypeInAddr ? "type='pci' " : "",
+                   addr.domain,
+                   addr.bus,
+                   addr.slot,
+                   addr.function);
+
+    if (virPCIVFIOTokenIDIsPresent(&addr.token)) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+        virBufferAsprintf(&tokenBuf, "<vf-token uuid='%s'/>\n",
+                          virUUIDFormat(addr.token.uuid, uuidstr));
+        tb = &tokenBuf;
+    }
+
+    virXMLFormatElement(buf, "address", &attrBuf, tb);
 }
 
 int
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 22ad43e1d7..8bda81815a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5403,6 +5403,14 @@ virDomainDeviceInfoFormat(virBuffer *buf,
                               info->addr.pci.zpci.uid.value,
                               info->addr.pci.zpci.fid.value);
         }
+
+        if (virPCIVFIOTokenIDIsPresent(&info->addr.pci.token)) {
+            char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+            virBufferAsprintf(&childBuf, "<vf-token uuid='%s'/>\n",
+                              virUUIDFormat(info->addr.pci.token.uuid,
+                                            uuidstr));
+        }
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 31c0f169c3..b2bc26c323 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3138,6 +3138,7 @@ virPCIHeaderTypeToString;
 virPCIIsVirtualFunction;
 virPCIStubDriverTypeFromString;
 virPCIStubDriverTypeToString;
+virPCIVFIOTokenIDIsPresent;
 virPCIVirtualFunctionListFree;
 virZPCIDeviceAddressIsIncomplete;
 virZPCIDeviceAddressIsPresent;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index afce7b52b7..0a9ae7a881 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -2314,6 +2314,13 @@ virZPCIDeviceAddressIsPresent(const virZPCIDeviceAddress *addr)
 }
 
 
+bool
+virPCIVFIOTokenIDIsPresent(const virPCIDeviceToken *token)
+{
+    return token->isSet;
+}
+
+
 void
 virPCIVirtualFunctionListFree(virPCIVirtualFunctionList *list)
 {
diff --git a/src/util/virpci.h b/src/util/virpci.h
index da32c2f4d2..8510752e84 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -271,6 +271,8 @@ int virPCIDeviceAddressParse(char *address, virPCIDeviceAddress *bdf);
 bool virZPCIDeviceAddressIsIncomplete(const virZPCIDeviceAddress *addr);
 bool virZPCIDeviceAddressIsPresent(const virZPCIDeviceAddress *addr);
 
+bool virPCIVFIOTokenIDIsPresent(const virPCIDeviceToken *token);
+
 int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
                                  int pfNetDevIdx,
                                  char **pfname,
-- 
2.33.8
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux