From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:60895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpH7r-0000Pn-DE for qemu-devel@nongnu.org; Fri, 05 Aug 2011 05:55:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QpH7q-0006V8-8O for qemu-devel@nongnu.org; Fri, 05 Aug 2011 05:55:31 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:40115) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpH7q-0006V3-26 for qemu-devel@nongnu.org; Fri, 05 Aug 2011 05:55:30 -0400 Received: by qwj8 with SMTP id 8so60510qwj.4 for ; Fri, 05 Aug 2011 02:55:29 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <4E3BBE0C.4030109@redhat.com> Date: Fri, 05 Aug 2011 11:55:24 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <4E3BB203.5060703@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Safely reopening image files by stashing fds List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , Supriya Kannery , Anthony Liguori , qemu-devel On 08/05/2011 11:27 AM, Stefan Hajnoczi wrote: >>> First call bdrv_extract_fds() to stash the file descriptors, then close >>> the block device. Try opening the new image but if that fails, reopen using >>> the stashed file descriptors. >> >> Why not do the latter unconditionally? > > Because you cannot change O_DIRECT on an open fd:(. This is why > we're going through this pain. > > The only method I've found that works is to open("/proc/self/fd/X", > new_flags) but that's non-portable. Maybe I'm missing something obvious, but so is O_DIRECT, no? :) So for Linux you can dup the stashed file descriptors using /proc/self/fd and change flags directly, and for other OSes you can dup them using dup2 and change flags with F_SETFL. In any case, reopening can always be done using the stashed descriptors (or BlockDriverStates). Paolo