Re: [libvirt PATCH v2 06/15] conf: use virDeviceHostdevPCIDriverInfo in network and networkport objects

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

 



On Mon, Nov 06, 2023 at 02:38:51 -0500, Laine Stump wrote:
> The next step in consolidating parsing/formatting of the <driver>
> element of these objects using a common struct and common code. This
> eliminates the virNetworkForwardDriverNameType enum which is nearly
> identical to virDeviceHostdevPCIDriverType (the only non-identical bit
> was just because they'd gotten out of sync over time) and replaces its
> uses with a virDeviceHostdevPCIDriverInfo (which is a struct that
> contains a virDeviceHostdevPCIDriverType).
> 
> Signed-off-by: Laine Stump <laine@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c       | 48 +++---------------------------------
>  src/conf/network_conf.c      | 21 ++++++----------
>  src/conf/network_conf.h      | 17 ++-----------
>  src/conf/virnetworkportdef.c | 10 ++++----
>  src/conf/virnetworkportdef.h |  4 ++-
>  src/network/bridge_driver.c  |  2 +-
>  6 files changed, 22 insertions(+), 80 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index e322f1ffa7..82c1287986 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -29836,29 +29836,8 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDef *iface,
>          }
>          actual->data.hostdev.def.source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
>          actual->data.hostdev.def.source.subsys.u.pci.addr = port->plug.hostdevpci.addr;
> -        switch ((virNetworkForwardDriverNameType)port->plug.hostdevpci.driver) {
> -        case VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT:
> -            actual->data.hostdev.def.source.subsys.u.pci.driver.type =
> -                VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT;
> -            break;
> -
> -        case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM:
> -            actual->data.hostdev.def.source.subsys.u.pci.driver.type =
> -                VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_KVM;
> -            break;
> -
> -        case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO:
> -            actual->data.hostdev.def.source.subsys.u.pci.driver.type =
> -                VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_VFIO;
> -            break;
> -
> -        case VIR_NETWORK_FORWARD_DRIVER_NAME_LAST:
> -        default:
> -            virReportEnumRangeError(virNetworkForwardDriverNameType,
> -                                    port->plug.hostdevpci.driver);
> -            goto error;
> -        }
> -
> +        actual->data.hostdev.def.source.subsys.u.pci.driver.type
> +            = port->plug.hostdevpci.driver.type;
>          break;
>  
>      case VIR_NETWORK_PORT_PLUG_TYPE_LAST:
> @@ -29959,27 +29938,8 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
>          }
>          port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
>          port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr;
> -        switch (actual->data.hostdev.def.source.subsys.u.pci.driver.type) {
> -        case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT:
> -            port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
> -            break;
> -
> -        case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_KVM:
> -            port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_KVM;
> -            break;
> -
> -        case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_VFIO:
> -            port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO;
> -            break;
> -
> -        case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_XEN:
> -        case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_LAST:
> -        default:
> -            virReportEnumRangeError(virDeviceHostdevPCIDriverType,
> -                                    actual->data.hostdev.def.source.subsys.u.pci.driver.type);
> -            return NULL;
> -        }
> -
> +        port->plug.hostdevpci.driver.type
> +            = actual->data.hostdev.def.source.subsys.u.pci.driver.type;

It's okay if you un-break the line here. Don't need to create conflicts
in previous patches.


