]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu, lxc: move NodeDeviceGetPCIInfo() function to domain_driver.c
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 4 Jan 2021 12:54:26 +0000 (09:54 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 29 Jan 2021 20:49:54 +0000 (17:49 -0300)
libxlNodeDeviceGetPCIInfo() and qemuNodeDeviceGetPCIInfo() are equal.
Let's move the logic to a new virDomainDriverNodeDeviceGetPCIInfo()
info to be used by libxl_driver.c and qemu_driver.c.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/hypervisor/domain_driver.c
src/hypervisor/domain_driver.h
src/libvirt_private.syms
src/libxl/libxl_driver.c
src/qemu/qemu_driver.c

index 8dc5870a619aa737d04f5c236ebdc62770c34c90..9c54cd701e3f0098d98e674f303a8f0ab9594fb8 100644 (file)
@@ -336,3 +336,35 @@ virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
 
     return ret;
 }
+
+
+int
+virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
+                                    unsigned *domain,
+                                    unsigned *bus,
+                                    unsigned *slot,
+                                    unsigned *function)
+{
+    virNodeDevCapsDefPtr cap;
+
+    cap = def->caps;
+    while (cap) {
+        if (cap->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
+            *domain   = cap->data.pci_dev.domain;
+            *bus      = cap->data.pci_dev.bus;
+            *slot     = cap->data.pci_dev.slot;
+            *function = cap->data.pci_dev.function;
+            break;
+        }
+
+        cap = cap->next;
+    }
+
+    if (!cap) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("device %s is not a PCI device"), def->name);
+        return -1;
+    }
+
+    return 0;
+}
index b66ae2d4219ef1a961f916e794eca53af0b17dbf..2bb053d55905d52938b92879f617d2e953f42640 100644 (file)
@@ -21,6 +21,7 @@
 #pragma once
 
 #include "domain_conf.h"
+#include "node_device_conf.h"
 
 char *
 virDomainDriverGenerateRootHash(const char *drivername,
@@ -45,3 +46,9 @@ int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
 int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
                                                  virTypedParameterPtr params,
                                                  int nparams);
+
+int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
+                                        unsigned *domain,
+                                        unsigned *bus,
+                                        unsigned *slot,
+                                        unsigned *function);
index 4b6fca63d4c14d024e171131306e513a5fc26484..8138780237a0c882cffc8d48d1b033e27665abad 100644 (file)
@@ -1503,6 +1503,7 @@ virDomainCgroupSetupMemtune;
 virDomainDriverGenerateMachineName;
 virDomainDriverGenerateRootHash;
 virDomainDriverMergeBlkioDevice;
+virDomainDriverNodeDeviceGetPCIInfo;
 virDomainDriverParseBlkioDeviceStr;
 virDomainDriverSetupPersistentDefBlkioParams;
 
index 5bd3614e2161c6c1e29ec6225cf7e81b55b82428..0821d39c9b8ce35161ccd904f0fe50413041cd40 100644 (file)
@@ -56,6 +56,7 @@
 #include "cpu/cpu.h"
 #include "virutil.h"
 #include "domain_validate.h"
+#include "domain_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -5773,37 +5774,6 @@ libxlConnectSupportsFeature(virConnectPtr conn, int feature)
     }
 }
 
-static int
-libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
-                          unsigned *domain,
-                          unsigned *bus,
-                          unsigned *slot,
-                          unsigned *function)
-{
-    virNodeDevCapsDefPtr cap;
-
-    cap = def->caps;
-    while (cap) {
-        if (cap->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
-            *domain   = cap->data.pci_dev.domain;
-            *bus      = cap->data.pci_dev.bus;
-            *slot     = cap->data.pci_dev.slot;
-            *function = cap->data.pci_dev.function;
-            break;
-        }
-
-        cap = cap->next;
-    }
-
-    if (!cap) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("device %s is not a PCI device"), def->name);
-        return -1;
-    }
-
-    return 0;
-}
-
 static int
 libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
                            const char *driverName,
@@ -5845,7 +5815,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
     if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0)
         goto cleanup;
 
-    if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
         goto cleanup;
 
     pci = virPCIDeviceNew(domain, bus, slot, function);
@@ -5916,7 +5886,7 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
     if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0)
         goto cleanup;
 
-    if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
         goto cleanup;
 
     pci = virPCIDeviceNew(domain, bus, slot, function);
@@ -5974,7 +5944,7 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
     if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
         goto cleanup;
 
-    if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
         goto cleanup;
 
     pci = virPCIDeviceNew(domain, bus, slot, function);
index 6193376544d6192db2c35bd3ac1156db70e773fe..c02312d7b4447a0de91252e066fc5daf380e203d 100644 (file)
@@ -11964,37 +11964,6 @@ qemuDomainMigrateConfirm3Params(virDomainPtr domain,
 }
 
 
-static int
-qemuNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
-                         unsigned *domain,
-                         unsigned *bus,
-                         unsigned *slot,
-                         unsigned *function)
-{
-    virNodeDevCapsDefPtr cap;
-
-    cap = def->caps;
-    while (cap) {
-        if (cap->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
-            *domain   = cap->data.pci_dev.domain;
-            *bus      = cap->data.pci_dev.bus;
-            *slot     = cap->data.pci_dev.slot;
-            *function = cap->data.pci_dev.function;
-            break;
-        }
-
-        cap = cap->next;
-    }
-
-    if (!cap) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("device %s is not a PCI device"), def->name);
-        return -1;
-    }
-
-    return 0;
-}
-
 static int
 qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
                           const char *driverName,
@@ -12037,7 +12006,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
     if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0)
         goto cleanup;
 
-    if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
         goto cleanup;
 
     pci = virPCIDeviceNew(domain, bus, slot, function);
@@ -12118,7 +12087,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
     if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0)
         goto cleanup;
 
-    if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
         goto cleanup;
 
     pci = virPCIDeviceNew(domain, bus, slot, function);
@@ -12172,7 +12141,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
     if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
         goto cleanup;
 
-    if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
         goto cleanup;
 
     pci = virPCIDeviceNew(domain, bus, slot, function);