]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: add support for booting from redirected USB devices
authorJán Tomko <jtomko@redhat.com>
Tue, 20 Nov 2012 18:47:07 +0000 (19:47 +0100)
committerCole Robinson <crobinso@redhat.com>
Sun, 9 Dec 2012 21:32:58 +0000 (16:32 -0500)
Commit a4c19459aa8634c43b51e8138fb1d7eec4c17824 only added the
QEMU capability flag, command line option and added the boot element
for redirdev's in the XML schema.

This patch adds support for parsing and writing the XML with redirdevs
with the boot flag. It also ignores unknown XML elements in redirdev
instead of failing with:
"error: An error occurred, but the cause is unknown"

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=805414
(cherry picked from commit cc244e24416b7785258c69995483015bbf8927dd)

src/conf/domain_conf.c

index b0a0f4a96bb5f214c5e9a1c8d2a5fe2beda23b4e..242fec8f84eab2e35a8075ea6d7989df32c969a7 100644 (file)
@@ -7240,11 +7240,13 @@ error:
 
 static virDomainRedirdevDefPtr
 virDomainRedirdevDefParseXML(const xmlNodePtr node,
+                             virBitmapPtr bootMap,
                              unsigned int flags)
 {
     xmlNodePtr cur;
     virDomainRedirdevDefPtr def;
     char *bus, *type = NULL;
+    int remaining;
 
     if (VIR_ALLOC(def) < 0) {
         virReportOOMError();
@@ -7276,25 +7278,20 @@ virDomainRedirdevDefParseXML(const xmlNodePtr node,
     }
 
     cur = node->children;
-    while (cur != NULL) {
-        if (cur->type == XML_ELEMENT_NODE) {
-            if (xmlStrEqual(cur->name, BAD_CAST "source")) {
-                int remaining;
-
-                remaining = virDomainChrSourceDefParseXML(&def->source.chr, cur, flags,
-                                                          NULL, NULL, NULL, 0);
-                if (remaining != 0)
-                    goto error;
-            }
-        }
-        cur = cur->next;
-    }
+    /* boot gets parsed in virDomainDeviceInfoParseXML
+     * source gets parsed in virDomainChrSourceDefParseXML
+     * we don't know any of the elements that might remain */
+    remaining = virDomainChrSourceDefParseXML(&def->source.chr, cur, flags,
+                                              NULL, NULL, NULL, 0);
+    if (remaining < 0)
+        goto error;
 
     if (def->source.chr.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
         def->source.chr.data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR;
     }
 
-    if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
+    if (virDomainDeviceInfoParseXML(node, bootMap, &def->info,
+                                    flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0)
         goto error;
 
     if (def->bus == VIR_DOMAIN_REDIRDEV_BUS_USB &&
@@ -7638,7 +7635,7 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
             goto error;
     } else if (xmlStrEqual(node->name, BAD_CAST "redirdev")) {
         dev->type = VIR_DOMAIN_DEVICE_REDIRDEV;
-        if (!(dev->data.redirdev = virDomainRedirdevDefParseXML(node, flags)))
+        if (!(dev->data.redirdev = virDomainRedirdevDefParseXML(node, NULL, flags)))
             goto error;
     } else {
         virReportError(VIR_ERR_XML_ERROR,
@@ -8186,7 +8183,8 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
 
     if (virXPathULong("count(./devices/disk[boot]"
                       "|./devices/interface[boot]"
-                      "|./devices/hostdev[boot])", ctxt, &deviceBoot) < 0) {
+                      "|./devices/hostdev[boot]"
+                      "|./devices/redirdev[boot])", ctxt, &deviceBoot) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot count boot devices"));
         goto cleanup;
@@ -9769,6 +9767,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
         goto no_memory;
     for (i = 0 ; i < n ; i++) {
         virDomainRedirdevDefPtr redirdev = virDomainRedirdevDefParseXML(nodes[i],
+                                                                        bootMap,
                                                                         flags);
         if (!redirdev)
             goto error;
@@ -13192,7 +13191,8 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "    <redirdev bus='%s'", bus);
     if (virDomainChrSourceDefFormat(buf, &def->source.chr, false, flags) < 0)
         return -1;
-    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+    if (virDomainDeviceInfoFormat(buf, &def->info,
+                                  flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0)
         return -1;
     virBufferAddLit(buf, "    </redirdev>\n");