From: Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
To: Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: Linux Containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
Andrew Morton
<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 0/4] cgroups: show correct file mode
Date: Tue, 03 Mar 2009 09:08:23 +0800 [thread overview]
Message-ID: <49AC8307.7090008@cn.fujitsu.com> (raw)
In-Reply-To: <6599ad830903021019p3b29c173oc7772af6679d90e0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Paul Menage wrote:
> On Sun, Mar 1, 2009 at 6:13 PM, Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> wrote:
>> Now a cgroup subsystem can set default file mode of its control files,
>> so here is a patchset to correct file mode of each subsystem's files.
>
> I really think that we should be defaulting this based on whether the
> control file has read or write handlers.
>
> Sure, there are special cases like "tasks" that we'd need to set a
> manual value for, but most of these patches would be unnecessary.
>
Those patches are small and trivial, but it's ok for me to do this
automatically. How about below patch.
Note cpuset.memory_pressure is read-only though it has read handler.
Since if the read handler is removed, it'll return EINVAL instead of
the current EACCESS, I think it's better to leave as it is.
=====================
cgroups: show correct file mode
Signed-off-by: Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
---
include/linux/cgroup.h | 5 +++++
kernel/cgroup.c | 30 ++++++++++++++++++++++++++++++
kernel/cpuset.c | 1 +
3 files changed, 36 insertions(+)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 6ad1989..af3c10f 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -258,6 +258,11 @@ struct cftype {
*/
char name[MAX_CFTYPE_NAME];
int private;
+ /*
+ * If not 0, file mode is set to this value, otherwise it will
+ * be figured out automatically
+ */
+ int mode;
/*
* If non-zero, defines the maximum length of string that can
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 379baa3..0b19204 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1750,6 +1750,33 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry,
return error;
}
+/**
+ * cgroup_file_mode - deduce file mode of a control file
+ * @cft: the control file in question
+ *
+ * returns cftype->mode if ->mode is not 0
+ * returns 0644 if it has both a read and a write handler
+ * returns 0444 if it has only a read handler
+ * returns 0200 if it has only a write hander
+ */
+static int cgroup_file_mode(const struct cftype *cft)
+{
+ int mode = 0;
+
+ if (cft->mode)
+ return cft->mode;
+
+ if (cft->read || cft->read_u64 || cft->read_s64 ||
+ cft->read_map || cft->read_seq_string)
+ mode += 0444;
+
+ if (cft->write || cft->write_u64 || cft->write_s64 ||
+ cft->write_string || cft->trigger)
+ mode += 0200;
+
+ return mode;
+}
+
int cgroup_add_file(struct cgroup *cgrp,
struct cgroup_subsys *subsys,
const struct cftype *cft)
@@ -1757,6 +1784,7 @@ int cgroup_add_file(struct cgroup *cgrp,
struct dentry *dir = cgrp->dentry;
struct dentry *dentry;
int error;
+ int mode;
char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 };
if (subsys && !test_bit(ROOT_NOPREFIX, &cgrp->root->flags)) {
@@ -1767,6 +1795,7 @@ int cgroup_add_file(struct cgroup *cgrp,
BUG_ON(!mutex_is_locked(&dir->d_inode->i_mutex));
dentry = lookup_one_len(name, dir, strlen(name));
if (!IS_ERR(dentry)) {
+ mode = cgroup_file_mode(cft);
error = cgroup_create_file(dentry, 0644 | S_IFREG,
cgrp->root->sb);
if (!error)
@@ -2349,6 +2378,7 @@ static struct cftype files[] = {
.write_u64 = cgroup_tasks_write,
.release = cgroup_tasks_release,
.private = FILE_TASKLIST,
+ .mode = 0644,
},
{
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index a46d693..31e28b3 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1678,6 +1678,7 @@ static struct cftype files[] = {
.read_u64 = cpuset_read_u64,
.write_u64 = cpuset_write_u64,
.private = FILE_MEMORY_PRESSURE,
+ .mode = 0444,
},
{
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizf@cn.fujitsu.com>
To: Paul Menage <menage@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux Containers <containers@lists.linux-foundation.org>
Subject: Re: [PATCH 0/4] cgroups: show correct file mode
Date: Tue, 03 Mar 2009 09:08:23 +0800 [thread overview]
Message-ID: <49AC8307.7090008@cn.fujitsu.com> (raw)
In-Reply-To: <6599ad830903021019p3b29c173oc7772af6679d90e0@mail.gmail.com>
Paul Menage wrote:
> On Sun, Mar 1, 2009 at 6:13 PM, Li Zefan <lizf@cn.fujitsu.com> wrote:
>> Now a cgroup subsystem can set default file mode of its control files,
>> so here is a patchset to correct file mode of each subsystem's files.
>
> I really think that we should be defaulting this based on whether the
> control file has read or write handlers.
>
> Sure, there are special cases like "tasks" that we'd need to set a
> manual value for, but most of these patches would be unnecessary.
>
Those patches are small and trivial, but it's ok for me to do this
automatically. How about below patch.
Note cpuset.memory_pressure is read-only though it has read handler.
Since if the read handler is removed, it'll return EINVAL instead of
the current EACCESS, I think it's better to leave as it is.
=====================
cgroups: show correct file mode
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
include/linux/cgroup.h | 5 +++++
kernel/cgroup.c | 30 ++++++++++++++++++++++++++++++
kernel/cpuset.c | 1 +
3 files changed, 36 insertions(+)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 6ad1989..af3c10f 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -258,6 +258,11 @@ struct cftype {
*/
char name[MAX_CFTYPE_NAME];
int private;
+ /*
+ * If not 0, file mode is set to this value, otherwise it will
+ * be figured out automatically
+ */
+ int mode;
/*
* If non-zero, defines the maximum length of string that can
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 379baa3..0b19204 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1750,6 +1750,33 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry,
return error;
}
+/**
+ * cgroup_file_mode - deduce file mode of a control file
+ * @cft: the control file in question
+ *
+ * returns cftype->mode if ->mode is not 0
+ * returns 0644 if it has both a read and a write handler
+ * returns 0444 if it has only a read handler
+ * returns 0200 if it has only a write hander
+ */
+static int cgroup_file_mode(const struct cftype *cft)
+{
+ int mode = 0;
+
+ if (cft->mode)
+ return cft->mode;
+
+ if (cft->read || cft->read_u64 || cft->read_s64 ||
+ cft->read_map || cft->read_seq_string)
+ mode += 0444;
+
+ if (cft->write || cft->write_u64 || cft->write_s64 ||
+ cft->write_string || cft->trigger)
+ mode += 0200;
+
+ return mode;
+}
+
int cgroup_add_file(struct cgroup *cgrp,
struct cgroup_subsys *subsys,
const struct cftype *cft)
@@ -1757,6 +1784,7 @@ int cgroup_add_file(struct cgroup *cgrp,
struct dentry *dir = cgrp->dentry;
struct dentry *dentry;
int error;
+ int mode;
char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 };
if (subsys && !test_bit(ROOT_NOPREFIX, &cgrp->root->flags)) {
@@ -1767,6 +1795,7 @@ int cgroup_add_file(struct cgroup *cgrp,
BUG_ON(!mutex_is_locked(&dir->d_inode->i_mutex));
dentry = lookup_one_len(name, dir, strlen(name));
if (!IS_ERR(dentry)) {
+ mode = cgroup_file_mode(cft);
error = cgroup_create_file(dentry, 0644 | S_IFREG,
cgrp->root->sb);
if (!error)
@@ -2349,6 +2378,7 @@ static struct cftype files[] = {
.write_u64 = cgroup_tasks_write,
.release = cgroup_tasks_release,
.private = FILE_TASKLIST,
+ .mode = 0644,
},
{
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index a46d693..31e28b3 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1678,6 +1678,7 @@ static struct cftype files[] = {
.read_u64 = cpuset_read_u64,
.write_u64 = cpuset_write_u64,
.private = FILE_MEMORY_PRESSURE,
+ .mode = 0444,
},
{
next prev parent reply other threads:[~2009-03-03 1:08 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-02 2:13 [PATCH 0/4] cgroups: show correct file mode Li Zefan
[not found] ` <49AB40BF.4030706-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-03-02 2:13 ` [PATCH 1/4] cgroup debug: " Li Zefan
2009-03-02 2:13 ` Li Zefan
2009-03-02 2:14 ` [PATCH 2/4] cpuacct: " Li Zefan
2009-03-02 2:14 ` Li Zefan
2009-03-02 2:15 ` [PATCH 3/4] devcgroup: " Li Zefan
2009-03-02 2:16 ` [PATCH 4/4] cpuset: " Li Zefan
2009-03-02 18:19 ` [PATCH 0/4] cgroups: " Paul Menage
2009-03-02 2:15 ` [PATCH 3/4] devcgroup: " Li Zefan
2009-03-02 13:06 ` Serge E. Hallyn
[not found] ` <49AB4143.9050704-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-03-02 13:06 ` Serge E. Hallyn
2009-03-02 2:16 ` [PATCH 4/4] cpuset: " Li Zefan
2009-03-02 18:19 ` [PATCH 0/4] cgroups: " Paul Menage
2009-03-03 0:09 ` KAMEZAWA Hiroyuki
2009-03-03 0:15 ` Paul Menage
[not found] ` <6599ad830903021615j6e1380e2l1544b67b187c1f5e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-03-03 0:20 ` KAMEZAWA Hiroyuki
2009-03-03 0:20 ` KAMEZAWA Hiroyuki
[not found] ` <20090303092021.93e69b96.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-03-03 0:23 ` Paul Menage
2009-03-03 0:23 ` Mike Waychison
2009-03-03 0:23 ` Paul Menage
2009-03-03 0:23 ` Mike Waychison
2009-03-03 0:26 ` Paul Menage
[not found] ` <49AC789D.5050209-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2009-03-03 0:26 ` Paul Menage
[not found] ` <20090303090950.60cea53a.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-03-03 0:15 ` Paul Menage
[not found] ` <6599ad830903021019p3b29c173oc7772af6679d90e0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-03-03 0:09 ` KAMEZAWA Hiroyuki
2009-03-03 1:08 ` Li Zefan [this message]
2009-03-03 1:08 ` Li Zefan
[not found] ` <49AC8307.7090008-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-03-03 1:08 ` KAMEZAWA Hiroyuki
2009-03-03 1:16 ` Paul Menage
2009-03-03 1:16 ` Paul Menage
2009-03-03 1:08 ` KAMEZAWA Hiroyuki
2009-03-03 1:15 ` Li Zefan
2009-03-03 1:19 ` KAMEZAWA Hiroyuki
[not found] ` <49AC84BE.5020501-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-03-03 1:19 ` KAMEZAWA Hiroyuki
[not found] ` <20090303100827.43d82c3a.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-03-03 1:15 ` Li Zefan
-- strict thread matches above, loose matches on Subject: below --
2009-03-02 2:13 Li Zefan
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=49AC8307.7090008@cn.fujitsu.com \
--to=lizf-bthxqxjhjhxqfuhtdcdx3a@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=menage-hpIqsD4AKlfQT0dZR+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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.