X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdd%2Fmdd_device.c;h=6129e110e4586a99a915be08e6c161235299e400;hb=36e5b7203d5f80b5ac1341a05a35c19915c05bd6;hp=07b606d90a4f0e80a6a60ebddd07785c0a2c14c6;hpb=a44f229bcfd8636517460788753070f8af2b0ebf;p=fs%2Flustre-release.git diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 07b606d..6129e11 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2013, Intel Corporation. + * Copyright (c) 2011, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -43,6 +43,7 @@ #define DEBUG_SUBSYSTEM S_MDS #include +#include #include #include #include @@ -119,14 +120,26 @@ out: static int mdd_init0(const struct lu_env *env, struct mdd_device *mdd, struct lu_device_type *t, struct lustre_cfg *lcfg) { - int rc; + int rc = -EINVAL; + const char *dev; ENTRY; + /* LU-8040 Set defaults here, before values configs */ + mdd->mdd_cl.mc_flags = 0; /* off by default */ + mdd->mdd_cl.mc_mask = CHANGELOG_DEFMASK; + + dev = lustre_cfg_string(lcfg, 0); + if (dev == NULL) + RETURN(rc); + + mdd->mdd_md_dev.md_lu_dev.ld_obd = class_name2obd(dev); + if (mdd->mdd_md_dev.md_lu_dev.ld_obd == NULL) + RETURN(rc); mdd->mdd_md_dev.md_lu_dev.ld_ops = &mdd_lu_ops; mdd->mdd_md_dev.md_ops = &mdd_ops; rc = mdd_connect_to_next(env, mdd, lustre_cfg_string(lcfg, 3)); - if (rc) + if (rc != 0) RETURN(rc); mdd->mdd_atime_diff = MAX_ATIME_DIFF; @@ -148,17 +161,12 @@ static int mdd_init0(const struct lu_env *env, struct mdd_device *mdd, static struct lu_device *mdd_device_fini(const struct lu_env *env, struct lu_device *d) { - struct mdd_device *mdd = lu2mdd_dev(d); - int rc; + struct mdd_device *mdd = lu2mdd_dev(d); if (d->ld_site) lu_dev_del_linkage(d->ld_site, d); - rc = mdd_procfs_fini(mdd); - if (rc) { - CERROR("proc fini error %d \n", rc); - return ERR_PTR(rc); - } + mdd_procfs_fini(mdd); return NULL; } @@ -175,7 +183,7 @@ static int changelog_init_cb(const struct lu_env *env, struct llog_handle *llh, "seeing record at index %d/%d/"LPU64" t=%x %.*s in log" DOSTID"\n", hdr->lrh_index, rec->cr_hdr.lrh_index, rec->cr.cr_index, rec->cr.cr_type, rec->cr.cr_namelen, - rec->cr.cr_name, POSTID(&llh->lgh_id.lgl_oi)); + changelog_rec_name(&rec->cr), POSTID(&llh->lgh_id.lgl_oi)); mdd->mdd_cl.mc_index = rec->cr.cr_index; return LLOG_PROC_BREAK; @@ -262,7 +270,48 @@ static int llog_changelog_cancel(const struct lu_env *env, static struct llog_operations changelog_orig_logops; static int -mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on); +mdd_changelog_write_header(const struct lu_env *env, struct mdd_device *mdd, + int markerflags); + +static int +mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd) +{ + int rc = 0; + + if ((mdd->mdd_cl.mc_flags & CLM_ON) != 0) + return rc; + + LCONSOLE_INFO("%s: changelog on\n", mdd2obd_dev(mdd)->obd_name); + if (mdd->mdd_cl.mc_flags & CLM_ERR) { + CERROR("Changelogs cannot be enabled due to error " + "condition (see %s log).\n", + mdd2obd_dev(mdd)->obd_name); + rc = -ESRCH; + } else { + spin_lock(&mdd->mdd_cl.mc_lock); + mdd->mdd_cl.mc_flags |= CLM_ON; + spin_unlock(&mdd->mdd_cl.mc_lock); + rc = mdd_changelog_write_header(env, mdd, CLM_START); + } + return rc; +} + +static int +mdd_changelog_off(const struct lu_env *env, struct mdd_device *mdd) +{ + int rc = 0; + + if ((mdd->mdd_cl.mc_flags & CLM_ON) != CLM_ON) + return rc; + + LCONSOLE_INFO("%s: changelog off\n", mdd2obd_dev(mdd)->obd_name); + rc = mdd_changelog_write_header(env, mdd, CLM_FINI); + spin_lock(&mdd->mdd_cl.mc_lock); + mdd->mdd_cl.mc_flags &= ~CLM_ON; + spin_unlock(&mdd->mdd_cl.mc_lock); + + return rc; +} static int mdd_changelog_llog_init(const struct lu_env *env, struct mdd_device *mdd) @@ -295,7 +344,7 @@ static int mdd_changelog_llog_init(const struct lu_env *env, if (rc) GOTO(out_cleanup, rc); - rc = llog_cat_init_and_process(env, ctxt->loc_handle); + rc = llog_init_handle(env, ctxt->loc_handle, LLOG_F_IS_CAT, NULL); if (rc) GOTO(out_close, rc); @@ -331,7 +380,7 @@ static int mdd_changelog_llog_init(const struct lu_env *env, uctxt->loc_handle->lgh_logops->lop_add = llog_cat_add_rec; uctxt->loc_handle->lgh_logops->lop_declare_add = llog_cat_declare_add_rec; - rc = llog_cat_init_and_process(env, uctxt->loc_handle); + rc = llog_init_handle(env, uctxt->loc_handle, LLOG_F_IS_CAT, NULL); if (rc) GOTO(out_uclose, rc); @@ -345,7 +394,7 @@ static int mdd_changelog_llog_init(const struct lu_env *env, /* If we have registered users, assume we want changelogs on */ if (mdd->mdd_cl.mc_lastuser > 0) { - rc = mdd_changelog_on(env, mdd, 1); + rc = mdd_changelog_on(env, mdd); if (rc < 0) GOTO(out_uclose, rc); } @@ -371,8 +420,6 @@ static int mdd_changelog_init(const struct lu_env *env, struct mdd_device *mdd) mdd->mdd_cl.mc_index = 0; spin_lock_init(&mdd->mdd_cl.mc_lock); mdd->mdd_cl.mc_starttime = cfs_time_current_64(); - mdd->mdd_cl.mc_flags = 0; /* off by default */ - mdd->mdd_cl.mc_mask = CHANGELOG_DEFMASK; spin_lock_init(&mdd->mdd_cl.mc_user_lock); mdd->mdd_cl.mc_lastuser = 0; @@ -406,39 +453,6 @@ static void mdd_changelog_fini(const struct lu_env *env, } } -static int -mdd_changelog_write_header(const struct lu_env *env, struct mdd_device *mdd, - int markerflags); - -/* Start / stop recording */ -static int -mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on) -{ - int rc = 0; - - if ((on == 1) && ((mdd->mdd_cl.mc_flags & CLM_ON) == 0)) { - LCONSOLE_INFO("%s: changelog on\n", mdd2obd_dev(mdd)->obd_name); - if (mdd->mdd_cl.mc_flags & CLM_ERR) { - CERROR("Changelogs cannot be enabled due to error " - "condition (see %s log).\n", - mdd2obd_dev(mdd)->obd_name); - rc = -ESRCH; - } else { - spin_lock(&mdd->mdd_cl.mc_lock); - mdd->mdd_cl.mc_flags |= CLM_ON; - spin_unlock(&mdd->mdd_cl.mc_lock); - rc = mdd_changelog_write_header(env, mdd, CLM_START); - } - } else if ((on == 0) && ((mdd->mdd_cl.mc_flags & CLM_ON) == CLM_ON)) { - LCONSOLE_INFO("%s: changelog off\n",mdd2obd_dev(mdd)->obd_name); - rc = mdd_changelog_write_header(env, mdd, CLM_FINI); - spin_lock(&mdd->mdd_cl.mc_lock); - mdd->mdd_cl.mc_flags &= ~CLM_ON; - spin_unlock(&mdd->mdd_cl.mc_lock); - } - return rc; -} - /** Remove entries with indicies up to and including \a endrec from the * changelog * \param mdd @@ -522,10 +536,11 @@ int mdd_changelog_write_header(const struct lu_env *env, rec->cr.cr_flags = CLF_VERSION; rec->cr.cr_type = CL_MARK; rec->cr.cr_namelen = len; - memcpy(rec->cr.cr_name, obd->obd_name, rec->cr.cr_namelen); + memcpy(changelog_rec_name(&rec->cr), obd->obd_name, rec->cr.cr_namelen); /* Status and action flags */ rec->cr.cr_markerflags = mdd->mdd_cl.mc_flags | markerflags; - rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen); + rec->cr_hdr.lrh_len = llog_data_len(changelog_rec_size(&rec->cr) + + rec->cr.cr_namelen); rec->cr_hdr.lrh_type = CHANGELOG_REC; rec->cr.cr_time = cl_time(); spin_lock(&mdd->mdd_cl.mc_lock); @@ -535,7 +550,7 @@ int mdd_changelog_write_header(const struct lu_env *env, ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT); LASSERT(ctxt); - rc = llog_cat_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, NULL); + rc = llog_cat_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL); if (rc > 0) rc = 0; llog_ctxt_put(ctxt); @@ -582,8 +597,6 @@ static int obf_lookup(const struct lu_env *env, struct md_object *p, /* Check if object with this fid exists */ child = mdd_object_find(env, mdd, f); - if (child == NULL) - GOTO(out, rc = 0); if (IS_ERR(child)) GOTO(out, rc = PTR_ERR(child)); @@ -825,7 +838,7 @@ static int mdd_hsm_actions_llog_init(const struct lu_env *env, GOTO(out_cleanup, rc); } - rc = llog_cat_init_and_process(env, ctxt->loc_handle); + rc = llog_init_handle(env, ctxt->loc_handle, LLOG_F_IS_CAT, NULL); if (rc) GOTO(out_close, rc); @@ -864,6 +877,7 @@ static int mdd_hsm_actions_llog_fini(const struct lu_env *env, static void mdd_device_shutdown(const struct lu_env *env, struct mdd_device *m, struct lustre_cfg *cfg) { + mdd_generic_thread_stop(&m->mdd_orph_cleanup_thread); lfsck_degister(env, m->mdd_bottom); mdd_hsm_actions_llog_fini(env, m); mdd_changelog_fini(env, m); @@ -889,16 +903,15 @@ static int mdd_process_config(const struct lu_env *env, ENTRY; switch (cfg->lcfg_command) { - case LCFG_PARAM: { - struct lprocfs_static_vars lvars; - - lprocfs_mdd_init_vars(&lvars); - rc = class_process_proc_param(PARAM_MDD, lvars.obd_vars, cfg,m); - if (rc > 0 || rc == -ENOSYS) - /* we don't understand; pass it on */ - rc = next->ld_ops->ldo_process_config(env, next, cfg); - break; - } + case LCFG_PARAM: { + struct obd_device *obd = mdd2obd_dev(m); + + rc = class_process_proc_param(PARAM_MDD, obd->obd_vars, cfg, m); + if (rc > 0 || rc == -ENOSYS) + /* we don't understand; pass it on */ + rc = next->ld_ops->ldo_process_config(env, next, cfg); + break; + } case LCFG_SETUP: rc = next->ld_ops->ldo_process_config(env, next, cfg); if (rc) @@ -930,18 +943,18 @@ static int mdd_recovery_complete(const struct lu_env *env, next = &mdd->mdd_child->dd_lu_dev; /* XXX: orphans handling. */ - __mdd_orphan_cleanup(env, mdd); + mdd_orphan_cleanup(env, mdd); rc = next->ld_ops->ldo_recovery_complete(env, next); RETURN(rc); } int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd, - const struct lu_fid *pfid, const char *name, __u32 mode, - struct lu_fid *fid) + const struct lu_fid *pfid, const char *name, + __u32 mode, struct lu_fid *fid) { - struct dt_object *parent, *dto; - int rc; + struct dt_object *parent, *dto; + int rc; ENTRY; @@ -1022,10 +1035,6 @@ static int mdd_prepare(const struct lu_env *env, mdd2obd_dev(mdd)->obd_name, rc); GOTO(out_los, rc); } - - rc = mdd_compat_fixes(env, mdd); - if (rc != 0) - GOTO(out_dot, rc); } else { /* Normal client usually send root access to MDT0 directly, * the root FID on non-MDT0 will only be used by echo client. */ @@ -1107,24 +1116,6 @@ static int mdd_statfs(const struct lu_env *env, struct md_device *m, RETURN(rc); } -/* - * No permission check is needed. - */ -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); - int rc; - ENTRY; - - /* need barrier for mds_capa_keys access. */ - - rc = mdd_child_ops(mdd)->dt_init_capa_ctxt(env, mdd->mdd_child, mode, - timeout, alg, keys); - RETURN(rc); -} - static int mdd_maxeasize_get(const struct lu_env *env, struct md_device *m, int *easize) { @@ -1136,14 +1127,6 @@ static int mdd_maxeasize_get(const struct lu_env *env, struct md_device *m, RETURN(0); } -static int mdd_update_capa_key(const struct lu_env *env, - struct md_device *m, - struct lustre_capa_key *key) -{ - /* we do not support capabilities ... */ - return -EINVAL; -} - static int mdd_llog_ctxt_get(const struct lu_env *env, struct md_device *m, int idx, void **h) { @@ -1240,8 +1223,7 @@ static int mdd_obd_disconnect(struct obd_export *exp) } static int mdd_obd_get_info(const struct lu_env *env, struct obd_export *exp, - __u32 keylen, void *key, __u32 *vallen, void *val, - struct lov_stripe_md *lsm) + __u32 keylen, void *key, __u32 *vallen, void *val) { int rc = -EINVAL; @@ -1255,18 +1237,39 @@ static int mdd_obd_get_info(const struct lu_env *env, struct obd_export *exp, mdd = lu2mdd_dev(obd->obd_lu_dev); LASSERT(mdd); rc = obd_get_info(env, mdd->mdd_child_exp, keylen, key, vallen, - val, lsm); + val); RETURN(rc); } RETURN(rc); } +static int mdd_obd_set_info_async(const struct lu_env *env, + struct obd_export *exp, + __u32 keylen, void *key, + __u32 vallen, void *val, + struct ptlrpc_request_set *set) +{ + struct obd_device *obd = exp->exp_obd; + struct mdd_device *mdd; + int rc; + + if (!obd->obd_set_up || obd->obd_stopping) + RETURN(-EAGAIN); + + mdd = lu2mdd_dev(obd->obd_lu_dev); + LASSERT(mdd); + rc = obd_set_info_async(env, mdd->mdd_child_exp, keylen, key, + vallen, val, set); + RETURN(rc); +} + static struct obd_ops mdd_obd_device_ops = { .o_owner = THIS_MODULE, .o_connect = mdd_obd_connect, .o_disconnect = mdd_obd_disconnect, .o_get_info = mdd_obd_get_info, + .o_set_info_async = mdd_obd_set_info_async, }; static int mdd_changelog_user_register(const struct lu_env *env, @@ -1288,10 +1291,10 @@ static int mdd_changelog_user_register(const struct lu_env *env, RETURN(-ENOMEM); } - /* Assume we want it on since somebody registered */ - rc = mdd_changelog_on(env, mdd, 1); - if (rc) - GOTO(out, rc); + /* Assume we want it on since somebody registered */ + rc = mdd_changelog_on(env, mdd); + if (rc) + GOTO(out, rc); rec->cur_hdr.lrh_len = sizeof(*rec); rec->cur_hdr.lrh_type = CHANGELOG_USER_REC; @@ -1305,7 +1308,7 @@ static int mdd_changelog_user_register(const struct lu_env *env, rec->cur_endrec = mdd->mdd_cl.mc_index; spin_unlock(&mdd->mdd_cl.mc_user_lock); - rc = llog_cat_add(env, ctxt->loc_handle, &rec->cur_hdr, NULL, NULL); + rc = llog_cat_add(env, ctxt->loc_handle, &rec->cur_hdr, NULL); CDEBUG(D_IOCTL, "Registered changelog user %d\n", *id); out: @@ -1380,10 +1383,7 @@ static int mdd_changelog_user_purge_cb(const struct lu_env *env, CDEBUG(D_IOCTL, "Rewriting changelog user %d endrec to "LPU64"\n", mcud->mcud_id, rec->cur_endrec); - /* hdr+1 is loc of data */ - hdr->lrh_len -= sizeof(*hdr) + sizeof(struct llog_rec_tail); - rc = llog_write(env, llh, hdr, NULL, 0, (void *)(hdr + 1), - hdr->lrh_index); + rc = llog_write(env, llh, hdr, hdr->lrh_index); RETURN(rc); } @@ -1441,11 +1441,11 @@ static int mdd_changelog_user_purge(const struct lu_env *env, rc = -ENOENT; } - if (!rc && data.mcud_usercount == 0) - /* No more users; turn changelogs off */ - rc = mdd_changelog_on(env, mdd, 0); + if (!rc && data.mcud_usercount == 0) + /* No more users; turn changelogs off */ + rc = mdd_changelog_off(env, mdd); - RETURN (rc); + RETURN(rc); } /** mdd_iocontrol @@ -1489,7 +1489,12 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, (struct lfsck_stop *)karg); RETURN(rc); } - } + case OBD_IOC_QUERY_LFSCK: { + rc = lfsck_query(env, mdd->mdd_bottom, NULL, NULL, + (struct lfsck_query *)karg); + RETURN(rc); + } + } /* Below ioctls use obd_ioctl_data */ if (len != sizeof(*data)) { @@ -1523,8 +1528,6 @@ LU_TYPE_INIT_FINI(mdd, &mdd_thread_key); static const struct md_device_operations mdd_ops = { .mdo_statfs = mdd_statfs, .mdo_root_get = mdd_root_get, - .mdo_init_capa_ctxt = mdd_init_capa_ctxt, - .mdo_update_capa_key= mdd_update_capa_key, .mdo_llog_ctxt_get = mdd_llog_ctxt_get, .mdo_iocontrol = mdd_iocontrol, .mdo_maxeasize_get = mdd_maxeasize_get, @@ -1567,12 +1570,38 @@ static void mdd_key_fini(const struct lu_context *ctx, /* context key: mdd_thread_key */ LU_CONTEXT_KEY_DEFINE(mdd, LCT_MD_THREAD); -static int __init mdd_mod_init(void) +int mdd_generic_thread_start(struct mdd_generic_thread *thread, + int (*func)(void *), void *data, char *name) { - struct lprocfs_static_vars lvars; - int rc; + struct task_struct *task; + + LASSERT(thread->mgt_init == false); + init_completion(&thread->mgt_started); + init_completion(&thread->mgt_finished); + thread->mgt_data = data; + thread->mgt_abort = false; + thread->mgt_init = true; + + task = kthread_run(func, thread, name); + if (IS_ERR(task)) { + complete(&thread->mgt_finished); + return PTR_ERR(task); + } + wait_for_completion(&thread->mgt_started); + return 0; +} - lprocfs_mdd_init_vars(&lvars); +void mdd_generic_thread_stop(struct mdd_generic_thread *thread) +{ + if (thread->mgt_init == true) { + thread->mgt_abort = true; + wait_for_completion(&thread->mgt_finished); + } +} + +static int __init mdd_init(void) +{ + int rc; rc = lu_kmem_init(mdd_caches); if (rc) @@ -1588,23 +1617,22 @@ static int __init mdd_mod_init(void) hsm_actions_logops.lop_declare_add = llog_cat_declare_add_rec; rc = class_register_type(&mdd_obd_device_ops, NULL, true, NULL, -#ifndef HAVE_ONLY_PROCFS_SEQ - lvars.module_vars, -#endif LUSTRE_MDD_NAME, &mdd_device_type); if (rc) lu_kmem_fini(mdd_caches); return rc; } -static void __exit mdd_mod_exit(void) +static void __exit mdd_exit(void) { class_unregister_type(LUSTRE_MDD_NAME); lu_kmem_fini(mdd_caches); } -MODULE_AUTHOR("Sun Microsystems, Inc. "); -MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD_NAME")"); +MODULE_AUTHOR("OpenSFS, Inc. "); +MODULE_DESCRIPTION("Lustre Meta-data Device Driver ("LUSTRE_MDD_NAME")"); +MODULE_VERSION(LUSTRE_VERSION_STRING); MODULE_LICENSE("GPL"); -cfs_module(mdd, "0.1.0", mdd_mod_init, mdd_mod_exit); +module_init(mdd_init); +module_exit(mdd_exit);