From patchwork Wed Mar 23 17:40:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 88104 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 5A488B6F7B for ; Thu, 24 Mar 2011 04:43:04 +1100 (EST) Received: from localhost ([127.0.0.1]:41581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2S5E-00021i-Jm for incoming@patchwork.ozlabs.org; Wed, 23 Mar 2011 13:43:00 -0400 Received: from [140.186.70.92] (port=60555 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2S3h-0001tt-Rd for qemu-devel@nongnu.org; Wed, 23 Mar 2011 13:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2S3g-0003sF-Gg for qemu-devel@nongnu.org; Wed, 23 Mar 2011 13:41:25 -0400 Received: from mtagate2.uk.ibm.com ([194.196.100.162]:36391) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2S3g-0003rg-9X for qemu-devel@nongnu.org; Wed, 23 Mar 2011 13:41:24 -0400 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p2NHfMbt022464 for ; Wed, 23 Mar 2011 17:41:22 GMT Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2NHfol21933330 for ; Wed, 23 Mar 2011 17:41:50 GMT Received: from d06av10.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2NHfLKt016822 for ; Wed, 23 Mar 2011 11:41:22 -0600 Received: from stefanha-thinkpad.ibm.com (sig-9-145-129-205.de.ibm.com [9.145.129.205]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p2NHfJeJ016713; Wed, 23 Mar 2011 11:41:21 -0600 From: Stefan Hajnoczi To: Date: Wed, 23 Mar 2011 17:40:54 +0000 Message-Id: <1300902055-25850-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1300902055-25850-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1300902055-25850-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.162 Cc: Kevin Wolf , Amit Shah , Anthony Liguori , Ryan Harper , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 2/3] block: Do not cache device size for removable media 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 The block layer caches the device size to avoid doing lseek(fd, 0, SEEK_END) every time this value is needed. For removable media the device size becomes stale if a new medium is inserted. This patch simply prevents device size caching for removable media. A smarter solution is to update the cached device size when a new medium is inserted. Given that there are currently bugs with CD-ROM media change I do not want to implement that approach until we've gotten things correct first. Signed-off-by: Stefan Hajnoczi --- block.c | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 8f224b4..89f6ded 100644 --- a/block.c +++ b/block.c @@ -1153,14 +1153,12 @@ int64_t bdrv_getlength(BlockDriverState *bs) if (!drv) return -ENOMEDIUM; - /* Fixed size devices use the total_sectors value for speed instead of - issuing a length query (like lseek) on each call. Also, legacy block - drivers don't provide a bdrv_getlength function and must use - total_sectors. */ - if (!bs->growable || !drv->bdrv_getlength) { - return bs->total_sectors * BDRV_SECTOR_SIZE; - } - return drv->bdrv_getlength(bs); + if (bs->growable || bs->removable) { + if (drv->bdrv_getlength) { + return drv->bdrv_getlength(bs); + } + } + return bs->total_sectors * BDRV_SECTOR_SIZE; } /* return 0 as number of sectors if no device present or error */