Skip to content

Commit

Permalink
container freezer: make freezer state names less generic
Browse files Browse the repository at this point in the history
Rename cgroup freezer states to be less generic to avoid any name
collisions while also better describing what each state is.

Signed-off-by: Matt Helsley <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matt Helsley authored and torvalds committed Oct 20, 2008
1 parent 957a4ee commit 81dcf33
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions kernel/cgroup_freezer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <linux/seq_file.h>

enum freezer_state {
STATE_RUNNING = 0,
STATE_FREEZING,
STATE_FROZEN,
CGROUP_THAWED = 0,
CGROUP_FREEZING,
CGROUP_FROZEN,
};

struct freezer {
Expand Down Expand Up @@ -57,15 +57,15 @@ int cgroup_frozen(struct task_struct *task)
state = freezer->state;
task_unlock(task);

return state == STATE_FROZEN;
return state == CGROUP_FROZEN;
}

/*
* cgroups_write_string() limits the size of freezer state strings to
* CGROUP_LOCAL_BUFFER_SIZE
*/
static const char *freezer_state_strs[] = {
"RUNNING",
"THAWED",
"FREEZING",
"FROZEN",
};
Expand All @@ -75,10 +75,10 @@ static const char *freezer_state_strs[] = {
* Transitions are caused by userspace writes to the freezer.state file.
* The values in parenthesis are state labels. The rest are edge labels.
*
* (RUNNING) --FROZEN--> (FREEZING) --FROZEN--> (FROZEN)
* ^ ^ | |
* | \_______RUNNING_______/ |
* \_____________________________RUNNING___________/
* (THAWED) --FROZEN--> (FREEZING) --FROZEN--> (FROZEN)
* ^ ^ | |
* | \_______THAWED_______/ |
* \__________________________THAWED____________/
*/

struct cgroup_subsys freezer_subsys;
Expand Down Expand Up @@ -135,7 +135,7 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup_subsys *ss,
return ERR_PTR(-ENOMEM);

spin_lock_init(&freezer->lock);
freezer->state = STATE_RUNNING;
freezer->state = CGROUP_THAWED;
return &freezer->css;
}

Expand Down Expand Up @@ -170,13 +170,13 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
return -EBUSY;

freezer = cgroup_freezer(new_cgroup);
if (freezer->state == STATE_FROZEN)
if (freezer->state == CGROUP_FROZEN)
return -EBUSY;

retval = 0;
task_lock(task);
freezer = task_freezer(task);
if (freezer->state == STATE_FROZEN)
if (freezer->state == CGROUP_FROZEN)
retval = -EBUSY;
task_unlock(task);
return retval;
Expand All @@ -190,10 +190,10 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
freezer = task_freezer(task);
task_unlock(task);

BUG_ON(freezer->state == STATE_FROZEN);
BUG_ON(freezer->state == CGROUP_FROZEN);
spin_lock_irq(&freezer->lock);
/* Locking avoids race with FREEZING -> RUNNING transitions. */
if (freezer->state == STATE_FREEZING)
/* Locking avoids race with FREEZING -> THAWED transitions. */
if (freezer->state == CGROUP_FREEZING)
freeze_task(task, true);
spin_unlock_irq(&freezer->lock);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ static void check_if_frozen(struct cgroup *cgroup,
* tasks.
*/
if (nfrozen == ntotal)
freezer->state = STATE_FROZEN;
freezer->state = CGROUP_FROZEN;
cgroup_iter_end(cgroup, &it);
}

Expand All @@ -237,7 +237,7 @@ static int freezer_read(struct cgroup *cgroup, struct cftype *cft,
freezer = cgroup_freezer(cgroup);
spin_lock_irq(&freezer->lock);
state = freezer->state;
if (state == STATE_FREEZING) {
if (state == CGROUP_FREEZING) {
/* We change from FREEZING to FROZEN lazily if the cgroup was
* only partially frozen when we exitted write. */
check_if_frozen(cgroup, freezer);
Expand All @@ -257,7 +257,7 @@ static int try_to_freeze_cgroup(struct cgroup *cgroup, struct freezer *freezer)
struct task_struct *task;
unsigned int num_cant_freeze_now = 0;

freezer->state = STATE_FREEZING;
freezer->state = CGROUP_FREEZING;
cgroup_iter_start(cgroup, &it);
while ((task = cgroup_iter_next(cgroup, &it))) {
if (!freeze_task(task, true))
Expand Down Expand Up @@ -288,7 +288,7 @@ static int unfreeze_cgroup(struct cgroup *cgroup, struct freezer *freezer)
wake_up_process(task);
}
cgroup_iter_end(cgroup, &it);
freezer->state = STATE_RUNNING;
freezer->state = CGROUP_THAWED;

return 0;
}
Expand All @@ -305,18 +305,18 @@ static int freezer_change_state(struct cgroup *cgroup,
if (goal_state == freezer->state)
goto out;
switch (freezer->state) {
case STATE_RUNNING:
case CGROUP_THAWED:
retval = try_to_freeze_cgroup(cgroup, freezer);
break;
case STATE_FREEZING:
if (goal_state == STATE_FROZEN) {
case CGROUP_FREEZING:
if (goal_state == CGROUP_FROZEN) {
/* Userspace is retrying after
* "/bin/echo FROZEN > freezer.state" returned -EBUSY */
retval = try_to_freeze_cgroup(cgroup, freezer);
break;
}
/* state == FREEZING and goal_state == RUNNING, so unfreeze */
case STATE_FROZEN:
/* state == FREEZING and goal_state == THAWED, so unfreeze */
case CGROUP_FROZEN:
retval = unfreeze_cgroup(cgroup, freezer);
break;
default:
Expand All @@ -335,10 +335,10 @@ static int freezer_write(struct cgroup *cgroup,
int retval;
enum freezer_state goal_state;

if (strcmp(buffer, freezer_state_strs[STATE_RUNNING]) == 0)
goal_state = STATE_RUNNING;
else if (strcmp(buffer, freezer_state_strs[STATE_FROZEN]) == 0)
goal_state = STATE_FROZEN;
if (strcmp(buffer, freezer_state_strs[CGROUP_THAWED]) == 0)
goal_state = CGROUP_THAWED;
else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0)
goal_state = CGROUP_FROZEN;
else
return -EIO;

Expand Down

0 comments on commit 81dcf33

Please sign in to comment.