Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
cgroup: remove cgroup->name
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
htejun committed Feb 12, 2014
1 parent 6f30558 commit e61734c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 210 deletions.
12 changes: 8 additions & 4 deletions block/blk-cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd)
*/
static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen)
{
int ret;
char *p;

ret = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
if (ret)
p = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
if (!p) {
strncpy(buf, "<unavailable>", buflen);
return ret;
return -ENAMETOOLONG;
}

memmove(buf, p, buf + buflen - p);
return 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions fs/kernfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ char *kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
spin_unlock_irqrestore(&kernfs_rename_lock, flags);
return p;
}
EXPORT_SYMBOL_GPL(kernfs_path);

/**
* pr_cont_kernfs_name - pr_cont name of a kernfs_node
Expand Down
63 changes: 36 additions & 27 deletions include/linux/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ enum {
CGRP_SANE_BEHAVIOR,
};

struct cgroup_name {
struct rcu_head rcu_head;
char name[];
};

struct cgroup {
unsigned long flags; /* "unsigned long" so bitops work */

Expand Down Expand Up @@ -179,19 +174,6 @@ struct cgroup {
*/
u64 serial_nr;

/*
* This is a copy of dentry->d_name, and it's needed because
* we can't use dentry->d_name in cgroup_path().
*
* You must acquire rcu_read_lock() to access cgrp->name, and
* the only place that can change it is rename(), which is
* protected by parent dir's i_mutex.
*
* Normally you should use cgroup_name() wrapper rather than
* access it directly.
*/
struct cgroup_name __rcu *name;

/* Private pointers for each registered subsystem */
struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];

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

/* Caller should hold rcu_read_lock() */
static inline const char *cgroup_name(const struct cgroup *cgrp)
{
return rcu_dereference(cgrp->name)->name;
}

/* returns ino associated with a cgroup, 0 indicates unmounted root */
static inline ino_t cgroup_ino(struct cgroup *cgrp)
{
Expand All @@ -503,14 +479,47 @@ static inline struct cftype *seq_cft(struct seq_file *seq)

struct cgroup_subsys_state *seq_css(struct seq_file *seq);

/*
* Name / path handling functions. All are thin wrappers around the kernfs
* counterparts and can be called under any context.
*/

static inline int cgroup_name(struct cgroup *cgrp, char *buf, size_t buflen)
{
return kernfs_name(cgrp->kn, buf, buflen);
}

static inline char * __must_check cgroup_path(struct cgroup *cgrp, char *buf,
size_t buflen)
{
return kernfs_path(cgrp->kn, buf, buflen);
}

static inline void pr_cont_cgroup_name(struct cgroup *cgrp)
{
/* dummy_top doesn't have a kn associated */
if (cgrp->kn)
pr_cont_kernfs_name(cgrp->kn);
else
pr_cont("/");
}

static inline void pr_cont_cgroup_path(struct cgroup *cgrp)
{
/* dummy_top doesn't have a kn associated */
if (cgrp->kn)
pr_cont_kernfs_path(cgrp->kn);
else
pr_cont("/");
}

char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);

int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
int cgroup_rm_cftypes(struct cftype *cfts);

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

int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);

int cgroup_task_count(const struct cgroup *cgrp);

/*
Expand Down
Loading

0 comments on commit e61734c

Please sign in to comment.