[libvirt] [PATCH] Fix disk stats retrieval with QEMU >= 0.12

Daniel Veillard veillard at redhat.com
Wed Feb 10 21:38:21 UTC 2010


On Wed, Feb 10, 2010 at 05:49:15PM +0000, Daniel P. Berrange wrote:
> 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 3988582..c1d03cd 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 d26bb90..498f1d1 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 e5288ce..032afef 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 23fc4cf..a6a4598 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] == ' ') {
>  

ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list