[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/12] block/raw-posix: use a character device if a
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 04/12] block/raw-posix: use a character device if a block device is given |
Date: |
Wed, 8 Jun 2011 15:48:22 +0200 |
From: Christoph Egger <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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
- [Qemu-devel] [PULL 00/12] Block patches, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 03/12] vmdk: fix endianness bugs, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 04/12] block/raw-posix: use a character device if a block device is given,
Kevin Wolf <=
- [Qemu-devel] [PATCH 08/12] rbd: check return values when scheduling aio, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 02/12] block: clarify the meaning of BDRV_O_NOCACHE, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 06/12] rbd: use the higher level librbd instead of just librados, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 11/12] bdrv_img_create: Fix segfault, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 07/12] rbd: allow configuration of rados from the rbd filename, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 01/12] ide/core: Remove explicit setting of BM_STATUS_INT, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 10/12] qcow2: Fix memory leaks in error cases, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 05/12] block/raw-posix: get right partition size, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 09/12] rbd: Add bdrv_truncate implementation, Kevin Wolf, 2011/06/08
- [Qemu-devel] [PATCH 12/12] qemu-img create: Fix displayed default cluster size, Kevin Wolf, 2011/06/08