From: "Serge E. Hallyn" <serue@us.ibm.com>
To: menage@google.com
Cc: pj@sgi.com, xemul@openvz.org, balbir@in.ibm.com,
serue@us.ibm.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org,
containers@lists.linux-foundation.org
Subject: Re: [PATCH 2/8] CGroup Files: Add write_string cgroup control file method
Date: Tue, 24 Jun 2008 10:34:34 -0500 [thread overview]
Message-ID: <20080624153434.GA4993@us.ibm.com> (raw)
In-Reply-To: <20080621000730.052131000@menage.corp.google.com>
Quoting menage@google.com (menage@google.com):
> This patch adds a write_string() method for cgroups control files. The
> semantics are that a buffer is copied from userspace to kernelspace
> and the handler function invoked on that buffer. The buffer is
> guaranteed to be nul-terminated, and no longer than max_write_len
> (defaulting to 64 bytes if unspecified). Later patches will convert
> existing raw file write handlers in control group subsystems to use
> this method.
>
> Signed-off-by: Paul Menage <menage@google.com>
Looks sane to me.
Acked-by: Serge Hallyn <serue@us.ibm.com>
thanks,
-serge
>
> ---
> include/linux/cgroup.h | 14 ++++++++++++++
> kernel/cgroup.c | 35 +++++++++++++++++++++++++++++++++++
> 2 files changed, 49 insertions(+)
>
> Index: cws-2.6.26-rc5-mm3/include/linux/cgroup.h
> ===================================================================
> --- cws-2.6.26-rc5-mm3.orig/include/linux/cgroup.h
> +++ cws-2.6.26-rc5-mm3/include/linux/cgroup.h
> @@ -205,6 +205,13 @@ struct cftype {
> * subsystem, followed by a period */
> char name[MAX_CFTYPE_NAME];
> int private;
> +
> + /*
> + * If non-zero, defines the maximum length of string that can
> + * be passed to write_string; defaults to 64
> + */
> + size_t max_write_len;
> +
> int (*open)(struct inode *inode, struct file *file);
> ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
> struct file *file,
> @@ -249,6 +256,13 @@ struct cftype {
> int (*write_s64)(struct cgroup *cgrp, struct cftype *cft, s64 val);
>
> /*
> + * write_string() is passed a nul-terminated kernelspace
> + * buffer of maximum length determined by max_write_len.
> + * Returns 0 or -ve error code.
> + */
> + int (*write_string)(struct cgroup *cgrp, struct cftype *cft,
> + const char *buffer);
> + /*
> * trigger() callback can be used to get some kick from the
> * userspace, when the actual string written is not important
> * at all. The private field can be used to determine the
> Index: cws-2.6.26-rc5-mm3/kernel/cgroup.c
> ===================================================================
> --- cws-2.6.26-rc5-mm3.orig/kernel/cgroup.c
> +++ cws-2.6.26-rc5-mm3/kernel/cgroup.c
> @@ -1363,6 +1363,39 @@ static ssize_t cgroup_write_X64(struct c
> return retval;
> }
>
> +static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft,
> + struct file *file,
> + const char __user *userbuf,
> + size_t nbytes, loff_t *unused_ppos)
> +{
> + char local_buffer[64];
> + int retval = 0;
> + size_t max_bytes = cft->max_write_len;
> + char *buffer = local_buffer;
> +
> + if (!max_bytes)
> + max_bytes = sizeof(local_buffer) - 1;
> + if (nbytes >= max_bytes)
> + return -E2BIG;
> + /* Allocate a dynamic buffer if we need one */
> + if (nbytes >= sizeof(local_buffer)) {
> + buffer = kmalloc(nbytes + 1, GFP_KERNEL);
> + if (buffer == NULL)
> + return -ENOMEM;
> + }
> + if (nbytes && copy_from_user(buffer, userbuf, nbytes))
> + return -EFAULT;
> +
> + buffer[nbytes] = 0; /* nul-terminate */
> + strstrip(buffer);
> + retval = cft->write_string(cgrp, cft, buffer);
> + if (!retval)
> + retval = nbytes;
> + if (buffer != local_buffer)
> + kfree(buffer);
> + return retval;
> +}
> +
> static ssize_t cgroup_common_file_write(struct cgroup *cgrp,
> struct cftype *cft,
> struct file *file,
> @@ -1440,6 +1473,8 @@ static ssize_t cgroup_file_write(struct
> return cft->write(cgrp, cft, file, buf, nbytes, ppos);
> if (cft->write_u64 || cft->write_s64)
> return cgroup_write_X64(cgrp, cft, file, buf, nbytes, ppos);
> + if (cft->write_string)
> + return cgroup_write_string(cgrp, cft, file, buf, nbytes, ppos);
> if (cft->trigger) {
> int ret = cft->trigger(cgrp, (unsigned int)cft->private);
> return ret ? ret : nbytes;
>
> --
next prev parent reply other threads:[~2008-06-24 15:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-20 23:43 [PATCH 0/8] CGroup Files: Add write_string control file method menage
2008-06-20 23:43 ` [PATCH 1/8] CGroup Files: Clean up whitespace in struct cftype menage
2008-06-20 23:43 ` menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` [PATCH 2/8] CGroup Files: Add write_string cgroup control file method menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` menage
2008-06-22 14:32 ` Balbir Singh
[not found] ` <20080622143236.GA19380-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2008-06-24 14:27 ` Paul Menage
2008-06-24 14:27 ` Paul Menage
[not found] ` <20080621000730.052131000-B63HFAS8fGlSzHKm+aFRNNkmqwFzkYv6@public.gmane.org>
2008-06-22 14:32 ` Balbir Singh
2008-06-24 15:34 ` Serge E. Hallyn
2008-06-24 23:19 ` Andrew Morton
2008-06-24 15:34 ` Serge E. Hallyn [this message]
2008-06-24 23:19 ` Andrew Morton
[not found] ` <20080624161923.449ecea4.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-06-24 23:26 ` Paul Menage
2008-06-24 23:26 ` Paul Menage
2008-06-20 23:44 ` [PATCH 3/8] CGroup Files: Move the release_agent file to use typed handlers menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` menage
[not found] ` <20080621000730.255258000-B63HFAS8fGlSzHKm+aFRNNkmqwFzkYv6@public.gmane.org>
2008-06-24 15:56 ` Serge E. Hallyn
2008-06-24 23:23 ` Andrew Morton
2008-06-24 23:23 ` Andrew Morton
[not found] ` <20080624162325.005c87e0.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-06-24 23:30 ` Paul Menage
2008-06-24 23:30 ` Paul Menage
2008-06-24 15:56 ` Serge E. Hallyn
2008-06-20 23:44 ` [PATCH 4/8] CGroup Files: Move notify_on_release file to separate write handler menage
2008-06-20 23:44 ` menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` [PATCH 5/8] CGroup Files: Turn attach_task_by_pid directly into a cgroup " menage
2008-06-20 23:44 ` menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` [PATCH 6/8] CGroup Files: Remove cpuset_common_file_write() menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` menage
2008-06-20 23:44 ` [PATCH 7/8] CGroup Files: Convert devcgroup_access_write() into a cgroup write_string() handler menage
[not found] ` <20080621000731.082343000-B63HFAS8fGlSzHKm+aFRNNkmqwFzkYv6@public.gmane.org>
2008-06-24 16:21 ` Serge E. Hallyn
2008-06-24 16:21 ` Serge E. Hallyn
2008-06-20 23:44 ` menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` [PATCH 8/8] CGroup Files: Convert res_counter_write() to be a cgroups " menage-hpIqsD4AKlfQT0dZR+AlfA
2008-06-20 23:44 ` menage
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=20080624153434.GA4993@us.ibm.com \
--to=serue@us.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@in.ibm.com \
--cc=containers@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=menage@google.com \
--cc=pj@sgi.com \
--cc=xemul@openvz.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.