]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Store the interface vlan number in the domain state
authorMark McLoughlin <markmc@redhat.com>
Fri, 17 Jul 2009 21:08:34 +0000 (22:08 +0100)
committerMark McLoughlin <markmc@redhat.com>
Wed, 22 Jul 2009 10:34:06 +0000 (11:34 +0100)
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

src/domain_conf.c
src/domain_conf.h
src/qemu_conf.c

index 2750c88a25392e611be8b84f2439775f2ecf87c2..0fd6cc8e75629bc8fd87bccb7dd4b22c96a714a3 100644 (file)
@@ -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");
     }
 
index a274efe17e26567dad49171d979c61a0fcd6d8f0..2836b013f12127f6d73c9bddf68be00462192d97 100644 (file)
@@ -192,6 +192,7 @@ struct _virDomainNetDef {
     char *ifname;
     char *nic_name;
     char *hostnet_name;
+    int vlan;
 };
 
 enum virDomainChrSrcType {
index 0362d765dfe6ab66d0f038d9736a2e1e96a753f5..6d876cb5a394adecace1312ad0fa7d0ae01e2557 100644 (file)
@@ -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");