[RFC v2: vf-token 4/7] conf: vf-token parsing and formatting

Vivek Kashyap posted 7 patches 2 years ago
There is a newer version of this series
[RFC v2: vf-token 4/7] conf: vf-token parsing and formatting
Posted by Vivek Kashyap 2 years ago
XML parsing and formatting of vf-token attribute

Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com>
---
 src/conf/device_conf.c          | 32 ++++++++++++++++++++++++++++++--
 src/conf/device_conf.h          |  3 +++
 src/conf/domain_conf.c          |  8 ++++++++
 src/conf/schemas/basictypes.rng |  7 +++++++
 src/libvirt_private.syms        |  1 +
 src/util/virpci.c               |  7 +++++++
 src/util/virpci.h               |  3 +++
 7 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index f3d977f2b7..f365e98bfd 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -188,11 +188,20 @@ virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info)
            virZPCIDeviceAddressIsIncomplete(&info->addr.pci.zpci);
 }
 
+bool
+virDeviceExtensionIsPresent(const virPCIDeviceAddress *pci)
+{
+    return (((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) &&
+           virZPCIDeviceAddressIsPresent(&pci->zpci)) ||
+           ((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) &&
+           pci->token.isSet));
+}
+
 bool
 virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info)
 {
-    return (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) &&
-           virZPCIDeviceAddressIsPresent(&info->addr.pci.zpci);
+    return (info->addr.pci.extFlags != VIR_PCI_ADDRESS_EXTENSION_NONE) &&
+           virDeviceExtensionIsPresent(&info->addr.pci);
 }
 
 int
@@ -200,6 +209,7 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
                             virPCIDeviceAddress *addr)
 {
     xmlNodePtr zpci;
+    xmlNodePtr token;
 
     memset(addr, 0, sizeof(*addr));
 
@@ -231,6 +241,11 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
             return -1;
     }
 
+    if ((token = virXMLNodeGetSubelement(node, "vf-token"))) {
+       if (virPCIDeviceTokenParseXML(token, addr) < 0)
+           return -1;
+    }
+
     return 0;
 }
 
@@ -248,6 +263,19 @@ virPCIDeviceAddressFormat(virBuffer *buf,
                       addr.function);
 }
 
+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;
+}
+
 int
 virCCWDeviceAddressParseXML(xmlNodePtr node,
                             virCCWDeviceAddress *addr)
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index a83377417a..a37ee29b88 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -188,6 +188,9 @@ bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info);
 int virPCIDeviceAddressParseXML(xmlNodePtr node,
                                 virPCIDeviceAddress *addr);
 
+int virPCIDeviceTokenParseXML(xmlNodePtr node,
+                              virPCIDeviceAddress *addr);
+
 void virPCIDeviceAddressFormat(virBuffer *buf,
                                virPCIDeviceAddress addr,
                                bool includeTypeInAddr);
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/conf/schemas/basictypes.rng b/src/conf/schemas/basictypes.rng
index 26eb538077..bbb7484430 100644
--- a/src/conf/schemas/basictypes.rng
+++ b/src/conf/schemas/basictypes.rng
@@ -121,6 +121,13 @@
         <ref name="virOnOff"/>
       </attribute>
     </optional>
+    <optional>
+     <element name="vf-token">
+       <attribute name="uuid">
+         <ref name="UUID"/>
+       </attribute>
+     </element>
+    </optional>
   </define>
   <define name="zpciaddress">
     <optional>
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 553b01b8c0..0726ae6622 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3137,6 +3137,7 @@ virPCIHeaderTypeToString;
 virPCIIsVirtualFunction;
 virPCIStubDriverTypeFromString;
 virPCIStubDriverTypeToString;
+virPCIVFIOTokenIDIsPresent;
 virPCIVirtualFunctionListFree;
 virZPCIDeviceAddressIsIncomplete;
 virZPCIDeviceAddressIsPresent;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index baacde4c14..2aca144e85 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -2313,6 +2313,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 f080fceb97..2d49bbd53f 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -279,6 +279,9 @@ int virPCIDeviceAddressParse(char *address, virPCIDeviceAddress *bdf);
 bool virZPCIDeviceAddressIsIncomplete(const virZPCIDeviceAddress *addr);
 bool virZPCIDeviceAddressIsPresent(const virZPCIDeviceAddress *addr);
 
+bool virPCIVFIOTokenIDIsPresent(const virPCIDeviceToken *token);
+bool virDeviceExtensionIsPresent(const virPCIDeviceAddress *pci);
+
 int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
                                  int pfNetDevIdx,
                                  char **pfname,
