From: Kevin Wolf <kwolf@redhat.com>
To: Supriya Kannery <supriyak@linux.vnet.ibm.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [Qemu-devel] [v8 Patch 6/6]Qemu: raw posix implementation of reopen functions
Date: Fri, 04 Nov 2011 11:19:12 +0100 [thread overview]
Message-ID: <4EB3BC20.6080607@redhat.com> (raw)
In-Reply-To: <20111030103523.31685.85976.sendpatchset@skannery.in.ibm.com>
Am 30.10.2011 11:35, schrieb Supriya Kannery:
> raw-posix driver changes for bdrv_reopen_xx functions to
> safely reopen image files. Reopening of image files while
> changing hostcache dynamically, is handled here.
>
> Signed-off-by: Supriya Kannery <supriyak@linux.vnet.ibm.com>
>
> Index: qemu/block/raw.c
> ===================================================================
> --- qemu.orig/block/raw.c
> +++ qemu/block/raw.c
> @@ -9,6 +9,24 @@ static int raw_open(BlockDriverState *bs
> return 0;
> }
>
> +static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
> + int flags)
> +{
> + return bdrv_reopen_prepare(bs->file, prs, flags);
> +}
> +
> +static void raw_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs,
> + int flags)
> +{
> + bdrv_reopen_commit(bs->file, rs, flags);
> + bs->open_flags = bs->file->open_flags;
I think it should be bs->open_flags = flags, even if the underlying
driver masks something away (which it shouldn't do in the first place,
but using flags here is clearer).
Also I'm wondering if updating bs->open_flags isn't common to all
formats, so could we move it into the block.c function?
> +}
> +
> +static void raw_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
> +{
> + bdrv_reopen_abort(bs->file, rs);
> +}
> +
> static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
> int nb_sectors, QEMUIOVector *qiov)
> {
> @@ -107,7 +125,10 @@ static BlockDriver bdrv_raw = {
>
> /* It's really 0, but we need to make g_malloc() happy */
> .instance_size = 1,
> -
> + .bdrv_reopen_prepare
> + = raw_reopen_prepare,
> + .bdrv_reopen_commit = raw_reopen_commit,
> + .bdrv_reopen_abort = raw_reopen_abort,
> .bdrv_open = raw_open,
> .bdrv_close = raw_close,
Mostly a matter of taste, but I would prefer open/close to stay first
and having bdrv_reopen_* only after them.
>
> Index: qemu/block/raw-posix.c
> ===================================================================
> --- qemu.orig/block/raw-posix.c
> +++ qemu/block/raw-posix.c
> @@ -279,6 +279,60 @@ static int raw_open(BlockDriverState *bs
> return raw_open_common(bs, filename, flags, 0);
> }
>
> +static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
> + int flags)
> +{
> + BDRVReopenState *raw_rs = g_malloc0(sizeof(BDRVReopenState));
> + BDRVRawState *s = bs->opaque;
> +
> + raw_rs->bs = bs;
> + raw_rs->reopen_flags = s->open_flags;
> + raw_rs->reopen_fd = -1;
> + *prs = raw_rs;
> + int ret = 0;
> +
> + /* If only O_DIRECT to be toggled, use fcntl */
> + if (!((bs->open_flags & ~BDRV_O_NOCACHE) ^
> + (flags & ~BDRV_O_NOCACHE))) {
Wouldn't it be more readable like this?
/* Use fcntl if all affected flags can be changes this way */
fcntl_flags = BDRV_O_NOCACHE;
if ((bs->open_flags & ~fcntl_flags) == (flags & ~fcntl_flags)) {
...
> + raw_rs->reopen_fd = dup(s->fd);
> + if (raw_rs->reopen_fd <= 0) {
> + return -1;
> + }
> + if ((flags & BDRV_O_NOCACHE)) {
> + raw_rs->reopen_flags |= O_DIRECT;
> + } else {
> + raw_rs->reopen_flags &= ~O_DIRECT;
> + }
> + ret = fcntl_setfl(raw_rs->reopen_fd, raw_rs->reopen_flags);
> + }
I think there should be an else branch that returns an error. Currently
requests involving anything but BDRV_O_NOCACHE are completely ignored,
but still success is returned.
> +
> + /* TBD: Handle O_DSYNC and other flags */
> +
> + return ret;
> +}
Kevin
next prev parent reply other threads:[~2011-11-04 10:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-30 10:33 [Qemu-devel] [v8 Patch 0/6]Qemu: Host pagecache setting from cmdline and monitor Supriya Kannery
2011-10-30 10:33 ` [Qemu-devel] [v8 Patch 1/6]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
2011-11-03 13:55 ` Luiz Capitulino
2011-11-04 10:55 ` Supriya Kannery
2011-10-30 10:34 ` [Qemu-devel] [v8 Patch 2/6]Qemu: Error classes for file reopen and data sync failure Supriya Kannery
2011-10-30 10:34 ` [Qemu-devel] [v8 Patch 3/6]Qemu: Cmd "block_set_hostcache" for dynamic cache change Supriya Kannery
2011-11-04 10:00 ` Kevin Wolf
2011-11-04 11:03 ` Supriya Kannery
2011-10-30 10:34 ` [Qemu-devel] [v8 Patch 4/6]Qemu: Add commandline -drive option 'hostcache' Supriya Kannery
2011-10-30 10:35 ` [Qemu-devel] [v8 Patch 5/6]Qemu: Framework for reopening images safely Supriya Kannery
2011-11-04 10:05 ` Kevin Wolf
2011-11-04 11:10 ` Supriya Kannery
2011-10-30 10:35 ` [Qemu-devel] [v8 Patch 6/6]Qemu: raw posix implementation of reopen functions Supriya Kannery
2011-11-04 10:19 ` Kevin Wolf [this message]
2011-11-04 2:29 ` [Qemu-devel] [v8 Patch 0/6]Qemu: Host pagecache setting from cmdline and monitor Zhi Yong Wu
2011-11-07 8:38 ` Supriya Kannery
2011-11-07 8:49 ` Zhi Yong Wu
2011-11-07 9:35 ` Supriya Kannery
2011-11-07 10:24 ` Zhi Yong Wu
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=4EB3BC20.6080607@redhat.com \
--to=kwolf@redhat.com \
--cc=hch@lst.de \
--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).