From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:60759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQCxL-0001QF-57 for qemu-devel@nongnu.org; Tue, 15 Nov 2011 01:57:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQCxJ-0002yx-Uc for qemu-devel@nongnu.org; Tue, 15 Nov 2011 01:57:19 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:36854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQCxJ-0002ym-5q for qemu-devel@nongnu.org; Tue, 15 Nov 2011 01:57:17 -0500 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Nov 2011 06:45:16 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAF6us214984874 for ; Tue, 15 Nov 2011 17:57:01 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAF6useX015772 for ; Tue, 15 Nov 2011 17:56:54 +1100 Message-ID: <4EC20D33.8090408@linux.vnet.ibm.com> Date: Tue, 15 Nov 2011 14:56:51 +0800 From: Zhi Hui Li MIME-Version: 1.0 References: <4EB78CE9.4030305@linux.vnet.ibm.com> <4EB89ED1.90307@linux.vnet.ibm.com> <4EC0AB7D.2020807@linux.vnet.ibm.com> <20111114100022.GA25870@stefanha-thinkpad.localdomain> In-Reply-To: <20111114100022.GA25870@stefanha-thinkpad.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] I have some questions in block , can anyone help me, thank you! List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: QEMU-devel On 2011年11月14日 18:00, Stefan Hajnoczi wrote: > On Mon, Nov 14, 2011 at 01:47:41PM +0800, Zhi Hui Li wrote: >> 1) In qcow2.c, in function: qcow2_co_readv >> In qcow2.h, in struct BDRVQcowState >> I want to know the relations between sector_num in function >> qcow2_co_readv and cluster_sectors in struct BDRVQcowState ? > > sector_num is the starting offset of the I/O request. For example, > sector_num=10 means that the read begins at 10 * 512 = 5120 bytes. > > cluster_sectors is the number of sectors in a qcow2 cluster. (The qcow2 > format manages space in "clusters" instead of sectors. They are > typically many sectors large, e.g. 128.) > >> 2) In qcow2.c, in function; qcow2_co_writev >> at line 547: >> >> index_in_cluster = sector_num& (s->cluster_sectors - 1); >> How to understand it ? > > cluster_sectors is a power of 2, e.g. 1024, 2048, 4096, and so on. So > this expression is the same as: > > index_in_cluster = sector_num % cluster_sectors > > It calculates the offset from the start of the cluster. For example: > > sector_num = 130 > cluster_sectors = 128 > > cluster = sector_num / cluster_sectors = 1 > index_in_cluster = sector_num % cluster_sectors = 2 > > We can get back to the original sector_num value like this: > > sector_num = cluster * cluster_sectors + index_in_cluster > = 1 * 128 + 2 > = 130 > > So this is about managing space in "clusters". It's similar to how > memory is managed in pages instead of bytes by the memory management > unit. > >> 3) In qcow2.c, in the function : qcow2_co_readv and qcow2_co_writev >> I want to know the least unit that it was read by the function. >> for example: >> BDRVQcowState s; >> Is s->cluster_size or 512 ? > > The block layer minimum I/O size is BDRV_SECTOR_SIZE. For convenience > there is the bdrv_pread()/bdrv_pwrite() interface which allows > byte-granularity access but uses bounce buffers underneath. > > s->cluster_size is the number of bytes per cluster. A cluster is > typically 64 KB but the value can be set in the image file. Qcow2 > internally manages space in cluster but the I/O granularity is > BDRV_SECTOR_SIZE (512). > > Stefan > > Thank you very much!