qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Supriya Kannery <supriyak@in.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change
Date: Mon, 25 Jul 2011 07:30:15 +0100	[thread overview]
Message-ID: <20110725063015.GA12854@stefanha-thinkpad.localdomain> (raw)
In-Reply-To: <4E1D9879.8060009@in.ibm.com>

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

  parent reply	other threads:[~2011-07-25  6:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=20110725063015.GA12854@stefanha-thinkpad.localdomain \
    --to=stefanha@gmail.com \
    --cc=hch@lst.de \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=supriyak@in.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).