]> xenbits.xensource.com Git - people/aperard/libvirt.git/commitdiff
conf: put hostdev PCI backend into a struct
authorLaine Stump <laine@redhat.com>
Fri, 5 Jan 2024 01:12:51 +0000 (20:12 -0500)
committerLaine Stump <laine@redhat.com>
Mon, 8 Jan 2024 04:57:09 +0000 (23:57 -0500)
The new struct is virDeviceHostdevPCIDriverInfo, and the "backend"
enum in the hostdevDef will be replaced with a
virDeviceHostdevPCIDriverInfo named "driver'. Since the enum value in
this new struct is called "name", it means that all references to
"backend" will become "driver.name".

This will allow easily adding other items for new attributes in the
<driver> element / C struct, which will be useful once we are using
this new struct in multiple places.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
16 files changed:
src/conf/device_conf.h
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/virconftypes.h
src/hypervisor/virhostdev.c
src/libxl/libxl_domain.c
src/libxl/libxl_driver.c
src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/qemu/qemu_validate.c
src/security/security_apparmor.c
src/security/security_dac.c
src/security/security_selinux.c
src/security/virt-aa-helper.c
src/test/test_driver.c
tests/virhostdevtest.c

index 18aa4125fa8af045dd6cbf768ed3fe92988e9f5c..1f7e0661427ed83eaf01aeeca9977aaaabf197a6 100644 (file)
@@ -43,6 +43,10 @@ typedef enum {
 
 VIR_ENUM_DECL(virDeviceHostdevPCIDriverName);
 
+struct _virDeviceHostdevPCIDriverInfo {
+    virDeviceHostdevPCIDriverName name;
+};
+
 typedef enum {
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE = 0,
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,
index d09a0af9a5a8e566fba1c981afb6f859d4b4063b..295238894f028f2e2fac7205898dd8051deb8d28 100644 (file)
@@ -6287,7 +6287,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
             if (virXMLPropEnum(driver_node, "name",
                                virDeviceHostdevPCIDriverNameTypeFromString,
                                VIR_XML_PROP_NONZERO,
-                               &pcisrc->backend) < 0) {
+                               &pcisrc->driver.name) < 0) {
                 return -1;
             }
         }
@@ -23429,17 +23429,17 @@ virDomainHostdevDefFormatSubsysPCI(virBuffer *buf,
     g_auto(virBuffer) sourceChildBuf = VIR_BUFFER_INIT_CHILD(buf);
     virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
 
-    if (pcisrc->backend != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
-        const char *backend = virDeviceHostdevPCIDriverNameTypeToString(pcisrc->backend);
+    if (pcisrc->driver.name != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
+        const char *driverName = virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name);
 
-        if (!backend) {
+        if (!driverName) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("unexpected pci hostdev driver name type %1$d"),
-                           pcisrc->backend);
+                           _("unexpected pci hostdev driver type %1$d"),
+                           pcisrc->driver.name);
             return -1;
         }
 
-        virBufferAsprintf(&driverAttrBuf, " name='%s'", backend);
+        virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName);
     }
 
     virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
@@ -29967,15 +29967,15 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDef *iface,
         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.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT;
+            actual->data.hostdev.def.source.subsys.u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT;
             break;
 
         case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM:
-            actual->data.hostdev.def.source.subsys.u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM;
+            actual->data.hostdev.def.source.subsys.u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM;
             break;
 
         case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO:
-            actual->data.hostdev.def.source.subsys.u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
+            actual->data.hostdev.def.source.subsys.u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
             break;
 
         case VIR_NETWORK_FORWARD_DRIVER_NAME_LAST:
@@ -30085,7 +30085,7 @@ 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.backend) {
+        switch (actual->data.hostdev.def.source.subsys.u.pci.driver.name) {
         case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT:
             port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
             break;
@@ -30099,14 +30099,10 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
             break;
 
         case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN:
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Unexpected PCI backend 'xen'"));
-            break;
-
         case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
         default:
             virReportEnumRangeError(virDeviceHostdevPCIDriverName,
-                                    actual->data.hostdev.def.source.subsys.u.pci.backend);
+                                    actual->data.hostdev.def.source.subsys.u.pci.driver.name);
             return NULL;
         }
 
@@ -31050,7 +31046,7 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
 {
     return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
         hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-        hostdev->source.subsys.u.pci.backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
+        hostdev->source.subsys.u.pci.driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
 }
 
 
