[libvirt] [PATCH 23/27] Add API for issuing 'host_net_add' monitor command

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

 



* src/qemu/qemu_conf.h, src/qemu/qemu_conf.c: Remove prefix arg
  from qemuBuildHostNetStr which is no longer required
* src/qemu/qemu_driver.c: Refactor to use qemuMonitorAddHostNetwork()
  API for adding host network
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add new
  qemuMonitorAddHostNetwork() method for adding host networks
---
 src/qemu/qemu_conf.c         |   14 ++++----------
 src/qemu/qemu_conf.h         |    1 -
 src/qemu/qemu_driver.c       |   16 ++++++----------
 src/qemu/qemu_monitor_text.c |   30 ++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_text.h |    7 +++++++
 5 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index c531454..1d98637 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1287,7 +1287,6 @@ qemuBuildNicStr(virConnectPtr conn,
 int
 qemuBuildHostNetStr(virConnectPtr conn,
                     virDomainNetDefPtr net,
-                    const char *prefix,
                     char type_sep,
                     int vlan,
                     const char *tapfd,
@@ -1296,8 +1295,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
     switch (net->type) {
     case VIR_DOMAIN_NET_TYPE_NETWORK:
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
-        if (virAsprintf(str, "%stap%cfd=%s,vlan=%d%s%s",
-                        prefix ? prefix : "",
+        if (virAsprintf(str, "tap%cfd=%s,vlan=%d%s%s",
                         type_sep, tapfd, vlan,
                         (net->hostnet_name ? ",name=" : ""),
                         (net->hostnet_name ? net->hostnet_name : "")) < 0) {
@@ -1310,8 +1308,6 @@ qemuBuildHostNetStr(virConnectPtr conn,
         {
             virBuffer buf = VIR_BUFFER_INITIALIZER;
 
-            if (prefix)
-                virBufferAdd(&buf, prefix, strlen(prefix));
             virBufferAddLit(&buf, "tap");
             if (net->ifname) {
                 virBufferVSprintf(&buf, "%cifname=%s", type_sep, net->ifname);
@@ -1355,8 +1351,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
                 break;
             }
 
-            if (virAsprintf(str, "%ssocket%c%s=%s:%d,vlan=%d%s%s",
-                            prefix ? prefix : "",
+            if (virAsprintf(str, "socket%c%s=%s:%d,vlan=%d%s%s",
                             type_sep, mode,
                             net->data.socket.address,
                             net->data.socket.port,
@@ -1371,8 +1366,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
 
     case VIR_DOMAIN_NET_TYPE_USER:
     default:
-        if (virAsprintf(str, "%suser%cvlan=%d%s%s",
-                        prefix ? prefix : "",
+        if (virAsprintf(str, "user%cvlan=%d%s%s",
                         type_sep, vlan,
                         (net->hostnet_name ? ",name=" : ""),
                         (net->hostnet_name ? net->hostnet_name : "")) < 0) {
@@ -2014,7 +2008,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
                     goto no_memory;
             }
 
-            if (qemuBuildHostNetStr(conn, net, NULL, ',',
+            if (qemuBuildHostNetStr(conn, net, ',',
                                     net->vlan, tapfd_name, &host) < 0) {
                 VIR_FREE(tapfd_name);
                 goto error;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 6ff5f0d..96b7c0c 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -170,7 +170,6 @@ int         qemudBuildCommandLine       (virConnectPtr conn,
 
 int         qemuBuildHostNetStr         (virConnectPtr conn,
                                          virDomainNetDefPtr net,
-                                         const char *prefix,
                                          char type_sep,
                                          int vlan,
                                          const char *tapfd,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6363edc..dfd5359 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4556,6 +4556,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
     char *tapfd_name = NULL;
     int i, tapfd = -1;
     char *nicstr = NULL;
+    char *netstr = NULL;
 
     if (!(qemuCmdFlags & QEMUD_CMD_FLAG_HOST_NET_ADD)) {
         qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s",
@@ -4600,8 +4601,8 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
             goto cleanup;
     }
 
-    if (qemuBuildHostNetStr(conn, net, "host_net_add ", ' ',
-                            net->vlan, tapfd_name, &cmd) < 0)
+    if (qemuBuildHostNetStr(conn, net, ' ',
+                            net->vlan, tapfd_name, &netstr) < 0)
         goto try_tapfd_close;
 
     remove_cmd = NULL;
@@ -4612,16 +4613,9 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
         goto try_tapfd_close;
     }
 
-    if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
-        qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
-                         _("failed to add network backend with '%s'"), cmd);
+    if (qemuMonitorAddHostNetwork(vm, netstr) < 0)
         goto try_tapfd_close;
-    }
-
-    DEBUG("%s: host_net_add reply: %s", vm->def->name, reply);
 
-    VIR_FREE(reply);
-    VIR_FREE(cmd);
     VIR_FREE(tapfd_name);
     if (tapfd != -1)
         close(tapfd);
@@ -4636,6 +4630,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
                                  &net->pci_addr.slot) < 0)
         goto try_remove;
 
+    VIR_FREE(netstr);
     VIR_FREE(nicstr);
     VIR_FREE(remove_cmd);
 
@@ -4667,6 +4662,7 @@ no_memory:
     virReportOOMError(conn);
 cleanup:
     VIR_FREE(nicstr);
+    VIR_FREE(netstr);
     VIR_FREE(cmd);
     VIR_FREE(reply);
     VIR_FREE(remove_cmd);
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index c6ffd33..5bff427 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1665,3 +1665,33 @@ cleanup:
     return ret;
 }
 
+
+int qemuMonitorAddHostNetwork(const virDomainObjPtr vm,
+                              const char *netstr)
+{
+    char *cmd;
+    char *reply = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&cmd, "host_net_add %s", netstr) < 0) {
+        virReportOOMError(NULL);
+        return -1;
+    }
+
+    if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+                         _("failed to close fd in qemu with '%s'"), cmd);
+        goto cleanup;
+    }
+
+    DEBUG("%s: host_net_add reply: %s", vm->def->name, reply);
+
+    /* XXX error messages here ? */
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(cmd);
+    VIR_FREE(reply);
+    return ret;
+}
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index 1bd9d6d..d97baaf 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -192,4 +192,11 @@ int qemuMonitorSendFileHandle(const virDomainObjPtr vm,
 int qemuMonitorCloseFileHandle(const virDomainObjPtr vm,
                                const char *fdname);
 
+
+/* XXX do we relaly want to hardcode 'netstr' as the
+ * sendable item here
+ */
+int qemuMonitorAddHostNetwork(const virDomainObjPtr vm,
+                              const char *netstr);
+
 #endif /* QEMU_MONITOR_TEXT_H */
-- 
1.6.2.5

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