xref: /linux-6.15/include/linux/blk-cgroup.h (revision f12c74ca)
1eea8f41cSTejun Heo #ifndef _BLK_CGROUP_H
2eea8f41cSTejun Heo #define _BLK_CGROUP_H
3eea8f41cSTejun Heo /*
4eea8f41cSTejun Heo  * Common Block IO controller cgroup interface
5eea8f41cSTejun Heo  *
6eea8f41cSTejun Heo  * Based on ideas and code from CFQ, CFS and BFQ:
7eea8f41cSTejun Heo  * Copyright (C) 2003 Jens Axboe <[email protected]>
8eea8f41cSTejun Heo  *
9eea8f41cSTejun Heo  * Copyright (C) 2008 Fabio Checconi <[email protected]>
10eea8f41cSTejun Heo  *		      Paolo Valente <[email protected]>
11eea8f41cSTejun Heo  *
12eea8f41cSTejun Heo  * Copyright (C) 2009 Vivek Goyal <[email protected]>
13eea8f41cSTejun Heo  * 	              Nauman Rafique <[email protected]>
14eea8f41cSTejun Heo  */
15eea8f41cSTejun Heo 
16eea8f41cSTejun Heo #include <linux/cgroup.h>
1724bdb8efSTejun Heo #include <linux/percpu_counter.h>
18eea8f41cSTejun Heo #include <linux/seq_file.h>
19eea8f41cSTejun Heo #include <linux/radix-tree.h>
20eea8f41cSTejun Heo #include <linux/blkdev.h>
21eea8f41cSTejun Heo #include <linux/atomic.h>
22eea8f41cSTejun Heo 
2324bdb8efSTejun Heo /* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */
2424bdb8efSTejun Heo #define BLKG_STAT_CPU_BATCH	(INT_MAX / 2)
2524bdb8efSTejun Heo 
26eea8f41cSTejun Heo /* Max limits for throttle policy */
27eea8f41cSTejun Heo #define THROTL_IOPS_MAX		UINT_MAX
28eea8f41cSTejun Heo 
29eea8f41cSTejun Heo #ifdef CONFIG_BLK_CGROUP
30eea8f41cSTejun Heo 
31eea8f41cSTejun Heo enum blkg_rwstat_type {
32eea8f41cSTejun Heo 	BLKG_RWSTAT_READ,
33eea8f41cSTejun Heo 	BLKG_RWSTAT_WRITE,
34eea8f41cSTejun Heo 	BLKG_RWSTAT_SYNC,
35eea8f41cSTejun Heo 	BLKG_RWSTAT_ASYNC,
36eea8f41cSTejun Heo 
37eea8f41cSTejun Heo 	BLKG_RWSTAT_NR,
38eea8f41cSTejun Heo 	BLKG_RWSTAT_TOTAL = BLKG_RWSTAT_NR,
39eea8f41cSTejun Heo };
40eea8f41cSTejun Heo 
41eea8f41cSTejun Heo struct blkcg_gq;
42eea8f41cSTejun Heo 
43eea8f41cSTejun Heo struct blkcg {
44eea8f41cSTejun Heo 	struct cgroup_subsys_state	css;
45eea8f41cSTejun Heo 	spinlock_t			lock;
46eea8f41cSTejun Heo 
47eea8f41cSTejun Heo 	struct radix_tree_root		blkg_tree;
48eea8f41cSTejun Heo 	struct blkcg_gq			*blkg_hint;
49eea8f41cSTejun Heo 	struct hlist_head		blkg_list;
50eea8f41cSTejun Heo 
5181437648STejun Heo 	struct blkcg_policy_data	*cpd[BLKCG_MAX_POLS];
5252ebea74STejun Heo 
537876f930STejun Heo 	struct list_head		all_blkcgs_node;
5452ebea74STejun Heo #ifdef CONFIG_CGROUP_WRITEBACK
5552ebea74STejun Heo 	struct list_head		cgwb_list;
5652ebea74STejun Heo #endif
57eea8f41cSTejun Heo };
58eea8f41cSTejun Heo 
59e6269c44STejun Heo /*
60e6269c44STejun Heo  * blkg_[rw]stat->aux_cnt is excluded for local stats but included for
6124bdb8efSTejun Heo  * recursive.  Used to carry stats of dead children, and, for blkg_rwstat,
6224bdb8efSTejun Heo  * to carry result values from read and sum operations.
63e6269c44STejun Heo  */
64eea8f41cSTejun Heo struct blkg_stat {
6524bdb8efSTejun Heo 	struct percpu_counter		cpu_cnt;
66e6269c44STejun Heo 	atomic64_t			aux_cnt;
67eea8f41cSTejun Heo };
68eea8f41cSTejun Heo 
69eea8f41cSTejun Heo struct blkg_rwstat {
7024bdb8efSTejun Heo 	struct percpu_counter		cpu_cnt[BLKG_RWSTAT_NR];
71e6269c44STejun Heo 	atomic64_t			aux_cnt[BLKG_RWSTAT_NR];
72eea8f41cSTejun Heo };
73eea8f41cSTejun Heo 
74eea8f41cSTejun Heo /*
75eea8f41cSTejun Heo  * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
76eea8f41cSTejun Heo  * request_queue (q).  This is used by blkcg policies which need to track
77eea8f41cSTejun Heo  * information per blkcg - q pair.
78eea8f41cSTejun Heo  *
79001bea73STejun Heo  * There can be multiple active blkcg policies and each blkg:policy pair is
80001bea73STejun Heo  * represented by a blkg_policy_data which is allocated and freed by each
81001bea73STejun Heo  * policy's pd_alloc/free_fn() methods.  A policy can allocate private data
82001bea73STejun Heo  * area by allocating larger data structure which embeds blkg_policy_data
83001bea73STejun Heo  * at the beginning.
84eea8f41cSTejun Heo  */
85eea8f41cSTejun Heo struct blkg_policy_data {
86eea8f41cSTejun Heo 	/* the blkg and policy id this per-policy data belongs to */
87eea8f41cSTejun Heo 	struct blkcg_gq			*blkg;
88eea8f41cSTejun Heo 	int				plid;
89eea8f41cSTejun Heo };
90eea8f41cSTejun Heo 
91e4bc13adSLinus Torvalds /*
92e4a9bde9STejun Heo  * Policies that need to keep per-blkcg data which is independent from any
93e4a9bde9STejun Heo  * request_queue associated to it should implement cpd_alloc/free_fn()
94e4a9bde9STejun Heo  * methods.  A policy can allocate private data area by allocating larger
95e4a9bde9STejun Heo  * data structure which embeds blkcg_policy_data at the beginning.
96e4a9bde9STejun Heo  * cpd_init() is invoked to let each policy handle per-blkcg data.
97e4bc13adSLinus Torvalds  */
98e4bc13adSLinus Torvalds struct blkcg_policy_data {
9981437648STejun Heo 	/* the blkcg and policy id this per-policy data belongs to */
10081437648STejun Heo 	struct blkcg			*blkcg;
101e4bc13adSLinus Torvalds 	int				plid;
102e4bc13adSLinus Torvalds };
103e4bc13adSLinus Torvalds 
104eea8f41cSTejun Heo /* association between a blk cgroup and a request queue */
105eea8f41cSTejun Heo struct blkcg_gq {
106eea8f41cSTejun Heo 	/* Pointer to the associated request_queue */
107eea8f41cSTejun Heo 	struct request_queue		*q;
108eea8f41cSTejun Heo 	struct list_head		q_node;
109eea8f41cSTejun Heo 	struct hlist_node		blkcg_node;
110eea8f41cSTejun Heo 	struct blkcg			*blkcg;
111eea8f41cSTejun Heo 
112ce7acfeaSTejun Heo 	/*
113ce7acfeaSTejun Heo 	 * Each blkg gets congested separately and the congestion state is
114ce7acfeaSTejun Heo 	 * propagated to the matching bdi_writeback_congested.
115ce7acfeaSTejun Heo 	 */
116ce7acfeaSTejun Heo 	struct bdi_writeback_congested	*wb_congested;
117ce7acfeaSTejun Heo 
118eea8f41cSTejun Heo 	/* all non-root blkcg_gq's are guaranteed to have access to parent */
119eea8f41cSTejun Heo 	struct blkcg_gq			*parent;
120eea8f41cSTejun Heo 
121eea8f41cSTejun Heo 	/* request allocation list for this blkcg-q pair */
122eea8f41cSTejun Heo 	struct request_list		rl;
123eea8f41cSTejun Heo 
124eea8f41cSTejun Heo 	/* reference count */
125eea8f41cSTejun Heo 	atomic_t			refcnt;
126eea8f41cSTejun Heo 
127eea8f41cSTejun Heo 	/* is this blkg online? protected by both blkcg and q locks */
128eea8f41cSTejun Heo 	bool				online;
129eea8f41cSTejun Heo 
130eea8f41cSTejun Heo 	struct blkg_policy_data		*pd[BLKCG_MAX_POLS];
131eea8f41cSTejun Heo 
132eea8f41cSTejun Heo 	struct rcu_head			rcu_head;
133eea8f41cSTejun Heo };
134eea8f41cSTejun Heo 
135e4a9bde9STejun Heo typedef struct blkcg_policy_data *(blkcg_pol_alloc_cpd_fn)(gfp_t gfp);
13681437648STejun Heo typedef void (blkcg_pol_init_cpd_fn)(struct blkcg_policy_data *cpd);
137e4a9bde9STejun Heo typedef void (blkcg_pol_free_cpd_fn)(struct blkcg_policy_data *cpd);
138001bea73STejun Heo typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn)(gfp_t gfp, int node);
139a9520cd6STejun Heo typedef void (blkcg_pol_init_pd_fn)(struct blkg_policy_data *pd);
140a9520cd6STejun Heo typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd);
141a9520cd6STejun Heo typedef void (blkcg_pol_offline_pd_fn)(struct blkg_policy_data *pd);
142001bea73STejun Heo typedef void (blkcg_pol_free_pd_fn)(struct blkg_policy_data *pd);
143a9520cd6STejun Heo typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkg_policy_data *pd);
144eea8f41cSTejun Heo 
145eea8f41cSTejun Heo struct blkcg_policy {
146eea8f41cSTejun Heo 	int				plid;
147eea8f41cSTejun Heo 	/* cgroup files for the policy */
148eea8f41cSTejun Heo 	struct cftype			*cftypes;
149eea8f41cSTejun Heo 
150eea8f41cSTejun Heo 	/* operations */
151e4a9bde9STejun Heo 	blkcg_pol_alloc_cpd_fn		*cpd_alloc_fn;
152e4bc13adSLinus Torvalds 	blkcg_pol_init_cpd_fn		*cpd_init_fn;
153e4a9bde9STejun Heo 	blkcg_pol_free_cpd_fn		*cpd_free_fn;
154e4a9bde9STejun Heo 
155001bea73STejun Heo 	blkcg_pol_alloc_pd_fn		*pd_alloc_fn;
156eea8f41cSTejun Heo 	blkcg_pol_init_pd_fn		*pd_init_fn;
157eea8f41cSTejun Heo 	blkcg_pol_online_pd_fn		*pd_online_fn;
158eea8f41cSTejun Heo 	blkcg_pol_offline_pd_fn		*pd_offline_fn;
159001bea73STejun Heo 	blkcg_pol_free_pd_fn		*pd_free_fn;
160eea8f41cSTejun Heo 	blkcg_pol_reset_pd_stats_fn	*pd_reset_stats_fn;
161eea8f41cSTejun Heo };
162eea8f41cSTejun Heo 
163eea8f41cSTejun Heo extern struct blkcg blkcg_root;
164496d5e75STejun Heo extern struct cgroup_subsys_state * const blkcg_root_css;
165eea8f41cSTejun Heo 
16624f29046STejun Heo struct blkcg_gq *blkg_lookup_slowpath(struct blkcg *blkcg,
16724f29046STejun Heo 				      struct request_queue *q, bool update_hint);
168eea8f41cSTejun Heo struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
169eea8f41cSTejun Heo 				    struct request_queue *q);
170eea8f41cSTejun Heo int blkcg_init_queue(struct request_queue *q);
171eea8f41cSTejun Heo void blkcg_drain_queue(struct request_queue *q);
172eea8f41cSTejun Heo void blkcg_exit_queue(struct request_queue *q);
173eea8f41cSTejun Heo 
174eea8f41cSTejun Heo /* Blkio controller policy registration */
175eea8f41cSTejun Heo int blkcg_policy_register(struct blkcg_policy *pol);
176eea8f41cSTejun Heo void blkcg_policy_unregister(struct blkcg_policy *pol);
177eea8f41cSTejun Heo int blkcg_activate_policy(struct request_queue *q,
178eea8f41cSTejun Heo 			  const struct blkcg_policy *pol);
179eea8f41cSTejun Heo void blkcg_deactivate_policy(struct request_queue *q,
180eea8f41cSTejun Heo 			     const struct blkcg_policy *pol);
181eea8f41cSTejun Heo 
182eea8f41cSTejun Heo void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
183eea8f41cSTejun Heo 		       u64 (*prfill)(struct seq_file *,
184eea8f41cSTejun Heo 				     struct blkg_policy_data *, int),
185eea8f41cSTejun Heo 		       const struct blkcg_policy *pol, int data,
186eea8f41cSTejun Heo 		       bool show_total);
187eea8f41cSTejun Heo u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v);
188eea8f41cSTejun Heo u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
189eea8f41cSTejun Heo 			 const struct blkg_rwstat *rwstat);
190eea8f41cSTejun Heo u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd, int off);
191eea8f41cSTejun Heo u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
192eea8f41cSTejun Heo 		       int off);
193eea8f41cSTejun Heo 
194*f12c74caSTejun Heo u64 blkg_stat_recursive_sum(struct blkcg_gq *blkg,
195*f12c74caSTejun Heo 			    struct blkcg_policy *pol, int off);
196*f12c74caSTejun Heo struct blkg_rwstat blkg_rwstat_recursive_sum(struct blkcg_gq *blkg,
197*f12c74caSTejun Heo 					     struct blkcg_policy *pol, int off);
198eea8f41cSTejun Heo 
199eea8f41cSTejun Heo struct blkg_conf_ctx {
200eea8f41cSTejun Heo 	struct gendisk			*disk;
201eea8f41cSTejun Heo 	struct blkcg_gq			*blkg;
202eea8f41cSTejun Heo 	u64				v;
203eea8f41cSTejun Heo };
204eea8f41cSTejun Heo 
205eea8f41cSTejun Heo int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
206eea8f41cSTejun Heo 		   const char *input, struct blkg_conf_ctx *ctx);
207eea8f41cSTejun Heo void blkg_conf_finish(struct blkg_conf_ctx *ctx);
208eea8f41cSTejun Heo 
209eea8f41cSTejun Heo 
210eea8f41cSTejun Heo static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
211eea8f41cSTejun Heo {
212eea8f41cSTejun Heo 	return css ? container_of(css, struct blkcg, css) : NULL;
213eea8f41cSTejun Heo }
214eea8f41cSTejun Heo 
215eea8f41cSTejun Heo static inline struct blkcg *task_blkcg(struct task_struct *tsk)
216eea8f41cSTejun Heo {
217eea8f41cSTejun Heo 	return css_to_blkcg(task_css(tsk, blkio_cgrp_id));
218eea8f41cSTejun Heo }
219eea8f41cSTejun Heo 
220eea8f41cSTejun Heo static inline struct blkcg *bio_blkcg(struct bio *bio)
221eea8f41cSTejun Heo {
222eea8f41cSTejun Heo 	if (bio && bio->bi_css)
223eea8f41cSTejun Heo 		return css_to_blkcg(bio->bi_css);
224eea8f41cSTejun Heo 	return task_blkcg(current);
225eea8f41cSTejun Heo }
226eea8f41cSTejun Heo 
227fd383c2dSTejun Heo static inline struct cgroup_subsys_state *
228fd383c2dSTejun Heo task_get_blkcg_css(struct task_struct *task)
229fd383c2dSTejun Heo {
230fd383c2dSTejun Heo 	return task_get_css(task, blkio_cgrp_id);
231fd383c2dSTejun Heo }
232fd383c2dSTejun Heo 
233eea8f41cSTejun Heo /**
234eea8f41cSTejun Heo  * blkcg_parent - get the parent of a blkcg
235eea8f41cSTejun Heo  * @blkcg: blkcg of interest
236eea8f41cSTejun Heo  *
237eea8f41cSTejun Heo  * Return the parent blkcg of @blkcg.  Can be called anytime.
238eea8f41cSTejun Heo  */
239eea8f41cSTejun Heo static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
240eea8f41cSTejun Heo {
241eea8f41cSTejun Heo 	return css_to_blkcg(blkcg->css.parent);
242eea8f41cSTejun Heo }
243eea8f41cSTejun Heo 
244eea8f41cSTejun Heo /**
24524f29046STejun Heo  * __blkg_lookup - internal version of blkg_lookup()
24624f29046STejun Heo  * @blkcg: blkcg of interest
24724f29046STejun Heo  * @q: request_queue of interest
24824f29046STejun Heo  * @update_hint: whether to update lookup hint with the result or not
24924f29046STejun Heo  *
25024f29046STejun Heo  * This is internal version and shouldn't be used by policy
25124f29046STejun Heo  * implementations.  Looks up blkgs for the @blkcg - @q pair regardless of
25224f29046STejun Heo  * @q's bypass state.  If @update_hint is %true, the caller should be
25324f29046STejun Heo  * holding @q->queue_lock and lookup hint is updated on success.
25424f29046STejun Heo  */
25524f29046STejun Heo static inline struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
25624f29046STejun Heo 					     struct request_queue *q,
25724f29046STejun Heo 					     bool update_hint)
25824f29046STejun Heo {
25924f29046STejun Heo 	struct blkcg_gq *blkg;
26024f29046STejun Heo 
26185b6bc9dSTejun Heo 	if (blkcg == &blkcg_root)
26285b6bc9dSTejun Heo 		return q->root_blkg;
26385b6bc9dSTejun Heo 
26424f29046STejun Heo 	blkg = rcu_dereference(blkcg->blkg_hint);
26524f29046STejun Heo 	if (blkg && blkg->q == q)
26624f29046STejun Heo 		return blkg;
26724f29046STejun Heo 
26824f29046STejun Heo 	return blkg_lookup_slowpath(blkcg, q, update_hint);
26924f29046STejun Heo }
27024f29046STejun Heo 
27124f29046STejun Heo /**
27224f29046STejun Heo  * blkg_lookup - lookup blkg for the specified blkcg - q pair
27324f29046STejun Heo  * @blkcg: blkcg of interest
27424f29046STejun Heo  * @q: request_queue of interest
27524f29046STejun Heo  *
27624f29046STejun Heo  * Lookup blkg for the @blkcg - @q pair.  This function should be called
27724f29046STejun Heo  * under RCU read lock and is guaranteed to return %NULL if @q is bypassing
27824f29046STejun Heo  * - see blk_queue_bypass_start() for details.
27924f29046STejun Heo  */
28024f29046STejun Heo static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
28124f29046STejun Heo 					   struct request_queue *q)
28224f29046STejun Heo {
28324f29046STejun Heo 	WARN_ON_ONCE(!rcu_read_lock_held());
28424f29046STejun Heo 
28524f29046STejun Heo 	if (unlikely(blk_queue_bypass(q)))
28624f29046STejun Heo 		return NULL;
28724f29046STejun Heo 	return __blkg_lookup(blkcg, q, false);
28824f29046STejun Heo }
28924f29046STejun Heo 
29024f29046STejun Heo /**
291eea8f41cSTejun Heo  * blkg_to_pdata - get policy private data
292eea8f41cSTejun Heo  * @blkg: blkg of interest
293eea8f41cSTejun Heo  * @pol: policy of interest
294eea8f41cSTejun Heo  *
295eea8f41cSTejun Heo  * Return pointer to private data associated with the @blkg-@pol pair.
296eea8f41cSTejun Heo  */
297eea8f41cSTejun Heo static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
298eea8f41cSTejun Heo 						  struct blkcg_policy *pol)
299eea8f41cSTejun Heo {
300eea8f41cSTejun Heo 	return blkg ? blkg->pd[pol->plid] : NULL;
301eea8f41cSTejun Heo }
302eea8f41cSTejun Heo 
303e4bc13adSLinus Torvalds static inline struct blkcg_policy_data *blkcg_to_cpd(struct blkcg *blkcg,
304e4bc13adSLinus Torvalds 						     struct blkcg_policy *pol)
305e4bc13adSLinus Torvalds {
30681437648STejun Heo 	return blkcg ? blkcg->cpd[pol->plid] : NULL;
307e4bc13adSLinus Torvalds }
308e4bc13adSLinus Torvalds 
309eea8f41cSTejun Heo /**
310eea8f41cSTejun Heo  * pdata_to_blkg - get blkg associated with policy private data
311eea8f41cSTejun Heo  * @pd: policy private data of interest
312eea8f41cSTejun Heo  *
313eea8f41cSTejun Heo  * @pd is policy private data.  Determine the blkg it's associated with.
314eea8f41cSTejun Heo  */
315eea8f41cSTejun Heo static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd)
316eea8f41cSTejun Heo {
317eea8f41cSTejun Heo 	return pd ? pd->blkg : NULL;
318eea8f41cSTejun Heo }
319eea8f41cSTejun Heo 
32081437648STejun Heo static inline struct blkcg *cpd_to_blkcg(struct blkcg_policy_data *cpd)
32181437648STejun Heo {
32281437648STejun Heo 	return cpd ? cpd->blkcg : NULL;
32381437648STejun Heo }
32481437648STejun Heo 
325eea8f41cSTejun Heo /**
326eea8f41cSTejun Heo  * blkg_path - format cgroup path of blkg
327eea8f41cSTejun Heo  * @blkg: blkg of interest
328eea8f41cSTejun Heo  * @buf: target buffer
329eea8f41cSTejun Heo  * @buflen: target buffer length
330eea8f41cSTejun Heo  *
331eea8f41cSTejun Heo  * Format the path of the cgroup of @blkg into @buf.
332eea8f41cSTejun Heo  */
333eea8f41cSTejun Heo static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen)
334eea8f41cSTejun Heo {
335eea8f41cSTejun Heo 	char *p;
336eea8f41cSTejun Heo 
337eea8f41cSTejun Heo 	p = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
338eea8f41cSTejun Heo 	if (!p) {
339eea8f41cSTejun Heo 		strncpy(buf, "<unavailable>", buflen);
340eea8f41cSTejun Heo 		return -ENAMETOOLONG;
341eea8f41cSTejun Heo 	}
342eea8f41cSTejun Heo 
343eea8f41cSTejun Heo 	memmove(buf, p, buf + buflen - p);
344eea8f41cSTejun Heo 	return 0;
345eea8f41cSTejun Heo }
346eea8f41cSTejun Heo 
347eea8f41cSTejun Heo /**
348eea8f41cSTejun Heo  * blkg_get - get a blkg reference
349eea8f41cSTejun Heo  * @blkg: blkg to get
350eea8f41cSTejun Heo  *
351eea8f41cSTejun Heo  * The caller should be holding an existing reference.
352eea8f41cSTejun Heo  */
353eea8f41cSTejun Heo static inline void blkg_get(struct blkcg_gq *blkg)
354eea8f41cSTejun Heo {
355eea8f41cSTejun Heo 	WARN_ON_ONCE(atomic_read(&blkg->refcnt) <= 0);
356eea8f41cSTejun Heo 	atomic_inc(&blkg->refcnt);
357eea8f41cSTejun Heo }
358eea8f41cSTejun Heo 
359eea8f41cSTejun Heo void __blkg_release_rcu(struct rcu_head *rcu);
360eea8f41cSTejun Heo 
361eea8f41cSTejun Heo /**
362eea8f41cSTejun Heo  * blkg_put - put a blkg reference
363eea8f41cSTejun Heo  * @blkg: blkg to put
364eea8f41cSTejun Heo  */
365eea8f41cSTejun Heo static inline void blkg_put(struct blkcg_gq *blkg)
366eea8f41cSTejun Heo {
367eea8f41cSTejun Heo 	WARN_ON_ONCE(atomic_read(&blkg->refcnt) <= 0);
368eea8f41cSTejun Heo 	if (atomic_dec_and_test(&blkg->refcnt))
369eea8f41cSTejun Heo 		call_rcu(&blkg->rcu_head, __blkg_release_rcu);
370eea8f41cSTejun Heo }
371eea8f41cSTejun Heo 
372eea8f41cSTejun Heo /**
373eea8f41cSTejun Heo  * blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
374eea8f41cSTejun Heo  * @d_blkg: loop cursor pointing to the current descendant
375eea8f41cSTejun Heo  * @pos_css: used for iteration
376eea8f41cSTejun Heo  * @p_blkg: target blkg to walk descendants of
377eea8f41cSTejun Heo  *
378eea8f41cSTejun Heo  * Walk @c_blkg through the descendants of @p_blkg.  Must be used with RCU
379eea8f41cSTejun Heo  * read locked.  If called under either blkcg or queue lock, the iteration
380eea8f41cSTejun Heo  * is guaranteed to include all and only online blkgs.  The caller may
381eea8f41cSTejun Heo  * update @pos_css by calling css_rightmost_descendant() to skip subtree.
382eea8f41cSTejun Heo  * @p_blkg is included in the iteration and the first node to be visited.
383eea8f41cSTejun Heo  */
384eea8f41cSTejun Heo #define blkg_for_each_descendant_pre(d_blkg, pos_css, p_blkg)		\
385eea8f41cSTejun Heo 	css_for_each_descendant_pre((pos_css), &(p_blkg)->blkcg->css)	\
386eea8f41cSTejun Heo 		if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css),	\
387eea8f41cSTejun Heo 					      (p_blkg)->q, false)))
388eea8f41cSTejun Heo 
389eea8f41cSTejun Heo /**
390eea8f41cSTejun Heo  * blkg_for_each_descendant_post - post-order walk of a blkg's descendants
391eea8f41cSTejun Heo  * @d_blkg: loop cursor pointing to the current descendant
392eea8f41cSTejun Heo  * @pos_css: used for iteration
393eea8f41cSTejun Heo  * @p_blkg: target blkg to walk descendants of
394eea8f41cSTejun Heo  *
395eea8f41cSTejun Heo  * Similar to blkg_for_each_descendant_pre() but performs post-order
396eea8f41cSTejun Heo  * traversal instead.  Synchronization rules are the same.  @p_blkg is
397eea8f41cSTejun Heo  * included in the iteration and the last node to be visited.
398eea8f41cSTejun Heo  */
399eea8f41cSTejun Heo #define blkg_for_each_descendant_post(d_blkg, pos_css, p_blkg)		\
400eea8f41cSTejun Heo 	css_for_each_descendant_post((pos_css), &(p_blkg)->blkcg->css)	\
401eea8f41cSTejun Heo 		if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css),	\
402eea8f41cSTejun Heo 					      (p_blkg)->q, false)))
403eea8f41cSTejun Heo 
404eea8f41cSTejun Heo /**
405eea8f41cSTejun Heo  * blk_get_rl - get request_list to use
406eea8f41cSTejun Heo  * @q: request_queue of interest
407eea8f41cSTejun Heo  * @bio: bio which will be attached to the allocated request (may be %NULL)
408eea8f41cSTejun Heo  *
409eea8f41cSTejun Heo  * The caller wants to allocate a request from @q to use for @bio.  Find
410eea8f41cSTejun Heo  * the request_list to use and obtain a reference on it.  Should be called
411eea8f41cSTejun Heo  * under queue_lock.  This function is guaranteed to return non-%NULL
412eea8f41cSTejun Heo  * request_list.
413eea8f41cSTejun Heo  */
414eea8f41cSTejun Heo static inline struct request_list *blk_get_rl(struct request_queue *q,
415eea8f41cSTejun Heo 					      struct bio *bio)
416eea8f41cSTejun Heo {
417eea8f41cSTejun Heo 	struct blkcg *blkcg;
418eea8f41cSTejun Heo 	struct blkcg_gq *blkg;
419eea8f41cSTejun Heo 
420eea8f41cSTejun Heo 	rcu_read_lock();
421eea8f41cSTejun Heo 
422eea8f41cSTejun Heo 	blkcg = bio_blkcg(bio);
423eea8f41cSTejun Heo 
424eea8f41cSTejun Heo 	/* bypass blkg lookup and use @q->root_rl directly for root */
425eea8f41cSTejun Heo 	if (blkcg == &blkcg_root)
426eea8f41cSTejun Heo 		goto root_rl;
427eea8f41cSTejun Heo 
428eea8f41cSTejun Heo 	/*
429eea8f41cSTejun Heo 	 * Try to use blkg->rl.  blkg lookup may fail under memory pressure
430eea8f41cSTejun Heo 	 * or if either the blkcg or queue is going away.  Fall back to
431eea8f41cSTejun Heo 	 * root_rl in such cases.
432eea8f41cSTejun Heo 	 */
433ae118896STejun Heo 	blkg = blkg_lookup(blkcg, q);
434ae118896STejun Heo 	if (unlikely(!blkg))
435eea8f41cSTejun Heo 		goto root_rl;
436eea8f41cSTejun Heo 
437eea8f41cSTejun Heo 	blkg_get(blkg);
438eea8f41cSTejun Heo 	rcu_read_unlock();
439eea8f41cSTejun Heo 	return &blkg->rl;
440eea8f41cSTejun Heo root_rl:
441eea8f41cSTejun Heo 	rcu_read_unlock();
442eea8f41cSTejun Heo 	return &q->root_rl;
443eea8f41cSTejun Heo }
444eea8f41cSTejun Heo 
445eea8f41cSTejun Heo /**
446eea8f41cSTejun Heo  * blk_put_rl - put request_list
447eea8f41cSTejun Heo  * @rl: request_list to put
448eea8f41cSTejun Heo  *
449eea8f41cSTejun Heo  * Put the reference acquired by blk_get_rl().  Should be called under
450eea8f41cSTejun Heo  * queue_lock.
451eea8f41cSTejun Heo  */
452eea8f41cSTejun Heo static inline void blk_put_rl(struct request_list *rl)
453eea8f41cSTejun Heo {
454401efbf8STejun Heo 	if (rl->blkg->blkcg != &blkcg_root)
455eea8f41cSTejun Heo 		blkg_put(rl->blkg);
456eea8f41cSTejun Heo }
457eea8f41cSTejun Heo 
458eea8f41cSTejun Heo /**
459eea8f41cSTejun Heo  * blk_rq_set_rl - associate a request with a request_list
460eea8f41cSTejun Heo  * @rq: request of interest
461eea8f41cSTejun Heo  * @rl: target request_list
462eea8f41cSTejun Heo  *
463eea8f41cSTejun Heo  * Associate @rq with @rl so that accounting and freeing can know the
464eea8f41cSTejun Heo  * request_list @rq came from.
465eea8f41cSTejun Heo  */
466eea8f41cSTejun Heo static inline void blk_rq_set_rl(struct request *rq, struct request_list *rl)
467eea8f41cSTejun Heo {
468eea8f41cSTejun Heo 	rq->rl = rl;
469eea8f41cSTejun Heo }
470eea8f41cSTejun Heo 
471eea8f41cSTejun Heo /**
472eea8f41cSTejun Heo  * blk_rq_rl - return the request_list a request came from
473eea8f41cSTejun Heo  * @rq: request of interest
474eea8f41cSTejun Heo  *
475eea8f41cSTejun Heo  * Return the request_list @rq is allocated from.
476eea8f41cSTejun Heo  */
477eea8f41cSTejun Heo static inline struct request_list *blk_rq_rl(struct request *rq)
478eea8f41cSTejun Heo {
479eea8f41cSTejun Heo 	return rq->rl;
480eea8f41cSTejun Heo }
481eea8f41cSTejun Heo 
482eea8f41cSTejun Heo struct request_list *__blk_queue_next_rl(struct request_list *rl,
483eea8f41cSTejun Heo 					 struct request_queue *q);
484eea8f41cSTejun Heo /**
485eea8f41cSTejun Heo  * blk_queue_for_each_rl - iterate through all request_lists of a request_queue
486eea8f41cSTejun Heo  *
487eea8f41cSTejun Heo  * Should be used under queue_lock.
488eea8f41cSTejun Heo  */
489eea8f41cSTejun Heo #define blk_queue_for_each_rl(rl, q)	\
490eea8f41cSTejun Heo 	for ((rl) = &(q)->root_rl; (rl); (rl) = __blk_queue_next_rl((rl), (q)))
491eea8f41cSTejun Heo 
49224bdb8efSTejun Heo static inline int blkg_stat_init(struct blkg_stat *stat, gfp_t gfp)
493eea8f41cSTejun Heo {
49424bdb8efSTejun Heo 	int ret;
49524bdb8efSTejun Heo 
49624bdb8efSTejun Heo 	ret = percpu_counter_init(&stat->cpu_cnt, 0, gfp);
49724bdb8efSTejun Heo 	if (ret)
49824bdb8efSTejun Heo 		return ret;
49924bdb8efSTejun Heo 
500e6269c44STejun Heo 	atomic64_set(&stat->aux_cnt, 0);
50124bdb8efSTejun Heo 	return 0;
50224bdb8efSTejun Heo }
50324bdb8efSTejun Heo 
50424bdb8efSTejun Heo static inline void blkg_stat_exit(struct blkg_stat *stat)
50524bdb8efSTejun Heo {
50624bdb8efSTejun Heo 	percpu_counter_destroy(&stat->cpu_cnt);
507eea8f41cSTejun Heo }
508eea8f41cSTejun Heo 
509eea8f41cSTejun Heo /**
510eea8f41cSTejun Heo  * blkg_stat_add - add a value to a blkg_stat
511eea8f41cSTejun Heo  * @stat: target blkg_stat
512eea8f41cSTejun Heo  * @val: value to add
513eea8f41cSTejun Heo  *
51424bdb8efSTejun Heo  * Add @val to @stat.  The caller must ensure that IRQ on the same CPU
51524bdb8efSTejun Heo  * don't re-enter this function for the same counter.
516eea8f41cSTejun Heo  */
517eea8f41cSTejun Heo static inline void blkg_stat_add(struct blkg_stat *stat, uint64_t val)
518eea8f41cSTejun Heo {
51924bdb8efSTejun Heo 	__percpu_counter_add(&stat->cpu_cnt, val, BLKG_STAT_CPU_BATCH);
520eea8f41cSTejun Heo }
521eea8f41cSTejun Heo 
522eea8f41cSTejun Heo /**
523eea8f41cSTejun Heo  * blkg_stat_read - read the current value of a blkg_stat
524eea8f41cSTejun Heo  * @stat: blkg_stat to read
525eea8f41cSTejun Heo  */
526eea8f41cSTejun Heo static inline uint64_t blkg_stat_read(struct blkg_stat *stat)
527eea8f41cSTejun Heo {
52824bdb8efSTejun Heo 	return percpu_counter_sum_positive(&stat->cpu_cnt);
529eea8f41cSTejun Heo }
530eea8f41cSTejun Heo 
531eea8f41cSTejun Heo /**
532eea8f41cSTejun Heo  * blkg_stat_reset - reset a blkg_stat
533eea8f41cSTejun Heo  * @stat: blkg_stat to reset
534eea8f41cSTejun Heo  */
535eea8f41cSTejun Heo static inline void blkg_stat_reset(struct blkg_stat *stat)
536eea8f41cSTejun Heo {
53724bdb8efSTejun Heo 	percpu_counter_set(&stat->cpu_cnt, 0);
538e6269c44STejun Heo 	atomic64_set(&stat->aux_cnt, 0);
539eea8f41cSTejun Heo }
540eea8f41cSTejun Heo 
541eea8f41cSTejun Heo /**
542e6269c44STejun Heo  * blkg_stat_add_aux - add a blkg_stat into another's aux count
543eea8f41cSTejun Heo  * @to: the destination blkg_stat
544eea8f41cSTejun Heo  * @from: the source
545eea8f41cSTejun Heo  *
546e6269c44STejun Heo  * Add @from's count including the aux one to @to's aux count.
547eea8f41cSTejun Heo  */
548e6269c44STejun Heo static inline void blkg_stat_add_aux(struct blkg_stat *to,
549e6269c44STejun Heo 				     struct blkg_stat *from)
550eea8f41cSTejun Heo {
551e6269c44STejun Heo 	atomic64_add(blkg_stat_read(from) + atomic64_read(&from->aux_cnt),
552e6269c44STejun Heo 		     &to->aux_cnt);
553eea8f41cSTejun Heo }
554eea8f41cSTejun Heo 
55524bdb8efSTejun Heo static inline int blkg_rwstat_init(struct blkg_rwstat *rwstat, gfp_t gfp)
55624bdb8efSTejun Heo {
55724bdb8efSTejun Heo 	int i, ret;
55824bdb8efSTejun Heo 
55924bdb8efSTejun Heo 	for (i = 0; i < BLKG_RWSTAT_NR; i++) {
56024bdb8efSTejun Heo 		ret = percpu_counter_init(&rwstat->cpu_cnt[i], 0, gfp);
56124bdb8efSTejun Heo 		if (ret) {
56224bdb8efSTejun Heo 			while (--i >= 0)
56324bdb8efSTejun Heo 				percpu_counter_destroy(&rwstat->cpu_cnt[i]);
56424bdb8efSTejun Heo 			return ret;
56524bdb8efSTejun Heo 		}
56624bdb8efSTejun Heo 		atomic64_set(&rwstat->aux_cnt[i], 0);
56724bdb8efSTejun Heo 	}
56824bdb8efSTejun Heo 	return 0;
56924bdb8efSTejun Heo }
57024bdb8efSTejun Heo 
57124bdb8efSTejun Heo static inline void blkg_rwstat_exit(struct blkg_rwstat *rwstat)
572eea8f41cSTejun Heo {
573e6269c44STejun Heo 	int i;
574e6269c44STejun Heo 
575e6269c44STejun Heo 	for (i = 0; i < BLKG_RWSTAT_NR; i++)
57624bdb8efSTejun Heo 		percpu_counter_destroy(&rwstat->cpu_cnt[i]);
577eea8f41cSTejun Heo }
578eea8f41cSTejun Heo 
579eea8f41cSTejun Heo /**
580eea8f41cSTejun Heo  * blkg_rwstat_add - add a value to a blkg_rwstat
581eea8f41cSTejun Heo  * @rwstat: target blkg_rwstat
582eea8f41cSTejun Heo  * @rw: mask of REQ_{WRITE|SYNC}
583eea8f41cSTejun Heo  * @val: value to add
584eea8f41cSTejun Heo  *
585eea8f41cSTejun Heo  * Add @val to @rwstat.  The counters are chosen according to @rw.  The
586eea8f41cSTejun Heo  * caller is responsible for synchronizing calls to this function.
587eea8f41cSTejun Heo  */
588eea8f41cSTejun Heo static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat,
589eea8f41cSTejun Heo 				   int rw, uint64_t val)
590eea8f41cSTejun Heo {
59124bdb8efSTejun Heo 	struct percpu_counter *cnt;
592eea8f41cSTejun Heo 
593eea8f41cSTejun Heo 	if (rw & REQ_WRITE)
59424bdb8efSTejun Heo 		cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_WRITE];
595eea8f41cSTejun Heo 	else
59624bdb8efSTejun Heo 		cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_READ];
597eea8f41cSTejun Heo 
59824bdb8efSTejun Heo 	__percpu_counter_add(cnt, val, BLKG_STAT_CPU_BATCH);
59924bdb8efSTejun Heo 
60024bdb8efSTejun Heo 	if (rw & REQ_SYNC)
60124bdb8efSTejun Heo 		cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_SYNC];
60224bdb8efSTejun Heo 	else
60324bdb8efSTejun Heo 		cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_ASYNC];
60424bdb8efSTejun Heo 
60524bdb8efSTejun Heo 	__percpu_counter_add(cnt, val, BLKG_STAT_CPU_BATCH);
606eea8f41cSTejun Heo }
607eea8f41cSTejun Heo 
608eea8f41cSTejun Heo /**
609eea8f41cSTejun Heo  * blkg_rwstat_read - read the current values of a blkg_rwstat
610eea8f41cSTejun Heo  * @rwstat: blkg_rwstat to read
611eea8f41cSTejun Heo  *
61224bdb8efSTejun Heo  * Read the current snapshot of @rwstat and return it in the aux counts.
613eea8f41cSTejun Heo  */
614eea8f41cSTejun Heo static inline struct blkg_rwstat blkg_rwstat_read(struct blkg_rwstat *rwstat)
615eea8f41cSTejun Heo {
61624bdb8efSTejun Heo 	struct blkg_rwstat result;
61724bdb8efSTejun Heo 	int i;
618eea8f41cSTejun Heo 
61924bdb8efSTejun Heo 	for (i = 0; i < BLKG_RWSTAT_NR; i++)
62024bdb8efSTejun Heo 		atomic64_set(&result.aux_cnt[i],
62124bdb8efSTejun Heo 			     percpu_counter_sum_positive(&rwstat->cpu_cnt[i]));
62224bdb8efSTejun Heo 	return result;
623eea8f41cSTejun Heo }
624eea8f41cSTejun Heo 
625eea8f41cSTejun Heo /**
626eea8f41cSTejun Heo  * blkg_rwstat_total - read the total count of a blkg_rwstat
627eea8f41cSTejun Heo  * @rwstat: blkg_rwstat to read
628eea8f41cSTejun Heo  *
629eea8f41cSTejun Heo  * Return the total count of @rwstat regardless of the IO direction.  This
630eea8f41cSTejun Heo  * function can be called without synchronization and takes care of u64
631eea8f41cSTejun Heo  * atomicity.
632eea8f41cSTejun Heo  */
633eea8f41cSTejun Heo static inline uint64_t blkg_rwstat_total(struct blkg_rwstat *rwstat)
634eea8f41cSTejun Heo {
635eea8f41cSTejun Heo 	struct blkg_rwstat tmp = blkg_rwstat_read(rwstat);
636eea8f41cSTejun Heo 
63724bdb8efSTejun Heo 	return atomic64_read(&tmp.aux_cnt[BLKG_RWSTAT_READ]) +
63824bdb8efSTejun Heo 		atomic64_read(&tmp.aux_cnt[BLKG_RWSTAT_WRITE]);
639eea8f41cSTejun Heo }
640eea8f41cSTejun Heo 
641eea8f41cSTejun Heo /**
642eea8f41cSTejun Heo  * blkg_rwstat_reset - reset a blkg_rwstat
643eea8f41cSTejun Heo  * @rwstat: blkg_rwstat to reset
644eea8f41cSTejun Heo  */
645eea8f41cSTejun Heo static inline void blkg_rwstat_reset(struct blkg_rwstat *rwstat)
646eea8f41cSTejun Heo {
647e6269c44STejun Heo 	int i;
648e6269c44STejun Heo 
64924bdb8efSTejun Heo 	for (i = 0; i < BLKG_RWSTAT_NR; i++) {
65024bdb8efSTejun Heo 		percpu_counter_set(&rwstat->cpu_cnt[i], 0);
651e6269c44STejun Heo 		atomic64_set(&rwstat->aux_cnt[i], 0);
652eea8f41cSTejun Heo 	}
65324bdb8efSTejun Heo }
654eea8f41cSTejun Heo 
655eea8f41cSTejun Heo /**
656e6269c44STejun Heo  * blkg_rwstat_add_aux - add a blkg_rwstat into another's aux count
657eea8f41cSTejun Heo  * @to: the destination blkg_rwstat
658eea8f41cSTejun Heo  * @from: the source
659eea8f41cSTejun Heo  *
660e6269c44STejun Heo  * Add @from's count including the aux one to @to's aux count.
661eea8f41cSTejun Heo  */
662e6269c44STejun Heo static inline void blkg_rwstat_add_aux(struct blkg_rwstat *to,
663eea8f41cSTejun Heo 				       struct blkg_rwstat *from)
664eea8f41cSTejun Heo {
665eea8f41cSTejun Heo 	struct blkg_rwstat v = blkg_rwstat_read(from);
666eea8f41cSTejun Heo 	int i;
667eea8f41cSTejun Heo 
668eea8f41cSTejun Heo 	for (i = 0; i < BLKG_RWSTAT_NR; i++)
66924bdb8efSTejun Heo 		atomic64_add(atomic64_read(&v.aux_cnt[i]) +
67024bdb8efSTejun Heo 			     atomic64_read(&from->aux_cnt[i]),
671e6269c44STejun Heo 			     &to->aux_cnt[i]);
672eea8f41cSTejun Heo }
673eea8f41cSTejun Heo 
674ae118896STejun Heo #ifdef CONFIG_BLK_DEV_THROTTLING
675ae118896STejun Heo extern bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
676ae118896STejun Heo 			   struct bio *bio);
677ae118896STejun Heo #else
678ae118896STejun Heo static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
679ae118896STejun Heo 				  struct bio *bio) { return false; }
680ae118896STejun Heo #endif
681ae118896STejun Heo 
682ae118896STejun Heo static inline bool blkcg_bio_issue_check(struct request_queue *q,
683ae118896STejun Heo 					 struct bio *bio)
684ae118896STejun Heo {
685ae118896STejun Heo 	struct blkcg *blkcg;
686ae118896STejun Heo 	struct blkcg_gq *blkg;
687ae118896STejun Heo 	bool throtl = false;
688ae118896STejun Heo 
689ae118896STejun Heo 	rcu_read_lock();
690ae118896STejun Heo 	blkcg = bio_blkcg(bio);
691ae118896STejun Heo 
692ae118896STejun Heo 	blkg = blkg_lookup(blkcg, q);
693ae118896STejun Heo 	if (unlikely(!blkg)) {
694ae118896STejun Heo 		spin_lock_irq(q->queue_lock);
695ae118896STejun Heo 		blkg = blkg_lookup_create(blkcg, q);
696ae118896STejun Heo 		if (IS_ERR(blkg))
697ae118896STejun Heo 			blkg = NULL;
698ae118896STejun Heo 		spin_unlock_irq(q->queue_lock);
699ae118896STejun Heo 	}
700ae118896STejun Heo 
701ae118896STejun Heo 	throtl = blk_throtl_bio(q, blkg, bio);
702ae118896STejun Heo 
703ae118896STejun Heo 	rcu_read_unlock();
704ae118896STejun Heo 	return !throtl;
705ae118896STejun Heo }
706ae118896STejun Heo 
707eea8f41cSTejun Heo #else	/* CONFIG_BLK_CGROUP */
708eea8f41cSTejun Heo 
709efa7d1c7STejun Heo struct blkcg {
710efa7d1c7STejun Heo };
711eea8f41cSTejun Heo 
712eea8f41cSTejun Heo struct blkg_policy_data {
713eea8f41cSTejun Heo };
714eea8f41cSTejun Heo 
715e4bc13adSLinus Torvalds struct blkcg_policy_data {
716e4bc13adSLinus Torvalds };
717e4bc13adSLinus Torvalds 
718eea8f41cSTejun Heo struct blkcg_gq {
719eea8f41cSTejun Heo };
720eea8f41cSTejun Heo 
721eea8f41cSTejun Heo struct blkcg_policy {
722eea8f41cSTejun Heo };
723eea8f41cSTejun Heo 
724496d5e75STejun Heo #define blkcg_root_css	((struct cgroup_subsys_state *)ERR_PTR(-EINVAL))
725496d5e75STejun Heo 
726fd383c2dSTejun Heo static inline struct cgroup_subsys_state *
727fd383c2dSTejun Heo task_get_blkcg_css(struct task_struct *task)
728fd383c2dSTejun Heo {
729fd383c2dSTejun Heo 	return NULL;
730fd383c2dSTejun Heo }
731fd383c2dSTejun Heo 
732efa7d1c7STejun Heo #ifdef CONFIG_BLOCK
733efa7d1c7STejun Heo 
734eea8f41cSTejun Heo static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { return NULL; }
735eea8f41cSTejun Heo static inline int blkcg_init_queue(struct request_queue *q) { return 0; }
736eea8f41cSTejun Heo static inline void blkcg_drain_queue(struct request_queue *q) { }
737eea8f41cSTejun Heo static inline void blkcg_exit_queue(struct request_queue *q) { }
738eea8f41cSTejun Heo static inline int blkcg_policy_register(struct blkcg_policy *pol) { return 0; }
739eea8f41cSTejun Heo static inline void blkcg_policy_unregister(struct blkcg_policy *pol) { }
740eea8f41cSTejun Heo static inline int blkcg_activate_policy(struct request_queue *q,
741eea8f41cSTejun Heo 					const struct blkcg_policy *pol) { return 0; }
742eea8f41cSTejun Heo static inline void blkcg_deactivate_policy(struct request_queue *q,
743eea8f41cSTejun Heo 					   const struct blkcg_policy *pol) { }
744eea8f41cSTejun Heo 
745eea8f41cSTejun Heo static inline struct blkcg *bio_blkcg(struct bio *bio) { return NULL; }
746eea8f41cSTejun Heo 
747eea8f41cSTejun Heo static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
748eea8f41cSTejun Heo 						  struct blkcg_policy *pol) { return NULL; }
749eea8f41cSTejun Heo static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd) { return NULL; }
750eea8f41cSTejun Heo static inline char *blkg_path(struct blkcg_gq *blkg) { return NULL; }
751eea8f41cSTejun Heo static inline void blkg_get(struct blkcg_gq *blkg) { }
752eea8f41cSTejun Heo static inline void blkg_put(struct blkcg_gq *blkg) { }
753eea8f41cSTejun Heo 
754eea8f41cSTejun Heo static inline struct request_list *blk_get_rl(struct request_queue *q,
755eea8f41cSTejun Heo 					      struct bio *bio) { return &q->root_rl; }
756eea8f41cSTejun Heo static inline void blk_put_rl(struct request_list *rl) { }
757eea8f41cSTejun Heo static inline void blk_rq_set_rl(struct request *rq, struct request_list *rl) { }
758eea8f41cSTejun Heo static inline struct request_list *blk_rq_rl(struct request *rq) { return &rq->q->root_rl; }
759eea8f41cSTejun Heo 
760ae118896STejun Heo static inline bool blkcg_bio_issue_check(struct request_queue *q,
761ae118896STejun Heo 					 struct bio *bio) { return true; }
762ae118896STejun Heo 
763eea8f41cSTejun Heo #define blk_queue_for_each_rl(rl, q)	\
764eea8f41cSTejun Heo 	for ((rl) = &(q)->root_rl; (rl); (rl) = NULL)
765eea8f41cSTejun Heo 
766efa7d1c7STejun Heo #endif	/* CONFIG_BLOCK */
767eea8f41cSTejun Heo #endif	/* CONFIG_BLK_CGROUP */
768eea8f41cSTejun Heo #endif	/* _BLK_CGROUP_H */
769