aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/bcache/request.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/bcache/request.c')
-rw-r--r--drivers/md/bcache/request.c169
1 files changed, 0 insertions, 169 deletions
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 3e880869871f..15fff4f68a7c 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -12,11 +12,9 @@
12#include "request.h" 12#include "request.h"
13#include "writeback.h" 13#include "writeback.h"
14 14
15#include <linux/cgroup.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/hash.h> 16#include <linux/hash.h>
18#include <linux/random.h> 17#include <linux/random.h>
19#include "blk-cgroup.h"
20 18
21#include <trace/events/bcache.h> 19#include <trace/events/bcache.h>
22 20
@@ -27,171 +25,13 @@ struct kmem_cache *bch_search_cache;
27 25
28static void bch_data_insert_start(struct closure *); 26static void bch_data_insert_start(struct closure *);
29 27
30/* Cgroup interface */
31
32#ifdef CONFIG_CGROUP_BCACHE
33static struct bch_cgroup bcache_default_cgroup = { .cache_mode = -1 };
34
35static struct bch_cgroup *cgroup_to_bcache(struct cgroup *cgroup)
36{
37 struct cgroup_subsys_state *css;
38 return cgroup &&
39 (css = cgroup_subsys_state(cgroup, bcache_subsys_id))
40 ? container_of(css, struct bch_cgroup, css)
41 : &bcache_default_cgroup;
42}
43
44struct bch_cgroup *bch_bio_to_cgroup(struct bio *bio)
45{
46 struct cgroup_subsys_state *css = bio->bi_css
47 ? cgroup_subsys_state(bio->bi_css->cgroup, bcache_subsys_id)
48 : task_subsys_state(current, bcache_subsys_id);
49
50 return css
51 ? container_of(css, struct bch_cgroup, css)
52 : &bcache_default_cgroup;
53}
54
55static ssize_t cache_mode_read(struct cgroup *cgrp, struct cftype *cft,
56 struct file *file,
57 char __user *buf, size_t nbytes, loff_t *ppos)
58{
59 char tmp[1024];
60 int len = bch_snprint_string_list(tmp, PAGE_SIZE, bch_cache_modes,
61 cgroup_to_bcache(cgrp)->cache_mode + 1);
62
63 if (len < 0)
64 return len;
65
66 return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
67}
68
69static int cache_mode_write(struct cgroup *cgrp, struct cftype *cft,
70 const char *buf)
71{
72 int v = bch_read_string_list(buf, bch_cache_modes);
73 if (v < 0)
74 return v;
75
76 cgroup_to_bcache(cgrp)->cache_mode = v - 1;
77 return 0;
78}
79
80static u64 bch_verify_read(struct cgroup *cgrp, struct cftype *cft)
81{
82 return cgroup_to_bcache(cgrp)->verify;
83}
84
85static int bch_verify_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
86{
87 cgroup_to_bcache(cgrp)->verify = val;
88 return 0;
89}
90
91static u64 bch_cache_hits_read(struct cgroup *cgrp, struct cftype *cft)
92{
93 struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
94 return atomic_read(&bcachecg->stats.cache_hits);
95}
96
97static u64 bch_cache_misses_read(struct cgroup *cgrp, struct cftype *cft)
98{
99 struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
100 return atomic_read(&bcachecg->stats.cache_misses);
101}
102
103static u64 bch_cache_bypass_hits_read(struct cgroup *cgrp,
104 struct cftype *cft)
105{
106 struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
107 return atomic_read(&bcachecg->stats.cache_bypass_hits);
108}
109
110static u64 bch_cache_bypass_misses_read(struct cgroup *cgrp,
111 struct cftype *cft)
112{
113 struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
114 return atomic_read(&bcachecg->stats.cache_bypass_misses);
115}
116
117static struct cftype bch_files[] = {
118 {
119 .name = "cache_mode",
120 .read = cache_mode_read,
121 .write_string = cache_mode_write,
122 },
123 {
124 .name = "verify",
125 .read_u64 = bch_verify_read,
126 .write_u64 = bch_verify_write,
127 },
128 {
129 .name = "cache_hits",
130 .read_u64 = bch_cache_hits_read,
131 },
132 {
133 .name = "cache_misses",
134 .read_u64 = bch_cache_misses_read,
135 },
136 {
137 .name = "cache_bypass_hits",
138 .read_u64 = bch_cache_bypass_hits_read,
139 },
140 {
141 .name = "cache_bypass_misses",
142 .read_u64 = bch_cache_bypass_misses_read,
143 },
144 { } /* terminate */
145};
146
147static void init_bch_cgroup(struct bch_cgroup *cg)
148{
149 cg->cache_mode = -1;
150}
151
152static struct cgroup_subsys_state *bcachecg_create(struct cgroup *cgroup)
153{
154 struct bch_cgroup *cg;
155
156 cg = kzalloc(sizeof(*cg), GFP_KERNEL);
157 if (!cg)
158 return ERR_PTR(-ENOMEM);
159 init_bch_cgroup(cg);
160 return &cg->css;
161}
162
163static void bcachecg_destroy(struct cgroup *cgroup)
164{
165 struct bch_cgroup *cg = cgroup_to_bcache(cgroup);
166 kfree(cg);
167}
168
169struct cgroup_subsys bcache_subsys = {
170 .create = bcachecg_create,
171 .destroy = bcachecg_destroy,
172 .subsys_id = bcache_subsys_id,
173 .name = "bcache",
174 .module = THIS_MODULE,
175};
176EXPORT_SYMBOL_GPL(bcache_subsys);
177#endif
178
179static unsigned cache_mode(struct cached_dev *dc, struct bio *bio) 28static unsigned cache_mode(struct cached_dev *dc, struct bio *bio)
180{ 29{
181#ifdef CONFIG_CGROUP_BCACHE
182 int r = bch_bio_to_cgroup(bio)->cache_mode;
183 if (r >= 0)
184 return r;
185#endif
186 return BDEV_CACHE_MODE(&dc->sb); 30 return BDEV_CACHE_MODE(&dc->sb);
187} 31}
188 32
189static bool verify(struct cached_dev *dc, struct bio *bio) 33static bool verify(struct cached_dev *dc, struct bio *bio)
190{ 34{
191#ifdef CONFIG_CGROUP_BCACHE
192 if (bch_bio_to_cgroup(bio)->verify)
193 return true;
194#endif
195 return dc->verify; 35 return dc->verify;
196} 36}
197 37
@@ -1305,9 +1145,6 @@ void bch_flash_dev_request_init(struct bcache_device *d)
1305 1145
1306void bch_request_exit(void) 1146void bch_request_exit(void)
1307{ 1147{
1308#ifdef CONFIG_CGROUP_BCACHE
1309 cgroup_unload_subsys(&bcache_subsys);
1310#endif
1311 if (bch_search_cache) 1148 if (bch_search_cache)
1312 kmem_cache_destroy(bch_search_cache); 1149 kmem_cache_destroy(bch_search_cache);
1313} 1150}
@@ -1318,11 +1155,5 @@ int __init bch_request_init(void)
1318 if (!bch_search_cache) 1155 if (!bch_search_cache)
1319 return -ENOMEM; 1156 return -ENOMEM;
1320 1157
1321#ifdef CONFIG_CGROUP_BCACHE
1322 cgroup_load_subsys(&bcache_subsys);
1323 init_bch_cgroup(&bcache_default_cgroup);
1324
1325 cgroup_add_cftypes(&bcache_subsys, bch_files);
1326#endif
1327 return 0; 1158 return 0;
1328} 1159}