Skip to contentSkip to conversation

btrfs-progs: check/lowmem: Skip nbytes check for orphan inodes

PATCH In review Qu Wenruo 3 participants 5 messages Sep 2, 2019 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/2 btrfs-progs: check/lowmem: Skip nbytes check for orphan inodes

For orphan inodes, kernel won't update its nbytes and size since it's a waste of time.

So lowmem check can report false alert on some orphan inodes.

Fix it by checking if the inode is an orphan before complaining/repairing its nbytes.

---
 check/mode-lowmem.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
check/mode-lowmem.c +9 -5
index da6b6fd86ae3..5f7f101daab1 100644
@@ -2519,6 +2519,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)
 		return err;
 	}
 
+	is_orphan = has_orphan_item(root, inode_id);
 	ii = btrfs_item_ptr(node, slot, struct btrfs_inode_item);
 	isize = btrfs_inode_size(node, ii);
 	nbytes = btrfs_inode_nbytes(node, ii);
@@ -2672,19 +2673,22 @@ out:
 		"root %llu INODE[%llu] nlink(%llu) not equal to inode_refs(%llu)",
 				      root->objectid, inode_id, nlink, refs);
 			}
-		} else if (!nlink) {
-			is_orphan = has_orphan_item(root, inode_id);
-			if (!is_orphan && repair)
+		} else if (!nlink && !is_orphan) {
+			if (repair)
 				ret = repair_inode_orphan_item_lowmem(root,
 							      path, inode_id);
-			if (!is_orphan && (!repair || ret)) {
+			if (!repair || ret) {
 				err |= ORPHAN_ITEM;
 				error("root %llu INODE[%llu] is orphan item",
 				      root->objectid, inode_id);
 			}
 		}
 
-		if (nbytes != extent_size) {
+		/*
+		 * For orhpan inode, updating nbytes/size is just a waste of
+		 * time, so skip such repair and don't report them as error.
+		 */
+		if (nbytes != extent_size && !is_orphan) {
 			if (repair) {
 				ret = repair_inode_nbytes_lowmem(root, path,
 							 inode_id, extent_size);
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 2/2 btrfs-progs: fsck-tests: Add test image for valid half-dropped orphan inode

Btrfs check used to report false alerts on half dropped orphan inodes. Add test cases to prevent such problem from happening again.

---
 .../042-half-dropped-inode/default.raw.xz     | Bin 0 -> 58940 bytes
 .../fsck-tests/042-half-dropped-inode/test.sh |  34 ++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 tests/fsck-tests/042-half-dropped-inode/default.raw.xz
 create mode 100755 tests/fsck-tests/042-half-dropped-inode/test.sh
tests/fsck-tests/042-half-dropped-inode/default.raw.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6170fb35f49870685865bce6daa3becc04bc3501
GIT binary patch
tests/fsck-tests/042-half-dropped-inode/test.sh new file +34 -0
new file mode 100755
index 000000000000..1195fa19dd1a
@@ -0,0 +1,34 @@
+#!/bin/bash
+# To check if btrfs check can handle half dropped inodes.
+# Such inodes are orphan inodes going through file items evicting.
+# During that evicting, btrfs won't bother updating the nbytes of the orphan
+# inode as they will soon be removed completely.
+#
+# Btrfs check should be able to recognize such inodes without giving false
+# alerts
+#
+# The way to reproduce the image:
+# - Create a lot of regular file extents for one inode
+#   Using direct IO with small block size is the easiy method
+# - Modify kernel to commit transaction more aggresively
+#   Two locations are needed:
+#   * btrfs_unlink():
+#     To make the ORPHAN item reach disk asap
+#   * btrfs_evict_inode():
+#     Make the btrfs_end_transaction() call after btrfs_trncate_inode_items()
+#     to commit transaction, so we can catch every file item deletion
+# - Setup dm-log-writes
+#   To catch every transaction commit
+# - Delete the inode
+# - Sync the fs
+# - Replay the log
+
+source "$TEST_TOP/common"
+
+check_prereq btrfs
+
+check_image() {
+	run_check "$TOP/btrfs" check "$1"
+}
+
+check_all_images
Signature · 1 line
2.23.0
#2 lore raw
In reply to Qu Wenruo
Quoted 9 lines · Qu Wenruo

For orphan inodes, kernel won't update its nbytes and size since it's a waste of time.

So lowmem check can report false alert on some orphan inodes.

Fix it by checking if the inode is an orphan before complaining/repairing its nbytes.

Is this the same fix as :
https://patchwork.kernel.org/patch/11086471/ from josef, but for lowmem mode?

Quoted 45 lines
---
 check/mode-lowmem.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
check/mode-lowmem.c +9 -5
index da6b6fd86ae3..5f7f101daab1 100644
@@ -2519,6 +2519,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)
 		return err;
 	}
 
+	is_orphan = has_orphan_item(root, inode_id);
 	ii = btrfs_item_ptr(node, slot, struct btrfs_inode_item);
 	isize = btrfs_inode_size(node, ii);
 	nbytes = btrfs_inode_nbytes(node, ii);
@@ -2672,19 +2673,22 @@ out:
 		"root %llu INODE[%llu] nlink(%llu) not equal to inode_refs(%llu)",
 				      root->objectid, inode_id, nlink, refs);
 			}
-		} else if (!nlink) {
-			is_orphan = has_orphan_item(root, inode_id);
-			if (!is_orphan && repair)
+		} else if (!nlink && !is_orphan) {
+			if (repair)
 				ret = repair_inode_orphan_item_lowmem(root,
 							      path, inode_id);
-			if (!is_orphan && (!repair || ret)) {
+			if (!repair || ret) {
 				err |= ORPHAN_ITEM;
 				error("root %llu INODE[%llu] is orphan item",
 				      root->objectid, inode_id);
 			}
 		}
 
-		if (nbytes != extent_size) {
+		/*
+		 * For orhpan inode, updating nbytes/size is just a waste of
+		 * time, so skip such repair and don't report them as error.
+		 */
+		if (nbytes != extent_size && !is_orphan) {
 			if (repair) {
 				ret = repair_inode_nbytes_lowmem(root, path,
 							 inode_id, extent_size);
author
#3 lore raw
Quoted 8 lines · Nikolay Borisov
Quoted 5 lines · Qu Wenruo

For orphan inodes, kernel won't update its nbytes and size since it's a waste of time.

So lowmem check can report false alert on some orphan inodes.

Quoted 8 lines
Quoted 4 lines

Fix it by checking if the inode is an orphan before complaining/repairing its nbytes.

Is this the same fix as :
https://patchwork.kernel.org/patch/11086471/ from josef, but for lowmem mode?

Yep.

Thanks,
Qu

Quoted 46 lines
Quoted 46 lines
---
 check/mode-lowmem.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
check/mode-lowmem.c +9 -5
index da6b6fd86ae3..5f7f101daab1 100644
@@ -2519,6 +2519,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)
 		return err;
 	}
 
+	is_orphan = has_orphan_item(root, inode_id);
 	ii = btrfs_item_ptr(node, slot, struct btrfs_inode_item);
 	isize = btrfs_inode_size(node, ii);
 	nbytes = btrfs_inode_nbytes(node, ii);
@@ -2672,19 +2673,22 @@ out:
 		"root %llu INODE[%llu] nlink(%llu) not equal to inode_refs(%llu)",
 				      root->objectid, inode_id, nlink, refs);
 			}
-		} else if (!nlink) {
-			is_orphan = has_orphan_item(root, inode_id);
-			if (!is_orphan && repair)
+		} else if (!nlink && !is_orphan) {
+			if (repair)
 				ret = repair_inode_orphan_item_lowmem(root,
 							      path, inode_id);
-			if (!is_orphan && (!repair || ret)) {
+			if (!repair || ret) {
 				err |= ORPHAN_ITEM;
 				error("root %llu INODE[%llu] is orphan item",
 				      root->objectid, inode_id);
 			}
 		}
 
-		if (nbytes != extent_size) {
+		/*
+		 * For orhpan inode, updating nbytes/size is just a waste of
+		 * time, so skip such repair and don't report them as error.
+		 */
+		if (nbytes != extent_size && !is_orphan) {
 			if (repair) {
 				ret = repair_inode_nbytes_lowmem(root, path,
 							 inode_id, extent_size);
#4 lore raw
In reply to Qu Wenruo
Quoted 9 lines · Qu Wenruo

For orphan inodes, kernel won't update its nbytes and size since it's a waste of time.

So lowmem check can report false alert on some orphan inodes.

Fix it by checking if the inode is an orphan before complaining/repairing its nbytes.

Great, thanks!