From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzpXd-0003bE-Po for qemu-devel@nongnu.org; Fri, 10 Aug 2012 09:46:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzpXc-00072E-Fs for qemu-devel@nongnu.org; Fri, 10 Aug 2012 09:46:17 -0400 Received: from e32.co.us.ibm.com ([32.97.110.150]:56681) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzpXc-00070S-8f for qemu-devel@nongnu.org; Fri, 10 Aug 2012 09:46:16 -0400 Received: from /spool/local by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Aug 2012 07:46:14 -0600 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id D989B3E4003C for ; Fri, 10 Aug 2012 13:45:54 +0000 (WET) Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7ADjNcd145152 for ; Fri, 10 Aug 2012 07:45:39 -0600 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7ADkOGg013561 for ; Fri, 10 Aug 2012 07:46:24 -0600 Message-ID: <50251061.9090203@linux.vnet.ibm.com> Date: Fri, 10 Aug 2012 09:45:05 -0400 From: Corey Bryant MIME-Version: 1.0 References: <20120730213409.21536.7589.sendpatchset@skannery.in.ibm.com> <20120730213437.21536.87232.sendpatchset@skannery.in.ibm.com> In-Reply-To: <20120730213437.21536.87232.sendpatchset@skannery.in.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [v2 Patch 2/9]block: raw-posix image file reopen List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Supriya Kannery , Kevin Wolf , Eric Blake Cc: Shrinidhi Joshi , Stefan Hajnoczi , Jeff Cody , qemu-devel@nongnu.org, Luiz Capitulino , Christoph Hellwig On 07/30/2012 05:34 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) > { > @@ -113,6 +129,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 > @@ -140,8 +140,15 @@ 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); > +static void raw_stash_state(BDRVRawState *stashed_state, BDRVRawState *s); > +static void raw_revert_state(BDRVRawState *s, BDRVRawState *stashed_state); > > #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) > static int cdrom_reopen(BlockDriverState *bs); > @@ -283,6 +290,117 @@ 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)); > + raw_stash_state(raw_rs->stash_s, s); > + s->fd = dup3(raw_rs->stash_s->fd, s->fd, O_CLOEXEC); > + > + *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; > + } > + ret = fcntl_setfl(s->fd, s->open_flags); > + } else { > + > + /* close and reopen using new flags */ > + bs->drv->bdrv_close(bs); > + ret = bs->drv->bdrv_file_open(bs, bs->filename, flags); Will this allow the fdset refcount to get to zero? I was hoping your patches would prevent that from happening. Perhaps Kevin or Eric can weigh in. qemu_open() increments the refcount for an fdset when an fd from it is used, and qemu_close() decrements it. I think if you were able to perform the open before the close here that refcount wouldn't get to zero. -- Regards, Corey