From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org
Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 06/13] cgroup: update cgroup name handling
Date: Sat, 8 Feb 2014 11:15:20 -0500 [thread overview]
Message-ID: <1391876127-7134-7-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1391876127-7134-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Straightforward updates to cgroup name handling in preparation of
kernfs conversion.
* cgroup_alloc_name() is updated to take const char * isntead of
dentry * for name source.
* cgroup name formatting is separated out into cgroup_file_name().
While at it, buffer length protection is added.
Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
kernel/cgroup.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 8a9548c..3cef4a3 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -67,6 +67,9 @@
*/
#define CGROUP_PIDLIST_DESTROY_DELAY HZ
+#define CGROUP_FILE_NAME_MAX (MAX_CGROUP_TYPE_NAMELEN + \
+ MAX_CFTYPE_NAME + 2)
+
/*
* cgroup_tree_mutex nests above cgroup_mutex and protects cftypes, file
* creation/removal and hierarchy changing operations including cgroup
@@ -799,17 +802,29 @@ static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
return inode;
}
-static struct cgroup_name *cgroup_alloc_name(struct dentry *dentry)
+static struct cgroup_name *cgroup_alloc_name(const char *name_str)
{
struct cgroup_name *name;
- name = kmalloc(sizeof(*name) + dentry->d_name.len + 1, GFP_KERNEL);
+ name = kmalloc(sizeof(*name) + strlen(name_str) + 1, GFP_KERNEL);
if (!name)
return NULL;
- strcpy(name->name, dentry->d_name.name);
+ strcpy(name->name, name_str);
return name;
}
+static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft,
+ char *buf)
+{
+ if (cft->ss && !(cft->flags & CFTYPE_NO_PREFIX) &&
+ !(cgrp->root->flags & CGRP_ROOT_NOPREFIX))
+ snprintf(buf, CGROUP_FILE_NAME_MAX, "%s.%s",
+ cft->ss->name, cft->name);
+ else
+ strncpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
+ return buf;
+}
+
static void cgroup_free_fn(struct work_struct *work)
{
struct cgroup *cgrp = container_of(work, struct cgroup, destroy_work);
@@ -2435,7 +2450,7 @@ static int cgroup_rename(struct inode *old_dir, struct dentry *old_dentry,
if (cgroup_sane_behavior(cgrp))
return -EPERM;
- name = cgroup_alloc_name(new_dentry);
+ name = cgroup_alloc_name(new_dentry->d_name.name);
if (!name)
return -ENOMEM;
@@ -2611,14 +2626,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft)
struct cfent *cfe;
int error;
umode_t mode;
- char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 };
-
- if (cft->ss && !(cft->flags & CFTYPE_NO_PREFIX) &&
- !(cgrp->root->flags & CGRP_ROOT_NOPREFIX)) {
- strcpy(name, cft->ss->name);
- strcat(name, ".");
- }
- strcat(name, cft->name);
+ char name[CGROUP_FILE_NAME_MAX];
BUG_ON(!mutex_is_locked(&dir->d_inode->i_mutex));
@@ -2626,6 +2634,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft)
if (!cfe)
return -ENOMEM;
+ cgroup_file_name(cgrp, cft, name);
dentry = lookup_one_len(name, dir, strlen(name));
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
@@ -4133,7 +4142,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
if (!cgrp)
return -ENOMEM;
- name = cgroup_alloc_name(dentry);
+ name = cgroup_alloc_name(dentry->d_name.name);
if (!name) {
err = -ENOMEM;
goto err_free_cgrp;
--
1.8.5.3
next prev parent reply other threads:[~2014-02-08 16:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-08 16:15 [PATCHSET v2 cgroup/for-3.15] cgroup: convert to kernfs Tejun Heo
[not found] ` <1391876127-7134-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-08 16:15 ` [PATCH 01/13] cgroup: improve css_from_dir() into css_tryget_from_dir() Tejun Heo
2014-02-08 16:15 ` [PATCH 02/13] cgroup: introduce cgroup_tree_mutex Tejun Heo
2014-02-08 16:15 ` [PATCH 03/13] cgroup: release cgroup_mutex over file removals Tejun Heo
2014-02-08 16:15 ` [PATCH 04/13] cgroup: restructure locking and error handling in cgroup_mount() Tejun Heo
2014-02-08 16:15 ` [PATCH 05/13] cgroup: factor out cgroup_setup_root() from cgroup_mount() Tejun Heo
2014-02-08 16:15 ` Tejun Heo [this message]
2014-02-08 16:15 ` [PATCH 09/13] cgroup: introduce cgroup_init/exit_cftypes() Tejun Heo
2014-02-08 16:15 ` [PATCH 10/13] cgroup: introduce cgroup_ino() Tejun Heo
2014-02-08 16:15 ` [PATCH 11/13] cgroup: misc preps for kernfs conversion Tejun Heo
2014-02-08 16:15 ` [PATCH 13/13] cgroup: convert to kernfs Tejun Heo
2014-02-08 16:15 ` [PATCH 07/13] cgroup: make cgroup_subsys->base_cftypes use cgroup_add_cftypes() Tejun Heo
2014-02-08 16:15 ` [PATCH 08/13] cgroup: update the meaning of cftype->max_write_len Tejun Heo
2014-02-08 16:15 ` [PATCH 12/13] cgroup: relocate functions in preparation of kernfs conversion Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2014-01-28 23:54 [PATCHSET cgroup/for-3.15] cgroup: convert to kernfs Tejun Heo
[not found] ` <1390953285-16360-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-01-28 23:54 ` [PATCH 06/13] cgroup: update cgroup name handling 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=1391876127-7134-7-git-send-email-tj@kernel.org \
--to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lizefan-hv44wF8Li93QT0dZR+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).