Whamcloud - gitweb
LU-81 deadlock of changelog adding vs. changelog cancelling
[fs/lustre-release.git] / lustre / mdd / mdd_device.c
index 388780e..2747214 100644 (file)
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
@@ -90,7 +93,7 @@ static int mdd_device_init(const struct lu_env *env, struct lu_device *d,
         /* 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_txn_commit = NULL;
         mdd->mdd_txn_cb.dtc_cookie = mdd;
         mdd->mdd_txn_cb.dtc_tag = LCT_MD_THREAD;
         CFS_INIT_LIST_HEAD(&mdd->mdd_txn_cb.dtc_linkage);
@@ -241,7 +244,6 @@ static int mdd_changelog_init(const struct lu_env *env, struct mdd_device *mdd)
 
         mdd->mdd_cl.mc_index = 0;
         cfs_spin_lock_init(&mdd->mdd_cl.mc_lock);
-        cfs_waitq_init(&mdd->mdd_cl.mc_waitq);
         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;
@@ -312,9 +314,6 @@ int mdd_changelog_llog_write(struct mdd_device         *mdd,
         struct llog_ctxt *ctxt;
         int rc;
 
-        if ((mdd->mdd_cl.mc_mask & (1 << rec->cr.cr_type)) == 0)
-                return 0;
-
         rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
         /* llog_lvfs_write_rec sets the llog tail len */
         rec->cr_hdr.lrh_type = CHANGELOG_REC;
@@ -333,8 +332,6 @@ int mdd_changelog_llog_write(struct mdd_device         *mdd,
         rc = llog_add(ctxt, &rec->cr_hdr, NULL, NULL, 0);
         llog_ctxt_put(ctxt);
 
-        cfs_waitq_signal(&mdd->mdd_cl.mc_waitq);
-
         return rc;
 }
 
@@ -412,7 +409,8 @@ int mdd_changelog_write_header(struct mdd_device *mdd, int markerflags)
         /* Status and action flags */
         rec->cr.cr_markerflags = mdd->mdd_cl.mc_flags | markerflags;
 
-        rc = mdd_changelog_llog_write(mdd, rec, NULL);
+        rc = (mdd->mdd_cl.mc_mask & (1 << CL_MARK)) ?
+                mdd_changelog_llog_write(mdd, rec, NULL) : 0;
 
         /* assume on or off event; reset repeat-access time */
         mdd->mdd_cl.mc_starttime = cfs_time_current_64();
@@ -544,7 +542,7 @@ static int dot_lustre_mdd_open(const struct lu_env *env, struct md_object *obj,
 }
 
 static int dot_lustre_mdd_close(const struct lu_env *env, struct md_object *obj,
-                                struct md_attr *ma)
+                                struct md_attr *ma, int mode)
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
 
@@ -580,6 +578,18 @@ static int dot_lustre_mdd_path(const struct lu_env *env, struct md_object *obj,
         return -ENOSYS;
 }
 
