diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index e68223329c..0cbf570a13 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3020,6 +3020,11 @@
is only valid when the specified storage volume is of 'file' or
'block' type).
+ The source element may also have the index
+ attribute with same semantics the
+ index attribute of backingStore
+
+
The source element may contain the following sub elements:
@@ -3228,7 +3233,7 @@
by the backing store, see disk type attribute above for more
details and possible values.
- index
+ index
This attribute is only valid in output (and ignored on input) and
it can be used to refer to a specific part of the disk chain when
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 385fa8666c..f176538195 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1545,6 +1545,14 @@
+
+
+
+
+
+
+
+
@@ -1568,6 +1576,7 @@
+
@@ -1592,6 +1601,7 @@
+
@@ -1617,6 +1627,7 @@
+
@@ -1670,6 +1681,7 @@
rbd
+
@@ -1709,6 +1721,7 @@
iscsi
+
@@ -1731,6 +1744,7 @@
+
@@ -1749,6 +1763,7 @@
+
@@ -1769,6 +1784,7 @@
+
@@ -1782,6 +1798,7 @@
gluster
+
@@ -1799,6 +1816,7 @@
+
@@ -1843,6 +1861,7 @@
+
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6b43c78ca4..bde9fef914 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9811,6 +9811,13 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
startupPolicy = virXMLPropString(cur, "startupPolicy");
+ if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
+ (tmp = virXMLPropString(cur, "index")) &&
+ virStrToLong_uip(tmp, NULL, 10, &def->src->id) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, _("invalid disk index '%s'"), tmp);
+ goto error;
+ }
+ VIR_FREE(tmp);
} else if (!target &&
virXMLNodeNameEqual(cur, "target")) {
target = virXMLPropString(cur, "dev");
@@ -23979,6 +23986,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
int policy,
unsigned int flags,
bool skipSeclabels,
+ bool attrIndex,
virDomainXMLOptionPtr xmlopt)
{
virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
@@ -23995,6 +24003,9 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
virBufferEscapeString(&attrBuf, " startupPolicy='%s'",
virDomainStartupPolicyTypeToString(policy));
+ if (attrIndex && src->id != 0)
+ virBufferAsprintf(&attrBuf, " index='%u'", src->id);
+
if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0)
goto cleanup;
@@ -24017,7 +24028,8 @@ virDomainDiskSourceFormat(virBufferPtr buf,
unsigned int flags,
virDomainXMLOptionPtr xmlopt)
{
- return virDomainDiskSourceFormatInternal(buf, src, policy, flags, false, xmlopt);
+ return virDomainDiskSourceFormatInternal(buf, src, policy, flags, false,
+ false, xmlopt);
}
@@ -24059,7 +24071,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
virBufferAsprintf(buf, " \n", format);
/* We currently don't output seclabels for backing chain element */
- if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, flags, true, xmlopt) < 0 ||
+ if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, flags, true,
+ false, xmlopt) < 0 ||
virDomainDiskBackingStoreFormat(buf, backingStore->backingStore,
xmlopt, flags) < 0)
return -1;
@@ -24325,8 +24338,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
if (def->src->auth && !def->src->authInherited)
virStorageAuthDefFormat(buf, def->src->auth);
- if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy,
- flags, xmlopt) < 0)
+ if (virDomainDiskSourceFormatInternal(buf, def->src, def->startupPolicy,
+ flags, false, true, xmlopt) < 0)
return -1;
/* Don't format backingStore to inactive XMLs until the code for
diff --git a/tests/qemuxml2argvdata/disk-backing-chains-index.xml b/tests/qemuxml2argvdata/disk-backing-chains-index.xml
index 95b8a64cf8..5e0a03fbc4 100644
--- a/tests/qemuxml2argvdata/disk-backing-chains-index.xml
+++ b/tests/qemuxml2argvdata/disk-backing-chains-index.xml
@@ -16,7 +16,7 @@
/usr/bin/qemu-system-i686
-
+
@@ -27,7 +27,7 @@
-
+
@@ -61,7 +61,7 @@
-
+
@@ -71,7 +71,7 @@
-
+
@@ -85,12 +85,12 @@
-
+
-
+
diff --git a/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml b/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
index 724afa4e83..2b5bc9e1b4 100644
--- a/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
+++ b/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
@@ -16,7 +16,7 @@
/usr/bin/qemu-system-i686
-
+
@@ -28,7 +28,7 @@
-
+
@@ -61,7 +61,7 @@
-
+
@@ -73,7 +73,7 @@
-
+
@@ -88,13 +88,13 @@
-
+
-
+