On 04/06/2011 10:37 AM, Jan Safranek wrote:
> 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<[email protected]>
Acked-by: Ivana Hutarova Varekova<[email protected]>
> ---
>
> include/libcgroup/init.h | 3 ++
> include/libcgroup/iterators.h | 34 ++++++++++++++++++++++++
> src/api.c | 59
> +++++++++++++++++++++++++++++++++++++++++
> src/libcgroup.map | 7 +++++
> 4 files changed, 103 insertions(+), 0 deletions(-)
>
> diff --git a/include/libcgroup/init.h b/include/libcgroup/init.h
> index 881b830..3709096 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 8ecc53f..c6d453d 100644
> --- a/include/libcgroup/iterators.h
> +++ b/include/libcgroup/iterators.h
> @@ -387,8 +387,42 @@ 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 0dc135a..dfc70a4 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 2a3439f..fb30801 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;
> +
>
>
> ------------------------------------------------------------------------------
> Xperia(TM) PLAY
> It's a major breakthrough. An authentic gaming
> smartphone on the nation's most reliable network.
> And it wants your games.
> http://p.sf.net/sfu/verizon-sfdev
> _______________________________________________
> Libcg-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel