From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MGYTw-0007Qd-Rj for qemu-devel@nongnu.org; Tue, 16 Jun 2009 09:13:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MGYTr-0007NT-L0 for qemu-devel@nongnu.org; Tue, 16 Jun 2009 09:13:44 -0400 Received: from [199.232.76.173] (port=40940 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MGYTr-0007NC-81 for qemu-devel@nongnu.org; Tue, 16 Jun 2009 09:13:39 -0400 Received: from mx2.redhat.com ([66.187.237.31]:51441) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MGYTq-00013B-Rt for qemu-devel@nongnu.org; Tue, 16 Jun 2009 09:13:39 -0400 Message-ID: <4A379A37.3020903@redhat.com> Date: Tue, 16 Jun 2009 15:12:23 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 2/2] raw-posix: Remove O_RDWR when attempting to open a file read-only References: <1245154972-21581-1-git-send-email-avi@redhat.com> <1245154972-21581-3-git-send-email-avi@redhat.com> In-Reply-To: <1245154972-21581-3-git-send-email-avi@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel@nongnu.org, Christoph Hellwig Avi Kivity schrieb: > When we open a file, we first attempt to open it read-write, then fall back > to read-only. Unfortunately we reuse the flags from the previous attempt, > so both attempts try to open the file with write permissions, and fail. > > Fix by clearing the O_RDWR flag from the previous attempt. > > Signed-off-by: Avi Kivity > --- > block/raw-posix.c | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 5790206..7536a72 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -136,6 +136,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, > if ((flags & BDRV_O_ACCESS) == BDRV_O_RDWR) { > s->open_flags |= O_RDWR; > } else { > + s->open_flags &= ~O_RDWR; > s->open_flags |= O_RDONLY; > bs->read_only = 1; > } Does the standard say anything about the values of the constants? Wouldn't it be cleaner to have a s->open_flags &= ~O_ACCMODE before the if instead, so that O_RDONLY is reset in the other case? Kevin