linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: wqu@suse.com, fdmanana@suse.com, dsterba@suse.com,
	linux-btrfs@vger.kernel.org
Subject: [PATCH stable-5.4 3/6] btrfs: volumes: Use more straightforward way to calculate map length
Date: Thu,  8 Oct 2020 18:59:51 +0800	[thread overview]
Message-ID: <b15e98a7c6129f8b5f0a7748061e93865bb944e1.1599750901.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1599750901.git.anand.jain@oracle.com>

From: Qu Wenruo <wqu@suse.com>

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>
---
 fs/btrfs/volumes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 196ddbcd2936..1dba45d43485 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5712,7 +5712,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;
 	/*
-- 
2.25.1


  parent reply	other threads:[~2020-10-08 11:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 10:59 [PATCH stable-5.4 0/6] backport fixes for xfstests btrfs/199,200,203,204 Anand Jain
2020-10-08 10:59 ` [PATCH stable-5.4 1/6] Btrfs: send, allow clone operations within the same file Anand Jain
2020-10-08 10:59 ` [PATCH stable-5.4 2/6] Btrfs: send, fix emission of invalid " Anand Jain
2020-10-08 10:59 ` Anand Jain [this message]
2020-10-08 10:59 ` [PATCH stable-5.4 4/6] btrfs: Ensure we trim ranges across block group boundary Anand Jain
2020-10-08 10:59 ` [PATCH stable-5.4 5/6] btrfs: fix RWF_NOWAIT write not failling when we need to cow Anand Jain
2020-10-08 10:59 ` [PATCH stable-5.4 6/6] btrfs: allow btrfs_truncate_block() to fallback to nocow for data space reservation Anand Jain
2020-10-09 14:06   ` Greg KH

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=b15e98a7c6129f8b5f0a7748061e93865bb944e1.1599750901.git.anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wqu@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).