All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-block@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
	mreitz@redhat.com, ronniesahlberg@gmail.com
Subject: Re: [Qemu-devel] [PATCH V4] block/iscsi: allow caching of the allocation map
Date: Mon, 18 Jul 2016 09:55:45 +0200	[thread overview]
Message-ID: <578C8B81.9020509@kamp.de> (raw)
In-Reply-To: <08e4d9ef-8d72-e4fd-5494-7a9301bf6438@redhat.com>

Am 16.07.2016 um 15:38 schrieb Paolo Bonzini:
>
> On 30/06/2016 13:07, Peter Lieven wrote:
>> +static void
>> +iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,
>> +                      int nb_sectors, bool allocated, bool valid)
>>   {
>>       int64_t cluster_num, nb_clusters;
>> -    if (iscsilun->allocationmap == NULL) {
>> +
>> +    if (iscsilun->allocmap == NULL) {
>>           return;
>>       }
>>       cluster_num = DIV_ROUND_UP(sector_num, iscsilun->cluster_sectors);
>>       nb_clusters = (sector_num + nb_sectors) / iscsilun->cluster_sectors
>>                     - cluster_num;
>> -    if (nb_clusters > 0) {
>> -        bitmap_clear(iscsilun->allocationmap, cluster_num, nb_clusters);
>> +    if (allocated) {
>> +        bitmap_set(iscsilun->allocmap,
>> +                   sector_num / iscsilun->cluster_sectors,
>> +                   DIV_ROUND_UP(nb_sectors, iscsilun->cluster_sectors));
>> +    } else if (nb_clusters > 0) {
>> +        bitmap_clear(iscsilun->allocmap, cluster_num, nb_clusters);
> I'm sorry for the delay in review, but this is still wrong.
>
> Suppose cluster_sectors is 2, sector_num = 1, nb_sectors = 6:
>
>     0--.--2--.--4--.--6--.--8
>        |_________________|
>
> Here in the "mark unallocated" case you want to set 2..6, i.e.
> cluster_num=2, nb_clusters=2.  This is right.
>
>     0--.--2--.--4--.--6--.--8
>        xxx|___________|xxx     (x = shrunk)

cluster_num = 1 and nb_clusters = 2

>
> In the "mark allocated" case, instead, you want to set 0..8, i.e.
> cluster_num=0, nb_clusters=4.
>
>     0--.--2--.--4--.--6--.--8
>     <--|_________________|-->  (<--> = expanded)
>
>    Instead you are setting nb_clusters=3, so that 6..8 is not marked
> allocated and reading 6..7 will return zeroes:
>
>     0--.--2--.--4--.--6--.--8
>     <--|______________|!!!     (! = wrong)
>
>   Instead you need to use
>
>     DIV_ROUND_UP(sector_num + nb_sectors, ...)
>         - sector_num / iscsilun->cluster_sectors
>
> which does the rounding correctly.

Right, but this has been wrong even in the currently active version.

So I would propose to send 2 patches.

1) fix the rounding in the old version cc'ing qemu-stable
2) rebase the new patch on top of that.

Thanks for catching this,
Peter

  reply	other threads:[~2016-07-18  7:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-30 11:07 [Qemu-devel] [PATCH V4] block/iscsi: allow caching of the allocation map Peter Lieven
2016-07-16 13:38 ` Paolo Bonzini
2016-07-18  7:55   ` Peter Lieven [this message]
2016-07-18  8:25     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=578C8B81.9020509@kamp.de \
    --to=pl@kamp.de \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.