43fe83
From 933e0aeebdbdc2932a1b11ce338c67bb163268f5 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <933e0aeebdbdc2932a1b11ce338c67bb163268f5.1377873637.git.jdenemar@redhat.com>
43fe83
From: Guannan Ren <gren@redhat.com>
43fe83
Date: Thu, 8 Aug 2013 16:07:29 +0800
43fe83
Subject: [PATCH] conf: add startupPolicy attribute for harddisk
43fe83
43fe83
Resovles: https://bugzilla.redhat.com/show_bug.cgi?id=910171
43fe83
(cherry picked from commit 93319da42cd1a23245577dda244998f1ff725703)
43fe83
43fe83
Add startupPolicy attribute for harddisk with type "file",
43fe83
"block" and "dir". 'requisite' is not supported currently for
43fe83
harddisk.
43fe83
---
43fe83
 docs/formatdomain.html.in     |  8 ++++++--
43fe83
 docs/schemas/domaincommon.rng |  6 ++++++
43fe83
 src/conf/domain_conf.c        | 31 +++++++++++++++++++++++--------
43fe83
 3 files changed, 35 insertions(+), 10 deletions(-)
43fe83
43fe83
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
43fe83
index 562d991..fb7d671 100644
43fe83
--- a/docs/formatdomain.html.in
43fe83
+++ b/docs/formatdomain.html.in
43fe83
@@ -1620,7 +1620,8 @@
43fe83
         policy what to do with the disk if the source file is not accessible.
43fe83
         (NB, startupPolicy is not valid for "volume" disk unless
43fe83
          the specified storage volume is of "file" type). This is done by the
43fe83
-        startupPolicy attribute, accepting these values:
43fe83
+        startupPolicy attribute (Since 0.9.7),
43fe83
+        accepting these values:
43fe83
         
43fe83
           
43fe83
              mandatory 
43fe83
@@ -1636,7 +1637,10 @@
43fe83
              drop if missing at any start attempt 
43fe83
           
43fe83
         
43fe83
-        Since 0.9.7
43fe83
+        Since 1.1.2 the startupPolicy is extended
43fe83
+        to support hard disks besides cdrom and floppy. On guest cold bootup, if a certain disk
43fe83
+        is not accessible or its disk chain is broken, with startupPolicy 'optional' the guest
43fe83
+        will drop this disk. This feature doesn't support migration currently.
43fe83
         
43fe83
       
mirror
43fe83
       
43fe83
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
43fe83
index 173359c..ac807e6 100644
43fe83
--- a/docs/schemas/domaincommon.rng
43fe83
+++ b/docs/schemas/domaincommon.rng
43fe83
@@ -1124,6 +1124,9 @@
43fe83
                   <ref name="absFilePath"/>
43fe83
                 </attribute>
43fe83
                 <optional>
43fe83
+                  <ref name="startupPolicy"/>
43fe83
+                </optional>
43fe83
+                <optional>
43fe83
                   <ref name='devSeclabel'/>
43fe83
                 </optional>
43fe83
               </element>
43fe83
@@ -1141,6 +1144,9 @@
43fe83
                 <attribute name="dir">
43fe83
                   <ref name="absFilePath"/>
43fe83
                 </attribute>
43fe83
+                <optional>
43fe83
+                  <ref name="startupPolicy"/>
43fe83
+                </optional>
43fe83
                 <empty/>
43fe83
               </element>
43fe83
             </optional>
43fe83
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
43fe83
index f46b17e..01f9bd0 100644
43fe83
--- a/src/conf/domain_conf.c
43fe83
+++ b/src/conf/domain_conf.c
43fe83
@@ -4796,7 +4796,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
43fe83
                 switch (def->type) {
43fe83
                 case VIR_DOMAIN_DISK_TYPE_FILE:
43fe83
                     source = virXMLPropString(cur, "file");
43fe83
-                    startupPolicy = virXMLPropString(cur, "startupPolicy");
43fe83
                     break;
43fe83
                 case VIR_DOMAIN_DISK_TYPE_BLOCK:
43fe83
                     source = virXMLPropString(cur, "dev");
43fe83
@@ -4883,7 +4882,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
43fe83
                 case VIR_DOMAIN_DISK_TYPE_VOLUME:
43fe83
                     if (virDomainDiskSourcePoolDefParse(cur, def) < 0)
43fe83
                         goto error;
43fe83
-                    startupPolicy = virXMLPropString(cur, "startupPolicy");
43fe83
                     break;
43fe83
                 default:
43fe83
                     virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
@@ -4892,6 +4890,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
43fe83
                     goto error;
43fe83
                 }
43fe83
 
43fe83
+                startupPolicy = virXMLPropString(cur, "startupPolicy");
43fe83
+
43fe83
                 /* People sometimes pass a bogus '' source path
43fe83
                    when they mean to omit the source element
43fe83
                    completely (e.g. CDROM without media). This is
43fe83
@@ -5464,14 +5464,22 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
43fe83
             goto error;
43fe83
         }
43fe83
 
43fe83
-        if (def->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
43fe83
-            def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
43fe83
-            virReportError(VIR_ERR_INVALID_ARG,
43fe83
-                           _("Setting disk %s is allowed only for "
43fe83
-                             "cdrom or floppy"),
43fe83
+        if (def->type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
43fe83
+            virReportError(VIR_ERR_XML_ERROR,
43fe83
+                           _("Setting disk %s is not allowed for "
43fe83
+                             "disk of network type"),
43fe83
                            startupPolicy);
43fe83
             goto error;
43fe83
         }
43fe83
+
43fe83
+        if (def->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
43fe83
+            def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
43fe83
+            val == VIR_DOMAIN_STARTUP_POLICY_REQUISITE) {
43fe83
+            virReportError(VIR_ERR_XML_ERROR, "%s",
43fe83
+                           _("Setting disk 'requisite' is allowed only for "
43fe83
+                             "cdrom or floppy"));
43fe83
+            goto error;
43fe83
+        }
43fe83
         def->startupPolicy = val;
43fe83
     }
43fe83
 
43fe83
@@ -14121,6 +14129,9 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
43fe83
         case VIR_DOMAIN_DISK_TYPE_BLOCK:
43fe83
             virBufferEscapeString(buf, "      
43fe83
                                   def->src);
43fe83
+            if (def->startupPolicy)
43fe83
+                virBufferEscapeString(buf, " startupPolicy='%s'",
43fe83
+                                      startupPolicy);
43fe83
             if (def->nseclabels) {
43fe83
                 virBufferAddLit(buf, ">\n");
43fe83
                 virBufferAdjustIndent(buf, 8);
43fe83
@@ -14133,8 +14144,12 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
43fe83
             }
43fe83
             break;
43fe83
         case VIR_DOMAIN_DISK_TYPE_DIR:
43fe83
-            virBufferEscapeString(buf, "      <source dir='%s'/>\n",
43fe83
+            virBufferEscapeString(buf, "      
43fe83
                                   def->src);
43fe83
+            if (def->startupPolicy)
43fe83
+                virBufferEscapeString(buf, " startupPolicy='%s'",
43fe83
+                                      startupPolicy);
43fe83
+            virBufferAddLit(buf, "/>\n");
43fe83
             break;
43fe83
         case VIR_DOMAIN_DISK_TYPE_NETWORK:
43fe83
             virBufferAsprintf(buf, "      
43fe83
-- 
43fe83
1.8.3.2
43fe83