Skip to contentSkip to conversation

Btrfs: check file extent type before anything else

PATCH In review Josef Bacik 2 participants 3 messages Oct 31, 2013 – Nov 1, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: check file extent type before anything else

I hit this problem with my no holes patch and it made me realize what the problem was for bz 60834. If the first item in the leaf is an inline extent and we try to read anything starting from disk_bytenr onward we will read off the end of the leaf. So we need to check to see what it's type is, and if it's not REG we can just break out. This should fix this problem. Thanks,

---
 fs/btrfs/backref.c |  1 +
 fs/btrfs/send.c    | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/backref.c +1 -0
index 3775947..b763f10 100644
@@ -1051,6 +1051,7 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
 
 	if (ret < 0 && ret != -ENOENT) {
 		free_leaf_list(*leafs);
+		ulist_free(*leafs);
 		return ret;
 	}
 
fs/btrfs/send.c +5 -5
index 8af536f..629cb9e 100644
@@ -3943,16 +3943,16 @@ static int is_extent_unchanged(struct send_ctx *sctx,
 	while (key.offset < ekey->offset + left_len) {
 		ei = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
 		right_type = btrfs_file_extent_type(eb, ei);
-		right_disknr = btrfs_file_extent_disk_bytenr(eb, ei);
-		right_len = btrfs_file_extent_num_bytes(eb, ei);
-		right_offset = btrfs_file_extent_offset(eb, ei);
-		right_gen = btrfs_file_extent_generation(eb, ei);
-
 		if (right_type != BTRFS_FILE_EXTENT_REG) {
 			ret = 0;
 			goto out;
 		}
 
+		right_disknr = btrfs_file_extent_disk_bytenr(eb, ei);
+		right_len = btrfs_file_extent_num_bytes(eb, ei);
+		right_offset = btrfs_file_extent_offset(eb, ei);
+		right_gen = btrfs_file_extent_generation(eb, ei);
+
 		/*
 		 * Are we at extent 8? If yes, we know the extent is changed.
 		 * This may only happen on the first iteration.
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 17 lines · Josef Bacik

I hit this problem with my no holes patch and it made me realize what the problem was for bz 60834. If the first item in the leaf is an inline extent and we try to read anything starting from disk_bytenr onward we will read off the end of the leaf. So we need to check to see what it's type is, and if it's not REG we can just break out. This should fix this problem. Thanks,

---
 fs/btrfs/backref.c |  1 +
 fs/btrfs/send.c    | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/backref.c +0 -0
index 3775947..b763f10 100644

fs/btrfs/backref.c static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans, · line 1054

Quoted 4 lines
fs/btrfs/backref.c +1 -0
@@ -1051,6 +1051,7 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
 
 	if (ret < 0 && ret != -ENOENT) {
 		free_leaf_list(*leafs);
+		ulist_free(*leafs);

An en passant fix for which problem?

Quoted 30 lines
fs/btrfs/backref.c +0 -0
 		return ret;
 	}
 
fs/btrfs/send.c +5 -5
index 8af536f..629cb9e 100644
@@ -3943,16 +3943,16 @@ static int is_extent_unchanged(struct send_ctx *sctx,
 	while (key.offset < ekey->offset + left_len) {
 		ei = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
 		right_type = btrfs_file_extent_type(eb, ei);
-		right_disknr = btrfs_file_extent_disk_bytenr(eb, ei);
-		right_len = btrfs_file_extent_num_bytes(eb, ei);
-		right_offset = btrfs_file_extent_offset(eb, ei);
-		right_gen = btrfs_file_extent_generation(eb, ei);
-
 		if (right_type != BTRFS_FILE_EXTENT_REG) {
 			ret = 0;
 			goto out;
 		}
 
+		right_disknr = btrfs_file_extent_disk_bytenr(eb, ei);
+		right_len = btrfs_file_extent_num_bytes(eb, ei);
+		right_offset = btrfs_file_extent_offset(eb, ei);
+		right_gen = btrfs_file_extent_generation(eb, ei);
+
 		/*
 		 * Are we at extent 8? If yes, we know the extent is changed.
 		 * This may only happen on the first iteration.
#2 lore raw
Quoted 19 lines · Stefan Behrens
Quoted 18 lines · Josef Bacik

I hit this problem with my no holes patch and it made me realize what the problem was for bz 60834. If the first item in the leaf is an inline extent and we try to read anything starting from disk_bytenr onward we will read off the end of the leaf. So we need to check to see what it's type is, and if it's not REG we can just break out. This should fix this problem. Thanks,

---
 fs/btrfs/backref.c |  1 +
 fs/btrfs/send.c    | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/backref.c +0 -0
index 3775947..b763f10 100644
@@ -1051,6 +1051,7 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
 
Quoted 6 lines

fs/btrfs/backref.c static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans, · line 1054

Quoted 3 lines
fs/btrfs/backref.c +1 -0
 	if (ret < 0 && ret != -ENOENT) {
 		free_leaf_list(*leafs);
+		ulist_free(*leafs);

An en passant fix for which problem?

Oops, sorry about that, not a problem just me doing other things, I'll drop that bit. Thanks,

Josef