1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Fix disk stats retrieval with QEMU >= 0.12

With QEMU >= 0.12 the host and guest side of disks no longer have
the same naming convention. Specifically the host side will now
get a 'drive-' prefix added to its name. The 'info blockstats'
monitor command returns the host side name, so it is neccessary
to strip this off when looking up stats since libvirt stores the
guest side name !

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Move 'drive-' prefix
  string to a defined constant
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_text.c: Strip
  off 'drive-' prefix (if found) when looking up disk stats
This commit is contained in:
Daniel P. Berrange 2010-02-10 17:46:44 +00:00
parent d3024a2cce
commit 7357975000
4 changed files with 18 additions and 2 deletions

View File

@ -2301,7 +2301,7 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
virBufferAddLit(&opt, ",media=cdrom"); virBufferAddLit(&opt, ",media=cdrom");
if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) { if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
virBufferVSprintf(&opt, ",id=drive-%s", disk->info.alias); virBufferVSprintf(&opt, ",id=%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
} else { } else {
if (busid == -1 && unitid == -1) { if (busid == -1 && unitid == -1) {
if (idx != -1) if (idx != -1)
@ -2390,7 +2390,7 @@ qemuBuildDriveDevStr(virDomainDiskDefPtr disk)
_("unsupported disk bus '%s' with device setup"), bus); _("unsupported disk bus '%s' with device setup"), bus);
goto error; goto error;
} }
virBufferVSprintf(&opt, ",drive=drive-%s", disk->info.alias); virBufferVSprintf(&opt, ",drive=%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
virBufferVSprintf(&opt, ",id=%s", disk->info.alias); virBufferVSprintf(&opt, ",id=%s", disk->info.alias);
if (virBufferError(&opt)) { if (virBufferError(&opt)) {

View File

@ -157,6 +157,8 @@ typedef qemuDomainPCIAddressSet *qemuDomainPCIAddressSetPtr;
/* Config type for XML import/export conversions */ /* Config type for XML import/export conversions */
#define QEMU_CONFIG_FORMAT_ARGV "qemu-argv" #define QEMU_CONFIG_FORMAT_ARGV "qemu-argv"
#define QEMU_DRIVE_HOST_PREFIX "drive-"
#define qemuReportError(code, fmt...) \ #define qemuReportError(code, fmt...) \
virReportErrorHelper(NULL, VIR_FROM_QEMU, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_QEMU, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)

View File

@ -754,6 +754,13 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
/* New QEMU has separate names for host & guest side of the disk
* and libvirt gives the host side a 'drive-' prefix. The passed
* in devname is the guest side though
*/
if (STRPREFIX(thisdev, QEMU_DRIVE_HOST_PREFIX))
thisdev += strlen(QEMU_DRIVE_HOST_PREFIX);
if (STRNEQ(thisdev, devname)) if (STRNEQ(thisdev, devname))
continue; continue;

View File

@ -649,6 +649,13 @@ int qemuMonitorTextGetBlockStatsInfo(qemuMonitorPtr mon,
p = info; p = info;
while (*p) { while (*p) {
/* New QEMU has separate names for host & guest side of the disk
* and libvirt gives the host side a 'drive-' prefix. The passed
* in devname is the guest side though
*/
if (STRPREFIX(p, QEMU_DRIVE_HOST_PREFIX))
p += strlen(QEMU_DRIVE_HOST_PREFIX);
if (STREQLEN (p, devname, devnamelen) if (STREQLEN (p, devname, devnamelen)
&& p[devnamelen] == ':' && p[devnamelen+1] == ' ') { && p[devnamelen] == ':' && p[devnamelen+1] == ' ') {