[PATCH 05/21] qemuBuildChannelChrDeviceStr: Remove formatting of properties for -netdev

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

 



The output of the function is fed as argument to '-device' command line
argument or 'device_add' monitor command except for 'guestfwd' channels
where it needs to be fed to -netdev/netdev_add. This is confusing and
error prone. Split it up since the caller needs to know which
command/option to use anyways, so the caller can call the appropriate
function without any magic.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 36 ++++++++++++++++++++----------------
 src/qemu/qemu_command.h |  3 +++
 src/qemu/qemu_hotplug.c | 18 +++++++++++++-----
 3 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 56b4aae1dd..c20176f619 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8536,7 +8536,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,

         switch ((virDomainChrChannelTargetType) channel->targetType) {
         case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
-            if (qemuBuildChrDeviceStr(&netdevstr, def, channel, qemuCaps) < 0)
+            if (!(netdevstr = qemuBuildChannelGuestfwdNetdevProps(channel)))
                 return -1;
             virCommandAddArgList(cmd, "-netdev", netdevstr, NULL);
             break;
@@ -9804,36 +9804,40 @@ qemuBuildParallelChrDeviceStr(char **deviceStr,
     return 0;
 }

-static int
-qemuBuildChannelChrDeviceStr(char **deviceStr,
-                             const virDomainDef *def,
-                             virDomainChrDefPtr chr)
+
+char *
+qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr)
 {
-    int ret = -1;
     g_autofree char *addr = NULL;
     int port;

-    switch ((virDomainChrChannelTargetType)chr->targetType) {
-    case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
+    if (!(addr = virSocketAddrFormat(chr->target.addr)))
+        return NULL;

-        addr = virSocketAddrFormat(chr->target.addr);
-        if (!addr)
-            return ret;
-        port = virSocketAddrGetPort(chr->target.addr);
+    port = virSocketAddrGetPort(chr->target.addr);
+
+    return g_strdup_printf("user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s",
+                           addr, port, chr->info.alias, chr->info.alias);
+}

-        *deviceStr = g_strdup_printf("user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s",
-                                     addr, port, chr->info.alias, chr->info.alias);
-        break;

+static int
+qemuBuildChannelChrDeviceStr(char **deviceStr,
+                             const virDomainDef *def,
+                             virDomainChrDefPtr chr)
+{
+    switch ((virDomainChrChannelTargetType)chr->targetType) {
     case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
         if (!(*deviceStr = qemuBuildVirtioSerialPortDevStr(def, chr)))
             return -1;
         break;

+    case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
+        /* guestfwd is as a netdev handled separately */
     case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN:
     case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE:
     case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST:
-        return ret;
+        return -1;
     }

     return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 53e05777e7..7665b68548 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -86,6 +86,9 @@ qemuBuildChrDeviceStr(char **deviceStr,
                       virDomainChrDefPtr chr,
                       virQEMUCapsPtr qemuCaps);

+char *
+qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr);
+
 char *qemuBuildHostNetStr(virDomainNetDefPtr net,
                           char **tapfd,
                           size_t tapfdSize,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ab5a7aef84..2976ba7647 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2108,6 +2108,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
     virErrorPtr orig_err;
     virDomainDefPtr vmdef = vm->def;
     g_autofree char *devstr = NULL;
+    g_autofree char *netdevstr = NULL;
     virDomainChrSourceDefPtr dev = chr->source;
     g_autofree char *charAlias = NULL;
     bool chardevAttached = false;
@@ -2146,8 +2147,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
         goto cleanup;
     teardowncgroup = true;

-    if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
-        goto cleanup;
+    if (guestfwd) {
+        if (!(netdevstr = qemuBuildChannelGuestfwdNetdevProps(chr)))
+            goto cleanup;
+    } else {
+        if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
+            goto cleanup;
+    }

     if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
         goto cleanup;
@@ -2166,11 +2172,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
         goto exit_monitor;
     chardevAttached = true;

-    if (guestfwd) {
-        if (qemuMonitorAddNetdev(priv->mon, devstr,
+    if (netdevstr) {
+        if (qemuMonitorAddNetdev(priv->mon, netdevstr,
                                  NULL, NULL, 0, NULL, NULL, 0, -1, NULL) < 0)
             goto exit_monitor;
-    } else {
+    }
+
+    if (devstr) {
         if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
             goto exit_monitor;
     }
-- 
2.26.2




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

  Powered by Linux