diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_source.c index 2cfe3bc325..4612e710b0 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -543,6 +543,39 @@ virStorageSourceNewFromBacking(virStorageSource *parent, } +/** + * virStorageSourceNewFromDataFile: + * @parent: storage source parent + * + * Creates a storage source which describes the data file image of @parent. + * Returned storage source format is VIR_STORAGE_FILE_RAW, and, unlike + * backing storage creation, readonly flag is copied from @parent. + */ +static virStorageSource * +virStorageSourceNewFromDataFile(virStorageSource *parent) +{ + g_autoptr(virStorageSource) dataFile = NULL; + int rc; + + if ((rc = virStorageSourceNewFromChild(parent, + parent->dataFileRaw, + &dataFile)) < 0) + return NULL; + + if (rc == 1) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("can't use data file definition '%1$s'"), + parent->dataFileRaw); + return NULL; + } + + dataFile->format = VIR_STORAGE_FILE_RAW; + dataFile->readonly = parent->readonly; + + return g_steal_pointer(&dataFile); +} + + /** * @src: disk source definition structure * @fd: file descriptor @@ -1391,6 +1424,14 @@ virStorageSourceGetMetadataRecurse(virStorageSource *src, } } + /* The image we're detecting on can have a '' explicitly + * configured without a '' terminator so we must not + * overwrite it */ + if (!src->dataFileStore && src->dataFileRaw) { + if (!(src->dataFileStore = virStorageSourceNewFromDataFile(src))) + return -1; + } + if (src->backingStoreRaw) { if ((rv = virStorageSourceNewFromBacking(src, &backingStore)) < 0) return -1;