All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [V4 Patch 0/4]Qemu: Hostcache setting from cmdline and monitor
@ 2011-07-04 10:42 Supriya Kannery
  2011-07-04 10:42 ` [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-04 10:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Supriya Kannery, Christoph Hellwig


  Currently cache setting of a block device cannot be changed 
without restarting a running VM. Following patchset is for 
enabling dynamic change of cache setting for block devices 
through qemu monitor. Code changes are based on patches 
from Christoph Hellwig and Prerna Saxena.

  This patchset introduces monitor command 'block_set'
using which various parameters for block devices can be 
changed dynamically. Dynamic changing of host cache 
setting is implemented for now. This patchset also 
introduces 'hostcache', a new option for setting host
cache from qemu command line. 'Hostcache and 'cache' options 
cannot be used simultaneously from commandline.

Changes from patchset V3:
 1. Added 'hostcache' option to '-drive' commandline option.

New block command added:
"block_set" 
    -- Sets block device parameters while guest is running.
Usage:
 block_set <device> <param> <value> 
   <device> = block device
   <param>  = parameter (say, "hostcache")
   <value>  = on/off

New 'hostcache' option added to -drive:
 -drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
        ....    
"       [,readonly=on|off][,hostcache=on|off]\n"

 1/4 Enhance "info block" to display hostcache setting
 2/4 New error classes for file reopen and device insertion
 3/4 Command "block_set" for dynamic params change for block device
 4/4 'hostcache' option added to -drive in qemu commandline

 qemu/block.c         |   73 +++++++++++++++++++++++++++++++++++++++++++++++----
 qemu/block.h         |    2 +
 qemu/blockdev.c      |   43 +++++++++++++++++++++++++++++++++++++++++++++++
 qemu/blockdev.h      |    1
 qemu/hmp-commands.hx |   15 ++++++++++++++
 qemu/qemu-config.c   |    4 +++
 qemu/qemu-options.hx |    2 -
 qemu/qemu.pod        |    5 ++++
 qemu/qerror.c        |    8 +++++++
 qemu/qerror.h        |    6 +++++
 qemu/qmp-commands.hx |   30 +++++++++++++++++++++++++++
 11 files changed, 184 insertions(+), 5 deletions(-)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting
  2011-07-04 10:42 [Qemu-devel] [V4 Patch 0/4]Qemu: Hostcache setting from cmdline and monitor Supriya Kannery
@ 2011-07-04 10:42 ` Supriya Kannery
  2011-07-04 11:54   ` Stefan Hajnoczi
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 2/4]Qemu: Error classes for file reopen and data sync failure Supriya Kannery
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Supriya Kannery @ 2011-07-04 10:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Supriya Kannery, Christoph Hellwig

Enhance "info block" to display hostcache setting for each
block device.

Example:
(qemu) info block
ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2
encrypted=0

Enhanced to display "hostcache" setting:
(qemu) info block
ide0-hd0: type=hd removable=0 hostcache=true file=../rhel6-32.qcow2
ro=0 drv=qcow2 encrypted=0

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

---
 block.c         |   21 +++++++++++++++++----
 qmp-commands.hx |    2 ++
 2 files changed, 19 insertions(+), 4 deletions(-)

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -1694,6 +1694,14 @@ static void bdrv_print_dict(QObject *obj
         monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
     }
 
+    if (qdict_haskey(bs_dict, "open_flags")) {
+        int open_flags = qdict_get_int(bs_dict, "open_flags");
+        if (open_flags & BDRV_O_NOCACHE)
+            monitor_printf(mon, " hostcache=false");
+        else
+            monitor_printf(mon, " hostcache=true");
+    }
+
     if (qdict_haskey(bs_dict, "inserted")) {
         QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
 
@@ -1730,13 +1738,18 @@ void bdrv_info(Monitor *mon, QObject **r
         QObject *bs_obj;
 
         bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
-                                    "'removable': %i, 'locked': %i }",
-                                    bs->device_name, bs->removable,
-                                    bs->locked);
+                                     "'removable': %i, 'locked': %i, "
+                                     "'hostcache': %s }",
+                                     bs->device_name, bs->removable,
+                                     bs->locked,
+                                     (bs->open_flags & BDRV_O_NOCACHE) ?
+                                     "false" : "true");
+
+        QDict *bs_dict = qobject_to_qdict(bs_obj);
+        qdict_put(bs_dict, "open_flags", qint_from_int(bs->open_flags));
 
         if (bs->drv) {
             QObject *obj;
-            QDict *bs_dict = qobject_to_qdict(bs_obj);
 
             obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
                                      "'encrypted': %i }",
Index: qemu/qmp-commands.hx
===================================================================
--- qemu.orig/qmp-commands.hx
+++ qemu/qmp-commands.hx
@@ -1070,6 +1070,7 @@ Each json-object contain the following:
          - Possible values: "unknown"
 - "removable": true if the device is removable, false otherwise (json-bool)
 - "locked": true if the device is locked, false otherwise (json-bool)
+- "hostcache": true if hostcache enabled, false otherwise (json-bool)
 - "inserted": only present if the device is inserted, it is a json-object
    containing the following:
          - "file": device file name (json-string)
@@ -1091,6 +1092,7 @@ Example:
          {
             "device":"ide0-hd0",
             "locked":false,
+            "hostcache":false,
             "removable":false,
             "inserted":{
                "ro":false,

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Qemu-devel] [V4 Patch 2/4]Qemu: Error classes for file reopen and data sync failure
  2011-07-04 10:42 [Qemu-devel] [V4 Patch 0/4]Qemu: Hostcache setting from cmdline and monitor Supriya Kannery
  2011-07-04 10:42 ` [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
@ 2011-07-04 10:43 ` Supriya Kannery
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change Supriya Kannery
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 4/4]Qemu: Add commandline -drive option 'hostcache' Supriya Kannery
  3 siblings, 0 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-04 10:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Supriya Kannery, Christoph Hellwig

New error classes defined for cases where device not inserted
and file reopen failed.

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

---
 qerror.c |    8 ++++++++
 qerror.h |    6 ++++++
 2 files changed, 14 insertions(+)

Index: qemu/qerror.c
===================================================================
--- qemu.orig/qerror.c
+++ qemu/qerror.c
@@ -97,6 +97,14 @@ static const QErrorStringTable qerror_ta
         .desc      = "Device '%(device)' is not removable",
     },
     {
+        .error_fmt = QERR_DATA_SYNC_FAILED,
+        .desc      = "Syncing of data failed for device '%(device)'",
+    },
+    {
+        .error_fmt = QERR_REOPEN_FILE_FAILED,
+        .desc      = "Could not reopen '%(filename)'",
+    },
+    {
         .error_fmt = QERR_DEVICE_NO_BUS,
         .desc      = "Device '%(device)' has no child bus",
     },
Index: qemu/qerror.h
===================================================================
--- qemu.orig/qerror.h
+++ qemu/qerror.h
@@ -85,6 +85,9 @@ QError *qobject_to_qerror(const QObject 
 #define QERR_DEVICE_NOT_FOUND \
     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
 
+#define QERR_DATA_SYNC_FAILED \
+    "{ 'class': 'DataSyncFailed', 'data': { 'device': %s } }"
+
 #define QERR_DEVICE_NOT_REMOVABLE \
     "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }"
 
@@ -139,6 +142,9 @@ QError *qobject_to_qerror(const QObject 
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_REOPEN_FILE_FAILED \
+    "{ 'class': 'ReopenFileFailed', 'data': { 'filename': %s } }"
+
 #define QERR_PROPERTY_NOT_FOUND \
     "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change
  2011-07-04 10:42 [Qemu-devel] [V4 Patch 0/4]Qemu: Hostcache setting from cmdline and monitor Supriya Kannery
  2011-07-04 10:42 ` [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 2/4]Qemu: Error classes for file reopen and data sync failure Supriya Kannery
@ 2011-07-04 10:43 ` Supriya Kannery
  2011-07-04 12:29   ` Stefan Hajnoczi
  2011-07-04 12:35   ` [Qemu-devel] [V4 Patch 3/4]Qemu: " Stefan Hajnoczi
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 4/4]Qemu: Add commandline -drive option 'hostcache' Supriya Kannery
  3 siblings, 2 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-04 10:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Supriya Kannery, Christoph Hellwig

New command "block_set" added for dynamically changing any of the block
device parameters. For now, dynamic setting of hostcache params using this
command is implemented. Other block device parameters, can be integrated
in similar lines.

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

---
 block.c         |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 block.h         |    2 ++
 blockdev.c      |   26 ++++++++++++++++++++++++++
 blockdev.h      |    1 +
 hmp-commands.hx |   15 +++++++++++++++
 qmp-commands.hx |   28 ++++++++++++++++++++++++++++
 6 files changed, 124 insertions(+)

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -651,6 +651,32 @@ unlink_and_fail:
     return ret;
 }
 
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
+{
+    BlockDriver *drv = bs->drv;
+    int ret = 0;
+
+    /* Quiesce IO for the given block device */
+    qemu_aio_flush();
+    if (bdrv_flush(bs)) {
+        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
+        return ret;
+    }
+    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) {
@@ -691,6 +717,32 @@ void bdrv_close_all(void)
     }
 }
 
+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
+{
+    int bdrv_flags = bs->open_flags;
+
+    /* set hostcache flags (without changing WCE/flush bits) */
+    if (enable_host_cache) {
+        bdrv_flags &= ~BDRV_O_NOCACHE;
+    } else {
+        bdrv_flags |= BDRV_O_NOCACHE;
+    }
+
+    /* If no change in flags, no need to reopen */
+    if (bdrv_flags == bs->open_flags) {
+        return 0;
+    }
+
+    if (bdrv_is_inserted(bs)) {
+        /* Reopen file with changed set of flags */
+        return bdrv_reopen(bs, bdrv_flags);
+    } else {
+        /* Save hostcache change for future use */
+        bs->open_flags = bdrv_flags;
+        return 0;
+    }
+}
+
 /* make a BlockDriverState anonymous by removing from bdrv_state list.
    Also, NULL terminate the device_name to prevent double remove */
 void bdrv_make_anon(BlockDriverState *bs)
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_hostcache(BlockDriverState *bs, bool enable_host_cache);
 
 
 typedef struct BdrvCheckResult {
Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -797,3 +797,29 @@ int do_block_resize(Monitor *mon, const 
 
     return 0;
 }
+
+
+/*
+ * Handle changes to block device settings, like hostcache,
+ * while guest is running.
+*/
+int do_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *device = qdict_get_str(qdict, "device");
+    const char *name = qdict_get_str(qdict, "name");
+    int enable = qdict_get_bool(qdict, "enable");
+    BlockDriverState *bs;
+
+    bs = bdrv_find(device);
+    if (!bs) {
+        qerror_report(QERR_DEVICE_NOT_FOUND, device);
+        return -1;
+    }
+
+    if (!strcmp(name, "hostcache")) {
+        return bdrv_change_hostcache(bs, enable);
+    }
+
+    return 0;
+}
+
Index: qemu/blockdev.h
===================================================================
--- qemu.orig/blockdev.h
+++ qemu/blockdev.h
@@ -65,5 +65,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_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 #endif
Index: qemu/hmp-commands.hx
===================================================================
--- qemu.orig/hmp-commands.hx
+++ qemu/hmp-commands.hx
@@ -70,6 +70,21 @@ but should be used with extreme caution.
 resizes image files, it can not resize block devices like LVM volumes.
 ETEXI
 
+    {
+        .name       = "block_set",
+        .args_type  = "device:B,name:s,enable:b",
+        .params     = "device name enable",
+        .help       = "On/Off block device parameters like hostcache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set,
+    },
+
+STEXI
+@item block_set
+@findex block_set
+Change block device params (eg:"hostcache"=on/off) while guest is running.
+ETEXI
+
 
     {
         .name       = "eject",
Index: qemu/qmp-commands.hx
===================================================================
--- qemu.orig/qmp-commands.hx
+++ qemu/qmp-commands.hx
@@ -694,6 +694,34 @@ Example:
 EQMP
 
     {
+        .name       = "block_set",
+        .args_type  = "device:B,name:s,enable:b",
+        .params     = "device name enable",
+        .help       = "Enable/Disable block device params like hostcache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set,
+    },
+
+SQMP
+block_set
+---------
+
+Change various block device parameters like hostcache.
+
+Arguments:
+
+- "device": the device's ID, must be unique (json-string)
+- "name": name of the parameter to be changed" (json-string)
+- "enable": value to be set for the parameter, 'true' or 'false' (json-bool)
+
+Example:
+
+-> { "execute": "block_set", "arguments": { "device": "ide0-hd0", "name": "hostcache", "enable": true } }
+<- { "return": {} }
+
+EQMP
+
+	{
         .name       = "balloon",
         .args_type  = "value:M",
         .params     = "target",

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Qemu-devel] [V4 Patch 4/4]Qemu: Add commandline -drive option 'hostcache'
  2011-07-04 10:42 [Qemu-devel] [V4 Patch 0/4]Qemu: Hostcache setting from cmdline and monitor Supriya Kannery
                   ` (2 preceding siblings ...)
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change Supriya Kannery
@ 2011-07-04 10:43 ` Supriya Kannery
  2011-07-04 12:31   ` Stefan Hajnoczi
  3 siblings, 1 reply; 21+ messages in thread
From: Supriya Kannery @ 2011-07-04 10:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Supriya Kannery, Christoph Hellwig

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      |   17 +++++++++++++++++
 qemu-config.c   |    4 ++++
 qemu-options.hx |    2 +-
 qemu.pod        |    5 +++++
 4 files changed, 27 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;
+    bool option_hostcache = false;
 
     translation = BIOS_ATA_TRANSLATION_AUTO;
 
@@ -324,7 +325,23 @@ DriveInfo *drive_init(QemuOpts *opts, in
 	}
     }
 
