qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCHv3 08/20] block: honour BlockLimits in bdrv_co_di


From: Peter Lieven
Subject: Re: [Qemu-devel] [PATCHv3 08/20] block: honour BlockLimits in bdrv_co_discard
Date: Mon, 7 Oct 2013 10:36:14 +0200

Am 07.10.2013 um 10:29 schrieb Stefan Hajnoczi <address@hidden>:

> On Tue, Sep 24, 2013 at 03:35:02PM +0200, Peter Lieven wrote:
>> @@ -4245,7 +4250,37 @@ int coroutine_fn bdrv_co_discard(BlockDriverState 
>> *bs, int64_t sector_num,
>>     }
>> 
>>     if (bs->drv->bdrv_co_discard) {
>> -        return bs->drv->bdrv_co_discard(bs, sector_num, nb_sectors);
>> +        int max_discard = bs->bl.max_discard ?
>> +                          bs->bl.max_discard : MAX_DISCARD_DEFAULT;
>> +
>> +        while (nb_sectors > 0) {
>> +            int ret;
>> +            int num = nb_sectors;
>> +
>> +            /* align request */
>> +            if (bs->bl.discard_alignment &&
>> +                num >= bs->bl.discard_alignment &&
>> +                sector_num % bs->bl.discard_alignment) {
>> +                if (num > bs->bl.discard_alignment) {
>> +                    num = bs->bl.discard_alignment;
>> +                }
>> +                num -= sector_num % bs->bl.discard_alignment;
>> +            }
> 
> Is it always possible to discard at arbitrary sector offsets?

It should be. This just makes sure that the unaligned part of a request gets 
executed first (eventually resulting in an -ENOTSUP) and
consecutive calls are aligned.

For example. The alignment is 1MB (2048 sectors) and max_discard its 2048 
sectors as well.. Lets say you want to discard 4096 sectors starting at offset 
1024.

Then there will be 3 calls
1) discard at 1024, len 1024
2) discard at 2048, len 2048
3) discard at 4096, len 1024.

Peter


reply via email to

[Prev in Thread] Current Thread [Next in Thread]