Re: [libvirt] [PATCH 1/4] qemuBuildHostNetStr: use type_sep earlier

2016-10-21 Thread Pavel Hrdina
On Fri, Oct 14, 2016 at 04:32:15PM +0200, Ján Tomko wrote:
> When hotplugging networks with ancient QEMUs not supporting
> QEMU_CAPS_NETDEV, we use space instead of a comma as the separator
> between the network type and other options.
> 
> Except for "user", all the network types pass other options
> and use up the first separator by the time we get to the section
> that adds the alias (or vlan for QEMUs without CAPS_NETDEV).
> 
> Since the alias/vlan is mandatory, convert all preceding code to add
> the separator at the end, removing the need to rewrite type_sep for
> all types but NET_TYPE_USER.
> ---

ACK

Pavel


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/4] qemuBuildHostNetStr: use type_sep earlier

2016-10-14 Thread Ján Tomko
When hotplugging networks with ancient QEMUs not supporting
QEMU_CAPS_NETDEV, we use space instead of a comma as the separator
between the network type and other options.

Except for "user", all the network types pass other options
and use up the first separator by the time we get to the section
that adds the alias (or vlan for QEMUs without CAPS_NETDEV).

Since the alias/vlan is mandatory, convert all preceding code to add
the separator at the end, removing the need to rewrite type_sep for
all types but NET_TYPE_USER.
---
 src/qemu/qemu_command.c | 28 +++-
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 21fd85c..eba7ba9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3674,7 +3674,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
 /* for one tapfd 'fd=' shall be used,
  * for more than one 'fds=' is the right choice */
 if (tapfdSize == 1) {
-virBufferAsprintf(, "fd=%s", tapfd[0]);
+virBufferAsprintf(, "fd=%s,", tapfd[0]);
 } else {
 virBufferAddLit(, "fds=");
 for (i = 0; i < tapfdSize; i++) {
@@ -3682,49 +3682,45 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
 virBufferAddChar(, ':');
 virBufferAdd(, tapfd[i], -1);
 }
+virBufferAddChar(, ',');
 }
-type_sep = ',';
 is_tap = true;
 break;
 
 case VIR_DOMAIN_NET_TYPE_CLIENT:
-virBufferAsprintf(, "socket%cconnect=%s:%d",
+virBufferAsprintf(, "socket%cconnect=%s:%d,",
   type_sep,
   net->data.socket.address,
   net->data.socket.port);
-type_sep = ',';
 break;
 
 case VIR_DOMAIN_NET_TYPE_SERVER:
-virBufferAsprintf(, "socket%clisten=%s:%d",
+virBufferAsprintf(, "socket%clisten=%s:%d,",
   type_sep,
   net->data.socket.address ? net->data.socket.address
   : "",
   net->data.socket.port);
-type_sep = ',';
 break;
 
 case VIR_DOMAIN_NET_TYPE_MCAST:
-virBufferAsprintf(, "socket%cmcast=%s:%d",
+virBufferAsprintf(, "socket%cmcast=%s:%d,",
   type_sep,
   net->data.socket.address,
   net->data.socket.port);
-type_sep = ',';
 break;
 
 case VIR_DOMAIN_NET_TYPE_UDP:
-virBufferAsprintf(, "socket%cudp=%s:%d,localaddr=%s:%d",
+virBufferAsprintf(, "socket%cudp=%s:%d,localaddr=%s:%d,",
   type_sep,
   net->data.socket.address,
   net->data.socket.port,
   net->data.socket.localaddr,
   net->data.socket.localport);
-type_sep = ',';
 break;
 
 case VIR_DOMAIN_NET_TYPE_USER:
 case VIR_DOMAIN_NET_TYPE_INTERNAL:
-virBufferAddLit(, "user");
+virBufferAsprintf(, "user%c", type_sep);
 break;
 
 case VIR_DOMAIN_NET_TYPE_HOSTDEV:
@@ -3733,12 +3729,11 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
 return NULL;
 
 case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
-virBufferAsprintf(, "vhost-user%cchardev=char%s",
+virBufferAsprintf(, "vhost-user%cchardev=char%s,",
   type_sep,
   net->info.alias);
-type_sep = ',';
 if (net->driver.virtio.queues > 1)
-virBufferAsprintf(, ",queues=%u",
+virBufferAsprintf(, "queues=%u,",
   net->driver.virtio.queues);
 break;
 
@@ -3747,13 +3742,12 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
 }
 
 if (vlan >= 0) {
-virBufferAsprintf(, "%cvlan=%d", type_sep, vlan);
+virBufferAsprintf(, "vlan=%d", vlan);
 if (net->info.alias)
 virBufferAsprintf(, ",name=host%s",
   net->info.alias);
 } else {
-virBufferAsprintf(, "%cid=host%s",
-  type_sep, net->info.alias);
+virBufferAsprintf(, "id=host%s", net->info.alias);
 }
 
 if (is_tap) {
-- 
2.7.3

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