1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 #ifndef _LUSTRE_DLM_H__
6 #define _LUSTRE_DLM_H__
8 #include <linux/kp30.h>
9 #include <linux/list.h>
11 #include <linux/obd_class.h>
15 #define OBD_LDLM_DEVICENAME "ldlm"
17 typedef int cluster_host;
18 typedef int cluster_pid;
37 #define L2B(c) (1 << c)
39 /* compatibility matrix */
40 #define LCK_COMPAT_EX L2B(LCK_NL)
41 #define LCK_COMPAT_PW (LCK_COMPAT_EX | L2B(LCK_CR))
42 #define LCK_COMPAT_PR (LCK_COMPAT_PW | L2B(LCK_PR))
43 #define LCK_COMPAT_CW (LCK_COMPAT_PW | L2B(LCK_CW))
44 #define LCK_COMPAT_CR (LCK_COMPAT_CW | L2B(LCK_PR) | L2B(LCK_PW))
45 #define LCK_COMPAT_NL (LCK_COMPAT_CR | L2B(LCK_EX))
47 static ldlm_mode_t lck_compat_array[] = {
48 [LCK_EX] LCK_COMPAT_EX,
49 [LCK_PW] LCK_COMPAT_PW,
50 [LCK_PR] LCK_COMPAT_PR,
51 [LCK_CW] LCK_COMPAT_CW,
52 [LCK_CR] LCK_COMPAT_CR,
53 [LCK_NL] LCK_COMPAT_NL
56 static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
58 if (exist < LCK_EX || exist > LCK_NL)
60 if (new < LCK_EX || new > LCK_NL)
63 return (lck_compat_array[exist] & L2B(new));
72 #define DLM_OST_NAMESPACE 1
73 #define DLM_MDS_NAMESPACE 2
76 - do we just separate this by security domains and use a prefix for
77 multiple namespaces in the same domain?
81 struct ldlm_namespace {
82 struct list_head ns_link; /* in the list of ns's */
83 __u32 ns_id; /* identifier of ns */
84 struct list_head *ns_hash; /* hash table for ns */
85 struct list_head ns_root_list; /* all root resources in ns */
86 struct obd_device *ns_obddev;
95 #define RES_HASH_BITS 14
96 #define RES_HASH_SIZE (1UL << RES_HASH_BITS)
97 #define RES_HASH_MASK (RES_HASH_SIZE - 1)
99 #define RES_NAME_SIZE 6
100 #define RES_VERSION_SIZE 4
103 struct ldlm_resource *l_resource;
104 struct ldlm_lock *l_parent;
105 struct list_head l_children;
106 struct list_head l_childof;
107 struct list_head l_res_link; /*position in one of three res lists*/
108 ldlm_mode_t l_req_mode;
109 ldlm_mode_t l_granted_mode;
110 void *l_completion_ast;
111 void *l_blocking_ast;
113 //XXX cluster_host l_holder;
114 __u32 l_version[RES_VERSION_SIZE];
117 struct ldlm_resource {
118 struct ldlm_namespace *lr_namespace;
119 struct list_head lr_hash;
120 struct list_head lr_rootlink; /* link all root resources in NS */
121 struct ldlm_resource *lr_parent; /* 0 for a root resource */
122 struct list_head lr_children; /* list head for child resources */
123 struct list_head lr_childof; /* part of child list of parent */
125 struct list_head lr_granted;
126 struct list_head lr_converting;
127 struct list_head lr_waiting;
128 ldlm_mode_t lr_most_restr;
129 atomic_t lr_refcount;
130 struct ldlm_resource *lr_root;
131 //XXX cluster_host lr_master;
132 __u32 lr_name[RES_NAME_SIZE];
133 __u32 lr_version[RES_VERSION_SIZE];
136 void (*lr_blocking)(struct ldlm_lock *lock, struct ldlm_lock *new);
144 static inline void ldlm_lock(struct obd_device *obddev)
146 spin_lock(&obddev->u.ldlm.ldlm_lock);
149 static inline void ldlm_unlock(struct obd_device *obddev)
151 spin_unlock(&obddev->u.ldlm.ldlm_lock);
154 extern struct obd_ops ldlm_obd_ops;
157 ldlm_error_t ldlm_local_lock_enqueue(struct obd_device *obbdev, __u32 ns_id,
158 struct ldlm_resource *parent_res,
159 struct ldlm_lock *parent_lock,
160 __u32 *res_id, ldlm_mode_t mode);
161 void ldlm_lock_dump(struct ldlm_lock *lock);
164 int ldlm_test(struct obd_device *device);
167 struct ldlm_namespace *ldlm_namespace_find(struct obd_device *obddev, __u32 id);
168 struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obddev, __u32 id);
169 void ldlm_resource_dump(struct ldlm_resource *res);
170 struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
171 struct ldlm_resource *parent,
172 __u32 *name, int create);
173 void ldlm_resource_put(struct ldlm_resource *res);
175 #endif /* __KERNEL__ */
177 /* ioctls for trying requests */
178 #define IOC_LDLM_TYPE 'f'
179 #define IOC_LDLM_MIN_NR 40
181 #define IOC_LDLM_TEST _IOWR('f', 40, long)
182 #define IOC_LDLM_MAX_NR 41