diff options
author | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-06-18 19:42:46 +0530 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-06-18 19:49:39 +0530 |
commit | 7c8df4bd70091301e8473ef144153d1b2946edd3 (patch) | |
tree | 93fd0782419dd211471f9efb1a8879b7df6dc5d9 /src/api.c | |
parent | a32b08930f1828b39d6cafd2779bdab66aebc484 (diff) | |
download | libcg-7c8df4bd70091301e8473ef144153d1b2946edd3.tar.gz libcg-7c8df4bd70091301e8473ef144153d1b2946edd3.tar.xz libcg-7c8df4bd70091301e8473ef144153d1b2946edd3.zip |
libcgroup: Introduce post order walk
With the introduction of the flags, we now actually make use of them.
This patch adds a post mode and modifies the test case to also do a post
order walk.
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 | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -2212,7 +2212,7 @@ int cgroup_get_last_errno() static int cg_walk_node(FTS *fts, FTSENT *ent, const int depth, - struct cgroup_file_info *info) + struct cgroup_file_info *info, int dir) { int ret = 0; @@ -2236,12 +2236,15 @@ static int cg_walk_node(FTS *fts, FTSENT *ent, const int depth, errno = ent->fts_errno; break; case FTS_D: - info->type = CGROUP_FILE_TYPE_DIR; + if (dir & CGROUP_WALK_TYPE_PRE_DIR) + info->type = CGROUP_FILE_TYPE_DIR; break; case FTS_DC: case FTS_NSOK: case FTS_NS: case FTS_DP: + if (dir & CGROUP_WALK_TYPE_POST_DIR) + info->type = CGROUP_FILE_TYPE_DIR; break; case FTS_F: info->type = CGROUP_FILE_TYPE_FILE; @@ -2272,7 +2275,9 @@ int cgroup_walk_tree_next(const int depth, void **handle, return ECGEOF; if (!base_level && depth) base_level = ent->fts_level + depth; - ret = cg_walk_node(entry->fts, ent, base_level, info); + + ret = cg_walk_node(entry->fts, ent, base_level, info, entry->flags); + *handle = entry; return ret; } @@ -2326,6 +2331,8 @@ int cgroup_walk_tree_begin(char *controller, char *base_path, const int depth, return ECGOTHER; } + entry->flags |= CGROUP_WALK_TYPE_PRE_DIR; + *base_level = 0; cg_path[0] = full_path; cg_path[1] = NULL; @@ -2339,7 +2346,9 @@ int cgroup_walk_tree_begin(char *controller, char *base_path, const int depth, } if (!*base_level && depth) *base_level = ent->fts_level + depth; - ret = cg_walk_node(entry->fts, ent, *base_level, info); + + ret = cg_walk_node(entry->fts, ent, base_level, info, entry->flags); + *handle = entry; return ret; } |