mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Store the interface vlan number in the domain state
Currently, an interface's vlan number corresponds to its index in the table of network interfaces. That is no longer true when we allow devices to be removed. To fix this, we store the vlan number in the domain's state XML so that it survives libvirtd restarts. * src/domain_conf.h: add vlan number to virDomainNetDef * src/domain_conf.c: store it in XML as <state vlan='N'/>, defaulting to -1 if this is state saved by a previous version of libvirt * src/qemu_conf.c: assign vlan numbers before starting qemu
This commit is contained in:
parent
36c820e6c8
commit
30605477f2
@ -962,6 +962,7 @@ virDomainNetDefParseXML(virConnectPtr conn,
|
||||
char *internal = NULL;
|
||||
char *nic_name = NULL;
|
||||
char *hostnet_name = NULL;
|
||||
char *vlan = NULL;
|
||||
|
||||
if (VIR_ALLOC(def) < 0) {
|
||||
virReportOOMError(conn);
|
||||
@ -1031,6 +1032,7 @@ virDomainNetDefParseXML(virConnectPtr conn,
|
||||
xmlStrEqual(cur->name, BAD_CAST "state")) {
|
||||
nic_name = virXMLPropString(cur, "nic");
|
||||
hostnet_name = virXMLPropString(cur, "hostnet");
|
||||
vlan = virXMLPropString(cur, "vlan");
|
||||
}
|
||||
}
|
||||
cur = cur->next;
|
||||
@ -1046,6 +1048,13 @@ virDomainNetDefParseXML(virConnectPtr conn,
|
||||
def->hostnet_name = hostnet_name;
|
||||
nic_name = hostnet_name = NULL;
|
||||
|
||||
def->vlan = -1;
|
||||
if (vlan && virStrToLong_i(vlan, NULL, 10, &def->vlan) < 0) {
|
||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot parse <state> 'vlan' attribute"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (def->type) {
|
||||
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
||||
if (network == NULL) {
|
||||
@ -1167,6 +1176,7 @@ cleanup:
|
||||
VIR_FREE(internal);
|
||||
VIR_FREE(nic_name);
|
||||
VIR_FREE(hostnet_name);
|
||||
VIR_FREE(vlan);
|
||||
|
||||
return def;
|
||||
|
||||
@ -3624,6 +3634,8 @@ virDomainNetDefFormat(virConnectPtr conn,
|
||||
virBufferEscapeString(buf, " nic='%s'", def->nic_name);
|
||||
if (def->hostnet_name)
|
||||
virBufferEscapeString(buf, " hostnet='%s'", def->hostnet_name);
|
||||
if (def->vlan > 0)
|
||||
virBufferVSprintf(buf, " vlan='%d'", def->vlan);
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
}
|
||||
|
||||
|
@ -192,6 +192,7 @@ struct _virDomainNetDef {
|
||||
char *ifname;
|
||||
char *nic_name;
|
||||
char *hostnet_name;
|
||||
int vlan;
|
||||
};
|
||||
|
||||
enum virDomainChrSrcType {
|
||||
|
@ -1535,11 +1535,13 @@ int qemudBuildCommandLine(virConnectPtr conn,
|
||||
char *nic, *host;
|
||||
int tapfd = -1;
|
||||
|
||||
net->vlan = i;
|
||||
|
||||
if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) &&
|
||||
qemuAssignNetNames(def, net) < 0)
|
||||
goto no_memory;
|
||||
|
||||
if (qemuBuildNicStr(conn, net, NULL, ',', i, &nic) < 0)
|
||||
if (qemuBuildNicStr(conn, net, NULL, ',', net->vlan, &nic) < 0)
|
||||
goto error;
|
||||
|
||||
ADD_ARG_LIT("-net");
|
||||
@ -1565,7 +1567,8 @@ int qemudBuildCommandLine(virConnectPtr conn,
|
||||
(*tapfds)[(*ntapfds)++] = tapfd;
|
||||
}
|
||||
|
||||
if (qemuBuildHostNetStr(conn, net, NULL, ',', i, tapfd, &host) < 0)
|
||||
if (qemuBuildHostNetStr(conn, net, NULL, ',',
|
||||
net->vlan, tapfd, &host) < 0)
|
||||
goto error;
|
||||
|
||||
ADD_ARG_LIT("-net");
|
||||
|
Loading…
Reference in New Issue
Block a user