[PATCH 1/9] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReset() helper

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

 



libxlNodeDeviceReset() and qemuNodeDeviceReset() are mostly equal,
differing only how the virHostdevManager pointer is retrieved.

Put the common code into virDomainDriverNodeDeviceReset() to reduce
code duplication.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/hypervisor/domain_driver.c | 58 ++++++++++++++++++++++++++++++++++
 src/hypervisor/domain_driver.h |  4 +++
 src/hypervisor/meson.build     |  1 +
 src/libvirt_private.syms       |  1 +
 src/libxl/libxl_driver.c       | 53 ++-----------------------------
 src/qemu/qemu_driver.c         | 49 ++--------------------------
 6 files changed, 70 insertions(+), 96 deletions(-)

diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index 5b03f79833..0c86fd714f 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -25,6 +25,10 @@
 #include "virstring.h"
 #include "vircrypto.h"
 #include "virutil.h"
+#include "virhostdev.h"
+#include "viraccessapicheck.h"
+#include "datatypes.h"
+#include "driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -365,3 +369,57 @@ virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
 
     return 0;
 }
+
+
+int
+virDomainDriverNodeDeviceReset(virNodeDevicePtr dev,
+                               virHostdevManagerPtr hostdevMgr)
+{
+    virPCIDevicePtr pci;
+    virPCIDeviceAddress devAddr;
+    virNodeDeviceDefPtr def = NULL;
+    g_autofree char *xml = NULL;
+    virConnectPtr nodeconn = NULL;
+    virNodeDevicePtr nodedev = NULL;
+    int ret = -1;
+
+    if (!(nodeconn = virGetConnectNodeDev()))
+        goto cleanup;
+
+    /* 'dev' is associated with virConnectPtr, so for split
+     * daemons, we need to get a copy that is associated with
+     * the virnodedevd daemon. */
+    if (!(nodedev = virNodeDeviceLookupByName(
+              nodeconn, virNodeDeviceGetName(dev))))
+        goto cleanup;
+
+    xml = virNodeDeviceGetXMLDesc(nodedev, 0);
+    if (!xml)
+        goto cleanup;
+
+    def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
+    if (!def)
+        goto cleanup;
+
+    /* ACL check must happen against original 'dev',
+     * not the new 'nodedev' we acquired */
+    if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
+        goto cleanup;
+
+    if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
+        goto cleanup;
+
+    pci = virPCIDeviceNew(&devAddr);
+    if (!pci)
+        goto cleanup;
+
+    ret = virHostdevPCINodeDeviceReset(hostdevMgr, pci);
+
+    virPCIDeviceFree(pci);
+ cleanup:
+    virNodeDeviceDefFree(def);
+    virObjectUnref(nodedev);
+    virObjectUnref(nodeconn);
+    return ret;
+
+}
diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h
index 86b92d0284..b690844fe5 100644
--- a/src/hypervisor/domain_driver.h
+++ b/src/hypervisor/domain_driver.h
@@ -22,6 +22,7 @@
 
 #include "domain_conf.h"
 #include "node_device_conf.h"
+#include "virhostdev.h"
 
 char *
 virDomainDriverGenerateRootHash(const char *drivername,
@@ -49,3 +50,6 @@ int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
 
 int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
                                         virPCIDeviceAddressPtr devAddr);
