[libvirt] [PATCH v13 44/49] add 3 wrapper functions for prepare/reattach/update domain hostdevs

Chunyan Liu cyliu at suse.com
Sat Mar 1 06:29:39 UTC 2014


Signed-off-by: Chunyan Liu <cyliu at suse.com>
---
 src/libvirt_private.syms |    4 ++
 src/util/virhostdev.c    |  104 ++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virhostdev.h    |   24 ++++++++++-
 3 files changed, 130 insertions(+), 2 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a604c54..1b73518 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1296,15 +1296,19 @@ virHostdevManagerGetDefault;
 virHostdevPciNodeDeviceDetach;
 virHostdevPciNodeDeviceReAttach;
 virHostdevPciNodeDeviceReset;
+virHostdevPrepareDomainHostdevs;
 virHostdevPreparePciHostdevs;
 virHostdevPrepareScsiHostdevs;
 virHostdevPrepareUsbHostdevs;
+virHostdevReAttachDomainHostdevs;
 virHostdevReAttachPciHostdevs;
 virHostdevReAttachScsiHostdevs;
 virHostdevReAttachUsbHostdevs;
 virHostdevUpdateActivePciHostdevs;
 virHostdevUpdateActiveScsiHostdevs;
 virHostdevUpdateActiveUsbHostdevs;
+virHostdevUpdateDomainActiveHostdevs;
+
 
 # util/viridentity.h
 virIdentityGetAttr;
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 3160bb6..9c189a7 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1444,3 +1444,107 @@ out:
     virObjectUnlock(hostdev_mgr->activePciHostdevs);
     return ret;
 }
+
+int
+virHostdevPrepareDomainHostdevs(virHostdevManagerPtr mgr,
+                                const char *driver,
+                                virDomainDefPtr def,
+                                unsigned int flags)
+{
+    if (!def->nhostdevs)
+        return 0;
+
+    if (mgr == NULL)
+        return -1;
+
+    if (flags & VIR_SP_PCI_HOSTDEV) {
+        if (virHostdevPreparePciHostdevs(mgr, driver,
+                                         def->name, def->uuid,
+                                         def->hostdevs,
+                                         def->nhostdevs,
+                                         flags) < 0)
+            return -1;
+    }
+
+    if (flags & VIR_SP_USB_HOSTDEV) {
+        bool coldBoot = !!(flags & VIR_COLD_BOOT);
+        if (virHostdevPrepareUsbHostdevs(mgr, driver, def->name,
+                                         def->hostdevs, def->nhostdevs,
+                                         coldBoot) < 0)
+            return -1;
+    }
+
+    if (flags & VIR_SP_SCSI_HOSTDEV) {
+        if (virHostdevPrepareScsiHostdevs(mgr, driver, def->name,
+                                          def->hostdevs, def->nhostdevs) < 0)
+        return -1;
+    }
+
+    return 0;
+}
+
+/* @oldStateDir
+ * For upgrade purpose: see virHostdevReAttachPciHostdevs
+ */
+void
+virHostdevReAttachDomainHostdevs(virHostdevManagerPtr mgr,
+                                 const char *driver,
+                                 virDomainDefPtr def,
+                                 unsigned int flags,
+                                 char *oldStateDir)
+{
+    if (!def->nhostdevs || !mgr)
+        return;
+
+    if (flags & VIR_SP_PCI_HOSTDEV) {
+        virHostdevReAttachPciHostdevs(mgr, driver, def->name,
+                                      def->hostdevs, def->nhostdevs,
+                                      oldStateDir);
+    }
+
+    if (flags & VIR_SP_USB_HOSTDEV) {
+        virHostdevReAttachUsbHostdevs(mgr, driver, def->name,
+                                      def->hostdevs, def->nhostdevs);
+    }
+
+    if (flags & VIR_SP_SCSI_HOSTDEV) {
+        virHostdevReAttachScsiHostdevs(mgr, driver, def->name,
+                                       def->hostdevs, def->nhostdevs);
+    }
+}
+
+int
+virHostdevUpdateDomainActiveHostdevs(virHostdevManagerPtr mgr,
+                                     const char *driver,
+                                     virDomainDefPtr def,
+                                     unsigned int flags)
+{
+    if (!def->nhostdevs)
+        return 0;
+
+    if (flags & VIR_SP_PCI_HOSTDEV) {
+        if (virHostdevUpdateActivePciHostdevs(mgr,
+                                              def->hostdevs,
+                                              def->nhostdevs,
+                                              driver, def->name) < 0)
+            return -1;
+    }
+
+    if (flags & VIR_SP_USB_HOSTDEV) {
+        if (virHostdevUpdateActiveUsbHostdevs(mgr,
+                                              def->hostdevs,
+                                              def->nhostdevs,
+                                              driver, def->name) < 0)
+            return -1;
+    }
+
+    if (flags & VIR_SP_SCSI_HOSTDEV) {
+        if (virHostdevUpdateActiveScsiHostdevs(mgr,
+                                               def->hostdevs,
+                                               def->nhostdevs,
+                                               driver, def->name) < 0)
+            return -1;
+    }
+
+    return 0;
+}
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 387c160..74f1221 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -33,8 +33,12 @@
 # include "domain_conf.h"
 
 typedef enum {
-     VIR_STRICT_ACS_CHECK     = (1 << 0), /* strict acs check */
-     VIR_COLD_BOOT            = (1 << 1), /* cold boot */
+    VIR_STRICT_ACS_CHECK     = (1 << 0), /* strict acs check */
+    VIR_COLD_BOOT            = (1 << 1), /* cold boot */
+
+    VIR_SP_PCI_HOSTDEV       = (1 << 8), /* support pci passthrough */
+    VIR_SP_USB_HOSTDEV       = (1 << 9), /* support usb passthrough */
+    VIR_SP_SCSI_HOSTDEV      = (1 << 10), /* support scsi passthrough */
 } virHostdevFlag;
 
 
@@ -108,6 +112,22 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
                                    int nhostdevs,
                                    const char *drv_name,
                                    const char *dom_name);
+int
+virHostdevUpdateDomainActiveHostdevs(virHostdevManagerPtr mgr,
+                                     const char *driver,
+                                     virDomainDefPtr def,
+                                     unsigned int flags);
+int
+virHostdevPrepareDomainHostdevs(virHostdevManagerPtr mgr,
+                                const char *driver,
+                                virDomainDefPtr def,
+                                unsigned int flags);
+void
+virHostdevReAttachDomainHostdevs(virHostdevManagerPtr mgr,
+                                 const char *driver,
+                                 virDomainDefPtr def,
+                                 unsigned int flags,
+                                 char *oldStateDir);
 
 /* functions used by NodeDevDetach/Reattach/Reset */
 int virHostdevPciNodeDeviceDetach(virHostdevManagerPtr mgr,
-- 
1.6.0.2




More information about the libvir-list mailing list