[libvirt] [PATCH 2/7] Make qemuBuildHostNetStr() take tapfd as a string

Mark McLoughlin markmc at redhat.com
Wed Jul 22 21:57:31 UTC 2009


With hotplug, we're going to want to pass a tapfd name rather than an
actual file descriptor, so prepare the way by passing a string tapfd to
qemuBuildHostNetStr().

* src/qemu_conf.h: qemuBuildHostNetStr() takes a string tapfd now

* src/qemu_conf.c: pass qemuBuildHostNetStr() a string rather than an
  actual file descriptor

* src/qemu_driver.c: update qemudDomainAttachNetDevice() for change
---
 src/qemu_conf.c   |   17 ++++++++++++-----
 src/qemu_conf.h   |    2 +-
 src/qemu_driver.c |    2 +-
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index ed77153..e875435 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -910,13 +910,13 @@ qemuBuildHostNetStr(virConnectPtr conn,
                     const char *prefix,
                     char type_sep,
                     int vlan,
-                    int tapfd,
+                    const char *tapfd,
                     char **str)
 {
     switch (net->type) {
     case VIR_DOMAIN_NET_TYPE_NETWORK:
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
-        if (virAsprintf(str, "%stap%cfd=%d,vlan=%d%s%s",
+        if (virAsprintf(str, "%stap%cfd=%s,vlan=%d%s%s",
                         prefix ? prefix : "",
                         type_sep, tapfd, vlan,
                         (net->hostnet_name ? ",name=" : ""),
@@ -1534,7 +1534,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
         for (i = 0 ; i < def->nnets ; i++) {
             virDomainNetDefPtr net = def->nets[i];
             char *nic, *host;
-            int tapfd = -1;
+            char *tapfd_name = NULL;
 
             net->vlan = i;
 
@@ -1550,7 +1550,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
 
             if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
                 net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
-                tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags);
+                int tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags);
                 if (tapfd < 0)
                     goto error;
 
@@ -1560,14 +1560,21 @@ int qemudBuildCommandLine(virConnectPtr conn,
                 }
 
                 (*tapfds)[(*ntapfds)++] = tapfd;
+
+                if (virAsprintf(&tapfd_name, "%d", tapfd) < 0)
+                    goto no_memory;
             }
 
             if (qemuBuildHostNetStr(conn, net, NULL, ',',
-                                    net->vlan, tapfd, &host) < 0)
+                                    net->vlan, tapfd_name, &host) < 0) {
+                VIR_FREE(tapfd_name);
                 goto error;
+            }
 
             ADD_ARG_LIT("-net");
             ADD_ARG(host);
+
+            VIR_FREE(tapfd_name);
         }
     }
 
diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index 8ad5f94..8150a54 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -150,7 +150,7 @@ int         qemuBuildHostNetStr         (virConnectPtr conn,
                                          const char *prefix,
                                          char type_sep,
                                          int vlan,
-                                         int tapfd,
+                                         const char *tapfd,
                                          char **str);
 
 int         qemuBuildNicStr             (virConnectPtr conn,
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index c4683ae..7f4e2a1 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -4587,7 +4587,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
             net->vlan = vm->def->nets[i]->vlan;
 
     if (qemuBuildHostNetStr(conn, net,
-                            "host_net_add ", ' ', net->vlan, -1, &cmd) < 0)
+                            "host_net_add ", ' ', net->vlan, NULL, &cmd) < 0)
         return -1;
 
     remove_cmd = NULL;
-- 
1.6.2.5




More information about the libvir-list mailing list