blob: 84bf745fa77576898b8c01c13bd68879092bf869 [file] [log] [blame]
Vivek Goyal31e4c282009-12-03 12:59:42 -05001#ifndef _BLK_CGROUP_H
2#define _BLK_CGROUP_H
3/*
4 * Common Block IO controller cgroup interface
5 *
6 * Based on ideas and code from CFQ, CFS and BFQ:
7 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
8 *
9 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
10 * Paolo Valente <paolo.valente@unimore.it>
11 *
12 * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
13 * Nauman Rafique <nauman@google.com>
14 */
15
16#include <linux/cgroup.h>
17
Jens Axboe2f5ea472009-12-03 21:06:43 +010018#ifdef CONFIG_BLK_CGROUP
19
Vivek Goyal31e4c282009-12-03 12:59:42 -050020struct blkio_cgroup {
21 struct cgroup_subsys_state css;
22 unsigned int weight;
23 spinlock_t lock;
24 struct hlist_head blkg_list;
25};
26
27struct blkio_group {
28 /* An rcu protected unique identifier for the group */
29 void *key;
30 struct hlist_node blkcg_node;
Vivek Goyalb1c35762009-12-03 12:59:47 -050031 unsigned short blkcg_id;
Vivek Goyal2868ef72009-12-03 12:59:48 -050032#ifdef CONFIG_DEBUG_BLK_CGROUP
33 /* Store cgroup path */
34 char path[128];
Vivek Goyal22084192009-12-03 12:59:49 -050035 /* How many times this group has been removed from service tree */
36 unsigned long dequeue;
Vivek Goyal2868ef72009-12-03 12:59:48 -050037#endif
Vivek Goyal22084192009-12-03 12:59:49 -050038 /* The device MKDEV(major, minor), this group has been created for */
39 dev_t dev;
40
41 /* total disk time and nr sectors dispatched by this group */
42 unsigned long time;
43 unsigned long sectors;
Vivek Goyal31e4c282009-12-03 12:59:42 -050044};
45
Vivek Goyal3e252062009-12-04 10:36:42 -050046typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
47typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
48 unsigned int weight);
49
50struct blkio_policy_ops {
51 blkio_unlink_group_fn *blkio_unlink_group_fn;
52 blkio_update_group_weight_fn *blkio_update_group_weight_fn;
53};
54
55struct blkio_policy_type {
56 struct list_head list;
57 struct blkio_policy_ops ops;
58};
59
60/* Blkio controller policy registration */
61extern void blkio_policy_register(struct blkio_policy_type *);
62extern void blkio_policy_unregister(struct blkio_policy_type *);
63
Jens Axboe2f5ea472009-12-03 21:06:43 +010064#else
65
66struct blkio_group {
67};
68
Vivek Goyal3e252062009-12-04 10:36:42 -050069struct blkio_policy_type {
70};
71
72static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
73static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
74
Jens Axboe2f5ea472009-12-03 21:06:43 +010075#endif
76
Vivek Goyal31e4c282009-12-03 12:59:42 -050077#define BLKIO_WEIGHT_MIN 100
78#define BLKIO_WEIGHT_MAX 1000
79#define BLKIO_WEIGHT_DEFAULT 500
80
Vivek Goyal2868ef72009-12-03 12:59:48 -050081#ifdef CONFIG_DEBUG_BLK_CGROUP
82static inline char *blkg_path(struct blkio_group *blkg)
83{
84 return blkg->path;
85}
Vivek Goyal22084192009-12-03 12:59:49 -050086void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
87 unsigned long dequeue);
Vivek Goyal2868ef72009-12-03 12:59:48 -050088#else
89static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
Vivek Goyal22084192009-12-03 12:59:49 -050090static inline void blkiocg_update_blkio_group_dequeue_stats(
91 struct blkio_group *blkg, unsigned long dequeue) {}
Vivek Goyal2868ef72009-12-03 12:59:48 -050092#endif
93
Vivek Goyal31e4c282009-12-03 12:59:42 -050094#ifdef CONFIG_BLK_CGROUP
95extern struct blkio_cgroup blkio_root_cgroup;
96extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
97extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
Vivek Goyal22084192009-12-03 12:59:49 -050098 struct blkio_group *blkg, void *key, dev_t dev);
Vivek Goyal31e4c282009-12-03 12:59:42 -050099extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
100extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
101 void *key);
Vivek Goyal22084192009-12-03 12:59:49 -0500102void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
103 unsigned long time, unsigned long sectors);
Vivek Goyal31e4c282009-12-03 12:59:42 -0500104#else
Jens Axboe2f5ea472009-12-03 21:06:43 +0100105struct cgroup;
Vivek Goyal31e4c282009-12-03 12:59:42 -0500106static inline struct blkio_cgroup *
107cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
108
109static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
Vivek Goyal22084192009-12-03 12:59:49 -0500110 struct blkio_group *blkg, void *key, dev_t dev)
Vivek Goyal31e4c282009-12-03 12:59:42 -0500111{
112}
113
114static inline int
115blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
116
117static inline struct blkio_group *
118blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
Vivek Goyal22084192009-12-03 12:59:49 -0500119static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
120 unsigned long time, unsigned long sectors)
121{
122}
Vivek Goyal31e4c282009-12-03 12:59:42 -0500123#endif
124#endif /* _BLK_CGROUP_H */