qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block/raw-posix: use a character device if a block device is given
@ 2011-05-23 12:34 Christoph Egger
  2011-05-23 13:42 ` Christoph Hellwig
  2011-05-23 14:11 ` Kevin Wolf
  0 siblings, 2 replies; 11+ messages in thread
From: Christoph Egger @ 2011-05-23 12:34 UTC (permalink / raw)
  To: qemu-devel@nongnu.org


if given a block device, use the character device instead.

From: Manuel Bouyer <bouyer@NetBSD.org>
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6b72470..d05f373 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -136,11 +143,45 @@ static int64_t raw_getlength(BlockDriverState *bs);
  static int cdrom_reopen(BlockDriverState *bs);
  #endif

+#if defined(__NetBSD__)
+static const char *raw_get_rawdevice(const char *filename)
+{
+    static char namebuf[PATH_MAX];
+    const char *dp = strrchr(filename, '/');
+
+    if (dp == NULL) {
+        snprintf(namebuf, PATH_MAX, "r%s", filename);
+    } else {
+        snprintf(namebuf, PATH_MAX, "%.*s/r%s",
+            (int)(dp - filename), filename, dp + 1);
+    }
+    fprintf(stderr, "%s is a block device", filename);
+    filename = namebuf;
+    fprintf(stderr, ", using %s\n", filename);
+
+    return filename;
+}
+#else
+static const char *raw_get_rawdevice(const char *filename)
+{
+    return filename;
+}
+#endif
+
  static int raw_open_common(BlockDriverState *bs, const char *filename,
                             int bdrv_flags, int open_flags)
  {
      BDRVRawState *s = bs->opaque;
      int fd, ret;
+    struct stat sb;
+
+    if (lstat(filename, &sb) < 0) {
+        fprintf(stderr, "%s: stat failed: %s\n", filename, 
strerror(errno));
+        return -errno;
+    }
+
+    if (S_ISBLK(sb.st_mode))
+        filename = raw_get_rawdevice(filename);

      s->open_flags = open_flags | O_BINARY;
      s->open_flags &= ~O_ACCMODE;


-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH] block/raw-posix: use a character device if a block device is given
@ 2011-05-24  9:30 Christoph Egger
  2011-05-25 10:43 ` Kevin Wolf
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Egger @ 2011-05-24  9:30 UTC (permalink / raw)
  To: qemu-devel@nongnu.org


On NetBSD a userland process is better with the character device
interface. In addition, a block device can't be opened twice; if a Xen
backend opens it, qemu can't and vice-versa.

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6b72470..64dceb1 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -136,12 +143,55 @@ static int64_t raw_getlength(BlockDriverState *bs);
  static int cdrom_reopen(BlockDriverState *bs);
  #endif

+#if defined(__NetBSD__)
+static int raw_normalize_devicepath(const char **filename)
+{
+    static char namebuf[PATH_MAX];
+    const char *dp, *fname;
+    struct stat sb;
+
+    fname = *filename;
+    dp = strrchr(fname, '/');
+    if (lstat(fname, &sb) < 0) {
+        fprintf(stderr, "%s: stat failed: %s\n",
+            fname, strerror(errno));
+        return -errno;
+    }
+
+    if (!S_ISBLK(sb.st_mode)) {
+        return 0;
+    }
+
+    if (dp == NULL) {
+        snprintf(namebuf, PATH_MAX, "r%s", fname);
+    } else {
+        snprintf(namebuf, PATH_MAX, "%.*s/r%s",
+            (int)(dp - fname), fname, dp + 1);
+    }
+    fprintf(stderr, "%s is a block device", fname);
+    *filename = namebuf;
+    fprintf(stderr, ", using %s\n", *filename);
+
+    return 0;
+}
+#else
+static int raw_normalize_devicepath(const char **filename)
+{
+    return 0;
+}
+#endif
+
  static int raw_open_common(BlockDriverState *bs, const char *filename,
                             int bdrv_flags, int open_flags)
  {
      BDRVRawState *s = bs->opaque;
      int fd, ret;

+    ret = raw_normalize_devicepath(&filename);
+    if (ret != 0) {
+        return ret;
+    }
+
      s->open_flags = open_flags | O_BINARY;
      s->open_flags &= ~O_ACCMODE;
      if (bdrv_flags & BDRV_O_RDWR) {


-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-05-25 14:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-23 12:34 [Qemu-devel] [PATCH] block/raw-posix: use a character device if a block device is given Christoph Egger
2011-05-23 13:42 ` Christoph Hellwig
2011-05-23 13:49   ` Christoph Egger
2011-05-23 14:11 ` Kevin Wolf
2011-05-24  8:36   ` Christoph Egger
2011-05-24  9:10     ` Kevin Wolf
2011-05-24  9:24       ` Christoph Egger
  -- strict thread matches above, loose matches on Subject: below --
2011-05-24  9:30 Christoph Egger
2011-05-25 10:43 ` Kevin Wolf
2011-05-25 12:19   ` Christoph Egger
2011-05-25 13:01     ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).