Whamcloud - gitweb
- first parts of lock management: module & resource hash +
[fs/lustre-release.git] / lustre / include / linux / lustre_dlm.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef _LUSTRE_DLM_H__
6 #define _LUSTRE_DLM_H__
7
8 #include <linux/kp30.h>
9 #include <linux/list.h>
10
11 #define OBD_LDLM_DEVICENAME  "ldlm"
12
13 typedef  int cluster_host;
14 typedef  int cluster_pid;
15
16 /* lock types */
17 typedef enum  { 
18         LCK_EX,
19        LCK_PW,
20        LCK_PR,
21        LCK_CW,
22        LCK_CR,
23        LCK_NL
24 } ldlm_mode_t;
25
26 #define L2B(c) (1<<c)
27
28 /* compatibility matrix */
29 #define LCK_COMPAT_EX  L2B(LCK_NL)
30 #define LCK_COMPAT_PW  (LCK_COMPAT_EX | L2B(LCK_CR))
31 #define LCK_COMPAT_PR  (LCK_COMPAT_PW | L2B(LCK_PR))
32 #define LCK_COMPAT_CW  (LCK_COMPAT_PW | L2B(LCK_CW))
33 #define LCK_COMPAT_CR  (LCK_COMPAT_CW | L2B(LCK_PR) | L2B(LCK_PW))
34 #define LCK_COMPAT_NL  (LCK_COMPAT_CR | L2B(LCK_EX))
35
36 static ldlm_mode_t lck_compat_array[] = {
37        LCK_COMPAT_EX,
38        LCK_COMPAT_PW,
39        LCK_COMPAT_PR,
40        LCK_COMPAT_CW,
41        LCK_COMPAT_CR,
42        LCK_COMPAT_NL
43 };
44
45 static inline int lockmode_compat(ldlm_mode_t a, ldlm_mode_t b)
46 {
47        if ( 0 <= a && a <= 5 ) { 
48               BUG();
49        }
50        if( 0 <= b && b <= 5 ) { 
51               BUG();
52        }
53     
54        return 1 && (lck_compat_array[a] & L2B(b));
55 }
56
57 /* 
58  * 
59  * cluster name spaces 
60  *
61  */
62
63 #define DLM_OST_NAMESPACE 1
64 #define DLM_MDS_NAMESPACE 2
65
66 /* XXX 
67    - do we just separate this by security domains and use a prefix for 
68      multiple namespaces in the same domain? 
69    - 
70 */
71
72 struct ldlm_namespace {
73        struct list_head      ns_link;      /* in the list of ns's */
74        __u32                 ns_id;        /* identifier of ns */
75        struct list_head     *ns_hash;      /* hash table for ns */
76        struct list_head      ns_root_list; /* all root resources in ns */
77 };
78
79 /* 
80  * 
81  * Resource hash table 
82  *
83  */
84
85 #define RES_HASH_BITS 18
86 #define RES_HASH_SIZE (1UL << RES_HASH_BITS)
87 #define RES_HASH_MASK (RES_HASH_SIZE - 1)
88
89 #define RES_NAME_SIZE 6
90 #define RES_VERSION_SIZE 4
91
92 struct ldlm_resource {
93        struct list_head      lr_hash;
94        struct list_head      lr_rootlink; /* link all root resources in NS */
95        struct ldlm_resource *lr_parent;   /* 0 for a root resource */
96        struct list_head      lr_children; /* list head for child resources */
97        struct list_head      lr_childof;  /* part of child list of parent */
98
99        struct list_head      lr_granted;
100        struct list_head      lr_converting;
101        struct list_head      lr_waiting;
102        ldlm_mode_t           lr_most_restr;
103        struct ldlm_resource *lr_root;
104        //XXX cluster_host          lr_master;
105        __u32                 lr_name[RES_NAME_SIZE];
106        __u32                 lr_version[RES_VERSION_SIZE];
107 };
108
109 struct ldlm_lock {
110        struct ldlm_resource *lb_resource;
111        struct ldlm_lock     *lb_parent;
112        struct list_head      lb_children;
113        struct list_head      lb_childof;
114        unsigned long         lb_id;
115        ldlm_mode_t           lb_req_mode;
116        ldlm_mode_t           lb_granted_mode;
117        void                 *lb_completion_ast;
118        void                 *lb_blocking_ast;
119        void                 *lb_event;
120        //XXX cluster_host    lb_holder;
121        __u32                 lb_version[RES_VERSION_SIZE];
122 };
123
124 struct ldlm_obd {
125         struct list_head ldlm_namespaces;
126 };
127
128 extern struct obd_ops ldlm_obd_ops;
129
130 #endif