aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2022-08-19 13:50:23 -1000
committerTejun Heo <tj@kernel.org>2022-08-19 13:50:23 -1000
commitb3a0dc646ab7718099d2a3b03285a2bd1f539ab6 (patch)
tree09044822434a2123254a6559ebef0b2bff158cb1
parent5a44f6fff9b38351661265e85958f41d4f4067e7 (diff)
downloadmisc-kernfs-deactivate.tar.gz
cgroup: Implement cgroup_file_show()kernfs-deactivate
Add cgroup_file_show() which allows toggling visibility of a cgroup file using the new kernfs_deactivate(). This will be used to hide psi interface files on cgroups where it's disabled. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Chengming Zhou <zhouchengming@bytedance.com> Cc: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--include/linux/cgroup.h1
-rw-r--r--kernel/cgroup/cgroup.c23
2 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index ed53bfe7c46c47..f61dd135efbebb 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -114,6 +114,7 @@ int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
int cgroup_rm_cftypes(struct cftype *cfts);
void cgroup_file_notify(struct cgroup_file *cfile);
+void cgroup_file_show(struct cgroup_file *cfile, bool show);
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry);
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index ffaccd6373f1e7..eb096499c72bc2 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4340,6 +4340,29 @@ void cgroup_file_notify(struct cgroup_file *cfile)
}
/**
+ * cgroup_file_show - show or hide a hidden cgroup file
+ * @cfile: target cgroup_file obtained by setting cftype->file_offset
+ * @show: whether to show or hide
+ */
+void cgroup_file_show(struct cgroup_file *cfile, bool show)
+{
+ struct kernfs_node *kn;
+
+ spin_lock_irq(&cgroup_file_kn_lock);
+ kn = cfile->kn;
+ kernfs_get(kn);
+ spin_unlock_irq(&cgroup_file_kn_lock);
+
+ if (show)
+ kernfs_activate(kn);
+ else
+ kernfs_deactivate(kn);
+
+ kernfs_put(kn);
+}
+
+
+/**
* css_next_child - find the next child of a given css
* @pos: the current position (%NULL to initiate traversal)
* @parent: css whose children to walk