Re: [PATCH 1/5] cgroup: ID notification call back

From: KAMEZAWA Hiroyuki
Date: Tue Aug 24 2010 - 21:08:31 EST


On Tue, 24 Aug 2010 17:46:03 -0700
Paul Menage <menage@xxxxxxxxxx> wrote:

> On Tue, Aug 24, 2010 at 5:37 PM, KAMEZAWA Hiroyuki
> <kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
> >
> > Ou...I'm sorry but I would like to use attach_id() for this time.
> > Forgive me, above seems a big change.
> > I'd like to write a series of patch to do above, later.
> > At least, to do a trial.
> >
>
> Sure, for testing outside the tree. I don't think introducing new code
> into mainline that's intentionally ugly and cutting corners is a good
> idea.
>

Hmm. How this pseudo code looks like ? This passes "new id" via
cgroup->subsys[array] at creation. (Using union will be better, maybe).

---
include/linux/cgroup.h | 1 +
kernel/cgroup.c | 26 +++++++++++++++++++-------
2 files changed, 20 insertions(+), 7 deletions(-)

Index: mmotm-0811/include/linux/cgroup.h
===================================================================
--- mmotm-0811.orig/include/linux/cgroup.h
+++ mmotm-0811/include/linux/cgroup.h
@@ -508,6 +508,7 @@ struct cgroup_subsys {
struct cgroupfs_root *root;
struct list_head sibling;
/* used when use_id == true */
+ int max_id;
struct idr idr;
spinlock_t id_lock;

Index: mmotm-0811/kernel/cgroup.c
===================================================================
--- mmotm-0811.orig/kernel/cgroup.c
+++ mmotm-0811/kernel/cgroup.c
@@ -3335,19 +3335,31 @@ static long cgroup_create(struct cgroup
set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);

for_each_subsys(root, ss) {
- struct cgroup_subsys_state *css = ss->create(ss, cgrp);
+ struct cgroup_subsys_state *css;

- if (IS_ERR(css)) {
- err = PTR_ERR(css);
- goto err_destroy;
- }
- init_cgroup_css(css, ss, cgrp);
if (ss->use_id) {
err = alloc_css_id(ss, parent, cgrp);
if (err)
goto err_destroy;
+ /*
+ * Here, created css_id is recorded into
+ * cgrp->subsys[ss->subsys_id]
+ * array and passed to subsystem.
+ */
+ } else
+ cgrp->subsys[ss->subsys_id] = NULL;
+
+ css = ss->create(ss, cgrp);
+
+ if (IS_ERR(css)) {
+ /* forget preallocated id */
+ if (cgrp->subsys[ss->subsys_id])
+ free_css_id_direct((struct css_id *)
+ cgrp->subsys[ss->subsys_id]);
+ err = PTR_ERR(css);
+ goto err_destroy;
}
- /* At error, ->destroy() callback has to free assigned ID. */
+ init_cgroup_css(css, ss, cgrp);
}

cgroup_lock_hierarchy(root);



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/