]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Fix disk stats retrieval with QEMU >= 0.12
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 10 Feb 2010 17:46:44 +0000 (17:46 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 11 Feb 2010 12:07:23 +0000 (12:07 +0000)
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
src/qemu/qemu_conf.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_text.c

index 39885825442ded51df5caf43b5802b23a89cc40e..c1d03cd909281cdb288dd93d59fe87fd319d4886 100644 (file)
@@ -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)) {
index d26bb9093be35e72fd358437bb49a7a6981f5fab..498f1d1051cc41ee227945034a850c31f8fd2fac 100644 (file)
@@ -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)
index e5288ce26ebabf13fb6b759082519df0f57b8017..032afef1b6bba1d2c52d6c16283858255bd2d7fc 100644 (file)
@@ -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;
 
index 23fc4cff1acc7820d67141203bf3d8dea7ef5617..a6a4598e3a4123975e38afcd95fd2d3944451b0d 100644 (file)
@@ -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] == ' ') {