]> xenbits.xensource.com Git - qemu-xen-4.4-testing.git/commitdiff
qemu-xen-trad/block: use a character device if a block device is given
authorChristoph Egger <Christoph.Egger@amd.com>
Thu, 7 Jun 2012 18:35:28 +0000 (19:35 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 7 Jun 2012 18:37:36 +0000 (19:37 +0100)
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.

This is a backport of 1de1ae0a7d956b3c87712bf2c09d277f99873f4c.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Backport-requested-by: Roger Pau Monne <roger.pau@citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
block-raw-posix.c

index 9a02d4f311d02477dc180a5931a83eeb3c112376..e7d745787218105a25277a32d6576f508f2746b2 100644 (file)
@@ -116,11 +116,54 @@ static int posix_aio_init(void);
 
 static int fd_open(BlockDriverState *bs);
 
+#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(BlockDriverState *bs, const char *filename, int flags)
 {
     BDRVRawState *s = bs->opaque;
     int fd, open_flags, ret;
 
+    ret = raw_normalize_devicepath(&filename);
+    if (ret != 0) {
+        return ret;
+    }
+
     posix_aio_init();
 
     s->lseek_err_cnt = 0;