[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/26] block: split raw_getlength
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 11/26] block: split raw_getlength |
Date: |
Fri, 23 Apr 2010 17:30:43 +0200 |
From: Christoph Hellwig <address@hidden>
Split up the raw_getlength into separate generic, solaris and BSD
versions to reduce the ifdef maze a bit. The BSD variant still
is a complete maze, but to clean it up properly we'd need some
people using the BSD variants to figure out what code is used
for what variant.
Signed-off-by: Christoph Hellwig <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/raw-posix.c | 65 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6521ca4..4cda9c1 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -627,29 +627,48 @@ static int64_t raw_getlength(BlockDriverState *bs)
} else
return st.st_size;
}
-#else /* !__OpenBSD__ */
-static int64_t raw_getlength(BlockDriverState *bs)
+#elif defined(__sun__)
+static int64_t raw_getlength(BlockDriverState *bs)
+{
+ BDRVRawState *s = bs->opaque;
+ struct dk_minfo minfo;
+ int ret;
+
+ ret = fd_open(bs);
+ if (ret < 0) {
+ return ret;
+ }
+
+ /*
+ * Use the DKIOCGMEDIAINFO ioctl to read the size.
+ */
+ ret = ioctl(s->fd, DKIOCGMEDIAINFO, &minfo);
+ if (ret != -1) {
+ return minfo.dki_lbsize * minfo.dki_capacity;
+ }
+
+ /*
+ * There are reports that lseek on some devices fails, but
+ * irc discussion said that contingency on contingency was overkill.
+ */
+ return lseek(s->fd, 0, SEEK_END);
+}
+#elif defined(CONFIG_BSD)
+static int64_t raw_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int fd = s->fd;
int64_t size;
-#ifdef CONFIG_BSD
struct stat sb;
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
int reopened = 0;
#endif
-#endif
-#ifdef __sun__
- struct dk_minfo minfo;
- int rv;
-#endif
int ret;
ret = fd_open(bs);
if (ret < 0)
return ret;
-#ifdef CONFIG_BSD
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
again:
#endif
@@ -684,24 +703,24 @@ again:
}
}
#endif
- } else
-#endif
-#ifdef __sun__
- /*
- * use the DKIOCGMEDIAINFO ioctl to read the size.
- */
- rv = ioctl ( fd, DKIOCGMEDIAINFO, &minfo );
- if ( rv != -1 ) {
- size = minfo.dki_lbsize * minfo.dki_capacity;
- } else /* there are reports that lseek on some devices
- fails, but irc discussion said that contingency
- on contingency was overkill */
-#endif
- {
+ } else {
size = lseek(fd, 0, SEEK_END);
}
return size;
}
+#else
+static int64_t raw_getlength(BlockDriverState *bs)
+{
+ BDRVRawState *s = bs->opaque;
+ int ret;
+
+ ret = fd_open(bs);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return lseek(s->fd, 0, SEEK_END);
+}
#endif
static int raw_create(const char *filename, QEMUOptionParameter *options)
--
1.6.6.1
- [Qemu-devel] [PATCH 04/26] blkdebug: Inject errors, (continued)
- [Qemu-devel] [PATCH 04/26] blkdebug: Inject errors, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 03/26] blkdebug: Basic request passthrough, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 05/26] Make qemu-config available for tools, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 06/26] blkdebug: Add events and rules, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 08/26] qcow2: Fix creation of large images, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 09/26] Replace calls of old bdrv_open, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 13/26] qcow2: Fix error return code in qcow2_alloc_cluster_link_l2, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 10/26] block: get rid of the BDRV_O_FILE flag, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 12/26] qcow2: Return 0/-errno in write_l2_entries, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 07/26] qcow2: Trigger blkdebug events, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 11/26] block: split raw_getlength,
Kevin Wolf <=
- [Qemu-devel] [PATCH 15/26] qcow2: Return 0/-errno in l2_allocate, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 14/26] qcow2: Return 0/-errno in write_l1_entry, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 17/26] block: Do not export bdrv_first, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 16/26] cleanup block driver option handling in vl.c, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 18/26] block: Convert bdrv_first to QTAILQ, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 21/26] block: Convert first_drv to QLIST, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 19/26] Remove un-needed code, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 20/26] block.h: bdrv_create2 doesn't exist any more, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 22/26] qemu-img: Eliminate bdrv_new_open() code duplication, Kevin Wolf, 2010/04/23
- [Qemu-devel] [PATCH 23/26] qemu-img: Fix BRDV_O_FLAGS typo, Kevin Wolf, 2010/04/23