btrfs: don't warn if discard range is not aligned to sector
Subsystems (2)
David Sterba
maintainerPATCH 1/1 btrfs: don't warn if discard range is not aligned to sector
There's a warning in btrfs_issue_discard() when the range is not aligned to 512 bytes, originally added in 4d89d377bbb0 ("btrfs:btrfs_issue_discard ensure offset/length are aligned to sector boundaries"). We can't do sub-sector writes anyway so the adjustment is the only thing that we can do and the warning is unnecessary.
--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +2 -1
@@ -1260,7 +1260,8 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,u64 bytes_left, end;u64 aligned_start =ALIGN (start,1 <<SECTOR_SHIFT ); -if (WARN_ON (start != aligned_start)) { +/* Adjust the range to be aligned to 512B sectors if necessary. */ +if (start != aligned_start) { len -= aligned_start - start; len =round_down (len,1 <<SECTOR_SHIFT ); start = aligned_start;
Signature · 1 line
2.42.1
Quoted 18 lines · David Sterba
There's a warning in
btrfs_issue_discard()when the range is not aligned to 512 bytes, originally added in4d89d377bbb0("btrfs:btrfs_issue_discardensure offset/length are aligned to sector boundaries"). We can't do sub-sector writes anyway so the adjustment is the only thing that we can do and the warning is unnecessary.CC [email protected] # 4.19+Reported-by [email protected]Signed-off-by David Sterba <[email protected]>--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/extent-tree.c +0
-0
fs/btrfs/extent-tree.c static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len, · line 1267
Quoted 9 lines
fs/btrfs/extent-tree.c +2
-1@@ -1260,7 +1260,8 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,u64 bytes_left, end;u64 aligned_start =ALIGN (start,1 <<SECTOR_SHIFT ); -if (WARN_ON (start != aligned_start)) { +/* Adjust the range to be aligned to 512B sectors if necessary. */ +if (start != aligned_start) { len -= aligned_start - start; len =round_down (len,1 <<SECTOR_SHIFT ); start = aligned_start;
Maybe leave abtrfs_warn(fs_info, "adjusting discard range to 512b boundary"); in there?
Or is info a more appropriate level?
Quoted 33 lines · Johannes Thumshirn
Quoted 18 lines · David Sterba
There's a warning in
btrfs_issue_discard()when the range is not aligned to 512 bytes, originally added in4d89d377bbb0("btrfs:btrfs_issue_discardensure offset/length are aligned to sector boundaries"). We can't do sub-sector writes anyway so the adjustment is the only thing that we can do and the warning is unnecessary.CC [email protected] # 4.19+Reported-by [email protected]Signed-off-by David Sterba <[email protected]>--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/extent-tree.c +0
-0fs/btrfs/extent-tree.c static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len, · line 1267
Quoted 9 lines
fs/btrfs/extent-tree.c +2
-1@@ -1260,7 +1260,8 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,u64 bytes_left, end;u64 aligned_start =ALIGN (start,1 <<SECTOR_SHIFT ); -if (WARN_ON (start != aligned_start)) { +/* Adjust the range to be aligned to 512B sectors if necessary. */ +if (start != aligned_start) { len -= aligned_start - start; len =round_down (len,1 <<SECTOR_SHIFT ); start = aligned_start;Maybe leave a
btrfs_warn(fs_info, "adjusting discard range to 512b boundary"); in there?
Quoted 1 line
Or is info a more appropriate level?
I don't know if we should warn here at all, the warning is there since 2015 and only now we see it triggered, I guess everybody sane using the discard interface uses proper values. Warning level means that it needs user attention that something is wrong and take some action or examine the system.
The discard range could be verified at the beginning of the ioctl, but printing it here is a bit late. I've checked xfs and it silently rounds down the start and offset the same way, I find this sufficient thing to do.
Johannes Thumshirn
Reviewed-byQuoted 7 lines · David Sterba
I don't know if we should warn here at all, the warning is there since 2015 and only now we see it triggered, I guess everybody sane using the discard interface uses proper values. Warning level means that it needs user attention that something is wrong and take some action or examine the system.
Quoted 5 lines
The discard range could be verified at the beginning of the ioctl, but printing it here is a bit late. I've checked xfs and it silently rounds down the start and offset the same way, I find this sufficient thing to do.
Yeah thenm lets do it this way,
Quoted 18 lines · David Sterba
There's a warning in
btrfs_issue_discard()when the range is not aligned to 512 bytes, originally added in4d89d377bbb0("btrfs:btrfs_issue_discardensure offset/length are aligned to sector boundaries"). We can't do sub-sector writes anyway so the adjustment is the only thing that we can do and the warning is unnecessary.CC [email protected] # 4.19+Reported-by [email protected]Signed-off-by David Sterba <[email protected]>--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/extent-tree.c +0
-0
fs/btrfs/extent-tree.c static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len, · line 1267
Quoted 9 lines
fs/btrfs/extent-tree.c +2
-1@@ -1260,7 +1260,8 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,u64 bytes_left, end;u64 aligned_start =ALIGN (start,1 <<SECTOR_SHIFT ); -if (WARN_ON (start != aligned_start)) { +/* Adjust the range to be aligned to 512B sectors if necessary. */ +if (start != aligned_start) { len -= aligned_start - start; len =round_down (len,1 <<SECTOR_SHIFT ); start = aligned_start;
Can we do one step further in mkfs and device add, by rounding down the device size to btrfs sector boundary?
Add maybe output a warning message at mount time when adding one device?
Thanks,
Qu
Quoted 24 lines · Qu Wenruo
Quoted 21 lines · David Sterba
There's a warning in
btrfs_issue_discard()when the range is not aligned to 512 bytes, originally added in4d89d377bbb0("btrfs:btrfs_issue_discardensure offset/length are aligned to sector boundaries"). We can't do sub-sector writes anyway so the adjustment is the only thing that we can do and the warning is unnecessary.CC [email protected] # 4.19+Reported-by [email protected]Signed-off-by David Sterba <[email protected]>--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/extent-tree.c +0
-0@@ -1260,7 +1260,8 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,u64 bytes_left, end;u64 aligned_start =ALIGN (start,1 <<SECTOR_SHIFT );
Quoted 8 lines
fs/btrfs/extent-tree.c static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len, · line 1267
Quoted 6 lines
fs/btrfs/extent-tree.c +2
-1-if (WARN_ON (start != aligned_start)) { +/* Adjust the range to be aligned to 512B sectors if necessary. */ +if (start != aligned_start) { len -= aligned_start - start; len =round_down (len,1 <<SECTOR_SHIFT ); start = aligned_start;Can we do one step further in mkfs and device add, by rounding down the device size to btrfs sector boundary?
This is not device size but the range that gets passed to discard. The start and size get converted to the 512B units anyway when calling blkdev_issue_discard(), so nothing else needs to be done.
fs/btrfs/extent-tree.c static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len, · line 1264
Quoted 4 lines
fs/btrfs/extent-tree.c +2
-1-if (WARN_ON (start != aligned_start)) { +/* Adjust the range to be aligned to 512B sectors if necessary. */ +if (start != aligned_start) {
Thanks, Anand