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

[libvirt] [RFC PATCH] Support for qemu aio drive option



This is a "quick" implementation to support the qemu aio drive option. I tried 
to stay true to the coding style and this has been tested w/ libvirt 0.7.6 and 
works just fine.

Since I am not that familiar w/ the inner workings of libvirt, I am sure I 
missed a few spots, so I hope either someone will base his work on this patch 
or point me into the right direction so I can finish this up for good. :-)

For everyone else, enjoy...

---
 src/conf/domain_conf.c |   23 +++++++++++++++++++++++
 src/conf/domain_conf.h |   10 ++++++++++
 src/qemu/qemu_conf.c   |   14 ++++++++++++++
 src/qemu/qemu_conf.h   |    2 ++
 4 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 766993c..8bee7b8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -120,6 +120,11 @@ VIR_ENUM_IMPL(virDomainDiskCache, 
VIR_DOMAIN_DISK_CACHE_LAST,
               "writethrough",
               "writeback")
 
+VIR_ENUM_IMPL(virDomainDiskAIO, VIR_DOMAIN_DISK_AIO_LAST,
+              "default",
+              "native",
+              "threads")
+
 VIR_ENUM_IMPL(virDomainController, VIR_DOMAIN_CONTROLLER_TYPE_LAST,
               "ide",
               "fdc",
@@ -1228,6 +1233,7 @@ virDomainDiskDefParseXML(virConnectPtr conn,
     char *target = NULL;
     char *bus = NULL;
     char *cachetag = NULL;
+    char *aiotag = NULL;
     char *devaddr = NULL;
     virStorageEncryptionPtr encryption = NULL;
     char *serial = NULL;
@@ -1293,6 +1299,7 @@ virDomainDiskDefParseXML(virConnectPtr conn,
                 driverName = virXMLPropString(cur, "name");
                 driverType = virXMLPropString(cur, "type");
                 cachetag = virXMLPropString(cur, "cache");
+                aiotag = virXMLPropString(cur, "aio");
             } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
                 def->readonly = 1;
             } else if (xmlStrEqual(cur->name, BAD_CAST "shareable")) {
@@ -1409,6 +1416,13 @@ virDomainDiskDefParseXML(virConnectPtr conn,
         goto error;
     }
 
+    if (aiotag &&
+        (def->aiomode = virDomainDiskAIOTypeFromString(aiotag)) < 0) {
+        virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                             _("unknown disk aio mode '%s'"), aiotag);
+        goto error;
+    }
+
     if (devaddr) {
         if (sscanf(devaddr, "%x:%x:%x",
                    &def->info.addr.pci.domain,
@@ -1450,6 +1464,7 @@ cleanup:
     VIR_FREE(driverType);
     VIR_FREE(driverName);
     VIR_FREE(cachetag);
+    VIR_FREE(aiotag);
     VIR_FREE(devaddr);
     VIR_FREE(serial);
     virStorageEncryptionFree(encryption);
@@ -4565,6 +4580,7 @@ virDomainDiskDefFormat(virConnectPtr conn,
     const char *device = virDomainDiskDeviceTypeToString(def->device);
     const char *bus = virDomainDiskBusTypeToString(def->bus);
     const char *cachemode = virDomainDiskCacheTypeToString(def->cachemode);
+    const char *aiomode = virDomainDiskAIOTypeToString(def->aiomode);
 
     if (!type) {
         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -4586,6 +4602,11 @@ virDomainDiskDefFormat(virConnectPtr conn,
                              _("unexpected disk cache mode %d"), def-
>cachemode);
         return -1;
     }
+    if (!aiomode) {
+        virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                             _("unexpected disk aio mode %d"), def->aiomode);
+        return -1;
+    }
 
     virBufferVSprintf(buf,
                       "    <disk type='%s' device='%s'>\n",
@@ -4597,6 +4618,8 @@ virDomainDiskDefFormat(virConnectPtr conn,
             virBufferVSprintf(buf, " type='%s'", def->driverType);
         if (def->cachemode)
             virBufferVSprintf(buf, " cache='%s'", cachemode);
+        if (def->aiomode)
+            virBufferVSprintf(buf, " aio='%s'", aiomode);
         virBufferVSprintf(buf, "/>\n");
     }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0b79e88..07805a6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -141,6 +141,14 @@ enum  virDomainDiskCache {
     VIR_DOMAIN_DISK_CACHE_LAST
 };
 
+enum  virDomainDiskAIO {
+    VIR_DOMAIN_DISK_AIO_DEFAULT,
+    VIR_DOMAIN_DISK_AIO_NATIVE,
+    VIR_DOMAIN_DISK_AIO_THREADS,
+
+    VIR_DOMAIN_DISK_AIO_LAST
+};
+
 /* Stores the virtual disk configuration */
 typedef struct _virDomainDiskDef virDomainDiskDef;
 typedef virDomainDiskDef *virDomainDiskDefPtr;
@@ -154,6 +162,7 @@ struct _virDomainDiskDef {
     char *driverType;
     char *serial;
     int cachemode;
+    int aiomode;
     unsigned int readonly : 1;
     unsigned int shared : 1;
     virDomainDeviceInfo info;
@@ -897,6 +906,7 @@ VIR_ENUM_DECL(virDomainDisk)
 VIR_ENUM_DECL(virDomainDiskDevice)
 VIR_ENUM_DECL(virDomainDiskBus)
 VIR_ENUM_DECL(virDomainDiskCache)
+VIR_ENUM_DECL(virDomainDiskAIO)
 VIR_ENUM_DECL(virDomainController)
 VIR_ENUM_DECL(virDomainFS)
 VIR_ENUM_DECL(virDomainNet)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 3d83a8f..fd3a670 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -83,6 +83,12 @@ VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAIN_DISK_CACHE_LAST,
               "writethrough",
               "writeback");
 
+VIR_ENUM_DECL(qemuDiskAIO)
+VIR_ENUM_IMPL(qemuDiskAIO, VIR_DOMAIN_DISK_AIO_LAST,
+              "default",
+              "native",
+              "threads");
+
 VIR_ENUM_DECL(qemuVideo)
 
 VIR_ENUM_IMPL(qemuVideo, VIR_DOMAIN_VIDEO_TYPE_LAST,
@@ -1137,6 +1143,8 @@ static unsigned int qemudComputeCmdFlags(const char 
*help,
             flags |= QEMUD_CMD_FLAG_DRIVE_CACHE_V2;
         if (strstr(help, "format="))
             flags |= QEMUD_CMD_FLAG_DRIVE_FORMAT;
+        if (strstr(help, "aio=threads|native"))
+            flags |= QEMUD_CMD_FLAG_DRIVE_AIO;
     }
     if (strstr(help, "-vga") && !strstr(help, "-std-vga"))
         flags |= QEMUD_CMD_FLAG_VGA;
@@ -2340,6 +2348,12 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
         virBufferAddLit(&opt, ",cache=off");
     }
 
+    if (disk->aiomode && (qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE_AIO)) {
+        const char * mode = qemuDiskAIOTypeToString(disk->aiomode);
+
+        virBufferVSprintf(&opt, ",aio=%s", mode);
+    }
+
     if (virBufferError(&opt)) {
         virReportOOMError(NULL);
         goto error;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 101f187..780ae6e 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -82,6 +82,8 @@ enum qemud_cmd_flags {
     QEMUD_CMD_FLAG_SDL           = (1 << 27), /* Is the new -sdl arg 
available */
     QEMUD_CMD_FLAG_SMP_TOPOLOGY  = (1 << 28), /* Is 
sockets=s,cores=c,threads=t available for -smp? */
     QEMUD_CMD_FLAG_NETDEV        = (1 << 29), /* The -netdev flag & 
netdev_add/remove monitor commands */
+
+    QEMUD_CMD_FLAG_DRIVE_AIO     = (1 << 30), /* Is -drive aio= avail */
 };
 
 /* Main driver state */
-- 
1.7.0.4


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