xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Christoph Egger <Christoph.Egger@amd.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given
Date: Wed, 30 May 2012 14:45:21 +0100	[thread overview]
Message-ID: <1338385522-21949-2-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1338385522-21949-1-git-send-email-roger.pau@citrix.com>

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>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 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;
-- 
1.7.7.5 (Apple Git-26)

  reply	other threads:[~2012-05-30 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 13:45 [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Roger Pau Monne
2012-05-30 13:45 ` Roger Pau Monne [this message]
2012-05-30 13:45 ` [PATCH 2/2] qemu-xen-trad/block: get right partition size Roger Pau Monne
2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
2012-05-30 16:13   ` Roger Pau Monne
2012-06-07 18:39   ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338385522-21949-2-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=Christoph.Egger@amd.com \
    --cc=kwolf@redhat.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).