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) 2012, Intel Corporation.
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>
51 #include <lustre_log.h>
53 #include "osp_internal.h"
55 /* Slab for OSP object allocation */
56 cfs_mem_cache_t *osp_object_kmem;
58 static struct lu_kmem_descr osp_caches[] = {
60 .ckd_cache = &osp_object_kmem,
61 .ckd_name = "osp_obj",
62 .ckd_size = sizeof(struct osp_object)
69 struct lu_object *osp_object_alloc(const struct lu_env *env,
70 const struct lu_object_header *hdr,
73 struct lu_object_header *h;
79 OBD_SLAB_ALLOC_PTR_GFP(o, osp_object_kmem, CFS_ALLOC_IO);
81 l = &o->opo_obj.do_lu;
84 lu_object_header_init(h);
85 dt_object_init(&o->opo_obj, h, d);
86 lu_object_add_top(h, l);
88 l->lo_ops = &osp_lu_obj_ops;
96 /* Update opd_last_used_id along with checking for gap in objid sequence */
97 void osp_update_last_id(struct osp_device *d, obd_id objid)
100 * we might have lost precreated objects due to VBR and precreate
101 * orphans, the gap in objid can be calculated properly only here
103 if (objid > le64_to_cpu(d->opd_last_used_id)) {
104 if (objid - le64_to_cpu(d->opd_last_used_id) > 1) {
105 d->opd_gap_start = le64_to_cpu(d->opd_last_used_id) + 1;
106 d->opd_gap_count = objid - d->opd_gap_start;
107 CDEBUG(D_HA, "Gap in objids: %d, start = %llu\n",
108 d->opd_gap_count, d->opd_gap_start);
110 d->opd_last_used_id = cpu_to_le64(objid);
114 static int osp_last_used_init(const struct lu_env *env, struct osp_device *m)
116 struct osp_thread_info *osi = osp_env_info(env);
117 struct dt_object_format dof = { 0 };
123 osi->osi_attr.la_valid = LA_MODE;
124 osi->osi_attr.la_mode = S_IFREG | 0644;
125 lu_local_obj_fid(&osi->osi_fid, MDD_LOV_OBJ_OID);
126 dof.dof_type = DFT_REGULAR;
127 o = dt_find_or_create(env, m->opd_storage, &osi->osi_fid, &dof,
132 rc = dt_attr_get(env, o, &osi->osi_attr, NULL);
136 /* object will be released in device cleanup path */
137 m->opd_last_used_file = o;
139 if (osi->osi_attr.la_size >= sizeof(osi->osi_id) *
140 (m->opd_index + 1)) {
141 osp_objid_buf_prep(osi, m, m->opd_index);
142 rc = dt_record_read(env, o, &osi->osi_lb, &osi->osi_off);
146 /* reset value to 0, just to make sure and change file's size */
149 m->opd_last_used_id = 0;
150 osp_objid_buf_prep(osi, m, m->opd_index);
152 th = dt_trans_create(env, m->opd_storage);
154 GOTO(out, rc = PTR_ERR(th));
156 rc = dt_declare_record_write(env, m->opd_last_used_file,
157 osi->osi_lb.lb_len, osi->osi_off,
160 dt_trans_stop(env, m->opd_storage, th);
164 rc = dt_trans_start_local(env, m->opd_storage, th);
166 dt_trans_stop(env, m->opd_storage, th);
170 rc = dt_record_write(env, m->opd_last_used_file, &osi->osi_lb,
172 dt_trans_stop(env, m->opd_storage, th);
176 CDEBUG(D_HA, "%s: Read last used ID: "LPU64"\n", m->opd_obd->obd_name,
177 le64_to_cpu(m->opd_last_used_id));
180 CERROR("%s: can't initialize lov_objid: %d\n",
181 m->opd_obd->obd_name, rc);
182 lu_object_put(env, &o->do_lu);
183 m->opd_last_used_file = NULL;
187 static void osp_last_used_fini(const struct lu_env *env, struct osp_device *d)
189 if (d->opd_last_used_file != NULL) {
190 lu_object_put(env, &d->opd_last_used_file->do_lu);
191 d->opd_last_used_file = NULL;
195 int osp_disconnect(struct osp_device *d)
197 struct obd_import *imp;
200 imp = d->opd_obd->u.cli.cl_import;
202 /* Mark import deactivated now, so we don't try to reconnect if any
203 * of the cleanup RPCs fails (e.g. ldlm cancel, etc). We don't
204 * fully deactivate the import, or that would drop all requests. */
205 LASSERT(imp != NULL);
206 spin_lock(&imp->imp_lock);
207 imp->imp_deactive = 1;
208 spin_unlock(&imp->imp_lock);
210 ptlrpc_deactivate_import(imp);
212 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
213 * delete it regardless. (It's safe to delete an import that was
215 (void)ptlrpc_pinger_del_import(imp);
217 rc = ptlrpc_disconnect_import(imp, 0);
218 if (rc == -ETIMEDOUT || rc == -ENOTCONN || rc == -ESHUTDOWN)
221 CERROR("%s: can't disconnect: rc = %d\n",
222 d->opd_obd->obd_name, rc);
224 ptlrpc_invalidate_import(imp);
229 static int osp_shutdown(const struct lu_env *env, struct osp_device *d)
234 if (is_osp_on_ost(d->opd_obd->obd_name)) {
235 rc = osp_disconnect(d);
240 /* release last_used file */
241 osp_last_used_fini(env, d);
243 rc = osp_disconnect(d);
245 /* stop precreate thread */
246 osp_precreate_fini(d);
248 /* stop sync thread */
254 static int osp_process_config(const struct lu_env *env,
255 struct lu_device *dev, struct lustre_cfg *lcfg)
257 struct osp_device *d = lu2osp_dev(dev);
258 struct lprocfs_static_vars lvars = { 0 };
263 switch (lcfg->lcfg_command) {
265 if (!is_osp_on_ost(d->opd_obd->obd_name))
266 lu_dev_del_linkage(dev->ld_site, dev);
267 rc = osp_shutdown(env, d);
270 lprocfs_osp_init_vars(&lvars);
273 rc = class_process_proc_param(PARAM_OSC, lvars.obd_vars,
278 /* class_process_proc_param() haven't found matching
279 * parameter and returned ENOSYS so that layer(s)
280 * below could use that. But OSP is the bottom, so
282 CERROR("%s: unknown param %s\n",
283 (char *)lustre_cfg_string(lcfg, 0),
284 (char *)lustre_cfg_string(lcfg, 1));
289 CERROR("%s: unknown command %u\n",
290 (char *)lustre_cfg_string(lcfg, 0), lcfg->lcfg_command);
298 static int osp_recovery_complete(const struct lu_env *env,
299 struct lu_device *dev)
301 struct osp_device *osp = lu2osp_dev(dev);
305 osp->opd_recovery_completed = 1;
306 cfs_waitq_signal(&osp->opd_pre_waitq);
310 const struct lu_device_operations osp_lu_ops = {
311 .ldo_object_alloc = osp_object_alloc,
312 .ldo_process_config = osp_process_config,
313 .ldo_recovery_complete = osp_recovery_complete,
317 * provides with statfs from corresponded OST
320 static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
321 struct obd_statfs *sfs)
323 struct osp_device *d = dt2osp_dev(dev);
327 if (unlikely(d->opd_imp_active == 0))
330 /* return recently updated data */
331 *sfs = d->opd_statfs;
334 * layer above osp (usually lod) can use ffree to estimate
335 * how many objects are available for immediate creation
337 spin_lock(&d->opd_pre_lock);
338 sfs->os_fprecreated = d->opd_pre_last_created - d->opd_pre_used_id;
339 sfs->os_fprecreated -= d->opd_pre_reserved;
340 spin_unlock(&d->opd_pre_lock);
342 LASSERT(sfs->os_fprecreated <= OST_MAX_PRECREATE * 2);
344 CDEBUG(D_OTHER, "%s: "LPU64" blocks, "LPU64" free, "LPU64" avail, "
345 LPU64" files, "LPU64" free files\n", d->opd_obd->obd_name,
346 sfs->os_blocks, sfs->os_bfree, sfs->os_bavail,
347 sfs->os_files, sfs->os_ffree);
351 static int osp_sync(const struct lu_env *env, struct dt_device *dev)
356 * XXX: wake up sync thread, command it to start flushing asap?
362 const struct dt_device_operations osp_dt_ops = {
363 .dt_statfs = osp_statfs,
367 static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *m,
370 struct obd_connect_data *data = NULL;
371 struct obd_device *obd;
376 LASSERT(m->opd_storage_exp == NULL);
382 obd = class_name2obd(nextdev);
384 CERROR("%s: can't locate next device: %s\n",
385 m->opd_obd->obd_name, nextdev);
386 GOTO(out, rc = -ENOTCONN);
389 rc = obd_connect(env, &m->opd_storage_exp, obd, &obd->obd_uuid, data,
392 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
393 m->opd_obd->obd_name, nextdev, rc);
397 m->opd_dt_dev.dd_lu_dev.ld_site =
398 m->opd_storage_exp->exp_obd->obd_lu_dev->ld_site;
399 LASSERT(m->opd_dt_dev.dd_lu_dev.ld_site);
400 m->opd_storage = lu2dt_dev(m->opd_storage_exp->exp_obd->obd_lu_dev);
407 static int osp_init0(const struct lu_env *env, struct osp_device *m,
408 struct lu_device_type *ldt, struct lustre_cfg *cfg)
410 struct obd_device *obd;
411 struct obd_import *imp;
413 char *src, *ost, *mdt, *osdname = NULL;
418 obd = class_name2obd(lustre_cfg_string(cfg, 0));
420 CERROR("Cannot find obd with name %s\n",
421 lustre_cfg_string(cfg, 0));
426 /* There is no record in the MDT configuration for the local disk
427 * device, so we have to extract this from elsewhere in the profile.
428 * The only information we get at setup is from the OSC records:
429 * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
430 * Note that 1.8 generated configs are missing the -MDTxxxx part.
431 * We need to reconstruct the name of the underlying OSD from this:
432 * {fsname}-{svname}-osd, for example "lustre-MDT0000-osd". We
433 * also need to determine the OST index from this - will be used
434 * to calculate the offset in shared lov_objids file later */
436 src = lustre_cfg_string(cfg, 0);
440 ost = strstr(src, "-OST");
444 idx = simple_strtol(ost + 4, &mdt, 16);
445 if (mdt[0] != '-' || idx > INT_MAX || idx < 0) {
446 CERROR("%s: invalid OST index in '%s'\n", obd->obd_name, src);
447 GOTO(out_fini, rc = -EINVAL);
452 /* check the fsname length, and after this everything else will fit */
453 if (idx > MTI_NAME_MAXLEN) {
454 CERROR("%s: fsname too long in '%s'\n", obd->obd_name, src);
455 GOTO(out_fini, rc = -EINVAL);
458 OBD_ALLOC(osdname, MAX_OBD_NAME);
460 GOTO(out_fini, rc = -ENOMEM);
462 memcpy(osdname, src, idx); /* copy just the fsname part */
465 mdt = strstr(mdt, "-MDT");
466 if (mdt == NULL) /* 1.8 configs don't have "-MDT0000" at the end */
467 strcat(osdname, "-MDT0000");
469 strcat(osdname, mdt);
470 strcat(osdname, "-osd");
471 CDEBUG(D_HA, "%s: connect to %s (%s)\n", obd->obd_name, osdname, src);
473 m->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
474 m->opd_dt_dev.dd_ops = &osp_dt_ops;
475 obd->obd_lu_dev = &m->opd_dt_dev.dd_lu_dev;
477 rc = osp_connect_to_osd(env, m, osdname);
481 rc = ptlrpcd_addref();
483 GOTO(out_disconnect, rc);
485 rc = client_obd_setup(obd, cfg);
487 CERROR("%s: can't setup obd: %d\n", m->opd_obd->obd_name, rc);
494 * Initialize last id from the storage - will be used in orphan cleanup
496 rc = osp_last_used_init(env, m);
501 * Initialize precreation thread, it handles new connections as well
503 rc = osp_init_precreate(m);
505 GOTO(out_last_used, rc);
508 * Initialize synhronization mechanism taking care of propogating
509 * changes to OST in near transactional manner
511 rc = osp_sync_init(env, m);
513 GOTO(out_precreat, rc);
516 * Initiate connect to OST
518 ll_generate_random_uuid(uuid);
519 class_uuid_unparse(uuid, &m->opd_cluuid);
521 imp = obd->u.cli.cl_import;
523 rc = ptlrpc_init_import(imp);
527 OBD_FREE(osdname, MAX_OBD_NAME);
531 /* stop sync thread */
534 /* stop precreate thread */
535 osp_precreate_fini(m);
537 osp_last_used_fini(env, m);
539 ptlrpc_lprocfs_unregister_obd(obd);
540 lprocfs_obd_cleanup(obd);
541 class_destroy_import(obd->u.cli.cl_import);
542 client_obd_cleanup(obd);
546 obd_disconnect(m->opd_storage_exp);
549 OBD_FREE(osdname, MAX_OBD_NAME);
553 static struct lu_device *osp_device_free(const struct lu_env *env,
554 struct lu_device *lu)
556 struct osp_device *m = lu2osp_dev(lu);
560 if (cfs_atomic_read(&lu->ld_ref) && lu->ld_site) {
561 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
562 lu_site_print(env, lu->ld_site, &msgdata, lu_cdebug_printer);
564 dt_device_fini(&m->opd_dt_dev);
569 static struct lu_device *osp_device_alloc(const struct lu_env *env,
570 struct lu_device_type *t,
571 struct lustre_cfg *lcfg)
573 struct osp_device *m;
578 l = ERR_PTR(-ENOMEM);
583 dt_device_init(&m->opd_dt_dev, t);
584 if (is_osp_on_ost(lustre_cfg_string(lcfg, 0)))
585 rc = osp_init_for_ost(env, m, t, lcfg);
587 rc = osp_init0(env, m, t, lcfg);
589 osp_device_free(env, l);
596 static struct lu_device *osp_device_fini(const struct lu_env *env,
599 struct osp_device *m = lu2osp_dev(d);
600 struct obd_import *imp;
605 if (m->opd_storage_exp)
606 obd_disconnect(m->opd_storage_exp);
608 if (is_osp_on_ost(m->opd_obd->obd_name))
611 imp = m->opd_obd->u.cli.cl_import;
613 if (imp->imp_rq_pool) {
614 ptlrpc_free_rq_pool(imp->imp_rq_pool);
615 imp->imp_rq_pool = NULL;
618 obd_cleanup_client_import(m->opd_obd);
621 lprocfs_remove(&m->opd_symlink);
624 ptlrpc_lprocfs_unregister_obd(m->opd_obd);
625 lprocfs_obd_cleanup(m->opd_obd);
627 rc = client_obd_cleanup(m->opd_obd);
628 LASSERTF(rc == 0, "error %d\n", rc);
635 static int osp_reconnect(const struct lu_env *env,
636 struct obd_export *exp, struct obd_device *obd,
637 struct obd_uuid *cluuid,
638 struct obd_connect_data *data,
645 * we use exports to track all LOD users
647 static int osp_obd_connect(const struct lu_env *env, struct obd_export **exp,
648 struct obd_device *obd, struct obd_uuid *cluuid,
649 struct obd_connect_data *data, void *localdata)
651 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
652 struct obd_connect_data *ocd;
653 struct obd_import *imp;
654 struct lustre_handle conn;
659 CDEBUG(D_CONFIG, "connect #%d\n", osp->opd_connects);
661 rc = class_connect(&conn, obd, cluuid);
665 *exp = class_conn2export(&conn);
666 if (is_osp_on_ost(obd->obd_name))
669 /* Why should there ever be more than 1 connect? */
671 LASSERT(osp->opd_connects == 1);
673 imp = osp->opd_obd->u.cli.cl_import;
674 imp->imp_dlm_handle = conn;
676 ocd = &imp->imp_connect_data;
677 ocd->ocd_connect_flags = OBD_CONNECT_AT |
680 #ifdef HAVE_LRU_RESIZE_SUPPORT
681 OBD_CONNECT_LRU_RESIZE |
684 OBD_CONNECT_OSS_CAPA |
685 OBD_CONNECT_REQPORTAL |
686 OBD_CONNECT_SKIP_ORPHAN |
687 OBD_CONNECT_VERSION |
689 OBD_CONNECT_LVB_TYPE;
691 if (is_osp_on_ost(osp->opd_obd->obd_name))
692 ocd->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
694 ocd->ocd_version = LUSTRE_VERSION_CODE;
695 LASSERT(data->ocd_connect_flags & OBD_CONNECT_INDEX);
696 ocd->ocd_index = data->ocd_index;
697 imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
699 rc = ptlrpc_connect_import(imp);
701 CERROR("%s: can't connect obd: rc = %d\n", obd->obd_name, rc);
705 ptlrpc_pinger_add_import(imp);
712 * once last export (we don't count self-export) disappeared
713 * osp can be released
715 static int osp_obd_disconnect(struct obd_export *exp)
717 struct obd_device *obd = exp->exp_obd;
718 struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
722 /* Only disconnect the underlying layers on the final disconnect. */
723 LASSERT(osp->opd_connects == 1);
726 rc = class_disconnect(exp);
728 CERROR("%s: class disconnect error: rc = %d\n",
733 /* destroy the device */
734 if (!is_osp_on_ost(obd->obd_name))
735 class_manual_cleanup(obd);
741 * lprocfs helpers still use OBD API, let's keep obd_statfs() support
743 static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp,
744 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
746 struct obd_statfs *msfs;
747 struct ptlrpc_request *req;
748 struct obd_import *imp = NULL;
753 /* Since the request might also come from lprocfs, so we need
754 * sync this with client_disconnect_export Bug15684 */
755 down_read(&exp->exp_obd->u.cli.cl_sem);
756 if (exp->exp_obd->u.cli.cl_import)
757 imp = class_import_get(exp->exp_obd->u.cli.cl_import);
758 up_read(&exp->exp_obd->u.cli.cl_sem);
762 /* We could possibly pass max_age in the request (as an absolute
763 * timestamp or a "seconds.usec ago") so the target can avoid doing
764 * extra calls into the filesystem if that isn't necessary (e.g.
765 * during mount that would help a bit). Having relative timestamps
766 * is not so great if request processing is slow, while absolute
767 * timestamps are not ideal because they need time synchronization. */
768 req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
770 class_import_put(imp);
775 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_STATFS);
777 ptlrpc_request_free(req);
780 ptlrpc_request_set_replen(req);
781 req->rq_request_portal = OST_CREATE_PORTAL;
782 ptlrpc_at_set_req_timeout(req);
784 if (flags & OBD_STATFS_NODELAY) {
785 /* procfs requests not want stat in wait for avoid deadlock */
786 req->rq_no_resend = 1;
787 req->rq_no_delay = 1;
790 rc = ptlrpc_queue_wait(req);
794 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
796 GOTO(out, rc = -EPROTO);
802 ptlrpc_req_finished(req);
806 static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
807 enum obd_import_event event)
809 struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
812 case IMP_EVENT_DISCON:
813 d->opd_got_disconnected = 1;
814 d->opd_imp_connected = 0;
815 if (is_osp_on_ost(d->opd_obd->obd_name))
817 osp_pre_update_status(d, -ENODEV);
818 cfs_waitq_signal(&d->opd_pre_waitq);
819 CDEBUG(D_HA, "got disconnected\n");
821 case IMP_EVENT_INACTIVE:
822 d->opd_imp_active = 0;
823 if (is_osp_on_ost(d->opd_obd->obd_name))
825 osp_pre_update_status(d, -ENODEV);
826 cfs_waitq_signal(&d->opd_pre_waitq);
827 CDEBUG(D_HA, "got inactive\n");
829 case IMP_EVENT_ACTIVE:
830 d->opd_imp_active = 1;
831 if (d->opd_got_disconnected)
832 d->opd_new_connection = 1;
833 d->opd_imp_connected = 1;
834 d->opd_imp_seen_connected = 1;
835 if (is_osp_on_ost(d->opd_obd->obd_name))
837 cfs_waitq_signal(&d->opd_pre_waitq);
838 __osp_sync_check_for_work(d);
839 CDEBUG(D_HA, "got connected\n");
841 case IMP_EVENT_INVALIDATE:
842 if (obd->obd_namespace == NULL)
844 ldlm_namespace_cleanup(obd->obd_namespace, LDLM_FL_LOCAL_ONLY);
847 case IMP_EVENT_DEACTIVATE:
848 case IMP_EVENT_ACTIVATE:
851 CERROR("%s: unsupported import event: %#x\n",
852 obd->obd_name, event);
857 static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
858 void *karg, void *uarg)
860 struct obd_device *obd = exp->exp_obd;
861 struct osp_device *d;
862 struct obd_ioctl_data *data = karg;
867 LASSERT(obd->obd_lu_dev);
868 d = lu2osp_dev(obd->obd_lu_dev);
869 LASSERT(d->opd_dt_dev.dd_ops == &osp_dt_ops);
871 if (!cfs_try_module_get(THIS_MODULE)) {
872 CERROR("%s: can't get module. Is it alive?", obd->obd_name);
877 case OBD_IOC_CLIENT_RECOVER:
878 rc = ptlrpc_recover_import(obd->u.cli.cl_import,
879 data->ioc_inlbuf1, 0);
883 case IOC_OSC_SET_ACTIVE:
884 rc = ptlrpc_set_import_active(obd->u.cli.cl_import,
887 case OBD_IOC_PING_TARGET:
888 rc = ptlrpc_obd_ping(obd);
891 CERROR("%s: unrecognized ioctl %#x by %s\n", obd->obd_name,
892 cmd, cfs_curproc_comm());
895 cfs_module_put(THIS_MODULE);
899 static int osp_obd_health_check(const struct lu_env *env,
900 struct obd_device *obd)
902 struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
907 * 1.8/2.0 behaviour is that OST being connected once at least
908 * is considired "healthy". and one "healty" OST is enough to
909 * allow lustre clients to connect to MDS
912 RETURN(!d->opd_imp_seen_connected);
915 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
916 LU_KEY_INIT_FINI(osp, struct osp_thread_info);
917 static void osp_key_exit(const struct lu_context *ctx,
918 struct lu_context_key *key, void *data)
920 struct osp_thread_info *info = data;
922 info->osi_attr.la_valid = 0;
925 struct lu_context_key osp_thread_key = {
926 .lct_tags = LCT_MD_THREAD,
927 .lct_init = osp_key_init,
928 .lct_fini = osp_key_fini,
929 .lct_exit = osp_key_exit
932 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
933 LU_KEY_INIT_FINI(osp_txn, struct osp_txn_info);
935 struct lu_context_key osp_txn_key = {
936 .lct_tags = LCT_OSP_THREAD,
937 .lct_init = osp_txn_key_init,
938 .lct_fini = osp_txn_key_fini
940 LU_TYPE_INIT_FINI(osp, &osp_thread_key, &osp_txn_key);
942 static struct lu_device_type_operations osp_device_type_ops = {
943 .ldto_init = osp_type_init,
944 .ldto_fini = osp_type_fini,
946 .ldto_start = osp_type_start,
947 .ldto_stop = osp_type_stop,
949 .ldto_device_alloc = osp_device_alloc,
950 .ldto_device_free = osp_device_free,
952 .ldto_device_fini = osp_device_fini
955 static struct lu_device_type osp_device_type = {
956 .ldt_tags = LU_DEVICE_DT,
957 .ldt_name = LUSTRE_OSP_NAME,
958 .ldt_ops = &osp_device_type_ops,
959 .ldt_ctx_tags = LCT_MD_THREAD
962 static struct obd_ops osp_obd_device_ops = {
963 .o_owner = THIS_MODULE,
964 .o_add_conn = client_import_add_conn,
965 .o_del_conn = client_import_del_conn,
966 .o_reconnect = osp_reconnect,
967 .o_connect = osp_obd_connect,
968 .o_disconnect = osp_obd_disconnect,
969 .o_health_check = osp_obd_health_check,
970 .o_import_event = osp_import_event,
971 .o_iocontrol = osp_iocontrol,
972 .o_statfs = osp_obd_statfs,
975 struct llog_operations osp_mds_ost_orig_logops;
977 static int __init osp_mod_init(void)
979 struct lprocfs_static_vars lvars;
980 cfs_proc_dir_entry_t *osc_proc_dir;
983 rc = lu_kmem_init(osp_caches);
987 lprocfs_osp_init_vars(&lvars);
989 rc = class_register_type(&osp_obd_device_ops, NULL, lvars.module_vars,
990 LUSTRE_OSP_NAME, &osp_device_type);
992 /* create "osc" entry in procfs for compatibility purposes */
994 lu_kmem_fini(osp_caches);
998 /* Note: add_rec/delcare_add_rec will be only used by catalogs */
999 osp_mds_ost_orig_logops = llog_osd_ops;
1000 osp_mds_ost_orig_logops.lop_add = llog_cat_add_rec;
1001 osp_mds_ost_orig_logops.lop_declare_add = llog_cat_declare_add_rec;
1003 osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
1004 if (osc_proc_dir == NULL) {
1005 osc_proc_dir = lprocfs_register("osc", proc_lustre_root, NULL,
1007 if (IS_ERR(osc_proc_dir))
1008 CERROR("osp: can't create compat entry \"osc\": %d\n",
1009 (int) PTR_ERR(osc_proc_dir));
1014 static void __exit osp_mod_exit(void)
1016 lprocfs_try_remove_proc_entry("osc", proc_lustre_root);
1018 class_unregister_type(LUSTRE_OSP_NAME);
1019 lu_kmem_fini(osp_caches);
1022 MODULE_AUTHOR("Intel, Inc. <http://www.intel.com/>");
1023 MODULE_DESCRIPTION("Lustre OST Proxy Device ("LUSTRE_OSP_NAME")");
1024 MODULE_LICENSE("GPL");
1026 cfs_module(osp, LUSTRE_VERSION_STRING, osp_mod_init, osp_mod_exit);