Received: from [140.186.70.92] (port=44772 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2UXn-0000be-Hq for qemu-devel@nongnu.org; Wed, 23 Mar 2011 16:20:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2UX1-0006hd-HP for qemu-devel@nongnu.org; Wed, 23 Mar 2011 16:19:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23647) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2UX1-0006hI-7m for qemu-devel@nongnu.org; Wed, 23 Mar 2011 16:19:51 -0400 From: Juan Quintela In-Reply-To: <1300902055-25850-3-git-send-email-stefanha@linux.vnet.ibm.com> (Stefan Hajnoczi's message of "Wed, 23 Mar 2011 17:40:54 +0000") References: <1300902055-25850-1-git-send-email-stefanha@linux.vnet.ibm.com> <1300902055-25850-3-git-send-email-stefanha@linux.vnet.ibm.com> Date: Wed, 23 Mar 2011 21:18:08 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH 2/3] block: Do not cache device size for removable media Reply-To: quintela@redhat.com List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , Amit Shah , Anthony Liguori , Ryan Harper , qemu-devel@nongnu.org Stefan Hajnoczi wrote: > 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) { if (!bs->growable || !bs->removable|| !drv->bdrv_getlength) { changing just the test don't give exactly the same result? > - 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 */