[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [qemu-xen-unstable] qemu-xen-trad/block: use a character device if a block device is given



commit 136f340531929c723113bbd625d99de2b552a871
Author: Christoph Egger <Christoph.Egger@xxxxxxx>
Date:   Thu Jun 7 19:35:28 2012 +0100

    qemu-xen-trad/block: use a character device if a block device is given
    
    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@xxxxxxx>
    Signed-off-by: Kevin Wolf <kwolf@xxxxxxxxxx>
    
    Backport-requested-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
    Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
---
 block-raw-posix.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index 9a02d4f..e7d7457 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -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;
--
generated by git-patchbot for /home/xen/git/qemu-xen-unstable.git

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.