diff options
author | Tejun Heo <tj@kernel.org> | 2012-11-09 12:12:30 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2012-11-09 12:12:30 -0500 |
commit | 04a4ec32571e88c614b229824afec376d24cc035 (patch) | |
tree | 47149b8d0c5673a1e4278ac4f0874296b3d19b10 /kernel/cgroup_freezer.c | |
parent | bcd66c894ac994ef5d6fbbaa9a24506ffaf64fd4 (diff) |
cgroup_freezer: prepare freezer_change_state() for full hierarchy support
* Make freezer_change_state() take bool @freeze instead of enum
freezer_state.
* Separate out freezer_apply_state() out of freezer_change_state().
This makes freezer_change_state() a rather silly thin wrapper. It
will be filled with hierarchy handling later on.
This patch doesn't introduce any behavior change.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Diffstat (limited to 'kernel/cgroup_freezer.c')
-rw-r--r-- | kernel/cgroup_freezer.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c index 975b3d8732f4..2690830e7428 100644 --- a/kernel/cgroup_freezer.c +++ b/kernel/cgroup_freezer.c | |||
@@ -247,45 +247,57 @@ static void unfreeze_cgroup(struct freezer *freezer) | |||
247 | cgroup_iter_end(cgroup, &it); | 247 | cgroup_iter_end(cgroup, &it); |
248 | } | 248 | } |
249 | 249 | ||
250 | static void freezer_change_state(struct freezer *freezer, | 250 | /** |
251 | enum freezer_state goal_state) | 251 | * freezer_apply_state - apply state change to a single cgroup_freezer |
252 | * @freezer: freezer to apply state change to | ||
253 | * @freeze: whether to freeze or unfreeze | ||
254 | */ | ||
255 | static void freezer_apply_state(struct freezer *freezer, bool freeze) | ||
252 | { | 256 | { |
253 | /* also synchronizes against task migration, see freezer_attach() */ | 257 | /* also synchronizes against task migration, see freezer_attach() */ |
254 | spin_lock_irq(&freezer->lock); | 258 | lockdep_assert_held(&freezer->lock); |
255 | 259 | ||
256 | switch (goal_state) { | 260 | if (freeze) { |
257 | case CGROUP_THAWED: | ||
258 | if (freezer->state != CGROUP_THAWED) | ||
259 | atomic_dec(&system_freezing_cnt); | ||
260 | freezer->state = CGROUP_THAWED; | ||
261 | unfreeze_cgroup(freezer); | ||
262 | break; | ||
263 | case CGROUP_FROZEN: | ||
264 | if (freezer->state == CGROUP_THAWED) | 261 | if (freezer->state == CGROUP_THAWED) |
265 | atomic_inc(&system_freezing_cnt); | 262 | atomic_inc(&system_freezing_cnt); |
266 | freezer->state = CGROUP_FREEZING; | 263 | freezer->state = CGROUP_FREEZING; |
267 | freeze_cgroup(freezer); | 264 | freeze_cgroup(freezer); |
268 | break; | 265 | } else { |
269 | default: | 266 | if (freezer->state != CGROUP_THAWED) |
270 | BUG(); | 267 | atomic_dec(&system_freezing_cnt); |
268 | freezer->state = CGROUP_THAWED; | ||
269 | unfreeze_cgroup(freezer); | ||
271 | } | 270 | } |
271 | } | ||
272 | 272 | ||
273 | /** | ||
274 | * freezer_change_state - change the freezing state of a cgroup_freezer | ||
275 | * @freezer: freezer of interest | ||
276 | * @freeze: whether to freeze or thaw | ||
277 | * | ||
278 | * Freeze or thaw @cgroup according to @freeze. | ||
279 | */ | ||
280 | static void freezer_change_state(struct freezer *freezer, bool freeze) | ||
281 | { | ||
282 | /* update @freezer */ | ||
283 | spin_lock_irq(&freezer->lock); | ||
284 | freezer_apply_state(freezer, freeze); | ||
273 | spin_unlock_irq(&freezer->lock); | 285 | spin_unlock_irq(&freezer->lock); |
274 | } | 286 | } |
275 | 287 | ||
276 | static int freezer_write(struct cgroup *cgroup, struct cftype *cft, | 288 | static int freezer_write(struct cgroup *cgroup, struct cftype *cft, |
277 | const char *buffer) | 289 | const char *buffer) |
278 | { | 290 | { |
279 | enum freezer_state goal_state; | 291 | bool freeze; |
280 | 292 | ||
281 | if (strcmp(buffer, freezer_state_strs[CGROUP_THAWED]) == 0) | 293 | if (strcmp(buffer, freezer_state_strs[CGROUP_THAWED]) == 0) |
282 | goal_state = CGROUP_THAWED; | 294 | freeze = false; |
283 | else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0) | 295 | else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0) |
284 | goal_state = CGROUP_FROZEN; | 296 | freeze = true; |
285 | else | 297 | else |
286 | return -EINVAL; | 298 | return -EINVAL; |
287 | 299 | ||
288 | freezer_change_state(cgroup_freezer(cgroup), goal_state); | 300 | freezer_change_state(cgroup_freezer(cgroup), freeze); |
289 | return 0; | 301 | return 0; |
290 | } | 302 | } |
291 | 303 | ||