From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH] btrfs-progs: check: Support precise nlink tracking
Date: Thu, 27 Aug 2020 18:04:26 +0300 [thread overview]
Message-ID: <20200827150426.23842-4-nborisov@suse.com> (raw)
In-Reply-To: <20200827150426.23842-1-nborisov@suse.com>
This commit makes progs compatible with a kernel that has implemented
subdirectory tracking in nlink. To achieve this the logic is modified
such that found_link is incremented for the parent dir for every
DIR_ITEM found which points to a subdirectory. Another change is to
always set found_link to 1 when parsing INODE_ITEM which corresponds to
a subvolume/snapshot root. This is to account for the fact that such
inodes are the root in their respective fs trees so they won't have
their found_link count bumped when parsing their DIR_ITEM in the parent
directory.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
check/main.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/check/main.c b/check/main.c
index c622caa8e04f..eec18132f8e5 100644
--- a/check/main.c
+++ b/check/main.c
@@ -908,6 +908,8 @@ static int process_inode_item(struct extent_buffer *eb,
if (S_ISLNK(rec->imode) &&
flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND))
rec->errors |= I_ERR_ODD_INODE_FLAGS;
+ if (S_ISDIR(rec->imode) && rec->ino == BTRFS_FIRST_FREE_OBJECTID)
+ rec->found_link = 1;
/*
* We don't have accurate root info to determine the correct
* inode generation uplimit, use super_generation + 1 anyway
@@ -1421,6 +1423,16 @@ static int process_dir_item(struct extent_buffer *eb,
goto next;
}
+ if ((location.type == BTRFS_INODE_ITEM_KEY ||
+ location.type == BTRFS_ROOT_ITEM_KEY) && filetype == BTRFS_FT_DIR &&
+ key->type == BTRFS_DIR_ITEM_KEY) {
+ struct inode_record *dir_rec = get_inode_rec(inode_cache,
+ key->objectid, 1);
+ BUG_ON(IS_ERR(rec));
+ dir_rec->found_link++;
+ maybe_free_inode_rec(inode_cache, dir_rec);
+ }
+
if (location.type == BTRFS_INODE_ITEM_KEY) {
add_inode_backref(inode_cache, location.objectid,
key->objectid, key->offset, namebuf,
@@ -1893,7 +1905,7 @@ static int check_root_dir(struct inode_record *rec)
goto out;
}
- if (rec->nlink != 1 || rec->found_link != 0) {
+ if (rec->nlink != rec->found_link) {
rec->errors |= I_ERR_LINK_COUNT_WRONG;
goto out;
}
--
2.17.1
prev parent reply other threads:[~2020-08-27 15:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 15:04 [PATCH 0/1 NOT FOR MERGE] Basic subdir tracking in nlink Nikolay Borisov
2020-08-27 15:04 ` [PATCH] btrfs/218: Test for i_nlink tracking Nikolay Borisov
2020-08-27 15:04 ` [PATCH 1/1] btrfs: Track subdirectories in nlink Nikolay Borisov
2020-08-31 13:27 ` David Sterba
2020-08-27 15:04 ` Nikolay Borisov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200827150426.23842-4-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox