From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M8V5b-0004bc-9X for qemu-devel@nongnu.org; Mon, 25 May 2009 03:59:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M8V5V-0004bN-Oo for qemu-devel@nongnu.org; Mon, 25 May 2009 03:59:17 -0400 Received: from [199.232.76.173] (port=43355 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8V5V-0004bK-Iq for qemu-devel@nongnu.org; Mon, 25 May 2009 03:59:13 -0400 Received: from mx20.gnu.org ([199.232.41.8]:41405) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M8V5V-0005a9-0q for qemu-devel@nongnu.org; Mon, 25 May 2009 03:59:13 -0400 Received: from verein.lst.de ([213.95.11.210]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M8V5S-0004zf-OE for qemu-devel@nongnu.org; Mon, 25 May 2009 03:59:11 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id n4P7x2IF002985 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 25 May 2009 09:59:02 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-6.6) id n4P7x1MQ002983 for qemu-devel@nongnu.org; Mon, 25 May 2009 09:59:01 +0200 Date: Mon, 25 May 2009 09:59:01 +0200 From: Christoph Hellwig Message-ID: <20090525075901.GA2936@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH 1/4] raw-posix: always store open flags List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Both the Linux floppy and the FreeBSD CDROM host device need to store the open flags so that they can re-open the device later. Store the open flags unconditionally to remove the ifdef mess and simply the calling conventions for the later patches in the series. Signed-off-by: Christoph Hellwig Index: qemu/block/raw-posix.c =================================================================== --- qemu.orig/block/raw-posix.c 2009-05-25 09:20:12.188814196 +0200 +++ qemu/block/raw-posix.c 2009-05-25 09:20:13.949939473 +0200 @@ -103,17 +103,14 @@ typedef struct BDRVRawState { int fd; int type; unsigned int lseek_err_cnt; + int open_flags; #if defined(__linux__) /* linux floppy specific */ - int fd_open_flags; int64_t fd_open_time; int64_t fd_error_time; int fd_got_error; int fd_media_changed; #endif -#if defined(__FreeBSD__) - int cd_open_flags; -#endif uint8_t* aligned_buf; } BDRVRawState; @@ -130,32 +127,32 @@ static int raw_is_inserted(BlockDriverSt static int raw_open(BlockDriverState *bs, const char *filename, int flags) { BDRVRawState *s = bs->opaque; - int fd, open_flags, ret; + int fd, ret; posix_aio_init(); s->lseek_err_cnt = 0; - open_flags = O_BINARY; + s->open_flags |= O_BINARY; if ((flags & BDRV_O_ACCESS) == O_RDWR) { - open_flags |= O_RDWR; + s->open_flags |= O_RDWR; } else { - open_flags |= O_RDONLY; + s->open_flags |= O_RDONLY; bs->read_only = 1; } if (flags & BDRV_O_CREAT) - open_flags |= O_CREAT | O_TRUNC; + s->open_flags |= O_CREAT | O_TRUNC; /* Use O_DSYNC for write-through caching, no flags for write-back caching, * and O_DIRECT for no caching. */ if ((flags & BDRV_O_NOCACHE)) - open_flags |= O_DIRECT; + s->open_flags |= O_DIRECT; else if (!(flags & BDRV_O_CACHE_WB)) - open_flags |= O_DSYNC; + s->open_flags |= O_DSYNC; s->type = FTYPE_FILE; - fd = open(filename, open_flags, 0644); + fd = open(filename, s->open_flags, 0644); if (fd < 0) { ret = -errno; if (ret == -EROFS) @@ -945,7 +942,7 @@ kern_return_t GetBSDPath( io_iterator_t static int hdev_open(BlockDriverState *bs, const char *filename, int flags) { BDRVRawState *s = bs->opaque; - int fd, open_flags, ret; + int fd, ret; posix_aio_init(); @@ -975,31 +972,30 @@ static int hdev_open(BlockDriverState *b IOObjectRelease( mediaIterator ); } #endif - open_flags = O_BINARY; + s->open_flags |= O_BINARY; if ((flags & BDRV_O_ACCESS) == O_RDWR) { - open_flags |= O_RDWR; + s->open_flags |= O_RDWR; } else { - open_flags |= O_RDONLY; + s->open_flags |= O_RDONLY; bs->read_only = 1; } /* Use O_DSYNC for write-through caching, no flags for write-back caching, * and O_DIRECT for no caching. */ if ((flags & BDRV_O_NOCACHE)) - open_flags |= O_DIRECT; + s->open_flags |= O_DIRECT; else if (!(flags & BDRV_O_CACHE_WB)) - open_flags |= O_DSYNC; + s->open_flags |= O_DSYNC; s->type = FTYPE_FILE; #if defined(__linux__) if (strstart(filename, "/dev/cd", NULL)) { /* open will not fail even if no CD is inserted */ - open_flags |= O_NONBLOCK; + s->open_flags |= O_NONBLOCK; s->type = FTYPE_CD; } else if (strstart(filename, "/dev/fd", NULL)) { s->type = FTYPE_FD; - s->fd_open_flags = open_flags; /* open will not fail even if no floppy is inserted */ - open_flags |= O_NONBLOCK; + s->open_flags |= O_NONBLOCK; #ifdef CONFIG_AIO } else if (strstart(filename, "/dev/sg", NULL)) { bs->sg = 1; @@ -1010,11 +1006,10 @@ static int hdev_open(BlockDriverState *b if (strstart(filename, "/dev/cd", NULL) || strstart(filename, "/dev/acd", NULL)) { s->type = FTYPE_CD; - s->cd_open_flags = open_flags; } #endif s->fd = -1; - fd = open(filename, open_flags, 0644); + fd = open(filename, s->open_flags, 0644); if (fd < 0) { ret = -errno; if (ret == -EROFS) @@ -1066,7 +1061,7 @@ static int fd_open(BlockDriverState *bs) #endif return -EIO; } - s->fd = open(bs->filename, s->fd_open_flags); + s->fd = open(bs->filename, s->open_flags & ~O_NONBLOCK); if (s->fd < 0) { s->fd_error_time = qemu_get_clock(rt_clock); s->fd_got_error = 1; @@ -1155,7 +1150,7 @@ static int raw_eject(BlockDriverState *b close(s->fd); s->fd = -1; } - fd = open(bs->filename, s->fd_open_flags | O_NONBLOCK); + fd = open(bs->filename, s->open_flags | O_NONBLOCK); if (fd >= 0) { if (ioctl(fd, FDEJECT, 0) < 0) perror("FDEJECT"); @@ -1251,7 +1246,7 @@ static int cd_open(BlockDriverState *bs) * FreeBSD seems to not notice sometimes... */ if (s->fd >= 0) close (s->fd); - fd = open(bs->filename, s->cd_open_flags, 0644); + fd = open(bs->filename, s->open_flags, 0644); if (fd < 0) { s->fd = -1; return -EIO;