linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: check: Fix error reporting on root inode
@ 2020-08-24 14:00 Nikolay Borisov
  2020-08-24 15:23 ` Josef Bacik
  2020-08-31 15:17 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Nikolay Borisov @ 2020-08-24 14:00 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

If btrfs check detects an error on the root inode of a subvolume it
prints:

    Opening filesystem to check...
    Checking filesystem on /dev/vdc
    UUID: 4ac7a216-bf97-4c5f-9899-0f203c20d8af
    [1/7] checking root items
    [2/7] checking extents
    [3/7] checking free space cache
    [4/7] checking fs roots
    root 5 root dir 256 error
    ERROR: errors found in fs roots
    found 196608 bytes used, error(s) found
    total csum bytes: 0
    total tree bytes: 131072
    total fs tree bytes: 32768
    total extent tree bytes: 16384
    btree space waste bytes: 124376
    file data blocks allocated: 65536
     referenced 65536

This is not very helpful since there is no specific information about
the exact error. This is due to the fact that check_root_dir doesn't
set inode_record::errors accordingly. This patch rectifies this and now
the output would look like:

	[1/7] checking root items
	[2/7] checking extents
	[3/7] checking free space cache
	[4/7] checking fs roots
	root 5 inode 256 errors 2000, link count wrong
	ERROR: errors found in fs roots
	found 196608 bytes used, error(s) found
	total csum bytes: 0
	total tree bytes: 131072
	total fs tree bytes: 32768
	total extent tree bytes: 16384
	btree space waste bytes: 124376
	file data blocks allocated: 65536
	 referenced 65536

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 check/main.c | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/check/main.c b/check/main.c
index f93bd7d4ca70..c622caa8e04f 100644
--- a/check/main.c
+++ b/check/main.c
@@ -1885,20 +1885,45 @@ static int check_root_dir(struct inode_record *rec)
 	struct inode_backref *backref;
 	int ret = -1;

-	if (!rec->found_inode_item || rec->errors)
+	if (rec->errors)
 		goto out;
-	if (rec->nlink != 1 || rec->found_link != 0)
+
+	if (!rec->found_inode_item) {
+		rec->errors |= I_ERR_NO_INODE_ITEM;
+		goto out;
+	}
+
+	if (rec->nlink != 1 || rec->found_link != 0) {
+		rec->errors |= I_ERR_LINK_COUNT_WRONG;
 		goto out;
-	if (list_empty(&rec->backrefs))
+	}
+
+	if (list_empty(&rec->backrefs)) {
+		rec->errors |= REF_ERR_NO_ROOT_BACKREF;
 		goto out;
+	}
+
 	backref = to_inode_backref(rec->backrefs.next);
-	if (!backref->found_inode_ref)
+	if (!backref->found_inode_ref) {
+		rec->errors |= REF_ERR_NO_INODE_REF;
 		goto out;
+	}
+
 	if (backref->index != 0 || backref->namelen != 2 ||
-	    memcmp(backref->name, "..", 2))
+	    memcmp(backref->name, "..", 2)) {
+		rec->errors |= I_ERR_ODD_DIR_ITEM;
+		goto out;
+	}
+
+	if (backref->found_dir_index) {
+		rec->errors |= REF_ERR_DUP_DIR_INDEX;
 		goto out;
-	if (backref->found_dir_index || backref->found_dir_item)
+	}
+
+	if (backref->found_dir_item) {
+		rec->errors |= REF_ERR_DUP_DIR_ITEM;
 		goto out;
+	}
 	ret = 0;
 out:
 	return ret;
@@ -2992,9 +3017,6 @@ static int check_inode_recs(struct btrfs_root *root,
 		}
 		ret = check_root_dir(rec);
 		if (ret) {
-			fprintf(stderr, "root %llu root dir %llu error\n",
-				(unsigned long long)root->root_key.objectid,
-				(unsigned long long)root_dirid);
 			print_inode_error(root, rec);
 			error++;
 		}
--
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: check: Fix error reporting on root inode
  2020-08-24 14:00 [PATCH] btrfs-progs: check: Fix error reporting on root inode Nikolay Borisov
@ 2020-08-24 15:23 ` Josef Bacik
  2020-08-31 15:17 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2020-08-24 15:23 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs

