Whamcloud - gitweb
b=2969
authorzab <zab>
Fri, 19 Mar 2004 22:41:33 +0000 (22:41 +0000)
committerzab <zab>
Fri, 19 Mar 2004 22:41:33 +0000 (22:41 +0000)
r=phil

This adds a sync parameter to ldlm_cancel_lru() so that cancel_lru_locks in
tests doesn't return until the blocking callbacks have been completed.  This
removes a race that was failing test 45 in sanity and can only benefit
other tests.  (*knocks on wood*)

lustre/include/linux/lustre_dlm.h
lustre/ldlm/ldlm_internal.h
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_request.c
lustre/ldlm/ldlm_resource.c

index fe47d7f..cfedfa5 100644 (file)
@@ -425,11 +425,6 @@ int ldlm_handle_cancel(struct ptlrpc_request *req);
 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
 int ldlm_get_ref(void);
 void ldlm_put_ref(int force);
-#ifndef __KERNEL__
-void liblustre_ldlm_handle_bl_callback(struct ldlm_namespace *ns,
-                                       struct ldlm_lock_desc *ld,
-                                       struct ldlm_lock *lock);
-#endif
 
 /* ldlm_lock.c */
 ldlm_processing_policy ldlm_get_processing_policy(struct ldlm_resource *res);
index 735f776..8d27293 100644 (file)
@@ -1,5 +1,10 @@
 /* ldlm_request.c */
-int ldlm_cancel_lru(struct ldlm_namespace *ns);
+typedef enum {
+       LDLM_ASYNC,
+       LDLM_SYNC,
+} ldlm_sync_t;
+
+int ldlm_cancel_lru(struct ldlm_namespace *ns, ldlm_sync_t sync);
 
 /* ldlm_resource.c */
 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
@@ -26,6 +31,9 @@ int ldlm_run_ast_work(struct ldlm_namespace *, struct list_head *rpc_list);
 /* ldlm_lockd.c */
 int ldlm_bl_to_thread(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
                       struct ldlm_lock *lock);
+void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
+                             struct ldlm_lock_desc *ld, 
+                            struct ldlm_lock *lock);
 
 /* ldlm_plain.c */
 int ldlm_process_plain_lock(struct ldlm_lock *lock, int *flags, int first_enq,
index e720e4c..7fada77 100644 (file)
@@ -482,7 +482,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
                 l_unlock(&ns->ns_lock);
 #else
                 l_unlock(&ns->ns_lock);
-                liblustre_ldlm_handle_bl_callback(ns, NULL, lock);
+                ldlm_handle_bl_callback(ns, NULL, lock);
 #endif
         } else if (ns->ns_client == LDLM_NAMESPACE_CLIENT &&
                    !lock->l_readers && !lock->l_writers) {
@@ -493,7 +493,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
                 list_add_tail(&lock->l_lru, &ns->ns_unused_list);
                 ns->ns_nr_unused++;
                 l_unlock(&ns->ns_lock);
-                ldlm_cancel_lru(ns);
+                ldlm_cancel_lru(ns, LDLM_ASYNC);
         } else {
                 l_unlock(&ns->ns_lock);
         }
index a46dd73..9306dd8 100644 (file)
@@ -796,9 +796,8 @@ int ldlm_handle_cancel(struct ptlrpc_request *req)
         RETURN(0);
 }
 
-static void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
-                                    struct ldlm_lock_desc *ld,
-                                    struct ldlm_lock *lock)
+void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
+                             struct ldlm_lock_desc *ld, struct ldlm_lock *lock)
 {
         int do_ast;
         ENTRY;
@@ -944,10 +943,10 @@ static int ldlm_callback_reply(struct ptlrpc_request *req, int rc)
         return ptlrpc_reply(req);
 }
 
