mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 07:36:19 +00:00
qemuBuildHostNetStr: use type_sep earlier
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.
This commit is contained in:
parent
bdaf5e8098
commit
c70c56ded0
@ -3674,7 +3674,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
|||||||
/* for one tapfd 'fd=' shall be used,
|
/* for one tapfd 'fd=' shall be used,
|
||||||
* for more than one 'fds=' is the right choice */
|
* for more than one 'fds=' is the right choice */
|
||||||
if (tapfdSize == 1) {
|
if (tapfdSize == 1) {
|
||||||
virBufferAsprintf(&buf, "fd=%s", tapfd[0]);
|
virBufferAsprintf(&buf, "fd=%s,", tapfd[0]);
|
||||||
} else {
|
} else {
|
||||||
virBufferAddLit(&buf, "fds=");
|
virBufferAddLit(&buf, "fds=");
|
||||||
for (i = 0; i < tapfdSize; i++) {
|
for (i = 0; i < tapfdSize; i++) {
|
||||||
@ -3682,49 +3682,45 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
|||||||
virBufferAddChar(&buf, ':');
|
virBufferAddChar(&buf, ':');
|
||||||
virBufferAdd(&buf, tapfd[i], -1);
|
virBufferAdd(&buf, tapfd[i], -1);
|
||||||
}
|
}
|
||||||
|
virBufferAddChar(&buf, ',');
|
||||||
}
|
}
|
||||||
type_sep = ',';
|
|
||||||
is_tap = true;
|
is_tap = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
||||||
virBufferAsprintf(&buf, "socket%cconnect=%s:%d",
|
virBufferAsprintf(&buf, "socket%cconnect=%s:%d,",
|
||||||
type_sep,
|
type_sep,
|
||||||
net->data.socket.address,
|
net->data.socket.address,
|
||||||
net->data.socket.port);
|
net->data.socket.port);
|
||||||
type_sep = ',';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_SERVER:
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
||||||
virBufferAsprintf(&buf, "socket%clisten=%s:%d",
|
virBufferAsprintf(&buf, "socket%clisten=%s:%d,",
|
||||||
type_sep,
|
type_sep,
|
||||||
net->data.socket.address ? net->data.socket.address
|
net->data.socket.address ? net->data.socket.address
|
||||||
: "",
|
: "",
|
||||||
net->data.socket.port);
|
net->data.socket.port);
|
||||||
type_sep = ',';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_MCAST:
|
case VIR_DOMAIN_NET_TYPE_MCAST:
|
||||||
virBufferAsprintf(&buf, "socket%cmcast=%s:%d",
|
virBufferAsprintf(&buf, "socket%cmcast=%s:%d,",
|
||||||
type_sep,
|
type_sep,
|
||||||
net->data.socket.address,
|
net->data.socket.address,
|
||||||
net->data.socket.port);
|
net->data.socket.port);
|
||||||
type_sep = ',';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_UDP:
|
case VIR_DOMAIN_NET_TYPE_UDP:
|
||||||
virBufferAsprintf(&buf, "socket%cudp=%s:%d,localaddr=%s:%d",
|
virBufferAsprintf(&buf, "socket%cudp=%s:%d,localaddr=%s:%d,",
|
||||||
type_sep,
|
type_sep,
|
||||||
net->data.socket.address,
|
net->data.socket.address,
|
||||||
net->data.socket.port,
|
net->data.socket.port,
|
||||||
net->data.socket.localaddr,
|
net->data.socket.localaddr,
|
||||||
net->data.socket.localport);
|
net->data.socket.localport);
|
||||||
type_sep = ',';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_USER:
|
case VIR_DOMAIN_NET_TYPE_USER:
|
||||||
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
||||||
virBufferAddLit(&buf, "user");
|
virBufferAsprintf(&buf, "user%c", type_sep);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
||||||
@ -3733,12 +3729,11 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
||||||
virBufferAsprintf(&buf, "vhost-user%cchardev=char%s",
|
virBufferAsprintf(&buf, "vhost-user%cchardev=char%s,",
|
||||||
type_sep,
|
type_sep,
|
||||||
net->info.alias);
|
net->info.alias);
|
||||||
type_sep = ',';
|
|
||||||
if (net->driver.virtio.queues > 1)
|
if (net->driver.virtio.queues > 1)
|
||||||
virBufferAsprintf(&buf, ",queues=%u",
|
virBufferAsprintf(&buf, "queues=%u,",
|
||||||
net->driver.virtio.queues);
|
net->driver.virtio.queues);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3747,13 +3742,12 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vlan >= 0) {
|
if (vlan >= 0) {
|
||||||
virBufferAsprintf(&buf, "%cvlan=%d", type_sep, vlan);
|
virBufferAsprintf(&buf, "vlan=%d", vlan);
|
||||||
if (net->info.alias)
|
if (net->info.alias)
|
||||||
virBufferAsprintf(&buf, ",name=host%s",
|
virBufferAsprintf(&buf, ",name=host%s",
|
||||||
net->info.alias);
|
net->info.alias);
|
||||||
} else {
|
} else {
|
||||||
virBufferAsprintf(&buf, "%cid=host%s",
|
virBufferAsprintf(&buf, "id=host%s", net->info.alias);
|
||||||
type_sep, net->info.alias);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_tap) {
|
if (is_tap) {
|
||||||
|
Loading…
Reference in New Issue
Block a user