summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-26 23:06:18 +0530
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-26 23:06:18 +0530
commit305fdb705e4eca50f3dc18d7cc685b547ce0ee98 (patch)
tree492943020ca7fd7d7756aaab80434571785e8eca
parent3c60aa98093e94985fb3fe43c03bb91a5e6b45c6 (diff)
downloadlibcg-305fdb705e4eca50f3dc18d7cc685b547ce0ee98.tar.gz
libcg-305fdb705e4eca50f3dc18d7cc685b547ce0ee98.tar.xz
libcg-305fdb705e4eca50f3dc18d7cc685b547ce0ee98.zip
libcgroup: Introduce an API to get the mount point of a specific subsystem
Introduce an API which will query the mount table and return the mount point of a specific subsystem. This is needed in the case when the user knows which subsystem he wants the details of, which would make the use of the get_controller* APIs cumbersome. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
-rw-r--r--include/libcgroup.h9
-rw-r--r--src/api.c28
-rw-r--r--src/libcgroup.map1
-rw-r--r--tests/Makefile.am3
4 files changed, 40 insertions, 1 deletions
diff --git a/include/libcgroup.h b/include/libcgroup.h
index ce0d8a5..9bc74d6 100644
--- a/include/libcgroup.h
+++ b/include/libcgroup.h
@@ -324,6 +324,15 @@ int cgroup_get_controller_begin(void **handle, struct cgroup_mount_point *info);
*/
int cgroup_get_controller_next(void **handle, struct cgroup_mount_point *info);
int cgroup_get_controller_end(void **handle);
+
+/*
+ * Reads the mount to table to give the mount point of a controller
+ * @controller: Name of the controller
+ * @mount_point: The string where the mount point is stored. Please note,
+ * the caller must free mount_point.
+ */
+int cgroup_get_subsys_mount_point(char *controller, char **mount_point);
+
/* The wrappers for filling libcg structures */
struct cgroup *cgroup_new_cgroup(const char *name);
diff --git a/src/api.c b/src/api.c
index 76ba833..03d7520 100644
--- a/src/api.c
+++ b/src/api.c
@@ -2668,3 +2668,31 @@ int cgroup_get_uid_gid_from_procfs(pid_t pid, uid_t *euid, gid_t *egid)
return 0;
}
+int cgroup_get_subsys_mount_point(char *controller, char **mount_point)
+{
+ int i;
+ int ret = ECGROUPNOTEXIST;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ pthread_rwlock_rdlock(&cg_mount_table_lock);
+ for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {
+ if (strncmp(cg_mount_table[i].name, controller, FILENAME_MAX))
+ continue;
+
+ *mount_point = strdup(cg_mount_table[i].path);
+
+ if (!*mount_point) {
+ last_errno = errno;
+ ret = ECGOTHER;
+ goto out_exit;
+ }
+
+ ret = 0;
+ break;
+ }
+out_exit:
+ pthread_rwlock_unlock(&cg_mount_table_lock);
+ return ret;
+}
diff --git a/src/libcgroup.map b/src/libcgroup.map
index 5b088d4..5359892 100644
--- a/src/libcgroup.map
+++ b/src/libcgroup.map
@@ -69,4 +69,5 @@ global:
cgroup_unload_cgroups;
cgroup_get_controller;
cgroup_get_uid_gid_from_procfs;
+ cgroup_get_subsys_mount_point;
} CGROUP_0.33;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e8401f2..b10f356 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/include
LDADD = $(top_srcdir)/src/.libs/libcgroup.la
# compile the tests, but do not install them
-noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller
+noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point
libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h
libcg_ba_SOURCES=libcg_ba.cpp
@@ -12,6 +12,7 @@ walk_test_SOURCES=walk_test.c
read_stats_SOURCES=read_stats.c
walk_task_SOURCES=walk_task.c
get_controller_SOURCES=get_controller.c
+get_mount_point_SOURCES=get_mount_point.c
EXTRA_DIST = pathtest.sh runlibcgrouptest.sh