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

[libvirt] [PATCH 04/12] Add address info to sound, video and watchdog devices



Add the virDomainDeviceAddress information to the sound, video
and watchdog devices. This means all of them gain a new XML
element

  <address .... />

* src/conf/domain_conf.h: Add virDomainDeviceAddress to sound,
  video & watchdog device struts.
* src/conf/domain_conf.c: Hook up parsing/formatting for
  virDomainDeviceAddress in sound, video & watchdog devices
---
 src/conf/domain_conf.c |   85 ++++++++++++++++++++++++++++++++++++++++++-----
 src/conf/domain_conf.h |    3 ++
 2 files changed, 79 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9c0b8cf..a1eeb06 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2369,6 +2369,19 @@ virDomainSoundDefParseXML(virConnectPtr conn,
 
     char *model;
     virDomainSoundDefPtr def;
+    xmlNodePtr addr = NULL;
+    xmlNodePtr cur;
+
+    cur = node->children;
+    while (cur != NULL) {
+        if (cur->type == XML_ELEMENT_NODE) {
+            if ((addr == NULL) &&
+                xmlStrEqual(cur->name, BAD_CAST "address")) {
+                addr = cur;
+            }
+        }
+        cur = cur->next;
+    }
 
     if (VIR_ALLOC(def) < 0) {
         virReportOOMError(conn);
@@ -2382,6 +2395,10 @@ virDomainSoundDefParseXML(virConnectPtr conn,
         goto error;
     }
 
+    if (addr &&
+        virDomainDeviceAddressParseXML(conn, addr, &def->addr, flags) < 0)
+        goto error;
+
 cleanup:
     VIR_FREE(model);
 
@@ -2397,11 +2414,24 @@ error:
 static virDomainWatchdogDefPtr
 virDomainWatchdogDefParseXML(virConnectPtr conn,
                              const xmlNodePtr node,
-                             int flags ATTRIBUTE_UNUSED) {
+                             int flags) {
 
     char *model = NULL;
     char *action = NULL;
     virDomainWatchdogDefPtr def;
+    xmlNodePtr addr = NULL;
+    xmlNodePtr cur;
+
+    cur = node->children;
+    while (cur != NULL) {
+        if (cur->type == XML_ELEMENT_NODE) {
+            if ((addr == NULL) &&
+                xmlStrEqual(cur->name, BAD_CAST "address")) {
+                addr = cur;
+            }
+        }
+        cur = cur->next;
+    }
 
     if (VIR_ALLOC (def) < 0) {
         virReportOOMError (conn);
@@ -2433,6 +2463,10 @@ virDomainWatchdogDefParseXML(virConnectPtr conn,
         }
     }
 
+    if (addr && (def->model == VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB) &&
+        virDomainDeviceAddressParseXML(conn, addr, &def->addr, flags) < 0)
+        goto error;
+
 cleanup:
     VIR_FREE (action);
     VIR_FREE (model);
@@ -2548,6 +2582,7 @@ virDomainVideoDefParseXML(virConnectPtr conn,
                           int flags ATTRIBUTE_UNUSED) {
     virDomainVideoDefPtr def;
     xmlNodePtr cur;
+    xmlNodePtr addr = NULL;
     char *type = NULL;
     char *heads = NULL;
     char *vram = NULL;
@@ -2566,6 +2601,9 @@ virDomainVideoDefParseXML(virConnectPtr conn,
                 vram = virXMLPropString(cur, "vram");
                 heads = virXMLPropString(cur, "heads");
                 def->accel = virDomainVideoAccelDefParseXML(conn, cur);
+            } else if ((addr == NULL) &&
+                       xmlStrEqual(cur->name, BAD_CAST "address")) {
+                addr = cur;
             }
         }
         cur = cur->next;
@@ -2605,6 +2643,10 @@ virDomainVideoDefParseXML(virConnectPtr conn,
         def->heads = 1;
     }
 
+    if (addr &&
+        virDomainDeviceAddressParseXML(conn, addr, &def->addr, flags) < 0)
+        goto error;
+
     VIR_FREE(type);
     VIR_FREE(vram);
     VIR_FREE(heads);
@@ -4645,7 +4687,8 @@ cleanup:
 static int
 virDomainSoundDefFormat(virConnectPtr conn,
                         virBufferPtr buf,
-                        virDomainSoundDefPtr def)
+                        virDomainSoundDefPtr def,
+                        int flags)
 {
     const char *model = virDomainSoundModelTypeToString(def->model);
 
@@ -4655,9 +4698,18 @@ virDomainSoundDefFormat(virConnectPtr conn,
         return -1;
     }
 
-    virBufferVSprintf(buf, "    <sound model='%s'/>\n",
+    virBufferVSprintf(buf, "    <sound model='%s'",
                       model);
 
+    if (def->addr.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+        virBufferAddLit(buf, ">\n");
+        if (virDomainDeviceAddressFormat(buf, &def->addr, flags) < 0)
+            return -1;
+        virBufferAddLit(buf, "    </sound>\n");
+    } else {
+        virBufferAddLit(buf, "/>\n");
+    }
+
     return 0;
 }
 
@@ -4665,7 +4717,8 @@ virDomainSoundDefFormat(virConnectPtr conn,
 static int
 virDomainWatchdogDefFormat(virConnectPtr conn,
                            virBufferPtr buf,
-                           virDomainWatchdogDefPtr def)
+                           virDomainWatchdogDefPtr def,
+                           int flags)
 {
     const char *model = virDomainWatchdogModelTypeToString (def->model);
     const char *action = virDomainWatchdogActionTypeToString (def->action);
@@ -4682,9 +4735,18 @@ virDomainWatchdogDefFormat(virConnectPtr conn,
         return -1;
     }
 
-    virBufferVSprintf(buf, "    <watchdog model='%s' action='%s'/>\n",
+    virBufferVSprintf(buf, "    <watchdog model='%s' action='%s'",
                       model, action);
 
+    if (def->addr.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+        virBufferAddLit(buf, ">\n");
+        if (virDomainDeviceAddressFormat(buf, &def->addr, flags) < 0)
+            return -1;
+        virBufferAddLit(buf, "    </watchdog>\n");
+    } else {
+        virBufferAddLit(buf, "/>\n");
+    }
+
     return 0;
 }
 
@@ -4704,7 +4766,8 @@ virDomainVideoAccelDefFormat(virBufferPtr buf,
 static int
 virDomainVideoDefFormat(virConnectPtr conn,
                         virBufferPtr buf,
-                        virDomainVideoDefPtr def)
+                        virDomainVideoDefPtr def,
+                        int flags)
 {
     const char *model = virDomainVideoTypeToString(def->type);
 
@@ -4729,6 +4792,10 @@ virDomainVideoDefFormat(virConnectPtr conn,
         virBufferAddLit(buf, "/>\n");
     }
 
+    if (def->addr.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+        virDomainDeviceAddressFormat(buf, &def->addr, flags) < 0)
+        return -1;
+
     virBufferAddLit(buf, "    </video>\n");
 
     return 0;
@@ -5128,11 +5195,11 @@ char *virDomainDefFormat(virConnectPtr conn,
     }
 
     for (n = 0 ; n < def->nsounds ; n++)
-        if (virDomainSoundDefFormat(conn, &buf, def->sounds[n]) < 0)
+        if (virDomainSoundDefFormat(conn, &buf, def->sounds[n], flags) < 0)
             goto cleanup;
 
     for (n = 0 ; n < def->nvideos ; n++)
-        if (virDomainVideoDefFormat(conn, &buf, def->videos[n]) < 0)
+        if (virDomainVideoDefFormat(conn, &buf, def->videos[n], flags) < 0)
             goto cleanup;
 
     for (n = 0 ; n < def->nhostdevs ; n++)
@@ -5140,7 +5207,7 @@ char *virDomainDefFormat(virConnectPtr conn,
             goto cleanup;
 
     if (def->watchdog)
-        virDomainWatchdogDefFormat (conn, &buf, def->watchdog);
+        virDomainWatchdogDefFormat (conn, &buf, def->watchdog, flags);
 
     virBufferAddLit(&buf, "  </devices>\n");
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d1c1b67..f06c2dc 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -348,6 +348,7 @@ typedef struct _virDomainSoundDef virDomainSoundDef;
 typedef virDomainSoundDef *virDomainSoundDefPtr;
 struct _virDomainSoundDef {
     int model;
+    virDomainDeviceAddress addr;
 };
 
 enum virDomainWatchdogModel {
@@ -372,6 +373,7 @@ typedef virDomainWatchdogDef *virDomainWatchdogDefPtr;
 struct _virDomainWatchdogDef {
     int model;
     int action;
+    virDomainDeviceAddress addr;
 };
 
 
@@ -401,6 +403,7 @@ struct _virDomainVideoDef {
     unsigned int vram;
     unsigned int heads;
     virDomainVideoAccelDefPtr accel;
+    virDomainDeviceAddress addr;
 };
 
 /* 3 possible graphics console modes */
-- 
1.6.5.2


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