Patchwork block: split raw_getlength

login
register
mail settings
Submitter Christoph Hellwig
Date April 5, 2010, 2:12 p.m.
Message ID <20100405141257.GB24646@lst.de>
Download mbox | patch
Permalink /patch/49387/
State New
Headers show

Comments

Christoph Hellwig - April 5, 2010, 2:12 p.m.
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 <hch@lst.de>
Kevin Wolf - April 6, 2010, 9:36 a.m.
Am 05.04.2010 16:12, schrieb Christoph Hellwig:
> 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 <hch@lst.de>

Seems to leave some duplicate #ifdef CONFIG_BSD around, but that code is
a mess anyway and maybe it's the bit of additional ugliness that makes
someone of the BSD people clean it up. Anyway, it's definitely an
improvement over the current code.

Acked-by: Kevin Wolf <kwolf@redhat.com>

Patch

Index: qemu/block/raw-posix.c
===================================================================
--- qemu.orig/block/raw-posix.c	2010-04-05 15:35:06.621257218 +0200
+++ qemu/block/raw-posix.c	2010-04-05 15:43:28.532005927 +0200
@@ -628,8 +628,34 @@  static int64_t raw_getlength(BlockDriver
     } 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;
@@ -640,10 +666,6 @@  static int64_t  raw_getlength(BlockDrive
     int reopened = 0;
 #endif
 #endif
-#ifdef __sun__
-    struct dk_minfo minfo;
-    int rv;
-#endif
     int ret;
 
     ret = fd_open(bs);
@@ -687,22 +709,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
     {
         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)