aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Menage <menage@google.com>2008-07-25 04:47:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:35 -0400
commit84eea842886ac35020be6043e04748ed22014359 (patch)
treeacd2bb7c3bc267a032b5e637c598708f38c68cb3
parente788e066c651b1bbf4a927dc95395c1aa13be436 (diff)
cgroups: misc cleanups to write_string patchset
This patch contains cleanups suggested by reviewers for the recent write_string() patchset: - pair cgroup_lock_live_group() with cgroup_unlock() in cgroup.c for clarity, rather than directly unlocking cgroup_mutex. - make the return type of cgroup_lock_live_group() a bool - use a #define'd constant for the local buffer size in read/write functions Signed-off-by: Paul Menage <menage@google.com> Cc: Paul Jackson <pj@sgi.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Balbir Singh <balbir@in.ibm.com> Acked-by: Serge Hallyn <serue@us.ibm.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/cgroup.h4
-rw-r--r--kernel/cgroup.c21
2 files changed, 14 insertions, 11 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index e78377a91a74..cc59d3a21d87 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -21,11 +21,13 @@
21struct cgroupfs_root; 21struct cgroupfs_root;
22struct cgroup_subsys; 22struct cgroup_subsys;
23struct inode; 23struct inode;
24struct cgroup;
24 25
25extern int cgroup_init_early(void); 26extern int cgroup_init_early(void);
26extern int cgroup_init(void); 27extern int cgroup_init(void);
27extern void cgroup_init_smp(void); 28extern void cgroup_init_smp(void);
28extern void cgroup_lock(void); 29extern void cgroup_lock(void);
30extern bool cgroup_lock_live_group(struct cgroup *cgrp);
29extern void cgroup_unlock(void); 31extern void cgroup_unlock(void);
30extern void cgroup_fork(struct task_struct *p); 32extern void cgroup_fork(struct task_struct *p);
31extern void cgroup_fork_callbacks(struct task_struct *p); 33extern void cgroup_fork_callbacks(struct task_struct *p);
@@ -295,8 +297,6 @@ int cgroup_add_files(struct cgroup *cgrp,
295 297
296int cgroup_is_removed(const struct cgroup *cgrp); 298int cgroup_is_removed(const struct cgroup *cgrp);
297 299
298int cgroup_lock_live_group(struct cgroup *cgrp);
299
300int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); 300int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
301 301
302int cgroup_task_count(const struct cgroup *cgrp); 302int cgroup_task_count(const struct cgroup *cgrp);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0120b5d67a73..a14122ecaa5e 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1329,10 +1329,10 @@ enum cgroup_filetype {
1329 * cgroup_lock_live_group - take cgroup_mutex and check that cgrp is alive. 1329 * cgroup_lock_live_group - take cgroup_mutex and check that cgrp is alive.
1330 * @cgrp: the cgroup to be checked for liveness 1330 * @cgrp: the cgroup to be checked for liveness
1331 * 1331 *
1332 * Returns true (with lock held) on success, or false (with no lock 1332 * On success, returns true; the lock should be later released with
1333 * held) on failure. 1333 * cgroup_unlock(). On failure returns false with no lock held.
1334 */ 1334 */
1335int cgroup_lock_live_group(struct cgroup *cgrp) 1335bool cgroup_lock_live_group(struct cgroup *cgrp)
1336{ 1336{
1337 mutex_lock(&cgroup_mutex); 1337 mutex_lock(&cgroup_mutex);
1338 if (cgroup_is_removed(cgrp)) { 1338 if (cgroup_is_removed(cgrp)) {
@@ -1349,7 +1349,7 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
1349 if (!cgroup_lock_live_group(cgrp)) 1349 if (!cgroup_lock_live_group(cgrp))
1350 return -ENODEV; 1350 return -ENODEV;
1351 strcpy(cgrp->root->release_agent_path, buffer); 1351 strcpy(cgrp->root->release_agent_path, buffer);
1352 mutex_unlock(&cgroup_mutex); 1352 cgroup_unlock();
1353 return 0; 1353 return 0;
1354} 1354}
1355 1355
@@ -1360,16 +1360,19 @@ static int cgroup_release_agent_show(struct cgroup *cgrp, struct cftype *cft,
1360 return -ENODEV; 1360 return -ENODEV;
1361 seq_puts(seq, cgrp->root->release_agent_path); 1361 seq_puts(seq, cgrp->root->release_agent_path);
1362 seq_putc(seq, '\n'); 1362 seq_putc(seq, '\n');
1363 mutex_unlock(&cgroup_mutex); 1363 cgroup_unlock();
1364 return 0; 1364 return 0;
1365} 1365}
1366 1366
1367/* A buffer size big enough for numbers or short strings */
1368#define CGROUP_LOCAL_BUFFER_SIZE 64
1369
1367static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft, 1370static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft,
1368 struct file *file, 1371 struct file *file,
1369 const char __user *userbuf, 1372 const char __user *userbuf,
1370 size_t nbytes, loff_t *unused_ppos) 1373 size_t nbytes, loff_t *unused_ppos)
1371{ 1374{
1372 char buffer[64]; 1375 char buffer[CGROUP_LOCAL_BUFFER_SIZE];
1373 int retval = 0; 1376 int retval = 0;
1374 char *end; 1377 char *end;
1375 1378
@@ -1403,7 +1406,7 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft,
1403 const char __user *userbuf, 1406 const char __user *userbuf,
1404 size_t nbytes, loff_t *unused_ppos) 1407 size_t nbytes, loff_t *unused_ppos)
1405{ 1408{
1406 char local_buffer[64]; 1409 char local_buffer[CGROUP_LOCAL_BUFFER_SIZE];
1407 int retval = 0; 1410 int retval = 0;
1408 size_t max_bytes = cft->max_write_len; 1411 size_t max_bytes = cft->max_write_len;
1409 char *buffer = local_buffer; 1412 char *buffer = local_buffer;
@@ -1518,7 +1521,7 @@ static ssize_t cgroup_read_u64(struct cgroup *cgrp, struct cftype *cft,
1518 char __user *buf, size_t nbytes, 1521 char __user *buf, size_t nbytes,
1519 loff_t *ppos) 1522 loff_t *ppos)
1520{ 1523{
1521 char tmp[64]; 1524 char tmp[CGROUP_LOCAL_BUFFER_SIZE];
1522 u64 val = cft->read_u64(cgrp, cft); 1525 u64 val = cft->read_u64(cgrp, cft);
1523 int len = sprintf(tmp, "%llu\n", (unsigned long long) val); 1526 int len = sprintf(tmp, "%llu\n", (unsigned long long) val);
1524 1527
@@ -1530,7 +1533,7 @@ static ssize_t cgroup_read_s64(struct cgroup *cgrp, struct cftype *cft,
1530 char __user *buf, size_t nbytes, 1533 char __user *buf, size_t nbytes,
1531 loff_t *ppos) 1534 loff_t *ppos)
1532{ 1535{
1533 char tmp[64]; 1536 char tmp[CGROUP_LOCAL_BUFFER_SIZE];
1534 s64 val = cft->read_s64(cgrp, cft); 1537 s64 val = cft->read_s64(cgrp, cft);
1535 int len = sprintf(tmp, "%lld\n", (long long) val); 1538 int len = sprintf(tmp, "%lld\n", (long long) val);
1536 1539