4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osp/osp_dev.c
38 * Lustre OST Proxy Device
40 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41 * Author: Mikhail Pershin <mike.pershin@intel.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_MDS
49 #include <obd_class.h>
50 #include <lustre_param.h>
52 #include "osp_internal.h"
54 /* Slab for OSP object allocation */
55 cfs_mem_cache_t *osp_object_kmem;
57 static struct lu_kmem_descr osp_caches[] = {
59 .ckd_cache = &osp_object_kmem,
60 .ckd_name = "osp_obj",
61 .ckd_size = sizeof(struct osp_object)
68 struct lu_object *osp_object_alloc(const struct lu_env *env,
69 const struct lu_object_header *hdr,
72 struct lu_object_header *h;
78 OBD_SLAB_ALLOC_PTR_GFP(o, osp_object_kmem, CFS_ALLOC_IO);
80 l = &o->opo_obj.do_lu;
83 lu_object_header_init(h);
84 dt_object_init(&o->opo_obj, h, d);
85 lu_object_add_top(h, l);
87 l->lo_ops = &osp_lu_obj_ops;
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)
99 * we might have lost precreated objects due to VBR and precreate
100 * orphans, the gap in objid can be calculated properly only here
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);
109 d->opd_last_used_id = cpu_to_le64(objid);
113 static int osp_last_used_init(const struct lu_env *env, struct osp_device *m)
115 struct osp_thread_info *osi = osp_env_info(env);
116 struct dt_object_format dof = { 0 };
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,
131 rc = dt_attr_get(env, o, &osi->osi_attr, NULL);
135 /* object will be released in device cleanup path */
136 m->opd_last_used_file = o;
138 if (osi->osi_attr.la_size >= sizeof(osi->osi_id) *
139 (m->opd_index + 1)) {
140 osp_objid_buf_prep(osi, m, m->opd_index);
141 rc = dt_record_read(env, o, &osi->osi_lb, &osi->osi_off);
145 /* reset value to 0, just to make sure and change file's size */
148 m->opd_last_used_id = 0;
149 osp_objid_buf_prep(osi, m, m->opd_index);
151 th = dt_trans_create(env, m->opd_storage);
153 GOTO(out, rc = PTR_ERR(th));
155 rc = dt_declare_record_write(env, m->opd_last_used_file,
156 osi->osi_lb.lb_len, osi->osi_off,
159 dt_trans_stop(env, m->opd_storage, th);
163 rc = dt_trans_start_local(env, m->opd_storage, th);
165 dt_trans_stop(env, m->opd_storage, th);
169 rc = dt_record_write(env, m->opd_last_used_file, &osi->osi_lb,
171 dt_trans_stop(env, m->opd_storage, th);
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;
184 static void osp_last_used_fini(const struct lu_env *env, struct osp_device *d)
186 if (d->opd_last_used_file != NULL) {
187 lu_object_put(env, &d->opd_last_used_file->do_lu);
188 d->opd_last_used_file = NULL;
192 int osp_disconnect(struct osp_device *d)
194 struct obd_import *imp;
197 imp = d->opd_obd->u.cli.cl_import;
199 /* Mark import deactivated now, so we don't try to reconnect if any
200 * of the cleanup RPCs fails (e.g. ldlm cancel, etc). We don't
201 * fully deactivate the import, or that would drop all requests. */
202 LASSERT(imp != NULL);
203 cfs_spin_lock(&imp->imp_lock);
204 imp->imp_deactive = 1;
205 cfs_spin_unlock(&imp->imp_lock);
207 ptlrpc_deactivate_import(imp);
209 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
210 * delete it regardless. (It's safe to delete an import that was
212 (void)ptlrpc_pinger_del_import(imp);
214 rc = ptlrpc_disconnect_import(imp, 0);
216 CERROR("%s: can't disconnect: rc = %d\n",
217 d->opd_obd->obd_name, rc);
219 ptlrpc_invalidate_import(imp);
224 static int osp_shutdown(const struct lu_env *env, struct osp_device *d)
229 if (is_osp_on_ost(d->opd_obd->obd_name)) {
230 rc = osp_disconnect(d);
235 /* release last_used file */
236 osp_last_used_fini(env, d);
238 rc = osp_disconnect(d);
240 /* stop precreate thread */
241 osp_precreate_fini(d);
243 /* stop sync thread */
249 static int osp_process_config(const struct lu_env *env,
250 struct lu_device *dev, struct lustre_cfg *lcfg)
252 struct osp_device *d = lu2osp_dev(dev);
253 struct lprocfs_static_vars lvars = { 0 };
258 switch (lcfg->lcfg_command) {
260 if (!is_osp_on_ost(d->opd_obd->obd_name))
261 lu_dev_del_linkage(dev->ld_site, dev);
262 rc = osp_shutdown(env, d);
265 lprocfs_osp_init_vars(&lvars);
268 rc = class_process_proc_param(PARAM_OSC, lvars.obd_vars,
273 /* class_process_proc_param() haven't found matching
274 * parameter and returned ENOSYS so that layer(s)
275 * below could use that. But OSP is the bottom, so
277 CERROR("%s: unknown param %s\n",
278 (char *)lustre_cfg_string(lcfg, 0),
279 (char *)lustre_cfg_string(lcfg, 1));
284 CERROR("%s: unknown command %u\n",
285 (char *)lustre_cfg_string(lcfg, 0), lcfg->lcfg_command);
293 static int osp_recovery_complete(const struct lu_env *env,
294 struct lu_device *dev)
296 struct osp_device *osp = lu2osp_dev(dev);
300 osp->opd_recovery_completed = 1;
301 cfs_waitq_signal(&osp->opd_pre_waitq);
305 const struct lu_device_operations osp_lu_ops = {
306 .ldo_object_alloc = osp_object_alloc,
307 .ldo_process_config = osp_process_config,
308 .ldo_recovery_complete = osp_recovery_complete,
312 * provides with statfs from corresponded OST
315 static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
316 struct obd_statfs *sfs)
318 struct osp_device *d = dt2osp_dev(dev);
322 if (unlikely(d->opd_imp_active == 0)) {
324 * in case of inactive OST we return nulls
325 * so that caller can understand this device
326 * is unusable for new objects
328 * XXX: shouldn't we take normal statfs and fill
329 * just few specific fields with zeroes?
331 memset(sfs, 0, sizeof(*sfs));
332 sfs->os_bsize = 4096;
336 /* return recently updated data */
337 *sfs = d->opd_statfs;
340 * layer above osp (usually lod) can use ffree to estimate
341 * how many objects are available for immediate creation
343 cfs_spin_lock(&d->opd_pre_lock);
344 sfs->os_ffree = d->opd_pre_last_created - d->opd_pre_next;
345 cfs_spin_unlock(&d->opd_pre_lock);
347 CDEBUG(D_OTHER, "%s: "LPU64" blocks, "LPU64" free, "LPU64" avail, "
348 LPU64" files, "LPU64" free files\n", d->opd_obd->obd_name,
349 sfs->os_blocks, sfs->os_bfree, sfs->os_bavail,
350 sfs->os_files, sfs->os_ffree);
354 static int osp_sync(const struct lu_env *env, struct dt_device *dev)
359 * XXX: wake up sync thread, command it to start flushing asap?
365 const struct dt_device_operations osp_dt_ops = {
366 .dt_statfs = osp_statfs,
370 static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *m,
373 struct obd_connect_data *data = NULL;
374 struct obd_device *obd;
379 LASSERT(m->opd_storage_exp == NULL);
385 obd = class_name2obd(nextdev);
387 CERROR("%s: can't locate next device: %s\n",
388 m->opd_obd->obd_name, nextdev);
389 GOTO(out, rc = -ENOTCONN);
392 rc = obd_connect(env, &m->opd_storage_exp, obd, &obd->obd_uuid, data,
395 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
396 m->opd_obd->obd_name, nextdev, rc);
400 m->opd_dt_dev.dd_lu_dev.ld_site =
401 m->opd_storage_exp->exp_obd->obd_lu_dev->ld_site;
402 LASSERT(m->opd_dt_dev.dd_lu_dev.ld_site);
403 m->opd_storage = lu2dt_dev(m->opd_storage_exp->exp_obd->obd_lu_dev);
410 static int osp_init0(const struct lu_env *env, struct osp_device *m,
411 struct lu_device_type *ldt, struct lustre_cfg *cfg)
413 struct lprocfs_static_vars lvars = { 0 };
414 struct proc_dir_entry *osc_proc_dir;
415 struct obd_import *imp;
417 char *src, *ost, *mdt, *osdname = NULL;
422 m->opd_obd = class_name2obd(lustre_cfg_string(cfg, 0));
423 if (m->opd_obd == NULL) {
424 CERROR("Cannot find obd with name %s\n",
425 lustre_cfg_string(cfg, 0));
429 /* There is no record in the MDT configuration for the local disk
430 * device, so we have to extract this from elsewhere in the profile.
431 * The only information we get at setup is from the OSC records:
432 * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
433 * Note that 1.8 generated configs are missing the -MDTxxxx part.
434 * We need to reconstruct the name of the underlying OSD from this:
435 * {fsname}-{svname}-osd, for example "lustre-MDT0000-osd". We
436 * also need to determine the OST index from this - will be used
437 * to calculate the offset in shared lov_objids file later */
439 src = lustre_cfg_string(cfg, 0);
443 ost = strstr(src, "-OST");
447 idx = simple_strtol(ost + 4, &mdt, 16);
448 if (mdt[0] != '-' || idx > INT_MAX || idx < 0) {
449 CERROR("%s: invalid OST index in '%s'\n",
450 m->opd_obd->obd_name, src);
451 GOTO(out_fini, rc = -EINVAL);
456 /* check the fsname length, and after this everything else will fit */
457 if (idx > MTI_NAME_MAXLEN) {
458 CERROR("%s: fsname too long in '%s'\n",
459 m->opd_obd->obd_name, src);
460 GOTO(out_fini, rc = -EINVAL);
463 OBD_ALLOC(osdname, MAX_OBD_NAME);
465 GOTO(out_fini, rc = -ENOMEM);
467 memcpy(osdname, src, idx); /* copy just the fsname part */
470 mdt = strstr(mdt, "-MDT");
471 if (mdt == NULL) /* 1.8 configs don't have "-MDT0000" at the end */
472 strcat(osdname, "-MDT0000");
474 strcat(osdname, mdt);
475 strcat(osdname, "-osd");
476 CDEBUG(D_HA, "%s: connect to %s (%s)\n",
477 m->opd_obd->obd_name, osdname, src);
479 m->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
480 m->opd_dt_dev.dd_ops = &osp_dt_ops;
481 m->opd_obd->obd_lu_dev = &m->opd_dt_dev.dd_lu_dev;
483 rc = osp_connect_to_osd(env, m, osdname);
487 rc = ptlrpcd_addref();
489 GOTO(out_disconnect, rc);
491 rc = client_obd_setup(m->opd_obd, cfg);
493 CERROR("%s: can't setup obd: %d\n", m->opd_obd->obd_name, rc);
497 lprocfs_osp_init_vars(&lvars);
498 if (lprocfs_obd_setup(m->opd_obd, lvars.obd_vars) == 0)
499 ptlrpc_lprocfs_register_obd(m->opd_obd);
501 /* for compatibility we link old procfs's OSC entries to osp ones */
502 osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
504 cfs_proc_dir_entry_t *symlink = NULL;
507 OBD_ALLOC(name, strlen(m->opd_obd->obd_name) + 1);
509 GOTO(out, rc = -ENOMEM);
511 strcpy(name, m->opd_obd->obd_name);
512 if (strstr(name, "osc"))
513 symlink = lprocfs_add_symlink(name, osc_proc_dir,
515 m->opd_obd->obd_name);
516 OBD_FREE(name, strlen(m->opd_obd->obd_name) + 1);
517 m->opd_symlink = symlink;
521 * Initialize last id from the storage - will be used in orphan cleanup
523 rc = osp_last_used_init(env, m);
528 * Initialize precreation thread, it handles new connections as well
530 rc = osp_init_precreate(m);
532 GOTO(out_last_used, rc);
535 * Initialize synhronization mechanism taking care of propogating
536 * changes to OST in near transactional manner
538 rc = osp_sync_init(env, m);
540 GOTO(out_precreat, rc);
543 * Initiate connect to OST
545 ll_generate_random_uuid(uuid);
546 class_uuid_unparse(uuid, &m->opd_cluuid);
548 imp = m->opd_obd->u.cli.cl_import;
550 rc = ptlrpc_init_import(imp);
554 OBD_FREE(osdname, MAX_OBD_NAME);
558 /* stop sync thread */
561 /* stop precreate thread */
562 osp_precreate_fini(m);
564 osp_last_used_fini(env, m);
566 ptlrpc_lprocfs_unregister_obd(m->opd_obd);
567 lprocfs_obd_cleanup(m->opd_obd);
568 class_destroy_import(m->opd_obd->u.cli.cl_import);
569 client_obd_cleanup(m->opd_obd);
573 obd_disconnect(m->opd_storage_exp);
576 OBD_FREE(osdname, MAX_OBD_NAME);
580 static struct lu_device *osp_device_free(const struct lu_env *env,
581 struct lu_device *lu)
583 struct osp_device *m = lu2osp_dev(lu);
587 if (cfs_atomic_read(&lu->ld_ref) && lu->ld_site) {
588 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
589 lu_site_print(env, lu->ld_site, &msgdata, lu_cdebug_printer);
591 dt_device_fini(&m->opd_dt_dev);
596 static struct lu_device *osp_device_alloc(const struct lu_env *env,
597 struct lu_device_type *t,
598 struct lustre_cfg *lcfg)
600 struct osp_device *m;
605 l = ERR_PTR(-ENOMEM);
610 dt_device_init(&m->opd_dt_dev, t);
611 if (is_osp_on_ost(lustre_cfg_string(lcfg, 0)))
612 rc = osp_init_for_ost(env, m, t, lcfg);
614 rc = osp_init0(env, m, t, lcfg);
616 osp_device_free(env, l);
623 static struct lu_device *osp_device_fini(const struct lu_env *env,
626 struct osp_device *m = lu2osp_dev(d);
627 struct obd_import *imp;
632 if (m->opd_storage_exp)
633 obd_disconnect(m->opd_storage_exp);
635 if (is_osp_on_ost(m->opd_obd->obd_name))
638 imp = m->opd_obd->u.cli.cl_import;
640 if (imp->imp_rq_pool) {
641 ptlrpc_free_rq_pool(imp->imp_rq_pool);
642 imp->imp_rq_pool = NULL;
645 obd_cleanup_client_import(m->opd_obd);
648 lprocfs_remove(&m->opd_symlink);
651 ptlrpc_lprocfs_unregister_obd(m->opd_obd);
652 lprocfs_obd_cleanup(m->opd_obd);
654 rc = client_obd_cleanup(m->opd_obd);
655 LASSERTF(rc == 0, "error %d\n", rc);
662 static int osp_reconnect(const struct lu_env *env,
663 struct obd_export *exp, struct obd_device *obd,
664 struct obd_uuid *cluuid,
665 struct obd_connect_data *data,
672 * we use exports to track all LOD users
674 static int osp_obd_connect(const struct lu_env *env, struct obd_export **exp,
675 struct obd_device *obd, struct obd_uuid *cluuid,
676 struct obd_connect_data *data, void *localdata)
678 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
679 struct obd_connect_data *ocd;
680 struct obd_import *imp;
681 struct lustre_handle conn;
686 CDEBUG(D_CONFIG, "connect #%d\n", osp->opd_connects);
688 rc = class_connect(&conn, obd, cluuid);
692 *exp = class_conn2export(&conn);
693 if (is_osp_on_ost(obd->obd_name))
696 /* Why should there ever be more than 1 connect? */
698 LASSERT(osp->opd_connects == 1);
700 imp = osp->opd_obd->u.cli.cl_import;
701 imp->imp_dlm_handle = conn;
703 ocd = &imp->imp_connect_data;
704 ocd->ocd_connect_flags = OBD_CONNECT_AT |
707 #ifdef HAVE_LRU_RESIZE_SUPPORT
708 OBD_CONNECT_LRU_RESIZE |
711 OBD_CONNECT_OSS_CAPA |
712 OBD_CONNECT_REQPORTAL |
713 OBD_CONNECT_SKIP_ORPHAN |
714 OBD_CONNECT_VERSION |
716 ocd->ocd_version = LUSTRE_VERSION_CODE;
717 LASSERT(data->ocd_connect_flags & OBD_CONNECT_INDEX);
718 ocd->ocd_index = data->ocd_index;
719 imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
721 rc = ptlrpc_connect_import(imp);
723 CERROR("%s: can't connect obd: rc = %d\n", obd->obd_name, rc);
727 ptlrpc_pinger_add_import(imp);
734 * once last export (we don't count self-export) disappeared
735 * osp can be released
737 static int osp_obd_disconnect(struct obd_export *exp)
739 struct obd_device *obd = exp->exp_obd;
740 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
744 /* Only disconnect the underlying layers on the final disconnect. */
745 LASSERT(osp->opd_connects == 1);
748 rc = class_disconnect(exp);
750 CERROR("%s: class disconnect error: rc = %d\n",
755 /* destroy the device */
756 if (!is_osp_on_ost(obd->obd_name))
757 class_manual_cleanup(obd);
763 * lprocfs helpers still use OBD API, let's keep obd_statfs() support
765 static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp,
766 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
768 struct obd_statfs *msfs;
769 struct ptlrpc_request *req;
770 struct obd_import *imp = NULL;
775 /* Since the request might also come from lprocfs, so we need
776 * sync this with client_disconnect_export Bug15684 */
777 cfs_down_read(&exp->exp_obd->u.cli.cl_sem);
778 if (exp->exp_obd->u.cli.cl_import)
779 imp = class_import_get(exp->exp_obd->u.cli.cl_import);
780 cfs_up_read(&exp->exp_obd->u.cli.cl_sem);
784 /* We could possibly pass max_age in the request (as an absolute
785 * timestamp or a "seconds.usec ago") so the target can avoid doing
786 * extra calls into the filesystem if that isn't necessary (e.g.
787 * during mount that would help a bit). Having relative timestamps
788 * is not so great if request processing is slow, while absolute
789 * timestamps are not ideal because they need time synchronization. */
790 req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
792 class_import_put(imp);
797 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_STATFS);
799 ptlrpc_request_free(req);
802 ptlrpc_request_set_replen(req);
803 req->rq_request_portal = OST_CREATE_PORTAL;
804 ptlrpc_at_set_req_timeout(req);
806 if (flags & OBD_STATFS_NODELAY) {
807 /* procfs requests not want stat in wait for avoid deadlock */
808 req->rq_no_resend = 1;
809 req->rq_no_delay = 1;
812 rc = ptlrpc_queue_wait(req);
816 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
818 GOTO(out, rc = -EPROTO);
824 ptlrpc_req_finished(req);
828 static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
829 enum obd_import_event event)
831 struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
834 case IMP_EVENT_DISCON:
835 d->opd_got_disconnected = 1;
836 d->opd_imp_connected = 0;
837 if (is_osp_on_ost(d->opd_obd->obd_name))
839 osp_pre_update_status(d, -ENODEV);
840 cfs_waitq_signal(&d->opd_pre_waitq);
841 CDEBUG(D_HA, "got disconnected\n");
843 case IMP_EVENT_INACTIVE:
844 d->opd_imp_active = 0;
845 if (is_osp_on_ost(d->opd_obd->obd_name))
847 osp_pre_update_status(d, -ENODEV);
848 cfs_waitq_signal(&d->opd_pre_waitq);
849 CDEBUG(D_HA, "got inactive\n");
851 case IMP_EVENT_ACTIVE:
852 d->opd_imp_active = 1;
853 if (d->opd_got_disconnected)
854 d->opd_new_connection = 1;
855 d->opd_imp_connected = 1;
856 d->opd_imp_seen_connected = 1;
857 if (is_osp_on_ost(d->opd_obd->obd_name))
859 cfs_waitq_signal(&d->opd_pre_waitq);
860 __osp_sync_check_for_work(d);
861 CDEBUG(D_HA, "got connected\n");
863 case IMP_EVENT_INVALIDATE:
864 if (obd->obd_namespace == NULL)
866 ldlm_namespace_cleanup(obd->obd_namespace, LDLM_FL_LOCAL_ONLY);
871 CERROR("%s: unsupported import event: %#x\n",
872 obd->obd_name, event);
877 static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
878 void *karg, void *uarg)
880 struct obd_device *obd = exp->exp_obd;
881 struct osp_device *d;
882 struct obd_ioctl_data *data = karg;
887 LASSERT(obd->obd_lu_dev);
888 d = lu2osp_dev(obd->obd_lu_dev);
889 LASSERT(d->opd_dt_dev.dd_ops == &osp_dt_ops);
891 if (!cfs_try_module_get(THIS_MODULE)) {
892 CERROR("%s: can't get module. Is it alive?", obd->obd_name);
897 case OBD_IOC_CLIENT_RECOVER:
898 rc = ptlrpc_recover_import(obd->u.cli.cl_import,
899 data->ioc_inlbuf1, 0);
903 case IOC_OSC_SET_ACTIVE:
904 rc = ptlrpc_set_import_active(obd->u.cli.cl_import,
907 case OBD_IOC_PING_TARGET:
908 rc = ptlrpc_obd_ping(obd);
911 CERROR("%s: unrecognized ioctl %#x by %s\n", obd->obd_name,
912 cmd, cfs_curproc_comm());
915 cfs_module_put(THIS_MODULE);
919 static int osp_obd_health_check(const struct lu_env *env,
920 struct obd_device *obd)
922 struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
927 * 1.8/2.0 behaviour is that OST being connected once at least
928 * is considired "healthy". and one "healty" OST is enough to
929 * allow lustre clients to connect to MDS
932 RETURN(!d->opd_imp_seen_connected);
935 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
936 LU_KEY_INIT_FINI(osp, struct osp_thread_info);
937 static void osp_key_exit(const struct lu_context *ctx,
938 struct lu_context_key *key, void *data)
940 struct osp_thread_info *info = data;
942 info->osi_attr.la_valid = 0;
945 struct lu_context_key osp_thread_key = {
946 .lct_tags = LCT_MD_THREAD,
947 .lct_init = osp_key_init,
948 .lct_fini = osp_key_fini,
949 .lct_exit = osp_key_exit
952 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
953 LU_KEY_INIT_FINI(osp_txn, struct osp_txn_info);
955 struct lu_context_key osp_txn_key = {
956 .lct_tags = LCT_OSP_THREAD,
957 .lct_init = osp_txn_key_init,
958 .lct_fini = osp_txn_key_fini
960 LU_TYPE_INIT_FINI(osp, &osp_thread_key, &osp_txn_key);
962 static struct lu_device_type_operations osp_device_type_ops = {
963 .ldto_init = osp_type_init,
964 .ldto_fini = osp_type_fini,
966 .ldto_start = osp_type_start,
967 .ldto_stop = osp_type_stop,
969 .ldto_device_alloc = osp_device_alloc,
970 .ldto_device_free = osp_device_free,
972 .ldto_device_fini = osp_device_fini
975 static struct lu_device_type osp_device_type = {
976 .ldt_tags = LU_DEVICE_DT,
977 .ldt_name = LUSTRE_OSP_NAME,
978 .ldt_ops = &osp_device_type_ops,
979 .ldt_ctx_tags = LCT_MD_THREAD
982 static struct obd_ops osp_obd_device_ops = {
983 .o_owner = THIS_MODULE,
984 .o_add_conn = client_import_add_conn,
985 .o_del_conn = client_import_del_conn,
986 .o_reconnect = osp_reconnect,
987 .o_connect = osp_obd_connect,
988 .o_disconnect = osp_obd_disconnect,
989 .o_health_check = osp_obd_health_check,
990 .o_import_event = osp_import_event,
991 .o_iocontrol = osp_iocontrol,
992 .o_statfs = osp_obd_statfs,
995 static int __init osp_mod_init(void)
997 struct lprocfs_static_vars lvars;
998 cfs_proc_dir_entry_t *osc_proc_dir;
1001 rc = lu_kmem_init(osp_caches);
1005 lprocfs_osp_init_vars(&lvars);
1007 rc = class_register_type(&osp_obd_device_ops, NULL, lvars.module_vars,
1008 LUSTRE_OSP_NAME, &osp_device_type);
1010 /* create "osc" entry in procfs for compatibility purposes */
1012 lu_kmem_fini(osp_caches);
1016 osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
1017 if (osc_proc_dir == NULL) {
1018 osc_proc_dir = lprocfs_register("osc", proc_lustre_root, NULL,
1020 if (IS_ERR(osc_proc_dir))
1021 CERROR("osp: can't create compat entry \"osc\": %d\n",
1022 (int) PTR_ERR(osc_proc_dir));
1027 static void __exit osp_mod_exit(void)
1029 lprocfs_try_remove_proc_entry("osc", proc_lustre_root);
1031 class_unregister_type(LUSTRE_OSP_NAME);
1032 lu_kmem_fini(osp_caches);
1035 MODULE_AUTHOR("Intel, Inc. <http://www.intel.com/>");
1036 MODULE_DESCRIPTION("Lustre OST Proxy Device ("LUSTRE_OSP_NAME")");
1037 MODULE_LICENSE("GPL");
1039 cfs_module(osp, LUSTRE_VERSION_STRING, osp_mod_init, osp_mod_exit);