Whamcloud - gitweb
Branch b1_4
[fs/lustre-release.git] / lustre / ldlm / ldlm_test.c
index d445cad..7a5e066 100644 (file)
@@ -75,17 +75,26 @@ static int ldlm_do_convert(void);
  */
 static int ldlm_test_blocking_ast(struct ldlm_lock *lock,
                                   struct ldlm_lock_desc *new,
-                                  void *data, __u32 data_len)
+                                  void *data, int flag)
 {
         int rc;
         struct lustre_handle lockh;
         ENTRY;
 
-        LDLM_DEBUG(lock, "We're blocking. Cancelling lock");
-        ldlm_lock2handle(lock, &lockh);
-        rc = ldlm_cli_cancel(&lockh);
-        if (rc < 0) {
-                CERROR("ldlm_cli_cancel: %d\n", rc);
+        switch (flag) {
+        case LDLM_CB_BLOCKING:
+                LDLM_DEBUG(lock, "We're blocking. Cancelling lock");
+                ldlm_lock2handle(lock, &lockh);
+                rc = ldlm_cli_cancel(&lockh);
+                if (rc < 0) {
+                        CERROR("ldlm_cli_cancel: %d\n", rc);
+                        LBUG();
+                }
+                break;
+        case LDLM_CB_CANCELING:
+                LDLM_DEBUG(lock, "this lock is being cancelled");
+                break;
+        default:
                 LBUG();
         }
 
@@ -95,17 +104,18 @@ static int ldlm_test_blocking_ast(struct ldlm_lock *lock,
 /* blocking ast for basic tests. noop */
 static int ldlm_blocking_ast(struct ldlm_lock *lock,
                              struct ldlm_lock_desc *new,
-                             void *data, __u32 data_len)
+                             void *data, int flag)
 {
         ENTRY;
-        CERROR("ldlm_blocking_ast: lock=%p, new=%p\n", lock, new);
+        CERROR("ldlm_blocking_ast: lock=%p, new=%p, flag=%d\n", lock, new,
+               flag);
         RETURN(0);
 }
 
 /* Completion ast for regression test.
  * Does not sleep when blocked.
  */
-static int ldlm_test_completion_ast(struct ldlm_lock *lock, int flags)
+static int ldlm_test_completion_ast(struct ldlm_lock *lock, int flags, void *data)
 {
         struct ldlm_test_lock *lock_info;
         ENTRY;
@@ -149,7 +159,7 @@ int ldlm_test_basics(struct obd_device *obddev)
 {
         struct ldlm_namespace *ns;
         struct ldlm_resource *res;
-        __u64 res_id[RES_NAME_SIZE] = {1, 2, 3};
+        struct ldlm_res_id res_id = { .name = {1, 2, 3} };
         ldlm_error_t err;
         struct ldlm_lock *lock1, *lock;
         int flags;
@@ -162,7 +172,7 @@ int ldlm_test_basics(struct obd_device *obddev)
         lock1 = ldlm_lock_create(ns, NULL, res_id, LDLM_PLAIN, LCK_CR, NULL, 0);
         if (lock1 == NULL)
                 LBUG();
-        err = ldlm_lock_enqueue(lock1, NULL, 0, &flags,
+        err = ldlm_lock_enqueue(ns, lock1, NULL, 0, &flags,
                                 ldlm_completion_ast, ldlm_blocking_ast);
         if (err != ELDLM_OK)
                 LBUG();
@@ -170,7 +180,7 @@ int ldlm_test_basics(struct obd_device *obddev)
         lock = ldlm_lock_create(ns, NULL, res_id, LDLM_PLAIN, LCK_EX, NULL, 0);
         if (lock == NULL)
                 LBUG();
-        err = ldlm_lock_enqueue(lock, NULL, 0, &flags,
+        err = ldlm_lock_enqueue(ns, lock, NULL, 0, &flags,
                                 ldlm_completion_ast, ldlm_blocking_ast);
         if (err != ELDLM_OK)
                 LBUG();
@@ -187,7 +197,7 @@ int ldlm_test_basics(struct obd_device *obddev)
                 ldlm_reprocess_all(res);
 
         ldlm_resource_dump(res);
-        ldlm_namespace_free(ns);
+        ldlm_namespace_free(ns, 0);
 
         RETURN(0);
 }
@@ -197,7 +207,7 @@ int ldlm_test_extents(struct obd_device *obddev)
         struct ldlm_namespace *ns;
         struct ldlm_resource *res;
         struct ldlm_lock *lock, *lock1, *lock2;
-        __u64 res_id[RES_NAME_SIZE] = {0, 0, 0};
+        struct ldlm_res_id res_id = { .name = {0} };
         struct ldlm_extent ext1 = {4, 6}, ext2 = {6, 9}, ext3 = {10, 11};
         ldlm_error_t err;
         int flags;
@@ -208,20 +218,20 @@ int ldlm_test_extents(struct obd_device *obddev)
                 LBUG();
 
         flags = 0;
-        lock1 = ldlm_lock_create(ns, NULL, res_id, LDLM_EXTENT, LCK_PR, NULL,
-                                 0);
+        lock1 = ldlm_lock_create(ns, NULL, res_id, LDLM_EXTENT, LCK_PR, NULL,0);
         if (lock1 == NULL)
                 LBUG();
-        err = ldlm_lock_enqueue(lock1, &ext1, sizeof(ext1), &flags, NULL, NULL);
+        err = ldlm_lock_enqueue(ns, lock1, &ext1, sizeof(ext1), &flags, NULL,
+                                NULL);
         if (err != ELDLM_OK)
                 LBUG();
         if (!(flags & LDLM_FL_LOCK_CHANGED))
                 LBUG();
 
         flags = 0;
-        lock2 = ldlm_lock_create(ns, NULL, res_id, LDLM_EXTENT, LCK_PR,
-                                NULL, 0);
-        err = ldlm_lock_enqueue(lock2, &ext2, sizeof(ext2), &flags, NULL, NULL);
+        lock2 = ldlm_lock_create(ns, NULL, res_id, LDLM_EXTENT, LCK_PR, NULL,0);
+        err = ldlm_lock_enqueue(ns, lock2, &ext2, sizeof(ext2), &flags, NULL,
+                                NULL);
         if (err != ELDLM_OK)
                 LBUG();
         if (!(flags & LDLM_FL_LOCK_CHANGED))
@@ -231,7 +241,7 @@ int ldlm_test_extents(struct obd_device *obddev)
         lock = ldlm_lock_create(ns, NULL, res_id, LDLM_EXTENT, LCK_EX, NULL, 0);
         if (lock == NULL)
                 LBUG();
-        err = ldlm_lock_enqueue(lock, &ext3, sizeof(ext3), &flags,
+        err = ldlm_lock_enqueue(ns, lock, &ext3, sizeof(ext3), &flags,
                                 NULL, NULL);
         if (err != ELDLM_OK)
                 LBUG();
@@ -255,7 +265,7 @@ int ldlm_test_extents(struct obd_device *obddev)
         if (res == NULL)
                 LBUG();
         ldlm_resource_dump(res);
-        ldlm_namespace_free(ns);
+        ldlm_namespace_free(ns, 0);
 
         RETURN(0);
 }
@@ -263,8 +273,7 @@ int ldlm_test_extents(struct obd_device *obddev)
 static int ldlm_test_network(struct obd_device *obddev,
                              struct lustre_handle *connh)
 {
-
-        __u64 res_id[RES_NAME_SIZE] = {1, 2, 3};
+        struct ldlm_res_id res_id = { .name = {1, 2, 3} };
         struct ldlm_extent ext = {4, 6};
         struct lustre_handle lockh1;
         struct ldlm_lock *lock;
@@ -283,7 +292,7 @@ static int ldlm_test_network(struct obd_device *obddev,
         CERROR("ldlm_cli_convert: %d\n", err);
 
         lock = ldlm_handle2lock(&lockh1);
-        ldlm_lock_dump(lock);
+        ldlm_lock_dump(D_OTHER, lock);
         ldlm_lock_put(lock);
 
         /* Need to decrement old mode. Don't bother incrementing new
@@ -329,7 +338,7 @@ static int ldlm_do_decrement(void)
 static int ldlm_do_enqueue(struct ldlm_test_thread *thread)
 {
         struct lustre_handle lockh;
-        __u64 res_id[3] = {0};
+        struct ldlm_res_id res_id = { .name = {0} };
         __u32 lock_mode;
         struct ldlm_extent ext;
         unsigned char random;
@@ -338,7 +347,7 @@ static int ldlm_do_enqueue(struct ldlm_test_thread *thread)
 
         /* Pick a random resource from 1 to num_resources */
         get_random_bytes(&random, sizeof(random));
-        res_id[0] = random % num_resources;
+        res_id.name[0] = random % num_resources;
 
         /* Pick a random lock mode */
         get_random_bytes(&random, sizeof(random));
@@ -352,7 +361,7 @@ static int ldlm_do_enqueue(struct ldlm_test_thread *thread)
                 (num_extents - (int)ext.start) + ext.start;
 
         LDLM_DEBUG_NOLOCK("about to enqueue with resource "LPX64", mode %d,"
-                          " extent "LPX64" -> "LPX64, res_id[0], lock_mode,
+                          " extent "LPX64" -> "LPX64, res_id.name[0], lock_mode,
                           ext.start, ext.end);
 
         rc = ldlm_match_or_enqueue(&regress_connh, NULL,
@@ -422,14 +431,20 @@ static int ldlm_do_convert(void)
 static int ldlm_test_main(void *data)
 {
         struct ldlm_test_thread *thread = data;
+        unsigned long flags;
         ENTRY;
 
         lock_kernel();
         daemonize();
-        spin_lock_irq(&current->sigmask_lock);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+        sigfillset(&current->blocked);
+        recalc_sigpending();
+#else
+        spin_lock_irqsave(&current->sigmask_lock, flags);
         sigfillset(&current->blocked);
         recalc_sigpending(current);
-        spin_unlock_irq(&current->sigmask_lock);
+        spin_unlock_irqrestore(&current->sigmask_lock, flags);
+#endif
 
         sprintf(current->comm, "ldlm_test");
         unlock_kernel();