diff mbox

btrfs-progs: Enhance tree block check by checking empty leaf or node

Message ID 1463647475-22102-1-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Qu Wenruo May 19, 2016, 8:44 a.m. UTC
For btrfs, it's possible to have empty leaf, but empty node is not
possible.

Add check for empty node for tree blocks.

Suggested-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 disk-io.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

David Sterba May 19, 2016, 12:24 p.m. UTC | #1
On Thu, May 19, 2016 at 04:44:35PM +0800, Qu Wenruo wrote:
> For btrfs, it's possible to have empty leaf, but empty node is not
> possible.
> 
> Add check for empty node for tree blocks.
> 
> Suggested-by: Josef Bacik <jbacik@fb.com>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/disk-io.c b/disk-io.c
index 86abdeb..b4f185f 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -67,6 +67,11 @@  static int check_tree_block(struct btrfs_fs_info *fs_info,
 						    nodesize))
 		return BTRFS_BAD_NRITEMS;
 
+	/* Only leaf can be empty */
+	if (btrfs_header_nritems(buf) == 0 &&
+	    btrfs_header_level(buf) != 0)
+		return BTRFS_BAD_NRITEMS;
+
 	fs_devices = fs_info->fs_devices;
 	while (fs_devices) {
 		if (fs_info->ignore_fsid_mismatch ||