/* * Common Block IO controller cgroup interface * * Based on ideas and code from CFQ, CFS and BFQ: * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk> * * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it> * Paolo Valente <paolo.valente@unimore.it> * * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com> * Nauman Rafique <nauman@google.com> * * For policy-specific per-blkcg data: * Copyright (C) 2015 Paolo Valente <paolo.valente@unimore.it> * Arianna Avanzini <avanzini.arianna@gmail.com> */#include<linux/ioprio.h>#include<linux/kdev_t.h>#include<linux/module.h>#include<linux/err.h>#include<linux/blkdev.h>#include<linux/backing-dev.h>#include<linux/slab.h>#include<linux/genhd.h>#include<linux/delay.h>#include<linux/atomic.h>#include<linux/ctype.h>#include<linux/blk-cgroup.h>#include"blk.h"#define MAX_KEY_LEN 100/* * blkcg_pol_mutex protects blkcg_policy[] and policy [de]activation. * blkcg_pol_register_mutex nests outside of it and synchronizes entire * policy [un]register operations including cgroup file additions / * removals. Putting cgroup file registration outside blkcg_pol_mutex * allows grabbing it from cgroup callbacks. */staticDEFINE_MUTEX(blkcg_pol_register_mutex);staticDEFINE_MUTEX(blkcg_pol_mutex);structblkcgblkcg_root;EXPORT_SYMBOL_GPL(blkcg_root);structcgroup_subsys_state*constblkcg_root_css=&blkcg_root.css;staticstructblkcg_policy*blkcg_policy[BLKCG_MAX_POLS];staticLIST_HEAD(all_blkcgs);/* protected by blkcg_pol_mutex */staticboolblkcg_policy_enabled(structrequest_queue*q,conststructblkcg_policy*pol){returnpol&&test_bit(pol->plid,q->blkcg_pols);}/** * blkg_free - free a blkg * @blkg: blkg to free * * Free @blkg which may be partially allocated. */staticvoidblkg_free(structblkcg_gq*blkg){inti;if(!blkg)return;for(i=0;i<BLKCG_MAX_POLS;i++)if(blkg->pd[i])blkcg_policy[i]->pd_free_fn(blkg->pd[i]);if(blkg->blkcg!=&blkcg_root)blk_exit_rl(&blkg->rl);blkg_rwstat_exit(&blkg->stat_ios);blkg_rwstat_exit(&blkg->stat_bytes);kfree(blkg);}/** * blkg_alloc - allocate a blkg * @blkcg: block cgroup the new blkg is associated with * @q: request_queue the new blkg is associated with * @gfp_mask: allocation mask to use * * Allocate a new blkg assocating @blkcg and @q. */staticstructblkcg_gq*blkg_alloc(structblkcg*blkcg,structrequest_queue*q,gfp_tgfp_mask){structblkcg_gq*blkg;inti;/* alloc and init base part */blkg=kzalloc_node(