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_MUTEX(blkcg_pol_mutex);
29 struct blkio_cgroup blkio_root_cgroup = { .cfq_weight = 2 * CFQ_WEIGHT_DEFAULT };
30 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
32 static struct blkio_policy_type *blkio_policy[BLKCG_MAX_POLS];
34 struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
36 return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
37 struct blkio_cgroup, css);
39 EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup);
41 static struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk)
43 return container_of(task_subsys_state(tsk, blkio_subsys_id),
44 struct blkio_cgroup, css);
47 struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio)
49 if (bio && bio->bi_css)
50 return container_of(bio->bi_css, struct blkio_cgroup, css);
51 return task_blkio_cgroup(current);
53 EXPORT_SYMBOL_GPL(bio_blkio_cgroup);
55 static bool blkcg_policy_enabled(struct request_queue *q,
56 const struct blkio_policy_type *pol)
58 return pol && test_bit(pol->plid, q->blkcg_pols);
61 static size_t blkg_pd_size(const struct blkio_policy_type *pol)
63 return sizeof(struct blkg_policy_data) + pol->pdata_size;
67 * blkg_free - free a blkg
70 * Free @blkg which may be partially allocated.
72 static void blkg_free(struct blkio_group *blkg)
79 for (i = 0; i < BLKCG_MAX_POLS; i++) {
80 struct blkio_policy_type *pol = blkio_policy[i];
81 struct blkg_policy_data *pd = blkg->pd[i];
86 if (pol && pol->ops.blkio_exit_group_fn)
87 pol->ops.blkio_exit_group_fn(blkg);
96 * blkg_alloc - allocate a blkg
97 * @blkcg: block cgroup the new blkg is associated with
98 * @q: request_queue the new blkg is associated with
100 * Allocate a new blkg assocating @blkcg and @q.
102 static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
103 struct request_queue *q)
105 struct blkio_group *blkg;
108 /* alloc and init base part */
109 blkg = kzalloc_node(sizeof(*blkg), GFP_ATOMIC, q->node);
114 INIT_LIST_HEAD(&blkg->q_node);
117 cgroup_path(blkcg->css.cgroup, blkg->path, sizeof(blkg->path));
119 for (i = 0; i < BLKCG_MAX_POLS; i++) {
120 struct blkio_policy_type *pol = blkio_policy[i];
121 struct blkg_policy_data *pd;
123 if (!blkcg_policy_enabled(q, pol))
126 /* alloc per-policy data and attach it to blkg */
127 pd = kzalloc_node(blkg_pd_size(pol), GFP_ATOMIC, q->node);
137 /* invoke per-policy init */
138 for (i = 0; i < BLKCG_MAX_POLS; i++) {
139 struct blkio_policy_type *pol = blkio_policy[i];
141 if (blkcg_policy_enabled(blkg->q, pol))
142 pol->ops.blkio_init_group_fn(blkg);
148 static struct blkio_group *__blkg_lookup(struct blkio_cgroup *blkcg,
149 struct request_queue *q)
151 struct blkio_group *blkg;
152 struct hlist_node *n;
154 hlist_for_each_entry_rcu(blkg, n, &blkcg->blkg_list, blkcg_node)
161 * blkg_lookup - lookup blkg for the specified blkcg - q pair
162 * @blkcg: blkcg of interest
163 * @q: request_queue of interest
165 * Lookup blkg for the @blkcg - @q pair. This function should be called
166 * under RCU read lock and is guaranteed to return %NULL if @q is bypassing
167 * - see blk_queue_bypass_start() for details.
169 struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
170 struct request_queue *q)
172 WARN_ON_ONCE(!rcu_read_lock_held());
174 if (unlikely(blk_queue_bypass(q)))
176 return __blkg_lookup(blkcg, q);
178 EXPORT_SYMBOL_GPL(blkg_lookup);
180 static struct blkio_group *__blkg_lookup_create(struct blkio_cgroup *blkcg,
181 struct request_queue *q)
182 __releases(q->queue_lock) __acquires(q->queue_lock)
184 struct blkio_group *blkg;
186 WARN_ON_ONCE(!rcu_read_lock_held());
187 lockdep_assert_held(q->queue_lock);
189 blkg = __blkg_lookup(blkcg, q);
193 /* blkg holds a reference to blkcg */
194 if (!css_tryget(&blkcg->css))
195 return ERR_PTR(-EINVAL);
198 * Allocate and initialize.
200 blkg = blkg_alloc(blkcg, q);
202 /* did alloc fail? */
203 if (unlikely(!blkg)) {
204 blkg = ERR_PTR(-ENOMEM);
209 spin_lock(&blkcg->lock);
210 hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
211 list_add(&blkg->q_node, &q->blkg_list);
212 spin_unlock(&blkcg->lock);
217 struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
218 struct request_queue *q)
221 * This could be the first entry point of blkcg implementation and
222 * we shouldn't allow anything to go through for a bypassing queue.
224 if (unlikely(blk_queue_bypass(q)))
225 return ERR_PTR(blk_queue_dead(q) ? -EINVAL : -EBUSY);
226 return __blkg_lookup_create(blkcg, q);
228 EXPORT_SYMBOL_GPL(blkg_lookup_create);
230 static void blkg_destroy(struct blkio_group *blkg)
232 struct request_queue *q = blkg->q;
233 struct blkio_cgroup *blkcg = blkg->blkcg;
235 lockdep_assert_held(q->queue_lock);
236 lockdep_assert_held(&blkcg->lock);
238 /* Something wrong if we are trying to remove same group twice */
239 WARN_ON_ONCE(list_empty(&blkg->q_node));
240 WARN_ON_ONCE(hlist_unhashed(&blkg->blkcg_node));
241 list_del_init(&blkg->q_node);
242 hlist_del_init_rcu(&blkg->blkcg_node);
245 * Put the reference taken at the time of creation so that when all
246 * queues are gone, group can be destroyed.
252 * blkg_destroy_all - destroy all blkgs associated with a request_queue
253 * @q: request_queue of interest
255 * Destroy all blkgs associated with @q.
257 static void blkg_destroy_all(struct request_queue *q)
259 struct blkio_group *blkg, *n;
261 spin_lock_irq(q->queue_lock);
263 list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
264 struct blkio_cgroup *blkcg = blkg->blkcg;
266 spin_lock(&blkcg->lock);
268 spin_unlock(&blkcg->lock);
271 spin_unlock_irq(q->queue_lock);
274 static void blkg_rcu_free(struct rcu_head *rcu_head)
276 blkg_free(container_of(rcu_head, struct blkio_group, rcu_head));
279 void __blkg_release(struct blkio_group *blkg)
281 /* release the extra blkcg reference this blkg has been holding */
282 css_put(&blkg->blkcg->css);
285 * A group is freed in rcu manner. But having an rcu lock does not
286 * mean that one can access all the fields of blkg and assume these
287 * are valid. For example, don't try to follow throtl_data and
288 * request queue links.
290 * Having a reference to blkg under an rcu allows acess to only
291 * values local to groups like group stats and group rate limits
293 call_rcu(&blkg->rcu_head, blkg_rcu_free);
295 EXPORT_SYMBOL_GPL(__blkg_release);
298 blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
300 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
301 struct blkio_group *blkg;
302 struct hlist_node *n;
305 mutex_lock(&blkcg_pol_mutex);
306 spin_lock_irq(&blkcg->lock);
309 * Note that stat reset is racy - it doesn't synchronize against
310 * stat updates. This is a debug feature which shouldn't exist
311 * anyway. If you get hit by a race, retry.
313 hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
314 for (i = 0; i < BLKCG_MAX_POLS; i++) {
315 struct blkio_policy_type *pol = blkio_policy[i];
317 if (blkcg_policy_enabled(blkg->q, pol) &&
318 pol->ops.blkio_reset_group_stats_fn)
319 pol->ops.blkio_reset_group_stats_fn(blkg);
323 spin_unlock_irq(&blkcg->lock);
324 mutex_unlock(&blkcg_pol_mutex);
328 static const char *blkg_dev_name(struct blkio_group *blkg)
330 /* some drivers (floppy) instantiate a queue w/o disk registered */
331 if (blkg->q->backing_dev_info.dev)
332 return dev_name(blkg->q->backing_dev_info.dev);
337 * blkcg_print_blkgs - helper for printing per-blkg data
338 * @sf: seq_file to print to
339 * @blkcg: blkcg of interest
340 * @prfill: fill function to print out a blkg
341 * @pol: policy in question
342 * @data: data to be passed to @prfill
343 * @show_total: to print out sum of prfill return values or not
345 * This function invokes @prfill on each blkg of @blkcg if pd for the
346 * policy specified by @pol exists. @prfill is invoked with @sf, the
347 * policy data and @data. If @show_total is %true, the sum of the return
348 * values from @prfill is printed with "Total" label at the end.
350 * This is to be used to construct print functions for
351 * cftype->read_seq_string method.
353 void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
354 u64 (*prfill)(struct seq_file *, void *, int),
355 const struct blkio_policy_type *pol, int data,
358 struct blkio_group *blkg;
359 struct hlist_node *n;
362 spin_lock_irq(&blkcg->lock);
363 hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
364 if (blkcg_policy_enabled(blkg->q, pol))
365 total += prfill(sf, blkg->pd[pol->plid]->pdata, data);
366 spin_unlock_irq(&blkcg->lock);
369 seq_printf(sf, "Total %llu\n", (unsigned long long)total);
371 EXPORT_SYMBOL_GPL(blkcg_print_blkgs);
374 * __blkg_prfill_u64 - prfill helper for a single u64 value
375 * @sf: seq_file to print to
376 * @pdata: policy private data of interest
379 * Print @v to @sf for the device assocaited with @pdata.
381 u64 __blkg_prfill_u64(struct seq_file *sf, void *pdata, u64 v)
383 const char *dname = blkg_dev_name(pdata_to_blkg(pdata));
388 seq_printf(sf, "%s %llu\n", dname, (unsigned long long)v);
391 EXPORT_SYMBOL_GPL(__blkg_prfill_u64);
394 * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
395 * @sf: seq_file to print to
396 * @pdata: policy private data of interest
397 * @rwstat: rwstat to print
399 * Print @rwstat to @sf for the device assocaited with @pdata.
401 u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
402 const struct blkg_rwstat *rwstat)
404 static const char *rwstr[] = {
405 [BLKG_RWSTAT_READ] = "Read",
406 [BLKG_RWSTAT_WRITE] = "Write",
407 [BLKG_RWSTAT_SYNC] = "Sync",
408 [BLKG_RWSTAT_ASYNC] = "Async",
410 const char *dname = blkg_dev_name(pdata_to_blkg(pdata));
417 for (i = 0; i < BLKG_RWSTAT_NR; i++)
418 seq_printf(sf, "%s %s %llu\n", dname, rwstr[i],
419 (unsigned long long)rwstat->cnt[i]);
421 v = rwstat->cnt[BLKG_RWSTAT_READ] + rwstat->cnt[BLKG_RWSTAT_WRITE];
422 seq_printf(sf, "%s Total %llu\n", dname, (unsigned long long)v);
427 * blkg_prfill_stat - prfill callback for blkg_stat
428 * @sf: seq_file to print to
429 * @pdata: policy private data of interest
430 * @off: offset to the blkg_stat in @pdata
432 * prfill callback for printing a blkg_stat.
434 u64 blkg_prfill_stat(struct seq_file *sf, void *pdata, int off)
436 return __blkg_prfill_u64(sf, pdata, blkg_stat_read(pdata + off));
438 EXPORT_SYMBOL_GPL(blkg_prfill_stat);
441 * blkg_prfill_rwstat - prfill callback for blkg_rwstat
442 * @sf: seq_file to print to
443 * @pdata: policy private data of interest
444 * @off: offset to the blkg_rwstat in @pdata
446 * prfill callback for printing a blkg_rwstat.
448 u64 blkg_prfill_rwstat(struct seq_file *sf, void *pdata, int off)
450 struct blkg_rwstat rwstat = blkg_rwstat_read(pdata + off);
452 return __blkg_prfill_rwstat(sf, pdata, &rwstat);
454 EXPORT_SYMBOL_GPL(blkg_prfill_rwstat);
457 * blkg_conf_prep - parse and prepare for per-blkg config update
458 * @blkcg: target block cgroup
459 * @pol: target policy
460 * @input: input string
461 * @ctx: blkg_conf_ctx to be filled
463 * Parse per-blkg config update from @input and initialize @ctx with the
464 * result. @ctx->blkg points to the blkg to be updated and @ctx->v the new
465 * value. This function returns with RCU read lock and queue lock held and
466 * must be paired with blkg_conf_finish().
468 int blkg_conf_prep(struct blkio_cgroup *blkcg,
469 const struct blkio_policy_type *pol, const char *input,
470 struct blkg_conf_ctx *ctx)
471 __acquires(rcu) __acquires(disk->queue->queue_lock)
473 struct gendisk *disk;
474 struct blkio_group *blkg;
475 unsigned int major, minor;
476 unsigned long long v;
479 if (sscanf(input, "%u:%u %llu", &major, &minor, &v) != 3)
482 disk = get_gendisk(MKDEV(major, minor), &part);
487 spin_lock_irq(disk->queue->queue_lock);
489 if (blkcg_policy_enabled(disk->queue, pol))
490 blkg = blkg_lookup_create(blkcg, disk->queue);
492 blkg = ERR_PTR(-EINVAL);
497 spin_unlock_irq(disk->queue->queue_lock);
500 * If queue was bypassing, we should retry. Do so after a
501 * short msleep(). It isn't strictly necessary but queue
502 * can be bypassing for some time and it's always nice to
503 * avoid busy looping.
507 ret = restart_syscall();
517 EXPORT_SYMBOL_GPL(blkg_conf_prep);
520 * blkg_conf_finish - finish up per-blkg config update
521 * @ctx: blkg_conf_ctx intiailized by blkg_conf_prep()
523 * Finish up after per-blkg config update. This function must be paired
524 * with blkg_conf_prep().
526 void blkg_conf_finish(struct blkg_conf_ctx *ctx)
527 __releases(ctx->disk->queue->queue_lock) __releases(rcu)
529 spin_unlock_irq(ctx->disk->queue->queue_lock);
533 EXPORT_SYMBOL_GPL(blkg_conf_finish);
535 struct cftype blkio_files[] = {
537 .name = "reset_stats",
538 .write_u64 = blkiocg_reset_stats,
544 * blkiocg_pre_destroy - cgroup pre_destroy callback
545 * @cgroup: cgroup of interest
547 * This function is called when @cgroup is about to go away and responsible
548 * for shooting down all blkgs associated with @cgroup. blkgs should be
549 * removed while holding both q and blkcg locks. As blkcg lock is nested
550 * inside q lock, this function performs reverse double lock dancing.
552 * This is the blkcg counterpart of ioc_release_fn().
554 static int blkiocg_pre_destroy(struct cgroup *cgroup)
556 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
558 spin_lock_irq(&blkcg->lock);
560 while (!hlist_empty(&blkcg->blkg_list)) {
561 struct blkio_group *blkg = hlist_entry(blkcg->blkg_list.first,
562 struct blkio_group, blkcg_node);
563 struct request_queue *q = blkg->q;
565 if (spin_trylock(q->queue_lock)) {
567 spin_unlock(q->queue_lock);
569 spin_unlock_irq(&blkcg->lock);
571 spin_lock_irq(&blkcg->lock);
575 spin_unlock_irq(&blkcg->lock);
579 static void blkiocg_destroy(struct cgroup *cgroup)
581 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
583 if (blkcg != &blkio_root_cgroup)
587 static struct cgroup_subsys_state *blkiocg_create(struct cgroup *cgroup)
589 static atomic64_t id_seq = ATOMIC64_INIT(0);
590 struct blkio_cgroup *blkcg;
591 struct cgroup *parent = cgroup->parent;
594 blkcg = &blkio_root_cgroup;
598 blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL);
600 return ERR_PTR(-ENOMEM);
602 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
603 blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
605 spin_lock_init(&blkcg->lock);
606 INIT_HLIST_HEAD(&blkcg->blkg_list);
612 * blkcg_init_queue - initialize blkcg part of request queue
613 * @q: request_queue to initialize
615 * Called from blk_alloc_queue_node(). Responsible for initializing blkcg
616 * part of new request_queue @q.
619 * 0 on success, -errno on failure.
621 int blkcg_init_queue(struct request_queue *q)
625 return blk_throtl_init(q);
629 * blkcg_drain_queue - drain blkcg part of request_queue
630 * @q: request_queue to drain
632 * Called from blk_drain_queue(). Responsible for draining blkcg part.
634 void blkcg_drain_queue(struct request_queue *q)
636 lockdep_assert_held(q->queue_lock);
642 * blkcg_exit_queue - exit and release blkcg part of request_queue
643 * @q: request_queue being released
645 * Called from blk_release_queue(). Responsible for exiting blkcg part.
647 void blkcg_exit_queue(struct request_queue *q)
654 * We cannot support shared io contexts, as we have no mean to support
655 * two tasks with the same ioc in two different groups without major rework
656 * of the main cic data structures. For now we allow a task to change
657 * its cgroup only if it's the only owner of its ioc.
659 static int blkiocg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
661 struct task_struct *task;
662 struct io_context *ioc;
665 /* task_lock() is needed to avoid races with exit_io_context() */
666 cgroup_taskset_for_each(task, cgrp, tset) {
668 ioc = task->io_context;
669 if (ioc && atomic_read(&ioc->nr_tasks) > 1)
678 struct cgroup_subsys blkio_subsys = {
680 .create = blkiocg_create,
681 .can_attach = blkiocg_can_attach,
682 .pre_destroy = blkiocg_pre_destroy,
683 .destroy = blkiocg_destroy,
684 .subsys_id = blkio_subsys_id,
685 .base_cftypes = blkio_files,
686 .module = THIS_MODULE,
688 EXPORT_SYMBOL_GPL(blkio_subsys);
691 * blkcg_activate_policy - activate a blkcg policy on a request_queue
692 * @q: request_queue of interest
693 * @pol: blkcg policy to activate
695 * Activate @pol on @q. Requires %GFP_KERNEL context. @q goes through
696 * bypass mode to populate its blkgs with policy_data for @pol.
698 * Activation happens with @q bypassed, so nobody would be accessing blkgs
699 * from IO path. Update of each blkg is protected by both queue and blkcg
700 * locks so that holding either lock and testing blkcg_policy_enabled() is
701 * always enough for dereferencing policy data.
703 * The caller is responsible for synchronizing [de]activations and policy
704 * [un]registerations. Returns 0 on success, -errno on failure.
706 int blkcg_activate_policy(struct request_queue *q,
707 const struct blkio_policy_type *pol)
710 struct blkio_group *blkg;
711 struct blkg_policy_data *pd, *n;
714 if (blkcg_policy_enabled(q, pol))
717 blk_queue_bypass_start(q);
719 /* make sure the root blkg exists and count the existing blkgs */
720 spin_lock_irq(q->queue_lock);
723 blkg = __blkg_lookup_create(&blkio_root_cgroup, q);
732 list_for_each_entry(blkg, &q->blkg_list, q_node)
735 spin_unlock_irq(q->queue_lock);
737 /* allocate policy_data for all existing blkgs */
739 pd = kzalloc_node(blkg_pd_size(pol), GFP_KERNEL, q->node);
744 list_add_tail(&pd->alloc_node, &pds);
748 * Install the allocated pds. With @q bypassing, no new blkg
749 * should have been created while the queue lock was dropped.
751 spin_lock_irq(q->queue_lock);
753 list_for_each_entry(blkg, &q->blkg_list, q_node) {
754 if (WARN_ON(list_empty(&pds))) {
755 /* umm... this shouldn't happen, just abort */
759 pd = list_first_entry(&pds, struct blkg_policy_data, alloc_node);
760 list_del_init(&pd->alloc_node);
762 /* grab blkcg lock too while installing @pd on @blkg */
763 spin_lock(&blkg->blkcg->lock);
765 blkg->pd[pol->plid] = pd;
767 pol->ops.blkio_init_group_fn(blkg);
769 spin_unlock(&blkg->blkcg->lock);
772 __set_bit(pol->plid, q->blkcg_pols);
775 spin_unlock_irq(q->queue_lock);
777 blk_queue_bypass_end(q);
778 list_for_each_entry_safe(pd, n, &pds, alloc_node)
782 EXPORT_SYMBOL_GPL(blkcg_activate_policy);
785 * blkcg_deactivate_policy - deactivate a blkcg policy on a request_queue
786 * @q: request_queue of interest
787 * @pol: blkcg policy to deactivate
789 * Deactivate @pol on @q. Follows the same synchronization rules as
790 * blkcg_activate_policy().
792 void blkcg_deactivate_policy(struct request_queue *q,
793 const struct blkio_policy_type *pol)
795 struct blkio_group *blkg;
797 if (!blkcg_policy_enabled(q, pol))
800 blk_queue_bypass_start(q);
801 spin_lock_irq(q->queue_lock);
803 __clear_bit(pol->plid, q->blkcg_pols);
805 list_for_each_entry(blkg, &q->blkg_list, q_node) {
806 /* grab blkcg lock too while removing @pd from @blkg */
807 spin_lock(&blkg->blkcg->lock);
809 if (pol->ops.blkio_exit_group_fn)
810 pol->ops.blkio_exit_group_fn(blkg);
812 kfree(blkg->pd[pol->plid]);
813 blkg->pd[pol->plid] = NULL;
815 spin_unlock(&blkg->blkcg->lock);
818 spin_unlock_irq(q->queue_lock);
819 blk_queue_bypass_end(q);
821 EXPORT_SYMBOL_GPL(blkcg_deactivate_policy);
824 * blkio_policy_register - register a blkcg policy
825 * @blkiop: blkcg policy to register
827 * Register @blkiop with blkcg core. Might sleep and @blkiop may be
828 * modified on successful registration. Returns 0 on success and -errno on
831 int blkio_policy_register(struct blkio_policy_type *blkiop)
835 mutex_lock(&blkcg_pol_mutex);
837 /* find an empty slot */
839 for (i = 0; i < BLKCG_MAX_POLS; i++)
840 if (!blkio_policy[i])
842 if (i >= BLKCG_MAX_POLS)
845 /* register and update blkgs */
847 blkio_policy[i] = blkiop;
849 /* everything is in place, add intf files for the new policy */
851 WARN_ON(cgroup_add_cftypes(&blkio_subsys, blkiop->cftypes));
854 mutex_unlock(&blkcg_pol_mutex);
857 EXPORT_SYMBOL_GPL(blkio_policy_register);
860 * blkiop_policy_unregister - unregister a blkcg policy
861 * @blkiop: blkcg policy to unregister
863 * Undo blkio_policy_register(@blkiop). Might sleep.
865 void blkio_policy_unregister(struct blkio_policy_type *blkiop)
867 mutex_lock(&blkcg_pol_mutex);
869 if (WARN_ON(blkio_policy[blkiop->plid] != blkiop))
872 /* kill the intf files first */
874 cgroup_rm_cftypes(&blkio_subsys, blkiop->cftypes);
876 /* unregister and update blkgs */
877 blkio_policy[blkiop->plid] = NULL;
879 mutex_unlock(&blkcg_pol_mutex);
881 EXPORT_SYMBOL_GPL(blkio_policy_unregister);