Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kernfs: move struct kernfs_root out of the public view.

There is no need to have struct kernfs_root be part of kernfs.h for
the whole kernel to see and poke around it. Move it internal to kernfs
code and provide a helper function, kernfs_root_to_node(), to handle the
one field that kernfs users were directly accessing from the structure.

Cc: Imran Khan <imran.f.khan@oracle.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20220222070713.3517679-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+36 -5
+2 -2
arch/x86/kernel/cpu/resctrl/rdtgroup.c
··· 3221 3221 3222 3222 list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups); 3223 3223 3224 - ret = rdtgroup_add_files(rdt_root->kn, RF_CTRL_BASE); 3224 + ret = rdtgroup_add_files(kernfs_root_to_node(rdt_root), RF_CTRL_BASE); 3225 3225 if (ret) { 3226 3226 kernfs_destroy_root(rdt_root); 3227 3227 goto out; 3228 3228 } 3229 3229 3230 - rdtgroup_default.kn = rdt_root->kn; 3230 + rdtgroup_default.kn = kernfs_root_to_node(rdt_root); 3231 3231 kernfs_activate(rdtgroup_default.kn); 3232 3232 3233 3233 out:
+9
fs/kernfs/dir.c
··· 971 971 } 972 972 973 973 /** 974 + * kernfs_root_to_node - return the kernfs_node associated with a kernfs_root 975 + * @root: root to use to lookup 976 + */ 977 + struct kernfs_node *kernfs_root_to_node(struct kernfs_root *root) 978 + { 979 + return root->kn; 980 + } 981 + 982 + /** 974 983 * kernfs_create_dir_ns - create a directory 975 984 * @parent: parent in which to create a new directory 976 985 * @name: name of the new directory
+18
fs/kernfs/kernfs-internal.h
··· 31 31 atomic_t user_xattr_size; 32 32 }; 33 33 34 + struct kernfs_root { 35 + /* published fields */ 36 + struct kernfs_node *kn; 37 + unsigned int flags; /* KERNFS_ROOT_* flags */ 38 + 39 + /* private fields, do not use outside kernfs proper */ 40 + struct idr ino_idr; 41 + u32 last_id_lowbits; 42 + u32 id_highbits; 43 + struct kernfs_syscall_ops *syscall_ops; 44 + 45 + /* list of kernfs_super_info of this root, protected by kernfs_rwsem */ 46 + struct list_head supers; 47 + 48 + wait_queue_head_t deactivate_waitq; 49 + struct rw_semaphore kernfs_rwsem; 50 + }; 51 + 34 52 /* +1 to avoid triggering overflow warning when negating it */ 35 53 #define KN_DEACTIVATED_BIAS (INT_MIN + 1) 36 54
+1 -1
fs/sysfs/mount.c
··· 103 103 if (IS_ERR(sysfs_root)) 104 104 return PTR_ERR(sysfs_root); 105 105 106 - sysfs_root_kn = sysfs_root->kn; 106 + sysfs_root_kn = kernfs_root_to_node(sysfs_root); 107 107 108 108 err = register_filesystem(&sysfs_fs_type); 109 109 if (err) {
+4
include/linux/kernfs.h
··· 185 185 struct kernfs_root *root); 186 186 }; 187 187 188 + #if 0 188 189 struct kernfs_root { 189 190 /* published fields */ 190 191 struct kernfs_node *kn; ··· 203 202 wait_queue_head_t deactivate_waitq; 204 203 struct rw_semaphore kernfs_rwsem; 205 204 }; 205 + #endif 206 + 207 + struct kernfs_node *kernfs_root_to_node(struct kernfs_root *root); 206 208 207 209 struct kernfs_open_file { 208 210 /* published fields */
+2 -2
kernel/cgroup/cgroup.c
··· 1302 1302 1303 1303 struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root) 1304 1304 { 1305 - struct cgroup *root_cgrp = kf_root->kn->priv; 1305 + struct cgroup *root_cgrp = kernfs_root_to_node(kf_root)->priv; 1306 1306 1307 1307 return root_cgrp->root; 1308 1308 } ··· 2025 2025 ret = PTR_ERR(root->kf_root); 2026 2026 goto exit_root_id; 2027 2027 } 2028 - root_cgrp->kn = root->kf_root->kn; 2028 + root_cgrp->kn = kernfs_root_to_node(root->kf_root); 2029 2029 WARN_ON_ONCE(cgroup_ino(root_cgrp) != 1); 2030 2030 root_cgrp->ancestor_ids[0] = cgroup_id(root_cgrp); 2031 2031