From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:57947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOo8p-0006im-Kd for qemu-devel@nongnu.org; Tue, 24 May 2011 05:43:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOo8o-00073u-OG for qemu-devel@nongnu.org; Tue, 24 May 2011 05:43:07 -0400 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.31]:25085 helo=VA3EHSOBE005.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOo8o-00073q-KW for qemu-devel@nongnu.org; Tue, 24 May 2011 05:43:06 -0400 Received: from mail179-va3 (localhost.localdomain [127.0.0.1]) by mail179-va3-R.bigfish.com (Postfix) with ESMTP id 3D76889847C for ; Tue, 24 May 2011 09:43:05 +0000 (UTC) Received: from VA3EHSMHS008.bigfish.com (unknown [10.7.14.237]) by mail179-va3.bigfish.com (Postfix) with ESMTP id E51055C004F for ; Tue, 24 May 2011 09:43:04 +0000 (UTC) Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp02.amd.com (Axway MailGate 3.8.1) with ESMTP id 2831EC83F1 for ; Tue, 24 May 2011 04:43:01 -0500 (CDT) Message-ID: <4DDB7AB5.6010807@amd.com> Date: Tue, 24 May 2011 11:30:29 +0200 From: Christoph Egger MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15"; format=flowed Content-Transfer-Encoding: 7bit Subject: [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: "qemu-devel@nongnu.org" 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. 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) { -- ---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85689 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632