index 0c6a57c9a2c8de09404480ca55e653bba3e27adf..9d76dc7c7d4ecb5aba46340bb92df44f74d8959e 100644 (file)
@@ -235,7 +235,7 @@ struct _virDomainHostdevSubsysUSB {
 
 struct _virDomainHostdevSubsysPCI {
     virPCIDeviceAddress addr; /* host address */
-    virDeviceHostdevPCIDriverName backend;
+    virDeviceHostdevPCIDriverInfo driver;
 
     virBitmap *origstates;
 };
index 26cb96619417cdfcafe8443a44ef27ef4299198c..0779bc224b46caaea6229bd767924dd5f226c897 100644 (file)
@@ -66,6 +66,8 @@ typedef struct _virCapsHostSecModelLabel virCapsHostSecModelLabel;
 
 typedef struct _virCapsStoragePool virCapsStoragePool;
 
+typedef struct _virDeviceHostdevPCIDriverInfo virDeviceHostdevPCIDriverInfo;
+
 typedef struct _virDomainABIStability virDomainABIStability;
 
 typedef struct _virDomainActualNetDef virDomainActualNetDef;
index 26c9ac3c28e8d056507160a713845cb7d570980e..27b0acdc9115476727008073aaeb37ef29065179 100644 (file)
@@ -243,14 +243,14 @@ virHostdevGetPCIHostDevice(const virDomainHostdevDef *hostdev,
 
     virPCIDeviceSetManaged(actual, hostdev->managed);
 
-    if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+    if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
         virPCIDeviceSetStubDriverType(actual, VIR_PCI_STUB_DRIVER_VFIO);
-    } else if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN) {
+    } else if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN) {
         virPCIDeviceSetStubDriverType(actual, VIR_PCI_STUB_DRIVER_XEN);
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("pci backend driver type '%1$s' is not supported"),
-                       virDeviceHostdevPCIDriverNameTypeToString(pcisrc->backend));
+                       virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name));
         return -1;
     }
 
index 88d977e79b12fd2b14c8e08a916dd38d6e9247fd..1a7de00704375ed320d900d39ec57d48e3b448e4 100644 (file)
@@ -160,8 +160,8 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDef *dev,
 
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-            pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT)
-            pcisrc->backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
+            pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT)
+            pcisrc->driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
     }
 
     if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) {
@@ -997,7 +997,7 @@ libxlNetworkPrepareDevices(virDomainDef *def)
 
             if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
                 hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
-                pcisrc->backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
+                pcisrc->driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
 
             if (virDomainHostdevInsert(def, hostdev) < 0)
                 return -1;
index d7f79089c3179473895289723f500dcc41dcab6e..29fbc823ddab6832ca7a0cd6bce46b77cc18f409 100644 (file)
@@ -3397,13 +3397,13 @@ libxlDomainAttachNetDevice(libxlDriverPrivate *driver,
         virDomainHostdevDef *hostdev = virDomainNetGetActualHostdev(net);
         virDomainHostdevSubsysPCI *pcisrc = &hostdev->source.subsys.u.pci;
 
-        /* For those just allocated from a network pool whose backend is
+        /* For those just allocated from a network pool whose driver type is
          * still VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT, we need to set
-         * backend correctly.
+         * driver name correctly.
          */
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
-            pcisrc->backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
+            pcisrc->driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
 
         /* This is really a "smart hostdev", so it should be attached
          * as a hostdev (the hostdev code will reach over into the
index 73c80339c04e7dd7941dd8aa5cb661858b0112a7..2148419d3f9876acf221a8d55f939eeda7a708c6 100644 (file)
@@ -4707,8 +4707,8 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
     g_autofree char *host = virPCIDeviceAddressAsString(&pcisrc->addr);
     const char *failover_pair_id = NULL;
 
-    /* caller has to assign proper passthrough backend type */
-    switch (pcisrc->backend) {
+    /* caller has to assign proper passthrough driver name */
+    switch (pcisrc->driver.name) {
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO:
         break;
 
@@ -4718,7 +4718,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("invalid PCI passthrough type '%1$s'"),
-                       virDeviceHostdevPCIDriverNameTypeToString(pcisrc->backend));
+                       virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name));
         return NULL;
     }
 
