summaryrefslogtreecommitdiffstats
path: root/src/api.c
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-18 19:42:48 +0530
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-18 19:49:40 +0530
commit3ee2b056852a65bc7a3128ef924f1ae83573016e (patch)
tree04841d70bdd5722f8fd88e0c7a0b42db5002b65b /src/api.c
parent80e9084d3e7be7fbec1ed72f90b88c7626fb93d1 (diff)
downloadlibcg-3ee2b056852a65bc7a3128ef924f1ae83573016e.tar.gz
libcg-3ee2b056852a65bc7a3128ef924f1ae83573016e.tar.xz
libcg-3ee2b056852a65bc7a3128ef924f1ae83573016e.zip
libcgroup: Introduce get_controller API
This set of APIs will allow the caller to query the mount table and find out what controller is mounted at what path. Test program has been included in the patch. Running the test program results in [dhaval@gondor tests]$ ../libtool --mode=execute ./get_controller Controller cpu is mounted at /cgroup Controller cpuacct is mounted at /cgroup Controller memory is mounted at /cgroup1 [dhaval@gondor tests]$ Which is the setup on this system. Changes from v2 1. Remove the incorrect comments as pointed out by Bharata Changes from v1 1. Use a new structure as mentioned by bharata to return the values. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Cc: Jan Safranek <jsafrane@redhat.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Diffstat (limited to 'src/api.c')
-rw-r--r--src/api.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/api.c b/src/api.c
index ab35ed7..63813a3 100644
--- a/src/api.c
+++ b/src/api.c
@@ -2541,6 +2541,80 @@ int cgroup_get_task_begin(char *cgroup, char *controller, void **handle,
return ret;
}
+
+int cgroup_get_controller_end(void **handle)
+{
+ int *pos = (int *) *handle;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!pos)
+ return ECGINVAL;
+
+ free(pos);
+ *handle = NULL;
+
+ return 0;
+}
+
+int cgroup_get_controller_next(void **handle, struct cgroup_mount_point *info)
+{
+ int *pos = (int *) *handle;
+ int ret = 0;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!pos)
+ return ECGINVAL;
+
+ if (!info)
+ return ECGINVAL;
+
+ pthread_rwlock_rdlock(&cg_mount_table_lock);
+
+ if (cg_mount_table[*pos].name[0] == '\0') {
+ ret = ECGEOF;
+ goto out_unlock;
+ }
+
+ strncpy(info->name, cg_mount_table[*pos].name, FILENAME_MAX);
+
+ strncpy(info->path, cg_mount_table[*pos].path, FILENAME_MAX);
+
+ (*pos)++;
+ *handle = pos;
+
+out_unlock:
+ pthread_rwlock_unlock(&cg_mount_table_lock);
+ return ret;
+}
+
+int cgroup_get_controller_begin(void **handle, struct cgroup_mount_point *info)
+{
+ int *pos;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!info)
+ return ECGINVAL;
+
+ pos = malloc(sizeof(int));
+
+ if (!pos) {
+ last_errno = errno;
+ return ECGOTHER;
+ }
+
+ *pos = 0;
+
+ *handle = pos;
+
+ return cgroup_get_controller_next(handle, info);
+}
+
/**
* Get process data (euid and egid) from /proc/<pid>/status file.
* @param pid: The process id