Skip to contentSkip to conversation

btrfs: cleanup how we calculate lockend in lock_and_cleanup_extent_if_need()

PATCH In review Qu Wenruo 3 participants 3 messages Aug 13, 2020 – Aug 17, 2020 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: cleanup how we calculate lockend in lock_and_cleanup_extent_if_need()

We're just doing rounding up to sectorsize to calculate the lockend.

There is no need to do the unnecessary length calculation, just direct round_up() is enough.

---
 fs/btrfs/file.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/file.c +1 -3
index 2f96f083eb8c..c71ea9e5c529 100644
@@ -1475,9 +1475,7 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,
 	int ret = 0;
 
 	start_pos = round_down(pos, fs_info->sectorsize);
-	last_pos = start_pos
-		+ round_up(pos + write_bytes - start_pos,
-			   fs_info->sectorsize) - 1;
+	last_pos = round_up(pos + write_bytes, fs_info->sectorsize) - 1;
 
 	if (start_pos < inode->vfs_inode.i_size) {
 		struct btrfs_ordered_extent *ordered;
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Qu Wenruo

We're just doing rounding up to sectorsize to calculate the lockend.

There is no need to do the unnecessary length calculation, just direct round_up() is enough.

Quoted 20 lines
---
 fs/btrfs/file.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/file.c +1 -3
index 2f96f083eb8c..c71ea9e5c529 100644
@@ -1475,9 +1475,7 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,
 	int ret = 0;
 
 	start_pos = round_down(pos, fs_info->sectorsize);
-	last_pos = start_pos
-		+ round_up(pos + write_bytes - start_pos,
-			   fs_info->sectorsize) - 1;
+	last_pos = round_up(pos + write_bytes, fs_info->sectorsize) - 1;
 
 	if (start_pos < inode->vfs_inode.i_size) {
 		struct btrfs_ordered_extent *ordered;