+
+int virDomainDriverNodeDeviceReset(virNodeDevicePtr dev,
+                                   virHostdevManagerPtr hostdevMgr);
diff --git a/src/hypervisor/meson.build b/src/hypervisor/meson.build
index 85149c683e..32d5ab365f 100644
--- a/src/hypervisor/meson.build
+++ b/src/hypervisor/meson.build
@@ -11,6 +11,7 @@ hypervisor_lib = static_library(
     hypervisor_sources,
   ],
   dependencies: [
+    access_dep,
     src_dep,
   ],
   include_directories: [
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8138780237..1f6048e3f7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1504,6 +1504,7 @@ virDomainDriverGenerateMachineName;
 virDomainDriverGenerateRootHash;
 virDomainDriverMergeBlkioDevice;
 virDomainDriverNodeDeviceGetPCIInfo;
+virDomainDriverNodeDeviceReset;
 virDomainDriverParseBlkioDeviceStr;
 virDomainDriverSetupPersistentDefBlkioParams;
 
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 3eaf106006..50baeb43b6 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5910,59 +5910,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
 static int
 libxlNodeDeviceReset(virNodeDevicePtr dev)
 {
-    virPCIDevicePtr pci = NULL;
-    virPCIDeviceAddress devAddr;
-    int ret = -1;
-    virNodeDeviceDefPtr def = NULL;
-    char *xml = NULL;
     libxlDriverPrivatePtr driver = dev->conn->privateData;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
-    virConnectPtr nodeconn = NULL;
-    virNodeDevicePtr nodedev = NULL;
-
-    if (!(nodeconn = virGetConnectNodeDev()))
-        goto cleanup;
-
-    /* 'dev' is associated with the QEMU virConnectPtr,
-     * so for split daemons, we need to get a copy that
-     * is associated with the virnodedevd daemon.
-     */
-    if (!(nodedev = virNodeDeviceLookupByName(
-              nodeconn, virNodeDeviceGetName(dev))))
-        goto cleanup;
-
-    xml = virNodeDeviceGetXMLDesc(nodedev, 0);
-    if (!xml)
-        goto cleanup;
-
-    def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
-    if (!def)
-        goto cleanup;
-
-    /* ACL check must happen against original 'dev',
-     * not the new 'nodedev' we acquired */
-    if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
-        goto cleanup;
-
-    if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
-        goto cleanup;
-
-    pci = virPCIDeviceNew(&devAddr);
-    if (!pci)
-        goto cleanup;
-
-    if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci) < 0)
-        goto cleanup;
 
-    ret = 0;
-
- cleanup:
-    virPCIDeviceFree(pci);
-    virNodeDeviceDefFree(def);
-    virObjectUnref(nodedev);
-    virObjectUnref(nodeconn);
-    VIR_FREE(xml);
-    return ret;
+    /* virNodeDeviceResetEnsureACL() is being called by
+     * virDomainDriverNodeDeviceReset() */
+    return virDomainDriverNodeDeviceReset(dev, hostdev_mgr);
 }
 
 static char *
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ed840a5c8d..8270a26c0b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12108,54 +12108,11 @@ static int
 qemuNodeDeviceReset(virNodeDevicePtr dev)
 {
     virQEMUDriverPtr driver = dev->conn->privateData;
-    virPCIDevicePtr pci;
-    virPCIDeviceAddress devAddr;
-    int ret = -1;
-    virNodeDeviceDefPtr def = NULL;
-    g_autofree char *xml = NULL;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
-    virConnectPtr nodeconn = NULL;
-    virNodeDevicePtr nodedev = NULL;
-
-    if (!(nodeconn = virGetConnectNodeDev()))
-        goto cleanup;
-
-    /* 'dev' is associated with the QEMU virConnectPtr,
-     * so for split daemons, we need to get a copy that
-     * is associated with the virnodedevd daemon.
-     */
-    if (!(nodedev = virNodeDeviceLookupByName(
-              nodeconn, virNodeDeviceGetName(dev))))
-        goto cleanup;
 
-    xml = virNodeDeviceGetXMLDesc(nodedev, 0);
-    if (!xml)
-        goto cleanup;
-
-    def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
-    if (!def)
-        goto cleanup;
-
-    /* ACL check must happen against original 'dev',
-     * not the new 'nodedev' we acquired */
-    if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
-        goto cleanup;
-
-    if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
-        goto cleanup;
-
-    pci = virPCIDeviceNew(&devAddr);
-    if (!pci)
-        goto cleanup;
-
-    ret = virHostdevPCINodeDeviceReset(hostdev_mgr, pci);
-
-    virPCIDeviceFree(pci);
- cleanup:
-    virNodeDeviceDefFree(def);
-    virObjectUnref(nodedev);
-    virObjectUnref(nodeconn);
-    return ret;
+    /* virNodeDeviceResetEnsureACL() is being called by
+     * virDomainDriverNodeDeviceReset() */
+    return virDomainDriverNodeDeviceReset(dev, hostdev_mgr);
 }
 
 static int
-- 
2.26.2




[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