2 * Common Block IO controller cgroup interface
4 * Based on ideas and code from CFQ, CFS and BFQ:
5 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
7 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
8 * Paolo Valente <paolo.valente@unimore.it>
10 * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
11 * Nauman Rafique <nauman@google.com>
13 #include <linux/ioprio.h>
14 #include <linux/kdev_t.h>
15 #include <linux/module.h>
16 #include <linux/err.h>
17 #include <linux/blkdev.h>
18 #include <linux/slab.h>
19 #include <linux/genhd.h>
20 #include <linux/delay.h>
21 #include <linux/atomic.h>
22 #include "blk-cgroup.h"
25 #define MAX_KEY_LEN 100
27 static DEFINE_SPINLOCK(blkio_list_lock);
28 static LIST_HEAD(blkio_list);
30 static DEFINE_MUTEX(all_q_mutex);
31 static LIST_HEAD(all_q_list);
33 /* List of groups pending per cpu stats allocation */
34 static DEFINE_SPINLOCK(alloc_list_lock);
35 static LIST_HEAD(alloc_list);
37 static void blkio_stat_alloc_fn(struct work_struct *);
38 static DECLARE_DELAYED_WORK(blkio_stat_alloc_work, blkio_stat_alloc_fn);
40 struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
41 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
43 static struct blkio_policy_type *blkio_policy[BLKIO_NR_POLICIES];
45 struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
47 return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
48 struct blkio_cgroup, css);
50 EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup);
52 static struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk)
54 return container_of(task_subsys_state(tsk, blkio_subsys_id),
55 struct blkio_cgroup, css);
58 struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio)
60 if (bio && bio->bi_css)
61 return container_of(bio->bi_css, struct blkio_cgroup, css);
62 return task_blkio_cgroup(current);
64 EXPORT_SYMBOL_GPL(bio_blkio_cgroup);
67 * Worker for allocating per cpu stat for blk groups. This is scheduled on
68 * the system_nrt_wq once there are some groups on the alloc_list waiting
71 static void blkio_stat_alloc_fn(struct work_struct *work)
73 static void *pcpu_stats[BLKIO_NR_POLICIES];
74 struct delayed_work *dwork = to_delayed_work(work);
75 struct blkio_group *blkg;
80 for (i = 0; i < BLKIO_NR_POLICIES; i++) {
81 if (pcpu_stats[i] != NULL)
84 pcpu_stats[i] = alloc_percpu(struct blkio_group_stats_cpu);
86 /* Allocation failed. Try again after some time. */
87 if (pcpu_stats[i] == NULL) {
88 queue_delayed_work(system_nrt_wq, dwork,
89 msecs_to_jiffies(10));
94 spin_lock_irq(&blkio_list_lock);
95 spin_lock(&alloc_list_lock);
97 /* cgroup got deleted or queue exited. */
98 if (!list_empty(&alloc_list)) {
99 blkg = list_first_entry(&alloc_list, struct blkio_group,
101 for (i = 0; i < BLKIO_NR_POLICIES; i++) {
102 struct blkg_policy_data *pd = blkg->pd[i];
104 if (blkio_policy[i] && pd && !pd->stats_cpu)
105 swap(pd->stats_cpu, pcpu_stats[i]);
108 list_del_init(&blkg->alloc_node);
111 empty = list_empty(&alloc_list);
113 spin_unlock(&alloc_list_lock);
114 spin_unlock_irq(&blkio_list_lock);
121 * blkg_free - free a blkg
122 * @blkg: blkg to free
124 * Free @blkg which may be partially allocated.
126 static void blkg_free(struct blkio_group *blkg)
133 for (i = 0; i < BLKIO_NR_POLICIES; i++) {
134 struct blkg_policy_data *pd = blkg->pd[i];
137 free_percpu(pd->stats_cpu);
146 * blkg_alloc - allocate a blkg
147 * @blkcg: block cgroup the new blkg is associated with
148 * @q: request_queue the new blkg is associated with
150 * Allocate a new blkg assocating @blkcg and @q.
152 static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
153 struct request_queue *q)
155 struct blkio_group *blkg;
158 /* alloc and init base part */
159 blkg = kzalloc_node(sizeof(*blkg), GFP_ATOMIC, q->node);
164 INIT_LIST_HEAD(&blkg->q_node);
165 INIT_LIST_HEAD(&blkg->alloc_node);
168 cgroup_path(blkcg->css.cgroup, blkg->path, sizeof(blkg->path));
170 for (i = 0; i < BLKIO_NR_POLICIES; i++) {
171 struct blkio_policy_type *pol = blkio_policy[i];
172 struct blkg_policy_data *pd;
177 /* alloc per-policy data and attach it to blkg */
178 pd = kzalloc_node(sizeof(*pd) + pol->pdata_size, GFP_ATOMIC,
189 /* invoke per-policy init */
190 for (i = 0; i < BLKIO_NR_POLICIES; i++) {
191 struct blkio_policy_type *pol = blkio_policy[i];
194 pol->ops.blkio_init_group_fn(blkg);
200 struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
201 struct request_queue *q,
203 __releases(q->queue_lock) __acquires(q->queue_lock)
205 struct blkio_group *blkg;
207 WARN_ON_ONCE(!rcu_read_lock_held());
208 lockdep_assert_held(q->queue_lock);
211 * This could be the first entry point of blkcg implementation and
212 * we shouldn't allow anything to go through for a bypassing queue.
213 * The following can be removed if blkg lookup is guaranteed to
214 * fail on a bypassing queue.
216 if (unlikely(blk_queue_bypass(q)) && !for_root)
217 return ERR_PTR(blk_queue_dead(q) ? -EINVAL : -EBUSY);
219 blkg = blkg_lookup(blkcg, q);
223 /* blkg holds a reference to blkcg */
224 if (!css_tryget(&blkcg->css))
225 return ERR_PTR(-EINVAL);
228 * Allocate and initialize.
230 blkg = blkg_alloc(blkcg, q);
232 /* did alloc fail? */
233 if (unlikely(!blkg)) {
234 blkg = ERR_PTR(-ENOMEM);
239 spin_lock(&blkcg->lock);
240 hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
241 list_add(&blkg->q_node, &q->blkg_list);
242 spin_unlock(&blkcg->lock);
244 spin_lock(&alloc_list_lock);
245 list_add(&blkg->alloc_node, &alloc_list);
246 /* Queue per cpu stat allocation from worker thread. */
247 queue_delayed_work(system_nrt_wq, &blkio_stat_alloc_work, 0);
248 spin_unlock(&alloc_list_lock);
252 EXPORT_SYMBOL_GPL(blkg_lookup_create);
254 /* called under rcu_read_lock(). */
255 struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
256 struct request_queue *q)
258 struct blkio_group *blkg;
259 struct hlist_node *n;
261 hlist_for_each_entry_rcu(blkg, n, &blkcg->blkg_list, blkcg_node)
266 EXPORT_SYMBOL_GPL(blkg_lookup);
268 static void blkg_destroy(struct blkio_group *blkg)
270 struct request_queue *q = blkg->q;
271 struct blkio_cgroup *blkcg = blkg->blkcg;
273 lockdep_assert_held(q->queue_lock);
274 lockdep_assert_held(&blkcg->lock);
276 /* Something wrong if we are trying to remove same group twice */
277 WARN_ON_ONCE(list_empty(&blkg->q_node));
278 WARN_ON_ONCE(hlist_unhashed(&blkg->blkcg_node));
279 list_del_init(&blkg->q_node);
280 hlist_del_init_rcu(&blkg->blkcg_node);
282 spin_lock(&alloc_list_lock);
283 list_del_init(&blkg->alloc_node);
284 spin_unlock(&alloc_list_lock);
287 * Put the reference taken at the time of creation so that when all
288 * queues are gone, group can be destroyed.
294 * XXX: This updates blkg policy data in-place for root blkg, which is
295 * necessary across elevator switch and policy registration as root blkgs
296 * aren't shot down. This broken and racy implementation is temporary.
297 * Eventually, blkg shoot down will be replaced by proper in-place update.
299 void update_root_blkg_pd(struct request_queue *q, enum blkio_policy_id plid)
301 struct blkio_policy_type *pol = blkio_policy[plid];
302 struct blkio_group *blkg = blkg_lookup(&blkio_root_cgroup, q);
303 struct blkg_policy_data *pd;
308 kfree(blkg->pd[plid]);
309 blkg->pd[plid] = NULL;
314 pd = kzalloc(sizeof(*pd) + pol->pdata_size, GFP_KERNEL);
317 pd->stats_cpu = alloc_percpu(struct blkio_group_stats_cpu);
318 WARN_ON_ONCE(!pd->stats_cpu);
322 pol->ops.blkio_init_group_fn(blkg);
324 EXPORT_SYMBOL_GPL(update_root_blkg_pd);
327 * blkg_destroy_all - destroy all blkgs associated with a request_queue
328 * @q: request_queue of interest
329 * @destroy_root: whether to destroy root blkg or not
331 * Destroy blkgs associated with @q. If @destroy_root is %true, all are
332 * destroyed; otherwise, root blkg is left alone.
334 void blkg_destroy_all(struct request_queue *q, bool destroy_root)
336 struct blkio_group *blkg, *n;
338 spin_lock_irq(q->queue_lock);
340 list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
341 struct blkio_cgroup *blkcg = blkg->blkcg;
344 if (!destroy_root && blkg->blkcg == &blkio_root_cgroup)
347 spin_lock(&blkcg->lock);
349 spin_unlock(&blkcg->lock);
352 spin_unlock_irq(q->queue_lock);
354 EXPORT_SYMBOL_GPL(blkg_destroy_all);
356 static void blkg_rcu_free(struct rcu_head *rcu_head)
358 blkg_free(container_of(rcu_head, struct blkio_group, rcu_head));
361 void __blkg_release(struct blkio_group *blkg)
363 /* release the extra blkcg reference this blkg has been holding */
364 css_put(&blkg->blkcg->css);
367 * A group is freed in rcu manner. But having an rcu lock does not
368 * mean that one can access all the fields of blkg and assume these
369 * are valid. For example, don't try to follow throtl_data and
370 * request queue links.
372 * Having a reference to blkg under an rcu allows acess to only
373 * values local to groups like group stats and group rate limits
375 call_rcu(&blkg->rcu_head, blkg_rcu_free);
377 EXPORT_SYMBOL_GPL(__blkg_release);
379 static void blkio_reset_stats_cpu(struct blkio_group *blkg, int plid)
381 struct blkg_policy_data *pd = blkg->pd[plid];
384 if (pd->stats_cpu == NULL)
387 for_each_possible_cpu(cpu) {
388 struct blkio_group_stats_cpu *sc =
389 per_cpu_ptr(pd->stats_cpu, cpu);
391 blkg_rwstat_reset(&sc->service_bytes);
392 blkg_rwstat_reset(&sc->serviced);
397 blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
399 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
400 struct blkio_group *blkg;
401 struct hlist_node *n;
403 spin_lock(&blkio_list_lock);
404 spin_lock_irq(&blkcg->lock);
407 * Note that stat reset is racy - it doesn't synchronize against
408 * stat updates. This is a debug feature which shouldn't exist
409 * anyway. If you get hit by a race, retry.
411 hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
412 struct blkio_policy_type *pol;
414 list_for_each_entry(pol, &blkio_list, list) {
415 struct blkg_policy_data *pd = blkg->pd[pol->plid];
416 struct blkio_group_stats *stats = &pd->stats;
418 /* queued stats shouldn't be cleared */
419 blkg_rwstat_reset(&stats->service_bytes);
420 blkg_rwstat_reset(&stats->serviced);
421 blkg_rwstat_reset(&stats->merged);
422 blkg_rwstat_reset(&stats->service_time);
423 blkg_rwstat_reset(&stats->wait_time);
424 blkg_stat_reset(&stats->time);
425 #ifdef CONFIG_DEBUG_BLK_CGROUP
426 blkg_stat_reset(&stats->unaccounted_time);
427 blkg_stat_reset(&stats->avg_queue_size_sum);
428 blkg_stat_reset(&stats->avg_queue_size_samples);
429 blkg_stat_reset(&stats->dequeue);
430 blkg_stat_reset(&stats->group_wait_time);
431 blkg_stat_reset(&stats->idle_time);
432 blkg_stat_reset(&stats->empty_time);
434 blkio_reset_stats_cpu(blkg, pol->plid);
438 spin_unlock_irq(&blkcg->lock);
439 spin_unlock(&blkio_list_lock);
443 static const char *blkg_dev_name(struct blkio_group *blkg)
445 /* some drivers (floppy) instantiate a queue w/o disk registered */
446 if (blkg->q->backing_dev_info.dev)
447 return dev_name(blkg->q->backing_dev_info.dev);
452 * blkcg_print_blkgs - helper for printing per-blkg data
453 * @sf: seq_file to print to
454 * @blkcg: blkcg of interest
455 * @prfill: fill function to print out a blkg
456 * @pol: policy in question
457 * @data: data to be passed to @prfill
458 * @show_total: to print out sum of prfill return values or not
460 * This function invokes @prfill on each blkg of @blkcg if pd for the
461 * policy specified by @pol exists. @prfill is invoked with @sf, the
462 * policy data and @data. If @show_total is %true, the sum of the return
463 * values from @prfill is printed with "Total" label at the end.
465 * This is to be used to construct print functions for
466 * cftype->read_seq_string method.
468 void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
469 u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int),
470 int pol, int data, bool show_total)
472 struct blkio_group *blkg;
473 struct hlist_node *n;
476 spin_lock_irq(&blkcg->lock);
477 hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
479 total += prfill(sf, blkg->pd[pol], data);
480 spin_unlock_irq(&blkcg->lock);
483 seq_printf(sf, "Total %llu\n", (unsigned long long)total);
485 EXPORT_SYMBOL_GPL(blkcg_print_blkgs);
488 * __blkg_prfill_u64 - prfill helper for a single u64 value
489 * @sf: seq_file to print to
490 * @pd: policy data of interest
493 * Print @v to @sf for the device assocaited with @pd.
495 u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v)
497 const char *dname = blkg_dev_name(pd->blkg);
502 seq_printf(sf, "%s %llu\n", dname, (unsigned long long)v);
505 EXPORT_SYMBOL_GPL(__blkg_prfill_u64);
508 * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
509 * @sf: seq_file to print to
510 * @pd: policy data of interest
511 * @rwstat: rwstat to print
513 * Print @rwstat to @sf for the device assocaited with @pd.
515 u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
516 const struct blkg_rwstat *rwstat)
518 static const char *rwstr[] = {
519 [BLKG_RWSTAT_READ] = "Read",
520 [BLKG_RWSTAT_WRITE] = "Write",
521 [BLKG_RWSTAT_SYNC] = "Sync",
522 [BLKG_RWSTAT_ASYNC] = "Async",
524 const char *dname = blkg_dev_name(pd->blkg);
531 for (i = 0; i < BLKG_RWSTAT_NR; i++)
532 seq_printf(sf, "%s %s %llu\n", dname, rwstr[i],
533 (unsigned long long)rwstat->cnt[i]);
535 v = rwstat->cnt[BLKG_RWSTAT_READ] + rwstat->cnt[BLKG_RWSTAT_WRITE];
536 seq_printf(sf, "%s Total %llu\n", dname, (unsigned long long)v);
540 static u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd,
543 return __blkg_prfill_u64(sf, pd,
544 blkg_stat_read((void *)&pd->stats + off));
547 static u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
550 struct blkg_rwstat rwstat = blkg_rwstat_read((void *)&pd->stats + off);
552 return __blkg_prfill_rwstat(sf, pd, &rwstat);
555 /* print blkg_stat specified by BLKCG_STAT_PRIV() */
556 int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
559 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
561 blkcg_print_blkgs(sf, blkcg, blkg_prfill_stat,
562 BLKCG_STAT_POL(cft->private),
563 BLKCG_STAT_OFF(cft->private), false);
566 EXPORT_SYMBOL_GPL(blkcg_print_stat);
568 /* print blkg_rwstat specified by BLKCG_STAT_PRIV() */
569 int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
572 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
574 blkcg_print_blkgs(sf, blkcg, blkg_prfill_rwstat,
575 BLKCG_STAT_POL(cft->private),
576 BLKCG_STAT_OFF(cft->private), true);
579 EXPORT_SYMBOL_GPL(blkcg_print_rwstat);
582 * blkg_conf_prep - parse and prepare for per-blkg config update
583 * @blkcg: target block cgroup
584 * @input: input string
585 * @ctx: blkg_conf_ctx to be filled
587 * Parse per-blkg config update from @input and initialize @ctx with the
588 * result. @ctx->blkg points to the blkg to be updated and @ctx->v the new
589 * value. This function returns with RCU read locked and must be paired
590 * with blkg_conf_finish().
592 int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
593 struct blkg_conf_ctx *ctx)
596 struct gendisk *disk;
597 struct blkio_group *blkg;
598 unsigned int major, minor;
599 unsigned long long v;
602 if (sscanf(input, "%u:%u %llu", &major, &minor, &v) != 3)
605 disk = get_gendisk(MKDEV(major, minor), &part);
611 spin_lock_irq(disk->queue->queue_lock);
612 blkg = blkg_lookup_create(blkcg, disk->queue, false);
613 spin_unlock_irq(disk->queue->queue_lock);
620 * If queue was bypassing, we should retry. Do so after a
621 * short msleep(). It isn't strictly necessary but queue
622 * can be bypassing for some time and it's always nice to
623 * avoid busy looping.
627 ret = restart_syscall();
637 EXPORT_SYMBOL_GPL(blkg_conf_prep);
640 * blkg_conf_finish - finish up per-blkg config update
641 * @ctx: blkg_conf_ctx intiailized by blkg_conf_prep()
643 * Finish up after per-blkg config update. This function must be paired
644 * with blkg_conf_prep().
646 void blkg_conf_finish(struct blkg_conf_ctx *ctx)
652 EXPORT_SYMBOL_GPL(blkg_conf_finish);
654 struct cftype blkio_files[] = {
656 .name = "reset_stats",
657 .write_u64 = blkiocg_reset_stats,
663 * blkiocg_pre_destroy - cgroup pre_destroy callback
664 * @cgroup: cgroup of interest
666 * This function is called when @cgroup is about to go away and responsible
667 * for shooting down all blkgs associated with @cgroup. blkgs should be
668 * removed while holding both q and blkcg locks. As blkcg lock is nested
669 * inside q lock, this function performs reverse double lock dancing.
671 * This is the blkcg counterpart of ioc_release_fn().
673 static int blkiocg_pre_destroy(struct cgroup *cgroup)
675 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
677 spin_lock_irq(&blkcg->lock);
679 while (!hlist_empty(&blkcg->blkg_list)) {
680 struct blkio_group *blkg = hlist_entry(blkcg->blkg_list.first,
681 struct blkio_group, blkcg_node);
682 struct request_queue *q = blkg->q;
684 if (spin_trylock(q->queue_lock)) {
686 spin_unlock(q->queue_lock);
688 spin_unlock_irq(&blkcg->lock);
690 spin_lock_irq(&blkcg->lock);
694 spin_unlock_irq(&blkcg->lock);
698 static void blkiocg_destroy(struct cgroup *cgroup)
700 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
702 if (blkcg != &blkio_root_cgroup)
706 static struct cgroup_subsys_state *blkiocg_create(struct cgroup *cgroup)
708 static atomic64_t id_seq = ATOMIC64_INIT(0);
709 struct blkio_cgroup *blkcg;
710 struct cgroup *parent = cgroup->parent;
713 blkcg = &blkio_root_cgroup;
717 blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL);
719 return ERR_PTR(-ENOMEM);
721 blkcg->weight = BLKIO_WEIGHT_DEFAULT;
722 blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
724 spin_lock_init(&blkcg->lock);
725 INIT_HLIST_HEAD(&blkcg->blkg_list);
731 * blkcg_init_queue - initialize blkcg part of request queue
732 * @q: request_queue to initialize
734 * Called from blk_alloc_queue_node(). Responsible for initializing blkcg
735 * part of new request_queue @q.
738 * 0 on success, -errno on failure.
740 int blkcg_init_queue(struct request_queue *q)
746 ret = blk_throtl_init(q);
750 mutex_lock(&all_q_mutex);
751 INIT_LIST_HEAD(&q->all_q_node);
752 list_add_tail(&q->all_q_node, &all_q_list);
753 mutex_unlock(&all_q_mutex);
759 * blkcg_drain_queue - drain blkcg part of request_queue
760 * @q: request_queue to drain
762 * Called from blk_drain_queue(). Responsible for draining blkcg part.
764 void blkcg_drain_queue(struct request_queue *q)
766 lockdep_assert_held(q->queue_lock);
772 * blkcg_exit_queue - exit and release blkcg part of request_queue
773 * @q: request_queue being released
775 * Called from blk_release_queue(). Responsible for exiting blkcg part.
777 void blkcg_exit_queue(struct request_queue *q)
779 mutex_lock(&all_q_mutex);
780 list_del_init(&q->all_q_node);
781 mutex_unlock(&all_q_mutex);
783 blkg_destroy_all(q, true);
789 * We cannot support shared io contexts, as we have no mean to support
790 * two tasks with the same ioc in two different groups without major rework
791 * of the main cic data structures. For now we allow a task to change
792 * its cgroup only if it's the only owner of its ioc.
794 static int blkiocg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
796 struct task_struct *task;
797 struct io_context *ioc;
800 /* task_lock() is needed to avoid races with exit_io_context() */
801 cgroup_taskset_for_each(task, cgrp, tset) {
803 ioc = task->io_context;
804 if (ioc && atomic_read(&ioc->nr_tasks) > 1)
813 static void blkcg_bypass_start(void)
814 __acquires(&all_q_mutex)
816 struct request_queue *q;
818 mutex_lock(&all_q_mutex);
820 list_for_each_entry(q, &all_q_list, all_q_node) {
821 blk_queue_bypass_start(q);
822 blkg_destroy_all(q, false);
826 static void blkcg_bypass_end(void)
827 __releases(&all_q_mutex)
829 struct request_queue *q;
831 list_for_each_entry(q, &all_q_list, all_q_node)
832 blk_queue_bypass_end(q);
834 mutex_unlock(&all_q_mutex);
837 struct cgroup_subsys blkio_subsys = {
839 .create = blkiocg_create,
840 .can_attach = blkiocg_can_attach,
841 .pre_destroy = blkiocg_pre_destroy,
842 .destroy = blkiocg_destroy,
843 .subsys_id = blkio_subsys_id,
844 .base_cftypes = blkio_files,
845 .module = THIS_MODULE,
847 EXPORT_SYMBOL_GPL(blkio_subsys);
849 void blkio_policy_register(struct blkio_policy_type *blkiop)
851 struct request_queue *q;
853 blkcg_bypass_start();
854 spin_lock(&blkio_list_lock);
856 BUG_ON(blkio_policy[blkiop->plid]);
857 blkio_policy[blkiop->plid] = blkiop;
858 list_add_tail(&blkiop->list, &blkio_list);
860 spin_unlock(&blkio_list_lock);
861 list_for_each_entry(q, &all_q_list, all_q_node)
862 update_root_blkg_pd(q, blkiop->plid);
866 WARN_ON(cgroup_add_cftypes(&blkio_subsys, blkiop->cftypes));
868 EXPORT_SYMBOL_GPL(blkio_policy_register);
870 void blkio_policy_unregister(struct blkio_policy_type *blkiop)
872 struct request_queue *q;
875 cgroup_rm_cftypes(&blkio_subsys, blkiop->cftypes);
877 blkcg_bypass_start();
878 spin_lock(&blkio_list_lock);
880 BUG_ON(blkio_policy[blkiop->plid] != blkiop);
881 blkio_policy[blkiop->plid] = NULL;
882 list_del_init(&blkiop->list);
884 spin_unlock(&blkio_list_lock);
885 list_for_each_entry(q, &all_q_list, all_q_node)
886 update_root_blkg_pd(q, blkiop->plid);
889 EXPORT_SYMBOL_GPL(blkio_policy_unregister);