From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1F4b-0003Lp-Bg for qemu-devel@nongnu.org; Tue, 14 Aug 2012 07:14:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1F4a-0006dC-9W for qemu-devel@nongnu.org; Tue, 14 Aug 2012 07:14:09 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:33327) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1F4Z-0006d4-NP for qemu-devel@nongnu.org; Tue, 14 Aug 2012 07:14:08 -0400 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Aug 2012 21:13:49 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7EB5Txa17367088 for ; Tue, 14 Aug 2012 21:05:29 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7EBE0Lx000840 for ; Tue, 14 Aug 2012 21:14:01 +1000 Message-ID: <502A32F5.1030200@linux.vnet.ibm.com> Date: Tue, 14 Aug 2012 16:43:57 +0530 From: Supriya Kannery MIME-Version: 1.0 References: <20120730213409.21536.7589.sendpatchset@skannery.in.ibm.com> <20120730213437.21536.87232.sendpatchset@skannery.in.ibm.com> <50251061.9090203@linux.vnet.ibm.com> In-Reply-To: <50251061.9090203@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [v2 Patch 2/9]block: raw-posix image file reopen Reply-To: supriyak@linux.vnet.ibm.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: Kevin Wolf , Shrinidhi Joshi , Stefan Hajnoczi , Jeff Cody , qemu-devel@nongnu.org, Luiz Capitulino , Eric Blake , Christoph Hellwig On 08/10/2012 07:15 PM, Corey Bryant wrote: > > > On 07/30/2012 05:34 PM, Supriya Kannery wrote: >> +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. > Since we are duping the file descriptor before reaching this bdrv_close(), refcount for fd won't become zero. - thanks, Supriya