From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwSGT-0007pH-JG for qemu-devel@nongnu.org; Wed, 01 Aug 2012 02:18:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SwSGS-0004T4-GY for qemu-devel@nongnu.org; Wed, 01 Aug 2012 02:18:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwSGS-0004Sy-8Q for qemu-devel@nongnu.org; Wed, 01 Aug 2012 02:18:36 -0400 Message-ID: <5018CA31.8050800@redhat.com> Date: Wed, 01 Aug 2012 08:18:25 +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> <50181314.1040909@redhat.com> In-Reply-To: <50181314.1040909@redhat.com> Content-Type: text/plain; charset=UTF-8 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: Eric Blake Cc: Supriya Kannery , Shrinidhi Joshi , Stefan Hajnoczi , Jeff Cody , Corey Bryant , qemu-devel@nongnu.org, Luiz Capitulino , Christoph Hellwig Am 31.07.2012 19:17, schrieb Eric Blake: > On 07/30/2012 03: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 >> =================================================================== > >> +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); > > You called it out in your cover letter, but just pointing out that this > is one of the locations that needs a conditional fallback to > dup2/qemu_set_cloexec if dup3 and O_CLOEXEC are missing. > > More importantly, though, you want this to be fcntl(F_DUP_CLOEXEC) and > NOT dup3, so that you are duplicating to the first available fd rather > than accidentally overwriting whatever s->fd happened to be on entry. > Also, where is your error checking that you didn't just assign s->fd to > -1? It looks like your goal here is to stash a copy of the fd, so that > on failure you can then pivot over to your copy. Doesn't Corey's fd passing series introduce a helper function for F_DUP_CLOEXEC and emulation if it isn't support? Could be reused here then. Kevin