From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:33882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPFAX-0000Zg-BS for qemu-devel@nongnu.org; Wed, 25 May 2011 10:34:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPFAW-00023q-Gm for qemu-devel@nongnu.org; Wed, 25 May 2011 10:34:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32235) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPFAW-000225-8f for qemu-devel@nongnu.org; Wed, 25 May 2011 10:34:40 -0400 Message-ID: <4DDCDD55.6050602@redhat.com> Date: Wed, 25 May 2011 12:43:33 +0200 From: Kevin Wolf MIME-Version: 1.0 References: <4DDB7AB5.6010807@amd.com> In-Reply-To: <4DDB7AB5.6010807@amd.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] 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: Christoph Egger Cc: "qemu-devel@nongnu.org" Am 24.05.2011 11:30, schrieb 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. If you provide a Signed-off-by, I think this patch is ready to be committed. Kevin > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 6b72470..64dceb1 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -136,12 +143,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) { > >