>          break;
>  
>      case VIR_DOMAIN_NET_TYPE_CLIENT:
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index b9601cb307..e3ad4c7340 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -56,13 +56,6 @@ VIR_ENUM_IMPL(virNetworkForwardHostdevDevice,
>                "none", "pci", "netdev",
>  );
>  
> -VIR_ENUM_IMPL(virNetworkForwardDriverName,
> -              VIR_NETWORK_FORWARD_DRIVER_NAME_LAST,
> -              "default",
> -              "kvm",
> -              "vfio",
> -);
> -
>  VIR_ENUM_IMPL(virNetworkTaint,
>                VIR_NETWORK_TAINT_LAST,
>                "hook-script",
> @@ -1358,9 +1351,9 @@ virNetworkForwardDefParseXML(const char *networkName,
>  
>      if ((driverNode = virXPathNode("./driver", ctxt))) {
>          if (virXMLPropEnum(driverNode, "name",
> -                           virNetworkForwardDriverNameTypeFromString,
> +                           virDeviceHostdevPCIDriverTypeFromString,
>                             VIR_XML_PROP_NONZERO,
> -                           &def->driverName) < 0) {
> +                           &def->driver.type) < 0) {
>              return -1;
>          }
>      }
> @@ -2351,19 +2344,19 @@ virNetworkDefFormatBuf(virBuffer *buf,
>                           || VIR_SOCKET_ADDR_VALID(&def->forward.addr.end)
>                           || def->forward.port.start
>                           || def->forward.port.end
> -                         || (def->forward.driverName
> -                             != VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT)
> +                         || (def->forward.driver.type
> +                             != VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT)
>                           || def->forward.natIPv6);
>          virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : "");
>          virBufferAdjustIndent(buf, 2);
>  
> -        if (def->forward.driverName) {
> +        if (def->forward.driver.type) {
>              const char *driverName
> -                = virNetworkForwardDriverNameTypeToString(def->forward.driverName);
> +                = virDeviceHostdevPCIDriverTypeToString(def->forward.driver.type);
>              if (!driverName) {
>                  virReportError(VIR_ERR_INTERNAL_ERROR,
>                                 _("unexpected hostdev driver name type %1$d "),
> -                               def->forward.driverName);
> +                               def->forward.driver.type);
>                  return -1;
>              }
>              virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName);
> diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
> index 497ae765f2..1d7fd3ab6a 100644
> --- a/src/conf/network_conf.h
> +++ b/src/conf/network_conf.h
> @@ -24,6 +24,7 @@
>  #define DNS_RECORD_LENGTH_SRV  (512 - 30)  /* Limit minus overhead as mentioned in RFC-2782 */
>  
>  #include "internal.h"
> +#include "virconftypes.h"
>  #include "virsocketaddr.h"
>  #include "virnetdevbandwidth.h"
>  #include "virnetdevvportprofile.h"
> @@ -88,20 +89,6 @@ typedef enum {
>  
>  VIR_ENUM_DECL(virNetworkDHCPLeaseTimeUnit);
>  
> -/* The backend driver used for devices from the pool. Currently used
> - * only for PCI devices (vfio vs. kvm), but could be used for other
> - * device types in the future.
> - */
> -typedef enum {
> -    VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT, /* kvm now, could change */
> -    VIR_NETWORK_FORWARD_DRIVER_NAME_KVM,    /* force legacy kvm style */
> -    VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO,   /* force vfio */
> -
> -    VIR_NETWORK_FORWARD_DRIVER_NAME_LAST
> -} virNetworkForwardDriverNameType;
> -
> -VIR_ENUM_DECL(virNetworkForwardDriverName);
> -
>  typedef struct _virNetworkDHCPLeaseTimeDef virNetworkDHCPLeaseTimeDef;
>  struct _virNetworkDHCPLeaseTimeDef {
>      unsigned long long expiry;
> @@ -216,7 +203,7 @@ typedef struct _virNetworkForwardDef virNetworkForwardDef;
>  struct _virNetworkForwardDef {
>      int type;     /* One of virNetworkForwardType constants */
>      bool managed;  /* managed attribute for hostdev mode */
> -    virNetworkForwardDriverNameType driverName;
> +    virDeviceHostdevPCIDriverInfo driver;
>  
>      /* If there are multiple forward devices (i.e. a pool of
>       * interfaces), they will be listed here.
> diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
> index 402c0051ec..77ef705e18 100644
> --- a/src/conf/virnetworkportdef.c
> +++ b/src/conf/virnetworkportdef.c
> @@ -226,9 +226,9 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
>  
>          if ((driverNode = virXPathNode("./plug/driver", ctxt))) {
>              if (virXMLPropEnum(driverNode, "name",
> -                               virNetworkForwardDriverNameTypeFromString,
> +                               virDeviceHostdevPCIDriverTypeFromString,
>                                 VIR_XML_PROP_NONZERO,
> -                               &def->plug.hostdevpci.driver) < 0) {
> +                               &def->plug.hostdevpci.driver.type) < 0) {
>                  return NULL;
>              }
>          }
> @@ -356,10 +356,10 @@ virNetworkPortDefFormatBuf(virBuffer *buf,
>              virBufferAddLit(buf, ">\n");
>              virBufferAdjustIndent(buf, 2);
>  
> -            if (def->plug.hostdevpci.driver) {
> +            if (def->plug.hostdevpci.driver.type) {
>                  virBufferEscapeString(&driverAttrBuf, " name='%s'",
> -                                      virNetworkForwardDriverNameTypeToString(
> -                                          def->plug.hostdevpci.driver));
> +                                      virDeviceHostdevPCIDriverTypeToString(
> +                                          def->plug.hostdevpci.driver.type));
>              }
>  
>              virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
> diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h
> index bfe1dae9ea..9e51ab1a8b 100644
> --- a/src/conf/virnetworkportdef.h
> +++ b/src/conf/virnetworkportdef.h
> @@ -22,6 +22,8 @@
>  #pragma once
>  
>  #include "internal.h"
> +#include "virconftypes.h"
> +#include "device_conf.h"
>  #include "virnetdevvlan.h"
>  #include "virnetdevvportprofile.h"
>  #include "virnetdevbandwidth.h"
> @@ -69,7 +71,7 @@ struct _virNetworkPortDef {
>          } direct;
>          struct {
>              virPCIDeviceAddress addr; /* PCI Address of device */
> -            unsigned int driver; /* virNetworkForwardDriverNameType */
> +            virDeviceHostdevPCIDriverInfo driver;

You can ignore my earlier comment about this.

Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
_______________________________________________
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