mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
Require format to be passed into virStorageFileGetMetadata
Require the disk image to be passed into virStorageFileGetMetadata. If this is set to VIR_STORAGE_FILE_AUTO, then the format will be resolved using probing. This makes it easier to control when probing will be used * src/qemu/qemu_driver.c, src/qemu/qemu_security_dac.c, src/security/security_selinux.c, src/security/virt-aa-helper.c: Set VIR_STORAGE_FILE_AUTO when calling virStorageFileGetMetadata. * src/storage/storage_backend_fs.c: Probe for disk format before calling virStorageFileGetMetadata. * src/util/storage_file.h, src/util/storage_file.c: Remove format from virStorageFileMeta struct & require it to be passed into method.
This commit is contained in:
parent
c70cb0f49b
commit
bf80fc68ca
@ -3073,7 +3073,9 @@ static int qemuSetupDiskCgroup(virCgroupPtr cgroup,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = virStorageFileGetMetadata(path, &meta);
|
rc = virStorageFileGetMetadata(path,
|
||||||
|
VIR_STORAGE_FILE_AUTO,
|
||||||
|
&meta);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
VIR_WARN("Unable to lookup parent image for %s", path);
|
VIR_WARN("Unable to lookup parent image for %s", path);
|
||||||
|
|
||||||
@ -3123,7 +3125,9 @@ static int qemuTeardownDiskCgroup(virCgroupPtr cgroup,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = virStorageFileGetMetadata(path, &meta);
|
rc = virStorageFileGetMetadata(path,
|
||||||
|
VIR_STORAGE_FILE_AUTO,
|
||||||
|
&meta);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
VIR_WARN("Unable to lookup parent image for %s", path);
|
VIR_WARN("Unable to lookup parent image for %s", path);
|
||||||
|
|
||||||
@ -9618,6 +9622,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
|
|||||||
virDomainDiskDefPtr disk = NULL;
|
virDomainDiskDefPtr disk = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int i;
|
int i;
|
||||||
|
int format;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -9662,7 +9667,21 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Probe for magic formats */
|
/* Probe for magic formats */
|
||||||
if (virStorageFileGetMetadataFromFD(path, fd, &meta) < 0)
|
if (disk->driverType) {
|
||||||
|
if ((format = virStorageFileFormatTypeFromString(disk->driverType)) < 0) {
|
||||||
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("unknown disk format %s for %s"),
|
||||||
|
disk->driverType, disk->src);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((format = virStorageFileProbeFormat(disk->src)) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virStorageFileGetMetadataFromFD(path, fd,
|
||||||
|
format,
|
||||||
|
&meta) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Get info for normal formats */
|
/* Get info for normal formats */
|
||||||
@ -9710,7 +9729,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
|
|||||||
highest allocated extent from QEMU */
|
highest allocated extent from QEMU */
|
||||||
if (virDomainObjIsActive(vm) &&
|
if (virDomainObjIsActive(vm) &&
|
||||||
disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
|
disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
|
||||||
meta.format != VIR_STORAGE_FILE_RAW &&
|
format != VIR_STORAGE_FILE_RAW &&
|
||||||
S_ISBLK(sb.st_mode)) {
|
S_ISBLK(sb.st_mode)) {
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
if (qemuDomainObjBeginJob(vm) < 0)
|
if (qemuDomainObjBeginJob(vm) < 0)
|
||||||
|
@ -115,7 +115,9 @@ qemuSecurityDACSetSecurityImageLabel(virDomainObjPtr vm ATTRIBUTE_UNUSED,
|
|||||||
virStorageFileMetadata meta;
|
virStorageFileMetadata meta;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = virStorageFileGetMetadata(path, &meta);
|
ret = virStorageFileGetMetadata(path,
|
||||||
|
VIR_STORAGE_FILE_AUTO,
|
||||||
|
&meta);
|
||||||
|
|
||||||
if (path != disk->src)
|
if (path != disk->src)
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
|
@ -457,7 +457,9 @@ SELinuxSetSecurityImageLabel(virDomainObjPtr vm,
|
|||||||
virStorageFileMetadata meta;
|
virStorageFileMetadata meta;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = virStorageFileGetMetadata(path, &meta);
|
ret = virStorageFileGetMetadata(path,
|
||||||
|
VIR_STORAGE_FILE_AUTO,
|
||||||
|
&meta);
|
||||||
|
|
||||||
if (path != disk->src)
|
if (path != disk->src)
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
|
@ -830,7 +830,9 @@ get_files(vahControl * ctl)
|
|||||||
do {
|
do {
|
||||||
virStorageFileMetadata meta;
|
virStorageFileMetadata meta;
|
||||||
|
|
||||||
ret = virStorageFileGetMetadata(path, &meta);
|
ret = virStorageFileGetMetadata(path,
|
||||||
|
VIR_STORAGE_FILE_AUTO,
|
||||||
|
&meta);
|
||||||
|
|
||||||
if (path != ctl->def->disks[i]->src)
|
if (path != ctl->def->disks[i]->src)
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
|
@ -75,15 +75,20 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
|
|||||||
|
|
||||||
memset(&meta, 0, sizeof(meta));
|
memset(&meta, 0, sizeof(meta));
|
||||||
|
|
||||||
if (virStorageFileGetMetadataFromFD(target->path, fd, &meta) < 0) {
|
if ((target->format = virStorageFileProbeFormatFromFD(target->path, fd)) < 0) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virStorageFileGetMetadataFromFD(target->path, fd,
|
||||||
|
target->format,
|
||||||
|
&meta) < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
target->format = meta.format;
|
|
||||||
|
|
||||||
if (backingStore) {
|
if (backingStore) {
|
||||||
*backingStore = meta.backingStore;
|
*backingStore = meta.backingStore;
|
||||||
meta.backingStore = NULL;
|
meta.backingStore = NULL;
|
||||||
|
@ -696,18 +696,23 @@ virStorageFileProbeFormat(const char *path)
|
|||||||
/**
|
/**
|
||||||
* virStorageFileGetMetadataFromFD:
|
* virStorageFileGetMetadataFromFD:
|
||||||
*
|
*
|
||||||
* Probe for the format of 'fd' (which is an open file descriptor
|
* Extract metadata about the storage volume with the specified
|
||||||
* for the file 'path'), filling 'meta' with the detected
|
* image format. If image format is VIR_STORAGE_FILE_AUTO, it
|
||||||
* format and other associated metadata.
|
* will probe to automatically identify the format.
|
||||||
*
|
*
|
||||||
* Callers are advised never to trust the returned 'meta->format'
|
* Callers are advised never to use VIR_STORAGE_FILE_AUTO as a
|
||||||
* unless it is listed as VIR_STORAGE_FILE_RAW, since a
|
* format, since a malicious guest can turn a raw file into any
|
||||||
* malicious guest can turn a raw file into any other non-raw
|
* other non-raw format at will.
|
||||||
* format at will.
|
*
|
||||||
|
* If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO
|
||||||
|
* it indicates the image didn't specify an explicit format for its
|
||||||
|
* backing store. Callers are advised against probing for the
|
||||||
|
* backing store format in this case.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virStorageFileGetMetadataFromFD(const char *path,
|
virStorageFileGetMetadataFromFD(const char *path,
|
||||||
int fd,
|
int fd,
|
||||||
|
int format,
|
||||||
virStorageFileMetadata *meta)
|
virStorageFileMetadata *meta)
|
||||||
{
|
{
|
||||||
unsigned char *head;
|
unsigned char *head;
|
||||||
@ -731,9 +736,16 @@ virStorageFileGetMetadataFromFD(const char *path,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
meta->format = virStorageFileProbeFormatFromBuf(path, head, len);
|
if (format == VIR_STORAGE_FILE_AUTO)
|
||||||
|
format = virStorageFileProbeFormatFromBuf(path, head, len);
|
||||||
|
|
||||||
ret = virStorageFileGetMetadataFromBuf(meta->format, path, head, len, meta);
|
if (format < 0 ||
|
||||||
|
format >= VIR_STORAGE_FILE_LAST) {
|
||||||
|
virReportSystemError(EINVAL, _("unknown storage file format %d"), format);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = virStorageFileGetMetadataFromBuf(format, path, head, len, meta);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(head);
|
VIR_FREE(head);
|
||||||
@ -743,16 +755,22 @@ cleanup:
|
|||||||
/**
|
/**
|
||||||
* virStorageFileGetMetadata:
|
* virStorageFileGetMetadata:
|
||||||
*
|
*
|
||||||
* Probe for the format of 'path', filling 'meta' with the detected
|
* Extract metadata about the storage volume with the specified
|
||||||
* format and other associated metadata.
|
* image format. If image format is VIR_STORAGE_FILE_AUTO, it
|
||||||
|
* will probe to automatically identify the format.
|
||||||
*
|
*
|
||||||
* Callers are advised never to trust the returned 'meta->format'
|
* Callers are advised never to use VIR_STORAGE_FILE_AUTO as a
|
||||||
* unless it is listed as VIR_STORAGE_FILE_RAW, since a
|
* format, since a malicious guest can turn a raw file into any
|
||||||
* malicious guest can turn a raw file into any other non-raw
|
* other non-raw format at will.
|
||||||
* format at will.
|
*
|
||||||
|
* If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO
|
||||||
|
* it indicates the image didn't specify an explicit format for its
|
||||||
|
* backing store. Callers are advised against probing for the
|
||||||
|
* backing store format in this case.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virStorageFileGetMetadata(const char *path,
|
virStorageFileGetMetadata(const char *path,
|
||||||
|
int format,
|
||||||
virStorageFileMetadata *meta)
|
virStorageFileMetadata *meta)
|
||||||
{
|
{
|
||||||
int fd, ret;
|
int fd, ret;
|
||||||
@ -762,7 +780,7 @@ virStorageFileGetMetadata(const char *path,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virStorageFileGetMetadataFromFD(path, fd, meta);
|
ret = virStorageFileGetMetadataFromFD(path, fd, format, meta);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ enum virStorageFileFormat {
|
|||||||
VIR_ENUM_DECL(virStorageFileFormat);
|
VIR_ENUM_DECL(virStorageFileFormat);
|
||||||
|
|
||||||
typedef struct _virStorageFileMetadata {
|
typedef struct _virStorageFileMetadata {
|
||||||
int format;
|
|
||||||
char *backingStore;
|
char *backingStore;
|
||||||
int backingStoreFormat;
|
int backingStoreFormat;
|
||||||
unsigned long long capacity;
|
unsigned long long capacity;
|
||||||
@ -62,9 +61,11 @@ int virStorageFileProbeFormatFromFD(const char *path,
|
|||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
int virStorageFileGetMetadata(const char *path,
|
int virStorageFileGetMetadata(const char *path,
|
||||||
|
int format,
|
||||||
virStorageFileMetadata *meta);
|
virStorageFileMetadata *meta);
|
||||||
int virStorageFileGetMetadataFromFD(const char *path,
|
int virStorageFileGetMetadataFromFD(const char *path,
|
||||||
int fd,
|
int fd,
|
||||||
|
int format,
|
||||||
virStorageFileMetadata *meta);
|
virStorageFileMetadata *meta);
|
||||||
|
|
||||||
int virStorageFileIsSharedFS(const char *path);
|
int virStorageFileIsSharedFS(const char *path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user