Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * cgroup_freezer.c - control group freezer subsystem |
| 3 | * |
| 4 | * Copyright IBM Corporation, 2007 |
| 5 | * |
| 6 | * Author : Cedric Le Goater <clg@fr.ibm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2.1 of the GNU Lesser General Public License |
| 10 | * as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it would be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | */ |
| 16 | |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 19 | #include <linux/cgroup.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/freezer.h> |
| 23 | #include <linux/seq_file.h> |
| 24 | |
| 25 | enum freezer_state { |
Matt Helsley | 81dcf33 | 2008-10-18 20:27:23 -0700 | [diff] [blame] | 26 | CGROUP_THAWED = 0, |
| 27 | CGROUP_FREEZING, |
| 28 | CGROUP_FROZEN, |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct freezer { |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 32 | struct cgroup_subsys_state css; |
| 33 | enum freezer_state state; |
| 34 | spinlock_t lock; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 37 | static inline struct freezer *cgroup_freezer(struct cgroup *cgroup) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 38 | { |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 39 | return container_of(cgroup_subsys_state(cgroup, freezer_subsys_id), |
| 40 | struct freezer, css); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline struct freezer *task_freezer(struct task_struct *task) |
| 44 | { |
| 45 | return container_of(task_subsys_state(task, freezer_subsys_id), |
| 46 | struct freezer, css); |
| 47 | } |
| 48 | |
Tejun Heo | 22b4e11 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 49 | bool cgroup_freezing(struct task_struct *task) |
Tomasz Buchert | d5de4ddb | 2010-10-27 15:33:32 -0700 | [diff] [blame] | 50 | { |
Tejun Heo | 22b4e11 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 51 | enum freezer_state state; |
| 52 | bool ret; |
Tomasz Buchert | d5de4ddb | 2010-10-27 15:33:32 -0700 | [diff] [blame] | 53 | |
Tejun Heo | 22b4e11 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 54 | rcu_read_lock(); |
| 55 | state = task_freezer(task)->state; |
| 56 | ret = state == CGROUP_FREEZING || state == CGROUP_FROZEN; |
| 57 | rcu_read_unlock(); |
| 58 | |
| 59 | return ret; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* |
| 63 | * cgroups_write_string() limits the size of freezer state strings to |
| 64 | * CGROUP_LOCAL_BUFFER_SIZE |
| 65 | */ |
| 66 | static const char *freezer_state_strs[] = { |
Matt Helsley | 81dcf33 | 2008-10-18 20:27:23 -0700 | [diff] [blame] | 67 | "THAWED", |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 68 | "FREEZING", |
| 69 | "FROZEN", |
| 70 | }; |
| 71 | |
| 72 | /* |
| 73 | * State diagram |
| 74 | * Transitions are caused by userspace writes to the freezer.state file. |
| 75 | * The values in parenthesis are state labels. The rest are edge labels. |
| 76 | * |
Matt Helsley | 81dcf33 | 2008-10-18 20:27:23 -0700 | [diff] [blame] | 77 | * (THAWED) --FROZEN--> (FREEZING) --FROZEN--> (FROZEN) |
| 78 | * ^ ^ | | |
| 79 | * | \_______THAWED_______/ | |
| 80 | * \__________________________THAWED____________/ |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 81 | */ |
| 82 | |
| 83 | struct cgroup_subsys freezer_subsys; |
| 84 | |
Li Zefan | 761b3ef | 2012-01-31 13:47:36 +0800 | [diff] [blame] | 85 | static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 86 | { |
| 87 | struct freezer *freezer; |
| 88 | |
| 89 | freezer = kzalloc(sizeof(struct freezer), GFP_KERNEL); |
| 90 | if (!freezer) |
| 91 | return ERR_PTR(-ENOMEM); |
| 92 | |
| 93 | spin_lock_init(&freezer->lock); |
Matt Helsley | 81dcf33 | 2008-10-18 20:27:23 -0700 | [diff] [blame] | 94 | freezer->state = CGROUP_THAWED; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 95 | return &freezer->css; |
| 96 | } |
| 97 | |
Li Zefan | 761b3ef | 2012-01-31 13:47:36 +0800 | [diff] [blame] | 98 | static void freezer_destroy(struct cgroup *cgroup) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 99 | { |
Tejun Heo | a320122 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 100 | struct freezer *freezer = cgroup_freezer(cgroup); |
| 101 | |
| 102 | if (freezer->state != CGROUP_THAWED) |
| 103 | atomic_dec(&system_freezing_cnt); |
| 104 | kfree(freezer); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Matt Helsley | 957a4ee | 2008-10-18 20:27:22 -0700 | [diff] [blame] | 107 | /* |
Tejun Heo | ead5c47 | 2012-10-16 15:03:15 -0700 | [diff] [blame] | 108 | * Tasks can be migrated into a different freezer anytime regardless of its |
| 109 | * current state. freezer_attach() is responsible for making new tasks |
| 110 | * conform to the current state. |
| 111 | * |
| 112 | * Freezer state changes and task migration are synchronized via |
| 113 | * @freezer->lock. freezer_attach() makes the new tasks conform to the |
| 114 | * current state and all following state changes can see the new tasks. |
Matt Helsley | 957a4ee | 2008-10-18 20:27:22 -0700 | [diff] [blame] | 115 | */ |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 116 | static void freezer_attach(struct cgroup *new_cgrp, struct cgroup_taskset *tset) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 117 | { |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 118 | struct freezer *freezer = cgroup_freezer(new_cgrp); |
Tejun Heo | bb9d97b | 2011-12-12 18:12:21 -0800 | [diff] [blame] | 119 | struct task_struct *task; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 120 | |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 121 | spin_lock_irq(&freezer->lock); |
| 122 | |
Li Zefan | 80a6a2c | 2008-10-29 14:00:52 -0700 | [diff] [blame] | 123 | /* |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 124 | * Make the new tasks conform to the current state of @new_cgrp. |
| 125 | * For simplicity, when migrating any task to a FROZEN cgroup, we |
| 126 | * revert it to FREEZING and let update_if_frozen() determine the |
| 127 | * correct state later. |
| 128 | * |
| 129 | * Tasks in @tset are on @new_cgrp but may not conform to its |
| 130 | * current state before executing the following - !frozen tasks may |
| 131 | * be visible in a FROZEN cgroup and frozen tasks in a THAWED one. |
| 132 | * This means that, to determine whether to freeze, one should test |
| 133 | * whether the state equals THAWED. |
Li Zefan | 80a6a2c | 2008-10-29 14:00:52 -0700 | [diff] [blame] | 134 | */ |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 135 | cgroup_taskset_for_each(task, new_cgrp, tset) { |
| 136 | if (freezer->state == CGROUP_THAWED) { |
| 137 | __thaw_task(task); |
| 138 | } else { |
| 139 | freeze_task(task); |
| 140 | freezer->state = CGROUP_FREEZING; |
| 141 | } |
| 142 | } |
Matt Helsley | 957a4ee | 2008-10-18 20:27:22 -0700 | [diff] [blame] | 143 | |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 144 | spin_unlock_irq(&freezer->lock); |
Ben Blum | f780bdb | 2011-05-26 16:25:19 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Li Zefan | 761b3ef | 2012-01-31 13:47:36 +0800 | [diff] [blame] | 147 | static void freezer_fork(struct task_struct *task) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 148 | { |
| 149 | struct freezer *freezer; |
| 150 | |
Paul E. McKenney | 8b46f88 | 2010-04-21 13:02:08 -0700 | [diff] [blame] | 151 | rcu_read_lock(); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 152 | freezer = task_freezer(task); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 153 | |
Li Zefan | 3b1b3f6 | 2008-11-12 13:26:50 -0800 | [diff] [blame] | 154 | /* |
| 155 | * The root cgroup is non-freezable, so we can skip the |
| 156 | * following check. |
| 157 | */ |
| 158 | if (!freezer->css.cgroup->parent) |
Tejun Heo | 5edee61 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 159 | goto out; |
Li Zefan | 3b1b3f6 | 2008-11-12 13:26:50 -0800 | [diff] [blame] | 160 | |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 161 | spin_lock_irq(&freezer->lock); |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 162 | /* |
| 163 | * @task might have been just migrated into a FROZEN cgroup. Test |
| 164 | * equality with THAWED. Read the comment in freezer_attach(). |
| 165 | */ |
| 166 | if (freezer->state != CGROUP_THAWED) |
Tejun Heo | 839e340 | 2011-11-21 12:32:26 -0800 | [diff] [blame] | 167 | freeze_task(task); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 168 | spin_unlock_irq(&freezer->lock); |
Tejun Heo | 5edee61 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 169 | out: |
| 170 | rcu_read_unlock(); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
Tejun Heo | b4d1831 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 174 | * We change from FREEZING to FROZEN lazily if the cgroup was only |
| 175 | * partially frozen when we exitted write. Caller must hold freezer->lock. |
| 176 | * |
| 177 | * Task states and freezer state might disagree while tasks are being |
Tejun Heo | ead5c47 | 2012-10-16 15:03:15 -0700 | [diff] [blame] | 178 | * migrated into or out of @cgroup, so we can't verify task states against |
| 179 | * @freezer state here. See freezer_attach() for details. |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 180 | */ |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 181 | static void update_if_frozen(struct freezer *freezer) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 182 | { |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 183 | struct cgroup *cgroup = freezer->css.cgroup; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 184 | struct cgroup_iter it; |
| 185 | struct task_struct *task; |
Tejun Heo | b4d1831 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 186 | |
| 187 | if (freezer->state != CGROUP_FREEZING) |
| 188 | return; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 189 | |
| 190 | cgroup_iter_start(cgroup, &it); |
Tejun Heo | b4d1831 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 191 | |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 192 | while ((task = cgroup_iter_next(cgroup, &it))) { |
Tejun Heo | 3c426d5 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 193 | if (freezing(task)) { |
Tejun Heo | 3c426d5 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 194 | /* |
| 195 | * freezer_should_skip() indicates that the task |
| 196 | * should be skipped when determining freezing |
| 197 | * completion. Consider it frozen in addition to |
| 198 | * the usual frozen condition. |
| 199 | */ |
Oleg Nesterov | 5d8f72b | 2012-10-26 19:46:06 +0200 | [diff] [blame] | 200 | if (!frozen(task) && !freezer_should_skip(task)) |
Tejun Heo | b4d1831 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 201 | goto notyet; |
Tejun Heo | 3c426d5 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 202 | } |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Tejun Heo | b4d1831 | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 205 | freezer->state = CGROUP_FROZEN; |
| 206 | notyet: |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 207 | cgroup_iter_end(cgroup, &it); |
| 208 | } |
| 209 | |
| 210 | static int freezer_read(struct cgroup *cgroup, struct cftype *cft, |
| 211 | struct seq_file *m) |
| 212 | { |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 213 | struct freezer *freezer = cgroup_freezer(cgroup); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 214 | enum freezer_state state; |
| 215 | |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 216 | spin_lock_irq(&freezer->lock); |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 217 | update_if_frozen(freezer); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 218 | state = freezer->state; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 219 | spin_unlock_irq(&freezer->lock); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 220 | |
| 221 | seq_puts(m, freezer_state_strs[state]); |
| 222 | seq_putc(m, '\n'); |
| 223 | return 0; |
| 224 | } |
| 225 | |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 226 | static void freeze_cgroup(struct freezer *freezer) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 227 | { |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 228 | struct cgroup *cgroup = freezer->css.cgroup; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 229 | struct cgroup_iter it; |
| 230 | struct task_struct *task; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 231 | |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 232 | cgroup_iter_start(cgroup, &it); |
Tejun Heo | 51f246e | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 233 | while ((task = cgroup_iter_next(cgroup, &it))) |
| 234 | freeze_task(task); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 235 | cgroup_iter_end(cgroup, &it); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 238 | static void unfreeze_cgroup(struct freezer *freezer) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 239 | { |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 240 | struct cgroup *cgroup = freezer->css.cgroup; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 241 | struct cgroup_iter it; |
| 242 | struct task_struct *task; |
| 243 | |
| 244 | cgroup_iter_start(cgroup, &it); |
Tejun Heo | a5be2d0 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 245 | while ((task = cgroup_iter_next(cgroup, &it))) |
| 246 | __thaw_task(task); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 247 | cgroup_iter_end(cgroup, &it); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 250 | static void freezer_change_state(struct freezer *freezer, |
Tejun Heo | 51f246e | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 251 | enum freezer_state goal_state) |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 252 | { |
Tejun Heo | ead5c47 | 2012-10-16 15:03:15 -0700 | [diff] [blame] | 253 | /* also synchronizes against task migration, see freezer_attach() */ |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 254 | spin_lock_irq(&freezer->lock); |
Li Zefan | 51308ee | 2008-10-29 14:00:54 -0700 | [diff] [blame] | 255 | |
Li Zefan | 51308ee | 2008-10-29 14:00:54 -0700 | [diff] [blame] | 256 | switch (goal_state) { |
Matt Helsley | 81dcf33 | 2008-10-18 20:27:23 -0700 | [diff] [blame] | 257 | case CGROUP_THAWED: |
Tejun Heo | a320122 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 258 | if (freezer->state != CGROUP_THAWED) |
| 259 | atomic_dec(&system_freezing_cnt); |
Tejun Heo | 22b4e11 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 260 | freezer->state = CGROUP_THAWED; |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 261 | unfreeze_cgroup(freezer); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 262 | break; |
Li Zefan | 51308ee | 2008-10-29 14:00:54 -0700 | [diff] [blame] | 263 | case CGROUP_FROZEN: |
Tejun Heo | a320122 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 264 | if (freezer->state == CGROUP_THAWED) |
| 265 | atomic_inc(&system_freezing_cnt); |
Tejun Heo | 22b4e11 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 266 | freezer->state = CGROUP_FREEZING; |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 267 | freeze_cgroup(freezer); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 268 | break; |
Li Zefan | 51308ee | 2008-10-29 14:00:54 -0700 | [diff] [blame] | 269 | default: |
| 270 | BUG(); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 271 | } |
Tejun Heo | 22b4e11 | 2011-11-21 12:32:25 -0800 | [diff] [blame] | 272 | |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 273 | spin_unlock_irq(&freezer->lock); |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 276 | static int freezer_write(struct cgroup *cgroup, struct cftype *cft, |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 277 | const char *buffer) |
| 278 | { |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 279 | enum freezer_state goal_state; |
| 280 | |
Matt Helsley | 81dcf33 | 2008-10-18 20:27:23 -0700 | [diff] [blame] | 281 | if (strcmp(buffer, freezer_state_strs[CGROUP_THAWED]) == 0) |
| 282 | goal_state = CGROUP_THAWED; |
| 283 | else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0) |
| 284 | goal_state = CGROUP_FROZEN; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 285 | else |
Li Zefan | 3b1b3f6 | 2008-11-12 13:26:50 -0800 | [diff] [blame] | 286 | return -EINVAL; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 287 | |
Tejun Heo | bcd66c8 | 2012-11-09 09:12:29 -0800 | [diff] [blame^] | 288 | freezer_change_state(cgroup_freezer(cgroup), goal_state); |
Tejun Heo | 51f246e | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 289 | return 0; |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static struct cftype files[] = { |
| 293 | { |
| 294 | .name = "state", |
Tejun Heo | 4baf6e3 | 2012-04-01 12:09:55 -0700 | [diff] [blame] | 295 | .flags = CFTYPE_NOT_ON_ROOT, |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 296 | .read_seq_string = freezer_read, |
| 297 | .write_string = freezer_write, |
| 298 | }, |
Tejun Heo | 4baf6e3 | 2012-04-01 12:09:55 -0700 | [diff] [blame] | 299 | { } /* terminate */ |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 302 | struct cgroup_subsys freezer_subsys = { |
| 303 | .name = "freezer", |
| 304 | .create = freezer_create, |
| 305 | .destroy = freezer_destroy, |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 306 | .subsys_id = freezer_subsys_id, |
Tejun Heo | 8755ade | 2012-10-16 15:03:14 -0700 | [diff] [blame] | 307 | .attach = freezer_attach, |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 308 | .fork = freezer_fork, |
Tejun Heo | 4baf6e3 | 2012-04-01 12:09:55 -0700 | [diff] [blame] | 309 | .base_cftypes = files, |
Tejun Heo | 8c7f6ed | 2012-09-13 12:20:58 -0700 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | * freezer subsys doesn't handle hierarchy at all. Frozen state |
| 313 | * should be inherited through the hierarchy - if a parent is |
| 314 | * frozen, all its children should be frozen. Fix it and remove |
| 315 | * the following. |
| 316 | */ |
| 317 | .broken_hierarchy = true, |
Matt Helsley | dc52ddc | 2008-10-18 20:27:21 -0700 | [diff] [blame] | 318 | }; |