+    if ((buf = qemu_opt_get(opts, "hostcache")) != NULL) {
+        if (!strcmp(buf, "off")) {
+            bdrv_flags |= BDRV_O_NOCACHE;
+        } else if (!strcmp(buf, "on")) {
+            bdrv_flags &= ~BDRV_O_NOCACHE;
+        } else {
+            error_report("invalid hostcache option");
+            return NULL;
+        }
+        option_hostcache = true;
+    }
+
     if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
+        if (option_hostcache) {
+            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 */ }
     },
Index: qemu/qemu.pod
===================================================================
--- qemu.orig/qemu.pod
+++ qemu/qemu.pod
@@ -226,6 +226,11 @@ I<snapshot> is "on" or "off" and allows 
 
 I<cache> is "none", "writeback", "unsafe", or "writethrough" and controls how the host cache is used to access block data.
 
+=item B<hostcache=>I<hostcache>
+
+I<hostcache> is "on" or "off" and allows to enable or disable hostcache while accessing block data.
+Both 'cache=' and 'hostcache=' should not used in same command line. Use only one among them.
+
 =item B<aio=>I<aio>
 
 I<aio> is "threads", or "native" and selects between pthread based disk I/O and native Linux AIO.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting
  2011-07-04 10:42 ` [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
@ 2011-07-04 11:54   ` Stefan Hajnoczi
  2011-07-05 10:49     ` [Qemu-devel] [V4 Patch 1/4 -Updated]Qemu: " Supriya Kannery
  0 siblings, 1 reply; 21+ messages in thread
From: Stefan Hajnoczi @ 2011-07-04 11:54 UTC (permalink / raw)
  To: Supriya Kannery; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Mon, Jul 4, 2011 at 11:42 AM, Supriya Kannery
<supriyak@linux.vnet.ibm.com> wrote:
> Enhance "info block" to display hostcache setting for each
> block device.
>
> Example:
> (qemu) info block
> ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2
> encrypted=0
>
> Enhanced to display "hostcache" setting:
> (qemu) info block
> ide0-hd0: type=hd removable=0 hostcache=true file=../rhel6-32.qcow2
> ro=0 drv=qcow2 encrypted=0

The other boolean options use 0 or 1.  Please use the same HMP output
for consistency.

For QMP the true/false output is good (it's JSON).

Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change Supriya Kannery
@ 2011-07-04 12:29   ` Stefan Hajnoczi
  2011-07-05 10:55     ` Supriya Kannery
  2011-07-04 12:35   ` [Qemu-devel] [V4 Patch 3/4]Qemu: " Stefan Hajnoczi
  1 sibling, 1 reply; 21+ messages in thread
