qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Supriya Kannery <supriyak@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Supriya Kannery <supriyak@linux.vnet.ibm.com>,
	Christoph Hellwig <hch@lst.de>,
	Prerna Saxena <prerna@linux.vnet.ibm.com>
Subject: [Qemu-devel] [RFC Patch 3/3]Qemu: Add command "cache_set" for dynamic cache change
Date: Mon, 16 May 2011 23:41:04 +0530	[thread overview]
Message-ID: <20110516181104.7142.11570.sendpatchset@skannery> (raw)
In-Reply-To: <20110516181023.7142.33402.sendpatchset@skannery>

Add monitor command "cache_set" for dynamic cache change

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>

---
 block.c         |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 block.h         |    2 ++
 blockdev.c      |   20 ++++++++++++++++++++
 blockdev.h      |    1 +
 hmp-commands.hx |   14 ++++++++++++++
 qmp-commands.hx |   28 ++++++++++++++++++++++++++++
 6 files changed, 118 insertions(+)

Index: qemu/hmp-commands.hx
===================================================================
--- qemu.orig/hmp-commands.hx
+++ qemu/hmp-commands.hx
@@ -70,6 +70,20 @@ but should be used with extreme caution.
 resizes image files, it can not resize block devices like LVM volumes.
 ETEXI
 
+    {
+        .name       = "cache_set",
+        .args_type  = "device:B,cache:s",
+        .params     = "device cache",
+        .help       = "change cache setting for device",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_cache_set,
+    },
+
+STEXI
+@item cache_set
+@findex cache_set
+Change cache options for a block device while guest is running.
+ETEXI
 
     {
         .name       = "eject",
Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -657,6 +657,34 @@ unlink_and_fail:
     return ret;
 }
 
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
+{
+    BlockDriver *drv = bs->drv;
+    int ret = 0;
+
+    /* No need to reopen as no change in flags */
+    if (bdrv_flags == bs->open_flags) {
+        return 0;
+    }
+
+    /* Quiesce IO for the given block device */
+    qemu_aio_flush();
+    bdrv_flush(bs);
+
+    bdrv_close(bs);
+    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
+
+    /*
+     * A failed attempt to reopen the image file must lead to 'abort()'
+     */
+    if (ret != 0) {
+        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+        abort();
+    }
+
+    return ret;
+}
+
 void bdrv_close(BlockDriverState *bs)
 {
     if (bs->drv) {
@@ -3063,3 +3091,28 @@ out:
 
     return ret;
 }
+
+int bdrv_change_cache(BlockDriverState *bs, const char *cache)
+{
+    int bdrv_flags = 0;
+
+    /* Clear cache flags */
+    bdrv_flags = bs->open_flags & ~BDRV_O_CACHE_MASK;
+
+    /* Set flags for requested cache setting */
+    if (strcmp(cache, "writethrough")) {
+      if (!strcmp(cache, "off") || !strcmp(cache, "none")) {
+            bdrv_flags |= BDRV_O_NOCACHE;
+        } else if (!strcmp(cache, "writeback") || !strcmp(cache, "on")) {
+            bdrv_flags |= BDRV_O_CACHE_WB;
+        } else if (!strcmp(cache, "unsafe")) {
+            bdrv_flags |= BDRV_O_CACHE_WB;
+            bdrv_flags |= BDRV_O_NO_FLUSH;
+        } else {
+           error_report("invalid cache option");
+           return -1;
+        }
+    }
+
+    return(bdrv_reopen(bs, bdrv_flags));
+}
Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -796,3 +796,23 @@ int do_block_resize(Monitor *mon, const 
 
     return 0;
 }
+
+int do_cache_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *device = qdict_get_str(qdict, "device");
+    const char *cache = qdict_get_str(qdict, "cache");
+    BlockDriverState *bs;
+
+    bs = bdrv_find(device);
+    if (!bs) {
+        qerror_report(QERR_DEVICE_NOT_FOUND, device);
+        return -1;
+    }
+
+    if(bdrv_is_inserted(bs)) {
+       return(bdrv_change_cache(bs, cache));
+    } else {
+       qerror_report(QERR_DEVICE_NOT_INSERTED, device);
+       return -1;
+    }
+}
Index: qemu/block.h
===================================================================
--- qemu.orig/block.h
+++ qemu/block.h
@@ -71,6 +71,7 @@ void bdrv_delete(BlockDriverState *bs);
 int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
               BlockDriver *drv);
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags);
 void bdrv_close(BlockDriverState *bs);
 int bdrv_attach(BlockDriverState *bs, DeviceState *qdev);
 void bdrv_detach(BlockDriverState *bs, DeviceState *qdev);
@@ -96,6 +97,7 @@ void bdrv_commit_all(void);
 int bdrv_change_backing_file(BlockDriverState *bs,
     const char *backing_file, const char *backing_fmt);
 void bdrv_register(BlockDriver *bdrv);
+int bdrv_change_cache(BlockDriverState *bs, const char *cache);
 
 
 typedef struct BdrvCheckResult {
Index: qemu/blockdev.h
===================================================================
--- qemu.orig/blockdev.h
+++ qemu/blockdev.h
@@ -64,5 +64,6 @@ int do_change_block(Monitor *mon, const 
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_cache_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 #endif
Index: qemu/qmp-commands.hx
===================================================================
--- qemu.orig/qmp-commands.hx
+++ qemu/qmp-commands.hx
@@ -664,6 +664,34 @@ Example:
 -> { "execute": "block_resize", "arguments": { "device": "scratch", "size": 1073741824 } }
 <- { "return": {} }
 
+
+EQMP
+
+    {
+        .name       = "cache_set",
+        .args_type  = "device:B,cache:s",
+        .params     = "device cache",
+        .help       = "change cache setting for device",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_cache_set,
+    },
+
+SQMP
+cache_set
+---------
+
+Change cache setting while a guest is running.
+
+Arguments:
+
+- "device": the device's ID, must be unique (json-string)
+- "cache": new cache string like none, writethrough etc.. (json-string)
+
+Example:
+
+-> { "execute": "cache_set", "arguments": { "device": "ide0-hd0", "cache": "writeback" } }
+<- { "return": {} }
+
 EQMP
 
     {

  parent reply	other threads:[~2011-05-16 17:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-16 18:10 [Qemu-devel] [RFC Patch 0/3]Qemu: Enable dynamic cache change through qemu monitor Supriya Kannery
2011-05-16 18:10 ` [Qemu-devel] [RFC Patch 1/3]Qemu: Enhance "info block" to display cache setting Supriya Kannery
2011-05-17  8:39   ` Kevin Wolf
2011-05-17  9:00     ` supriya kannery
2011-05-16 18:10 ` [Qemu-devel] [RFC Patch 2/3]Qemu: New error classes for file reopen and device insertion Supriya Kannery
2011-05-16 18:11 ` Supriya Kannery [this message]
2011-05-16 20:23 ` [Qemu-devel] [RFC Patch 0/3]Qemu: Enable dynamic cache change through qemu monitor Christoph Hellwig
2011-05-16 21:10   ` Anthony Liguori
2011-05-17  9:27     ` supriya kannery
2011-05-17 15:41     ` Christoph Hellwig
2011-05-20  5:41       ` Supriya Kannery
2011-05-17  9:18   ` supriya kannery

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110516181104.7142.11570.sendpatchset@skannery \
    --to=supriyak@linux.vnet.ibm.com \
    --cc=hch@lst.de \
    --cc=kwolf@redhat.com \
    --cc=prerna@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).