提交 05e702cf 编写于 作者: E Eric Blake

getstats: rearrange blockinfo gathering

Ultimately, we want to avoid read()ing a file while qemu is running.
We still have to open() block devices to determine their physical
size, but that is safer.  This patch rearranges code to group
together all code that reads the image, to make it easier for later
patches to skip the metadata collection when possible.

* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Check for empty
disk up front.  Place metadata reading next to use.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 b1802714
......@@ -11057,6 +11057,12 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
disk = vm->def->disks[idx];
src = disk->src;
if (virStorageSourceIsEmpty(src)) {
virReportError(VIR_ERR_INVALID_ARG,
_("disk '%s' does not currently have a source assigned"),
path);
goto endjob;
}
/* FIXME: For an offline domain, we always want to check current
* on-disk statistics (as users have been known to change offline
......@@ -11079,13 +11085,6 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
* change.
*/
if (virStorageSourceIsLocalStorage(src)) {
if (!src->path) {
virReportError(VIR_ERR_INVALID_ARG,
_("disk '%s' does not currently have a source assigned"),
path);
goto endjob;
}
if ((fd = qemuOpenFile(driver, vm, src->path, O_RDONLY,
NULL, NULL)) == -1)
goto endjob;
......@@ -11116,26 +11115,6 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
}
}
/* Probe for magic formats */
if (virDomainDiskGetFormat(disk)) {
format = virDomainDiskGetFormat(disk);
} else {
if (!cfg->allowDiskFormatProbing) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("no disk format for %s and probing is disabled"),
path);
goto endjob;
}
if ((format = virStorageFileProbeFormatFromBuf(src->path,
buf, len)) < 0)
goto endjob;
}
if (!(meta = virStorageFileGetMetadataFromBuf(src->path, buf, len,
format, NULL)))
goto endjob;
/* Get info for normal formats */
if (S_ISREG(sb.st_mode) || fd == -1) {
#ifndef WIN32
......@@ -11164,6 +11143,22 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
/* If the file we probed has a capacity set, then override
* what we calculated from file/block extents */
/* Probe for magic formats */
if (!(format = src->format)) {
if (!cfg->allowDiskFormatProbing) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("no disk format for %s and probing is disabled"),
path);
goto endjob;
}
if ((format = virStorageFileProbeFormatFromBuf(src->path,
buf, len)) < 0)
goto endjob;
}
if (!(meta = virStorageFileGetMetadataFromBuf(src->path, buf, len,
format, NULL)))
goto endjob;
if (meta->capacity)
src->capacity = meta->capacity;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册