From 0ce7c12e88cfa3e4cb0800e8172e5befea5c199a Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Mon, 31 Jul 2023 11:47:31 -0700 Subject: kernfs: attach uuid for every kernfs and report it in fsid The following two commits added the same thing for tmpfs: * commit 2b4db79618ad ("tmpfs: generate random sb->s_uuid") * commit 59cda49ecf6c ("shmem: allow reporting fanotify events with file handles on tmpfs") Having fsid allows using fanotify, which is especially handy for cgroups, where one might be interested in knowing when they are created or removed. Signed-off-by: Ivan Babrou Acked-by: Jan Kara Acked-by: Christian Brauner Link: https://lore.kernel.org/r/20230731184731.64568-1-ivan@cloudflare.com Signed-off-by: Greg Kroah-Hartman --- fs/kernfs/mount.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'fs/kernfs') diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index d49606accb07..c4bf26142eec 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "kernfs-internal.h" @@ -45,8 +47,15 @@ static int kernfs_sop_show_path(struct seq_file *sf, struct dentry *dentry) return 0; } +static int kernfs_statfs(struct dentry *dentry, struct kstatfs *buf) +{ + simple_statfs(dentry, buf); + buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b); + return 0; +} + const struct super_operations kernfs_sops = { - .statfs = simple_statfs, + .statfs = kernfs_statfs, .drop_inode = generic_delete_inode, .evict_inode = kernfs_evict_inode, @@ -351,6 +360,8 @@ int kernfs_get_tree(struct fs_context *fc) } sb->s_flags |= SB_ACTIVE; + uuid_gen(&sb->s_uuid); + down_write(&root->kernfs_supers_rwsem); list_add(&info->node, &info->root->supers); up_write(&root->kernfs_supers_rwsem); -- cgit From 0559f63057f927d298d68294d6ff77ce09b99255 Mon Sep 17 00:00:00 2001 From: Ian Kent Date: Sun, 6 Aug 2023 09:26:49 +0800 Subject: kernfs: fix missing kernfs_iattr_rwsem locking When the kernfs_iattr_rwsem was introduced a case was missed. The update of the kernfs directory node child count was also protected by the kernfs_rwsem and needs to be included in the change so that the child count (and so the inode n_link attribute) does not change while holding the rwsem for read. Fixes: 9caf69614225 ("kernfs: Introduce separate rwsem to protect inode attributes.") Cc: stable Signed-off-by: Ian Kent Reviewed-By: Imran Khan Acked-by: Miklos Szeredi Cc: Anders Roxell Cc: Arnd Bergmann Cc: Minchan Kim Cc: Eric Sandeen Link: https://lore.kernel.org/r/169128520941.68052.15749253469930138901.stgit@donald.themaw.net Signed-off-by: Greg Kroah-Hartman --- fs/kernfs/dir.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'fs/kernfs') diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 5a1a4af9d3d2..bf243015834e 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -383,9 +383,11 @@ static int kernfs_link_sibling(struct kernfs_node *kn) rb_insert_color(&kn->rb, &kn->parent->dir.children); /* successfully added, account subdir number */ + down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); if (kernfs_type(kn) == KERNFS_DIR) kn->parent->dir.subdirs++; kernfs_inc_rev(kn->parent); + up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); return 0; } @@ -408,9 +410,11 @@ static bool kernfs_unlink_sibling(struct kernfs_node *kn) if (RB_EMPTY_NODE(&kn->rb)) return false; + down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); if (kernfs_type(kn) == KERNFS_DIR) kn->parent->dir.subdirs--; kernfs_inc_rev(kn->parent); + up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); rb_erase(&kn->rb, &kn->parent->dir.children); RB_CLEAR_NODE(&kn->rb); -- cgit