[V4,4/4,-,Updated] Qemu: Add commandline -drive option 'hostcache'

Submitted by supriya kannery on July 5, 2011, 11:05 a.m.

Details

Message ID 4E12EFEC.4040408@in.ibm.com
State New
Headers show

Commit Message

supriya kannery July 5, 2011, 11:05 a.m.
Updated patch to use qemu_opt_get_bool() instead of qemu_opt_get()
to read 'hostcache'

-------------------------------------------------------------------
qemu command option 'hostcache' added to -drive for block devices.
While starting a VM from qemu commandline, this option can be used
for setting host cache usage for block data access. It is not
allowed to specify both 'hostcache' and 'cache' options in the same
commandline. User has to specify only one among these.

Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>

---
  blockdev.c      |   13 +++++++++++++
  qemu-config.c   |    4 ++++
  qemu-options.hx |    2 +-
  3 files changed, 18 insertions(+), 1 deletion(-)

Comments

supriya kannery July 20, 2011, 7:39 a.m.
On 07/05/2011 04:35 PM, Supriya Kannery wrote:
> Updated patch to use qemu_opt_get_bool() instead of qemu_opt_get()
> to read 'hostcache'
>
> -------------------------------------------------------------------
> qemu command option 'hostcache' added to -drive for block devices.
> While starting a VM from qemu commandline, this option can be used
> for setting host cache usage for block data access. It is not
> allowed to specify both 'hostcache' and 'cache' options in the same
> commandline. User has to specify only one among these.
>
> Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
>
> ---
> blockdev.c | 13 +++++++++++++
> qemu-config.c | 4 ++++
> qemu-options.hx | 2 +-
> 3 files changed, 18 insertions(+), 1 deletion(-)
>
> Index: qemu/blockdev.c
> ===================================================================
> --- qemu.orig/blockdev.c
> +++ qemu/blockdev.c
> @@ -238,6 +238,7 @@ DriveInfo *drive_init(QemuOpts *opts, in
> DriveInfo *dinfo;
> int snapshot = 0;
> int ret;
> + int hostcache = 0;
>
> translation = BIOS_ATA_TRANSLATION_AUTO;
>
> @@ -324,7 +325,19 @@ DriveInfo *drive_init(QemuOpts *opts, in
> }
> }
>
> + if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {
> + if (!hostcache) {
> + bdrv_flags |= BDRV_O_NOCACHE;
> + } else {
> + bdrv_flags &= ~BDRV_O_NOCACHE;
> + }
> + }
> +
> if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
> + if (hostcache != -1) {
> + error_report("'hostcache' and 'cache' cannot co-exist");
> + return NULL;
> + }
> if (!strcmp(buf, "off") || !strcmp(buf, "none")) {
> bdrv_flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
> } else if (!strcmp(buf, "writeback")) {
> Index: qemu/qemu-options.hx
> ===================================================================
> --- qemu.orig/qemu-options.hx
> +++ qemu/qemu-options.hx
> @@ -120,7 +120,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive,
> " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
> " [,cache=writethrough|writeback|none|unsafe][,format=f]\n"
> " [,serial=s][,addr=A][,id=name][,aio=threads|native]\n"
> - " [,readonly=on|off]\n"
> + " [,readonly=on|off][,hostcache=on|off]\n"
> " use 'file' as a drive image\n", QEMU_ARCH_ALL)
> STEXI
> @item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
> Index: qemu/qemu-config.c
> ===================================================================
> --- qemu.orig/qemu-config.c
> +++ qemu/qemu-config.c
> @@ -78,6 +78,10 @@ static QemuOptsList qemu_drive_opts = {
> },{
> .name = "readonly",
> .type = QEMU_OPT_BOOL,
> + },{
> + .name = "hostcache",
> + .type = QEMU_OPT_BOOL,
> + .help = "set or reset hostcache (on/off)"
> },
> { /* end of list */ }
> },
>
Please review..

Patch hide | download patch | download mbox

Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -238,6 +238,7 @@  DriveInfo *drive_init(QemuOpts *opts, in
      DriveInfo *dinfo;
      int snapshot = 0;
      int ret;
+    int hostcache = 0;

      translation = BIOS_ATA_TRANSLATION_AUTO;

@@ -324,7 +325,19 @@  DriveInfo *drive_init(QemuOpts *opts, in
  	}
      }

+    if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {
+        if (!hostcache) {
+            bdrv_flags |= BDRV_O_NOCACHE;
+        } else {
+            bdrv_flags &= ~BDRV_O_NOCACHE;
+        }
+    }
+
      if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
+        if (hostcache != -1) {
+            error_report("'hostcache' and 'cache' cannot co-exist");
+            return NULL;
+        }
          if (!strcmp(buf, "off") || !strcmp(buf, "none")) {
              bdrv_flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
          } else if (!strcmp(buf, "writeback")) {
Index: qemu/qemu-options.hx
===================================================================
--- qemu.orig/qemu-options.hx
+++ qemu/qemu-options.hx
@@ -120,7 +120,7 @@  DEF("drive", HAS_ARG, QEMU_OPTION_drive,
      "       [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
      "       [,cache=writethrough|writeback|none|unsafe][,format=f]\n"
      "       [,serial=s][,addr=A][,id=name][,aio=threads|native]\n"
-    "       [,readonly=on|off]\n"
+    "       [,readonly=on|off][,hostcache=on|off]\n"
      "                use 'file' as a drive image\n", QEMU_ARCH_ALL)
  STEXI
  @item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
Index: qemu/qemu-config.c
===================================================================
--- qemu.orig/qemu-config.c
+++ qemu/qemu-config.c
@@ -78,6 +78,10 @@  static QemuOptsList qemu_drive_opts = {
          },{
              .name = "readonly",
              .type = QEMU_OPT_BOOL,
+        },{
+            .name = "hostcache",
+            .type = QEMU_OPT_BOOL,
+            .help = "set or reset hostcache (on/off)"
          },
          { /* end of list */ }
      },