[sheepdog] [Qemu-devel] [PATCH v2 2/2] sheepdog: implement .bdrv_co_is_allocated()

Stefan Hajnoczi stefanha at gmail.com
Mon Apr 22 22:46:00 CEST 2013


On Mon, Apr 22, 2013 at 5:18 PM, Liu Yuan <namei.unix at gmail.com> wrote:
> On 04/22/2013 11:03 PM, Stefan Hajnoczi wrote:
>> Imagine sector_num = 0 and nb_sectors = SD_DATA_OBJ_SIZE / BDRV_SECTOR_SIZE.
>>
>> start = 0
>> end = 1
>>
>> You don't want object 1, only object 0.
>
> Hmm, math, ouch. So nb_sectors include sector_num? What I mean is
>
> If [start, end] mean a range of sectors,so
>
> 1. nb_sectors = end - start + 1 (I assume this one)
> 2. nb_sectors = end - start (you meant this one?)
>
> which one is correct for .co_is_allocated?

The first sector is included in nb_sectors.  Mathematically the range
is defined as [sector_num, sector_num + nb_sectors).  Notice the
half-open interval, sector_num + nb_sectors is excluded.  The last
included sector is sector_num + nb_sectors - 1.

You can look at qcow2's implementation, especially
count_contiguous_clusters() to double-check.

Stefan



More information about the sheepdog mailing list