1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#define DEBUG_SUBSYSTEM S_OSC
42
43
44#include "../include/obd_class.h"
45
46#include "osc_cl_internal.h"
47
48
49
50
51
52struct kmem_cache *osc_lock_kmem;
53struct kmem_cache *osc_object_kmem;
54struct kmem_cache *osc_thread_kmem;
55struct kmem_cache *osc_session_kmem;
56struct kmem_cache *osc_req_kmem;
57struct kmem_cache *osc_extent_kmem;
58struct kmem_cache *osc_quota_kmem;
59
60struct lu_kmem_descr osc_caches[] = {
61 {
62 .ckd_cache = &osc_lock_kmem,
63 .ckd_name = "osc_lock_kmem",
64 .ckd_size = sizeof(struct osc_lock)
65 },
66 {
67 .ckd_cache = &osc_object_kmem,
68 .ckd_name = "osc_object_kmem",
69 .ckd_size = sizeof(struct osc_object)
70 },
71 {
72 .ckd_cache = &osc_thread_kmem,
73 .ckd_name = "osc_thread_kmem",
74 .ckd_size = sizeof(struct osc_thread_info)
75 },
76 {
77 .ckd_cache = &osc_session_kmem,
78 .ckd_name = "osc_session_kmem",
79 .ckd_size = sizeof(struct osc_session)
80 },
81 {
82 .ckd_cache = &osc_req_kmem,
83 .ckd_name = "osc_req_kmem",
84 .ckd_size = sizeof(struct osc_req)
85 },
86 {
87 .ckd_cache = &osc_extent_kmem,
88 .ckd_name = "osc_extent_kmem",
89 .ckd_size = sizeof(struct osc_extent)
90 },
91 {
92 .ckd_cache = &osc_quota_kmem,
93 .ckd_name = "osc_quota_kmem",
94 .ckd_size = sizeof(struct osc_quota_info)
95 },
96 {
97 .ckd_cache = NULL
98 }
99};
100
101struct lock_class_key osc_ast_guard_class;
102
103
104
105
106
107
108
109static struct lu_device *osc2lu_dev(struct osc_device *osc)
110{
111 return &osc->od_cl.cd_lu_dev;
112}
113
114
115
116
117
118
119
120static void *osc_key_init(const struct lu_context *ctx,
121 struct lu_context_key *key)
122{
123 struct osc_thread_info *info;
124
125 OBD_SLAB_ALLOC_PTR_GFP(info, osc_thread_kmem, GFP_NOFS);
126 if (info == NULL)
127 info = ERR_PTR(-ENOMEM);
128 return info;
129}
130
131static void osc_key_fini(const struct lu_context *ctx,
132 struct lu_context_key *key, void *data)
133{
134 struct osc_thread_info *info = data;
135
136 OBD_SLAB_FREE_PTR(info, osc_thread_kmem);
137}
138
139struct lu_context_key osc_key = {
140 .lct_tags = LCT_CL_THREAD,
141 .lct_init = osc_key_init,
142 .lct_fini = osc_key_fini
143};
144
145static void *osc_session_init(const struct lu_context *ctx,
146 struct lu_context_key *key)
147{
148 struct osc_session *info;
149
150 OBD_SLAB_ALLOC_PTR_GFP(info, osc_session_kmem, GFP_NOFS);
151 if (info == NULL)
152 info = ERR_PTR(-ENOMEM);
153 return info;
154}
155
156static void osc_session_fini(const struct lu_context *ctx,
157 struct lu_context_key *key, void *data)
158{
159 struct osc_session *info = data;
160
161 OBD_SLAB_FREE_PTR(info, osc_session_kmem);
162}
163
164struct lu_context_key osc_session_key = {
165 .lct_tags = LCT_SESSION,
166 .lct_init = osc_session_init,
167 .lct_fini = osc_session_fini
168};
169
170
171LU_TYPE_INIT_FINI(osc, &osc_key, &osc_session_key);
172
173static int osc_cl_process_config(const struct lu_env *env,
174 struct lu_device *d, struct lustre_cfg *cfg)
175{
176 return osc_process_config_base(d->ld_obd, cfg);
177}
178
179static const struct lu_device_operations osc_lu_ops = {
180 .ldo_object_alloc = osc_object_alloc,
181 .ldo_process_config = osc_cl_process_config,
182 .ldo_recovery_complete = NULL
183};
184
185static const struct cl_device_operations osc_cl_ops = {
186 .cdo_req_init = osc_req_init
187};
188
189static int osc_device_init(const struct lu_env *env, struct lu_device *d,
190 const char *name, struct lu_device *next)
191{
192 return 0;
193}
194
195static struct lu_device *osc_device_fini(const struct lu_env *env,
196 struct lu_device *d)
197{
198 return NULL;
199}
200
201static struct lu_device *osc_device_free(const struct lu_env *env,
202 struct lu_device *d)
203{
204 struct osc_device *od = lu2osc_dev(d);
205
206 cl_device_fini(lu2cl_dev(d));
207 OBD_FREE_PTR(od);
208 return NULL;
209}
210
211static struct lu_device *osc_device_alloc(const struct lu_env *env,
212 struct lu_device_type *t,
213 struct lustre_cfg *cfg)
214{
215 struct lu_device *d;
216 struct osc_device *od;
217 struct obd_device *obd;
218 int rc;
219
220 OBD_ALLOC_PTR(od);
221 if (od == NULL)
222 return ERR_PTR(-ENOMEM);
223
224 cl_device_init(&od->od_cl, t);
225 d = osc2lu_dev(od);
226 d->ld_ops = &osc_lu_ops;
227 od->od_cl.cd_ops = &osc_cl_ops;
228
229
230 obd = class_name2obd(lustre_cfg_string(cfg, 0));
231 LASSERT(obd != NULL);
232 rc = osc_setup(obd, cfg);
233 if (rc) {
234 osc_device_free(env, d);
235 return ERR_PTR(rc);
236 }
237 od->od_exp = obd->obd_self_export;
238 return d;
239}
240
241static const struct lu_device_type_operations osc_device_type_ops = {
242 .ldto_init = osc_type_init,
243 .ldto_fini = osc_type_fini,
244
245 .ldto_start = osc_type_start,
246 .ldto_stop = osc_type_stop,
247
248 .ldto_device_alloc = osc_device_alloc,
249 .ldto_device_free = osc_device_free,
250
251 .ldto_device_init = osc_device_init,
252 .ldto_device_fini = osc_device_fini
253};
254
255struct lu_device_type osc_device_type = {
256 .ldt_tags = LU_DEVICE_CL,
257 .ldt_name = LUSTRE_OSC_NAME,
258 .ldt_ops = &osc_device_type_ops,
259 .ldt_ctx_tags = LCT_CL_THREAD
260};
261
262
263