]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move qemuPhysIfaceConnect to qemu_interface.c and rename
authorJohn Ferlan <jferlan@redhat.com>
Mon, 15 Feb 2016 15:26:40 +0000 (10:26 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 16 Feb 2016 16:07:47 +0000 (11:07 -0500)
Move the misplaced function from qemu_command.c to qemu_interface.c
since it's closer in functionality there and had less to do with building
the command line.

Rename function to qemuInterfaceDirectConnect and modify callers.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_command.h
src/qemu/qemu_hotplug.c
src/qemu/qemu_interface.c
src/qemu/qemu_interface.h

index 17baf76d0197b4322de8e3d50c5f957b461dfeea..4b461f2197682359b34f14afd688a310317b51c1 100644 (file)
@@ -26,6 +26,7 @@
 #include "qemu_command.h"
 #include "qemu_hostdev.h"
 #include "qemu_capabilities.h"
+#include "qemu_interface.h"
 #include "cpu/cpu.h"
 #include "dirname.h"
 #include "passfd.h"
@@ -153,60 +154,6 @@ VIR_ENUM_IMPL(qemuNumaPolicy, VIR_DOMAIN_NUMATUNE_MEM_LAST,
               "preferred",
               "interleave");
 
-/**
- * qemuPhysIfaceConnect:
- * @def: the definition of the VM (needed by 802.1Qbh and audit)
- * @driver: pointer to the driver instance
- * @net: pointer to the VM's interface description with direct device type
- * @tapfd: array of file descriptor return value for the new device
- * @tapfdSize: number of file descriptors in @tapfd
- * @vmop: VM operation type
- *
- * Returns 0 on success or -1 in case of error.
- */
-int
-qemuPhysIfaceConnect(virDomainDefPtr def,
-                     virQEMUDriverPtr driver,
-                     virDomainNetDefPtr net,
-                     int *tapfd,
-                     size_t tapfdSize,
-                     virNetDevVPortProfileOp vmop)
-{
-    int ret = -1;
-    char *res_ifname = NULL;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
-
-    if (net->model && STREQ(net->model, "virtio"))
-        macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR;
-
-    if (virNetDevMacVLanCreateWithVPortProfile(net->ifname,
-                                               &net->mac,
-                                               virDomainNetGetActualDirectDev(net),
-                                               virDomainNetGetActualDirectMode(net),
-                                               def->uuid,
-                                               virDomainNetGetActualVirtPortProfile(net),
-                                               &res_ifname,
-                                               vmop, cfg->stateDir,
-                                               tapfd, tapfdSize,
-                                               macvlan_create_flags) < 0)
-        goto cleanup;
-
-    virDomainAuditNetDevice(def, net, res_ifname, true);
-    VIR_FREE(net->ifname);
-    net->ifname = res_ifname;
-    ret = 0;
-
- cleanup:
-    if (ret < 0) {
-        while (tapfdSize--)
-            VIR_FORCE_CLOSE(tapfd[tapfdSize]);
-    }
-    virObjectUnref(cfg);
-    return ret;
-}
-
-
 /**
  * qemuCreateInBridgePortWithHelper:
  * @cfg: the configuration object in which the helper name is looked up
@@ -8492,7 +8439,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
 
         memset(tapfd, -1, tapfdSize * sizeof(tapfd[0]));
 
-        if (qemuPhysIfaceConnect(def, driver, net, tapfd, tapfdSize, vmop) < 0)
+        if (qemuInterfaceDirectConnect(def, driver, net,
+                                       tapfd, tapfdSize, vmop) < 0)
             goto cleanup;
     }
 
index f549aa5390ce82da7e38af3afe63ca68cbc72334..2201c279cbd0515ef71e3e4ec3418f82cfbf42ca 100644 (file)
@@ -230,13 +230,6 @@ int qemuNetworkIfaceConnect(virDomainDefPtr def,
                             size_t *tapfdSize)
     ATTRIBUTE_NONNULL(2);
 
-int qemuPhysIfaceConnect(virDomainDefPtr def,
-                         virQEMUDriverPtr driver,
-                         virDomainNetDefPtr net,
-                         int *tapfd,
-                         size_t tapfdSize,
-                         virNetDevVPortProfileOp vmop);
-
 int qemuOpenVhostNet(virDomainDefPtr def,
                      virDomainNetDefPtr net,
                      virQEMUCapsPtr qemuCaps,
index afa99f125d5f4806cc00b7cf55ae502deb97d317..84421552416dcb97a7c633c09e4a0b654e16bba3 100644 (file)
@@ -938,8 +938,9 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
         if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0)
             goto cleanup;
         memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize);
-        if (qemuPhysIfaceConnect(vm->def, driver, net, tapfd, tapfdSize,
-                                 VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0)
+        if (qemuInterfaceDirectConnect(vm->def, driver, net,
+                                       tapfd, tapfdSize,
+                                       VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0)
             goto cleanup;
         iface_connected = true;
         if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0)
index 4d55e4dfd7b3364958b299399da4b2db027d785a..d3a1abc5781a06e028ecae5a6af2ef253879f0f3 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * qemu_interface.c: QEMU interface management
  *
+ * Copyright (C) 2015-2016 Red Hat, Inc.
  * Copyright IBM Corp. 2014
  *
  * This library is free software; you can redistribute it and/or
@@ -24,7 +25,9 @@
 #include <config.h>
 
 #include "network_conf.h"
+#include "domain_audit.h"
 #include "qemu_interface.h"
+#include "viralloc.h"
 #include "virnetdev.h"
 #include "virnetdevtap.h"
 #include "virnetdevmacvlan.h"
@@ -219,3 +222,57 @@ qemuInterfaceStopDevices(virDomainDefPtr def)
     }
     return 0;
 }
+
+
+/**
+ * qemuInterfaceDirectConnect:
+ * @def: the definition of the VM (needed by 802.1Qbh and audit)
+ * @driver: pointer to the driver instance
+ * @net: pointer to the VM's interface description with direct device type
+ * @tapfd: array of file descriptor return value for the new device
+ * @tapfdSize: number of file descriptors in @tapfd
+ * @vmop: VM operation type
+ *
+ * Returns 0 on success or -1 in case of error.
+ */
+int
+qemuInterfaceDirectConnect(virDomainDefPtr def,
+                           virQEMUDriverPtr driver,
+                           virDomainNetDefPtr net,
+                           int *tapfd,
+                           size_t tapfdSize,
+                           virNetDevVPortProfileOp vmop)
+{
+    int ret = -1;
+    char *res_ifname = NULL;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
+
+    if (net->model && STREQ(net->model, "virtio"))
+        macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR;
+
+    if (virNetDevMacVLanCreateWithVPortProfile(net->ifname,
+                                               &net->mac,
+                                               virDomainNetGetActualDirectDev(net),
+                                               virDomainNetGetActualDirectMode(net),
+                                               def->uuid,
+                                               virDomainNetGetActualVirtPortProfile(net),
+                                               &res_ifname,
+                                               vmop, cfg->stateDir,
+                                               tapfd, tapfdSize,
+                                               macvlan_create_flags) < 0)
+        goto cleanup;
+
+    virDomainAuditNetDevice(def, net, res_ifname, true);
+    VIR_FREE(net->ifname);
+    net->ifname = res_ifname;
+    ret = 0;
+
+ cleanup:
+    if (ret < 0) {
+        while (tapfdSize--)
+            VIR_FORCE_CLOSE(tapfd[tapfdSize]);
+    }
+    virObjectUnref(cfg);
+    return ret;
+}
index b4c1efcb084c50643e51742aa1283fb49d291899..48a8e96bde231cbd0716554cc2eb9fed1984d937 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * qemu_interface.h: QEMU interface management
  *
+ * Copyright (C) 2014, 2016 Red Hat, Inc.
  * Copyright IBM Corp. 2014
  *
  * This library is free software; you can redistribute it and/or
 # define __QEMU_INTERFACE_H__
 
 # include "domain_conf.h"
+# include "qemu_conf.h"
 
 int qemuInterfaceStartDevice(virDomainNetDefPtr net);
 int qemuInterfaceStartDevices(virDomainDefPtr def);
 int qemuInterfaceStopDevice(virDomainNetDefPtr net);
 int qemuInterfaceStopDevices(virDomainDefPtr def);
 
+int qemuInterfaceDirectConnect(virDomainDefPtr def,
+                                virQEMUDriverPtr driver,
+                                virDomainNetDefPtr net,
+                                int *tapfd,
+                                size_t tapfdSize,
+                                virNetDevVPortProfileOp vmop);
+
 #endif /* __QEMU_INTERFACE_H__ */