mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
util: storage: Store backing chain index in virStorageSource
The backing store indexes were not bound to the storage sources in any way. To allow us to bind a given alias to a given storage source we need to save the index in virStorageSource. The backing store ids are now generated when detecting the backing chain. Since we don't re-detect the backing chain after snapshots, the numbering needs to be fixed there.
This commit is contained in:
parent
7547ed1297
commit
c6231a6a6c
@ -8281,6 +8281,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
|
|||||||
xmlNodePtr source;
|
xmlNodePtr source;
|
||||||
char *type = NULL;
|
char *type = NULL;
|
||||||
char *format = NULL;
|
char *format = NULL;
|
||||||
|
char *idx = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
|
if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
|
||||||
@ -8291,6 +8292,13 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
|
|||||||
if (VIR_ALLOC(backingStore) < 0)
|
if (VIR_ALLOC(backingStore) < 0)
|
||||||
goto cleanup;
|
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"))) {
|
if (!(type = virXMLPropString(ctxt->node, "type"))) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing disk backing store type"));
|
_("missing disk backing store type"));
|
||||||
@ -21910,8 +21918,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
|
|||||||
static int
|
static int
|
||||||
virDomainDiskBackingStoreFormat(virBufferPtr buf,
|
virDomainDiskBackingStoreFormat(virBufferPtr buf,
|
||||||
virStorageSourcePtr backingStore,
|
virStorageSourcePtr backingStore,
|
||||||
const char *backingStoreRaw,
|
const char *backingStoreRaw)
|
||||||
unsigned int idx)
|
|
||||||
{
|
{
|
||||||
const char *type;
|
const char *type;
|
||||||
const char *format;
|
const char *format;
|
||||||
@ -21938,8 +21945,10 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<backingStore type='%s' index='%u'>\n",
|
virBufferAsprintf(buf, "<backingStore type='%s'", type);
|
||||||
type, idx);
|
if (backingStore->id != 0)
|
||||||
|
virBufferAsprintf(buf, " index='%u'", backingStore->id);
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
virBufferAdjustIndent(buf, 2);
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
|
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
|
||||||
@ -21947,8 +21956,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
|
|||||||
if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 ||
|
if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 ||
|
||||||
virDomainDiskBackingStoreFormat(buf,
|
virDomainDiskBackingStoreFormat(buf,
|
||||||
backingStore->backingStore,
|
backingStore->backingStore,
|
||||||
backingStore->backingStoreRaw,
|
backingStore->backingStoreRaw) < 0)
|
||||||
idx + 1) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
@ -22084,7 +22092,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
|
|||||||
* persistent storage of backing chains is ready. */
|
* persistent storage of backing chains is ready. */
|
||||||
if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
|
if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
|
||||||
virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
|
virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
|
||||||
def->src->backingStoreRaw, 1) < 0)
|
def->src->backingStoreRaw) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virBufferEscapeString(buf, "<backenddomain name='%s'/>\n", def->domain_name);
|
virBufferEscapeString(buf, "<backenddomain name='%s'/>\n", def->domain_name);
|
||||||
|
@ -14429,6 +14429,17 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
qemuDomainSnapshotUpdateDiskSourcesRenumber(virStorageSourcePtr src)
|
||||||
|
{
|
||||||
|
virStorageSourcePtr next;
|
||||||
|
unsigned int idx = 1;
|
||||||
|
|
||||||
|
for (next = src->backingStore; next; next = next->backingStore)
|
||||||
|
next->id = idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuDomainSnapshotUpdateDiskSources:
|
* qemuDomainSnapshotUpdateDiskSources:
|
||||||
* @dd: snapshot disk data object
|
* @dd: snapshot disk data object
|
||||||
@ -14451,6 +14462,9 @@ qemuDomainSnapshotUpdateDiskSources(qemuDomainSnapshotDiskDataPtr dd,
|
|||||||
VIR_STEAL_PTR(dd->src->backingStore, dd->disk->src);
|
VIR_STEAL_PTR(dd->src->backingStore, dd->disk->src);
|
||||||
VIR_STEAL_PTR(dd->disk->src, dd->src);
|
VIR_STEAL_PTR(dd->disk->src, dd->src);
|
||||||
|
|
||||||
|
/* fix numbering of disks */
|
||||||
|
qemuDomainSnapshotUpdateDiskSourcesRenumber(dd->disk->src);
|
||||||
|
|
||||||
if (dd->persistdisk) {
|
if (dd->persistdisk) {
|
||||||
VIR_STEAL_PTR(dd->persistsrc->backingStore, dd->persistdisk->src);
|
VIR_STEAL_PTR(dd->persistsrc->backingStore, dd->persistdisk->src);
|
||||||
VIR_STEAL_PTR(dd->persistdisk->src, dd->persistsrc);
|
VIR_STEAL_PTR(dd->persistdisk->src, dd->persistsrc);
|
||||||
|
@ -396,7 +396,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
uid_t uid, gid_t gid,
|
uid_t uid, gid_t gid,
|
||||||
bool allow_probe,
|
bool allow_probe,
|
||||||
bool report_broken,
|
bool report_broken,
|
||||||
virHashTablePtr cycle)
|
virHashTablePtr cycle,
|
||||||
|
unsigned int depth)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char *uniqueName;
|
const char *uniqueName;
|
||||||
@ -474,7 +475,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
if ((ret = virStorageFileGetMetadataRecurse(backingStore, parent,
|
if ((ret = virStorageFileGetMetadataRecurse(backingStore, parent,
|
||||||
uid, gid,
|
uid, gid,
|
||||||
allow_probe, report_broken,
|
allow_probe, report_broken,
|
||||||
cycle)) < 0) {
|
cycle, depth + 1)) < 0) {
|
||||||
if (report_broken)
|
if (report_broken)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -489,6 +490,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (src->backingStore)
|
||||||
|
src->backingStore->id = depth;
|
||||||
VIR_FREE(buf);
|
VIR_FREE(buf);
|
||||||
virStorageFileDeinit(src);
|
virStorageFileDeinit(src);
|
||||||
virStorageSourceFree(backingStore);
|
virStorageSourceFree(backingStore);
|
||||||
@ -543,7 +546,7 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = virStorageFileGetMetadataRecurse(src, src, uid, gid,
|
ret = virStorageFileGetMetadataRecurse(src, src, uid, gid,
|
||||||
allow_probe, report_broken, cycle);
|
allow_probe, report_broken, cycle, 1);
|
||||||
|
|
||||||
virHashFree(cycle);
|
virHashFree(cycle);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2030,6 +2030,7 @@ virStorageSourceCopy(const virStorageSource *src,
|
|||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
ret->id = src->id;
|
||||||
ret->type = src->type;
|
ret->type = src->type;
|
||||||
ret->protocol = src->protocol;
|
ret->protocol = src->protocol;
|
||||||
ret->format = src->format;
|
ret->format = src->format;
|
||||||
|
@ -227,6 +227,7 @@ typedef virStorageSource *virStorageSourcePtr;
|
|||||||
* IMPORTANT: When adding fields to this struct it's also necessary to add
|
* IMPORTANT: When adding fields to this struct it's also necessary to add
|
||||||
* appropriate code to the virStorageSourceCopy deep copy function */
|
* appropriate code to the virStorageSourceCopy deep copy function */
|
||||||
struct _virStorageSource {
|
struct _virStorageSource {
|
||||||
|
unsigned int id; /* backing chain identifier, 0 is unset */
|
||||||
int type; /* virStorageType */
|
int type; /* virStorageType */
|
||||||
char *path;
|
char *path;
|
||||||
int protocol; /* virStorageNetProtocol */
|
int protocol; /* virStorageNetProtocol */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user