Whamcloud - gitweb
LU-731 ldlm: revise and export ldlm_lock_set_data
authorJinshan Xiong <jay@whamcloud.com>
Mon, 3 Oct 2011 22:48:36 +0000 (15:48 -0700)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Oct 2011 22:25:04 +0000 (18:25 -0400)
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 <jay@whamcloud.com>
Reviewed-on: http://review.whamcloud.com/1466
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_dlm.h
lustre/ldlm/ldlm_lock.c

index 5c31761..1b04e4c 100644 (file)
@@ -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)
 {
index 2123535..08eae35 100644 (file)
@@ -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)