From patchwork Fri Apr 23 15:30:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 50831 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 C9B21B7D27 for ; Sat, 24 Apr 2010 01:58:55 +1000 (EST) Received: from localhost ([127.0.0.1]:54961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5LG3-0007rP-Tr for incoming@patchwork.ozlabs.org; Fri, 23 Apr 2010 11:57:35 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O5KrQ-0007XB-4m for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:32:08 -0400 Received: from [140.186.70.92] (port=50412 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5KrN-0007VE-GZ for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:32:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O5KrH-0005uS-OI for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:32:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21549) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5KrF-0005tn-V7 for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:31:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3NFVtPU023492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Apr 2010 11:31:55 -0400 Received: from localhost.localdomain (vpn2-9-155.ams2.redhat.com [10.36.9.155]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3NFVOCG020467; Fri, 23 Apr 2010 11:31:53 -0400 From: Kevin Wolf To: aliguori@linux.vnet.ibm.com Date: Fri, 23 Apr 2010 17:30:43 +0200 Message-Id: <1272036658-26776-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1272036658-26776-1-git-send-email-kwolf@redhat.com> References: <1272036658-26776-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 11/26] 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 From: Christoph Hellwig 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 Signed-off-by: Kevin Wolf --- block/raw-posix.c | 65 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 42 insertions(+), 23 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 6521ca4..4cda9c1 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -627,29 +627,48 @@ static int64_t raw_getlength(BlockDriverState *bs) } 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 @@ -684,24 +703,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)