From: Stefan Hajnoczi @ 2011-07-04 12:29 UTC (permalink / raw)
  To: Supriya Kannery; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Mon, Jul 4, 2011 at 11:43 AM, Supriya Kannery
<supriyak@linux.vnet.ibm.com> wrote:
> +/*
> + * Handle changes to block device settings, like hostcache,
> + * while guest is running.
> +*/
> +int do_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +{
> +    const char *device = qdict_get_str(qdict, "device");
> +    const char *name = qdict_get_str(qdict, "name");
> +    int enable = qdict_get_bool(qdict, "enable");
> +    BlockDriverState *bs;
> +
> +    bs = bdrv_find(device);
> +    if (!bs) {
> +        qerror_report(QERR_DEVICE_NOT_FOUND, device);
> +        return -1;
> +    }
> +
> +    if (!strcmp(name, "hostcache")) {
> +        return bdrv_change_hostcache(bs, enable);
> +    }
> +
> +    return 0;

No error for unknown "name" argument?

>  #endif
> Index: qemu/hmp-commands.hx
> ===================================================================
> --- qemu.orig/hmp-commands.hx
> +++ qemu/hmp-commands.hx
> @@ -70,6 +70,21 @@ but should be used with extreme caution.
>  resizes image files, it can not resize block devices like LVM volumes.
>  ETEXI
>
> +    {
> +        .name       = "block_set",
> +        .args_type  = "device:B,name:s,enable:b",
> +        .params     = "device name enable",
> +        .help       = "On/Off block device parameters like hostcache",
> +        .user_print = monitor_user_noop,
> +        .mhandler.cmd_new = do_block_set,
> +    },
> +
> +STEXI
> +@item block_set
> +@findex block_set
> +Change block device params (eg:"hostcache"=on/off) while guest is running.
> +ETEXI

See QMP comments below.

> +
>
>     {
>         .name       = "eject",
> Index: qemu/qmp-commands.hx
> ===================================================================
> --- qemu.orig/qmp-commands.hx
> +++ qemu/qmp-commands.hx
> @@ -694,6 +694,34 @@ Example:
>  EQMP
>
>     {
> +        .name       = "block_set",
> +        .args_type  = "device:B,name:s,enable:b",
> +        .params     = "device name enable",

Perhaps:

.args_type  = "device:B,name:s,enable:b?",
.params     = "device name [enable]",

But I am not sure what the best way to express this is.

> +        .help       = "Enable/Disable block device params like hostcache",

Arguments (like "enable") should depend on the block parameter that is
being set:

.help = "Set block device parameter"

If there is no good way to support different optional arguments and
types then a json-string "value" argument would be best.

> +        .user_print = monitor_user_noop,
> +        .mhandler.cmd_new = do_block_set,
> +    },
> +
> +SQMP
> +block_set
> +---------
> +
> +Change various block device parameters like hostcache.
> +
> +Arguments:
> +
> +- "device": the device's ID, must be unique (json-string)
> +- "name": name of the parameter to be changed" (json-string)

Trailing '"'.

> +- "enable": value to be set for the parameter, 'true' or 'false' (json-bool)

The relevant arguments depend on which block parameter you are
changing.  I think "enable" should be documented specifically for
"hostcache":

Block parameters:

- "hostcache": Enable/disable host buffer cache
    - "enable": 'true' or 'false' (json-bool)

Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 4/4]Qemu: Add commandline -drive option 'hostcache'
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 4/4]Qemu: Add commandline -drive option 'hostcache' Supriya Kannery
@ 2011-07-04 12:31   ` Stefan Hajnoczi
  2011-07-05 11:05     ` [Qemu-devel] [V4 Patch 4/4 - Updated]Qemu: " Supriya Kannery
  0 siblings, 1 reply; 21+ messages in thread
From: Stefan Hajnoczi @ 2011-07-04 12:31 UTC (permalink / raw)
  To: Supriya Kannery; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Mon, Jul 4, 2011 at 11:43 AM, Supriya Kannery
