From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: Supriya Kannery <supriyak@linux.vnet.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [Qemu-devel] [RFC Patch 5/7]Qemu: raw-posix image file reopen
Date: Wed, 01 Feb 2012 18:15:57 -0600 [thread overview]
Message-ID: <4F29D5BD.2010209@linux.vnet.ibm.com> (raw)
In-Reply-To: <20120201030712.2990.41527.sendpatchset@skannery.in.ibm.com>
On 01/31/2012 09:07 PM, Supriya Kannery wrote:
> 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,22 @@ 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)
> +{
> + bdrv_reopen_commit(bs->file, rs);
> +}
> +
> +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)
> {
> @@ -109,6 +125,10 @@ static BlockDriver bdrv_raw = {
> .instance_size = 1,
>
> .bdrv_open = raw_open,
> + .bdrv_reopen_prepare
> + = raw_reopen_prepare,
> + .bdrv_reopen_commit = raw_reopen_commit,
> + .bdrv_reopen_abort = raw_reopen_abort,
> .bdrv_close = raw_close,
>
> .bdrv_co_readv = raw_co_readv,
> Index: qemu/block/raw-posix.c
> ===================================================================
> --- qemu.orig/block/raw-posix.c
> +++ qemu/block/raw-posix.c
> @@ -136,6 +136,11 @@ typedef struct BDRVRawState {
> #endif
> } BDRVRawState;
>
> +typedef struct BDRVRawReopenState {
> + BDRVReopenState reopen_state;
> + BDRVRawState *stash_s;
> +} BDRVRawReopenState;
> +
> static int fd_open(BlockDriverState *bs);
> static int64_t raw_getlength(BlockDriverState *bs);
>
> @@ -279,6 +284,71 @@ 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)
> +{
> + BDRVRawReopenState *raw_rs = g_malloc0(sizeof(BDRVRawReopenState));
> + BDRVRawState *s = bs->opaque;
> + int ret = 0;
> +
> + raw_rs->reopen_state.bs = bs;
> +
> + /* stash state before reopen */
> + raw_rs->stash_s = g_malloc0(sizeof(BDRVRawState));
> + memcpy(raw_rs->stash_s, s, sizeof(BDRVRawState));
> + s->fd = dup(raw_rs->stash_s->fd);
> +
> + *prs =&(raw_rs->reopen_state);
> +
> + /* Flags that can be set using fcntl */
> + int fcntl_flags = BDRV_O_NOCACHE;
> +
> + if ((bs->open_flags& ~fcntl_flags) == (flags& ~fcntl_flags)) {
> + if ((flags& BDRV_O_NOCACHE)) {
> + s->open_flags |= O_DIRECT;
> + } else {
> + s->open_flags&= ~O_DIRECT;
> + }
> + printf("O_DIRECT flag\n");
> + ret = fcntl_setfl(s->fd, s->open_flags);
raw-posix.c:raw_aio_submit() does some extra alignment work if
s->aligned_buf was set due to the image being opened O_DIRECT initially,
not sure what the impact is but probably want to clean that up here.
> + } else {
> +
> + printf("close and open with new flags\n");
> + /* close and reopen using new flags */
> + bs->drv->bdrv_close(bs);
> + ret = bs->drv->bdrv_file_open(bs, bs->filename, flags);
> + }
> + return ret;
> +}
> +
> +static void raw_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs)
> +{
> + BDRVRawReopenState *raw_rs;
> +
> + raw_rs = container_of(rs, BDRVRawReopenState, reopen_state);
> +
> + /* clean up stashed state */
> + close(raw_rs->stash_s->fd);
> + g_free(raw_rs->stash_s);
> + g_free(raw_rs);
> +}
> +
> +static void raw_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
> +{
> + BDRVRawReopenState *raw_rs;
> + BDRVRawState *s = bs->opaque;
> +
> + raw_rs = container_of(rs, BDRVRawReopenState, reopen_state);
> +
> + /* revert to stashed state */
> + if (s->fd != -1) {
> + close(s->fd);
> + }
> + memcpy(s, raw_rs->stash_s, sizeof(BDRVRawState));
> + g_free(raw_rs->stash_s);
> + g_free(raw_rs);
> +}
> +
> /* XXX: use host sector size if necessary with:
> #ifdef DIOCGSECTORSIZE
> {
> @@ -631,6 +701,9 @@ static BlockDriver bdrv_file = {
> .instance_size = sizeof(BDRVRawState),
> .bdrv_probe = NULL, /* no probe for protocols */
> .bdrv_file_open = raw_open,
> + .bdrv_reopen_prepare = raw_reopen_prepare,
> + .bdrv_reopen_commit = raw_reopen_commit,
> + .bdrv_reopen_abort = raw_reopen_abort,
> .bdrv_close = raw_close,
> .bdrv_create = raw_create,
> .bdrv_co_discard = raw_co_discard,
>
>
next prev parent reply other threads:[~2012-02-02 0:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-01 3:05 [Qemu-devel] [RFC Patch 0/7]Qemu: Dynamic host pagecache change Supriya Kannery
2012-02-01 3:06 ` [Qemu-devel] [RFC Patch 1/7]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
2012-02-08 12:00 ` Luiz Capitulino
2012-02-13 13:19 ` Supriya Kannery
2012-02-01 3:06 ` [Qemu-devel] [RFC Patch 2/7]Qemu: Error classes for file reopen and data sync failure Supriya Kannery
2012-02-07 7:56 ` Stefan Hajnoczi
2012-02-13 13:13 ` Supriya Kannery
2012-02-01 3:06 ` [Qemu-devel] [RFC Patch 3/7]Qemu: Cmd "block_set_hostcache" for dynamic cache change Supriya Kannery
2012-02-02 0:09 ` Michael Roth
2012-02-02 10:14 ` Kevin Wolf
2012-02-08 12:07 ` Luiz Capitulino
2012-02-13 13:21 ` Supriya Kannery
2012-02-01 3:06 ` [Qemu-devel] [RFC Patch 4/7]Qemu: Framework for reopening image files safely Supriya Kannery
2012-02-07 10:08 ` Stefan Hajnoczi
2012-02-14 13:34 ` Supriya Kannery
2012-02-08 15:07 ` Kevin Wolf
2012-02-13 13:49 ` Supriya Kannery
2012-02-01 3:07 ` [Qemu-devel] [RFC Patch 5/7]Qemu: raw-posix image file reopen Supriya Kannery
2012-02-02 0:15 ` Michael Roth [this message]
2012-02-13 13:12 ` Supriya Kannery
2012-02-07 10:17 ` Stefan Hajnoczi
2012-02-14 13:36 ` Supriya Kannery
2012-02-08 14:54 ` Kevin Wolf
2012-02-13 13:28 ` Supriya Kannery
2012-02-01 3:07 ` [Qemu-devel] [RFC Patch 6/7]Qemu: raw-win32 " Supriya Kannery
2012-02-08 15:02 ` Kevin Wolf
2012-02-13 13:29 ` Supriya Kannery
2012-02-01 3:07 ` [Qemu-devel] [RFC Patch 7/7]Qemu: vmdk " Supriya Kannery
2012-02-01 22:41 ` [Qemu-devel] [RFC Patch 0/7]Qemu: Dynamic host pagecache change Eric Blake
2012-02-02 9:12 ` Kevin Wolf
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=4F29D5BD.2010209@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=hch@lst.de \
--cc=kwolf@redhat.com \
--cc=lcapitulino@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).