Whamcloud - gitweb
bef9aad0483098d8b05afdb577f384238e0254da
[fs/lustre-release.git] / lustre / ldlm / ldlm_test.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * by Cluster File Systems, Inc.
10  */
11
12 #define EXPORT_SYMTAB
13
14 #include <linux/version.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <asm/unistd.h>
18
19 #define DEBUG_SUBSYSTEM S_LDLM
20
21 #include <linux/obd_support.h>
22 #include <linux/obd_class.h>
23
24 #include <linux/lustre_dlm.h>
25
26 static void ldlm_test_callback(struct ldlm_lock *lock, struct ldlm_lock *new)
27 {
28         printk("ldlm_test_callback: lock=%p, new=%p\n", lock, new);
29 }
30
31 int ldlm_test(struct obd_device *obddev)
32 {
33         struct ldlm_namespace *ns;
34         struct ldlm_resource *res;
35         __u64 res_id[RES_NAME_SIZE] = {1, 2, 3};
36         ldlm_error_t err;
37         struct ldlm_handle h;
38         int flags;
39
40         ns = ldlm_namespace_new(obddev, 1);
41         if (ns == NULL)
42                 LBUG();
43
44         res = ldlm_resource_get(ns, NULL, res_id, 1);
45         if (res == NULL)
46                 LBUG();
47
48         res->lr_blocking = ldlm_test_callback;
49
50         /* Get a couple of read locks */
51         err = ldlm_local_lock_enqueue(obddev, 1, NULL, NULL, res_id, LCK_CR,
52                                       &flags, NULL, NULL, 0, NULL, &h);
53         if (err != ELDLM_OK)
54                 LBUG();
55
56         err = ldlm_local_lock_enqueue(obddev, 1, NULL, NULL, res_id, LCK_CR,
57                                       &flags, NULL, NULL, 0, NULL, &h);
58         if (err != ELDLM_OK)
59                 LBUG();
60
61         ldlm_resource_dump(res);
62
63         return 0;
64 }