/* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * mdd/mdd_handler.c * Lustre Metadata Server (mdd) routines * * Copyright (C) 2006 Cluster File Systems, Inc. * Author: Wang Di * * This file is part of the Lustre file system, http://www.lustre.org * Lustre is a trademark of Cluster File Systems, Inc. * * You may have signed or agreed to another license before downloading * this software. If so, you are bound by the terms and conditions * of that agreement, and the following does not apply to you. See the * LICENSE file included with this distribution for more information. * * If you did not agree to a different license, then this copy of Lustre * is open source software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * In either case, Lustre is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * license text for more details. */ #ifndef EXPORT_SYMTAB # define EXPORT_SYMTAB #endif #define DEBUG_SUBSYSTEM S_MDS #include #include #include #include #include #include #include #include #include #include #include "mdd_internal.h" struct md_device_operations mdd_ops; static const char *mdd_root_dir_name = "root"; static int mdd_device_init(const struct lu_env *env, struct lu_device *d, const char *name, struct lu_device *next) { struct mdd_device *mdd = lu2mdd_dev(d); int rc; ENTRY; mdd->mdd_child = lu2dt_dev(next); /* Prepare transactions callbacks. */ mdd->mdd_txn_cb.dtc_txn_start = mdd_txn_start_cb; mdd->mdd_txn_cb.dtc_txn_stop = mdd_txn_stop_cb; mdd->mdd_txn_cb.dtc_txn_commit = mdd_txn_commit_cb; mdd->mdd_txn_cb.dtc_cookie = mdd; INIT_LIST_HEAD(&mdd->mdd_txn_cb.dtc_linkage); rc = mdd_procfs_init(mdd, name); RETURN(rc); } static struct lu_device *mdd_device_fini(const struct lu_env *env, struct lu_device *d) { struct mdd_device *mdd = lu2mdd_dev(d); struct lu_device *next = &mdd->mdd_child->dd_lu_dev; int rc; rc = mdd_procfs_fini(mdd); if (rc) { CERROR("proc fini error %d \n", rc); return ERR_PTR(rc); } return next; } static int mdd_mount(const struct lu_env *env, struct mdd_device *mdd) { int rc; struct dt_object *root; ENTRY; dt_txn_callback_add(mdd->mdd_child, &mdd->mdd_txn_cb); root = dt_store_open(env, mdd->mdd_child, mdd_root_dir_name, &mdd->mdd_root_fid); if (!IS_ERR(root)) { LASSERT(root != NULL); lu_object_put(env, &root->do_lu); rc = orph_index_init(env, mdd); } else rc = PTR_ERR(root); RETURN(rc); } static void mdd_device_shutdown(const struct lu_env *env, struct mdd_device *m, struct lustre_cfg *cfg) { ENTRY; dt_txn_callback_del(m->mdd_child, &m->mdd_txn_cb); if (m->mdd_obd_dev) mdd_fini_obd(env, m, cfg); orph_index_fini(env, m); /* remove upcall device*/ md_upcall_fini(&m->mdd_md_dev); EXIT; } static int mdd_process_config(const struct lu_env *env, struct lu_device *d, struct lustre_cfg *cfg) { struct mdd_device *m = lu2mdd_dev(d); struct dt_device *dt = m->mdd_child; struct lu_device *next = &dt->dd_lu_dev; int rc; ENTRY; switch (cfg->lcfg_command) { case LCFG_SETUP: rc = next->ld_ops->ldo_process_config(env, next, cfg); if (rc) GOTO(out, rc); dt->dd_ops->dt_conf_get(env, dt, &m->mdd_dt_conf); rc = mdd_init_obd(env, m, cfg); if (rc) { CERROR("lov init error %d \n", rc); GOTO(out, rc); } rc = mdd_mount(env, m); if (rc) GOTO(out, rc); rc = mdd_txn_init_credits(env, m); break; case LCFG_CLEANUP: mdd_device_shutdown(env, m, cfg); default: rc = next->ld_ops->ldo_process_config(env, next, cfg); break; } out: RETURN(rc); } #if 0 static int mdd_lov_set_nextid(const struct lu_env *env, struct mdd_device *mdd) { struct mds_obd *mds = &mdd->mdd_obd_dev->u.mds; int rc; ENTRY; LASSERT(mds->mds_lov_objids != NULL); rc = obd_set_info_async(mds->mds_osc_exp, strlen(KEY_NEXT_ID), KEY_NEXT_ID, mds->mds_lov_desc.ld_tgt_count, mds->mds_lov_objids, NULL); RETURN(rc); } static int mdd_cleanup_unlink_llog(const struct lu_env *env, struct mdd_device *mdd) { /* XXX: to be implemented! */ return 0; } #endif static int mdd_recovery_complete(const struct lu_env *env, struct lu_device *d) { struct mdd_device *mdd = lu2mdd_dev(d); struct lu_device *next = &mdd->mdd_child->dd_lu_dev; struct obd_device *obd = mdd2obd_dev(mdd); int rc; ENTRY; LASSERT(mdd != NULL); LASSERT(obd != NULL); #if 0 /* XXX: Do we need this in new stack? */ rc = mdd_lov_set_nextid(env, mdd); if (rc) { CERROR("mdd_lov_set_nextid() failed %d\n", rc); RETURN(rc); } /* XXX: cleanup unlink. */ rc = mdd_cleanup_unlink_llog(env, mdd); if (rc) { CERROR("mdd_cleanup_unlink_llog() failed %d\n", rc); RETURN(rc); } #endif /* Call that with obd_recovering = 1 just to update objids */ obd_notify(obd->u.mds.mds_osc_obd, NULL, (obd->obd_async_recov ? OBD_NOTIFY_SYNC_NONBLOCK : OBD_NOTIFY_SYNC), NULL); /* Drop obd_recovering to 0 and call o_postrecov to recover mds_lov */ obd->obd_recovering = 0; obd->obd_type->typ_dt_ops->o_postrecov(obd); /* XXX: orphans handling. */ __mdd_orphan_cleanup(env, mdd); rc = next->ld_ops->ldo_recovery_complete(env, next); RETURN(rc); } struct lu_device_operations mdd_lu_ops = { .ldo_object_alloc = mdd_object_alloc, .ldo_process_config = mdd_process_config, .ldo_recovery_complete = mdd_recovery_complete }; /* * No permission check is needed. */ static int mdd_root_get(const struct lu_env *env, struct md_device *m, struct lu_fid *f) { struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); ENTRY; *f = mdd->mdd_root_fid; RETURN(0); } /* * No permission check is needed. */ static int mdd_statfs(const struct lu_env *env, struct md_device *m, struct kstatfs *sfs) { struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); int rc; ENTRY; rc = mdd_child_ops(mdd)->dt_statfs(env, mdd->mdd_child, sfs); RETURN(rc); } /* * No permission check is needed. */ static int mdd_maxsize_get(const struct lu_env *env, struct md_device *m, int *md_size, int *cookie_size) { struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); ENTRY; *md_size = mdd_lov_mdsize(env, mdd); *cookie_size = mdd_lov_cookiesize(env, mdd); RETURN(0); } static int mdd_init_capa_ctxt(const struct lu_env *env, struct md_device *m, int mode, unsigned long timeout, __u32 alg, struct lustre_capa_key *keys) { struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); struct mds_obd *mds = &mdd2obd_dev(mdd)->u.mds; int rc; ENTRY; mds->mds_capa_keys = keys; rc = mdd_child_ops(mdd)->dt_init_capa_ctxt(env, mdd->mdd_child, mode, timeout, alg, keys); RETURN(rc); } static int mdd_update_capa_key(const struct lu_env *env, struct md_device *m, struct lustre_capa_key *key) { struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); struct obd_export *lov_exp = mdd2obd_dev(mdd)->u.mds.mds_osc_exp; int rc; ENTRY; rc = obd_set_info_async(lov_exp, strlen(KEY_CAPA_KEY), KEY_CAPA_KEY, sizeof(*key), key, NULL); RETURN(rc); } static struct lu_device *mdd_device_alloc(const struct lu_env *env, struct lu_device_type *t, struct lustre_cfg *lcfg) { struct lu_device *l; struct mdd_device *m; OBD_ALLOC_PTR(m); if (m == NULL) { l = ERR_PTR(-ENOMEM); } else { md_device_init(&m->mdd_md_dev, t); l = mdd2lu_dev(m); l->ld_ops = &mdd_lu_ops; m->mdd_md_dev.md_ops = &mdd_ops; md_upcall_init(&m->mdd_md_dev, NULL); } return l; } static void mdd_device_free(const struct lu_env *env, struct lu_device *lu) { struct mdd_device *m = lu2mdd_dev(lu); LASSERT(atomic_read(&lu->ld_ref) == 0); md_device_fini(&m->mdd_md_dev); OBD_FREE_PTR(m); } static struct obd_ops mdd_obd_device_ops = { .o_owner = THIS_MODULE }; LU_KEY_INIT_FINI(mdd_ucred, struct md_ucred); static struct lu_context_key mdd_ucred_key = { .lct_tags = LCT_SESSION, .lct_init = mdd_ucred_key_init, .lct_fini = mdd_ucred_key_fini }; struct md_ucred *md_ucred(const struct lu_env *env) { LASSERT(env->le_ses != NULL); return lu_context_key_get(env->le_ses, &mdd_ucred_key); } EXPORT_SYMBOL(md_ucred); LU_KEY_INIT_FINI(mdd_capainfo, struct md_capainfo); struct lu_context_key mdd_capainfo_key = { .lct_tags = LCT_SESSION, .lct_init = mdd_capainfo_key_init, .lct_fini = mdd_capainfo_key_fini }; struct md_capainfo *md_capainfo(const struct lu_env *env) { /* NB, in mdt_init0 */ if (env->le_ses == NULL) return NULL; return lu_context_key_get(env->le_ses, &mdd_capainfo_key); } EXPORT_SYMBOL(md_capainfo); static int mdd_type_init(struct lu_device_type *t) { int result; LU_CONTEXT_KEY_INIT(&mdd_thread_key); result = lu_context_key_register(&mdd_thread_key); if (result == 0) { LU_CONTEXT_KEY_INIT(&mdd_ucred_key); result = lu_context_key_register(&mdd_ucred_key); } if (result == 0) { LU_CONTEXT_KEY_INIT(&mdd_capainfo_key); result = lu_context_key_register(&mdd_capainfo_key); } return result; } static void mdd_type_fini(struct lu_device_type *t) { lu_context_key_degister(&mdd_capainfo_key); lu_context_key_degister(&mdd_ucred_key); lu_context_key_degister(&mdd_thread_key); } struct md_device_operations mdd_ops = { .mdo_statfs = mdd_statfs, .mdo_root_get = mdd_root_get, .mdo_maxsize_get = mdd_maxsize_get, .mdo_init_capa_ctxt = mdd_init_capa_ctxt, .mdo_update_capa_key= mdd_update_capa_key, }; static struct lu_device_type_operations mdd_device_type_ops = { .ldto_init = mdd_type_init, .ldto_fini = mdd_type_fini, .ldto_device_alloc = mdd_device_alloc, .ldto_device_free = mdd_device_free, .ldto_device_init = mdd_device_init, .ldto_device_fini = mdd_device_fini }; static struct lu_device_type mdd_device_type = { .ldt_tags = LU_DEVICE_MD, .ldt_name = LUSTRE_MDD_NAME, .ldt_ops = &mdd_device_type_ops, .ldt_ctx_tags = LCT_MD_THREAD }; LU_KEY_INIT(mdd, struct mdd_thread_info); static void mdd_key_fini(const struct lu_context *ctx, struct lu_context_key *key, void *data) { struct mdd_thread_info *info = data; if (info->mti_max_lmm != NULL) OBD_FREE(info->mti_max_lmm, info->mti_max_lmm_size); if (info->mti_max_cookie != NULL) OBD_FREE(info->mti_max_cookie, info->mti_max_cookie_size); OBD_FREE_PTR(info); } struct lu_context_key mdd_thread_key = { .lct_tags = LCT_MD_THREAD, .lct_init = mdd_key_init, .lct_fini = mdd_key_fini }; struct lprocfs_vars lprocfs_mdd_obd_vars[] = { { 0 } }; struct lprocfs_vars lprocfs_mdd_module_vars[] = { { 0 } }; LPROCFS_INIT_VARS(mdd, lprocfs_mdd_module_vars, lprocfs_mdd_obd_vars); static int __init mdd_mod_init(void) { struct lprocfs_static_vars lvars; lprocfs_init_vars(mdd, &lvars); return class_register_type(&mdd_obd_device_ops, NULL, lvars.module_vars, LUSTRE_MDD_NAME, &mdd_device_type); } static void __exit mdd_mod_exit(void) { class_unregister_type(LUSTRE_MDD_NAME); } MODULE_AUTHOR("Cluster File Systems, Inc. "); MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD_NAME")"); MODULE_LICENSE("GPL"); cfs_module(mdd, "0.1.0", mdd_mod_init, mdd_mod_exit);