-- 
2.25.1
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [RFC v2: vf-token 4/7] conf: vf-token parsing and formatting
Posted by Peter Krempa 2 years ago
On Wed, Nov 29, 2023 at 21:07:24 -0700, Vivek Kashyap wrote:
> XML parsing and formatting of vf-token attribute
> 
> Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com>
> ---
>  src/conf/device_conf.c          | 32 ++++++++++++++++++++++++++++++--
>  src/conf/device_conf.h          |  3 +++
>  src/conf/domain_conf.c          |  8 ++++++++
>  src/conf/schemas/basictypes.rng |  7 +++++++
>  src/libvirt_private.syms        |  1 +
>  src/util/virpci.c               |  7 +++++++
>  src/util/virpci.h               |  3 +++
>  7 files changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
> index f3d977f2b7..f365e98bfd 100644
> --- a/src/conf/device_conf.c
> +++ b/src/conf/device_conf.c
> @@ -188,11 +188,20 @@ virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info)
>             virZPCIDeviceAddressIsIncomplete(&info->addr.pci.zpci);
>  }
>  
> +bool
> +virDeviceExtensionIsPresent(const virPCIDeviceAddress *pci)
> +{
> +    return (((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) &&
> +           virZPCIDeviceAddressIsPresent(&pci->zpci)) ||
> +           ((pci->extFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) &&
> +           pci->token.isSet));
> +}
> +
>  bool
>  virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info)
>  {
> -    return (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) &&
> -           virZPCIDeviceAddressIsPresent(&info->addr.pci.zpci);
> +    return (info->addr.pci.extFlags != VIR_PCI_ADDRESS_EXTENSION_NONE) &&
> +           virDeviceExtensionIsPresent(&info->addr.pci);
>  }

Fixes to coding style requested before:

https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/46WYW3QL7DNVDLVLDLEHWV46LHNTVSI3/

were not addressed. Note that reviews aren't an easy task an thus not
addressing all feedback may deter reviewers from a timely look at your
next postings.

>  
>  int
> @@ -200,6 +209,7 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
>                              virPCIDeviceAddress *addr)
>  {
>      xmlNodePtr zpci;
> +    xmlNodePtr token;
>  
>      memset(addr, 0, sizeof(*addr));
>  
> @@ -231,6 +241,11 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
>              return -1;
>      }
>  
> +    if ((token = virXMLNodeGetSubelement(node, "vf-token"))) {
> +       if (virPCIDeviceTokenParseXML(token, addr) < 0)
> +           return -1;
> +    }
> +
>      return 0;
>  }
>  
> @@ -248,6 +263,19 @@ virPCIDeviceAddressFormat(virBuffer *buf,
>                        addr.function);
>  }
>  
> +int

No need to export this function, as it's used just in this file. Place
it properly and make it static.

> +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;
> +}
> +
>  int
>  virCCWDeviceAddressParseXML(xmlNodePtr node,
>                              virCCWDeviceAddress *addr)
> diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
> index a83377417a..a37ee29b88 100644
> --- a/src/conf/device_conf.h
> +++ b/src/conf/device_conf.h
> @@ -188,6 +188,9 @@ bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info);
>  int virPCIDeviceAddressParseXML(xmlNodePtr node,
>                                  virPCIDeviceAddress *addr);
>  
> +int virPCIDeviceTokenParseXML(xmlNodePtr node,
> +                              virPCIDeviceAddress *addr);
> +

Drop this hunk.

>  void virPCIDeviceAddressFormat(virBuffer *buf,
>                                 virPCIDeviceAddress addr,
>                                 bool includeTypeInAddr);
> 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/conf/schemas/basictypes.rng b/src/conf/schemas/basictypes.rng
> index 26eb538077..bbb7484430 100644
> --- a/src/conf/schemas/basictypes.rng
> +++ b/src/conf/schemas/basictypes.rng
> @@ -121,6 +121,13 @@
>          <ref name="virOnOff"/>
>        </attribute>
>      </optional>
> +    <optional>
> +     <element name="vf-token">
> +       <attribute name="uuid">
> +         <ref name="UUID"/>
> +       </attribute>
> +     </element>
> +    </optional>
>    </define>
>    <define name="zpciaddress">
>      <optional>

And move the documentation from the last patch to this one.
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [RFC v2: vf-token 4/7] conf: vf-token parsing and formatting
Posted by Peter Krempa 2 years ago
On Thu, Nov 30, 2023 at 09:36:00 +0100, Peter Krempa wrote:
> On Wed, Nov 29, 2023 at 21:07:24 -0700, Vivek Kashyap wrote:
> > XML parsing and formatting of vf-token attribute
> > 
> > Signed-off-by: Vivek Kashyap <vivek.kashyap@linux.intel.com>
> > ---
> >  src/conf/device_conf.c          | 32 ++++++++++++++++++++++++++++++--
> >  src/conf/device_conf.h          |  3 +++
> >  src/conf/domain_conf.c          |  8 ++++++++
> >  src/conf/schemas/basictypes.rng |  7 +++++++
> >  src/libvirt_private.syms        |  1 +
> >  src/util/virpci.c               |  7 +++++++
> >  src/util/virpci.h               |  3 +++
> >  7 files changed, 59 insertions(+), 2 deletions(-)

[...]

> > 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));

Also this is the wrong place to format this data. This function formats
the frontend address. You are parsing the token inside the
<source><address> sub-element.

Also add a qemuxml2xmltest case with the same input to make sure you
actually test it.

> > +        }
> >          break;
> >  
> >      case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org