-#ifdef __KERNEL__
 int ldlm_bl_to_thread(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
                       struct ldlm_lock *lock)
 {
+#ifdef __KERNEL__
         struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
         struct ldlm_bl_work_item *blwi;
         ENTRY;
@@ -965,18 +964,12 @@ int ldlm_bl_to_thread(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
         list_add_tail(&blwi->blwi_entry, &blp->blp_list);
         wake_up(&blp->blp_waitq);
         spin_unlock(&blp->blp_lock);
+#else
+        LBUG();
+#endif
 
         RETURN(0);
 }
-#else
-/* XXX */
-void liblustre_ldlm_handle_bl_callback(struct ldlm_namespace *ns,
-                                       struct ldlm_lock_desc *ld,
-                                       struct ldlm_lock *lock)
-{
-        ldlm_handle_bl_callback(ns, ld, lock);
-}
-#endif
 
 static int ldlm_callback_handler(struct ptlrpc_request *req)
 {
index 37868ca..f52d37d 100644 (file)
@@ -590,13 +590,16 @@ int ldlm_cli_cancel(struct lustre_handle *lockh)
         return rc;
 }
 
-int ldlm_cancel_lru(struct ldlm_namespace *ns)
+/* when called with LDLM_ASYNC the blocking callback will be handled
+ * in a thread and this function will return after the thread has been
+ * asked to call the callback.  when called with LDLM_SYNC the blocking
+ * callback will be performed in this function. */
+int ldlm_cancel_lru(struct ldlm_namespace *ns, ldlm_sync_t sync)
 {
         struct list_head *tmp, *next;
-#ifndef __KERNEL__
-        LIST_HEAD(cblist);
-#endif
+        struct ldlm_lock *lock;
         int count, rc = 0;
+        LIST_HEAD(cblist);
         ENTRY;
 
         l_lock(&ns->ns_lock);
@@ -608,7 +611,7 @@ int ldlm_cancel_lru(struct ldlm_namespace *ns)
         }
 
         list_for_each_safe(tmp, next, &ns->ns_unused_list) {
-                struct ldlm_lock *lock;
+
                 lock = list_entry(tmp, struct ldlm_lock, l_lru);
 
                 LASSERT(!lock->l_readers && !lock->l_writers);
@@ -622,25 +625,21 @@ int ldlm_cancel_lru(struct ldlm_namespace *ns)
 
                 LDLM_LOCK_GET(lock); /* dropped by bl thread */
                 ldlm_lock_remove_from_lru(lock);
-#if __KERNEL__
-                ldlm_bl_to_thread(ns, NULL, lock);
-#else
-                list_add(&lock->l_lru, &cblist);
-#endif
+                if (sync == LDLM_ASYNC)
+                        ldlm_bl_to_thread(ns, NULL, lock);
+                else
+                        list_add(&lock->l_lru, &cblist);
 
                 if (--count == 0)
                         break;
         }
         l_unlock(&ns->ns_lock);
-#ifndef __KERNEL__
-        while (!list_empty(&cblist)) {
-                struct ldlm_lock *lock;
 
-                lock = list_entry(cblist.next, struct ldlm_lock, l_lru);
+        list_for_each_safe(tmp, next, &cblist) {
+                lock = list_entry(tmp, struct ldlm_lock, l_lru);
                 list_del_init(&lock->l_lru);
-                liblustre_ldlm_handle_bl_callback(ns, NULL, lock);
+                ldlm_handle_bl_callback(ns, NULL, lock);
         }
-#endif
         RETURN(rc);
 }
 
index 52770e9..8ed3de9 100644 (file)
@@ -148,7 +148,7 @@ static int lprocfs_write_lru_size(struct file *file, const char *buffer,
                        ns->ns_name);
                 tmp = ns->ns_max_unused;
                 ns->ns_max_unused = 0;
-                ldlm_cancel_lru(ns);
+                ldlm_cancel_lru(ns, LDLM_SYNC);
                 ns->ns_max_unused = tmp;
                 return count;
         }
@@ -158,7 +158,7 @@ static int lprocfs_write_lru_size(struct file *file, const char *buffer,
                ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
         ns->ns_max_unused = (unsigned int)tmp;
 
-        ldlm_cancel_lru(ns);
+        ldlm_cancel_lru(ns, LDLM_ASYNC);
 
         return count;
 }