From e611655b0cb8438290795bc43c0aba44e70b670f Mon Sep 17 00:00:00 2001 From: nikita Date: Thu, 21 Sep 2006 13:31:34 +0000 Subject: [PATCH] move fid_{,un}_lock() functions into fid module --- lustre/fid/fid_lib.c | 40 +++++++++++++++++++++++++++ lustre/include/lustre_fid.h | 27 +++++++++++++++++++ lustre/mdt/mdt_handler.c | 66 +++++++++++---------------------------------- lustre/mdt/mdt_internal.h | 14 ---------- 4 files changed, 82 insertions(+), 65 deletions(-) diff --git a/lustre/fid/fid_lib.c b/lustre/fid/fid_lib.c index bca8668..16587e9 100644 --- a/lustre/fid/fid_lib.c +++ b/lustre/fid/fid_lib.c @@ -162,3 +162,43 @@ void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src) } EXPORT_SYMBOL(range_be_to_cpu); #endif + +/* issues dlm lock on passed @ns, @f stores it lock handle into @lh. */ +int fid_lock(struct ldlm_namespace *ns, const struct lu_fid *f, + struct lustre_handle *lh, ldlm_mode_t mode, + ldlm_policy_data_t *policy, + struct ldlm_res_id *res_id) +{ + int flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB; + int rc; + + LASSERT(ns != NULL); + LASSERT(lh != NULL); + LASSERT(f != NULL); + + rc = ldlm_cli_enqueue_local(ns, *fid_build_res_name(f, res_id), + LDLM_IBITS, policy, mode, &flags, + ldlm_blocking_ast, ldlm_completion_ast, + NULL, NULL, 0, NULL, lh); + return rc == ELDLM_OK ? 0 : -EIO; +} +EXPORT_SYMBOL(fid_lock); + +void fid_unlock(const struct lu_fid *f, + struct lustre_handle *lh, ldlm_mode_t mode) +{ + { + /* FIXME: this is debug stuff, remove it later. */ + struct ldlm_lock *lock = ldlm_handle2lock(lh); + if (!lock) { + CERROR("Invalid lock handle "LPX64"\n", + lh->cookie); + LBUG(); + } + LASSERT(fid_res_name_eq(f, &lock->l_resource->lr_name)); + LDLM_LOCK_PUT(lock); + } + ldlm_lock_decref(lh, mode); +} +EXPORT_SYMBOL(fid_unlock); + diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index e792374..58fe2ee 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -192,6 +192,33 @@ void fid_cpu_to_be(struct lu_fid *dst, const struct lu_fid *src); void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src); void fid_be_to_cpu(struct lu_fid *dst, const struct lu_fid *src); +/* fid locking */ + +struct ldlm_namespace; + +int fid_lock(struct ldlm_namespace *ns, const struct lu_fid *f, + struct lustre_handle *lh, ldlm_mode_t mode, + ldlm_policy_data_t *policy, + struct ldlm_res_id *res_id); +void fid_unlock(const struct lu_fid *f, + struct lustre_handle *lh, ldlm_mode_t mode); + +/* + * Build (DLM) resource name from fid. + */ +static inline struct ldlm_res_id * +fid_build_res_name(const struct lu_fid *f, + struct ldlm_res_id *name) +{ + memset(name, 0, sizeof *name); + name->name[0] = fid_seq(f); + name->name[1] = fid_oid(f); + name->name[2] = fid_ver(f); + return name; +} + + + /* Range common stuff */ void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src); void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index c6bcd03..3316297 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -1154,52 +1154,6 @@ static int mdt_sec_ctx_handle(struct mdt_thread_info *info) return 0; } -/* issues dlm lock on passed @ns, @f stores it lock handle into @lh. */ -int fid_lock(struct ldlm_namespace *ns, const struct lu_fid *f, - struct lustre_handle *lh, ldlm_mode_t mode, - ldlm_policy_data_t *policy, - struct ldlm_res_id *res_id) -{ - int flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB; - int rc; - - LASSERT(ns != NULL); - LASSERT(lh != NULL); - LASSERT(f != NULL); - - rc = ldlm_cli_enqueue_local(ns, *fid_build_res_name(f, res_id), - LDLM_IBITS, policy, mode, &flags, - ldlm_blocking_ast, ldlm_completion_ast, - NULL, NULL, 0, NULL, lh); - return rc == ELDLM_OK ? 0 : -EIO; -} - -/* - * 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, too. - */ -void fid_unlock(struct ptlrpc_request *req, const struct lu_fid *f, - struct lustre_handle *lh, ldlm_mode_t mode, int decref) -{ - { - /* FIXME: this is debug stuff, remove it later. */ - struct ldlm_lock *lock = ldlm_handle2lock(lh); - if (!lock) { - CERROR("Invalid lock handle "LPX64"\n", - lh->cookie); - LBUG(); - } - LASSERT(fid_res_name_eq(f, &lock->l_resource->lr_name)); - LDLM_LOCK_PUT(lock); - } - - if (decref) - ldlm_lock_decref(lh, mode); - else - ptlrpc_save_lock(req, lh, mode); -} - static struct mdt_object *mdt_obj(struct lu_object *o) { LASSERT(lu_device_is_mdt(o->lo_dev)); @@ -1241,16 +1195,26 @@ int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o, RETURN(rc); } +/* + * 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, too. + */ void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o, struct mdt_lock_handle *lh, int decref) { - struct ptlrpc_request *req = mdt_info_req(info); + struct ptlrpc_request *req = mdt_info_req(info); + struct lustre_handle *handle = &lh->mlh_lh; + ldlm_mode_t mode = lh->mlh_mode; ENTRY; - if (lustre_handle_is_used(&lh->mlh_lh)) { - fid_unlock(req, mdt_object_fid(o), - &lh->mlh_lh, lh->mlh_mode, decref); - lh->mlh_lh.cookie = 0; + if (lustre_handle_is_used(handle)) { + + if (decref) + fid_unlock(mdt_object_fid(o), handle, mode); + else + ptlrpc_save_lock(req, handle, mode); + handle->cookie = 0; } EXIT; } diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 86e407f..fd78729 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -469,19 +469,5 @@ do { \ } \ } while(0) -/* - * Build (DLM) resource name from fid. - */ -static inline struct ldlm_res_id * -fid_build_res_name(const struct lu_fid *f, - struct ldlm_res_id *name) -{ - memset(name, 0, sizeof *name); - name->name[0] = fid_seq(f); - name->name[1] = fid_oid(f); - name->name[2] = fid_ver(f); - return name; -} - #endif /* __KERNEL__ */ #endif /* _MDT_H */ -- 1.8.3.1