From patchwork Tue Apr 6 17:13:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 49533 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 49E94B7D44 for ; Wed, 7 Apr 2010 03:27:27 +1000 (EST) Received: from localhost ([127.0.0.1]:55627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzCNL-00030l-P8 for incoming@patchwork.ozlabs.org; Tue, 06 Apr 2010 13:15:43 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NzCLY-0002pJ-RB for qemu-devel@nongnu.org; Tue, 06 Apr 2010 13:13:52 -0400 Received: from [140.186.70.92] (port=54812 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzCLU-0002oh-S5 for qemu-devel@nongnu.org; Tue, 06 Apr 2010 13:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NzCLR-0007Yw-0Z for qemu-devel@nongnu.org; Tue, 06 Apr 2010 13:13:48 -0400 Received: from verein.lst.de ([213.95.11.210]:33419) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NzCLQ-0007Yn-OM for qemu-devel@nongnu.org; Tue, 06 Apr 2010 13:13:44 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id o36HDiWY011075 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 6 Apr 2010 19:13:44 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o36HDiF7011074 for qemu-devel@nongnu.org; Tue, 6 Apr 2010 19:13:44 +0200 Date: Tue, 6 Apr 2010 19:13:44 +0200 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20100406171344.GB10881@lst.de> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.3.28i X-Scanned-By: MIMEDefang 2.39 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH v2] block: split raw_getlength X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Split up the raw_getlength into separate generic, solaris and BSD versions to reduce the ifdef maze a bit. The BSD variant still is a complete maze, but to clean it up properly we'd need some people using the BSD variants to figure out what code is used for what variant. Signed-off-by: Christoph Hellwig Acked-by: Kevin Wolf Index: qemu/block/raw-posix.c =================================================================== --- qemu.orig/block/raw-posix.c 2010-04-06 19:05:52.342010185 +0200 +++ qemu/block/raw-posix.c 2010-04-06 19:10:59.508006065 +0200 @@ -628,29 +628,48 @@ static int64_t raw_getlength(BlockDriver } else return st.st_size; } -#else /* !__OpenBSD__ */ -static int64_t raw_getlength(BlockDriverState *bs) +#elif defined(__sun__) +static int64_t raw_getlength(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + struct dk_minfo minfo; + int ret; + + ret = fd_open(bs); + if (ret < 0) { + return ret; + } + + /* + * Use the DKIOCGMEDIAINFO ioctl to read the size. + */ + ret = ioctl(s->fd, DKIOCGMEDIAINFO, &minfo); + if (ret != -1) { + return minfo.dki_lbsize * minfo.dki_capacity; + } + + /* + * There are reports that lseek on some devices fails, but + * irc discussion said that contingency on contingency was overkill. + */ + return lseek(s->fd, 0, SEEK_END); +} +#elif defined(CONFIG_BSD) +static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; int fd = s->fd; int64_t size; -#ifdef CONFIG_BSD struct stat sb; #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) int reopened = 0; #endif -#endif -#ifdef __sun__ - struct dk_minfo minfo; - int rv; -#endif int ret; ret = fd_open(bs); if (ret < 0) return ret; -#ifdef CONFIG_BSD #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) again: #endif @@ -685,24 +704,24 @@ again: } } #endif - } else -#endif -#ifdef __sun__ - /* - * use the DKIOCGMEDIAINFO ioctl to read the size. - */ - rv = ioctl ( fd, DKIOCGMEDIAINFO, &minfo ); - if ( rv != -1 ) { - size = minfo.dki_lbsize * minfo.dki_capacity; - } else /* there are reports that lseek on some devices - fails, but irc discussion said that contingency - on contingency was overkill */ -#endif - { + } else { size = lseek(fd, 0, SEEK_END); } return size; } +#else +static int64_t raw_getlength(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + int ret; + + ret = fd_open(bs); + if (ret < 0) { + return ret; + } + + return lseek(s->fd, 0, SEEK_END); +} #endif static int raw_create(const char *filename, QEMUOptionParameter *options)