mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
Use the extract backing store format in storage volume lookup
The storage volume lookup code was probing for the backing store format, instead of using the format extracted from the file itself. This meant it could report in accurate information. If a format is included in the file, then use that in preference, with probing as a fallback. * src/storage/storage_backend_fs.c: Use extracted backing store format
This commit is contained in:
parent
27f45438c8
commit
187da82fea
@ -51,6 +51,7 @@
|
|||||||
static int
|
static int
|
||||||
virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
||||||
char **backingStore,
|
char **backingStore,
|
||||||
|
int *backingStoreFormat,
|
||||||
unsigned long long *allocation,
|
unsigned long long *allocation,
|
||||||
unsigned long long *capacity,
|
unsigned long long *capacity,
|
||||||
virStorageEncryptionPtr *encryption)
|
virStorageEncryptionPtr *encryption)
|
||||||
@ -58,6 +59,10 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
|||||||
int fd, ret;
|
int fd, ret;
|
||||||
virStorageFileMetadata meta;
|
virStorageFileMetadata meta;
|
||||||
|
|
||||||
|
if (backingStore)
|
||||||
|
*backingStore = NULL;
|
||||||
|
if (backingStoreFormat)
|
||||||
|
*backingStoreFormat = VIR_STORAGE_FILE_AUTO;
|
||||||
if (encryption)
|
if (encryption)
|
||||||
*encryption = NULL;
|
*encryption = NULL;
|
||||||
|
|
||||||
@ -89,12 +94,22 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
|||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
if (meta.backingStore) {
|
||||||
if (backingStore) {
|
if (backingStore) {
|
||||||
*backingStore = meta.backingStore;
|
*backingStore = meta.backingStore;
|
||||||
meta.backingStore = NULL;
|
meta.backingStore = NULL;
|
||||||
|
if (meta.backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
|
||||||
|
if ((*backingStoreFormat = virStorageFileProbeFormat(*backingStore)) < 0) {
|
||||||
|
close(fd);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
*backingStoreFormat = meta.backingStoreFormat;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
VIR_FREE(meta.backingStore);
|
VIR_FREE(meta.backingStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (capacity && meta.capacity)
|
if (capacity && meta.capacity)
|
||||||
*capacity = meta.capacity;
|
*capacity = meta.capacity;
|
||||||
@ -102,9 +117,7 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
|||||||
if (encryption != NULL && meta.encrypted) {
|
if (encryption != NULL && meta.encrypted) {
|
||||||
if (VIR_ALLOC(*encryption) < 0) {
|
if (VIR_ALLOC(*encryption) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
if (backingStore)
|
goto cleanup;
|
||||||
VIR_FREE(*backingStore);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (target->format) {
|
switch (target->format) {
|
||||||
@ -124,6 +137,11 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (backingStore)
|
||||||
|
VIR_FREE(*backingStore);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WITH_STORAGE_FS
|
#if WITH_STORAGE_FS
|
||||||
@ -585,6 +603,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
while ((ent = readdir(dir)) != NULL) {
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
int ret;
|
int ret;
|
||||||
char *backingStore;
|
char *backingStore;
|
||||||
|
int backingStoreFormat;
|
||||||
|
|
||||||
if (VIR_ALLOC(vol) < 0)
|
if (VIR_ALLOC(vol) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
@ -604,6 +623,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
if ((ret = virStorageBackendProbeTarget(&vol->target,
|
if ((ret = virStorageBackendProbeTarget(&vol->target,
|
||||||
&backingStore,
|
&backingStore,
|
||||||
|
&backingStoreFormat,
|
||||||
&vol->allocation,
|
&vol->allocation,
|
||||||
&vol->capacity,
|
&vol->capacity,
|
||||||
&vol->target.encryption)) < 0) {
|
&vol->target.encryption)) < 0) {
|
||||||
@ -619,44 +639,16 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (backingStore != NULL) {
|
if (backingStore != NULL) {
|
||||||
if (vol->target.format == VIR_STORAGE_FILE_QCOW2 &&
|
|
||||||
STRPREFIX("fmt:", backingStore)) {
|
|
||||||
char *fmtstr = backingStore + 4;
|
|
||||||
char *path = strchr(fmtstr, ':');
|
|
||||||
if (!path) {
|
|
||||||
VIR_FREE(backingStore);
|
|
||||||
} else {
|
|
||||||
*path = '\0';
|
|
||||||
if ((vol->backingStore.format =
|
|
||||||
virStorageFileFormatTypeFromString(fmtstr)) < 0) {
|
|
||||||
VIR_FREE(backingStore);
|
|
||||||
} else {
|
|
||||||
memmove(backingStore, path, strlen(path) + 1);
|
|
||||||
vol->backingStore.path = backingStore;
|
vol->backingStore.path = backingStore;
|
||||||
|
vol->backingStore.format = backingStoreFormat;
|
||||||
|
|
||||||
if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
|
if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
|
||||||
NULL,
|
NULL,
|
||||||
NULL) < 0)
|
NULL) < 0) {
|
||||||
VIR_FREE(vol->backingStore);
|
VIR_FREE(vol->backingStore.path);
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vol->backingStore.path = backingStore;
|
|
||||||
|
|
||||||
if ((ret = virStorageBackendProbeTarget(&vol->backingStore,
|
|
||||||
NULL, NULL, NULL,
|
|
||||||
NULL)) < 0) {
|
|
||||||
if (ret == -1)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
else {
|
|
||||||
/* Silently ignore non-regular files,
|
|
||||||
* eg '.' '..', 'lost+found' */
|
|
||||||
VIR_FREE(vol->backingStore);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (VIR_REALLOC_N(pool->volumes.objs,
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
||||||
|
Loading…
Reference in New Issue
Block a user