From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RskNm-0007el-0l for qemu-devel@nongnu.org; Wed, 01 Feb 2012 19:18:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RskNj-0008N5-44 for qemu-devel@nongnu.org; Wed, 01 Feb 2012 19:18:33 -0500 Received: from e4.ny.us.ibm.com ([32.97.182.144]:36733) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RskNi-0008Mu-PT for qemu-devel@nongnu.org; Wed, 01 Feb 2012 19:18:31 -0500 Received: from /spool/local by e4.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 1 Feb 2012 19:18:28 -0500 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 897FB38C8065 for ; Wed, 1 Feb 2012 19:17:16 -0500 (EST) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q120Fxxe316688 for ; Wed, 1 Feb 2012 19:16:00 -0500 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q120Fw6f031398 for ; Wed, 1 Feb 2012 17:15:59 -0700 Message-ID: <4F29D5BD.2010209@linux.vnet.ibm.com> Date: Wed, 01 Feb 2012 18:15:57 -0600 From: Michael Roth MIME-Version: 1.0 References: <20120201030557.2990.74150.sendpatchset@skannery.in.ibm.com> <20120201030712.2990.41527.sendpatchset@skannery.in.ibm.com> In-Reply-To: <20120201030712.2990.41527.sendpatchset@skannery.in.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC Patch 5/7]Qemu: raw-posix image file reopen List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Supriya Kannery Cc: Kevin Wolf , Stefan Hajnoczi , Luiz Capitulino , qemu-devel@nongnu.org, Christoph Hellwig 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 > > 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, > >