index 0bda1699d5618e60ca448d3f5a740210f16c9aa6..642ab78e6c3ed6c12f6e87e9d67b3231b31df13d 100644 (file)
@@ -10534,7 +10534,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDef *dev,
     case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
         switch (dev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-            if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+            if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
                 if (!(tmpPath = virPCIDeviceAddressGetIOMMUGroupDev(&pcisrc->addr)))
                     return -1;
 
@@ -11305,7 +11305,7 @@ qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev,
                             virQEMUCaps *qemuCaps)
 {
     bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
-    virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.backend;
+    virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.driver.name;
 
     /* assign defaults for hostdev passthrough */
     switch (*driverName) {
index a10ab03cb28754d16ef84b21cf7b005dae81f927..697abb8dc314186e5d7c9d9852b36c2e0702cecd 100644 (file)
@@ -2437,7 +2437,7 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
                                    const virDomainDef *def,
                                    virQEMUCaps *qemuCaps)
 {
-    int backend;
+    virDeviceHostdevPCIDriverName driverName;
 
     /* forbid capabilities mode hostdev in this kind of hypervisor */
     if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
@@ -2462,9 +2462,9 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
             break;
 
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-            backend = hostdev->source.subsys.u.pci.backend;
+            driverName = hostdev->source.subsys.u.pci.driver.name;
 
-            if (backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+            if (driverName == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
                 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                    _("VFIO PCI device assignment is not supported by this version of qemu"));
index a1cbbc77e90d829b0100df3d11dc2622d8f54da1..c1dc859751d41d4c265d647a89b96b486fb6b0e7 100644 (file)
@@ -869,7 +869,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mgr,
         if (!pci)
             goto done;
 
-        if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+        if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
             char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev) {
index cb8b72b2894733117820e505c7c8c673871eceb5..4b8130630fc1e7859854997e05fbd0a783bb8742 100644 (file)
@@ -1257,7 +1257,7 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mgr,
         if (!pci)
             return -1;
 
-        if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+        if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
             g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev)
@@ -1418,7 +1418,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager *mgr,
         if (!pci)
             return -1;
 
-        if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+        if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
             g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev)
index 2ee542f6a4f0698b34f262989bf365f05caf921d..ffad058d9a8be34f8a444c61486846f34ad955c6 100644 (file)
@@ -2201,7 +2201,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManager *mgr,
         if (!pci)
             return -1;
 
-        if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+        if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
             g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev)
@@ -2437,7 +2437,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManager *mgr,
         if (!pci)
             return -1;
 
-        if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
+        if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
             g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
 
             if (!vfioGroupDev)
index d01df8710d5e127e9152ffa14f0f848a88719d62..0374581f07c69b5fcb91ea82d1ea3113948e0f23 100644 (file)
@@ -1092,7 +1092,7 @@ get_files(vahControl * ctl)
             case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
                 virPCIDevice *pci = virPCIDeviceNew(&dev->source.subsys.u.pci.addr);
 
-                virDeviceHostdevPCIDriverName driverName = dev->source.subsys.u.pci.backend;
+                virDeviceHostdevPCIDriverName driverName = dev->source.subsys.u.pci.driver.name;
 
                 if (driverName == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO ||
                     driverName == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
index 63e1f743c3d331f3fc879a0f00abd93f67a018ae..ed545848afcd21e68c54724f62dea761e97dc7ce 100644 (file)
@@ -10042,9 +10042,9 @@ testDomainAttachHostPCIDevice(testDriver *driver G_GNUC_UNUSED,
                               virDomainObj *vm,
                               virDomainHostdevDef *hostdev)
 {
-    int backend = hostdev->source.subsys.u.pci.backend;
+    int driverName = hostdev->source.subsys.u.pci.driver.name;
 
-    switch (backend) {
+    switch (driverName) {
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO:
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT:
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM:
@@ -10054,7 +10054,7 @@ testDomainAttachHostPCIDevice(testDriver *driver G_GNUC_UNUSED,
     case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("test hypervisor does not support device assignment mode '%1$s'"),
-                       virDeviceHostdevPCIDriverNameTypeToString(backend));
+                       virDeviceHostdevPCIDriverNameTypeToString(driverName));
         return -1;
     }
 
index 89b4fb5e7c561f098dcf3fd9a655afdc863ef1ec..aec474a148c6750a8d9c0582e2b6c799699ebb01 100644 (file)
@@ -134,7 +134,7 @@ myInit(void)
         subsys->u.pci.addr.bus = 0;
         subsys->u.pci.addr.slot = i + 1;
         subsys->u.pci.addr.function = 0;
-        subsys->u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
+        subsys->u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
     }
 
     for (i = 0; i < nhostdevs; i++) {