Blob Blame History Raw
From 801bda8e304ca35628ec6bc2cb367f9537a6cd31 Mon Sep 17 00:00:00 2001
Message-Id: <801bda8e304ca35628ec6bc2cb367f9537a6cd31@dist-git>
From: Doug Goldstein <cardoe@cardoe.com>
Date: Wed, 26 Feb 2014 14:54:07 +0100
Subject: [PATCH] Allow <source> for type=block to have no dev

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

Currently the XML parser already allows the following syntax:
  <disk type='block' device='cdrom'>
    <source startupPolicy='optional'/>
    <target dev='hda' bus='ide'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
  </disk>

But it if the dev value is NULL then it would not have the leading
"<source ", resulting in invalid XML.

(cherry picked from commit 4b5652d0dcb2d53fd4240f589a63aaa434650fe0)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 docs/schemas/domaincommon.rng | 8 +++++---
 src/conf/domain_conf.c        | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 551e82b..a8f1d71 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1161,9 +1161,11 @@
           <interleave>
             <optional>
               <element name="source">
-                <attribute name="dev">
-                  <ref name="absFilePath"/>
-                </attribute>
+                <optional>
+                  <attribute name="dev">
+                    <ref name="absFilePath"/>
+                  </attribute>
+                </optional>
                 <optional>
                   <ref name="startupPolicy"/>
                 </optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b612f3a..7e43232 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14467,8 +14467,8 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
             }
             break;
         case VIR_DOMAIN_DISK_TYPE_BLOCK:
-            virBufferEscapeString(buf, "      <source dev='%s'",
-                                  def->src);
+            virBufferAddLit(buf, "      <source");
+            virBufferEscapeString(buf, " dev='%s'", def->src);
             if (def->startupPolicy)
                 virBufferEscapeString(buf, " startupPolicy='%s'",
                                       startupPolicy);
-- 
1.9.0