From 7357975000ee5d545b5e66df0a1050906c79ed89 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 10 Feb 2010 17:46:44 +0000 Subject: [PATCH] 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 --- src/qemu/qemu_conf.c | 4 ++-- src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_monitor_json.c | 7 +++++++ src/qemu/qemu_monitor_text.c | 7 +++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 3988582544..c1d03cd909 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -2301,7 +2301,7 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, virBufferAddLit(&opt, ",media=cdrom"); 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 { if (busid == -1 && unitid == -1) { if (idx != -1) @@ -2390,7 +2390,7 @@ qemuBuildDriveDevStr(virDomainDiskDefPtr disk) _("unsupported disk bus '%s' with device setup"), bus); 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); if (virBufferError(&opt)) { diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index d26bb9093b..498f1d1051 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -157,6 +157,8 @@ typedef qemuDomainPCIAddressSet *qemuDomainPCIAddressSetPtr; /* Config type for XML import/export conversions */ #define QEMU_CONFIG_FORMAT_ARGV "qemu-argv" +#define QEMU_DRIVE_HOST_PREFIX "drive-" + #define qemuReportError(code, fmt...) \ virReportErrorHelper(NULL, VIR_FROM_QEMU, code, __FILE__, \ __FUNCTION__, __LINE__, fmt) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e5288ce26e..032afef1b6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -754,6 +754,13 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, 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)) continue; diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 23fc4cff1a..a6a4598e3a 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -649,6 +649,13 @@ int qemuMonitorTextGetBlockStatsInfo(qemuMonitorPtr mon, p = info; 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) && p[devnamelen] == ':' && p[devnamelen+1] == ' ') { -- GitLab