[libvirt] [PATCH 07/14] Add NIC and hostnet names to domain state XML

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

 



The qemu driver needs to assign and keep track of identifiers for
network devices so that it can remove them. We need to keep this state
across libvirtd restarts, but it's not configuration that needs to
be kept across guest restarts.

* src/domain_conf.c: parse and format <state nic="foo" hostnet="bar"/>
---
 src/domain_conf.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index a5e4697..2b4fe90 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -952,6 +952,8 @@ virDomainNetDefParseXML(virConnectPtr conn,
     char *port = NULL;
     char *model = NULL;
     char *internal = NULL;
+    char *nic_name = NULL;
+    char *hostnet_name = NULL;
 
     if (VIR_ALLOC(def) < 0) {
         virReportOOMError(conn);
@@ -1017,6 +1019,10 @@ virDomainNetDefParseXML(virConnectPtr conn,
                 script = virXMLPropString(cur, "path");
             } else if (xmlStrEqual (cur->name, BAD_CAST "model")) {
                 model = virXMLPropString(cur, "type");
+            } else if ((flags & VIR_DOMAIN_XML_INTERNAL_STATUS) &&
+                       xmlStrEqual(cur->name, BAD_CAST "state")) {
+                nic_name = virXMLPropString(cur, "nic");
+                hostnet_name = virXMLPropString(cur, "hostnet");
             }
         }
         cur = cur->next;
@@ -1028,6 +1034,10 @@ virDomainNetDefParseXML(virConnectPtr conn,
         virCapabilitiesGenerateMac(caps, def->mac);
     }
 
+    def->nic_name = nic_name;
+    def->hostnet_name = hostnet_name;
+    nic_name = hostnet_name = NULL;
+
     switch (def->type) {
     case VIR_DOMAIN_NET_TYPE_NETWORK:
         if (network == NULL) {
@@ -1147,6 +1157,8 @@ cleanup:
     VIR_FREE(model);
     VIR_FREE(type);
     VIR_FREE(internal);
+    VIR_FREE(nic_name);
+    VIR_FREE(hostnet_name);
 
     return def;
 
@@ -3523,7 +3535,8 @@ virDomainFSDefFormat(virConnectPtr conn,
 static int
 virDomainNetDefFormat(virConnectPtr conn,
                       virBufferPtr buf,
-                      virDomainNetDefPtr def)
+                      virDomainNetDefPtr def,
+                      int flags)
 {
     const char *type = virDomainNetTypeToString(def->type);
 
@@ -3594,6 +3607,16 @@ virDomainNetDefFormat(virConnectPtr conn,
         virBufferEscapeString(buf, "      <model type='%s'/>\n",
                               def->model);
 
+    if ((flags & VIR_DOMAIN_XML_INTERNAL_STATUS) &&
+        (def->nic_name || def->hostnet_name)) {
+        virBufferAddLit(buf, "      <state");
+        if (def->nic_name)
+            virBufferEscapeString(buf, " nic='%s'", def->nic_name);
+        if (def->hostnet_name)
+            virBufferEscapeString(buf, " hostnet='%s'", def->hostnet_name);
+        virBufferAddLit(buf, "/>\n");
+    }
+
     virBufferAddLit(buf, "    </interface>\n");
 
     return 0;
@@ -4075,7 +4098,7 @@ char *virDomainDefFormat(virConnectPtr conn,
 
 
     for (n = 0 ; n < def->nnets ; n++)
-        if (virDomainNetDefFormat(conn, &buf, def->nets[n]) < 0)
+        if (virDomainNetDefFormat(conn, &buf, def->nets[n], flags) < 0)
             goto cleanup;
 
     for (n = 0 ; n < def->nserials ; n++)
-- 
1.6.2.5

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

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