Whamcloud - gitweb
LU-3319 procfs: move mdd/ofd proc handling to seq_files
[fs/lustre-release.git] / lustre / mdd / mdd_device.c
index 80ff70e..d55f358 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <linux/module.h>
 #include <obd_class.h>
+#include <lustre_ioctl.h>
 #include <lustre_mds.h>
 #include <obd_support.h>
 #include <lu_object.h>
@@ -52,7 +53,7 @@
 
 #include "mdd_internal.h"
 
-const struct md_device_operations mdd_ops;
+static const struct md_device_operations mdd_ops;
 static struct lu_device_type mdd_device_type;
 
 static const char mdd_root_dir_name[] = "ROOT";
@@ -147,17 +148,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;
 }
 
@@ -235,7 +231,6 @@ static int llog_changelog_cancel_cb(const struct lu_env *env,
 
 static int llog_changelog_cancel(const struct lu_env *env,
                                 struct llog_ctxt *ctxt,
-                                struct lov_stripe_md *lsm, int count,
                                 struct llog_cookie *cookies, int flags)
 {
        struct llog_handle      *cathandle = ctxt->loc_handle;
@@ -261,7 +256,8 @@ static int llog_changelog_cancel(const struct lu_env *env,
 
 static struct llog_operations changelog_orig_logops;
 
-int mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on);
+static int
+mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on);
 
 static int mdd_changelog_llog_init(const struct lu_env *env,
                                   struct mdd_device *mdd)
@@ -405,11 +401,13 @@ static void mdd_changelog_fini(const struct lu_env *env,
        }
 }
 
-int mdd_changelog_write_header(const struct lu_env *env,
-                              struct mdd_device *mdd, int markerflags);
+static int
+mdd_changelog_write_header(const struct lu_env *env, struct mdd_device *mdd,
+                          int markerflags);
 
 /* Start / stop recording */
-int mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on)
+static int
+mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on)
 {
         int rc = 0;
 
@@ -442,8 +440,9 @@ int mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on)
  * \param endrec
  * \retval 0 ok
  */
-int mdd_changelog_llog_cancel(const struct lu_env *env,
-                             struct mdd_device *mdd, long long endrec)
+static int
+mdd_changelog_llog_cancel(const struct lu_env *env, struct mdd_device *mdd,
+                         long long endrec)
 {
         struct obd_device *obd = mdd2obd_dev(mdd);
         struct llog_ctxt *ctxt;
@@ -480,7 +479,7 @@ int mdd_changelog_llog_cancel(const struct lu_env *env,
            changed since the last purge) */
         mdd->mdd_cl.mc_starttime = cfs_time_current_64();
 
-       rc = llog_cancel(env, ctxt, NULL, 1, (struct llog_cookie *)&endrec, 0);
+       rc = llog_cancel(env, ctxt, (struct llog_cookie *)&endrec, 0);
 out:
         llog_ctxt_put(ctxt);
         return rc;
@@ -531,7 +530,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);
@@ -559,19 +558,20 @@ static int obf_lookup(const struct lu_env *env, struct md_object *p,
 
         sscanf(name, SFID, RFID(f));
         if (!fid_is_sane(f)) {
-               CWARN("%s: bad FID format [%s], should be "DFID"\n",
-                     mdd2obd_dev(mdd)->obd_name, lname->ln_name,
+               CWARN("%s: Trying to lookup invalid FID [%s] in %s/%s, FID "
+                     "format should be "DFID"\n", mdd2obd_dev(mdd)->obd_name,
+                     lname->ln_name, dot_lustre_name, mdd_obf_dir_name,
                      (__u64)FID_SEQ_NORMAL, 1, 0);
                 GOTO(out, rc = -EINVAL);
         }
 
        if (!fid_is_norm(f) && !fid_is_igif(f) && !fid_is_root(f) &&
            !fid_seq_is_dot(f->f_seq)) {
-               CWARN("%s: "DFID" is invalid, sequence should be "
-                     ">= "LPX64" or within ["LPX64","LPX64"].\n",
-                     mdd2obd_dev(mdd)->obd_name, PFID(f),
-                     (__u64)FID_SEQ_NORMAL, (__u64)FID_SEQ_IGIF,
-                     (__u64)FID_SEQ_IGIF_MAX);
+               CWARN("%s: Trying to lookup invalid FID "DFID" in %s/%s, "
+                     "sequence should be >= "LPX64" or within ["LPX64","
+                     ""LPX64"].\n", mdd2obd_dev(mdd)->obd_name, PFID(f),
+                     dot_lustre_name, mdd_obf_dir_name, (__u64)FID_SEQ_NORMAL,
+                     (__u64)FID_SEQ_IGIF, (__u64)FID_SEQ_IGIF_MAX);
                GOTO(out, rc = -EINVAL);
        }
 
@@ -859,13 +859,16 @@ 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);
        orph_index_fini(env, m);
        mdd_dot_lustre_cleanup(env, m);
-       if (m->mdd_los != NULL)
+       if (m->mdd_los != NULL) {
                local_oid_storage_fini(env, m->mdd_los);
+               m->mdd_los = NULL;
+       }
        lu_site_purge(env, mdd2lu_dev(m)->ld_site, ~0);
 
        if (m->mdd_child_exp)
@@ -882,16 +885,16 @@ 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_seq_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)
@@ -923,7 +926,7 @@ 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);
@@ -1298,7 +1301,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:
@@ -1373,10 +1376,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);
 }
@@ -1513,7 +1513,7 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
 /* type constructor/destructor: mdd_type_init, mdd_type_fini */
 LU_TYPE_INIT_FINI(mdd, &mdd_thread_key);
 
-const struct md_device_operations mdd_ops = {
+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,
@@ -1560,13 +1560,39 @@ static void mdd_key_fini(const struct lu_context *ctx,
 /* context key: mdd_thread_key */
 LU_CONTEXT_KEY_DEFINE(mdd, LCT_MD_THREAD);
 
+int mdd_generic_thread_start(struct mdd_generic_thread *thread,
+                            int (*func)(void *), void *data, char *name)
+{
+       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;
+}
+
+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_mod_init(void)
 {
-       struct lprocfs_static_vars lvars;
        int rc;
 
-       lprocfs_mdd_init_vars(&lvars);
-
        rc = lu_kmem_init(mdd_caches);
        if (rc)
                return rc;
@@ -1580,11 +1606,11 @@ static int __init mdd_mod_init(void)
        hsm_actions_logops.lop_add = llog_cat_add_rec;
        hsm_actions_logops.lop_declare_add = llog_cat_declare_add_rec;
 
-       rc = class_register_type(&mdd_obd_device_ops, NULL, NULL,
+       rc = class_register_type(&mdd_obd_device_ops, NULL, true, NULL,
 #ifndef HAVE_ONLY_PROCFS_SEQ
-                               lvars.module_vars,
+                                NULL,
 #endif
-                               LUSTRE_MDD_NAME, &mdd_device_type);
+                                LUSTRE_MDD_NAME, &mdd_device_type);
        if (rc)
                lu_kmem_fini(mdd_caches);
        return rc;