]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Added iterators to go through all mount points of a hierarchy.
authorJan Safranek <jsafrane@redhat.com>
Wed, 6 Apr 2011 06:37:11 +0000 (08:37 +0200)
committerJan Safranek <jsafrane@redhat.com>
Mon, 18 Apr 2011 12:13:43 +0000 (14:13 +0200)
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 <jsafrane@redhat.com>
Acked-by: Ivana Hutarova Varekova<varekova@redhat.com>
include/libcgroup/init.h
include/libcgroup/iterators.h
src/api.c
src/libcgroup.map

index 881b8302749d400e543399e2fafa73d44ba9dda6..3709096541a6b93f18a165695e72b63da9f6cac6 100644 (file)
@@ -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.
index 8ecc53f508b384b7b9333326a65b18bc73ed2cc4..c6d453d6419196b72f1dfc249dcc0c9cabb51faa 100644 (file)
@@ -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 */
index 0dc135ab1dda5c1f47bbc780f9143e7ee2fbc762..dfc70a4938c60f450a4e8dce891d063356590ef4 100644 (file)
--- 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;
+}
+
+
index 2a3439f3aeb5b3cb63a5b49065ff1c4584e9e220..fb30801de3eb890fd96c9c2e708c9eb17a3dc706 100644 (file)
@@ -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;
+