From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1FP6-0002Ob-Es for qemu-devel@nongnu.org; Tue, 14 Aug 2012 07:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1FP5-0004qg-Ei for qemu-devel@nongnu.org; Tue, 14 Aug 2012 07:35:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57965) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1FP5-0004qa-5C for qemu-devel@nongnu.org; Tue, 14 Aug 2012 07:35:19 -0400 Message-ID: <502A37E5.7070504@redhat.com> Date: Tue, 14 Aug 2012 13:35:01 +0200 From: Kevin Wolf 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> <502A32F5.1030200@linux.vnet.ibm.com> In-Reply-To: <502A32F5.1030200@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 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: supriyak@linux.vnet.ibm.com Cc: Shrinidhi Joshi , Stefan Hajnoczi , Jeff Cody , Corey Bryant , qemu-devel@nongnu.org, Luiz Capitulino , Eric Blake , Christoph Hellwig Am 14.08.2012 13:13, schrieb Supriya Kannery: > 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. We need to use a qemu_dup() here, so that the fdset implementation can keep track of the new fd. Kevin