From: Anthony Liguori <anthony@codemonkey.ws>
To: Supriya Kannery <supriyak@linux.vnet.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [Qemu-devel] [V5 Patch 3/4]Qemu: Command "block_set" for dynamic block params change
Date: Wed, 27 Jul 2011 07:58:54 -0500 [thread overview]
Message-ID: <4E300B8E.2020509@codemonkey.ws> (raw)
In-Reply-To: <20110727113045.25109.54866.sendpatchset@skannery>
On 07/27/2011 06:30 AM, Supriya Kannery wrote:
> 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 parameter changes, can be
> integrated in similar lines.
>
> Signed-off-by: Supriya Kannery<supriyak@in.ibm.com>
>
> ---
> block.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
> block.h | 2 +
> blockdev.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 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, 200 insertions(+)
>
> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c
> +++ qemu/block.c
> @@ -651,6 +651,34 @@ unlink_and_fail:
> return ret;
> }
>
> +int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
> +{
> + BlockDriver *drv = bs->drv;
> + int ret = 0, open_flags;
> +
> + /* 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;
> + }
> + open_flags = bs->open_flags;
> + bdrv_close(bs);
> +
> + ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
> + if (ret< 0) {
> + /* Reopen failed. Try to open with original flags */
> + qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
> + ret = bdrv_open(bs, bs->filename, open_flags, drv);
> + if (ret< 0) {
> + /* Reopen failed with orig and modified flags */
> + abort();
> + }
> + }
> +
> + return ret;
> +}
> +
> void bdrv_close(BlockDriverState *bs)
> {
> if (bs->drv) {
> @@ -691,6 +719,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);
> @@ -97,6 +98,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,64 @@ 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;
> + char usage[50];
> +
> + /* 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) {
> + qerror_report(QERR_INVALID_PARAMETER, driver);
> + return -1;
> + }
> +
> + /* Before validating parameters, remove "device" option */
> + ret = qemu_opt_delete(opts, "device");
> + if (ret == 1) {
> + strcpy(usage,"block_set device [prop=value][,...]");
> + qerror_report(QERR_INCORRECT_COMMAND_SYNTAX, usage);
> + 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 {
> + qerror_report(QERR_INVALID_PARAMETER_VALUE, "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
> +
block_set_hostcache() please.
Multiplexing commands is generally a bad idea. It weakens typing. In
the absence of a generic way to set block device properties,
implementing properties as generic in the QMP layer seems like a bad
idea to me.
Regards,
Anthony Liguori
next prev parent reply other threads:[~2011-07-27 12:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-27 11:30 [Qemu-devel] [V5 Patch 0/4]Qemu: Set host cache from cmdline and monitor Supriya Kannery
2011-07-27 11:30 ` [Qemu-devel] [V5 Patch 1/4]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
2011-07-27 14:19 ` Stefan Hajnoczi
2011-07-28 10:39 ` Supriya Kannery
2011-07-27 11:30 ` [Qemu-devel] [V5 Patch 2/4]Qemu: qerrors for file reopen, data sync and cmd syntax Supriya Kannery
2011-07-27 11:30 ` [Qemu-devel] [V5 Patch 3/4]Qemu: Command "block_set" for dynamic block params change Supriya Kannery
2011-07-27 12:58 ` Anthony Liguori [this message]
2011-07-27 14:31 ` Stefan Hajnoczi
2011-07-27 16:02 ` Anthony Liguori
2011-07-28 9:29 ` Stefan Hajnoczi
2011-08-01 15:22 ` Stefan Hajnoczi
2011-08-01 15:28 ` Anthony Liguori
2011-08-01 15:34 ` Stefan Hajnoczi
2011-08-01 15:44 ` Kevin Wolf
2011-08-01 15:44 ` Anthony Liguori
2011-08-04 8:32 ` Supriya Kannery
2011-08-04 8:31 ` Stefan Hajnoczi
2011-08-04 9:33 ` Supriya Kannery
2011-08-04 9:17 ` Supriya Kannery
2011-08-01 15:44 ` Stefan Hajnoczi
2011-08-01 15:46 ` Anthony Liguori
2011-07-28 10:13 ` Supriya Kannery
2011-07-28 12:48 ` Anthony Liguori
2011-07-27 13:43 ` Michael Tokarev
2011-07-27 13:52 ` Anthony Liguori
2011-07-27 14:51 ` Stefan Hajnoczi
2011-07-28 10:23 ` Kevin Wolf
2011-07-28 13:10 ` Stefan Hajnoczi
2011-07-28 13:23 ` Kevin Wolf
2011-07-27 11:31 ` [Qemu-devel] [V5 Patch 4/4]Qemu: Add commandline -drive option 'hostcache' 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=4E300B8E.2020509@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=hch@lst.de \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--cc=supriyak@linux.vnet.ibm.com \
/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).