xmlNodePtr source;
char *type = NULL;
char *format = NULL;
+ char *idx = NULL;
int ret = -1;
if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
if (VIR_ALLOC(backingStore) < 0)
goto cleanup;
+ if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
+ (idx = virXMLPropString(ctxt->node, "index")) &&
+ virStrToLong_uip(idx, NULL, 10, &backingStore->id) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, _("invalid disk index '%s'"), idx);
+ goto cleanup;
+ }
+
if (!(type = virXMLPropString(ctxt->node, "type"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing disk backing store type"));
static int
virDomainDiskBackingStoreFormat(virBufferPtr buf,
virStorageSourcePtr backingStore,
- const char *backingStoreRaw,
- unsigned int idx)
+ const char *backingStoreRaw)
{
const char *type;
const char *format;
return -1;
}
- virBufferAsprintf(buf, "<backingStore type='%s' index='%u'>\n",
- type, idx);
+ virBufferAsprintf(buf, "<backingStore type='%s'", type);
+ if (backingStore->id != 0)
+ virBufferAsprintf(buf, " index='%u'", backingStore->id);
+ virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 ||
virDomainDiskBackingStoreFormat(buf,
backingStore->backingStore,
- backingStore->backingStoreRaw,
- idx + 1) < 0)
+ backingStore->backingStoreRaw) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
* persistent storage of backing chains is ready. */
if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
- def->src->backingStoreRaw, 1) < 0)
+ def->src->backingStoreRaw) < 0)
return -1;
virBufferEscapeString(buf, "<backenddomain name='%s'/>\n", def->domain_name);
}
+static void
+qemuDomainSnapshotUpdateDiskSourcesRenumber(virStorageSourcePtr src)
+{
+ virStorageSourcePtr next;
+ unsigned int idx = 1;
+
+ for (next = src->backingStore; next; next = next->backingStore)
+ next->id = idx++;
+}
+
+
/**
* qemuDomainSnapshotUpdateDiskSources:
* @dd: snapshot disk data object
VIR_STEAL_PTR(dd->src->backingStore, dd->disk->src);
VIR_STEAL_PTR(dd->disk->src, dd->src);
+ /* fix numbering of disks */
+ qemuDomainSnapshotUpdateDiskSourcesRenumber(dd->disk->src);
+
if (dd->persistdisk) {
VIR_STEAL_PTR(dd->persistsrc->backingStore, dd->persistdisk->src);
VIR_STEAL_PTR(dd->persistdisk->src, dd->persistsrc);
uid_t uid, gid_t gid,
bool allow_probe,
bool report_broken,
- virHashTablePtr cycle)
+ virHashTablePtr cycle,
+ unsigned int depth)
{
int ret = -1;
const char *uniqueName;
if ((ret = virStorageFileGetMetadataRecurse(backingStore, parent,
uid, gid,
allow_probe, report_broken,
- cycle)) < 0) {
+ cycle, depth + 1)) < 0) {
if (report_broken)
goto cleanup;
ret = 0;
cleanup:
+ if (src->backingStore)
+ src->backingStore->id = depth;
VIR_FREE(buf);
virStorageFileDeinit(src);
virStorageSourceFree(backingStore);
}
ret = virStorageFileGetMetadataRecurse(src, src, uid, gid,
- allow_probe, report_broken, cycle);
+ allow_probe, report_broken, cycle, 1);
virHashFree(cycle);
return ret;