hugetlb_cgroup: convert away from cftype->read()
authorTejun Heo <tj@kernel.org>
Thu, 5 Dec 2013 17:28:03 +0000 (12:28 -0500)
committerTejun Heo <tj@kernel.org>
Thu, 5 Dec 2013 17:28:03 +0000 (12:28 -0500)
In preparation of conversion to kernfs, cgroup file handling is being
consolidated so that it can be easily mapped to the seq_file based
interface of kernfs.

All users of cftype->read() can be easily served, usually better, by
seq_file and other methods.  Update hugetlb_cgroup_read() to return
u64 instead of printing itself and rename it to
hugetlb_cgroup_read_u64().

This patch doesn't make any visible behavior changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Acked-by: Li Zefan <lizefan@huawei.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
mm/hugetlb_cgroup.c

index bda8e44f6fdee72c31d805aa5ae4164a0e01a952..d747a84e09b088e4e585a56089ce7e6c6302a3a5 100644 (file)
@@ -242,22 +242,16 @@ void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
        return;
 }
 
-static ssize_t hugetlb_cgroup_read(struct cgroup_subsys_state *css,
-                                  struct cftype *cft, struct file *file,
-                                  char __user *buf, size_t nbytes,
-                                  loff_t *ppos)
+static u64 hugetlb_cgroup_read_u64(struct cgroup_subsys_state *css,
+                                  struct cftype *cft)
 {
-       u64 val;
-       char str[64];
-       int idx, name, len;
+       int idx, name;
        struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(css);
 
        idx = MEMFILE_IDX(cft->private);
        name = MEMFILE_ATTR(cft->private);
 
-       val = res_counter_read_u64(&h_cg->hugepage[idx], name);
-       len = scnprintf(str, sizeof(str), "%llu\n", (unsigned long long)val);
-       return simple_read_from_buffer(buf, nbytes, ppos, str, len);
+       return res_counter_read_u64(&h_cg->hugepage[idx], name);
 }
 
 static int hugetlb_cgroup_write(struct cgroup_subsys_state *css,
@@ -337,28 +331,28 @@ static void __init __hugetlb_cgroup_file_init(int idx)
        cft = &h->cgroup_files[0];
        snprintf(cft->name, MAX_CFTYPE_NAME, "%s.limit_in_bytes", buf);
        cft->private = MEMFILE_PRIVATE(idx, RES_LIMIT);
-       cft->read = hugetlb_cgroup_read;
+       cft->read_u64 = hugetlb_cgroup_read_u64;
        cft->write_string = hugetlb_cgroup_write;
 
        /* Add the usage file */
        cft = &h->cgroup_files[1];
        snprintf(cft->name, MAX_CFTYPE_NAME, "%s.usage_in_bytes", buf);
        cft->private = MEMFILE_PRIVATE(idx, RES_USAGE);
-       cft->read = hugetlb_cgroup_read;
+       cft->read_u64 = hugetlb_cgroup_read_u64;
 
        /* Add the MAX usage file */
        cft = &h->cgroup_files[2];
        snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max_usage_in_bytes", buf);
        cft->private = MEMFILE_PRIVATE(idx, RES_MAX_USAGE);
        cft->trigger = hugetlb_cgroup_reset;
-       cft->read = hugetlb_cgroup_read;
+       cft->read_u64 = hugetlb_cgroup_read_u64;
 
        /* Add the failcntfile */
        cft = &h->cgroup_files[3];
        snprintf(cft->name, MAX_CFTYPE_NAME, "%s.failcnt", buf);
        cft->private  = MEMFILE_PRIVATE(idx, RES_FAILCNT);
        cft->trigger  = hugetlb_cgroup_reset;
-       cft->read = hugetlb_cgroup_read;
+       cft->read_u64 = hugetlb_cgroup_read_u64;
 
        /* NULL terminate the last cft */
        cft = &h->cgroup_files[4];