From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=55930 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4eQn-000724-DD for qemu-devel@nongnu.org; Tue, 29 Mar 2011 15:18:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4eFD-0001AC-St for qemu-devel@nongnu.org; Tue, 29 Mar 2011 15:06:25 -0400 Received: from mtagate5.uk.ibm.com ([194.196.100.165]:44543) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4eFD-00019k-KT for qemu-devel@nongnu.org; Tue, 29 Mar 2011 15:06:23 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate5.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p2TJ6MQ9022691 for ; Tue, 29 Mar 2011 19:06:22 GMT Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2TJ6uEJ1912968 for ; Tue, 29 Mar 2011 20:06:56 +0100 Received: from d06av11.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2TJ6LLu008146 for ; Tue, 29 Mar 2011 13:06:21 -0600 From: Stefan Hajnoczi Date: Tue, 29 Mar 2011 20:04:41 +0100 Message-Id: <1301425482-8722-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1301425482-8722-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1301425482-8722-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 2/3] block: Do not cache device size for removable media List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Juan Quintela , Ryan Harper , Amit Shah 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 f812c20..2bd353f 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 */ -- 1.7.4.1