* 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/
#define DEBUG_SUBSYSTEM S_MDS
#include <linux/module.h>
+#include <linux/kthread.h>
#include <obd_class.h>
#include <lustre_ioctl.h>
#include <lustre_mds.h>
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;
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;
}
"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;
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)
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);
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);
/* 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);
}
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;
}
}
-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
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);
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);
/* 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));
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);
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);
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)
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;
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. */
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)
{
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)
{
}
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;
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,
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;
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:
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);
}
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
(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)) {
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,
/* 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)
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. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD_NAME")");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
+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);