From 43c01b9d94e783295edc2d1432ed3af0076a0e51 Mon Sep 17 00:00:00 2001 From: Jinshan Xiong Date: Mon, 3 Oct 2011 15:48:36 -0700 Subject: [PATCH] LU-731 ldlm: revise and export ldlm_lock_set_data We can only reset ->l_ast_data if it's NULL; otherwise, returning an error if ->l_ast_data is trying to be changed to a different value. Change-Id: I8f999a98101daa2c465256792285582f581909c5 Signed-off-by: Jinshan Xiong Reviewed-on: http://review.whamcloud.com/1466 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/lustre_dlm.h | 1 + lustre/ldlm/ldlm_lock.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index 5c31761..1b04e4c 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -984,6 +984,7 @@ void ldlm_lock2handle(const struct ldlm_lock *lock, struct ldlm_lock *__ldlm_handle2lock(const struct lustre_handle *, int flags); void ldlm_cancel_callback(struct ldlm_lock *); int ldlm_lock_remove_from_lru(struct ldlm_lock *); +int ldlm_lock_set_data(struct lustre_handle *, void *); static inline struct ldlm_lock *ldlm_handle2lock(const struct lustre_handle *h) { diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index 2123535..08eae35 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -1711,15 +1711,19 @@ void ldlm_lock_cancel(struct ldlm_lock *lock) int ldlm_lock_set_data(struct lustre_handle *lockh, void *data) { struct ldlm_lock *lock = ldlm_handle2lock(lockh); + int rc = -EINVAL; ENTRY; - if (lock == NULL) - RETURN(-EINVAL); - - lock->l_ast_data = data; - LDLM_LOCK_PUT(lock); - RETURN(0); + if (lock) { + if (lock->l_ast_data == NULL) + lock->l_ast_data = data; + if (lock->l_ast_data == data) + rc = 0; + LDLM_LOCK_PUT(lock); + } + RETURN(rc); } +EXPORT_SYMBOL(ldlm_lock_set_data); int ldlm_cancel_locks_for_export_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd, cfs_hlist_node_t *hnode, void *data) -- 1.8.3.1