[libvirt] [PATCH 3/3] qemu: fix block stats for virtio and scsi

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
use qemudDiskDeviceName to determine the block device name (as suggested
by Cole).
 -- Guido
>From 6985fee585561b04942036d283632e7cb2bb708f Mon Sep 17 00:00:00 2001
From: Guido Guenther <agx@xxxxxxxxxxx>
Date: Thu, 2 Oct 2008 21:12:20 +0200
Subject: [PATCH] support virtio and scsi disks in qemudDomainBlockStats

---
 src/qemu_driver.c |   56 ++++++++++++++++++++++++----------------------------
 1 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index b2ea0d1..5ffaf21 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -3397,11 +3397,13 @@ qemudDomainBlockStats (virDomainPtr dom,
 {
     const struct qemud_driver *driver =
         (struct qemud_driver *)dom->conn->privateData;
-    char *dummy, *info;
+    char *dummy, *info = NULL;
     const char *p, *eol;
-    char qemu_dev_name[32];
+    const char *qemu_dev_name = NULL;
     size_t len;
+    int ret = -1;
     const virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id);
+    virDomainDiskDefPtr disk;
 
     if (!vm) {
         qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@@ -3414,34 +3416,31 @@ qemudDomainBlockStats (virDomainPtr dom,
         return -1;
     }
 
-    /*
-     * QEMU internal block device names are different from the device
-     * names we use in libvirt, so we need to map between them:
-     *
-     *   hd[a-]   to  ide0-hd[0-]
-     *   cdrom    to  ide1-cd0
-     *   fd[a-]   to  floppy[0-]
-     */
-    if (STRPREFIX (path, "hd") && c_islower(path[2]))
-        snprintf (qemu_dev_name, sizeof (qemu_dev_name),
-                  "ide0-hd%d", path[2] - 'a');
-    else if (STREQ (path, "cdrom"))
-        strcpy (qemu_dev_name, "ide1-cd0");
-    else if (STRPREFIX (path, "fd") && c_islower(path[2]))
-        snprintf (qemu_dev_name, sizeof (qemu_dev_name),
-                  "floppy%d", path[2] - 'a');
-    else {
+    disk = vm->def->disks;
+    while (disk) {
+        if (STREQ(disk->dst, path))
+            break;
+        disk = disk->next;
+    }
+
+    if (!disk) {
         qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
                           _("invalid path: %s"), path);
         return -1;
     }
 
+    qemu_dev_name = qemudDiskDeviceName(dom, disk);
+    if (!qemu_dev_name) {
+        qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
+                          _("unknown path %s"), path);
+        return -1;
+    }
     len = strlen (qemu_dev_name);
 
     if (qemudMonitorCommand (driver, vm, "info blockstats", &info) < 0) {
         qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
                           "%s", _("'info blockstats' command failed"));
-        return -1;
+        goto out;
     }
 
     DEBUG ("info blockstats reply: %s", info);
@@ -3452,11 +3451,10 @@ qemudDomainBlockStats (virDomainPtr dom,
      * to detect if qemu supports the command.
      */
     if (STRPREFIX (info, "info ")) {
-        free (info);
         qemudReportError (dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
                           "%s",
                           _("'info blockstats' not supported by this qemu"));
-        return -1;
+        goto out;
     }
 
     stats->rd_req = -1;
@@ -3507,8 +3505,8 @@ qemudDomainBlockStats (virDomainPtr dom,
                 if (!p || p >= eol) break;
                 p++;
             }
-
-            goto done;
+            ret = 0;
+            goto out;
         }
 
         /* Skip to next line. */
@@ -3518,14 +3516,12 @@ qemudDomainBlockStats (virDomainPtr dom,
     }
 
     /* If we reach here then the device was not found. */
-    free (info);
     qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
                       _("device not found: %s (%s)"), path, qemu_dev_name);
-    return -1;
-
- done:
-    free (info);
-    return 0;
+ out:
+    VIR_FREE(qemu_dev_name);
+    VIR_FREE(info);
+    return ret;
 }
 
 static int
-- 
1.5.6.5

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]