+static int dot_file_lock(const struct lu_env *env, struct md_object *obj,
+                         struct lov_mds_md *lmm, struct ldlm_extent *extent,
+                         struct lustre_handle *lockh)
+{
+        return -ENOSYS;
+}
+
+static int dot_file_unlock(const struct lu_env *env, struct md_object *obj,
+                           struct lov_mds_md *lmm, struct lustre_handle *lockh)
+{
+        return -ENOSYS;
+}
 
 static struct md_object_operations mdd_dot_lustre_obj_ops = {
         .moo_permission    = dot_lustre_mdd_permission,
@@ -601,6 +611,8 @@ static struct md_object_operations mdd_dot_lustre_obj_ops = {
         .moo_version_get   = dot_lustre_mdd_version_get,
         .moo_version_set   = dot_lustre_mdd_version_set,
         .moo_path          = dot_lustre_mdd_path,
+        .moo_file_lock     = dot_file_lock,
+        .moo_file_unlock   = dot_file_unlock,
 };
 
 
@@ -744,9 +756,9 @@ static int obf_attr_get(const struct lu_env *env, struct md_object *obj,
                         return 0;
 
                 if (ma->ma_need & MA_LOV_DEF) {
-                        rc = mdd_get_default_md(mdd_obj, ma->ma_lmm,
-                                                &ma->ma_lmm_size);
+                        rc = mdd_get_default_md(mdd_obj, ma->ma_lmm);
                         if (rc > 0) {
+                                ma->ma_lmm_size = rc;
                                 ma->ma_valid |= MA_LOV;
                                 rc = 0;
                         }
@@ -782,7 +794,7 @@ static int obf_mdd_open(const struct lu_env *env, struct md_object *obj,
 }
 
 static int obf_mdd_close(const struct lu_env *env, struct md_object *obj,
-                         struct md_attr *ma)
+                         struct md_attr *ma, int mode)
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
 
@@ -1010,7 +1022,7 @@ static int mdd_lov_set_nextid(const struct lu_env *env,
         ENTRY;
 
         LASSERT(mds->mds_lov_objids != NULL);
-        rc = obd_set_info_async(mds->mds_osc_exp, strlen(KEY_NEXT_ID),
+        rc = obd_set_info_async(mds->mds_lov_exp, strlen(KEY_NEXT_ID),
                                 KEY_NEXT_ID, mds->mds_lov_desc.ld_tgt_count,
                                 mds->mds_lov_objids, NULL);
 
@@ -1054,11 +1066,13 @@ static int mdd_recovery_complete(const struct lu_env *env,
         }
 #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(obd->u.mds.mds_lov_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 */
+        cfs_spin_lock(&obd->obd_dev_lock);
         obd->obd_recovering = 0;
+        cfs_spin_unlock(&obd->obd_dev_lock);
         obd->obd_type->typ_dt_ops->o_postrecov(obd);
 
         /* XXX: orphans handling. */
@@ -1181,7 +1195,7 @@ static int mdd_update_capa_key(const struct lu_env *env,
 {
         struct mds_capa_info info = { .uuid = NULL, .capa = key };
         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
-        struct obd_export *lov_exp = mdd2obd_dev(mdd)->u.mds.mds_osc_exp;
+        struct obd_export *lov_exp = mdd2obd_dev(mdd)->u.mds.mds_lov_exp;
         int rc;
         ENTRY;
 
@@ -1343,6 +1357,8 @@ struct mdd_changelog_user_data {
         __u32 mcud_minid;  /**< user id with lowest rec reference */
         __u32 mcud_usercount;
         int   mcud_found:1;
+        struct mdd_device   *mcud_mdd;
+        const struct lu_env *mcud_env;
 };
 #define MCUD_UNREGISTER -1LL
 
@@ -1385,12 +1401,28 @@ static int mdd_changelog_user_purge_cb(struct llog_handle *llh,
         /* Special case: unregister this user */
         if (mcud->mcud_endrec == MCUD_UNREGISTER) {
                 struct llog_cookie cookie;
+                void *trans_h;
+                struct mdd_device *mdd = mcud->mcud_mdd;
+
                 cookie.lgc_lgl = llh->lgh_id;
                 cookie.lgc_index = hdr->lrh_index;
+
+                /* XXX This is a workaround for the deadlock of changelog
+                 * adding vs. changelog cancelling. LU-81. */
+                mdd_txn_param_build(mcud->mcud_env, mdd, MDD_TXN_UNLINK_OP, 0);
+                trans_h = mdd_trans_start(mcud->mcud_env, mdd);
+                if (IS_ERR(trans_h)) {
+                        CERROR("fsfilt_start_log failed: %ld\n",
+                               PTR_ERR(trans_h));
+                        RETURN(PTR_ERR(trans_h));
+                }
+
                 rc = llog_cat_cancel_records(llh->u.phd.phd_cat_handle,
                                              1, &cookie);
                 if (rc == 0)
                         mcud->mcud_usercount--;
+
+                mdd_trans_stop(mcud->mcud_env, mdd, rc, trans_h);
                 RETURN(rc);
         }
 
@@ -1406,7 +1438,8 @@ static int mdd_changelog_user_purge_cb(struct llog_handle *llh,
         RETURN(rc);
 }
 
-static int mdd_changelog_user_purge(struct mdd_device *mdd, int id,
+static int mdd_changelog_user_purge(const struct lu_env *env,
+                                    struct mdd_device *mdd, int id,
                                     long long endrec)
 {
         struct mdd_changelog_user_data data;
@@ -1421,6 +1454,8 @@ static int mdd_changelog_user_purge(struct mdd_device *mdd, int id,
         data.mcud_minrec = 0;
         data.mcud_usercount = 0;
         data.mcud_endrec = endrec;
+        data.mcud_mdd = mdd;
+        data.mcud_env = env;
         cfs_spin_lock(&mdd->mdd_cl.mc_lock);
         endrec = mdd->mdd_cl.mc_index;
         cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
@@ -1481,11 +1516,19 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
         mdd = lu2mdd_dev(&m->md_lu_dev);
 
         /* Doesn't use obd_ioctl_data */
-        if (cmd == OBD_IOC_CHANGELOG_CLEAR) {
+        switch (cmd) {
+        case OBD_IOC_CHANGELOG_CLEAR: {
                 struct changelog_setinfo *cs = karg;
-                rc = mdd_changelog_user_purge(mdd, cs->cs_id, cs->cs_recno);
+                rc = mdd_changelog_user_purge(env, mdd, cs->cs_id,
+                                              cs->cs_recno);
                 RETURN(rc);
         }
+        case OBD_IOC_GET_MNTOPT: {
+                mntopt_t *mntopts = (mntopt_t *)karg;
+                *mntopts = mdd->mdd_dt_conf.ddp_mntopts;
+                RETURN(0);
+        }
+        }
 
         /* Below ioctls use obd_ioctl_data */
         if (len != sizeof(*data)) {
@@ -1503,11 +1546,11 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
                 rc = mdd_changelog_user_register(mdd, &data->ioc_u32_1);
                 break;
         case OBD_IOC_CHANGELOG_DEREG:
-                rc = mdd_changelog_user_purge(mdd, data->ioc_u32_1,
+                rc = mdd_changelog_user_purge(env, mdd, data->ioc_u32_1,
                                               MCUD_UNREGISTER);
                 break;
         default:
-                rc = -EOPNOTSUPP;
+                rc = -ENOTTY;
         }
 
         RETURN (rc);