Skip to content

Commit e61734c

Browse files
committed
cgroup: remove cgroup->name
cgroup->name handling became quite complicated over time involving dedicated struct cgroup_name for RCU protection. Now that cgroup is on kernfs, we can drop all of it and simply use kernfs_name/path() and friends. Replace cgroup->name and all related code with kernfs name/path constructs. * Reimplement cgroup_name() and cgroup_path() as thin wrappers on top of kernfs counterparts, which involves semantic changes. pr_cont_cgroup_name() and pr_cont_cgroup_path() added. * cgroup->name handling dropped from cgroup_rename(). * All users of cgroup_name/path() updated to the new semantics. Users which were formatting the string just to printk them are converted to use pr_cont_cgroup_name/path() instead, which simplifies things quite a bit. As cgroup_name() no longer requires RCU read lock around it, RCU lockings which were protecting only cgroup_name() are removed. v2: Comment above oom_info_lock updated as suggested by Michal. v3: dummy_top doesn't have a kn associated and pr_cont_cgroup_name/path() ended up calling the matching kernfs functions with NULL kn leading to oops. Test for NULL kn and print "/" if so. This issue was reported by Fengguang Wu. v4: Rebased on top of 0ab02ca ("cgroup: protect modifications to cgroup_idr with cgroup_mutex"). Signed-off-by: Tejun Heo <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Li Zefan <[email protected]> Cc: Fengguang Wu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Balbir Singh <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]>
1 parent 6f30558 commit e61734c

File tree

7 files changed

+110
-210
lines changed

7 files changed

+110
-210
lines changed

block/blk-cgroup.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,16 @@ static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd)
241241
*/
242242
static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen)
243243
{
244-
int ret;
244+
char *p;
245245

246-
ret = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
247-
if (ret)
246+
p = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
247+
if (!p) {
248248
strncpy(buf, "<unavailable>", buflen);
249-
return ret;
249+
return -ENAMETOOLONG;
250+
}
251+
252+
memmove(buf, p, buf + buflen - p);
253+
return 0;
250254
}
251255

252256
/**

fs/kernfs/dir.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ char *kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
112112
spin_unlock_irqrestore(&kernfs_rename_lock, flags);
113113
return p;
114114
}
115+
EXPORT_SYMBOL_GPL(kernfs_path);
115116

116117
/**
117118
* pr_cont_kernfs_name - pr_cont name of a kernfs_node

include/linux/cgroup.h

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ enum {
138138
CGRP_SANE_BEHAVIOR,
139139
};
140140

141-
struct cgroup_name {
142-
struct rcu_head rcu_head;
143-
char name[];
144-
};
145-
146141
struct cgroup {
147142
unsigned long flags; /* "unsigned long" so bitops work */
148143

@@ -179,19 +174,6 @@ struct cgroup {
179174
*/
180175
u64 serial_nr;
181176

182-
/*
183-
* This is a copy of dentry->d_name, and it's needed because
184-
* we can't use dentry->d_name in cgroup_path().
185-
*
186-
* You must acquire rcu_read_lock() to access cgrp->name, and
187-
* the only place that can change it is rename(), which is
188-
* protected by parent dir's i_mutex.
189-
*
190-
* Normally you should use cgroup_name() wrapper rather than
191-
* access it directly.
192-
*/
193-
struct cgroup_name __rcu *name;
194-
195177
/* Private pointers for each registered subsystem */
196178
struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
197179

@@ -479,12 +461,6 @@ static inline bool cgroup_sane_behavior(const struct cgroup *cgrp)
479461
return cgrp->root->flags & CGRP_ROOT_SANE_BEHAVIOR;
480462
}
481463

482-
/* Caller should hold rcu_read_lock() */
483-
static inline const char *cgroup_name(const struct cgroup *cgrp)
484-
{
485-
return rcu_dereference(cgrp->name)->name;
486-
}
487-
488464
/* returns ino associated with a cgroup, 0 indicates unmounted root */
489465
static inline ino_t cgroup_ino(struct cgroup *cgrp)
490466
{
@@ -503,14 +479,47 @@ static inline struct cftype *seq_cft(struct seq_file *seq)
503479

504480
struct cgroup_subsys_state *seq_css(struct seq_file *seq);
505481

482+
/*
483+
* Name / path handling functions. All are thin wrappers around the kernfs
484+
* counterparts and can be called under any context.
485+
*/
486+
487+
static inline int cgroup_name(struct cgroup *cgrp, char *buf, size_t buflen)
488+
{
489+
return kernfs_name(cgrp->kn, buf, buflen);
490+
}
491+
492+
static inline char * __must_check cgroup_path(struct cgroup *cgrp, char *buf,
493+
size_t buflen)
494+
{
495+
return kernfs_path(cgrp->kn, buf, buflen);
496+
}
497+
498+
static inline void pr_cont_cgroup_name(struct cgroup *cgrp)
499+
{
500+
/* dummy_top doesn't have a kn associated */
501+
if (cgrp->kn)
502+
pr_cont_kernfs_name(cgrp->kn);
503+
else
504+
pr_cont("/");
505+
}
506+
507+
static inline void pr_cont_cgroup_path(struct cgroup *cgrp)
508+
{
509+
/* dummy_top doesn't have a kn associated */
510+
if (cgrp->kn)
511+
pr_cont_kernfs_path(cgrp->kn);
512+
else
513+
pr_cont("/");
514+
}
515+
516+
char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
517+
506518
int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
507519
int cgroup_rm_cftypes(struct cftype *cfts);
508520

509521
bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
510522

511-
int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
512-
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
513-
514523
int cgroup_task_count(const struct cgroup *cgrp);
515524

516525
/*

0 commit comments

Comments
 (0)