This API does two things, 1. Reads a controller structure to see if a value exists. If it does, then it returns it. 2. If the value does not exist, then it reads the filesystem to get that value, and then return it.
Inspiration: A short discussion with Glauber Costa, led to an understanding that this API would make life much easier for him. The problem with cgroup_get_cgroup is that it is too heavy handed, and gets you everything. Now something like, cgroup_get_cgroup() Modify what you want to in that cgroup cgroup_modify_cgroup() will try to write to stuff that is not needed, and might lead to weird failures because cgroups interface is not consistent. Therefore, leaving control entirely in the hands of the programmer is what is more useful and so we do that, and modify just what is needed. The smarter way of using this, when we have multiple values to be read is to just do a cgroup_get_cgroup and get those values separately. Signed-off-by: Dhaval Giani <dhaval.gi...@gmail.com> Cc: Glauber Costa <glom...@parallels.com> diff --git a/src/api.c b/src/api.c index f050df7..79e922a 100644 --- a/src/api.c +++ b/src/api.c @@ -4228,4 +4228,60 @@ int cgroup_get_subsys_mount_point_end(void **handle) return 0; } +/* + * Simple experiment for glommer's usecase + * User must free value + */ +int cgroup_get_cgroup_value(struct cgroup_controller *cgc, char *file_name, char **value) +{ + struct cgroup *cgroup; + char *cnt_name = cgc->name; + struct cgroup_controller *cg = NULL; + int i = 0; + int ret = 0; + + if (!cgroup_initialized) { + ret = ECGROUPNOTINITIALIZED; + goto free_nothing; + } + + if (!cgc) { + ret = ECGINVAL; + goto free_nothing; + } + + if (!file_name) { + ret = ECGINVAL; + goto free_nothing; + } + /* + * check if we actually do have something in it already. + */ + + ret = cgroup_get_value_string(cgc, file_name, value); + + if (!ret) + goto free_nothing; + + /* + * Let's fill it up from the filesystem + */ + ret = 0; + + cgroup = cgroup_new_cgroup(cgc->cgroup->name); + cgroup_get_cgroup(cgroup); + + cg = cgroup_get_controller(cgroup, cnt_name); + if (!cg) { + ret = ECGROUPNOTEXIST; + goto free_cgroup; + } + + ret = cgroup_get_value_string(cg, file_name, value); +free_cgroups: + cgroup_free(&cgroup); +free_nothing: + return ret; + +} ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel