From e4f9ba367252bfb521878133124c51711ce687e7 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Wed, 6 Apr 2011 08:37:11 +0200 Subject: [PATCH] Added iterators to go through all mount points of a hierarchy. Add new iterators, which return all mount points of given hierarchy. The order of the mount points is the same as in /proc/mounts, The first returned mount point is the same as cgroup_get_subsys_mount_point(). Signed-off-by: Jan Safranek Acked-by: Ivana Hutarova Varekova --- include/libcgroup/init.h | 3 ++ include/libcgroup/iterators.h | 34 ++++++++++++++++++++ src/api.c | 59 +++++++++++++++++++++++++++++++++++ src/libcgroup.map | 7 +++++ 4 files changed, 103 insertions(+) diff --git a/include/libcgroup/init.h b/include/libcgroup/init.h index 881b8302..37090965 100644 --- a/include/libcgroup/init.h +++ b/include/libcgroup/init.h @@ -41,6 +41,9 @@ int cgroup_init(void); /** * Returns path where is mounted given controller. Applications should rely on * @c libcgroup API and not call this function directly. + * Only the first mount point is returned, use + * cgroup_get_subsys_mount_point_begin(), cgroup_get_subsys_mount_point_next() + * and cgroup_get_subsys_mount_point_end() to get all of them. * @param controller Name of the controller * @param mount_point The string where the mount point location is stored. * Please note, the caller must free the mount_point. diff --git a/include/libcgroup/iterators.h b/include/libcgroup/iterators.h index 8ecc53f5..c6d453d6 100644 --- a/include/libcgroup/iterators.h +++ b/include/libcgroup/iterators.h @@ -385,10 +385,44 @@ int cgroup_get_all_controller_next(void **handle, struct controller_data *info); */ int cgroup_get_all_controller_end(void **handle); +/** + * @} + * + * @name List all mount points of a controller. + * Use following functions to list all mount points of a hierarchy with given + * controller. + */ + +/** + * Read the first mount point of the hierarchy with given controller. + * The first is the same as the mount point returned by + * cgroup_get_subsys_mount_point(). + * @param handle Handle to be used for iteration. + * @param controller Controller name. + * @param path Buffer to fill the path into. The buffer must be at least + * FILENAME_MAX characters long. + */ +int cgroup_get_subsys_mount_point_begin(const char *controller, void **handle, + char *path); +/** + * Read next mount point of the hierarchy with given controller. + * @param handle Handle to be used for iteration. + * @param path Buffer to fill the path into. The buffer must be at least + * FILENAME_MAX characters long. + */ +int cgroup_get_subsys_mount_point_next(void **handle, + char *path); + +/** + * Release the iterator. + */ +int cgroup_get_subsys_mount_point_end(void **handle); + /** * @} * @} */ + __END_DECLS #endif /* _LIBCGROUP_ITERATORS_H */ diff --git a/src/api.c b/src/api.c index 0dc135ab..dfc70a49 100644 --- a/src/api.c +++ b/src/api.c @@ -3922,3 +3922,62 @@ void cgroup_dictionary_iterator_end(void **handle) *handle = NULL; } +int cgroup_get_subsys_mount_point_begin(const char *controller, void **handle, + char *path) +{ + int i; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + if (!handle || !path || !controller) + return ECGINVAL; + + + for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) + if (strcmp(controller, cg_mount_table[i].name) == 0) + break; + + if (cg_mount_table[i].name[0] == '\0') { + /* the controller is not mounted at all */ + *handle = NULL; + *path = '\0'; + return ECGEOF; + } + + /* + * 'handle' is pointer to struct cg_mount_point, which should be + * returned next. + */ + *handle = cg_mount_table[i].mount.next; + strcpy(path, cg_mount_table[i].mount.path); + return 0; +} + +int cgroup_get_subsys_mount_point_next(void **handle, + char *path) +{ + struct cg_mount_point *it; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + if (!handle || !path) + return ECGINVAL; + + it = *handle; + if (!it) { + *handle = NULL; + *path = '\0'; + return ECGEOF; + } + + *handle = it->next; + strcpy(path, it->path); + return 0; +} + +int cgroup_get_subsys_mount_point_end(void **handle) +{ + return 0; +} + + diff --git a/src/libcgroup.map b/src/libcgroup.map index 2a3439f3..fb30801d 100644 --- a/src/libcgroup.map +++ b/src/libcgroup.map @@ -96,3 +96,10 @@ CGROUP_0.37 { cgroup_read_value_end; cg_chmod_recursive; } CGROUP_0.36; + +CGROUP_0.38 { + cgroup_get_subsys_mount_point_begin; + cgroup_get_subsys_mount_point_next; + cgroup_get_subsys_mount_point_end; +} CGROUP_0.37; + -- 2.47.2