From a61b8d9961b7fe86cef2eb2383200aff41579804 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 8 Mar 2023 10:13:07 -0800 Subject: [PATCH] Fix renaming into root directory The VFS performs a lot of checks on renames before calling the fs method. We acquire locks and refresh inodes in the rename method so we have to duplciate a lot of the vfs checks. One of the checks involves loops with ancestors and subdirectories. We missed the case where the root directory is the destination and doesn't have any parent directories. The backref walker it calls returns -ENOENT instead of 0 with an empty set of parents and that error bubbled up to rename. The fix is to notice when we're asking for ancestors of the one directory that can't have ancestors and short circuit the test. Signed-off-by: Zach Brown --- kmod/src/dir.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kmod/src/dir.c b/kmod/src/dir.c index 21d29b6b..242a6f5c 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -1443,6 +1443,11 @@ static int item_d_ancestor(struct super_block *sb, u64 p1, u64 p2, u64 *p_ret) *p_ret = 0; + if (p2 == SCOUTFS_ROOT_INO) { + ret = 0; + goto out; + } + ret = scoutfs_dir_get_backref_path(sb, p2, 0, 0, &list); if (ret) goto out;