<supriyak@linux.vnet.ibm.com> wrote:
> @@ -324,7 +325,23 @@ DriveInfo *drive_init(QemuOpts *opts, in
>        }
>     }
>
> +    if ((buf = qemu_opt_get(opts, "hostcache")) != NULL) {
> +        if (!strcmp(buf, "off")) {

Please use qemu_opt_get_bool().

Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change
  2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change Supriya Kannery
  2011-07-04 12:29   ` Stefan Hajnoczi
@ 2011-07-04 12:35   ` Stefan Hajnoczi
  1 sibling, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2011-07-04 12:35 UTC (permalink / raw)
  To: Supriya Kannery; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Mon, Jul 4, 2011 at 11:43 AM, Supriya Kannery
<supriyak@linux.vnet.ibm.com> wrote:
> +int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
> +{
> +    BlockDriver *drv = bs->drv;
> +    int ret = 0;
> +
> +    /* Quiesce IO for the given block device */
> +    qemu_aio_flush();
> +    if (bdrv_flush(bs)) {
> +        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
> +        return ret;
> +    }
> +    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();

I think it is still worth trying to reopen with the old flags.  If you
specialy hostcache=off for a file on tmpfs then the open will fail
(tmpfs doesn't support O_DIRECT), but we can still save ourselves by
reopening with the old flags.

Ideally we'd probably treat this condition just like ENOSPC and keep
the VM paused until the administrator has taken action, and then
retry.

BTW qerror_report() followed by abort(3) does not actually report the
error because we exit before QMP has a chance to send out the error.

Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 1/4 -Updated]Qemu: Enhance "info block" to display host cache setting
  2011-07-04 11:54   ` Stefan Hajnoczi
@ 2011-07-05 10:49     ` Supriya Kannery
  2011-07-20  7:37       ` Supriya Kannery
  0 siblings, 1 reply; 21+ messages in thread
From: Supriya Kannery @ 2011-07-05 10:49 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Supriya Kannery, qemu-devel, Christoph Hellwig


Updated patch to display hostcache = 1/0 instead of true/false
in monitor.

-------------------------------------------------------------------
Enhance "info block" to display hostcache setting for each
block device.

Example:
(qemu) info block
ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2
encrypted=0

Enhanced to display "hostcache" setting:
(qemu) info block
ide0-hd0: type=hd removable=0 hostcache=true file=../rhel6-32.qcow2
ro=0 drv=qcow2 encrypted=0

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

---
  block.c         |   21 +++++++++++++++++----
  qmp-commands.hx |    2 ++
  2 files changed, 19 insertions(+), 4 deletions(-)

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -1694,6 +1694,14 @@ static void bdrv_print_dict(QObject *obj
          monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, 
"locked"));
      }

+    if (qdict_haskey(bs_dict, "open_flags")) {
+        int open_flags = qdict_get_int(bs_dict, "open_flags");
+        if (open_flags & BDRV_O_NOCACHE)
+            monitor_printf(mon, " hostcache=0");
+        else
+            monitor_printf(mon, " hostcache=1");
+    }
+
      if (qdict_haskey(bs_dict, "inserted")) {
          QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));

@@ -1730,13 +1738,18 @@ void bdrv_info(Monitor *mon, QObject **r
          QObject *bs_obj;

          bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
-                                    "'removable': %i, 'locked': %i }",
-                                    bs->device_name, bs->removable,
-                                    bs->locked);
+                                     "'removable': %i, 'locked': %i, "
+                                     "'hostcache': %s }",
+                                     bs->device_name, bs->removable,
+                                     bs->locked,
+                                     (bs->open_flags & BDRV_O_NOCACHE) ?
+                                     "false" : "true");
+
+        QDict *bs_dict = qobject_to_qdict(bs_obj);
+        qdict_put(bs_dict, "open_flags", qint_from_int(bs->open_flags));

          if (bs->drv) {
              QObject *obj;
-            QDict *bs_dict = qobject_to_qdict(bs_obj);

              obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
                                       "'encrypted': %i }",
Index: qemu/qmp-commands.hx
===================================================================
--- qemu.orig/qmp-commands.hx
+++ qemu/qmp-commands.hx
@@ -1070,6 +1070,7 @@ Each json-object contain the following:
           - Possible values: "unknown"
  - "removable": true if the device is removable, false otherwise 
(json-bool)
  - "locked": true if the device is locked, false otherwise (json-bool)
+- "hostcache": true if hostcache enabled, false otherwise (json-bool)
  - "inserted": only present if the device is inserted, it is a json-object
     containing the following:
           - "file": device file name (json-string)
@@ -1091,6 +1092,7 @@ Example:
           {
              "device":"ide0-hd0",
              "locked":false,
+            "hostcache":false,
              "removable":false,
              "inserted":{
                 "ro":false,

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change
  2011-07-04 12:29   ` Stefan Hajnoczi
@ 2011-07-05 10:55     ` Supriya Kannery
  2011-07-13 13:07       ` [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: " Supriya Kannery
  0 siblings, 1 reply; 21+ messages in thread
From: Supriya Kannery @ 2011-07-05 10:55 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Supriya Kannery, qemu-devel, Christoph Hellwig

On 07/04/2011 05:59 PM, Stefan Hajnoczi wrote:
> On Mon, Jul 4, 2011 at 11:43 AM, Supriya Kannery
> <supriyak@linux.vnet.ibm.com>  wrote:
>>
>>      {
>> +        .name       = "block_set",
>> +        .args_type  = "device:B,name:s,enable:b",
>> +        .params     = "device name enable",
>
> Perhaps:
>
> .args_type  = "device:B,name:s,enable:b?",
> .params     = "device name [enable]",
>
> But I am not sure what the best way to express this is.
>
>> +        .help       = "Enable/Disable block device params like hostcache",
>
> Arguments (like "enable") should depend on the block parameter that is
> being set:
>
> .help = "Set block device parameter"
>
> If there is no good way to support different optional arguments and
> types then a json-string "value" argument would be best.
>

"device_add" is defined and implemented to handle multiple types of
optional arguments. Will work on to see whether that approach
can be adopted for block_set
     {
         .name       = "device_add",
         .args_type  = "device:O",
         .params     = "driver[,prop=value][,...]",
         .help       = "add device, like -device on the command line",
         .user_print = monitor_user_noop,
         .mhandler.cmd_new = do_device_add,
     },



>
> Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 4/4 - Updated]Qemu: Add commandline -drive option 'hostcache'
  2011-07-04 12:31   ` Stefan Hajnoczi
@ 2011-07-05 11:05     ` Supriya Kannery
  2011-07-20  7:39       ` Supriya Kannery
  0 siblings, 1 reply; 21+ messages in thread
From: Supriya Kannery @ 2011-07-05 11:05 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Supriya Kannery, qemu-devel, Christoph Hellwig

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 */ }
      },

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-05 10:55     ` Supriya Kannery
@ 2011-07-13 13:07       ` Supriya Kannery
  2011-07-20  7:38         ` Supriya Kannery
  2011-07-25  6:30         ` Stefan Hajnoczi
  0 siblings, 2 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-13 13:07 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

Updated "block_set" command to accept multiple -drive parameters.
Also, added code for re-opening of device file with original flags,
incase opening file using changed hostcache setting fails.

----------------------------------------------------------------------
New command "block_set" added for dynamically changing any of the block
device parameters. For now, dynamic setting of hostcache params using this
command is implemented. Other block device parameters, can be integrated
in similar lines.

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

---
  block.c         |   60 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  block.h         |    2 +
  blockdev.c      |   60 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  blockdev.h      |    1
  hmp-commands.hx |   14 +++++++++++++
  qemu-config.c   |   13 ++++++++++++
  qemu-option.c   |   25 +++++++++++++++++++++++
  qemu-option.h   |    2 +
  qmp-commands.hx |   28 ++++++++++++++++++++++++++
  9 files changed, 205 insertions(+)

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -651,6 +651,40 @@ unlink_and_fail:
      return ret;
  }

+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
+{
+    BlockDriver *drv = bs->drv;
+    int ret = 0;
+
+    /* Quiesce IO for the given block device */
+    qemu_aio_flush();
+    if (bdrv_flush(bs)) {
+        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
+        return ret;
+    }
+    bdrv_close(bs);
+
+
+    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
+    if (ret < 0) {
+        /* Reopen failed. Try to open with original flags */
+        error_report("Opening file with changed flags...");
+        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+
+        ret = bdrv_open(bs, bs->filename, bs->open_flags, drv);
+        if (ret < 0) {
+            /*
+             * Reopen failed with orig and modified flags
+            */
+            error_report("Opening file with original flags...");
+            qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+            abort();
+        }
+    }
+
+    return ret;
+}
+
  void bdrv_close(BlockDriverState *bs)
  {
      if (bs->drv) {
@@ -691,6 +725,32 @@ void bdrv_close_all(void)
      }
  }

+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
+{
+    int bdrv_flags = bs->open_flags;
+
+    /* set hostcache flags (without changing WCE/flush bits) */
+    if (enable_host_cache) {
+        bdrv_flags &= ~BDRV_O_NOCACHE;
+    } else {
+        bdrv_flags |= BDRV_O_NOCACHE;
+    }
+
+    /* If no change in flags, no need to reopen */
+    if (bdrv_flags == bs->open_flags) {
+        return 0;
+    }
+
+    if (bdrv_is_inserted(bs)) {
+        /* Reopen file with changed set of flags */
+        return bdrv_reopen(bs, bdrv_flags);
+    } else {
+        /* Save hostcache change for future use */
+        bs->open_flags = bdrv_flags;
+        return 0;
+    }
+}
+
  /* make a BlockDriverState anonymous by removing from bdrv_state list.
     Also, NULL terminate the device_name to prevent double remove */
  void bdrv_make_anon(BlockDriverState *bs)
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_hostcache(BlockDriverState *bs, bool enable_host_cache);


  typedef struct BdrvCheckResult {
Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -793,3 +793,63 @@ int do_block_resize(Monitor *mon, const

      return 0;
  }
+
+
+/*
+ * Handle changes to block device settings, like hostcache,
+ * while guest is running.
+*/
+int do_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    BlockDriverState *bs = NULL;
+    QemuOpts *opts;
+    int enable;
+    const char *device, *driver;
+    int ret;
+
+    /* Validate device */
+    device = qdict_get_str(qdict, "device");
+    bs = bdrv_find(device);
+    if (!bs) {
+        qerror_report(QERR_DEVICE_NOT_FOUND, device);
+        return -1;
+    }
+
+    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict);
+    if (opts == NULL) {
+        return -1;
+    }
+
+    /* If input not in "param=value" format, display error */
+    driver = qemu_opt_get(opts, "driver");
+    if (driver != NULL) {
+        error_report("Invalid parameter %s", driver);
+        return -1;
+    }
+
+    /* Before validating parameters, remove "device" option */
+    ret = qemu_opt_delete(opts, "device");
+    if (ret == 1) {
+        error_report("Specify parameter to be changed");
+        error_report("Usage: block_set device [prop=value][,...]");
+        return 0;
+    }
+
+    /* Validate parameters with "-drive" parameter list */
+    ret = qemu_validate_opts(opts, "drive");
+    if (ret == -1) {
+        return -1;
+    }
+
+    /* Check for 'hostcache' parameter */
+    enable = qemu_opt_get_bool(opts, "hostcache", -1);
+    if (enable != -1) {
+        return bdrv_change_hostcache(bs, enable);
+    } else {
+        error_report("Specify 'hostcache=on/off'");
+    }
+
+    return 0;
+
+}
+
Index: qemu/blockdev.h
===================================================================
--- qemu.orig/blockdev.h
+++ qemu/blockdev.h
@@ -65,5 +65,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_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data);

  #endif
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       = "block_set",
+        .args_type  = "device:B,device:O",
+        .params     = "device [prop=value][,...]",
+        .help       = "Change block device parameters [hostcache=on/off]",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set,
+    },
+STEXI
+@item block_set @var{config}
+@findex block_set
+Change block device parameters (eg: hostcache=on/off) while guest is 
running.
+ETEXI
+

      {
          .name       = "eject",
Index: qemu/qemu-config.c
===================================================================
--- qemu.orig/qemu-config.c
+++ qemu/qemu-config.c
@@ -506,6 +506,19 @@ QemuOptsList *qemu_find_opts(const char
      return find_list(vm_config_groups, group);
  }

+/* Validate given opts list with that of defined vm_group */
+int qemu_validate_opts(QemuOpts *opts, const char *group)
+{
+    QemuOptsList *vm_group;
+
+    vm_group  = qemu_find_opts(group);
+    if (vm_group == NULL) {
+        return -1;
+    }
+
+    return qemu_opts_validate(opts, &vm_group->desc[0]);
+}
+
  void qemu_add_opts(QemuOptsList *list)
  {
      int entries, i;
Index: qemu/qemu-option.c
===================================================================
--- qemu.orig/qemu-option.c
+++ qemu/qemu-option.c
@@ -599,6 +599,31 @@ static void qemu_opt_del(QemuOpt *opt)
      qemu_free(opt);
  }

+/*
+ * Delete specified parameter with name "name" from opts
+ * Return
+ *     0 - Deletion Successful
+ *    -1 - Param doesn't exist in opts
+ *     1 - Deletion Successful and opts is empty.
+*/
+
+int qemu_opt_delete(QemuOpts *opts, const char *name)
+{
+    QemuOpt *opt = qemu_opt_find(opts, name);
+    if (opt == NULL) {
+        return -1;
+    }
+
+    qemu_opt_del(opt);
+
+    if ((&opts->head)->tqh_first == NULL) {
+        /* opt queue is empty */
+        return 1;
+    }
+
+    return 0;
+}
+
  int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
  {
      QemuOpt *opt;
Index: qemu/qemu-option.h
===================================================================
--- qemu.orig/qemu-option.h
+++ qemu/qemu-option.h
@@ -121,6 +121,7 @@ int qemu_opts_set(QemuOptsList *list, co
                    const char *name, const char *value);
  const char *qemu_opts_id(QemuOpts *opts);
  void qemu_opts_del(QemuOpts *opts);
+int qemu_opt_delete(QemuOpts *opts, const char *name);
  int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
  int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char 
*firstname);
  QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int 
permit_abbrev);
@@ -131,5 +132,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOp
  int qemu_opts_print(QemuOpts *opts, void *dummy);
  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, 
void *opaque,
                        int abort_on_failure);
+int qemu_validate_opts(QemuOpts *opts, const char *id);

  #endif
Index: qemu/qmp-commands.hx
===================================================================
--- qemu.orig/qmp-commands.hx
+++ qemu/qmp-commands.hx
@@ -693,7 +693,35 @@ Example:

  EQMP

+
      {
+        .name       = "block_set",
+        .args_type  = "device:B,device:O",
+        .params     = "device [prop=value][,...]",
+        .help       = "Change block device parameters [hostcache=on/off]",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set,
+    },
+
+SQMP
+block_set
+---------
+
+Change various block device parameters (eg: hostcache=on/off)
+
+Arguments:
+
+- "device": the device's ID, must be unique (json-string)
+- device parameters to be changed (eg: "hostcache": "off")
+
+Example:
+
+-> { "execute": "block_set", "arguments": { "device": "ide0-hd0", 
"hostcache": "off"} }
+<- { "return": {} }
+
+EQMP
+
+	{
          .name       = "balloon",
          .args_type  = "value:M",
          .params     = "target",

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 1/4 -Updated]Qemu: Enhance "info block" to display host cache setting
  2011-07-05 10:49     ` [Qemu-devel] [V4 Patch 1/4 -Updated]Qemu: " Supriya Kannery
@ 2011-07-20  7:37       ` Supriya Kannery
  0 siblings, 0 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-20  7:37 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Supriya Kannery, qemu-devel, Christoph Hellwig

On 07/05/2011 04:19 PM, Supriya Kannery wrote:
>
> Updated patch to display hostcache = 1/0 instead of true/false
> in monitor.
>
> -------------------------------------------------------------------
> Enhance "info block" to display hostcache setting for each
> block device.
>
> Example:
> (qemu) info block
> ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2
> encrypted=0
>
> Enhanced to display "hostcache" setting:
> (qemu) info block
> ide0-hd0: type=hd removable=0 hostcache=true file=../rhel6-32.qcow2
> ro=0 drv=qcow2 encrypted=0
>
> Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
>
> ---
> block.c | 21 +++++++++++++++++----
> qmp-commands.hx | 2 ++
> 2 files changed, 19 insertions(+), 4 deletions(-)
>
> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c
> +++ qemu/block.c
> @@ -1694,6 +1694,14 @@ static void bdrv_print_dict(QObject *obj
> monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
> }
>
> + if (qdict_haskey(bs_dict, "open_flags")) {
> + int open_flags = qdict_get_int(bs_dict, "open_flags");
> + if (open_flags & BDRV_O_NOCACHE)
> + monitor_printf(mon, " hostcache=0");
> + else
> + monitor_printf(mon, " hostcache=1");
> + }
> +
> if (qdict_haskey(bs_dict, "inserted")) {
> QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
>
> @@ -1730,13 +1738,18 @@ void bdrv_info(Monitor *mon, QObject **r
> QObject *bs_obj;
>
> bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
> - "'removable': %i, 'locked': %i }",
> - bs->device_name, bs->removable,
> - bs->locked);
> + "'removable': %i, 'locked': %i, "
> + "'hostcache': %s }",
> + bs->device_name, bs->removable,
> + bs->locked,
> + (bs->open_flags & BDRV_O_NOCACHE) ?
> + "false" : "true");
> +
> + QDict *bs_dict = qobject_to_qdict(bs_obj);
> + qdict_put(bs_dict, "open_flags", qint_from_int(bs->open_flags));
>
> if (bs->drv) {
> QObject *obj;
> - QDict *bs_dict = qobject_to_qdict(bs_obj);
>
> obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
> "'encrypted': %i }",
> Index: qemu/qmp-commands.hx
> ===================================================================
> --- qemu.orig/qmp-commands.hx
> +++ qemu/qmp-commands.hx
> @@ -1070,6 +1070,7 @@ Each json-object contain the following:
> - Possible values: "unknown"
> - "removable": true if the device is removable, false otherwise (json-bool)
> - "locked": true if the device is locked, false otherwise (json-bool)
> +- "hostcache": true if hostcache enabled, false otherwise (json-bool)
> - "inserted": only present if the device is inserted, it is a json-object
> containing the following:
> - "file": device file name (json-string)
> @@ -1091,6 +1092,7 @@ Example:
> {
> "device":"ide0-hd0",
> "locked":false,
> + "hostcache":false,
> "removable":false,
> "inserted":{
> "ro":false,

Pls review..

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-13 13:07       ` [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: " Supriya Kannery
@ 2011-07-20  7:38         ` Supriya Kannery
  2011-07-25  6:30         ` Stefan Hajnoczi
  1 sibling, 0 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-20  7:38 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On 07/13/2011 06:37 PM, Supriya Kannery wrote:
> Updated "block_set" command to accept multiple -drive parameters.
> Also, added code for re-opening of device file with original flags,
> incase opening file using changed hostcache setting fails.
>
> ----------------------------------------------------------------------
> New command "block_set" added for dynamically changing any of the block
> device parameters. For now, dynamic setting of hostcache params using this
> command is implemented. Other block device parameters, can be integrated
> in similar lines.
>
> Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
>
> ---
> block.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> block.h | 2 +
> blockdev.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> blockdev.h | 1
> hmp-commands.hx | 14 +++++++++++++
> qemu-config.c | 13 ++++++++++++
> qemu-option.c | 25 +++++++++++++++++++++++
> qemu-option.h | 2 +
> qmp-commands.hx | 28 ++++++++++++++++++++++++++
> 9 files changed, 205 insertions(+)
>
> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c
> +++ qemu/block.c
> @@ -651,6 +651,40 @@ unlink_and_fail:
> return ret;
> }
>
> +int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
> +{
> + BlockDriver *drv = bs->drv;
> + int ret = 0;
> +
> + /* Quiesce IO for the given block device */
> + qemu_aio_flush();
> + if (bdrv_flush(bs)) {
> + qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
> + return ret;
> + }
> + bdrv_close(bs);
> +
> +
> + ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
> + if (ret < 0) {
> + /* Reopen failed. Try to open with original flags */
> + error_report("Opening file with changed flags...");
> + qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
> +
> + ret = bdrv_open(bs, bs->filename, bs->open_flags, drv);
> + if (ret < 0) {
> + /*
> + * Reopen failed with orig and modified flags
> + */
> + error_report("Opening file with original flags...");
> + qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
> + abort();
> + }
> + }
> +
> + return ret;
> +}
> +
> void bdrv_close(BlockDriverState *bs)
> {
> if (bs->drv) {
> @@ -691,6 +725,32 @@ void bdrv_close_all(void)
> }
> }
>
> +int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
> +{
> + int bdrv_flags = bs->open_flags;
> +
> + /* set hostcache flags (without changing WCE/flush bits) */
> + if (enable_host_cache) {
> + bdrv_flags &= ~BDRV_O_NOCACHE;
> + } else {
> + bdrv_flags |= BDRV_O_NOCACHE;
> + }
> +
> + /* If no change in flags, no need to reopen */
> + if (bdrv_flags == bs->open_flags) {
> + return 0;
> + }
> +
> + if (bdrv_is_inserted(bs)) {
> + /* Reopen file with changed set of flags */
> + return bdrv_reopen(bs, bdrv_flags);
> + } else {
> + /* Save hostcache change for future use */
> + bs->open_flags = bdrv_flags;
> + return 0;
> + }
> +}
> +
> /* make a BlockDriverState anonymous by removing from bdrv_state list.
> Also, NULL terminate the device_name to prevent double remove */
> void bdrv_make_anon(BlockDriverState *bs)
> 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_hostcache(BlockDriverState *bs, bool enable_host_cache);
>
>
> typedef struct BdrvCheckResult {
> Index: qemu/blockdev.c
> ===================================================================
> --- qemu.orig/blockdev.c
> +++ qemu/blockdev.c
> @@ -793,3 +793,63 @@ int do_block_resize(Monitor *mon, const
>
> return 0;
> }
> +
> +
> +/*
> + * Handle changes to block device settings, like hostcache,
> + * while guest is running.
> +*/
> +int do_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +{
> + BlockDriverState *bs = NULL;
> + QemuOpts *opts;
> + int enable;
> + const char *device, *driver;
> + int ret;
> +
> + /* Validate device */
> + device = qdict_get_str(qdict, "device");
> + bs = bdrv_find(device);
> + if (!bs) {
> + qerror_report(QERR_DEVICE_NOT_FOUND, device);
> + return -1;
> + }
> +
> + opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict);
> + if (opts == NULL) {
> + return -1;
> + }
> +
> + /* If input not in "param=value" format, display error */
> + driver = qemu_opt_get(opts, "driver");
> + if (driver != NULL) {
> + error_report("Invalid parameter %s", driver);
> + return -1;
> + }
> +
> + /* Before validating parameters, remove "device" option */
> + ret = qemu_opt_delete(opts, "device");
> + if (ret == 1) {
> + error_report("Specify parameter to be changed");
> + error_report("Usage: block_set device [prop=value][,...]");
> + return 0;
> + }
> +
> + /* Validate parameters with "-drive" parameter list */
> + ret = qemu_validate_opts(opts, "drive");
> + if (ret == -1) {
> + return -1;
> + }
> +
> + /* Check for 'hostcache' parameter */
> + enable = qemu_opt_get_bool(opts, "hostcache", -1);
> + if (enable != -1) {
> + return bdrv_change_hostcache(bs, enable);
> + } else {
> + error_report("Specify 'hostcache=on/off'");
> + }
> +
> + return 0;
> +
> +}
> +
> Index: qemu/blockdev.h
> ===================================================================
> --- qemu.orig/blockdev.h
> +++ qemu/blockdev.h
> @@ -65,5 +65,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_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
>
> #endif
> 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 = "block_set",
> + .args_type = "device:B,device:O",
> + .params = "device [prop=value][,...]",
> + .help = "Change block device parameters [hostcache=on/off]",
> + .user_print = monitor_user_noop,
> + .mhandler.cmd_new = do_block_set,
> + },
> +STEXI
> +@item block_set @var{config}
> +@findex block_set
> +Change block device parameters (eg: hostcache=on/off) while guest is
> running.
> +ETEXI
> +
>
> {
> .name = "eject",
> Index: qemu/qemu-config.c
> ===================================================================
> --- qemu.orig/qemu-config.c
> +++ qemu/qemu-config.c
> @@ -506,6 +506,19 @@ QemuOptsList *qemu_find_opts(const char
> return find_list(vm_config_groups, group);
> }
>
> +/* Validate given opts list with that of defined vm_group */
> +int qemu_validate_opts(QemuOpts *opts, const char *group)
> +{
> + QemuOptsList *vm_group;
> +
> + vm_group = qemu_find_opts(group);
> + if (vm_group == NULL) {
> + return -1;
> + }
> +
> + return qemu_opts_validate(opts, &vm_group->desc[0]);
> +}
> +
> void qemu_add_opts(QemuOptsList *list)
> {
> int entries, i;
> Index: qemu/qemu-option.c
> ===================================================================
> --- qemu.orig/qemu-option.c
> +++ qemu/qemu-option.c
> @@ -599,6 +599,31 @@ static void qemu_opt_del(QemuOpt *opt)
> qemu_free(opt);
> }
>
> +/*
> + * Delete specified parameter with name "name" from opts
> + * Return
> + * 0 - Deletion Successful
> + * -1 - Param doesn't exist in opts
> + * 1 - Deletion Successful and opts is empty.
> +*/
> +
> +int qemu_opt_delete(QemuOpts *opts, const char *name)
> +{
> + QemuOpt *opt = qemu_opt_find(opts, name);
> + if (opt == NULL) {
> + return -1;
> + }
> +
> + qemu_opt_del(opt);
> +
> + if ((&opts->head)->tqh_first == NULL) {
> + /* opt queue is empty */
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
> {
> QemuOpt *opt;
> Index: qemu/qemu-option.h
> ===================================================================
> --- qemu.orig/qemu-option.h
> +++ qemu/qemu-option.h
> @@ -121,6 +121,7 @@ int qemu_opts_set(QemuOptsList *list, co
> const char *name, const char *value);
> const char *qemu_opts_id(QemuOpts *opts);
> void qemu_opts_del(QemuOpts *opts);
> +int qemu_opt_delete(QemuOpts *opts, const char *name);
> int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
> int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char
> *firstname);
> QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int
> permit_abbrev);
> @@ -131,5 +132,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOp
> int qemu_opts_print(QemuOpts *opts, void *dummy);
> int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void
> *opaque,
> int abort_on_failure);
> +int qemu_validate_opts(QemuOpts *opts, const char *id);
>
> #endif
> Index: qemu/qmp-commands.hx
> ===================================================================
> --- qemu.orig/qmp-commands.hx
> +++ qemu/qmp-commands.hx
> @@ -693,7 +693,35 @@ Example:
>
> EQMP
>
> +
> {
> + .name = "block_set",
> + .args_type = "device:B,device:O",
> + .params = "device [prop=value][,...]",
> + .help = "Change block device parameters [hostcache=on/off]",
> + .user_print = monitor_user_noop,
> + .mhandler.cmd_new = do_block_set,
> + },
> +
> +SQMP
> +block_set
> +---------
> +
> +Change various block device parameters (eg: hostcache=on/off)
> +
> +Arguments:
> +
> +- "device": the device's ID, must be unique (json-string)
> +- device parameters to be changed (eg: "hostcache": "off")
> +
> +Example:
> +
> +-> { "execute": "block_set", "arguments": { "device": "ide0-hd0",
> "hostcache": "off"} }
> +<- { "return": {} }
> +
> +EQMP
> +
> + {
> .name = "balloon",
> .args_type = "value:M",
> .params = "target",
>
Please review..

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 4/4 - Updated]Qemu: Add commandline -drive option 'hostcache'
  2011-07-05 11:05     ` [Qemu-devel] [V4 Patch 4/4 - Updated]Qemu: " Supriya Kannery
@ 2011-07-20  7:39       ` Supriya Kannery
  0 siblings, 0 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-20  7:39 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Supriya Kannery, qemu-devel, Christoph Hellwig

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..

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-13 13:07       ` [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: " Supriya Kannery
  2011-07-20  7:38         ` Supriya Kannery
@ 2011-07-25  6:30         ` Stefan Hajnoczi
  2011-07-25 12:52           ` Supriya Kannery
  1 sibling, 1 reply; 21+ messages in thread
From: Stefan Hajnoczi @ 2011-07-25  6:30 UTC (permalink / raw)
  To: Supriya Kannery; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Wed, Jul 13, 2011 at 06:37:05PM +0530, Supriya Kannery wrote:
> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c
> +++ qemu/block.c
> @@ -651,6 +651,40 @@ unlink_and_fail:
>      return ret;
>  }
> 
> +int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
> +{
> +    BlockDriver *drv = bs->drv;
> +    int ret = 0;
> +
> +    /* Quiesce IO for the given block device */
> +    qemu_aio_flush();
> +    if (bdrv_flush(bs)) {
> +        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
> +        return ret;
> +    }
> +    bdrv_close(bs);
> +
> +
> +    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
> +    if (ret < 0) {
> +        /* Reopen failed. Try to open with original flags */
> +        error_report("Opening file with changed flags...");
> +        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);

If the next open fails too then there will be two qerror_report() calls.
This causes a warning and the new qerror is dropped.  Please consolidate
the error reporting so there is only one error before returning from
this function.

> +
> +        ret = bdrv_open(bs, bs->filename, bs->open_flags, drv);

bs->open_flags has been clobbered by the previous bdrv_open().  It would
be best to take a copy of bs->open_flags before bdrv_close(bs) above.

> +        if (ret < 0) {
> +            /*
> +             * Reopen failed with orig and modified flags
> +            */
> +            error_report("Opening file with original flags...");
> +            qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
> +            abort();
> +        }
> +    }
> +
> +    return ret;
> +}
> +
>  void bdrv_close(BlockDriverState *bs)
>  {
>      if (bs->drv) {
> @@ -691,6 +725,32 @@ void bdrv_close_all(void)
>      }
>  }
> 
> +int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
> +{
> +    int bdrv_flags = bs->open_flags;
> +
> +    /* set hostcache flags (without changing WCE/flush bits) */
> +    if (enable_host_cache) {
> +        bdrv_flags &= ~BDRV_O_NOCACHE;
> +    } else {
> +        bdrv_flags |= BDRV_O_NOCACHE;
> +    }
> +
> +    /* If no change in flags, no need to reopen */
> +    if (bdrv_flags == bs->open_flags) {
> +        return 0;
> +    }
> +
> +    if (bdrv_is_inserted(bs)) {
> +        /* Reopen file with changed set of flags */
> +        return bdrv_reopen(bs, bdrv_flags);
> +    } else {
> +        /* Save hostcache change for future use */
> +        bs->open_flags = bdrv_flags;

Can you explain the scenario where this works?

Looking at do_change_block() the flags will be clobbered so saving them
away does not help.

> Index: qemu/blockdev.c
> ===================================================================
> --- qemu.orig/blockdev.c
> +++ qemu/blockdev.c
> @@ -793,3 +793,63 @@ int do_block_resize(Monitor *mon, const
> 
>      return 0;
>  }
> +
> +
> +/*
> + * Handle changes to block device settings, like hostcache,
> + * while guest is running.
> +*/
> +int do_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +{
> +    BlockDriverState *bs = NULL;
> +    QemuOpts *opts;
> +    int enable;
> +    const char *device, *driver;
> +    int ret;
> +
> +    /* Validate device */
> +    device = qdict_get_str(qdict, "device");
> +    bs = bdrv_find(device);
> +    if (!bs) {
> +        qerror_report(QERR_DEVICE_NOT_FOUND, device);
> +        return -1;
> +    }
> +
> +    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict);
> +    if (opts == NULL) {
> +        return -1;
> +    }
> +
> +    /* If input not in "param=value" format, display error */
> +    driver = qemu_opt_get(opts, "driver");
> +    if (driver != NULL) {
> +        error_report("Invalid parameter %s", driver);

error_report() only works for HMP.  Please use qerror_report() so both
HMP and QMP see the error.  Same issue further down.

Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-25 12:52           ` Supriya Kannery
@ 2011-07-25 12:50             ` Stefan Hajnoczi
  2011-07-25 13:34               ` Kevin Wolf
  0 siblings, 1 reply; 21+ messages in thread
From: Stefan Hajnoczi @ 2011-07-25 12:50 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Supriya Kannery, qemu-devel, Christoph Hellwig

On Mon, Jul 25, 2011 at 1:52 PM, Supriya Kannery <supriyak@in.ibm.com> wrote:
> On 07/25/2011 12:00 PM, Stefan Hajnoczi wrote:
>>
>> On Wed, Jul 13, 2011 at 06:37:05PM +0530, Supriya Kannery wrote:
>>> +    if (bdrv_is_inserted(bs)) {
>>> +        /* Reopen file with changed set of flags */
>>> +        return bdrv_reopen(bs, bdrv_flags);
>>> +    } else {
>>> +        /* Save hostcache change for future use */
>>> +        bs->open_flags = bdrv_flags;
>
>>
>> Can you explain the scenario where this works?
>>
>> Looking at do_change_block() the flags will be clobbered so saving them
>> away does not help.
>
> Intention here is to use the changed hostcache setting during device
> insertion and there after. To apply this to 'change' command (during
> insertion of a device), will need to make the following code changes
> in do_change_block.
>
> +
> +    bdrv_flags = bs->open_flags;
> +    bdrv_flags |= bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
>     bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
>     if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
>         qerror_report(QERR_OPEN_FILE_FAILED, filename);
>
> Need to track bs->open_flags a bit more to see what other changes
> needed to ensure usage of changed hostcache setting until user
> initiates next hostcache change explicitly for that drive.
>
> Please suggest... should we be saving the hostcache change for
> future use or just inhibit user from changing hostcache setting
> for an empty drive?

The 'change' command does not support any cache= options today.  It
always opens the new image with cache=writethrough semantics.

This seems like a bug in 'change' to me.  We should preserve cache=
settings across change or at least provide a way to specify them as
arguments.

Perhaps your existing code is fine.  When 'change' is fixed or
replaced then 'block_set' will work across 'change' too.

Kevin: Thoughts?

Stefan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-25  6:30         ` Stefan Hajnoczi
@ 2011-07-25 12:52           ` Supriya Kannery
  2011-07-25 12:50             ` Stefan Hajnoczi
  0 siblings, 1 reply; 21+ messages in thread
From: Supriya Kannery @ 2011-07-25 12:52 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On 07/25/2011 12:00 PM, Stefan Hajnoczi wrote:
> On Wed, Jul 13, 2011 at 06:37:05PM +0530, Supriya Kannery wrote:

>> +    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
>> +    if (ret<  0) {
>> +        /* Reopen failed. Try to open with original flags */
>> +        error_report("Opening file with changed flags...");
>> +        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
>
> If the next open fails too then there will be two qerror_report() calls.
> This causes a warning and the new qerror is dropped.  Please consolidate
> the error reporting so there is only one error before returning from
> this function.
>

ok

>> +    if (bdrv_is_inserted(bs)) {
>> +        /* Reopen file with changed set of flags */
>> +        return bdrv_reopen(bs, bdrv_flags);
>> +    } else {
>> +        /* Save hostcache change for future use */
>> +        bs->open_flags = bdrv_flags;

>
> Can you explain the scenario where this works?
>
> Looking at do_change_block() the flags will be clobbered so saving them
> away does not help.

Intention here is to use the changed hostcache setting during device 
insertion and there after. To apply this to 'change' command (during 
insertion of a device), will need to make the following code changes
in do_change_block.

+
+    bdrv_flags = bs->open_flags;
+    bdrv_flags |= bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
      bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
      if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
          qerror_report(QERR_OPEN_FILE_FAILED, filename);

Need to track bs->open_flags a bit more to see what other changes
needed to ensure usage of changed hostcache setting until user
initiates next hostcache change explicitly for that drive.

Please suggest... should we be saving the hostcache change for
future use or just inhibit user from changing hostcache setting
for an empty drive?

>> +    /* If input not in "param=value" format, display error */
>> +    driver = qemu_opt_get(opts, "driver");
>> +    if (driver != NULL) {
>> +        error_report("Invalid parameter %s", driver);
>
> error_report() only works for HMP.  Please use qerror_report() so both
> HMP and QMP see the error.  Same issue further down.
>

ok..will change error_report to qerror_report.

Will make further code changes into patchset version 5

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-25 12:50             ` Stefan Hajnoczi
@ 2011-07-25 13:34               ` Kevin Wolf
  2011-07-26  5:47                 ` Supriya Kannery
  0 siblings, 1 reply; 21+ messages in thread
From: Kevin Wolf @ 2011-07-25 13:34 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Supriya Kannery, qemu-devel, Christoph Hellwig

Am 25.07.2011 14:50, schrieb Stefan Hajnoczi:
> On Mon, Jul 25, 2011 at 1:52 PM, Supriya Kannery <supriyak@in.ibm.com> wrote:
>> On 07/25/2011 12:00 PM, Stefan Hajnoczi wrote:
>>>
>>> On Wed, Jul 13, 2011 at 06:37:05PM +0530, Supriya Kannery wrote:
>>>> +    if (bdrv_is_inserted(bs)) {
>>>> +        /* Reopen file with changed set of flags */
>>>> +        return bdrv_reopen(bs, bdrv_flags);
>>>> +    } else {
>>>> +        /* Save hostcache change for future use */
>>>> +        bs->open_flags = bdrv_flags;
>>
>>>
>>> Can you explain the scenario where this works?
>>>
>>> Looking at do_change_block() the flags will be clobbered so saving them
>>> away does not help.
>>
>> Intention here is to use the changed hostcache setting during device
>> insertion and there after. To apply this to 'change' command (during
>> insertion of a device), will need to make the following code changes
>> in do_change_block.
>>
>> +
>> +    bdrv_flags = bs->open_flags;
>> +    bdrv_flags |= bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
>>     bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
>>     if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
>>         qerror_report(QERR_OPEN_FILE_FAILED, filename);
>>
>> Need to track bs->open_flags a bit more to see what other changes
>> needed to ensure usage of changed hostcache setting until user
>> initiates next hostcache change explicitly for that drive.
>>
>> Please suggest... should we be saving the hostcache change for
>> future use or just inhibit user from changing hostcache setting
>> for an empty drive?
> 
> The 'change' command does not support any cache= options today.  It
> always opens the new image with cache=writethrough semantics.
> 
> This seems like a bug in 'change' to me.  We should preserve cache=
> settings across change or at least provide a way to specify them as
> arguments.
> 
> Perhaps your existing code is fine.  When 'change' is fixed or
> replaced then 'block_set' will work across 'change' too.
> 
> Kevin: Thoughts?

I'm not sure if I would say it's a bug. Probably preserving would be
more useful in most cases, but using the default cache mode doesn't
appear completely wrong either. If you like to change it, I'm not
opposed to it.

Kevin

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
  2011-07-25 13:34               ` Kevin Wolf
@ 2011-07-26  5:47                 ` Supriya Kannery
  0 siblings, 0 replies; 21+ messages in thread
From: Supriya Kannery @ 2011-07-26  5:47 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Stefan Hajnoczi, qemu-devel, Christoph Hellwig

On 07/25/2011 07:04 PM, Kevin Wolf wrote:
> Am 25.07.2011 14:50, schrieb Stefan Hajnoczi:
>> On Mon, Jul 25, 2011 at 1:52 PM, Supriya Kannery<supriyak@in.ibm.com>  wrote:
>>> On 07/25/2011 12:00 PM, Stefan Hajnoczi wrote:
>>>> On Wed, Jul 13, 2011 at 06:37:05PM +0530, Supriya Kannery wrote:
>>>>> +    if (bdrv_is_inserted(bs)) {
>>>>> +        /* Reopen file with changed set of flags */
>>>>> +        return bdrv_reopen(bs, bdrv_flags);
>>>>> +    } else {
>>>>> +        /* Save hostcache change for future use */
>>>>> +        bs->open_flags = bdrv_flags;
>>>> Can you explain the scenario where this works?
>>>>
>>>> Looking at do_change_block() the flags will be clobbered so saving them
>>>> away does not help.
>>> Intention here is to use the changed hostcache setting during device
>>> insertion and there after. To apply this to 'change' command (during
>>> insertion of a device), will need to make the following code changes
>>> in do_change_block.
>>>
>>> +
>>> +    bdrv_flags = bs->open_flags;
>>> +    bdrv_flags |= bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
>>>      bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
>>>      if (bdrv_open(bs, filename, bdrv_flags, drv)<  0) {
>>>          qerror_report(QERR_OPEN_FILE_FAILED, filename);
>>>
>>> Need to track bs->open_flags a bit more to see what other changes
>>> needed to ensure usage of changed hostcache setting until user
>>> initiates next hostcache change explicitly for that drive.
>>>
>>> Please suggest... should we be saving the hostcache change for
>>> future use or just inhibit user from changing hostcache setting
>>> for an empty drive?
>> The 'change' command does not support any cache= options today.  It
>> always opens the new image with cache=writethrough semantics.
>>
>> This seems like a bug in 'change' to me.  We should preserve cache=
>> settings across change or at least provide a way to specify them as
>> arguments.
>>
>> Perhaps your existing code is fine.  When 'change' is fixed or
>> replaced then 'block_set' will work across 'change' too.
>>
>> Kevin: Thoughts?
>
> I'm not sure if I would say it's a bug. Probably preserving would be
> more useful in most cases, but using the default cache mode doesn't
> appear completely wrong either. If you like to change it, I'm not
> opposed to it.
>
> Kevin
>

ok, so for now, will retain the code that saves hostcache setting
for empty drives. When other commands (like 'change') are focused,
can look at using this saved setting.

Will post V5 with other error_report related code changes.

thanks, Supriya

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2011-07-26  5:35 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-04 10:42 [Qemu-devel] [V4 Patch 0/4]Qemu: Hostcache setting from cmdline and monitor Supriya Kannery
2011-07-04 10:42 ` [Qemu-devel] [V4 Patch 1/4]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
2011-07-04 11:54   ` Stefan Hajnoczi
2011-07-05 10:49     ` [Qemu-devel] [V4 Patch 1/4 -Updated]Qemu: " Supriya Kannery
2011-07-20  7:37       ` Supriya Kannery
2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 2/4]Qemu: Error classes for file reopen and data sync failure Supriya Kannery
2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 3/4]Qemu: Command "block_set" for dynamic block params change Supriya Kannery
2011-07-04 12:29   ` Stefan Hajnoczi
2011-07-05 10:55     ` Supriya Kannery
2011-07-13 13:07       ` [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: " Supriya Kannery
2011-07-20  7:38         ` Supriya Kannery
2011-07-25  6:30         ` Stefan Hajnoczi
2011-07-25 12:52           ` Supriya Kannery
2011-07-25 12:50             ` Stefan Hajnoczi
2011-07-25 13:34               ` Kevin Wolf
2011-07-26  5:47                 ` Supriya Kannery
2011-07-04 12:35   ` [Qemu-devel] [V4 Patch 3/4]Qemu: " Stefan Hajnoczi
2011-07-04 10:43 ` [Qemu-devel] [V4 Patch 4/4]Qemu: Add commandline -drive option 'hostcache' Supriya Kannery
2011-07-04 12:31   ` Stefan Hajnoczi
2011-07-05 11:05     ` [Qemu-devel] [V4 Patch 4/4 - Updated]Qemu: " Supriya Kannery
2011-07-20  7:39       ` Supriya Kannery

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.