4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39 * Author: Mike Pershin <tappro@whamcloud.com>
40 * Author: Johann Lombardi <johann@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_FILTER
45 #include <obd_class.h>
46 #include <lustre_param.h>
48 #include "ofd_internal.h"
50 /* Slab for OFD object allocation */
51 static cfs_mem_cache_t *ofd_object_kmem;
53 static struct lu_kmem_descr ofd_caches[] = {
55 .ckd_cache = &ofd_object_kmem,
56 .ckd_name = "ofd_obj",
57 .ckd_size = sizeof(struct ofd_object)
64 /* used by MGS to process specific configurations */
65 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
66 struct lustre_cfg *cfg)
72 switch (cfg->lcfg_command) {
74 struct lprocfs_static_vars lvars;
76 lprocfs_ofd_init_vars(&lvars);
77 rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, cfg,
81 case LCFG_SPTLRPC_CONF: {
91 struct lu_object_operations ofd_obj_ops = {
94 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
95 const struct lu_object_header *hdr,
98 struct ofd_object *of;
102 OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, CFS_ALLOC_IO);
105 struct lu_object_header *h;
107 o = &of->ofo_obj.do_lu;
109 lu_object_header_init(h);
110 lu_object_init(o, h, d);
111 lu_object_add_top(h, o);
112 o->lo_ops = &ofd_obj_ops;
119 static int ofd_start(const struct lu_env *env, struct lu_device *parent,
120 struct lu_device *dev)
122 struct obd_device *obd = dev->ld_obd;
127 LASSERT(obd->obd_no_conn);
128 cfs_spin_lock(&obd->obd_dev_lock);
129 obd->obd_no_conn = 0;
130 cfs_spin_unlock(&obd->obd_dev_lock);
135 static int ofd_recovery_complete(const struct lu_env *env,
136 struct lu_device *dev)
145 static struct lu_device_operations ofd_lu_ops = {
146 .ldo_object_alloc = ofd_object_alloc,
147 .ldo_process_config = ofd_process_config,
148 .ldo_prepare = ofd_start,
149 .ldo_recovery_complete = ofd_recovery_complete,
152 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
153 struct lu_device_type *ldt, struct lustre_cfg *cfg)
155 const char *dev = lustre_cfg_string(cfg, 0);
156 struct obd_device *obd;
161 obd = class_name2obd(dev);
163 CERROR("Cannot find obd with name %s\n", dev);
167 rc = lu_env_refill((struct lu_env *)env);
171 obd->u.obt.obt_magic = OBT_MAGIC;
173 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
174 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
175 /* set this lu_device to obd, because error handling need it */
176 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
178 /* No connection accepted until configurations will finish */
179 obd->obd_no_conn = 1;
180 obd->obd_replayable = 1;
181 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
182 char *str = lustre_cfg_string(cfg, 4);
184 if (strchr(str, 'n')) {
185 CWARN("%s: recovery disabled\n", obd->obd_name);
186 obd->obd_replayable = 0;
193 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
195 struct obd_device *obd = ofd_obd(m);
196 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
198 obd_exports_barrier(obd);
199 obd_zombie_barrier();
201 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
205 static struct lu_device* ofd_device_fini(const struct lu_env *env,
209 ofd_fini(env, ofd_dev(d));
213 static struct lu_device *ofd_device_free(const struct lu_env *env,
216 struct ofd_device *m = ofd_dev(d);
218 dt_device_fini(&m->ofd_dt_dev);
223 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
224 struct lu_device_type *t,
225 struct lustre_cfg *cfg)
227 struct ofd_device *m;
233 return ERR_PTR(-ENOMEM);
235 l = &m->ofd_dt_dev.dd_lu_dev;
236 dt_device_init(&m->ofd_dt_dev, t);
237 rc = ofd_init0(env, m, t, cfg);
239 ofd_device_free(env, l);
246 /* thread context key constructor/destructor */
247 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
249 static void ofd_key_exit(const struct lu_context *ctx,
250 struct lu_context_key *key, void *data)
252 struct ofd_thread_info *info = data;
254 info->fti_env = NULL;
257 struct lu_context_key ofd_thread_key = {
258 .lct_tags = LCT_DT_THREAD,
259 .lct_init = ofd_key_init,
260 .lct_fini = ofd_key_fini,
261 .lct_exit = ofd_key_exit
264 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
265 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
267 static struct lu_device_type_operations ofd_device_type_ops = {
268 .ldto_init = ofd_type_init,
269 .ldto_fini = ofd_type_fini,
271 .ldto_start = ofd_type_start,
272 .ldto_stop = ofd_type_stop,
274 .ldto_device_alloc = ofd_device_alloc,
275 .ldto_device_free = ofd_device_free,
276 .ldto_device_fini = ofd_device_fini
279 static struct lu_device_type ofd_device_type = {
280 .ldt_tags = LU_DEVICE_DT,
281 .ldt_name = LUSTRE_OST_NAME,
282 .ldt_ops = &ofd_device_type_ops,
283 .ldt_ctx_tags = LCT_DT_THREAD
286 int __init ofd_init(void)
288 struct lprocfs_static_vars lvars;
291 rc = lu_kmem_init(ofd_caches);
295 lprocfs_ofd_init_vars(&lvars);
297 rc = class_register_type(&ofd_obd_ops, NULL, lvars.module_vars,
298 LUSTRE_OST_NAME, &ofd_device_type);
302 void __exit ofd_exit(void)
304 class_unregister_type(LUSTRE_OST_NAME);
305 lu_kmem_fini(ofd_caches);
308 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
309 MODULE_DESCRIPTION("Lustre Object Filtering Device");
310 MODULE_LICENSE("GPL");
312 module_init(ofd_init);
313 module_exit(ofd_exit);