Whamcloud - gitweb
1d2c5fbda5fb5c928ce4106e3213ed851699153a
[fs/lustre-release.git] / lustre / osp / osp_dev.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/osp/osp_dev.c
37  *
38  * Lustre OST Proxy Device
39  *
40  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41  * Author: Mikhail Pershin <mike.pershin@intel.com>
42  */
43
44 #ifndef EXPORT_SYMTAB
45 # define EXPORT_SYMTAB
46 #endif
47 #define DEBUG_SUBSYSTEM S_MDS
48
49 #include <obd_class.h>
50 #include <lustre_param.h>
51
52 #include "osp_internal.h"
53
54 /* Slab for OSP object allocation */
55 cfs_mem_cache_t *osp_object_kmem;
56
57 static struct lu_kmem_descr osp_caches[] = {
58         {
59                 .ckd_cache = &osp_object_kmem,
60                 .ckd_name  = "osp_obj",
61                 .ckd_size  = sizeof(struct osp_object)
62         },
63         {
64                 .ckd_cache = NULL
65         }
66 };
67
68 struct lu_object *osp_object_alloc(const struct lu_env *env,
69                                    const struct lu_object_header *hdr,
70                                    struct lu_device *d)
71 {
72         struct lu_object_header *h;
73         struct osp_object       *o;
74         struct lu_object        *l;
75
76         LASSERT(hdr == NULL);
77
78         OBD_SLAB_ALLOC_PTR_GFP(o, osp_object_kmem, CFS_ALLOC_IO);
79         if (o != NULL) {
80                 l = &o->opo_obj.do_lu;
81                 h = &o->opo_header;
82
83                 lu_object_header_init(h);
84                 dt_object_init(&o->opo_obj, h, d);
85                 lu_object_add_top(h, l);
86
87                 l->lo_ops = &osp_lu_obj_ops;
88
89                 return l;
90         } else {
91                 return NULL;
92         }
93 }
94
95 /* Update opd_last_used_id along with checking for gap in objid sequence */
96 void osp_update_last_id(struct osp_device *d, obd_id objid)
97 {
98         /*
99          * we might have lost precreated objects due to VBR and precreate
100          * orphans, the gap in objid can be calculated properly only here
101          */
102         if (objid > le64_to_cpu(d->opd_last_used_id)) {
103                 if (objid - le64_to_cpu(d->opd_last_used_id) > 1) {
104                         d->opd_gap_start = le64_to_cpu(d->opd_last_used_id) + 1;
105                         d->opd_gap_count = objid - d->opd_gap_start;
106                         CDEBUG(D_HA, "Gap in objids: %d, start = %llu\n",
107                                d->opd_gap_count, d->opd_gap_start);
108                 }
109                 d->opd_last_used_id = cpu_to_le64(objid);
110         }
111 }
112
113 static int osp_last_used_init(const struct lu_env *env, struct osp_device *m)
114 {
115         struct osp_thread_info  *osi = osp_env_info(env);
116         struct dt_object_format  dof = { 0 };
117         struct dt_object        *o;
118         int                      rc;
119
120         ENTRY;
121
122         osi->osi_attr.la_valid = LA_MODE;
123         osi->osi_attr.la_mode = S_IFREG | 0644;
124         lu_local_obj_fid(&osi->osi_fid, MDD_LOV_OBJ_OID);
125         dof.dof_type = DFT_REGULAR;
126         o = dt_find_or_create(env, m->opd_storage, &osi->osi_fid, &dof,
127                               &osi->osi_attr);
128         if (IS_ERR(o))
129                 RETURN(PTR_ERR(o));
130
131         rc = dt_attr_get(env, o, &osi->osi_attr, NULL);
132         if (rc)
133                 GOTO(out, rc);
134
135         m->opd_last_used_file = o;
136
137         if (osi->osi_attr.la_size >= sizeof(osi->osi_id) *
138                                      (m->opd_index + 1)) {
139                 osp_objid_buf_prep(osi, m, m->opd_index);
140                 rc = dt_record_read(env, o, &osi->osi_lb, &osi->osi_off);
141                 if (rc != 0)
142                         GOTO(out, rc);
143         } else {
144                 /* reset value to 0, just to make sure and change file's size */
145                 struct thandle *th;
146
147                 m->opd_last_used_id = 0;
148                 osp_objid_buf_prep(osi, m, m->opd_index);
149
150                 th = dt_trans_create(env, m->opd_storage);
151                 if (IS_ERR(th))
152                         GOTO(out, rc = PTR_ERR(th));
153
154                 rc = dt_declare_record_write(env, m->opd_last_used_file,
155                                              osi->osi_lb.lb_len, osi->osi_off,
156                                              th);
157                 if (rc) {
158                         dt_trans_stop(env, m->opd_storage, th);
159                         GOTO(out, rc);
160                 }
161
162                 rc = dt_trans_start_local(env, m->opd_storage, th);
163                 if (rc) {
164                         dt_trans_stop(env, m->opd_storage, th);
165                         GOTO(out, rc);
166                 }
167
168                 rc = dt_record_write(env, m->opd_last_used_file, &osi->osi_lb,
169                                      &osi->osi_off, th);
170                 dt_trans_stop(env, m->opd_storage, th);
171                 if (rc)
172                         GOTO(out, rc);
173         }
174         RETURN(0);
175 out:
176         /* object will be released in device cleanup path */
177         CERROR("%s: can't initialize lov_objid: %d\n",
178                m->opd_obd->obd_name, rc);
179         lu_object_put(env, &o->do_lu);
180         m->opd_last_used_file = NULL;
181         RETURN(rc);
182 }
183
184 static void osp_last_used_fini(const struct lu_env *env, struct osp_device *d)
185 {
186         lu_object_put(env, &d->opd_last_used_file->do_lu);
187         d->opd_last_used_file = NULL;
188 }
189
190 static int osp_shutdown(const struct lu_env *env, struct osp_device *d)
191 {
192         struct obd_import       *imp;
193         int                      rc = 0;
194         ENTRY;
195
196         /* release last_used file */
197         osp_last_used_fini(env, d);
198
199         imp = d->opd_obd->u.cli.cl_import;
200
201         /* Mark import deactivated now, so we don't try to reconnect if any
202          * of the cleanup RPCs fails (e.g. ldlm cancel, etc).  We don't
203          * fully deactivate the import, or that would drop all requests. */
204         cfs_spin_lock(&imp->imp_lock);
205         imp->imp_deactive = 1;
206         cfs_spin_unlock(&imp->imp_lock);
207
208         ptlrpc_deactivate_import(imp);
209
210         /* Some non-replayable imports (MDS's OSCs) are pinged, so just
211          * delete it regardless.  (It's safe to delete an import that was
212          * never added.) */
213         (void)ptlrpc_pinger_del_import(imp);
214
215         rc = ptlrpc_disconnect_import(imp, 0);
216         if (rc)
217                 CERROR("%s: can't disconnect: rc = %d\n",
218                        d->opd_obd->obd_name, rc);
219
220         ptlrpc_invalidate_import(imp);
221
222         RETURN(rc);
223 }
224
225 static int osp_process_config(const struct lu_env *env,
226                               struct lu_device *dev, struct lustre_cfg *lcfg)
227 {
228         struct osp_device               *d = lu2osp_dev(dev);
229         struct lprocfs_static_vars       lvars = { 0 };
230         int                              rc;
231
232         ENTRY;
233
234         switch (lcfg->lcfg_command) {
235         case LCFG_CLEANUP:
236                 lu_dev_del_linkage(dev->ld_site, dev);
237                 rc = osp_shutdown(env, d);
238                 break;
239         case LCFG_PARAM:
240                 lprocfs_osp_init_vars(&lvars);
241
242                 LASSERT(d->opd_obd);
243                 rc = class_process_proc_param(PARAM_OSP, lvars.obd_vars,
244                                               lcfg, d->opd_obd);
245                 if (rc > 0)
246                         rc = 0;
247                 if (rc == -ENOSYS) {
248                         /* class_process_proc_param() haven't found matching
249                          * parameter and returned ENOSYS so that layer(s)
250                          * below could use that. But OSP is the bottom, so
251                          * just ignore it */
252                         CERROR("%s: unknown param %s\n",
253                                (char *)lustre_cfg_string(lcfg, 0),
254                                (char *)lustre_cfg_string(lcfg, 1));
255                         rc = 0;
256                 }
257                 break;
258         default:
259                 CERROR("%s: unknown command %u\n",
260                        (char *)lustre_cfg_string(lcfg, 0), lcfg->lcfg_command);
261                 rc = 0;
262                 break;
263         }
264
265         RETURN(rc);
266 }
267
268 static int osp_recovery_complete(const struct lu_env *env,
269                                  struct lu_device *dev)
270 {
271         struct osp_device       *osp = lu2osp_dev(dev);
272         int                      rc = 0;
273
274         ENTRY;
275         osp->opd_recovery_completed = 1;
276         RETURN(rc);
277 }
278
279 const struct lu_device_operations osp_lu_ops = {
280         .ldo_object_alloc       = osp_object_alloc,
281         .ldo_process_config     = osp_process_config,
282         .ldo_recovery_complete  = osp_recovery_complete,
283 };
284
285 static int osp_sync(const struct lu_env *env, struct dt_device *dev)
286 {
287         ENTRY;
288
289         /*
290          * XXX: wake up sync thread, command it to start flushing asap?
291          */
292
293         RETURN(0);
294 }
295
296 static const struct dt_device_operations osp_dt_ops = {
297         .dt_sync        = osp_sync,
298 };
299
300 static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *m,
301                               const char *nextdev)
302 {
303         struct obd_connect_data *data = NULL;
304         struct obd_device       *obd;
305         int                      rc;
306
307         ENTRY;
308
309         LASSERT(m->opd_storage_exp == NULL);
310
311         OBD_ALLOC_PTR(data);
312         if (data == NULL)
313                 RETURN(-ENOMEM);
314
315         obd = class_name2obd(nextdev);
316         if (obd == NULL) {
317                 CERROR("%s: can't locate next device: %s\n",
318                        m->opd_obd->obd_name, nextdev);
319                 GOTO(out, rc = -ENOTCONN);
320         }
321
322         rc = obd_connect(env, &m->opd_storage_exp, obd, &obd->obd_uuid, data,
323                          NULL);
324         if (rc) {
325                 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
326                        m->opd_obd->obd_name, nextdev, rc);
327                 GOTO(out, rc);
328         }
329
330         m->opd_dt_dev.dd_lu_dev.ld_site =
331                 m->opd_storage_exp->exp_obd->obd_lu_dev->ld_site;
332         LASSERT(m->opd_dt_dev.dd_lu_dev.ld_site);
333         m->opd_storage = lu2dt_dev(m->opd_storage_exp->exp_obd->obd_lu_dev);
334
335 out:
336         OBD_FREE_PTR(data);
337         RETURN(rc);
338 }
339
340 static int osp_init0(const struct lu_env *env, struct osp_device *m,
341                      struct lu_device_type *ldt, struct lustre_cfg *cfg)
342 {
343         struct lprocfs_static_vars       lvars = { 0 };
344         struct proc_dir_entry           *osc_proc_dir;
345         struct obd_import               *imp;
346         class_uuid_t                     uuid;
347         char                            *src, *ost, *mdt, *osdname = NULL;
348         int                              rc, idx;
349
350         ENTRY;
351
352         m->opd_obd = class_name2obd(lustre_cfg_string(cfg, 0));
353         if (m->opd_obd == NULL) {
354                 CERROR("Cannot find obd with name %s\n",
355                        lustre_cfg_string(cfg, 0));
356                 RETURN(-ENODEV);
357         }
358
359         /* There is no record in the MDT configuration for the local disk
360          * device, so we have to extract this from elsewhere in the profile.
361          * The only information we get at setup is from the OSC records:
362          * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
363          * Note that 1.8 generated configs are missing the -MDTxxxx part.
364          * We need to reconstruct the name of the underlying OSD from this:
365          * {fsname}-{svname}-osd, for example "lustre-MDT0000-osd".  We
366          * also need to determine the OST index from this - will be used
367          * to calculate the offset in shared lov_objids file later */
368
369         src = lustre_cfg_string(cfg, 0);
370         if (src == NULL)
371                 RETURN(-EINVAL);
372
373         ost = strstr(src, "-OST");
374         if (ost == NULL)
375                 RETURN(-EINVAL);
376
377         idx = simple_strtol(ost + 4, &mdt, 16);
378         if (mdt[0] != '-' || idx > INT_MAX || idx < 0) {
379                 CERROR("%s: invalid OST index in '%s'\n",
380                        m->opd_obd->obd_name, src);
381                 GOTO(out_fini, rc = -EINVAL);
382         }
383         m->opd_index = idx;
384
385         idx = ost - src;
386         /* check the fsname length, and after this everything else will fit */
387         if (idx > MTI_NAME_MAXLEN) {
388                 CERROR("%s: fsname too long in '%s'\n",
389                        m->opd_obd->obd_name, src);
390                 GOTO(out_fini, rc = -EINVAL);
391         }
392
393         OBD_ALLOC(osdname, MAX_OBD_NAME);
394         if (osdname == NULL)
395                 GOTO(out_fini, rc = -ENOMEM);
396
397         memcpy(osdname, src, idx); /* copy just the fsname part */
398         osdname[idx] = '\0';
399
400         mdt = strstr(mdt, "-MDT");
401         if (mdt == NULL) /* 1.8 configs don't have "-MDT0000" at the end */
402                 strcat(osdname, "-MDT0000");
403         else
404                 strcat(osdname, mdt);
405         strcat(osdname, "-osd");
406         CDEBUG(D_HA, "%s: connect to %s (%s)\n",
407                m->opd_obd->obd_name, osdname, src);
408
409         m->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
410         m->opd_dt_dev.dd_ops = &osp_dt_ops;
411         m->opd_obd->obd_lu_dev = &m->opd_dt_dev.dd_lu_dev;
412
413         rc = osp_connect_to_osd(env, m, osdname);
414         if (rc)
415                 GOTO(out_fini, rc);
416
417         rc = ptlrpcd_addref();
418         if (rc)
419                 GOTO(out_disconnect, rc);
420
421         rc = client_obd_setup(m->opd_obd, cfg);
422         if (rc) {
423                 CERROR("%s: can't setup obd: %d\n", m->opd_obd->obd_name, rc);
424                 GOTO(out_ref, rc);
425         }
426
427         lprocfs_osp_init_vars(&lvars);
428         if (lprocfs_obd_setup(m->opd_obd, lvars.obd_vars) == 0)
429                 ptlrpc_lprocfs_register_obd(m->opd_obd);
430
431         /* for compatibility we link old procfs's OSC entries to osp ones */
432         osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
433         if (osc_proc_dir) {
434                 cfs_proc_dir_entry_t    *symlink = NULL;
435                 char                    *name;
436
437                 OBD_ALLOC(name, strlen(m->opd_obd->obd_name) + 1);
438                 if (name == NULL)
439                         GOTO(out, rc = -ENOMEM);
440
441                 strcpy(name, m->opd_obd->obd_name);
442                 if (strstr(name, "osc"))
443                         symlink = lprocfs_add_symlink(name, osc_proc_dir,
444                                                       "../osp/%s",
445                                                       m->opd_obd->obd_name);
446                 OBD_FREE(name, strlen(m->opd_obd->obd_name) + 1);
447                 m->opd_symlink = symlink;
448         }
449
450         /*
451          * Initialize last id from the storage - will be used in orphan cleanup
452          */
453         rc = osp_last_used_init(env, m);
454         if (rc)
455                 GOTO(out_proc, rc);
456
457         /*
458          * Initiate connect to OST
459          */
460         ll_generate_random_uuid(uuid);
461         class_uuid_unparse(uuid, &m->opd_cluuid);
462
463         imp = m->opd_obd->u.cli.cl_import;
464
465         rc = ptlrpc_init_import(imp);
466         if (rc)
467                 GOTO(out, rc);
468         if (osdname)
469                 OBD_FREE(osdname, MAX_OBD_NAME);
470         RETURN(0);
471
472 out:
473         osp_last_used_fini(env, m);
474 out_proc:
475         ptlrpc_lprocfs_unregister_obd(m->opd_obd);
476         lprocfs_obd_cleanup(m->opd_obd);
477         class_destroy_import(m->opd_obd->u.cli.cl_import);
478         client_obd_cleanup(m->opd_obd);
479 out_ref:
480         ptlrpcd_decref();
481 out_disconnect:
482         obd_disconnect(m->opd_storage_exp);
483 out_fini:
484         if (osdname)
485                 OBD_FREE(osdname, MAX_OBD_NAME);
486         RETURN(rc);
487 }
488
489 static struct lu_device *osp_device_free(const struct lu_env *env,
490                                          struct lu_device *lu)
491 {
492         struct osp_device *m = lu2osp_dev(lu);
493
494         ENTRY;
495
496         dt_device_fini(&m->opd_dt_dev);
497         OBD_FREE_PTR(m);
498         RETURN(NULL);
499 }
500
501 static struct lu_device *osp_device_alloc(const struct lu_env *env,
502                                           struct lu_device_type *t,
503                                           struct lustre_cfg *lcfg)
504 {
505         struct osp_device *m;
506         struct lu_device  *l;
507
508         OBD_ALLOC_PTR(m);
509         if (m == NULL) {
510                 l = ERR_PTR(-ENOMEM);
511         } else {
512                 int rc;
513
514                 l = osp2lu_dev(m);
515                 dt_device_init(&m->opd_dt_dev, t);
516                 rc = osp_init0(env, m, t, lcfg);
517                 if (rc != 0) {
518                         osp_device_free(env, l);
519                         l = ERR_PTR(rc);
520                 }
521         }
522         return l;
523 }
524
525 static struct lu_device *osp_device_fini(const struct lu_env *env,
526                                          struct lu_device *d)
527 {
528         struct osp_device *m = lu2osp_dev(d);
529         struct obd_import *imp;
530         int                rc;
531
532         ENTRY;
533
534         LASSERT(m->opd_storage_exp);
535         obd_disconnect(m->opd_storage_exp);
536
537         imp = m->opd_obd->u.cli.cl_import;
538
539         if (imp->imp_rq_pool) {
540                 ptlrpc_free_rq_pool(imp->imp_rq_pool);
541                 imp->imp_rq_pool = NULL;
542         }
543
544         obd_cleanup_client_import(m->opd_obd);
545
546         if (m->opd_symlink)
547                 lprocfs_remove(&m->opd_symlink);
548
549         LASSERT(m->opd_obd);
550         ptlrpc_lprocfs_unregister_obd(m->opd_obd);
551         lprocfs_obd_cleanup(m->opd_obd);
552
553         rc = client_obd_cleanup(m->opd_obd);
554         LASSERTF(rc == 0, "error %d\n", rc);
555
556         ptlrpcd_decref();
557
558         RETURN(NULL);
559 }
560
561 static int osp_reconnect(const struct lu_env *env,
562                          struct obd_export *exp, struct obd_device *obd,
563                          struct obd_uuid *cluuid,
564                          struct obd_connect_data *data,
565                          void *localdata)
566 {
567         return 0;
568 }
569
570 /*
571  * we use exports to track all LOD users
572  */
573 static int osp_obd_connect(const struct lu_env *env, struct obd_export **exp,
574                            struct obd_device *obd, struct obd_uuid *cluuid,
575                            struct obd_connect_data *data, void *localdata)
576 {
577         struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
578         struct obd_connect_data *ocd;
579         struct obd_import       *imp;
580         struct lustre_handle     conn;
581         int                      rc;
582
583         ENTRY;
584
585         CDEBUG(D_CONFIG, "connect #%d\n", osp->opd_connects);
586
587         rc = class_connect(&conn, obd, cluuid);
588         if (rc)
589                 RETURN(rc);
590
591         *exp = class_conn2export(&conn);
592
593         /* Why should there ever be more than 1 connect? */
594         osp->opd_connects++;
595         LASSERT(osp->opd_connects == 1);
596
597         imp = osp->opd_obd->u.cli.cl_import;
598         imp->imp_dlm_handle = conn;
599
600         ocd = &imp->imp_connect_data;
601         ocd->ocd_connect_flags = OBD_CONNECT_AT |
602                                  OBD_CONNECT_FULL20 |
603                                  OBD_CONNECT_INDEX |
604 #ifdef HAVE_LRU_RESIZE_SUPPORT
605                                  OBD_CONNECT_LRU_RESIZE |
606 #endif
607                                  OBD_CONNECT_MDS |
608                                  OBD_CONNECT_OSS_CAPA |
609                                  OBD_CONNECT_REQPORTAL |
610                                  OBD_CONNECT_SKIP_ORPHAN |
611                                  OBD_CONNECT_VERSION;
612         ocd->ocd_version = LUSTRE_VERSION_CODE;
613         LASSERT(data->ocd_connect_flags & OBD_CONNECT_INDEX);
614         ocd->ocd_index = data->ocd_index;
615         imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
616
617         rc = ptlrpc_connect_import(imp);
618         if (rc) {
619                 CERROR("%s: can't connect obd: rc = %d\n", obd->obd_name, rc);
620                 GOTO(out, rc);
621         }
622
623         ptlrpc_pinger_add_import(imp);
624
625 out:
626         RETURN(rc);
627 }
628
629 /*
630  * once last export (we don't count self-export) disappeared
631  * osp can be released
632  */
633 static int osp_obd_disconnect(struct obd_export *exp)
634 {
635         struct obd_device *obd = exp->exp_obd;
636         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
637         int                rc;
638
639         ENTRY;
640
641         /* Only disconnect the underlying layers on the final disconnect. */
642         LASSERT(osp->opd_connects == 1);
643         osp->opd_connects--;
644
645         rc = class_disconnect(exp);
646
647         /* destroy the device */
648         if (rc == 0)
649                 class_manual_cleanup(obd);
650
651         RETURN(rc);
652 }
653
654 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
655 LU_KEY_INIT_FINI(osp, struct osp_thread_info);
656 static void osp_key_exit(const struct lu_context *ctx,
657                          struct lu_context_key *key, void *data)
658 {
659         struct osp_thread_info *info = data;
660
661         info->osi_attr.la_valid = 0;
662 }
663
664 struct lu_context_key osp_thread_key = {
665         .lct_tags = LCT_MD_THREAD,
666         .lct_init = osp_key_init,
667         .lct_fini = osp_key_fini,
668         .lct_exit = osp_key_exit
669 };
670
671 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
672 LU_KEY_INIT_FINI(osp_txn, struct osp_txn_info);
673
674 struct lu_context_key osp_txn_key = {
675         .lct_tags = LCT_OSP_THREAD,
676         .lct_init = osp_txn_key_init,
677         .lct_fini = osp_txn_key_fini
678 };
679 LU_TYPE_INIT_FINI(osp, &osp_thread_key, &osp_txn_key);
680
681 static struct lu_device_type_operations osp_device_type_ops = {
682         .ldto_init           = osp_type_init,
683         .ldto_fini           = osp_type_fini,
684
685         .ldto_start          = osp_type_start,
686         .ldto_stop           = osp_type_stop,
687
688         .ldto_device_alloc   = osp_device_alloc,
689         .ldto_device_free    = osp_device_free,
690
691         .ldto_device_fini    = osp_device_fini
692 };
693
694 static struct lu_device_type osp_device_type = {
695         .ldt_tags     = LU_DEVICE_DT,
696         .ldt_name     = LUSTRE_OSP_NAME,
697         .ldt_ops      = &osp_device_type_ops,
698         .ldt_ctx_tags = LCT_MD_THREAD
699 };
700
701 static struct obd_ops osp_obd_device_ops = {
702         .o_owner        = THIS_MODULE,
703         .o_add_conn     = client_import_add_conn,
704         .o_del_conn     = client_import_del_conn,
705         .o_reconnect    = osp_reconnect,
706         .o_connect      = osp_obd_connect,
707         .o_disconnect   = osp_obd_disconnect,
708 };
709
710 static int __init osp_mod_init(void)
711 {
712         struct lprocfs_static_vars       lvars;
713         cfs_proc_dir_entry_t            *osc_proc_dir;
714         int                              rc;
715
716         rc = lu_kmem_init(osp_caches);
717         if (rc)
718                 return rc;
719
720         lprocfs_osp_init_vars(&lvars);
721
722         rc = class_register_type(&osp_obd_device_ops, NULL, lvars.module_vars,
723                                  LUSTRE_OSP_NAME, &osp_device_type);
724
725         /* create "osc" entry in procfs for compatibility purposes */
726         if (rc != 0) {
727                 lu_kmem_fini(osp_caches);
728                 return rc;
729         }
730
731         osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
732         if (osc_proc_dir == NULL) {
733                 osc_proc_dir = lprocfs_register("osc", proc_lustre_root, NULL,
734                                                 NULL);
735                 if (IS_ERR(osc_proc_dir))
736                         CERROR("osp: can't create compat entry \"osc\": %d\n",
737                                (int) PTR_ERR(osc_proc_dir));
738         }
739         return rc;
740 }
741
742 static void __exit osp_mod_exit(void)
743 {
744         lprocfs_try_remove_proc_entry("osc", proc_lustre_root);
745
746         class_unregister_type(LUSTRE_OSP_NAME);
747         lu_kmem_fini(osp_caches);
748 }
749
750 MODULE_AUTHOR("Intel, Inc. <http://www.intel.com/>");
751 MODULE_DESCRIPTION("Lustre OST Proxy Device ("LUSTRE_OSP_NAME")");
752 MODULE_LICENSE("GPL");
753
754 cfs_module(osp, LUSTRE_VERSION_STRING, osp_mod_init, osp_mod_exit);
755