]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: btrfs_issue_discard ensure offset/length are aligned to sector boundaries
authorJeff Mahoney <jeffm@suse.com>
Mon, 15 Jun 2015 13:41:15 +0000 (09:41 -0400)
committerChris Mason <clm@fb.com>
Wed, 29 Jul 2015 15:15:24 +0000 (08:15 -0700)
commite4d3342fc4bb0a8f73e91041d63dfaac052f484a
tree25f9ec35458694e08e6f852bd6f05c22faf00891
parentfdbce30a4a8c6d8f015384e9da1c2610f1338b46
btrfs: btrfs_issue_discard ensure offset/length are aligned to sector boundaries

It's possible, though unexpected, to pass unaligned offsets and lengths
to btrfs_issue_discard.  We then shift the offset/length values to sector
units.  If an unaligned offset has been passed, it will result in the
entire sector being discarded, possibly losing data.  An unaligned
length is safe but we'll end up returning an inaccurate number of
discarded bytes.

This patch aligns the offset to the 512B boundary, adjusts the length,
and warns, since we shouldn't be discarding on an offset that isn't
aligned with our sector size.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Tested-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/extent-tree.c