From patchwork Mon Apr 5 14:12:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 49387 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 B9CBBB7BEE for ; Tue, 6 Apr 2010 00:15:28 +1000 (EST) Received: from localhost ([127.0.0.1]:45451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nyn5J-0007yC-Rn for incoming@patchwork.ozlabs.org; Mon, 05 Apr 2010 10:15:25 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nyn30-0007TH-5t for qemu-devel@nongnu.org; Mon, 05 Apr 2010 10:13:02 -0400 Received: from [140.186.70.92] (port=34260 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nyn2y-0007SY-23 for qemu-devel@nongnu.org; Mon, 05 Apr 2010 10:13:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nyn2w-0000gs-NQ for qemu-devel@nongnu.org; Mon, 05 Apr 2010 10:12:59 -0400 Received: from verein.lst.de ([213.95.11.210]:56927) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nyn2w-0000gl-Dy for qemu-devel@nongnu.org; Mon, 05 Apr 2010 10:12:58 -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 o35ECvWY024673 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 5 Apr 2010 16:12:57 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o35ECvl5024672 for qemu-devel@nongnu.org; Mon, 5 Apr 2010 16:12:57 +0200 Date: Mon, 5 Apr 2010 16:12:57 +0200 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20100405141257.GB24646@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] 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-05 15:35:06.621257218 +0200 +++ qemu/block/raw-posix.c 2010-04-05 15:43:28.532005927 +0200 @@ -628,8 +628,34 @@ 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; @@ -640,10 +666,6 @@ static int64_t raw_getlength(BlockDrive int reopened = 0; #endif #endif -#ifdef __sun__ - struct dk_minfo minfo; - int rv; -#endif int ret; ret = fd_open(bs); @@ -687,22 +709,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 { 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)