Whamcloud - gitweb
LU-14487 modules: remove references to Sun Trademark.
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/osp/osp_dev.c
32  *
33  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
34  * Author: Mikhail Pershin <mike.pershin@intel.com>
35  * Author: Di Wang <di.wang@intel.com>
36  */
37 /*
38  * The Object Storage Proxy (OSP) module provides an implementation of
39  * the DT API for remote MDTs and OSTs. Every local OSP device (or
40  * object) is a proxy for a remote OSD device (or object). Thus OSP
41  * converts DT operations into RPCs, which are sent to the OUT service
42  * on a remote target, converted back to DT operations, and
43  * executed. Of course there are many ways in which this description
44  * is inaccurate but it's a good enough mental model. OSP is used by
45  * the MDT stack in several ways:
46  *
47  * - OSP devices allocate FIDs for the stripe sub-objects of a striped
48  *   file or directory.
49  *
50  * - OSP objects represent the remote MDT and OST objects that are
51  *   the stripes of a striped object.
52  *
53  * - OSP devices log, send, and track synchronous operations (setattr
54  *   and unlink) to remote targets.
55  *
56  * - OSP objects are the bottom slice of the compound LU object
57  *   representing a remote MDT object: MDT/MDD/LOD/OSP.
58  *
59  * - OSP objects are used by LFSCK to represent remote OST objects
60  *   during the verification of MDT-OST consistency.
61  *
62  * - OSP devices batch idempotent requests (declare_attr_get() and
63  *   declare_xattr_get()) to the remote target and cache their results.
64  *
65  * In addition the OSP layer implements a subset of the OBD device API
66  * to support being a client of a remote target, connecting to other
67  * layers, and FID allocation.
68  */
69
70 #define DEBUG_SUBSYSTEM S_MDS
71
72 #include <linux/kthread.h>
73
74 #include <uapi/linux/lustre/lustre_ioctl.h>
75 #include <lustre_log.h>
76 #include <lustre_obdo.h>
77 #include <uapi/linux/lustre/lustre_param.h>
78 #include <obd_class.h>
79
80 #include "osp_internal.h"
81
82 /* Slab for OSP object allocation */
83 struct kmem_cache *osp_object_kmem;
84
85 static struct lu_kmem_descr osp_caches[] = {
86         {
87                 .ckd_cache = &osp_object_kmem,
88                 .ckd_name  = "osp_obj",
89                 .ckd_size  = sizeof(struct osp_object)
90         },
91         {
92                 .ckd_cache = NULL
93         }
94 };
95
96 /**
97  * Implementation of lu_device_operations::ldo_object_alloc
98  *
99  * Allocates an OSP object in memory, whose FID is on the remote target.
100  *
101  * \param[in] env       execution environment
102  * \param[in] hdr       The header of the object stack. If it is NULL, it
103  *                      means the object is not built from top device, i.e.
104  *                      it is a sub-stripe object of striped directory or
105  *                      an OST object.
106  * \param[in] d         OSP device
107  *
108  * \retval object       object being created if the creation succeed.
109  * \retval NULL         NULL if the creation failed.
110  */
111 static struct lu_object *osp_object_alloc(const struct lu_env *env,
112                                           const struct lu_object_header *hdr,
113                                           struct lu_device *d)
114 {
115         struct lu_object_header *h = NULL;
116         struct osp_object       *o;
117         struct lu_object        *l;
118
119         OBD_SLAB_ALLOC_PTR_GFP(o, osp_object_kmem, GFP_NOFS);
120         if (o != NULL) {
121                 l = &o->opo_obj.do_lu;
122
123                 /* If hdr is NULL, it means the object is not built
124                  * from the top dev(MDT/OST), usually it happens when
125                  * building striped object, like data object on MDT or
126                  * striped object for directory */
127                 if (hdr == NULL) {
128                         h = &o->opo_header;
129                         lu_object_header_init(h);
130                         dt_object_init(&o->opo_obj, h, d);
131                         lu_object_add_top(h, l);
132                 } else {
133                         dt_object_init(&o->opo_obj, h, d);
134                 }
135
136                 l->lo_ops = &osp_lu_obj_ops;
137
138                 return l;
139         } else {
140                 return NULL;
141         }
142 }
143
144 /**
145  * Find or create the local object
146  *
147  * Finds or creates the local file referenced by \a reg_id and return the
148  * attributes of the local file.
149  *
150  * \param[in] env       execution environment
151  * \param[in] osp       OSP device
152  * \param[out] attr     attributes of the object
153  * \param[in] reg_id    the local object ID of the file. It will be used
154  *                      to compose a local FID{FID_SEQ_LOCAL_FILE, reg_id, 0}
155  *                      to identify the object.
156  *
157  * \retval object               object(dt_object) found or created
158  * \retval ERR_PTR(errno)       ERR_PTR(errno) if not get the object.
159  */
160 static struct dt_object
161 *osp_find_or_create_local_file(const struct lu_env *env, struct osp_device *osp,
162                                struct lu_attr *attr, __u32 reg_id)
163 {
164         struct osp_thread_info *osi = osp_env_info(env);
165         struct dt_object_format dof = { 0 };
166         struct dt_object       *dto;
167         int                  rc;
168         ENTRY;
169
170         lu_local_obj_fid(&osi->osi_fid, reg_id);
171         attr->la_valid = LA_MODE;
172         attr->la_mode = S_IFREG | 0644;
173         dof.dof_type = DFT_REGULAR;
174         /* Find or create the local object by osi_fid. */
175         dto = dt_find_or_create(env, osp->opd_storage, &osi->osi_fid,
176                                 &dof, attr);
177         if (IS_ERR(dto))
178                 RETURN(dto);
179
180         /* Get attributes of the local object. */
181         rc = dt_attr_get(env, dto, attr);
182         if (rc) {
183                 CERROR("%s: can't be initialized: rc = %d\n",
184                        osp->opd_obd->obd_name, rc);
185                 dt_object_put(env, dto);
186                 RETURN(ERR_PTR(rc));
187         }
188         RETURN(dto);
189 }
190
191 /**
192  * Write data buffer to a local file object.
193  *
194  * \param[in] env       execution environment
195  * \param[in] osp       OSP device
196  * \param[in] dt_obj    object written to
197  * \param[in] buf       buffer containing byte array and length
198  * \param[in] offset    write offset in the object in bytes
199  *
200  * \retval 0            0 if write succeed
201  * \retval -EFAULT      -EFAULT if only part of buffer is written.
202  * \retval negative             other negative errno if write failed.
203  */
204 static int osp_write_local_file(const struct lu_env *env,
205                                 struct osp_device *osp,
206                                 struct dt_object *dt_obj,
207                                 struct lu_buf *buf,
208                                 loff_t offset)
209 {
210         struct thandle *th;
211         int rc;
212
213         if (osp->opd_storage->dd_rdonly)
214                 RETURN(0);
215
216         th = dt_trans_create(env, osp->opd_storage);
217         if (IS_ERR(th))
218                 RETURN(PTR_ERR(th));
219
220         rc = dt_declare_record_write(env, dt_obj, buf, offset, th);
221         if (rc)
222                 GOTO(out, rc);
223         rc = dt_trans_start_local(env, osp->opd_storage, th);
224         if (rc)
225                 GOTO(out, rc);
226
227         rc = dt_record_write(env, dt_obj, buf, &offset, th);
228 out:
229         dt_trans_stop(env, osp->opd_storage, th);
230         RETURN(rc);
231 }
232
233 /**
234  * Initialize last ID object.
235  *
236  * This function initializes the LAST_ID file, which stores the current last
237  * used id of data objects. The MDT will use the last used id and the last_seq
238  * (\see osp_init_last_seq()) to synchronize the precreate object cache with
239  * OSTs.
240  *
241  * \param[in] env       execution environment
242  * \param[in] osp       OSP device
243  *
244  * \retval 0            0 if initialization succeed
245  * \retval negative     negative errno if initialization failed
246  */
247 static int osp_init_last_objid(const struct lu_env *env, struct osp_device *osp)
248 {
249         struct osp_thread_info  *osi = osp_env_info(env);
250         struct lu_fid           *fid = &osp->opd_last_used_fid;
251         struct dt_object        *dto;
252         int                     rc = -EFAULT;
253         ENTRY;
254
255         dto = osp_find_or_create_local_file(env, osp, &osi->osi_attr,
256                                             MDD_LOV_OBJ_OID);
257         if (IS_ERR(dto))
258                 RETURN(PTR_ERR(dto));
259
260         osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, &osp->opd_last_id,
261                            osp->opd_index);
262
263         /* object will be released in device cleanup path */
264         if (osi->osi_attr.la_size >= (osi->osi_off + osi->osi_lb.lb_len)) {
265                 rc = dt_record_read(env, dto, &osi->osi_lb, &osi->osi_off);
266                 if (rc != 0 && rc != -EFAULT)
267                         GOTO(out, rc);
268                 /* In case of idif bits 32-48 go to f_seq
269                  * (see osp_init_last_seq). So don't care
270                  * about u64->u32 convertion. */
271                 fid->f_oid = osp->opd_last_id;
272         }
273
274         if (rc == -EFAULT) { /* fresh LAST_ID */
275                 osp->opd_last_id = 0;
276                 fid->f_oid = 0;
277                 rc = osp_write_local_file(env, osp, dto, &osi->osi_lb,
278                                           osi->osi_off);
279                 if (rc != 0)
280                         GOTO(out, rc);
281         }
282         osp->opd_last_used_oid_file = dto;
283         RETURN(0);
284 out:
285         /* object will be released in device cleanup path */
286         CERROR("%s: can't initialize lov_objid: rc = %d\n",
287                osp->opd_obd->obd_name, rc);
288         dt_object_put(env, dto);
289         osp->opd_last_used_oid_file = NULL;
290         RETURN(rc);
291 }
292
293 /**
294  * Initialize last sequence object.
295  *
296  * This function initializes the LAST_SEQ file in the local OSD, which stores
297  * the current last used sequence of data objects. The MDT will use the last
298  * sequence and last id (\see osp_init_last_objid()) to synchronize the
299  * precreate object cache with OSTs.
300  *
301  * \param[in] env       execution environment
302  * \param[in] osp       OSP device
303  *
304  * \retval 0            0 if initialization succeed
305  * \retval negative     negative errno if initialization failed
306  */
307 static int osp_init_last_seq(const struct lu_env *env, struct osp_device *osp)
308 {
309         struct osp_thread_info  *osi = osp_env_info(env);
310         struct lu_fid           *fid = &osp->opd_last_used_fid;
311         struct dt_object        *dto;
312         int                     rc = -EFAULT;
313         ENTRY;
314
315         dto = osp_find_or_create_local_file(env, osp, &osi->osi_attr,
316                                             MDD_LOV_OBJ_OSEQ);
317         if (IS_ERR(dto))
318                 RETURN(PTR_ERR(dto));
319
320         osp_objseq_buf_prep(&osi->osi_lb, &osi->osi_off, &fid->f_seq,
321                            osp->opd_index);
322
323         /* object will be released in device cleanup path */
324         if (osi->osi_attr.la_size >= (osi->osi_off + osi->osi_lb.lb_len)) {
325                 rc = dt_record_read(env, dto, &osi->osi_lb, &osi->osi_off);
326                 if (rc != 0 && rc != -EFAULT)
327                         GOTO(out, rc);
328                 if (fid_is_idif(fid))
329                         fid->f_seq = fid_idif_seq(osp->opd_last_id,
330                                                   osp->opd_index);
331         }
332
333         if (rc == -EFAULT) { /* fresh OSP */
334                 fid->f_seq = 0;
335                 rc = osp_write_local_file(env, osp, dto, &osi->osi_lb,
336                                           osi->osi_off);
337                 if (rc != 0)
338                         GOTO(out, rc);
339         }
340         osp->opd_last_used_seq_file = dto;
341         RETURN(0);
342 out:
343         /* object will be released in device cleanup path */
344         CERROR("%s: can't initialize lov_seq: rc = %d\n",
345                osp->opd_obd->obd_name, rc);
346         dt_object_put(env, dto);
347         osp->opd_last_used_seq_file = NULL;
348         RETURN(rc);
349 }
350
351 /**
352  * Initialize last OID and sequence object.
353  *
354  * If the MDT is just upgraded to 2.4 from the lower version, where the
355  * LAST_SEQ file does not exist, the file will be created and IDIF sequence
356  * will be written into the file.
357  *
358  * \param[in] env       execution environment
359  * \param[in] osp       OSP device
360  *
361  * \retval 0            0 if initialization succeed
362  * \retval negative     negative error if initialization failed
363  */
364 static int osp_last_used_init(const struct lu_env *env, struct osp_device *osp)
365 {
366         struct osp_thread_info *osi = osp_env_info(env);
367         int                  rc;
368         ENTRY;
369
370         fid_zero(&osp->opd_last_used_fid);
371         rc = osp_init_last_objid(env, osp);
372         if (rc < 0) {
373                 CERROR("%s: Can not get ids %d from old objid!\n",
374                        osp->opd_obd->obd_name, rc);
375                 RETURN(rc);
376         }
377
378         rc = osp_init_last_seq(env, osp);
379         if (rc < 0) {
380                 CERROR("%s: Can not get sequence %d from old objseq!\n",
381                        osp->opd_obd->obd_name, rc);
382                 GOTO(out, rc);
383         }
384
385         if (fid_oid(&osp->opd_last_used_fid) != 0 &&
386             fid_seq(&osp->opd_last_used_fid) == 0) {
387                 /* Just upgrade from the old version,
388                  * set the seq to be IDIF */
389                 osp->opd_last_used_fid.f_seq =
390                    fid_idif_seq(fid_oid(&osp->opd_last_used_fid),
391                                 osp->opd_index);
392                 osp_objseq_buf_prep(&osi->osi_lb, &osi->osi_off,
393                                     &osp->opd_last_used_fid.f_seq,
394                                     osp->opd_index);
395                 rc = osp_write_local_file(env, osp, osp->opd_last_used_seq_file,
396                                           &osi->osi_lb, osi->osi_off);
397                 if (rc) {
398                         CERROR("%s : Can not write seq file: rc = %d\n",
399                                osp->opd_obd->obd_name, rc);
400                         GOTO(out, rc);
401                 }
402         }
403
404         if (!fid_is_zero(&osp->opd_last_used_fid) &&
405                  !fid_is_sane(&osp->opd_last_used_fid)) {
406                 CERROR("%s: Got invalid FID "DFID"\n", osp->opd_obd->obd_name,
407                         PFID(&osp->opd_last_used_fid));
408                 GOTO(out, rc = -EINVAL);
409         }
410
411         osp_fid_to_obdid(&osp->opd_last_used_fid, &osp->opd_last_id);
412         CDEBUG(D_INFO, "%s: Init last used fid "DFID"\n",
413                osp->opd_obd->obd_name, PFID(&osp->opd_last_used_fid));
414 out:
415         if (rc != 0) {
416                 if (osp->opd_last_used_oid_file != NULL) {
417                         dt_object_put(env, osp->opd_last_used_oid_file);
418                         osp->opd_last_used_oid_file = NULL;
419                 }
420                 if (osp->opd_last_used_seq_file != NULL) {
421                         dt_object_put(env, osp->opd_last_used_seq_file);
422                         osp->opd_last_used_seq_file = NULL;
423                 }
424         }
425
426         RETURN(rc);
427 }
428
429 /**
430  * Release the last sequence and OID file objects in OSP device.
431  *
432  * \param[in] env       execution environment
433  * \param[in] osp       OSP device
434  */
435 static void osp_last_used_fini(const struct lu_env *env, struct osp_device *osp)
436 {
437         /* release last_used file */
438         if (osp->opd_last_used_oid_file != NULL) {
439                 dt_object_put(env, osp->opd_last_used_oid_file);
440                 osp->opd_last_used_oid_file = NULL;
441         }
442
443         if (osp->opd_last_used_seq_file != NULL) {
444                 dt_object_put(env, osp->opd_last_used_seq_file);
445                 osp->opd_last_used_seq_file = NULL;
446         }
447 }
448
449 /**
450  * Disconnects the connection between OSP and its correspondent MDT or OST, and
451  * the import will be marked as inactive. It will only be called during OSP
452  * cleanup process.
453  *
454  * \param[in] d         OSP device being disconnected
455  *
456  * \retval 0            0 if disconnection succeed
457  * \retval negative     negative errno if disconnection failed
458  */
459 static int osp_disconnect(struct osp_device *d)
460 {
461         struct obd_device *obd = d->opd_obd;
462         struct obd_import *imp;
463         int rc = 0;
464
465         imp = obd->u.cli.cl_import;
466
467         /* Mark import deactivated now, so we don't try to reconnect if any
468          * of the cleanup RPCs fails (e.g. ldlm cancel, etc).  We don't
469          * fully deactivate the import, or that would drop all requests. */
470         LASSERT(imp != NULL);
471         spin_lock(&imp->imp_lock);
472         imp->imp_deactive = 1;
473         spin_unlock(&imp->imp_lock);
474
475         ptlrpc_deactivate_import(imp);
476
477         /* Some non-replayable imports (MDS's OSCs) are pinged, so just
478          * delete it regardless.  (It's safe to delete an import that was
479          * never added.) */
480         (void)ptlrpc_pinger_del_import(imp);
481
482         rc = ptlrpc_disconnect_import(imp, 0);
483         if (rc != 0)
484                 CERROR("%s: can't disconnect: rc = %d\n", obd->obd_name, rc);
485
486         ptlrpc_invalidate_import(imp);
487
488         RETURN(rc);
489 }
490
491 /**
492  * Initialize the osp_update structure in OSP device
493  *
494  * Allocate osp update structure and start update thread.
495  *
496  * \param[in] osp       OSP device
497  *
498  * \retval              0 if initialization succeeds.
499  * \retval              negative errno if initialization fails.
500  */
501 static int osp_update_init(struct osp_device *osp)
502 {
503         struct task_struct *task;
504         int rc;
505
506         ENTRY;
507
508         LASSERT(osp->opd_connect_mdt);
509
510         if (osp->opd_storage->dd_rdonly)
511                 RETURN(0);
512
513         OBD_ALLOC_PTR(osp->opd_update);
514         if (osp->opd_update == NULL)
515                 RETURN(-ENOMEM);
516
517         init_waitqueue_head(&osp->opd_update->ou_waitq);
518         spin_lock_init(&osp->opd_update->ou_lock);
519         INIT_LIST_HEAD(&osp->opd_update->ou_list);
520         osp->opd_update->ou_rpc_version = 1;
521         osp->opd_update->ou_version = 1;
522         osp->opd_update->ou_generation = 0;
523
524         rc = lu_env_init(&osp->opd_update->ou_env,
525                          osp->opd_dt_dev.dd_lu_dev.ld_type->ldt_ctx_tags);
526         if (rc < 0) {
527                 CERROR("%s: init env error: rc = %d\n", osp->opd_obd->obd_name,
528                        rc);
529                 OBD_FREE_PTR(osp->opd_update);
530                 osp->opd_update = NULL;
531                 RETURN(rc);
532         }
533         /* start thread handling sending updates to the remote MDT */
534         task = kthread_create(osp_send_update_thread, osp,
535                               "osp_up%u-%u", osp->opd_index, osp->opd_group);
536         if (IS_ERR(task)) {
537                 int rc = PTR_ERR(task);
538
539                 lu_env_fini(&osp->opd_update->ou_env);
540                 OBD_FREE_PTR(osp->opd_update);
541                 osp->opd_update = NULL;
542                 CERROR("%s: can't start precreate thread: rc = %d\n",
543                        osp->opd_obd->obd_name, rc);
544                 RETURN(rc);
545         }
546
547         osp->opd_update->ou_update_task = task;
548         wake_up_process(task);
549
550         RETURN(0);
551 }
552
553 /**
554  * Finialize osp_update structure in OSP device
555  *
556  * Stop the OSP update sending thread, then delete the left
557  * osp thandle in the sending list.
558  *
559  * \param [in] osp      OSP device.
560  */
561 static void osp_update_fini(const struct lu_env *env, struct osp_device *osp)
562 {
563         struct osp_update_request *our;
564         struct osp_update_request *tmp;
565         struct osp_updates *ou = osp->opd_update;
566
567         if (ou == NULL)
568                 return;
569
570         kthread_stop(ou->ou_update_task);
571         lu_env_fini(&ou->ou_env);
572
573         /* Remove the left osp thandle from the list */
574         spin_lock(&ou->ou_lock);
575         list_for_each_entry_safe(our, tmp, &ou->ou_list,
576                                  our_list) {
577                 list_del_init(&our->our_list);
578                 LASSERT(our->our_th != NULL);
579                 osp_trans_callback(env, our->our_th, -EIO);
580                 /* our will be destroyed in osp_thandle_put() */
581                 osp_thandle_put(env, our->our_th);
582         }
583         spin_unlock(&ou->ou_lock);
584
585         OBD_FREE_PTR(ou);
586         osp->opd_update = NULL;
587 }
588
589 /**
590  * Cleanup OSP, which includes disconnect import, cleanup unlink log, stop
591  * precreate threads etc.
592  *
593  * \param[in] env       execution environment.
594  * \param[in] d         OSP device being disconnected.
595  *
596  * \retval 0            0 if cleanup succeed
597  * \retval negative     negative errno if cleanup failed
598  */
599 static int osp_shutdown(const struct lu_env *env, struct osp_device *d)
600 {
601         int                      rc = 0;
602         ENTRY;
603
604         LASSERT(env);
605
606         rc = osp_disconnect(d);
607
608         osp_statfs_fini(d);
609
610         if (!d->opd_connect_mdt) {
611                 /* stop sync thread */
612                 osp_sync_fini(d);
613
614                 /* stop precreate thread */
615                 osp_precreate_fini(d);
616
617                 /* release last_used file */
618                 osp_last_used_fini(env, d);
619         }
620
621         obd_fid_fini(d->opd_obd);
622
623         RETURN(rc);
624 }
625
626 /**
627  * Implementation of osp_lu_ops::ldo_process_config
628  *
629  * This function processes config log records in OSP layer. It is usually
630  * called from the top layer of MDT stack, and goes through the stack by calling
631  * ldo_process_config of next layer.
632  *
633  * \param[in] env       execution environment
634  * \param[in] dev       lu_device of OSP
635  * \param[in] lcfg      config log
636  *
637  * \retval 0            0 if the config log record is executed correctly.
638  * \retval negative     negative errno if the record execution fails.
639  */
640 static int osp_process_config(const struct lu_env *env,
641                               struct lu_device *dev, struct lustre_cfg *lcfg)
642 {
643         struct osp_device *d = lu2osp_dev(dev);
644         struct dt_device *dt = lu2dt_dev(dev);
645         struct obd_device *obd = d->opd_obd;
646         ssize_t count;
647         int rc;
648
649         ENTRY;
650
651         switch (lcfg->lcfg_command) {
652         case LCFG_PRE_CLEANUP:
653                 rc = osp_disconnect(d);
654                 osp_update_fini(env, d);
655                 if (obd->obd_namespace != NULL)
656                         ldlm_namespace_free_prior(obd->obd_namespace, NULL, 1);
657                 break;
658         case LCFG_CLEANUP:
659                 lu_dev_del_linkage(dev->ld_site, dev);
660                 rc = osp_shutdown(env, d);
661                 break;
662         case LCFG_PARAM:
663                 count = class_modify_config(lcfg, d->opd_connect_mdt ?
664                                                   PARAM_OSP : PARAM_OSC,
665                                             &dt->dd_kobj);
666                 if (count < 0) {
667                         /* class_modify_config() haven't found matching
668                          * parameter and returned an error so that layer(s)
669                          * below could use that. But OSP is the bottom, so
670                          * just ignore it
671                          */
672                         CERROR("%s: unknown param %s\n",
673                                (char *)lustre_cfg_string(lcfg, 0),
674                                (char *)lustre_cfg_string(lcfg, 1));
675                 }
676                 rc = 0;
677                 break;
678         default:
679                 CERROR("%s: unknown command %u\n",
680                        (char *)lustre_cfg_string(lcfg, 0), lcfg->lcfg_command);
681                 rc = 0;
682                 break;
683         }
684
685         RETURN(rc);
686 }
687
688 /**
689  * Implementation of osp_lu_ops::ldo_recovery_complete
690  *
691  * This function is called after recovery is finished, and OSP layer
692  * will wake up precreate thread here.
693  *
694  * \param[in] env       execution environment
695  * \param[in] dev       lu_device of OSP
696  *
697  * \retval 0            0 unconditionally
698  */
699 static int osp_recovery_complete(const struct lu_env *env,
700                                  struct lu_device *dev)
701 {
702         struct osp_device       *osp = lu2osp_dev(dev);
703
704         ENTRY;
705         osp->opd_recovery_completed = 1;
706
707         if (!osp->opd_connect_mdt && osp->opd_pre != NULL)
708                 wake_up(&osp->opd_pre_waitq);
709
710         RETURN(0);
711 }
712
713 /**
714  * Implementation of lu_device_operations::ldo_fid_alloc() for OSP
715  *
716  * Allocate FID from remote MDT.
717  *
718  * see include/lu_object.h for the details.
719  */
720 static int osp_fid_alloc(const struct lu_env *env, struct lu_device *d,
721                          struct lu_fid *fid, struct lu_object *parent,
722                          const struct lu_name *name)
723 {
724         struct osp_device *osp = lu2osp_dev(d);
725         struct client_obd *cli = &osp->opd_obd->u.cli;
726         struct lu_client_seq *seq = cli->cl_seq;
727         int rc;
728
729         ENTRY;
730
731         /* Sigh, fid client is not ready yet */
732         if (!osp->opd_obd->u.cli.cl_seq)
733                 RETURN(-ENOTCONN);
734
735         if (!osp->opd_obd->u.cli.cl_seq->lcs_exp)
736                 RETURN(-ENOTCONN);
737
738         rc = seq_client_alloc_fid(env, seq, fid);
739
740         RETURN(rc);
741 }
742
743 const struct lu_device_operations osp_lu_ops = {
744         .ldo_object_alloc       = osp_object_alloc,
745         .ldo_process_config     = osp_process_config,
746         .ldo_recovery_complete  = osp_recovery_complete,
747         .ldo_fid_alloc          = osp_fid_alloc,
748 };
749
750 /**
751  * Implementation of dt_device_operations::dt_statfs
752  *
753  * This function provides statfs status (for precreation) from
754  * corresponding OST. Note: this function only retrieves the status
755  * from the OSP device, and the real statfs RPC happens inside
756  * precreate thread (\see osp_statfs_update). Note: OSP for MDT does
757  * not need to retrieve statfs data for now.
758  *
759  * \param[in] env       execution environment.
760  * \param[in] dev       dt_device of OSP.
761  * \param[out] sfs      holds the retrieved statfs data.
762  *
763  * \retval 0            0 statfs data was retrieved successfully or
764  *                      retrieval was not needed
765  * \retval negative     negative errno if get statfs failed.
766  */
767 static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
768                       struct obd_statfs *sfs, struct obd_statfs_info *info)
769 {
770         struct osp_device *d = dt2osp_dev(dev);
771         struct obd_import *imp = d->opd_obd->u.cli.cl_import;
772
773         ENTRY;
774
775         if (imp->imp_state == LUSTRE_IMP_CLOSED)
776                 RETURN(-ESHUTDOWN);
777
778         if (unlikely(d->opd_imp_active == 0))
779                 RETURN(-ENOTCONN);
780
781         /* return recently updated data */
782         *sfs = d->opd_statfs;
783         if (info) {
784                 info->os_reserved_mb_low = d->opd_reserved_mb_low;
785                 info->os_reserved_mb_high = d->opd_reserved_mb_high;
786         }
787
788         if (d->opd_pre == NULL)
789                 RETURN(0);
790
791         CDEBUG(D_OTHER, "%s: %llu blocks, %llu free, %llu avail, "
792                "%u bsize, %u reserved mb low, %u reserved mb high, "
793                "%llu files, %llu free files\n", d->opd_obd->obd_name,
794                sfs->os_blocks, sfs->os_bfree, sfs->os_bavail, sfs->os_bsize,
795                d->opd_reserved_mb_low, d->opd_reserved_mb_high,
796                sfs->os_files, sfs->os_ffree);
797
798
799         if (info && !info->os_enable_pre)
800                 RETURN(0);
801
802         /*
803          * The layer above osp (usually lod) can use f_precreated to
804          * estimate how many objects are available for immediate usage.
805          */
806         spin_lock(&d->opd_pre_lock);
807         sfs->os_fprecreated = osp_fid_diff(&d->opd_pre_last_created_fid,
808                                            &d->opd_pre_used_fid);
809         sfs->os_fprecreated -= d->opd_pre_reserved;
810         LASSERTF(sfs->os_fprecreated <= OST_MAX_PRECREATE * 2,
811                  "last_created "DFID", next_fid "DFID", reserved %llu\n",
812                  PFID(&d->opd_pre_last_created_fid), PFID(&d->opd_pre_used_fid),
813                  d->opd_pre_reserved);
814         spin_unlock(&d->opd_pre_lock);
815         RETURN(0);
816 }
817
818 /**
819  * Implementation of dt_device_operations::dt_sync
820  *
821  * This function synchronizes the OSP cache to the remote target. It wakes
822  * up unlink log threads and sends out unlink records to the remote OST.
823  *
824  * \param[in] env       execution environment
825  * \param[in] dev       dt_device of OSP
826  *
827  * \retval 0            0 if synchronization succeeds
828  * \retval negative     negative errno if synchronization fails
829  */
830 static int osp_sync(const struct lu_env *env, struct dt_device *dev)
831 {
832         struct osp_device *d = dt2osp_dev(dev);
833         time64_t start = ktime_get_seconds();
834         int recs, rc = 0;
835         u64 old;
836
837         ENTRY;
838
839         /* No Sync between MDTs yet. */
840         if (d->opd_connect_mdt)
841                 RETURN(0);
842
843         recs = atomic_read(&d->opd_sync_changes);
844         old = atomic64_read(&d->opd_sync_processed_recs);
845
846         osp_sync_force(env, dt2osp_dev(dev));
847
848         if (unlikely(d->opd_imp_active == 0))
849                 RETURN(-ENOTCONN);
850
851         down_write(&d->opd_async_updates_rwsem);
852
853         CDEBUG(D_OTHER, "%s: async updates %d\n", d->opd_obd->obd_name,
854                atomic_read(&d->opd_async_updates_count));
855
856         /* make sure the connection is fine */
857         rc = wait_event_idle_timeout(
858                 d->opd_sync_barrier_waitq,
859                 atomic_read(&d->opd_async_updates_count) == 0,
860                 cfs_time_seconds(obd_timeout));
861         if (rc > 0)
862                 rc = 0;
863         else if (rc == 0)
864                 rc = -ETIMEDOUT;
865
866         up_write(&d->opd_async_updates_rwsem);
867         if (rc != 0)
868                 GOTO(out, rc);
869
870         CDEBUG(D_CACHE, "%s: processed %llu\n", d->opd_obd->obd_name,
871                (unsigned long long)atomic64_read(&d->opd_sync_processed_recs));
872
873         while (atomic64_read(&d->opd_sync_processed_recs) < old + recs) {
874                 __u64 last = atomic64_read(&d->opd_sync_processed_recs);
875                 /* make sure the connection is fine */
876                 wait_event_idle_timeout(
877                         d->opd_sync_barrier_waitq,
878                         atomic64_read(&d->opd_sync_processed_recs)
879                              >= old + recs,
880                         cfs_time_seconds(obd_timeout));
881
882                 if (atomic64_read(&d->opd_sync_processed_recs) >= old + recs)
883                         break;
884
885                 if (atomic64_read(&d->opd_sync_processed_recs) != last) {
886                         /* some progress have been made,
887                          * keep trying... */
888                         continue;
889                 }
890
891                 /* no changes and expired, something is wrong */
892                 GOTO(out, rc = -ETIMEDOUT);
893         }
894
895         /* block new processing (barrier>0 - few callers are possible */
896         atomic_inc(&d->opd_sync_barrier);
897
898         CDEBUG(D_CACHE, "%s: %u in flight\n", d->opd_obd->obd_name,
899                atomic_read(&d->opd_sync_rpcs_in_flight));
900
901         /* wait till all-in-flight are replied, so executed by the target */
902         /* XXX: this is used by LFSCK at the moment, which doesn't require
903          *      all the changes to be committed, but in general it'd be
904          *      better to wait till commit */
905         while (atomic_read(&d->opd_sync_rpcs_in_flight) > 0) {
906                 old = atomic_read(&d->opd_sync_rpcs_in_flight);
907
908                 wait_event_idle_timeout(
909                         d->opd_sync_barrier_waitq,
910                         atomic_read(&d->opd_sync_rpcs_in_flight) == 0,
911                         cfs_time_seconds(obd_timeout));
912
913                 if (atomic_read(&d->opd_sync_rpcs_in_flight) == 0)
914                         break;
915
916                 if (atomic_read(&d->opd_sync_rpcs_in_flight) != old) {
917                         /* some progress have been made */
918                         continue;
919                 }
920
921                 /* no changes and expired, something is wrong */
922                 GOTO(out, rc = -ETIMEDOUT);
923         }
924
925 out:
926         /* resume normal processing (barrier=0) */
927         atomic_dec(&d->opd_sync_barrier);
928         osp_sync_check_for_work(d);
929
930         CDEBUG(D_CACHE, "%s: done in %lld: rc = %d\n", d->opd_obd->obd_name,
931                ktime_get_seconds() - start, rc);
932
933         RETURN(rc);
934 }
935
936 static const struct dt_device_operations osp_dt_ops = {
937         .dt_statfs       = osp_statfs,
938         .dt_sync         = osp_sync,
939         .dt_trans_create = osp_trans_create,
940         .dt_trans_start  = osp_trans_start,
941         .dt_trans_stop   = osp_trans_stop,
942         .dt_trans_cb_add   = osp_trans_cb_add,
943 };
944
945 /**
946  * Connect OSP to local OSD.
947  *
948  * Locate the local OSD referenced by \a nextdev and connect to it. Sometimes,
949  * OSP needs to access the local OSD to store some information. For example,
950  * during precreate, it needs to update last used OID and sequence file
951  * (LAST_SEQ) in local OSD.
952  *
953  * \param[in] env       execution environment
954  * \param[in] osp       OSP device
955  * \param[in] nextdev   the name of local OSD
956  *
957  * \retval 0            0 connection succeeded
958  * \retval negative     negative errno connection failed
959  */
960 static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *osp,
961                               const char *nextdev)
962 {
963         struct obd_connect_data *data = NULL;
964         struct obd_device       *obd;
965         int                      rc;
966
967         ENTRY;
968
969         LASSERT(osp->opd_storage_exp == NULL);
970
971         OBD_ALLOC_PTR(data);
972         if (data == NULL)
973                 RETURN(-ENOMEM);
974
975         obd = class_name2obd(nextdev);
976         if (obd == NULL) {
977                 CERROR("%s: can't locate next device: %s\n",
978                        osp->opd_obd->obd_name, nextdev);
979                 GOTO(out, rc = -ENOTCONN);
980         }
981
982         rc = obd_connect(env, &osp->opd_storage_exp, obd, &obd->obd_uuid, data,
983                          NULL);
984         if (rc) {
985                 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
986                        osp->opd_obd->obd_name, nextdev, rc);
987                 GOTO(out, rc);
988         }
989
990         osp->opd_dt_dev.dd_lu_dev.ld_site =
991                 osp->opd_storage_exp->exp_obd->obd_lu_dev->ld_site;
992         LASSERT(osp->opd_dt_dev.dd_lu_dev.ld_site);
993         osp->opd_storage = lu2dt_dev(osp->opd_storage_exp->exp_obd->obd_lu_dev);
994
995 out:
996         OBD_FREE_PTR(data);
997         RETURN(rc);
998 }
999
1000 /**
1001  * Determine if the lock needs to be cancelled
1002  *
1003  * Determine if the unused lock should be cancelled before replay, see
1004  * (ldlm_cancel_no_wait_policy()). Currently, only inode bits lock exists
1005  * between MDTs.
1006  *
1007  * \param[in] lock      lock to be checked.
1008  *
1009  * \retval              1 if the lock needs to be cancelled before replay.
1010  * \retval              0 if the lock does not need to be cancelled before
1011  *                      replay.
1012  */
1013 static int osp_cancel_weight(struct ldlm_lock *lock)
1014 {
1015         if (lock->l_resource->lr_type != LDLM_IBITS)
1016                 RETURN(0);
1017
1018         RETURN(1);
1019 }
1020
1021 /**
1022  * Initialize OSP device according to the parameters in the configuration
1023  * log \a cfg.
1024  *
1025  * Reconstruct the local device name from the configuration profile, and
1026  * initialize necessary threads and structures according to the OSP type
1027  * (MDT or OST).
1028  *
1029  * Since there is no record in the MDT configuration for the local disk
1030  * device, we have to extract this from elsewhere in the profile.
1031  * The only information we get at setup is from the OSC records:
1032  * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
1033  *
1034  * Note: configs generated by Lustre 1.8 are missing the -MDTxxxx part,
1035  * so, we need to reconstruct the name of the underlying OSD from this:
1036  * {fsname}-{svname}-osd, for example "lustre-MDT0000-osd".
1037  *
1038  * \param[in] env       execution environment
1039  * \param[in] osp       OSP device
1040  * \param[in] ldt       lu device type of OSP
1041  * \param[in] cfg       configuration log
1042  *
1043  * \retval 0            0 if OSP initialization succeeded.
1044  * \retval negative     negative errno if OSP initialization failed.
1045  */
1046 static int osp_init0(const struct lu_env *env, struct osp_device *osp,
1047                      struct lu_device_type *ldt, struct lustre_cfg *cfg)
1048 {
1049         struct obd_device       *obd;
1050         struct obd_import       *imp;
1051         char *src, *tgt, *osdname = NULL;
1052         const char *mdt;
1053         int                     rc;
1054         u32 idx;
1055
1056         ENTRY;
1057
1058         mutex_init(&osp->opd_async_requests_mutex);
1059         INIT_LIST_HEAD(&osp->opd_async_updates);
1060         init_rwsem(&osp->opd_async_updates_rwsem);
1061         atomic_set(&osp->opd_async_updates_count, 0);
1062
1063         obd = class_name2obd(lustre_cfg_string(cfg, 0));
1064         if (obd == NULL) {
1065                 CERROR("Cannot find obd with name %s\n",
1066                        lustre_cfg_string(cfg, 0));
1067                 RETURN(-ENODEV);
1068         }
1069         osp->opd_obd = obd;
1070
1071         src = lustre_cfg_string(cfg, 0);
1072         if (src == NULL)
1073                 RETURN(-EINVAL);
1074
1075         tgt = strrchr(src, '-');
1076         if (tgt == NULL) {
1077                 CERROR("%s: invalid target name %s: rc = %d\n",
1078                        osp->opd_obd->obd_name, lustre_cfg_string(cfg, 0),
1079                        -EINVAL);
1080                 RETURN(-EINVAL);
1081         }
1082
1083         if (strncmp(tgt, "-osc", 4) == 0) {
1084                 /* Old OSC name fsname-OSTXXXX-osc */
1085                 for (tgt--; tgt > src && *tgt != '-'; tgt--)
1086                         ;
1087                 if (tgt == src) {
1088                         CERROR("%s: invalid target name %s: rc = %d\n",
1089                                osp->opd_obd->obd_name,
1090                                lustre_cfg_string(cfg, 0), -EINVAL);
1091                         RETURN(-EINVAL);
1092                 }
1093
1094                 if (strncmp(tgt, "-OST", 4) != 0) {
1095                         CERROR("%s: invalid target name %s: rc = %d\n",
1096                                osp->opd_obd->obd_name,
1097                                lustre_cfg_string(cfg, 0), -EINVAL);
1098                         RETURN(-EINVAL);
1099                 }
1100
1101                 rc = target_name2index(tgt + 1, &idx, &mdt);
1102                 if (rc < 0 || rc & LDD_F_SV_ALL || mdt[0] != '-') {
1103                         CERROR("%s: invalid OST index in '%s': rc = %d\n",
1104                                osp->opd_obd->obd_name, src, -EINVAL);
1105                         RETURN(-EINVAL);
1106                 }
1107                 osp->opd_index = idx;
1108                 osp->opd_group = 0;
1109                 idx = tgt - src;
1110         } else {
1111                 /* New OSC name fsname-OSTXXXX-osc-MDTXXXX */
1112                 if (strncmp(tgt, "-MDT", 4) != 0 &&
1113                     strncmp(tgt, "-OST", 4) != 0) {
1114                         CERROR("%s: invalid target name %s: rc = %d\n",
1115                                osp->opd_obd->obd_name,
1116                                lustre_cfg_string(cfg, 0), -EINVAL);
1117                         RETURN(-EINVAL);
1118                 }
1119
1120                 rc = target_name2index(tgt + 1, &idx, &mdt);
1121                 if (rc < 0 || rc & LDD_F_SV_ALL || *mdt != '\0') {
1122                         CERROR("%s: invalid OST index in '%s': rc = %d\n",
1123                                osp->opd_obd->obd_name, src, -EINVAL);
1124                         RETURN(-EINVAL);
1125                 }
1126
1127                 /* Get MDT index from the name and set it to opd_group,
1128                  * which will be used by OSP to connect with OST */
1129                 osp->opd_group = idx;
1130                 if (tgt - src <= 12) {
1131                         CERROR("%s: invalid mdt index from %s: rc =%d\n",
1132                                osp->opd_obd->obd_name,
1133                                lustre_cfg_string(cfg, 0), -EINVAL);
1134                         RETURN(-EINVAL);
1135                 }
1136
1137                 if (strncmp(tgt - 12, "-MDT", 4) == 0)
1138                         osp->opd_connect_mdt = 1;
1139
1140                 rc = target_name2index(tgt - 11, &idx, &mdt);
1141                 if (rc < 0 || rc & LDD_F_SV_ALL || mdt[0] != '-') {
1142                         CERROR("%s: invalid OST index in '%s': rc =%d\n",
1143                                osp->opd_obd->obd_name, src, -EINVAL);
1144                         RETURN(-EINVAL);
1145                 }
1146
1147                 osp->opd_index = idx;
1148                 idx = tgt - src - 12;
1149         }
1150         /* check the fsname length, and after this everything else will fit */
1151         if (idx > MTI_NAME_MAXLEN) {
1152                 CERROR("%s: fsname too long in '%s': rc = %d\n",
1153                        osp->opd_obd->obd_name, src, -EINVAL);
1154                 RETURN(-EINVAL);
1155         }
1156
1157         OBD_ALLOC(osdname, MAX_OBD_NAME);
1158         if (osdname == NULL)
1159                 RETURN(-ENOMEM);
1160
1161         memcpy(osdname, src, idx); /* copy just the fsname part */
1162         osdname[idx] = '\0';
1163
1164         mdt = strstr(mdt, "-MDT");
1165         if (mdt == NULL) /* 1.8 configs don't have "-MDT0000" at the end */
1166                 strcat(osdname, "-MDT0000");
1167         else
1168                 strcat(osdname, mdt);
1169         strcat(osdname, "-osd");
1170         CDEBUG(D_HA, "%s: connect to %s (%s)\n", obd->obd_name, osdname, src);
1171
1172         osp_init_rpc_lock(osp);
1173
1174         osp->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
1175         osp->opd_dt_dev.dd_ops = &osp_dt_ops;
1176
1177         obd->obd_lu_dev = &osp->opd_dt_dev.dd_lu_dev;
1178
1179         rc = osp_connect_to_osd(env, osp, osdname);
1180         if (rc)
1181                 GOTO(out_fini, rc);
1182
1183         rc = ptlrpcd_addref();
1184         if (rc)
1185                 GOTO(out_disconnect, rc);
1186
1187         rc = client_obd_setup(obd, cfg);
1188         if (rc) {
1189                 CERROR("%s: can't setup obd: rc = %d\n", osp->opd_obd->obd_name,
1190                        rc);
1191                 GOTO(out_ref, rc);
1192         }
1193
1194         osp_tunables_init(osp);
1195
1196         rc = obd_fid_init(osp->opd_obd, NULL, osp->opd_connect_mdt ?
1197                           LUSTRE_SEQ_METADATA : LUSTRE_SEQ_DATA);
1198         if (rc) {
1199                 CERROR("%s: fid init error: rc = %d\n",
1200                        osp->opd_obd->obd_name, rc);
1201                 GOTO(out_proc, rc);
1202         }
1203
1204         if (!osp->opd_connect_mdt) {
1205                 /* Initialize last id from the storage - will be
1206                  * used in orphan cleanup. */
1207                 if (!osp->opd_storage->dd_rdonly) {
1208                         rc = osp_last_used_init(env, osp);
1209                         if (rc)
1210                                 GOTO(out_fid, rc);
1211                 }
1212
1213                 /* Initialize precreation thread, it handles new
1214                  * connections as well. */
1215                 rc = osp_init_precreate(osp);
1216                 if (rc)
1217                         GOTO(out_last_used, rc);
1218
1219                 /*
1220                  * Initialize synhronization mechanism taking
1221                  * care of propogating changes to OST in near
1222                  * transactional manner.
1223                  */
1224                 rc = osp_sync_init(env, osp);
1225                 if (rc < 0)
1226                         GOTO(out_precreat, rc);
1227         } else {
1228                 osp->opd_got_disconnected = 1;
1229                 rc = osp_update_init(osp);
1230                 if (rc != 0)
1231                         GOTO(out_fid, rc);
1232         }
1233
1234         rc = osp_init_statfs(osp);
1235         if (rc)
1236                 GOTO(out_precreat, rc);
1237
1238         ns_register_cancel(obd->obd_namespace, osp_cancel_weight);
1239
1240         /*
1241          * Initiate connect to OST
1242          */
1243         imp = obd->u.cli.cl_import;
1244
1245         rc = ptlrpc_init_import(imp);
1246         if (rc)
1247                 GOTO(out, rc);
1248         if (osdname)
1249                 OBD_FREE(osdname, MAX_OBD_NAME);
1250         RETURN(0);
1251
1252 out:
1253         if (!osp->opd_connect_mdt)
1254                 /* stop sync thread */
1255                 osp_sync_fini(osp);
1256 out_precreat:
1257         /* stop precreate thread */
1258         if (!osp->opd_connect_mdt)
1259                 osp_precreate_fini(osp);
1260         else
1261                 osp_update_fini(env, osp);
1262 out_last_used:
1263         if (!osp->opd_connect_mdt)
1264                 osp_last_used_fini(env, osp);
1265 out_fid:
1266         obd_fid_fini(osp->opd_obd);
1267 out_proc:
1268         osp_tunables_fini(osp);
1269         client_obd_cleanup(obd);
1270 out_ref:
1271         ptlrpcd_decref();
1272 out_disconnect:
1273         obd_disconnect(osp->opd_storage_exp);
1274 out_fini:
1275         if (osdname)
1276                 OBD_FREE(osdname, MAX_OBD_NAME);
1277         RETURN(rc);
1278 }
1279
1280 /**
1281  * Implementation of lu_device_type_operations::ldto_device_free
1282  *
1283  * Free the OSP device in memory.  No return value is needed for now,
1284  * so always return NULL to comply with the interface.
1285  *
1286  * \param[in] env       execution environment
1287  * \param[in] lu        lu_device of OSP
1288  *
1289  * \retval NULL         NULL unconditionally
1290  */
1291 static struct lu_device *osp_device_free(const struct lu_env *env,
1292                                          struct lu_device *lu)
1293 {
1294         struct osp_device *osp = lu2osp_dev(lu);
1295
1296         lu_site_print(env, lu->ld_site, &lu->ld_ref, D_ERROR,
1297                       lu_cdebug_printer);
1298         dt_device_fini(&osp->opd_dt_dev);
1299         OBD_FREE_PTR(osp);
1300
1301         return NULL;
1302 }
1303
1304 /**
1305  * Implementation of lu_device_type_operations::ldto_device_alloc
1306  *
1307  * This function allocates and initializes OSP device in memory according to
1308  * the config log.
1309  *
1310  * \param[in] env       execution environment
1311  * \param[in] type      device type of OSP
1312  * \param[in] lcfg      config log
1313  *
1314  * \retval pointer              the pointer of allocated OSP if succeed.
1315  * \retval ERR_PTR(errno)       ERR_PTR(errno) if failed.
1316  */
1317 static struct lu_device *osp_device_alloc(const struct lu_env *env,
1318                                           struct lu_device_type *type,
1319                                           struct lustre_cfg *lcfg)
1320 {
1321         struct osp_device *osp;
1322         struct lu_device  *ld;
1323
1324         OBD_ALLOC_PTR(osp);
1325         if (osp == NULL) {
1326                 ld = ERR_PTR(-ENOMEM);
1327         } else {
1328                 int rc;
1329
1330                 ld = osp2lu_dev(osp);
1331                 dt_device_init(&osp->opd_dt_dev, type);
1332                 rc = osp_init0(env, osp, type, lcfg);
1333                 if (rc != 0) {
1334                         osp_device_free(env, ld);
1335                         ld = ERR_PTR(rc);
1336                 }
1337         }
1338         return ld;
1339 }
1340
1341 /**
1342  * Implementation of lu_device_type_operations::ldto_device_fini
1343  *
1344  * This function cleans up the OSP device, i.e. release and free those
1345  * attached items in osp_device.
1346  *
1347  * \param[in] env       execution environment
1348  * \param[in] ld        lu_device of OSP
1349  *
1350  * \retval NULL                 NULL if cleanup succeeded.
1351  * \retval ERR_PTR(errno)       ERR_PTR(errno) if cleanup failed.
1352  */
1353 static struct lu_device *osp_device_fini(const struct lu_env *env,
1354                                          struct lu_device *ld)
1355 {
1356         struct osp_device *osp = lu2osp_dev(ld);
1357         int                rc;
1358
1359         ENTRY;
1360
1361         if (osp->opd_async_requests != NULL) {
1362                 osp_update_request_destroy(env, osp->opd_async_requests);
1363                 osp->opd_async_requests = NULL;
1364         }
1365
1366         if (osp->opd_storage_exp) {
1367                 /* wait for the commit callbacks to complete */
1368                 wait_event(osp->opd_sync_waitq,
1369                           atomic_read(&osp->opd_commits_registered) == 0);
1370                 obd_disconnect(osp->opd_storage_exp);
1371         }
1372
1373         LASSERT(osp->opd_obd);
1374
1375         rc = client_obd_cleanup(osp->opd_obd);
1376         if (rc != 0) {
1377                 ptlrpcd_decref();
1378                 RETURN(ERR_PTR(rc));
1379         }
1380
1381         osp_tunables_fini(osp);
1382
1383         ptlrpcd_decref();
1384
1385         RETURN(NULL);
1386 }
1387
1388 /**
1389  * Implementation of obd_ops::o_reconnect
1390  *
1391  * This function is empty and does not need to do anything for now.
1392  */
1393 static int osp_reconnect(const struct lu_env *env,
1394                          struct obd_export *exp, struct obd_device *obd,
1395                          struct obd_uuid *cluuid,
1396                          struct obd_connect_data *data,
1397                          void *localdata)
1398 {
1399         return 0;
1400 }
1401
1402 /*
1403  * Implementation of obd_ops::o_connect
1404  *
1405  * Connect OSP to the remote target (MDT or OST). Allocate the
1406  * export and return it to the LOD, which calls this function
1407  * for each OSP to connect it to the remote target. This function
1408  * is currently only called once per OSP.
1409  *
1410  * \param[in] env       execution environment
1411  * \param[out] exp      export connected to OSP
1412  * \param[in] obd       OSP device
1413  * \param[in] cluuid    OSP device client uuid
1414  * \param[in] data      connect_data to be used to connect to the remote
1415  *                      target
1416  * \param[in] localdata necessary for the API interface, but not used in
1417  *                      this function
1418  *
1419  * \retval 0            0 if the connection succeeded.
1420  * \retval negative     negative errno if the connection failed.
1421  */
1422 static int osp_obd_connect(const struct lu_env *env, struct obd_export **exp,
1423                            struct obd_device *obd, struct obd_uuid *cluuid,
1424                            struct obd_connect_data *data, void *localdata)
1425 {
1426         struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
1427         struct obd_connect_data *ocd;
1428         struct obd_import       *imp;
1429         struct lustre_handle     conn;
1430         int                      rc;
1431
1432         ENTRY;
1433
1434         CDEBUG(D_CONFIG, "connect #%d\n", osp->opd_connects);
1435
1436         rc = class_connect(&conn, obd, cluuid);
1437         if (rc)
1438                 RETURN(rc);
1439
1440         *exp = class_conn2export(&conn);
1441         /* Why should there ever be more than 1 connect? */
1442         osp->opd_connects++;
1443         LASSERT(osp->opd_connects == 1);
1444
1445         osp->opd_exp = *exp;
1446
1447         imp = osp->opd_obd->u.cli.cl_import;
1448         imp->imp_dlm_handle = conn;
1449
1450         LASSERT(data != NULL);
1451         LASSERT(data->ocd_connect_flags & OBD_CONNECT_INDEX);
1452         ocd = &imp->imp_connect_data;
1453         *ocd = *data;
1454
1455         imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
1456         imp->imp_connect_flags2_orig = ocd->ocd_connect_flags2;
1457
1458         ocd->ocd_version = LUSTRE_VERSION_CODE;
1459         ocd->ocd_index = data->ocd_index;
1460
1461         rc = ptlrpc_connect_import(imp);
1462         if (rc) {
1463                 CERROR("%s: can't connect obd: rc = %d\n", obd->obd_name, rc);
1464                 GOTO(out, rc);
1465         } else {
1466                 osp->opd_obd->u.cli.cl_seq->lcs_exp =
1467                                 class_export_get(osp->opd_exp);
1468         }
1469
1470         ptlrpc_pinger_add_import(imp);
1471 out:
1472         RETURN(rc);
1473 }
1474
1475 /**
1476  * Implementation of obd_ops::o_disconnect
1477  *
1478  * Disconnect the export for the OSP.  This is called by LOD to release the
1479  * OSP during cleanup (\see lod_del_device()). The OSP will be released after
1480  * the export is released.
1481  *
1482  * \param[in] exp       export to be disconnected.
1483  *
1484  * \retval 0            0 if disconnection succeed
1485  * \retval negative     negative errno if disconnection failed
1486  */
1487 static int osp_obd_disconnect(struct obd_export *exp)
1488 {
1489         struct obd_device *obd = exp->exp_obd;
1490         struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
1491         int                rc;
1492         ENTRY;
1493
1494         /* Only disconnect the underlying layers on the final disconnect. */
1495         LASSERT(osp->opd_connects == 1);
1496         osp->opd_connects--;
1497
1498         rc = class_disconnect(exp);
1499         if (rc) {
1500                 CERROR("%s: class disconnect error: rc = %d\n",
1501                        obd->obd_name, rc);
1502                 RETURN(rc);
1503         }
1504
1505         /* destroy the device */
1506         class_manual_cleanup(obd);
1507
1508         RETURN(rc);
1509 }
1510
1511 /**
1512  * Implementation of obd_ops::o_statfs
1513  *
1514  * Send a RPC to the remote target to get statfs status. This is only used
1515  * in lprocfs helpers by obd_statfs.
1516  *
1517  * \param[in] env       execution environment
1518  * \param[in] exp       connection state from this OSP to the parent (LOD)
1519  *                      device
1520  * \param[out] osfs     hold the statfs result
1521  * \param[in] unused    Not used in this function for now
1522  * \param[in] flags     flags to indicate how OSP will issue the RPC
1523  *
1524  * \retval 0            0 if statfs succeeded.
1525  * \retval negative     negative errno if statfs failed.
1526  */
1527 static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp,
1528                           struct obd_statfs *osfs, time64_t unused, __u32 flags)
1529 {
1530         struct obd_statfs       *msfs;
1531         struct ptlrpc_request   *req;
1532         struct obd_import       *imp = NULL, *imp0;
1533         int                      rc;
1534
1535         ENTRY;
1536
1537         /* Since the request might also come from lprocfs, so we need
1538          * sync this with client_disconnect_export Bug15684
1539          */
1540         with_imp_locked(exp->exp_obd, imp0, rc)
1541                 imp = class_import_get(imp0);
1542         if (rc)
1543                 RETURN(rc);
1544
1545         req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
1546
1547         class_import_put(imp);
1548
1549         if (req == NULL)
1550                 RETURN(-ENOMEM);
1551
1552         rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_STATFS);
1553         if (rc) {
1554                 ptlrpc_request_free(req);
1555                 RETURN(rc);
1556         }
1557         ptlrpc_request_set_replen(req);
1558         req->rq_request_portal = OST_CREATE_PORTAL;
1559         ptlrpc_at_set_req_timeout(req);
1560
1561         if (flags & OBD_STATFS_NODELAY) {
1562                 /* procfs requests not want stat in wait for avoid deadlock */
1563                 req->rq_no_resend = 1;
1564                 req->rq_no_delay = 1;
1565         }
1566
1567         rc = ptlrpc_queue_wait(req);
1568         if (rc)
1569                 GOTO(out, rc);
1570
1571         msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1572         if (msfs == NULL)
1573                 GOTO(out, rc = -EPROTO);
1574
1575         *osfs = *msfs;
1576
1577         EXIT;
1578 out:
1579         ptlrpc_req_finished(req);
1580         return rc;
1581 }
1582
1583 /**
1584  * Implementation of obd_ops::o_import_event
1585  *
1586  * This function is called when some related import event happens. It will
1587  * mark the necessary flags according to the event and notify the necessary
1588  * threads (mainly precreate thread).
1589  *
1590  * \param[in] obd       OSP OBD device
1591  * \param[in] imp       import attached from OSP to remote (OST/MDT) service
1592  * \param[in] event     event related to remote service (IMP_EVENT_*)
1593  *
1594  * \retval 0            0 if the event handling succeeded.
1595  * \retval negative     negative errno if the event handling failed.
1596  */
1597 static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
1598                             enum obd_import_event event)
1599 {
1600         struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
1601         int rc;
1602
1603         switch (event) {
1604         case IMP_EVENT_DISCON:
1605                 d->opd_got_disconnected = 1;
1606                 d->opd_imp_connected = 0;
1607                 if (d->opd_connect_mdt)
1608                         break;
1609
1610                 if (d->opd_pre != NULL) {
1611                         osp_pre_update_status(d, -ENODEV);
1612                         wake_up(&d->opd_pre_waitq);
1613                 }
1614
1615                 CDEBUG(D_HA, "got disconnected\n");
1616                 break;
1617         case IMP_EVENT_INACTIVE:
1618                 d->opd_imp_active = 0;
1619                 d->opd_imp_connected = 0;
1620                 d->opd_obd->obd_inactive = 1;
1621                 if (d->opd_connect_mdt)
1622                         break;
1623                 if (d->opd_pre != NULL) {
1624                         /* Import is invalid, we can`t get stripes so
1625                          * wakeup waiters */
1626                         rc = imp->imp_deactive ? -ESHUTDOWN : -ENODEV;
1627                         osp_pre_update_status(d, rc);
1628                         wake_up(&d->opd_pre_waitq);
1629                 }
1630
1631                 CDEBUG(D_HA, "got inactive\n");
1632                 break;
1633         case IMP_EVENT_ACTIVE:
1634                 d->opd_imp_active = 1;
1635
1636                 d->opd_new_connection = 1;
1637                 d->opd_imp_connected = 1;
1638                 d->opd_imp_seen_connected = 1;
1639                 d->opd_obd->obd_inactive = 0;
1640                 wake_up(&d->opd_pre_waitq);
1641                 if (d->opd_connect_mdt)
1642                         break;
1643
1644                 osp_sync_check_for_work(d);
1645                 CDEBUG(D_HA, "got connected\n");
1646                 break;
1647         case IMP_EVENT_INVALIDATE:
1648                 if (d->opd_connect_mdt)
1649                         osp_invalidate_request(d);
1650
1651                 if (obd->obd_namespace == NULL)
1652                         break;
1653                 ldlm_namespace_cleanup(obd->obd_namespace, LDLM_FL_LOCAL_ONLY);
1654                 break;
1655         case IMP_EVENT_OCD:
1656         case IMP_EVENT_DEACTIVATE:
1657         case IMP_EVENT_ACTIVATE:
1658                 break;
1659         default:
1660                 CERROR("%s: unsupported import event: %#x\n",
1661                        obd->obd_name, event);
1662         }
1663         return 0;
1664 }
1665
1666 /**
1667  * Implementation of obd_ops: o_iocontrol
1668  *
1669  * This function is the ioctl handler for OSP. Note: lctl will access the OSP
1670  * directly by ioctl, instead of through the MDS stack.
1671  *
1672  * param[in] cmd        ioctl command.
1673  * param[in] exp        export of this OSP.
1674  * param[in] len        data length of \a karg.
1675  * param[in] karg       input argument which is packed as
1676  *                      obd_ioctl_data
1677  * param[out] uarg      pointer to userspace buffer (must access by
1678  *                      copy_to_user()).
1679  *
1680  * \retval 0            0 if the ioctl handling succeeded.
1681  * \retval negative     negative errno if the ioctl handling failed.
1682  */
1683 static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1684                          void *karg, void __user *uarg)
1685 {
1686         struct obd_device       *obd = exp->exp_obd;
1687         struct osp_device       *d;
1688         struct obd_ioctl_data   *data = karg;
1689         int                      rc = 0;
1690
1691         ENTRY;
1692
1693         LASSERT(obd->obd_lu_dev);
1694         d = lu2osp_dev(obd->obd_lu_dev);
1695         LASSERT(d->opd_dt_dev.dd_ops == &osp_dt_ops);
1696
1697         if (!try_module_get(THIS_MODULE)) {
1698                 CERROR("%s: cannot get module '%s'\n", obd->obd_name,
1699                        module_name(THIS_MODULE));
1700                 return -EINVAL;
1701         }
1702
1703         switch (cmd) {
1704         case OBD_IOC_CLIENT_RECOVER:
1705                 rc = ptlrpc_recover_import(obd->u.cli.cl_import,
1706                                            data->ioc_inlbuf1, 0);
1707                 if (rc > 0)
1708                         rc = 0;
1709                 break;
1710         case IOC_OSC_SET_ACTIVE:
1711                 rc = ptlrpc_set_import_active(obd->u.cli.cl_import,
1712                                               data->ioc_offset);
1713                 break;
1714         default:
1715                 CERROR("%s: unrecognized ioctl %#x by %s\n", obd->obd_name,
1716                        cmd, current->comm);
1717                 rc = -ENOTTY;
1718         }
1719         module_put(THIS_MODULE);
1720         return rc;
1721 }
1722
1723
1724 /**
1725  * Implementation of obd_ops::o_get_info
1726  *
1727  * Retrieve information by key. Retrieval starts from the top layer
1728  * (MDT) of the MDS stack and traverses the stack by calling the
1729  * obd_get_info() method of the next sub-layer.
1730  *
1731  * \param[in] env       execution environment
1732  * \param[in] exp       export of this OSP
1733  * \param[in] keylen    length of \a key
1734  * \param[in] key       the key
1735  * \param[out] vallen   length of \a val
1736  * \param[out] val      holds the value returned by the key
1737  *
1738  * \retval 0            0 if getting information succeeded.
1739  * \retval negative     negative errno if getting information failed.
1740  */
1741 static int osp_obd_get_info(const struct lu_env *env, struct obd_export *exp,
1742                             __u32 keylen, void *key, __u32 *vallen, void *val)
1743 {
1744         int rc = -EINVAL;
1745
1746         if (KEY_IS(KEY_OSP_CONNECTED)) {
1747                 struct obd_device       *obd = exp->exp_obd;
1748                 struct osp_device       *osp;
1749
1750                 if (!obd->obd_set_up || obd->obd_stopping)
1751                         RETURN(-EAGAIN);
1752
1753                 osp = lu2osp_dev(obd->obd_lu_dev);
1754                 LASSERT(osp);
1755                 /*
1756                  * 1.8/2.0 behaviour is that OST being connected once at least
1757                  * is considered "healthy". and one "healthy" OST is enough to
1758                  * allow lustre clients to connect to MDS
1759                  */
1760                 RETURN(!osp->opd_imp_seen_connected);
1761         }
1762
1763         RETURN(rc);
1764 }
1765
1766 static int osp_obd_set_info_async(const struct lu_env *env,
1767                                   struct obd_export *exp,
1768                                   u32 keylen, void *key,
1769                                   u32 vallen, void *val,
1770                                   struct ptlrpc_request_set *set)
1771 {
1772         struct obd_device       *obd = exp->exp_obd;
1773         struct obd_import       *imp = obd->u.cli.cl_import;
1774         struct osp_device       *osp;
1775         struct ptlrpc_request   *req;
1776         char                    *tmp;
1777         int                      rc;
1778
1779         if (KEY_IS(KEY_SPTLRPC_CONF)) {
1780                 sptlrpc_conf_client_adapt(exp->exp_obd);
1781                 RETURN(0);
1782         }
1783
1784         LASSERT(set != NULL);
1785         if (!obd->obd_set_up || obd->obd_stopping)
1786                 RETURN(-EAGAIN);
1787         osp = lu2osp_dev(obd->obd_lu_dev);
1788
1789         req = ptlrpc_request_alloc(imp, &RQF_OBD_SET_INFO);
1790         if (req == NULL)
1791                 RETURN(-ENOMEM);
1792
1793         req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1794                              RCL_CLIENT, keylen);
1795         req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1796                              RCL_CLIENT, vallen);
1797         if (osp->opd_connect_mdt)
1798                 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1799         else
1800                 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_SET_INFO);
1801         if (rc) {
1802                 ptlrpc_request_free(req);
1803                 RETURN(rc);
1804         }
1805
1806         tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1807         memcpy(tmp, key, keylen);
1808         tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1809         memcpy(tmp, val, vallen);
1810
1811         ptlrpc_request_set_replen(req);
1812         ptlrpc_set_add_req(set, req);
1813         ptlrpc_check_set(NULL, set);
1814
1815         RETURN(0);
1816 }
1817
1818 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
1819 LU_KEY_INIT_FINI(osp, struct osp_thread_info);
1820 static void osp_key_exit(const struct lu_context *ctx,
1821                          struct lu_context_key *key, void *data)
1822 {
1823         struct osp_thread_info *info = data;
1824
1825         info->osi_attr.la_valid = 0;
1826 }
1827
1828 struct lu_context_key osp_thread_key = {
1829         .lct_tags = LCT_MD_THREAD,
1830         .lct_init = osp_key_init,
1831         .lct_fini = osp_key_fini,
1832         .lct_exit = osp_key_exit
1833 };
1834
1835 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
1836 LU_KEY_INIT_FINI(osp_txn, struct osp_txn_info);
1837
1838 struct lu_context_key osp_txn_key = {
1839         .lct_tags = LCT_OSP_THREAD,
1840         .lct_init = osp_txn_key_init,
1841         .lct_fini = osp_txn_key_fini
1842 };
1843 LU_TYPE_INIT_FINI(osp, &osp_thread_key, &osp_txn_key);
1844
1845 static const struct lu_device_type_operations osp_device_type_ops = {
1846         .ldto_init           = osp_type_init,
1847         .ldto_fini           = osp_type_fini,
1848
1849         .ldto_start          = osp_type_start,
1850         .ldto_stop           = osp_type_stop,
1851
1852         .ldto_device_alloc   = osp_device_alloc,
1853         .ldto_device_free    = osp_device_free,
1854
1855         .ldto_device_fini    = osp_device_fini
1856 };
1857
1858 static struct lu_device_type osp_device_type = {
1859         .ldt_tags     = LU_DEVICE_DT,
1860         .ldt_name     = LUSTRE_OSP_NAME,
1861         .ldt_ops      = &osp_device_type_ops,
1862         .ldt_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD,
1863 };
1864
1865 static const struct obd_ops osp_obd_device_ops = {
1866         .o_owner        = THIS_MODULE,
1867         .o_add_conn     = client_import_add_conn,
1868         .o_del_conn     = client_import_del_conn,
1869         .o_reconnect    = osp_reconnect,
1870         .o_connect      = osp_obd_connect,
1871         .o_disconnect   = osp_obd_disconnect,
1872         .o_get_info     = osp_obd_get_info,
1873         .o_set_info_async = osp_obd_set_info_async,
1874         .o_import_event = osp_import_event,
1875         .o_iocontrol    = osp_iocontrol,
1876         .o_statfs       = osp_obd_statfs,
1877         .o_fid_init     = client_fid_init,
1878         .o_fid_fini     = client_fid_fini,
1879 };
1880
1881 /**
1882  * Initialize OSP module.
1883  *
1884  * Register device types OSP and Light Weight Proxy (LWP) (\see lwp_dev.c)
1885  * in obd_types (\see class_obd.c).  Initialize procfs for the
1886  * the OSP device.  Note: OSP was called OSC before Lustre 2.4,
1887  * so for compatibility it still uses the name "osc" in procfs.
1888  * This is called at module load time.
1889  *
1890  * \retval 0            0 if initialization succeeds.
1891  * \retval negative     negative errno if initialization failed.
1892  */
1893 static int __init osp_init(void)
1894 {
1895         struct obd_type *sym;
1896         int rc;
1897
1898         rc = lu_kmem_init(osp_caches);
1899         if (rc)
1900                 return rc;
1901
1902         rc = class_register_type(&osp_obd_device_ops, NULL, false,
1903                                  LUSTRE_OSP_NAME, &osp_device_type);
1904         if (rc != 0) {
1905                 lu_kmem_fini(osp_caches);
1906                 return rc;
1907         }
1908
1909         rc = class_register_type(&lwp_obd_device_ops, NULL, false,
1910                                  LUSTRE_LWP_NAME, &lwp_device_type);
1911         if (rc != 0) {
1912                 class_unregister_type(LUSTRE_OSP_NAME);
1913                 lu_kmem_fini(osp_caches);
1914                 return rc;
1915         }
1916
1917         /* create "osc" entry for compatibility purposes */
1918         sym = class_add_symlinks(LUSTRE_OSC_NAME, true);
1919         if (IS_ERR(sym)) {
1920                 rc = PTR_ERR(sym);
1921                 /* does real "osc" already exist ? */
1922                 if (rc == -EEXIST)
1923                         rc = 0;
1924         }
1925
1926         return rc;
1927 }
1928
1929 /**
1930  * Finalize OSP module.
1931  *
1932  * This callback is called when kernel unloads OSP module from memory, and
1933  * it will deregister OSP and LWP device type from obd_types (\see class_obd.c).
1934  */
1935 static void __exit osp_exit(void)
1936 {
1937         struct obd_type *sym = class_search_type(LUSTRE_OSC_NAME);
1938
1939         /* if this was never fully initialized by the osc layer
1940          * then we are responsible for freeing this obd_type
1941          */
1942         if (sym) {
1943                 /* final put if we manage this obd type */
1944                 if (sym->typ_sym_filter)
1945                         kobject_put(&sym->typ_kobj);
1946                 /* put reference taken by class_search_type */
1947                 kobject_put(&sym->typ_kobj);
1948         }
1949
1950         class_unregister_type(LUSTRE_LWP_NAME);
1951         class_unregister_type(LUSTRE_OSP_NAME);
1952         lu_kmem_fini(osp_caches);
1953 }
1954
1955 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
1956 MODULE_DESCRIPTION("Lustre OSD Storage Proxy ("LUSTRE_OSP_NAME")");
1957 MODULE_VERSION(LUSTRE_VERSION_STRING);
1958 MODULE_LICENSE("GPL");
1959
1960 module_init(osp_init);
1961 module_exit(osp_exit);