From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org,
hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org,
mhocko-AlSwsSmVLrQ@public.gmane.org,
bsingharora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org,
nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org,
daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org,
arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: [PATCH 10/12] cgroup: attach cgroup_open_file to all cgroup files
Date: Wed, 27 Nov 2013 18:42:37 -0500 [thread overview]
Message-ID: <1385595759-17656-11-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1385595759-17656-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
In preparation of conversion to kernfs, cgroup file handling is
updated so that it can be easily mapped to kernfs. This patch
attaches cgroup_open_file, which used to be attached to pidlist files,
to all cgroup files, introduces seq_css/cft() accessors to determine
the cgroup_subsys_state and cftype associated with a given cgroup
seq_file, exports them as public interface.
This doesn't cause any behavior changes but unifies cgroup file
handling across different file types and will help converting them to
kernfs seq_show() interface.
Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
include/linux/cgroup.h | 33 +++++++++++++++++++++++++++++++++
kernel/cgroup.c | 47 +++++++++++++++++------------------------------
2 files changed, 50 insertions(+), 30 deletions(-)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 53e11da..c3d698a 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -21,6 +21,7 @@
#include <linux/xattr.h>
#include <linux/fs.h>
#include <linux/percpu-refcount.h>
+#include <linux/seq_file.h>
#ifdef CONFIG_CGROUPS
@@ -490,6 +491,26 @@ struct cftype_set {
};
/*
+ * cgroupfs file entry, pointed to from leaf dentry->d_fsdata. Don't
+ * access directly.
+ */
+struct cfent {
+ struct list_head node;
+ struct dentry *dentry;
+ struct cftype *type;
+ struct cgroup_subsys_state *css;
+
+ /* file xattrs */
+ struct simple_xattrs xattrs;
+};
+
+/* seq_file->private points to the following, only ->priv is public */
+struct cgroup_open_file {
+ struct cfent *cfe;
+ void *priv;
+};
+
+/*
* See the comment above CGRP_ROOT_SANE_BEHAVIOR for details. This
* function can be called as long as @cgrp is accessible.
*/
@@ -504,6 +525,18 @@ static inline const char *cgroup_name(const struct cgroup *cgrp)
return rcu_dereference(cgrp->name)->name;
}
+static inline struct cgroup_subsys_state *seq_css(struct seq_file *seq)
+{
+ struct cgroup_open_file *of = seq->private;
+ return of->cfe->css;
+}
+
+static inline struct cftype *seq_cft(struct seq_file *seq)
+{
+ struct cgroup_open_file *of = seq->private;
+ return of->cfe->type;
+}
+
int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
int cgroup_rm_cftypes(struct cftype *cfts);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index bdb8e8d..1189de7 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -41,7 +41,6 @@
#include <linux/rcupdate.h>
#include <linux/sched.h>
#include <linux/backing-dev.h>
-#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/magic.h>
#include <linux/spinlock.h>
@@ -130,19 +129,6 @@ static struct cgroupfs_root cgroup_dummy_root;
/* dummy_top is a shorthand for the dummy hierarchy's top cgroup */
static struct cgroup * const cgroup_dummy_top = &cgroup_dummy_root.top_cgroup;
-/*
- * cgroupfs file entry, pointed to from leaf dentry->d_fsdata.
- */
-struct cfent {
- struct list_head node;
- struct dentry *dentry;
- struct cftype *type;
- struct cgroup_subsys_state *css;
-
- /* file xattrs */
- struct simple_xattrs xattrs;
-};
-
/* The list of hierarchy roots */
static LIST_HEAD(cgroup_roots);
@@ -2302,9 +2288,8 @@ out_free:
static int cgroup_seqfile_show(struct seq_file *m, void *arg)
{
- struct cfent *cfe = m->private;
- struct cftype *cft = cfe->type;
- struct cgroup_subsys_state *css = cfe->css;
+ struct cftype *cft = seq_cft(m);
+ struct cgroup_subsys_state *css = seq_css(m);
if (cft->read_seq_string)
return cft->read_seq_string(css, cft, m);
@@ -2353,10 +2338,18 @@ static int cgroup_file_open(struct inode *inode, struct file *file)
WARN_ON_ONCE(cfe->css && cfe->css != css);
cfe->css = css;
- if (cft->open)
+ if (cft->open) {
err = cft->open(inode, file);
- else
- err = single_open(file, cgroup_seqfile_show, cfe);
+ } else {
+ err = single_open_size(file, cgroup_seqfile_show, cfe,
+ sizeof(struct cgroup_open_file));
+ if (!err) {
+ struct seq_file *sf = file->private_data;
+ struct cgroup_open_file *of = sf->private;
+
+ of->cfe = cfe;
+ }
+ }
if (css->ss && err)
css_put(css);
@@ -3368,12 +3361,6 @@ struct cgroup_pidlist {
struct delayed_work destroy_dwork;
};
-/* seq_file->private points to the following */
-struct cgroup_open_file {
- struct cfent *cfe;
- void *priv;
-};
-
/*
* The following two functions "fix" the issue where there are more pids
* than kmalloc will give memory for; in such cases, we use vmalloc/vfree.
@@ -3689,9 +3676,9 @@ static void *cgroup_pidlist_start(struct seq_file *s, loff_t *pos)
* next pid to display, if any
*/
struct cgroup_open_file *of = s->private;
- struct cgroup *cgrp = of->cfe->css->cgroup;
+ struct cgroup *cgrp = seq_css(s)->cgroup;
struct cgroup_pidlist *l;
- enum cgroup_filetype type = of->cfe->type->private;
+ enum cgroup_filetype type = seq_cft(s)->private;
int index = 0, pid = *pos;
int *iter, ret;
@@ -3749,7 +3736,7 @@ static void cgroup_pidlist_stop(struct seq_file *s, void *v)
if (l)
mod_delayed_work(cgroup_pidlist_destroy_wq, &l->destroy_dwork,
CGROUP_PIDLIST_DESTROY_DELAY);
- mutex_unlock(&of->cfe->css->cgroup->pidlist_mutex);
+ mutex_unlock(&seq_css(s)->cgroup->pidlist_mutex);
}
static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos)
@@ -3766,7 +3753,7 @@ static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos)
if (p >= end) {
return NULL;
} else {
- *pos = cgroup_pid_fry(of->cfe->css->cgroup, *p);
+ *pos = cgroup_pid_fry(seq_css(s)->cgroup, *p);
return p;
}
}
--
1.8.4.2
next prev parent reply other threads:[~2013-11-27 23:42 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-27 23:42 [PATCHSET cgroup/for-3.14] cgroup: consolidate file handling Tejun Heo
[not found] ` <1385595759-17656-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-11-27 23:42 ` [PATCH 01/12] cgroup, sched: convert away from cftype->read_map() Tejun Heo
2013-11-27 23:42 ` [PATCH 02/12] cpuset: convert away from cftype->read() Tejun Heo
2013-11-27 23:42 ` [PATCH 03/12] memcg: convert away from cftype->read() and ->read_map() Tejun Heo
[not found] ` <1385595759-17656-4-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-11-28 8:26 ` Michal Hocko
2013-11-27 23:42 ` [PATCH 04/12] netprio_cgroup: convert away from cftype->read_map() Tejun Heo
[not found] ` <1385595759-17656-5-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-11-29 1:56 ` Neil Horman
2013-11-29 8:52 ` Daniel Wagner
2013-11-27 23:42 ` [PATCH 05/12] hugetlb_cgroup: convert away from cftype->read() Tejun Heo
[not found] ` <1385595759-17656-6-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-11-28 8:29 ` Michal Hocko
2013-11-27 23:42 ` [PATCH 06/12] cgroup: remove cftype->read(), ->read_map() and ->write() Tejun Heo
2013-11-27 23:42 ` [PATCH 07/12] cgroup: unify cgroup_write_X64() and cgroup_write_string() Tejun Heo
[not found] ` <1385595759-17656-8-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-11-28 11:18 ` Michal Hocko
[not found] ` <20131128111818.GG2761-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-11-29 20:05 ` Tejun Heo
[not found] ` <20131129200525.GC21755-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-12-02 9:54 ` Michal Hocko
[not found] ` <20131202095401.GA18838-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-12-02 13:30 ` Tejun Heo
[not found] ` <20131202133059.GA3626-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-12-02 14:12 ` Michal Hocko
[not found] ` <20131202141242.GD18838-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-12-03 20:41 ` Tejun Heo
[not found] ` <20131203204155.GL8277-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-12-03 21:04 ` Michal Hocko
2013-12-02 16:44 ` Johannes Weiner
[not found] ` <20131202164406.GP3556-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2013-12-03 7:35 ` Li Zefan
2013-11-27 23:42 ` [PATCH 08/12] cgroup: unify read path so that seq_file is always used Tejun Heo
2013-11-27 23:42 ` [PATCH 09/12] cgroup: generalize cgroup_pidlist_open_file Tejun Heo
2013-11-27 23:42 ` Tejun Heo [this message]
[not found] ` <1385595759-17656-11-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-12-04 6:04 ` [PATCH 10/12] cgroup: attach cgroup_open_file to all cgroup files Li Zefan
[not found] ` <529EC5F4.10708-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-12-04 13:04 ` Tejun Heo
2013-12-04 15:09 ` [PATCH v2 " Tejun Heo
2013-11-27 23:42 ` [PATCH 11/12] cgroup: replace cftype->read_seq_string() with cftype->seq_show() Tejun Heo
[not found] ` <1385595759-17656-12-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-11-28 9:07 ` Daniel Wagner
2013-11-28 11:25 ` Michal Hocko
2013-12-02 14:41 ` Aristeu Rozanski
2013-12-02 14:52 ` Vivek Goyal
2013-11-27 23:42 ` [PATCH 12/12] cgroup: unify pidlist and other file handling Tejun Heo
[not found] ` <1385595759-17656-13-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-12-04 6:20 ` Li Zefan
[not found] ` <529EC9A6.903-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-12-04 13:08 ` Tejun Heo
2013-12-04 15:09 ` [PATCH v3 " Tejun Heo
2013-12-05 1:48 ` [PATCHSET cgroup/for-3.14] cgroup: consolidate " Li Zefan
2013-12-05 17:26 ` Tejun Heo
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=1385595759-17656-11-git-send-email-tj@kernel.org \
--to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=arozansk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=bsingharora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org \
--cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
--cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
--cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org \
--cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=vgoyal-H+wXaHxf7aLQT0dZR+AlfA@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).