]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Introduce an API to get the mount point of a specific subsystem
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 26 Jun 2009 17:36:18 +0000 (23:06 +0530)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 26 Jun 2009 17:36:18 +0000 (23:06 +0530)
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>
include/libcgroup.h
src/api.c
src/libcgroup.map
tests/Makefile.am

index ce0d8a5b41cd05c9a545d5d70ecb1d279996054d..9bc74d64ca0f0d32a7878f3fadb0f7a60b014a1d 100644 (file)
@@ -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);
index 76ba833f7c920d476b7e3a37b886cea23ab4c902..03d7520bdbc6e29ca579943a30ed2b6f382f8ce3 100644 (file)
--- 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;
+}
index 5b088d4b42469cc1c0e78a45e707584f0112a635..5359892856fe6433604e301c0444c546386fba5f 100644 (file)
@@ -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;
index e8401f22ce0844d37dac41d5142678a100be991c..b10f3562fe1289c6b9c5dae40c2d08c499da2675 100644 (file)
@@ -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