From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUJ52-0005e5-68 for qemu-devel@nongnu.org; Wed, 08 Jun 2011 09:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUJ4u-0008Vy-PY for qemu-devel@nongnu.org; Wed, 08 Jun 2011 09:45:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39335) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUJ4u-0008VZ-EG for qemu-devel@nongnu.org; Wed, 08 Jun 2011 09:45:48 -0400 From: Kevin Wolf Date: Wed, 8 Jun 2011 15:48:22 +0200 Message-Id: <1307540910-12398-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1307540910-12398-1-git-send-email-kwolf@redhat.com> References: <1307540910-12398-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 04/12] block/raw-posix: use a character device if a block device is given List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Christoph Egger 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. Signed-off-by: Christoph Egger Signed-off-by: Kevin Wolf --- 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 50428fd..00ed580 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -136,12 +136,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) { -- 1.7.5.2