Whamcloud - gitweb
LU-2349 osp: Move log ops init to module init.
[fs/lustre-release.git] / lustre / mdd / mdd_device.c
index 416d6e5..104d2b5 100644 (file)
@@ -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, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -221,11 +221,11 @@ static int changelog_user_init_cb(const struct lu_env *env,
                " in log "LPX64"\n", hdr->lrh_index, rec->cur_hdr.lrh_index,
                rec->cur_id, rec->cur_endrec, llh->lgh_id.lgl_oid);
 
-        cfs_spin_lock(&mdd->mdd_cl.mc_user_lock);
-        mdd->mdd_cl.mc_lastuser = rec->cur_id;
-        cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
+       spin_lock(&mdd->mdd_cl.mc_user_lock);
+       mdd->mdd_cl.mc_lastuser = rec->cur_id;
+       spin_unlock(&mdd->mdd_cl.mc_user_lock);
 
-        return LLOG_PROC_BREAK;
+       return LLOG_PROC_BREAK;
 }
 
 static int llog_changelog_cancel_cb(const struct lu_env *env,
@@ -301,8 +301,6 @@ static int mdd_changelog_llog_init(const struct lu_env *env,
        if (rc)
                RETURN(-ENODEV);
 
-       changelog_orig_logops = llog_osd_ops;
-       changelog_orig_logops.lop_cancel = llog_changelog_cancel;
        rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CHANGELOG_ORIG_CTXT,
                        obd, &changelog_orig_logops);
        if (rc) {
@@ -319,10 +317,6 @@ static int mdd_changelog_llog_init(const struct lu_env *env,
        if (rc)
                GOTO(out_cleanup, rc);
 
-       ctxt->loc_handle->lgh_logops->lop_add = llog_cat_add_rec;
-       ctxt->loc_handle->lgh_logops->lop_declare_add =
-                                       llog_cat_declare_add_rec;
-
        rc = llog_cat_init_and_process(env, ctxt->loc_handle);
        if (rc)
                GOTO(out_close, rc);
@@ -397,11 +391,11 @@ static int mdd_changelog_init(const struct lu_env *env, struct mdd_device *mdd)
        int                      rc;
 
        mdd->mdd_cl.mc_index = 0;
-       cfs_spin_lock_init(&mdd->mdd_cl.mc_lock);
+       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;
-       cfs_spin_lock_init(&mdd->mdd_cl.mc_user_lock);
+       spin_lock_init(&mdd->mdd_cl.mc_user_lock);
        mdd->mdd_cl.mc_lastuser = 0;
 
        rc = mdd_changelog_llog_init(env, mdd);
@@ -450,19 +444,19 @@ int mdd_changelog_on(const struct lu_env *env, struct mdd_device *mdd, int on)
                                mdd2obd_dev(mdd)->obd_name);
                         rc = -ESRCH;
                 } else {
-                        cfs_spin_lock(&mdd->mdd_cl.mc_lock);
-                        mdd->mdd_cl.mc_flags |= CLM_ON;
-                        cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+                       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);
+               }
+       } 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);
-                cfs_spin_lock(&mdd->mdd_cl.mc_lock);
-                mdd->mdd_cl.mc_flags &= ~CLM_ON;
-                cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
-        }
-        return rc;
+               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
@@ -483,9 +477,9 @@ int mdd_changelog_llog_cancel(const struct lu_env *env,
         if (ctxt == NULL)
                 return -ENXIO;
 
-        cfs_spin_lock(&mdd->mdd_cl.mc_lock);
-        cur = (long long)mdd->mdd_cl.mc_index;
-        cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+       spin_lock(&mdd->mdd_cl.mc_lock);
+       cur = (long long)mdd->mdd_cl.mc_index;
+       spin_unlock(&mdd->mdd_cl.mc_lock);
         if (endrec > cur)
                 endrec = cur;
 
@@ -553,9 +547,9 @@ int mdd_changelog_write_header(const struct lu_env *env,
        rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
        rec->cr_hdr.lrh_type = CHANGELOG_REC;
        rec->cr.cr_time = cl_time();
-       cfs_spin_lock(&mdd->mdd_cl.mc_lock);
+       spin_lock(&mdd->mdd_cl.mc_lock);
        rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
-       cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+       spin_unlock(&mdd->mdd_cl.mc_lock);
 
        ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
        LASSERT(ctxt);
@@ -637,6 +631,14 @@ static int dot_lustre_mdd_xattr_del(const struct lu_env *env,
         return -EPERM;
 }
 
+static int dot_lustre_mdd_swap_layouts(const struct lu_env *env,
+                                      struct md_object *obj1,
+                                      struct md_object *obj2,
+                                      __u64 flags)
+{
+       return -EPERM;
+}
+
 static int dot_lustre_mdd_readlink(const struct lu_env *env,
                                    struct md_object *obj, struct lu_buf *buf)
 {
@@ -715,25 +717,26 @@ static int dot_file_unlock(const struct lu_env *env, struct md_object *obj,
 }
 
 static struct md_object_operations mdd_dot_lustre_obj_ops = {
-        .moo_permission    = dot_lustre_mdd_permission,
-       .moo_attr_get      = mdd_attr_get,
-       .moo_attr_set      = mdd_attr_set,
-        .moo_xattr_get     = dot_lustre_mdd_xattr_get,
-        .moo_xattr_list    = dot_lustre_mdd_xattr_list,
-        .moo_xattr_set     = dot_lustre_mdd_xattr_set,
-        .moo_xattr_del     = dot_lustre_mdd_xattr_del,
-        .moo_readpage      = mdd_readpage,
-        .moo_readlink      = dot_lustre_mdd_readlink,
-        .moo_object_create = dot_lustre_mdd_object_create,
-        .moo_ref_add       = dot_lustre_mdd_ref_add,
-        .moo_ref_del       = dot_lustre_mdd_ref_del,
-        .moo_open          = dot_lustre_mdd_open,
-        .moo_close         = dot_lustre_mdd_close,
-        .moo_capa_get      = mdd_capa_get,
-        .moo_object_sync   = dot_lustre_mdd_object_sync,
-        .moo_path          = dot_lustre_mdd_path,
-        .moo_file_lock     = dot_file_lock,
-        .moo_file_unlock   = dot_file_unlock,
+       .moo_permission         = dot_lustre_mdd_permission,
+       .moo_attr_get           = mdd_attr_get,
+       .moo_attr_set           = mdd_attr_set,
+       .moo_xattr_get          = dot_lustre_mdd_xattr_get,
+       .moo_xattr_list         = dot_lustre_mdd_xattr_list,
+       .moo_xattr_set          = dot_lustre_mdd_xattr_set,
+       .moo_xattr_del          = dot_lustre_mdd_xattr_del,
+       .moo_swap_layouts       = dot_lustre_mdd_swap_layouts,
+       .moo_readpage           = mdd_readpage,
+       .moo_readlink           = dot_lustre_mdd_readlink,
+       .moo_object_create      = dot_lustre_mdd_object_create,
+       .moo_ref_add            = dot_lustre_mdd_ref_add,
+       .moo_ref_del            = dot_lustre_mdd_ref_del,
+       .moo_open               = dot_lustre_mdd_open,
+       .moo_close              = dot_lustre_mdd_close,
+       .moo_capa_get           = mdd_capa_get,
+       .moo_object_sync        = dot_lustre_mdd_object_sync,
+       .moo_path               = dot_lustre_mdd_path,
+       .moo_file_lock          = dot_file_lock,
+       .moo_file_unlock        = dot_file_unlock,
 };
 
 
@@ -1396,22 +1399,6 @@ static struct obd_ops mdd_obd_device_ops = {
        .o_health_check = mdd_obd_health_check
 };
 
-/* context key constructor/destructor: mdd_ucred_key_init, mdd_ucred_key_fini */
-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);
-
 /*
  * context key constructor/destructor:
  * mdd_capainfo_key_init, mdd_capainfo_key_fini
@@ -1459,15 +1446,15 @@ static int mdd_changelog_user_register(const struct lu_env *env,
 
         rec->cur_hdr.lrh_len = sizeof(*rec);
         rec->cur_hdr.lrh_type = CHANGELOG_USER_REC;
-        cfs_spin_lock(&mdd->mdd_cl.mc_user_lock);
-        if (mdd->mdd_cl.mc_lastuser == (unsigned int)(-1)) {
-                cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
-                CERROR("Maximum number of changelog users exceeded!\n");
-                GOTO(out, rc = -EOVERFLOW);
-        }
-        *id = rec->cur_id = ++mdd->mdd_cl.mc_lastuser;
-        rec->cur_endrec = mdd->mdd_cl.mc_index;
-        cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
+       spin_lock(&mdd->mdd_cl.mc_user_lock);
+       if (mdd->mdd_cl.mc_lastuser == (unsigned int)(-1)) {
+               spin_unlock(&mdd->mdd_cl.mc_user_lock);
+               CERROR("Maximum number of changelog users exceeded!\n");
+               GOTO(out, rc = -EOVERFLOW);
+       }
+       *id = rec->cur_id = ++mdd->mdd_cl.mc_lastuser;
+       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);
 
@@ -1568,9 +1555,9 @@ static int mdd_changelog_user_purge(const struct lu_env *env,
         data.mcud_minrec = 0;
         data.mcud_usercount = 0;
         data.mcud_endrec = endrec;
-        cfs_spin_lock(&mdd->mdd_cl.mc_lock);
-        endrec = mdd->mdd_cl.mc_index;
-        cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+       spin_lock(&mdd->mdd_cl.mc_lock);
+       endrec = mdd->mdd_cl.mc_index;
+       spin_unlock(&mdd->mdd_cl.mc_lock);
         if ((data.mcud_endrec == 0) ||
             ((data.mcud_endrec > endrec) &&
              (data.mcud_endrec != MCUD_UNREGISTER)))
@@ -1686,7 +1673,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, &mdd_ucred_key, &mdd_capainfo_key);
+LU_TYPE_INIT_FINI(mdd, &mdd_thread_key, &mdd_capainfo_key);
 
 const struct md_device_operations mdd_ops = {
         .mdo_statfs         = mdd_statfs,
@@ -1773,6 +1760,11 @@ static int __init mdd_mod_init(void)
        if (rc)
                return rc;
 
+       changelog_orig_logops = llog_osd_ops;
+       changelog_orig_logops.lop_cancel = llog_changelog_cancel;
+       changelog_orig_logops.lop_add = llog_cat_add_rec;
+       changelog_orig_logops.lop_declare_add = llog_cat_declare_add_rec;
+
        llo_local_obj_register(&llod_capa_key);
        llo_local_obj_register(&llod_mdd_orphan);
        llo_local_obj_register(&llod_mdd_root);