]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: volumes: Use more straightforward way to calculate map length
authorQu Wenruo <wqu@suse.com>
Wed, 23 Oct 2019 13:57:26 +0000 (21:57 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Oct 2020 08:32:59 +0000 (10:32 +0200)
commit 2d974619a77f106f3d1341686dea95c0eaad601f upstream.

The old code goes:

  offset = logical - em->start;
length = min_t(u64, em->len - offset, length);

Where @length calculation is dependent on offset, it can take reader
several more seconds to find it's just the same code as:

  offset = logical - em->start;
length = min_t(u64, em->start + em->len - logical, length);

Use above code to make the length calculate independent from other
variable, thus slightly increase the readability.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/volumes.c

index 4ecd6663dfb515892d465c0ad52a43a17188d0a6..0fff144119371180ecf318b2a5c20cca538e0fb7 100644 (file)
@@ -5714,7 +5714,7 @@ static int __btrfs_map_block_for_discard(struct btrfs_fs_info *fs_info,
        }
 
        offset = logical - em->start;
-       length = min_t(u64, em->len - offset, length);
+       length = min_t(u64, em->start + em->len - logical, length);
 
        stripe_len = map->stripe_len;
        /*