[PATCH 13/15] Hostdev-hybrid qemu driver implementation

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

 



---
 src/qemu/qemu_command.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_hotplug.c |   23 ++++++++++++++++--
 src/qemu/qemu_process.c |    3 +-
 3 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bb66364..d67394e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -27,6 +27,7 @@
 #include "qemu_hostdev.h"
 #include "qemu_capabilities.h"
 #include "qemu_bridge_filter.h"
+#include "qemu_hostdev.h"
 #include "cpu/cpu.h"
 #include "memory.h"
 #include "logging.h"
@@ -4330,10 +4331,16 @@ qemuBuildCommandLine(virConnectPtr conn,
     bool emitBootindex = false;
     int usbcontroller = 0;
     bool usblegacy = false;
+
+    virDomainObjPtr vm = NULL;
+    virDomainObjListPtr doms = &driver->domains;
+
     uname_normalize(&ut);
 
     virUUIDFormat(def->uuid, uuid);
 
+    vm = virHashLookup(doms->objs, uuid);
+
     emulator = def->emulator;
 
     /*
@@ -5257,6 +5264,58 @@ qemuBuildCommandLine(virConnectPtr conn,
                 continue;
             }
 
+           if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV_HYBRID) {
+                virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+                virDomainHostdevDefPtr found;
+                if (vmop == VIR_NETDEV_VPORT_PROFILE_OP_CREATE) {
+                    if (qemuAssignDeviceHostdevAlias(def,
+                                                     hostdev,
+                                                     (def->nhostdevs-1)) < 0) {
+                        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                       _("Could not assign alias to Net Hostdev"));
+                        goto error;
+                    }
+                    
+                    if (virDomainHostdevFind(def,
+                                             hostdev,
+                                             &found) < 0) {
+                        qemuDomainObjPrivatePtr priv = vm->privateData;
+                        if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs,
+                                                           hostdev->info) < 0) {
+                            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                           _("Could not assign PCI addr to Hostdev hybrid"));
+                            goto error;
+                        }
+                        
+                        if (virDomainHostdevInsert(def, 
+                                                  hostdev) < 0) {
+                            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                           _("Hostdev not inserted into the array"));
+                            goto error;
+                        }
+                        
+                        if (qemuPrepareHostdevPCIDevices(driver, def->name,
+                                                         def->uuid, &hostdev, 1) < 0) {
+                            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                           _("Prepare Hostdev PCI Devices failed"));
+                            goto error;
+                        }
+                    }
+                }
+                
+                int tapfd = qemuPhysIfaceConnect(def, driver, net,
+                                                 qemuCaps, vmop);
+                if (tapfd < 0)
+                    goto error;
+
+                last_good_net = i;
+                virCommandTransferFD(cmd, tapfd);
+
+                if (snprintf(tapfd_name, sizeof(tapfd_name), "%d",
+                             tapfd) >= sizeof(tapfd_name))
+                    goto no_memory;
+            } 
+
             if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
                 actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
                 /*
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0fd506e..3586d3e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -694,6 +694,21 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
         goto cleanup;
     }
 
+    if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV_HYBRID) {
+        ret = qemuDomainAttachHostDevice(driver, vm,
+                                         virDomainNetGetActualHostdev(net));
+        if (ret < 0)
+            goto cleanup;
+        
+        if ((tapfd = qemuPhysIfaceConnect(vm->def, driver, net,
+                                          priv->qemuCaps,
+                                          VIR_NETDEV_VPORT_PROFILE_OP_CREATE)) < 0)
+            goto cleanup;
+        iface_connected = true;
+        if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
+            goto cleanup;
+    }
+
     if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
         actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
         /*
@@ -2198,7 +2213,8 @@ qemuDomainDetachNetDevice(struct qemud_driver *driver,
         goto cleanup;
     }
 
-    if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+    if ((virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_HOSTDEV) ||
+        (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_HOSTDEV_HYBRID)) { 
         ret = qemuDomainDetachThisHostDevice(driver, vm,
                                              virDomainNetGetActualHostdev(detach),
                                              -1);
@@ -2270,8 +2286,9 @@ qemuDomainDetachNetDevice(struct qemud_driver *driver,
         VIR_WARN("Unable to release PCI address on NIC");
 
     virDomainConfNWFilterTeardown(detach);
-
-    if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_DIRECT) {
+    
+    if ((virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_DIRECT) ||
+        (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_HOSTDEV_HYBRID)) {
         ignore_value(virNetDevMacVLanDeleteWithVPortProfile(
                          detach->ifname, &detach->mac,
                          virDomainNetGetActualDirectDev(detach),
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index df4a016..9f9a5d2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4098,7 +4098,8 @@ void qemuProcessStop(struct qemud_driver *driver,
     def = vm->def;
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
-        if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
+        if ((virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) ||
+            (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV_HYBRID)) {
             ignore_value(virNetDevMacVLanDeleteWithVPortProfile(
                              net->ifname, &net->mac,
                              virDomainNetGetActualDirectDev(net),
-- 
1.7.4.4


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]