On 8/24/20 10:00 AM, Nikolay Borisov wrote:
> If btrfs check detects an error on the root inode of a subvolume it
> prints:
> 
>      Opening filesystem to check...
>      Checking filesystem on /dev/vdc
>      UUID: 4ac7a216-bf97-4c5f-9899-0f203c20d8af
>      [1/7] checking root items
>      [2/7] checking extents
>      [3/7] checking free space cache
>      [4/7] checking fs roots
>      root 5 root dir 256 error
>      ERROR: errors found in fs roots
>      found 196608 bytes used, error(s) found
>      total csum bytes: 0
>      total tree bytes: 131072
>      total fs tree bytes: 32768
>      total extent tree bytes: 16384
>      btree space waste bytes: 124376
>      file data blocks allocated: 65536
>       referenced 65536
> 
> This is not very helpful since there is no specific information about
> the exact error. This is due to the fact that check_root_dir doesn't
> set inode_record::errors accordingly. This patch rectifies this and now
> the output would look like:
> 
> 	[1/7] checking root items
> 	[2/7] checking extents
> 	[3/7] checking free space cache
> 	[4/7] checking fs roots
> 	root 5 inode 256 errors 2000, link count wrong
> 	ERROR: errors found in fs roots
> 	found 196608 bytes used, error(s) found
> 	total csum bytes: 0
> 	total tree bytes: 131072
> 	total fs tree bytes: 32768
> 	total extent tree bytes: 16384
> 	btree space waste bytes: 124376
> 	file data blocks allocated: 65536
> 	 referenced 65536
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: check: Fix error reporting on root inode
  2020-08-24 14:00 [PATCH] btrfs-progs: check: Fix error reporting on root inode Nikolay Borisov
  2020-08-24 15:23 ` Josef Bacik
@ 2020-08-31 15:17 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2020-08-31 15:17 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Mon, Aug 24, 2020 at 05:00:49PM +0300, Nikolay Borisov wrote:
> If btrfs check detects an error on the root inode of a subvolume it
> prints:
> 
>     Opening filesystem to check...
>     Checking filesystem on /dev/vdc
>     UUID: 4ac7a216-bf97-4c5f-9899-0f203c20d8af
>     [1/7] checking root items
>     [2/7] checking extents
>     [3/7] checking free space cache
>     [4/7] checking fs roots
>     root 5 root dir 256 error
>     ERROR: errors found in fs roots
>     found 196608 bytes used, error(s) found
>     total csum bytes: 0
>     total tree bytes: 131072
>     total fs tree bytes: 32768
>     total extent tree bytes: 16384
>     btree space waste bytes: 124376
>     file data blocks allocated: 65536
>      referenced 65536
> 
> This is not very helpful since there is no specific information about
> the exact error. This is due to the fact that check_root_dir doesn't
> set inode_record::errors accordingly. This patch rectifies this and now
> the output would look like:
> 
> 	[1/7] checking root items
> 	[2/7] checking extents
> 	[3/7] checking free space cache
> 	[4/7] checking fs roots
> 	root 5 inode 256 errors 2000, link count wrong
> 	ERROR: errors found in fs roots
> 	found 196608 bytes used, error(s) found
> 	total csum bytes: 0
> 	total tree bytes: 131072
> 	total fs tree bytes: 32768
> 	total extent tree bytes: 16384
> 	btree space waste bytes: 124376
> 	file data blocks allocated: 65536
> 	 referenced 65536
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Added to devel, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-31 15:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 14:00 [PATCH] btrfs-progs: check: Fix error reporting on root inode Nikolay Borisov
2020-08-24 15:23 ` Josef Bacik
2020-08-31 15:17 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).