Skip to contentSkip to conversation

Btrfs: fill_holes: Fix slot number passed to hole_mergeable() call.

PATCH In review Chandan Rajendra 2 participants 2 messages Jul 1, 2014 – Jul 2, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fill_holes: Fix slot number passed to hole_mergeable() call.

For a non-existent key, btrfs_search_slot() sets path->slots[0] to the slot where the key could have been present, which in this case would be the slot containing the extent item which would be the next neighbor of the file range being punched. The current code passes an incremented path->slots[0] and we skip to the wrong file extent item. This would mean that we would fail to merge the "yet to be created" hole with the next neighboring hole (if one exists). Fix this.

---
 fs/btrfs/file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/file.c +1 -2
index ad7c059..3cd7997 100644
@@ -2126,10 +2126,9 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
 		goto out;
 	}
 
-	if (hole_mergeable(inode, leaf, path->slots[0]+1, offset, end)) {
+	if (hole_mergeable(inode, leaf, path->slots[0], offset, end)) {
 		u64 num_bytes;
 
-		path->slots[0]++;
 		key.offset = offset;
 		btrfs_set_item_key_safe(root, path, &key);
 		fi = btrfs_item_ptr(leaf, path->slots[0],
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Chandan Rajendra

For a non-existent key, btrfs_search_slot() sets path->slots[0] to the slot where the key could have been present, which in this case would be the slot containing the extent item which would be the next neighbor of the file range being punched. The current code passes an incremented path->slots[0] and we skip to the wrong file extent item. This would mean that we would fail to merge the "yet to be created" hole with the next neighboring hole (if one exists). Fix this.

---

Nice catch, this looks good to me.

Quoted 19 lines
  fs/btrfs/file.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/file.c +1 -2
index ad7c059..3cd7997 100644
@@ -2126,10 +2126,9 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
  		goto out;
  	}
 
-	if (hole_mergeable(inode, leaf, path->slots[0]+1, offset, end)) {
+	if (hole_mergeable(inode, leaf, path->slots[0], offset, end)) {
  		u64 num_bytes;
 
-		path->slots[0]++;
  		key.offset = offset;
  		btrfs_set_item_key_safe(root, path, &key);
  		fi = btrfs_item_ptr(leaf, path->slots[0],