diff options
author | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-06-18 19:42:45 +0530 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-06-18 19:49:39 +0530 |
commit | a32b08930f1828b39d6cafd2779bdab66aebc484 (patch) | |
tree | ad0be225f4af0e0c7369021810f1541487709e81 /src/api.c | |
parent | 89874676e7a84e504e3b2829228c7c3863a6d500 (diff) | |
download | libcg-a32b08930f1828b39d6cafd2779bdab66aebc484.tar.gz libcg-a32b08930f1828b39d6cafd2779bdab66aebc484.tar.xz libcg-a32b08930f1828b39d6cafd2779bdab66aebc484.zip |
libcgroup: Add flags to the walk_tree handle
Introduce a cgroup_tree_handle structure so that we can track flags for
the walk_tree operation. In a number of cases we would prefer to walk the
tree in postorder as opposed to pre-order which is the current default.
This patch does the addition.
Changes since V1:
1. Added checks for !handle as suggested by Bharata
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Diffstat (limited to 'src/api.c')
-rw-r--r-- | src/api.c | 60 |
1 files changed, 50 insertions, 10 deletions
@@ -2256,7 +2256,7 @@ int cgroup_walk_tree_next(const int depth, void **handle, struct cgroup_file_info *info, int base_level) { int ret = 0; - FTS *fts = *(FTS **)handle; + struct cgroup_tree_handle *entry; FTSENT *ent; if (!cgroup_initialized) @@ -2264,26 +2264,34 @@ int cgroup_walk_tree_next(const int depth, void **handle, if (!handle) return ECGINVAL; - ent = fts_read(fts); + + entry = (struct cgroup_tree_handle *) *handle; + + ent = fts_read(entry->fts); if (!ent) return ECGEOF; if (!base_level && depth) base_level = ent->fts_level + depth; - ret = cg_walk_node(fts, ent, base_level, info); - *handle = fts; + ret = cg_walk_node(entry->fts, ent, base_level, info); + *handle = entry; return ret; } int cgroup_walk_tree_end(void **handle) { - FTS *fts = *(FTS **)handle; + struct cgroup_tree_handle *entry; if (!cgroup_initialized) return ECGROUPNOTINITIALIZED; if (!handle) return ECGINVAL; - fts_close(fts); + + entry = (struct cgroup_tree_handle *) *handle; + + fts_close(entry->fts); + free(entry); + *handle = NULL; return 0; } @@ -2300,31 +2308,63 @@ int cgroup_walk_tree_begin(char *controller, char *base_path, const int depth, char full_path[FILENAME_MAX]; FTSENT *ent; FTS *fts; + struct cgroup_tree_handle *entry; if (!cgroup_initialized) return ECGROUPNOTINITIALIZED; + if (!handle) + return ECGINVAL; + if (!cg_build_path(base_path, full_path, controller)) return ECGOTHER; + entry = calloc(sizeof(struct cgroup_tree_handle), 1); + + if (!entry) { + last_errno = errno; + return ECGOTHER; + } + *base_level = 0; cg_path[0] = full_path; cg_path[1] = NULL; - fts = fts_open(cg_path, FTS_LOGICAL | FTS_NOCHDIR | + entry->fts = fts_open(cg_path, FTS_LOGICAL | FTS_NOCHDIR | FTS_NOSTAT, NULL); - ent = fts_read(fts); + ent = fts_read(entry->fts); if (!ent) { cgroup_dbg("fts_read failed\n"); return ECGINVAL; } if (!*base_level && depth) *base_level = ent->fts_level + depth; - ret = cg_walk_node(fts, ent, *base_level, info); - *handle = fts; + ret = cg_walk_node(entry->fts, ent, *base_level, info); + *handle = entry; return ret; } +int cgroup_walk_tree_set_flags(void **handle, int flags) +{ + struct cgroup_tree_handle *entry; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + + if (!handle) + return ECGINVAL; + + if ((flags & CGROUP_WALK_TYPE_PRE_DIR) && + (flags & CGROUP_WALK_TYPE_POST_DIR)) + return ECGINVAL; + + entry = (struct cgroup_tree_handle *) *handle; + entry->flags = flags; + + *handle = entry; + return 0; +} + /* * This parses a stat line which is in the form of (name value) pair * separated by a space. |