All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org, Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH] btrfs: Fix off-by-one error btrfs_trim_free_extents
Date: Wed, 24 Apr 2019 11:46:55 +0300	[thread overview]
Message-ID: <20190424084655.31615-1-nborisov@suse.com> (raw)

btrfs_trim_free_extents always caps the range it's going to trim based
on the size of the device. This happens if find_first_clear_extent_bit
detects that untrimmed range is past the last allocated range. Since it
doesn't have knowledge of the size of the device it just returns (u64)-1
for end. Then btrfs_trim_free_extents caps this to device->total_bytes.
However, btrfs_trim_free_extent calculates 'len' based off of the
actual usable end byte - in this case total_bytes - 1.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Fixes: 4d877687cbbc ("btrfs: Switch btrfs_trim_free_extents to find_first_clear_extent_bit")
---

David you might want to squash that in the 'Fixes' commit. With this I see 
generic/500 passing and also full xfstest didn't uncover any new regressions. 
 fs/btrfs/extent-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d9e2e35700fd..5a4b81259413 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -11175,7 +11175,7 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
 		 * end of the device it will set end to -1, in this case it's up
 		 * to the caller to trim the value to the size of the device.
 		 */
-		end = min(end, device->total_bytes);
+		end = min(end, device->total_bytes - 1);
 		len = end - start + 1;
 
 		/* We didn't find any extents */
-- 
2.17.1


             reply	other threads:[~2019-04-24  8:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24  8:46 Nikolay Borisov [this message]
2019-04-24 13:38 ` [PATCH] btrfs: Fix off-by-one error btrfs_trim_free_extents David Sterba

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=20190424084655.31615-1-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /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.