From: huanghua Date: Fri, 21 Jul 2006 09:14:09 +0000 (+0000) Subject: modified the mdt_object_unlock() interface: X-Git-Tag: v1_8_0_110~486^2~1363 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=2bde04f7d7df9b514400e0e28389cabac103b4b8;p=fs%2Flustre-release.git modified the mdt_object_unlock() interface: (1) add another parameter "int decref"; (1.1) if decref, call ldlm_lock_decref() to drop the lock; (1.2) else call ptlrpc_save_lock() to save to lock into request. (2) if some operation has transaction and success, we need to save the lock, otherwise, we just drop the lock. --- diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index aab9565..126a80e 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -424,7 +424,7 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, result = mdt_getattr_internal(info, child, ldlm_rep ? 0 : 1); if (result != 0) - mdt_object_unlock(info, child, lhc); + mdt_object_unlock(info, child, lhc, 1); } GOTO(out, result); } @@ -459,12 +459,12 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, /* finally, we can get attr for child. */ result = mdt_getattr_internal(info, child, ldlm_rep ? 0 : 1); if (result != 0) - mdt_object_unlock(info, child, lhc); + mdt_object_unlock(info, child, lhc, 1); mdt_object_put(info->mti_ctxt, child); EXIT; out_parent: - mdt_object_unlock(info, parent, lhp); + mdt_object_unlock(info, parent, lhp, 1); out: return result; } @@ -772,21 +772,26 @@ int fid_lock(struct ldlm_namespace *ns, const struct lu_fid *f, return rc == ELDLM_OK ? 0 : -EIO; } -void fid_unlock(struct ldlm_namespace *ns, const struct lu_fid *f, - struct lustre_handle *lh, ldlm_mode_t mode) +/* just call ldlm_lock_decref() if decref, + * else we only call ptlrpc_save_lock() to save this lock in req. + * when transaction committed, req will be released and lock will be released */ +void fid_unlock(struct ptlrpc_request *req, const struct lu_fid *f, + struct lustre_handle *lh, ldlm_mode_t mode, int decref) { - struct ldlm_lock *lock; - + { /* FIXME: this is debug stuff, remove it later. */ - lock = ldlm_handle2lock(lh); - if (!lock) { - CERROR("invalid lock handle "LPX64, lh->cookie); - LBUG(); + struct ldlm_lock *lock = ldlm_handle2lock(lh); + if (!lock) { + CERROR("invalid lock handle "LPX64, lh->cookie); + LBUG(); + } + LASSERT(fid_res_name_eq(f, &lock->l_resource->lr_name)); + LDLM_LOCK_PUT(lock); } - - LASSERT(fid_res_name_eq(f, &lock->l_resource->lr_name)); - - ldlm_lock_decref(lh, mode); + if (decref) + ldlm_lock_decref(lh, mode); + else + ptlrpc_save_lock(req, lh, mode); } static struct mdt_object *mdt_obj(struct lu_object *o) @@ -830,13 +835,14 @@ int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o, } void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o, - struct mdt_lock_handle *lh) + struct mdt_lock_handle *lh, int decref) { - struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace; + struct ptlrpc_request *req = mdt_info_req(info); ENTRY; if (lustre_handle_is_used(&lh->mlh_lh)) { - fid_unlock(ns, mdt_object_fid(o), &lh->mlh_lh, lh->mlh_mode); + fid_unlock(req, mdt_object_fid(o), + &lh->mlh_lh, lh->mlh_mode, decref); lh->mlh_lh.cookie = 0; } EXIT; @@ -864,9 +870,10 @@ struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info, void mdt_object_unlock_put(struct mdt_thread_info * info, struct mdt_object * o, - struct mdt_lock_handle *lh) + struct mdt_lock_handle *lh, + int decref) { - mdt_object_unlock(info, o, lh); + mdt_object_unlock(info, o, lh, decref); mdt_object_put(info->mti_ctxt, o); } diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index b7ea63f..0330845 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -293,7 +293,8 @@ int mdt_object_lock(struct mdt_thread_info *, void mdt_object_unlock(struct mdt_thread_info *, struct mdt_object *, - struct mdt_lock_handle *); + struct mdt_lock_handle *, + int decref); struct mdt_object *mdt_object_find(const struct lu_context *, struct mdt_device *, @@ -304,7 +305,8 @@ struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *, __u64); void mdt_object_unlock_put(struct mdt_thread_info *, struct mdt_object *, - struct mdt_lock_handle *); + struct mdt_lock_handle *, + int decref); int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op); int mdt_reint_rec(struct mdt_thread_info *); diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 8a26b63..d47981f 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -305,7 +305,7 @@ finish_open: out_child: mdt_object_put(info->mti_ctxt, child); out_parent: - mdt_object_unlock_put(info, parent, lh); + mdt_object_unlock_put(info, parent, lh, result); out: return result; } diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index 05bd2b4..e3ce014 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -74,7 +74,7 @@ static int mdt_md_create(struct mdt_thread_info *info) mdt_object_put(info->mti_ctxt, child); } else rc = PTR_ERR(child); - mdt_object_unlock_put(info, parent, lh); + mdt_object_unlock_put(info, parent, lh, rc); RETURN(rc); } @@ -182,7 +182,7 @@ static int mdt_reint_setattr(struct mdt_thread_info *info) /* FIXME & TODO Please deal with logcookies here*/ GOTO(out_unlock, rc); out_unlock: - mdt_object_unlock_put(info, mo, lh); + mdt_object_unlock_put(info, mo, lh, rc); return rc; } @@ -280,9 +280,9 @@ static int mdt_reint_unlink(struct mdt_thread_info *info) rc = mdt_handle_last_unlink(info, mc, &RQF_MDS_REINT_UNLINK_LAST); out_unlock_child: - mdt_object_unlock_put(info, mc, lhc); + mdt_object_unlock_put(info, mc, lhc, rc); out_unlock_parent: - mdt_object_unlock_put(info, mp, lhp); + mdt_object_unlock_put(info, mp, lhp, rc); return rc; } @@ -328,9 +328,9 @@ static int mdt_reint_link(struct mdt_thread_info *info) GOTO(out_unlock_target, rc); out_unlock_target: - mdt_object_unlock_put(info, mp, lhp); + mdt_object_unlock_put(info, mp, lhp, rc); out_unlock_source: - mdt_object_unlock_put(info, ms, lhs); + mdt_object_unlock_put(info, ms, lhs, rc); return rc; } @@ -388,10 +388,10 @@ static int mdt_reint_rename_tgt(struct mdt_thread_info *info) out_unlock_tgt: if (mtgt) { - mdt_object_unlock_put(info, mtgt, lh_tgt); + mdt_object_unlock_put(info, mtgt, lh_tgt, rc); } out_unlock_tgtdir: - mdt_object_unlock_put(info, mtgtdir, lh_tgtdir); + mdt_object_unlock_put(info, mtgtdir, lh_tgtdir, rc); out: return rc; } @@ -486,14 +486,14 @@ static int mdt_reint_rename(struct mdt_thread_info *info) out_unlock_new: if (mnew) { - mdt_object_unlock_put(info, mnew, lh_newp); + mdt_object_unlock_put(info, mnew, lh_newp, rc); } out_unlock_old: - mdt_object_unlock_put(info, mold, lh_oldp); + mdt_object_unlock_put(info, mold, lh_oldp, rc); out_unlock_target: - mdt_object_unlock_put(info, mtgtdir, lh_tgtdirp); + mdt_object_unlock_put(info, mtgtdir, lh_tgtdirp, rc); out_unlock_source: - mdt_object_unlock_put(info, msrcdir, lh_srcdirp); + mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc); out: return rc; } diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index 11e13db..69b96ff 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -226,7 +226,7 @@ int mdt_setxattr(struct mdt_thread_info *info) } EXIT; out_unlock: - mdt_object_unlock(info, info->mti_object, lh); + mdt_object_unlock(info, info->mti_object, lh, rc); out: return rc; }