From: Alexander Nikiforov <a.nikiforov-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
To: Cgroups <cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"Kirill A. Shutemov"
<kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>,
Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>,
KAMEZAWA Hiroyuki
<kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>,
Dmitry Solodkiy
<d.solodkiy-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Subject: Re: [RFD/RFC v2] event about group change
Date: Thu, 26 Apr 2012 10:04:46 +0400 [thread overview]
Message-ID: <4F98E57E.1040201@samsung.com> (raw)
In-Reply-To: <4F98E4E5.6020602-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: cgroup_fsnotify.patch --]
[-- Type: text/x-patch, Size: 4355 bytes --]
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 5a85b34..3594c40 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -179,6 +179,8 @@ struct cgroup {
struct cgroup *parent; /* my parent */
struct dentry __rcu *dentry; /* cgroup fs entry, RCU protected */
+ struct dentry *tasks_dentry; /* "tasks" dentry */
+
/* Private pointers for each registered subsystem */
struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
@@ -387,7 +389,8 @@ struct cgroup_scanner {
* called by subsystems from within a populate() method
*/
int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
- const struct cftype *cft);
+ const struct cftype *cft,
+ int tasks);
/*
* Add a set of new files to the given cgroup directory. Should
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index ed64cca..9ba3c02 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -60,6 +60,7 @@
#include <linux/eventfd.h>
#include <linux/poll.h>
#include <linux/flex_array.h> /* used in cgroup_attach_proc */
+#include <linux/fsnotify.h>
#include <linux/atomic.h>
@@ -699,6 +700,21 @@ static struct cgroup *task_cgroup_from_root(struct task_struct *task,
return res;
}
+static inline void fsnotify_cgroup(struct task_struct *tsk, __u32 mask)
+{
+ struct cgroupfs_root *root;
+ struct inode *d_inode;
+ struct cgroup *cgrp;
+
+ for_each_active_root(root) {
+ cgrp = task_cgroup_from_root(tsk, root);
+ d_inode = cgrp->tasks_dentry->d_inode;
+
+ fsnotify_parent(NULL, cgrp->tasks_dentry, mask);
+ fsnotify(d_inode, mask, d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
+ }
+}
+
/*
* There is one global cgroup mutex. We also require taking
* task_lock() when dereferencing a task's cgroup subsys pointers.
@@ -1924,6 +1940,9 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
goto out;
}
+ /* send event to the userspace */
+ fsnotify_cgroup(tsk, FS_MODIFY);
+
cgroup_task_migrate(cgrp, oldcgrp, tsk, newcg);
for_each_subsys(root, ss) {
@@ -2605,7 +2624,8 @@ static umode_t cgroup_file_mode(const struct cftype *cft)
int cgroup_add_file(struct cgroup *cgrp,
struct cgroup_subsys *subsys,
- const struct cftype *cft)
+ const struct cftype *cft,
+ int tasks)
{
struct dentry *dir = cgrp->dentry;
struct dentry *dentry;
@@ -2629,6 +2649,12 @@ int cgroup_add_file(struct cgroup *cgrp,
dput(dentry);
} else
error = PTR_ERR(dentry);
+
+ if(tasks) {
+ pr_warn("%s(): cft name: %s\n", __func__, name);
+ cgrp->tasks_dentry = dentry;
+ }
+
return error;
}
EXPORT_SYMBOL_GPL(cgroup_add_file);
@@ -2640,7 +2666,7 @@ int cgroup_add_files(struct cgroup *cgrp,
{
int i, err;
for (i = 0; i < count; i++) {
- err = cgroup_add_file(cgrp, subsys, &cft[i]);
+ err = cgroup_add_file(cgrp, subsys, &cft[i], 0);
if (err)
return err;
}
@@ -3642,12 +3668,16 @@ static int cgroup_populate_dir(struct cgroup *cgrp)
/* First clear out any existing files */
cgroup_clear_directory(cgrp->dentry);
- err = cgroup_add_files(cgrp, NULL, files, ARRAY_SIZE(files));
+ err = cgroup_add_file(cgrp, NULL, files, 1);
+ if (err)
+ return err;
+
+ err = cgroup_add_files(cgrp, NULL, files + 1, ARRAY_SIZE(files) - 1);
if (err < 0)
return err;
if (cgrp == cgrp->top_cgroup) {
- if ((err = cgroup_add_file(cgrp, NULL, &cft_release_agent)) < 0)
+ if ((err = cgroup_add_file(cgrp, NULL, &cft_release_agent, 0)) < 0)
return err;
}
@@ -4480,6 +4510,7 @@ static const struct file_operations proc_cgroupstats_operations = {
*/
void cgroup_fork(struct task_struct *child)
{
+
/*
* We don't need to task_lock() current because current->cgroups
* can't be changed concurrently here. The parent obviously hasn't
@@ -4489,6 +4520,10 @@ void cgroup_fork(struct task_struct *child)
child->cgroups = current->cgroups;
get_css_set(child->cgroups);
INIT_LIST_HEAD(&child->cg_list);
+
+ cgroup_lock();
+ fsnotify_cgroup(child, FS_MODIFY);
+ cgroup_unlock();
}
/**
@@ -4611,6 +4646,11 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
/* Reassign the task to the init_css_set. */
task_lock(tsk);
cg = tsk->cgroups;
+
+ cgroup_lock();
+ fsnotify_cgroup(tsk, FS_MODIFY);
+ cgroup_unlock();
+
tsk->cgroups = &init_css_set;
if (run_callbacks && need_forkexit_callback) {
next prev parent reply other threads:[~2012-04-26 6:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-26 6:02 [RFD/RFC v2] event about group change Alexander Nikiforov
[not found] ` <4F98E4E5.6020602-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-04-26 6:04 ` Alexander Nikiforov [this message]
[not found] ` <4F98E57E.1040201-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-04-26 6:09 ` Alexander Nikiforov
2012-04-27 22:34 ` Tejun Heo
[not found] ` <20120427223455.GU26595-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-04-28 5:40 ` Alexander Nikiforov
[not found] ` <4F9B82E1.3070602-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-04-28 21:41 ` Tejun Heo
[not found] ` <20120428214131.GB4586-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2012-05-03 9:17 ` Alexander Nikiforov
2012-05-03 9:21 ` [PATCH -V3 1/1] cgroup: Add inotify event on change tasks file (fork, exit, move pid from file) Alexander Nikiforov
[not found] ` <4FA24E07.1010206-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-05-03 15:50 ` Tejun Heo
[not found] ` <20120503155012.GB5528-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-04 12:55 ` Alexander Nikiforov
[not found] ` <4FA3D1D0.8000403-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-05-04 16:54 ` Tejun Heo
[not found] ` <20120504165433.GC24639-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-05 3:50 ` Alexander Nikiforov
2012-05-05 5:50 ` [PATCH V5] event about group change Alex Nikiforov
[not found] ` <1336197047-22145-1-git-send-email-a.nikiforov-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-05-05 5:50 ` [PATCH V5] Currently, user can get inotify FS_MODIFY event only if "tasks" file changed from the user space side (for example echo $$ > /patch/to/cgroup/tasks), but if another process forked user don't get FS_MODIFY event. This patch add this feature. With this user can get FS_MODIFY on do_fork()/do_exit()/move PID from one group to another Alex Nikiforov
2012-05-05 5:58 ` [PATCH -V3 1/1] cgroup: Add inotify event on change tasks file (fork, exit, move pid from file) Alexander Nikiforov
2012-05-03 20:05 ` Eric Paris
2012-05-04 5:24 ` Alexander Nikiforov
[not found] ` <4FA36818.9010409-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-05-04 17:04 ` Tejun Heo
[not found] ` <20120504170412.GD24639-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-04 17:43 ` Al Viro
[not found] ` <20120504174330.GS6871-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2012-05-07 20:38 ` Tejun Heo
[not found] ` <20120507203848.GL19417-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-15 15:16 ` Tejun Heo
[not found] ` <20120515151637.GD6119-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-15 15:25 ` Eric Paris
2012-05-15 15:28 ` Tejun Heo
[not found] ` <20120515152844.GE6119-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-22 5:31 ` Alexander Nikiforov
2012-04-28 5:15 ` [RFD/RFC v2] event about group change Alexander Nikiforov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F98E57E.1040201@samsung.com \
--to=a.nikiforov-sze3o3uu22jbdgjk7y7tuq@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=d.solodkiy-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
--cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org \
--cc=lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).