Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * dlmcommon.h |
| 5 | * |
| 6 | * Copyright (C) 2004 Oracle. All rights reserved. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public |
| 19 | * License along with this program; if not, write to the |
| 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | * Boston, MA 021110-1307, USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef DLMCOMMON_H |
| 26 | #define DLMCOMMON_H |
| 27 | |
| 28 | #include <linux/kref.h> |
| 29 | |
| 30 | #define DLM_HB_NODE_DOWN_PRI (0xf000000) |
| 31 | #define DLM_HB_NODE_UP_PRI (0x8000000) |
| 32 | |
| 33 | #define DLM_LOCKID_NAME_MAX 32 |
| 34 | |
| 35 | #define DLM_DOMAIN_NAME_MAX_LEN 255 |
| 36 | #define DLM_LOCK_RES_OWNER_UNKNOWN O2NM_MAX_NODES |
| 37 | #define DLM_THREAD_SHUFFLE_INTERVAL 5 // flush everything every 5 passes |
| 38 | #define DLM_THREAD_MS 200 // flush at least every 200 ms |
| 39 | |
Joel Becker | c8f33b6 | 2006-03-16 17:40:37 -0800 | [diff] [blame] | 40 | #define DLM_HASH_SIZE_DEFAULT (1 << 14) |
| 41 | #if DLM_HASH_SIZE_DEFAULT < PAGE_SIZE |
| 42 | # define DLM_HASH_PAGES 1 |
| 43 | #else |
| 44 | # define DLM_HASH_PAGES (DLM_HASH_SIZE_DEFAULT / PAGE_SIZE) |
| 45 | #endif |
Daniel Phillips | 03d864c | 2006-03-10 18:08:16 -0800 | [diff] [blame] | 46 | #define DLM_BUCKETS_PER_PAGE (PAGE_SIZE / sizeof(struct hlist_head)) |
| 47 | #define DLM_HASH_BUCKETS (DLM_HASH_PAGES * DLM_BUCKETS_PER_PAGE) |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 48 | |
Mark Fasheh | a3d3329 | 2006-03-09 17:55:56 -0800 | [diff] [blame] | 49 | /* Intended to make it easier for us to switch out hash functions */ |
| 50 | #define dlm_lockid_hash(_n, _l) full_name_hash(_n, _l) |
| 51 | |
Sunil Mushran | 751155a | 2008-03-10 15:16:25 -0700 | [diff] [blame] | 52 | enum dlm_mle_type { |
| 53 | DLM_MLE_BLOCK, |
| 54 | DLM_MLE_MASTER, |
Sunil Mushran | 2041d8f | 2009-02-26 15:00:43 -0800 | [diff] [blame] | 55 | DLM_MLE_MIGRATION, |
| 56 | DLM_MLE_NUM_TYPES |
Sunil Mushran | 751155a | 2008-03-10 15:16:25 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct dlm_lock_name { |
Sunil Mushran | 2ed6c75 | 2009-02-26 15:00:41 -0800 | [diff] [blame] | 60 | unsigned int hash; |
Sunil Mushran | f77a9a7 | 2009-02-26 15:00:38 -0800 | [diff] [blame] | 61 | unsigned int len; |
| 62 | unsigned char name[DLM_LOCKID_NAME_MAX]; |
Sunil Mushran | 751155a | 2008-03-10 15:16:25 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct dlm_master_list_entry { |
Sunil Mushran | 2ed6c75 | 2009-02-26 15:00:41 -0800 | [diff] [blame] | 66 | struct hlist_node master_hash_node; |
Sunil Mushran | 751155a | 2008-03-10 15:16:25 -0700 | [diff] [blame] | 67 | struct list_head hb_events; |
| 68 | struct dlm_ctxt *dlm; |
| 69 | spinlock_t spinlock; |
| 70 | wait_queue_head_t wq; |
| 71 | atomic_t woken; |
| 72 | struct kref mle_refs; |
| 73 | int inuse; |
| 74 | unsigned long maybe_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 75 | unsigned long vote_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 76 | unsigned long response_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 77 | unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 78 | u8 master; |
| 79 | u8 new_master; |
| 80 | enum dlm_mle_type type; |
| 81 | struct o2hb_callback_func mle_hb_up; |
| 82 | struct o2hb_callback_func mle_hb_down; |
| 83 | union { |
Sunil Mushran | f77a9a7 | 2009-02-26 15:00:38 -0800 | [diff] [blame] | 84 | struct dlm_lock_resource *mleres; |
| 85 | struct dlm_lock_name mlename; |
Sunil Mushran | 751155a | 2008-03-10 15:16:25 -0700 | [diff] [blame] | 86 | } u; |
| 87 | }; |
| 88 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 89 | enum dlm_ast_type { |
| 90 | DLM_AST = 0, |
| 91 | DLM_BAST, |
| 92 | DLM_ASTUNLOCK |
| 93 | }; |
| 94 | |
| 95 | |
| 96 | #define LKM_VALID_FLAGS (LKM_VALBLK | LKM_CONVERT | LKM_UNLOCK | \ |
| 97 | LKM_CANCEL | LKM_INVVALBLK | LKM_FORCE | \ |
| 98 | LKM_RECOVERY | LKM_LOCAL | LKM_NOQUEUE) |
| 99 | |
| 100 | #define DLM_RECOVERY_LOCK_NAME "$RECOVERY" |
| 101 | #define DLM_RECOVERY_LOCK_NAME_LEN 9 |
| 102 | |
| 103 | static inline int dlm_is_recovery_lock(const char *lock_name, int name_len) |
| 104 | { |
| 105 | if (name_len == DLM_RECOVERY_LOCK_NAME_LEN && |
| 106 | memcmp(lock_name, DLM_RECOVERY_LOCK_NAME, name_len)==0) |
| 107 | return 1; |
| 108 | return 0; |
| 109 | } |
| 110 | |
Kurt Hackel | 466d1a4 | 2006-05-01 11:11:13 -0700 | [diff] [blame] | 111 | #define DLM_RECO_STATE_ACTIVE 0x0001 |
| 112 | #define DLM_RECO_STATE_FINALIZE 0x0002 |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 113 | |
| 114 | struct dlm_recovery_ctxt |
| 115 | { |
| 116 | struct list_head resources; |
| 117 | struct list_head received; |
| 118 | struct list_head node_data; |
| 119 | u8 new_master; |
| 120 | u8 dead_node; |
| 121 | u16 state; |
| 122 | unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 123 | wait_queue_head_t event; |
| 124 | }; |
| 125 | |
| 126 | enum dlm_ctxt_state { |
| 127 | DLM_CTXT_NEW = 0, |
| 128 | DLM_CTXT_JOINED, |
| 129 | DLM_CTXT_IN_SHUTDOWN, |
| 130 | DLM_CTXT_LEAVING, |
| 131 | }; |
| 132 | |
| 133 | struct dlm_ctxt |
| 134 | { |
| 135 | struct list_head list; |
Daniel Phillips | 03d864c | 2006-03-10 18:08:16 -0800 | [diff] [blame] | 136 | struct hlist_head **lockres_hash; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 137 | struct list_head dirty_list; |
| 138 | struct list_head purge_list; |
| 139 | struct list_head pending_asts; |
| 140 | struct list_head pending_basts; |
Sunil Mushran | 29576f8 | 2008-03-10 15:16:21 -0700 | [diff] [blame] | 141 | struct list_head tracking_list; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 142 | unsigned int purge_count; |
| 143 | spinlock_t spinlock; |
| 144 | spinlock_t ast_lock; |
Sunil Mushran | b0d4f817 | 2008-12-16 15:49:22 -0800 | [diff] [blame] | 145 | spinlock_t track_lock; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 146 | char *name; |
| 147 | u8 node_num; |
| 148 | u32 key; |
| 149 | u8 joining_node; |
| 150 | wait_queue_head_t dlm_join_events; |
| 151 | unsigned long live_nodes_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 152 | unsigned long domain_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 153 | unsigned long recovery_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 154 | struct dlm_recovery_ctxt reco; |
| 155 | spinlock_t master_lock; |
Sunil Mushran | e2b66dd | 2009-02-26 15:00:40 -0800 | [diff] [blame] | 156 | struct hlist_head **master_hash; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 157 | struct list_head mle_hb_events; |
| 158 | |
| 159 | /* these give a really vague idea of the system load */ |
Sunil Mushran | 2041d8f | 2009-02-26 15:00:43 -0800 | [diff] [blame] | 160 | atomic_t mle_tot_count[DLM_MLE_NUM_TYPES]; |
| 161 | atomic_t mle_cur_count[DLM_MLE_NUM_TYPES]; |
Sunil Mushran | 6800791 | 2009-02-26 15:00:44 -0800 | [diff] [blame^] | 162 | atomic_t res_tot_count; |
| 163 | atomic_t res_cur_count; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 164 | |
Sunil Mushran | 007dce5 | 2008-03-10 15:16:23 -0700 | [diff] [blame] | 165 | struct dlm_debug_ctxt *dlm_debug_ctxt; |
Sunil Mushran | 6325b4a | 2008-03-10 15:16:22 -0700 | [diff] [blame] | 166 | struct dentry *dlm_debugfs_subroot; |
| 167 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 168 | /* NOTE: Next three are protected by dlm_domain_lock */ |
| 169 | struct kref dlm_refs; |
| 170 | enum dlm_ctxt_state dlm_state; |
| 171 | unsigned int num_joins; |
| 172 | |
| 173 | struct o2hb_callback_func dlm_hb_up; |
| 174 | struct o2hb_callback_func dlm_hb_down; |
| 175 | struct task_struct *dlm_thread_task; |
| 176 | struct task_struct *dlm_reco_thread_task; |
Kurt Hackel | 3156d26 | 2006-05-01 14:39:29 -0700 | [diff] [blame] | 177 | struct workqueue_struct *dlm_worker; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 178 | wait_queue_head_t dlm_thread_wq; |
| 179 | wait_queue_head_t dlm_reco_thread_wq; |
| 180 | wait_queue_head_t ast_wq; |
| 181 | wait_queue_head_t migration_wq; |
| 182 | |
| 183 | struct work_struct dispatched_work; |
| 184 | struct list_head work_list; |
| 185 | spinlock_t work_lock; |
| 186 | struct list_head dlm_domain_handlers; |
| 187 | struct list_head dlm_eviction_callbacks; |
Joel Becker | d24fbcd | 2008-01-25 17:02:21 -0800 | [diff] [blame] | 188 | |
| 189 | /* The filesystem specifies this at domain registration. We |
| 190 | * cache it here to know what to tell other nodes. */ |
| 191 | struct dlm_protocol_version fs_locking_proto; |
| 192 | /* This is the inter-dlm communication version */ |
| 193 | struct dlm_protocol_version dlm_locking_proto; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
Daniel Phillips | 03d864c | 2006-03-10 18:08:16 -0800 | [diff] [blame] | 196 | static inline struct hlist_head *dlm_lockres_hash(struct dlm_ctxt *dlm, unsigned i) |
| 197 | { |
| 198 | return dlm->lockres_hash[(i / DLM_BUCKETS_PER_PAGE) % DLM_HASH_PAGES] + (i % DLM_BUCKETS_PER_PAGE); |
| 199 | } |
| 200 | |
Sunil Mushran | e2b66dd | 2009-02-26 15:00:40 -0800 | [diff] [blame] | 201 | static inline struct hlist_head *dlm_master_hash(struct dlm_ctxt *dlm, |
| 202 | unsigned i) |
| 203 | { |
| 204 | return dlm->master_hash[(i / DLM_BUCKETS_PER_PAGE) % DLM_HASH_PAGES] + |
| 205 | (i % DLM_BUCKETS_PER_PAGE); |
| 206 | } |
| 207 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 208 | /* these keventd work queue items are for less-frequently |
| 209 | * called functions that cannot be directly called from the |
| 210 | * net message handlers for some reason, usually because |
| 211 | * they need to send net messages of their own. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 212 | void dlm_dispatch_work(struct work_struct *work); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 213 | |
| 214 | struct dlm_lock_resource; |
| 215 | struct dlm_work_item; |
| 216 | |
| 217 | typedef void (dlm_workfunc_t)(struct dlm_work_item *, void *); |
| 218 | |
| 219 | struct dlm_request_all_locks_priv |
| 220 | { |
| 221 | u8 reco_master; |
| 222 | u8 dead_node; |
| 223 | }; |
| 224 | |
| 225 | struct dlm_mig_lockres_priv |
| 226 | { |
| 227 | struct dlm_lock_resource *lockres; |
| 228 | u8 real_master; |
Sunil Mushran | 52987e2 | 2008-03-01 14:04:21 -0800 | [diff] [blame] | 229 | u8 extra_ref; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | struct dlm_assert_master_priv |
| 233 | { |
| 234 | struct dlm_lock_resource *lockres; |
| 235 | u8 request_from; |
| 236 | u32 flags; |
| 237 | unsigned ignore_higher:1; |
| 238 | }; |
| 239 | |
Sunil Mushran | f3f8546 | 2007-01-29 15:19:16 -0800 | [diff] [blame] | 240 | struct dlm_deref_lockres_priv |
| 241 | { |
| 242 | struct dlm_lock_resource *deref_res; |
| 243 | u8 deref_node; |
| 244 | }; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 245 | |
| 246 | struct dlm_work_item |
| 247 | { |
| 248 | struct list_head list; |
| 249 | dlm_workfunc_t *func; |
| 250 | struct dlm_ctxt *dlm; |
| 251 | void *data; |
| 252 | union { |
| 253 | struct dlm_request_all_locks_priv ral; |
| 254 | struct dlm_mig_lockres_priv ml; |
| 255 | struct dlm_assert_master_priv am; |
Sunil Mushran | f3f8546 | 2007-01-29 15:19:16 -0800 | [diff] [blame] | 256 | struct dlm_deref_lockres_priv dl; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 257 | } u; |
| 258 | }; |
| 259 | |
| 260 | static inline void dlm_init_work_item(struct dlm_ctxt *dlm, |
| 261 | struct dlm_work_item *i, |
| 262 | dlm_workfunc_t *f, void *data) |
| 263 | { |
| 264 | memset(i, 0, sizeof(*i)); |
| 265 | i->func = f; |
| 266 | INIT_LIST_HEAD(&i->list); |
| 267 | i->data = data; |
| 268 | i->dlm = dlm; /* must have already done a dlm_grab on this! */ |
| 269 | } |
| 270 | |
| 271 | |
| 272 | |
| 273 | static inline void __dlm_set_joining_node(struct dlm_ctxt *dlm, |
| 274 | u8 node) |
| 275 | { |
| 276 | assert_spin_locked(&dlm->spinlock); |
| 277 | |
| 278 | dlm->joining_node = node; |
| 279 | wake_up(&dlm->dlm_join_events); |
| 280 | } |
| 281 | |
| 282 | #define DLM_LOCK_RES_UNINITED 0x00000001 |
| 283 | #define DLM_LOCK_RES_RECOVERING 0x00000002 |
| 284 | #define DLM_LOCK_RES_READY 0x00000004 |
| 285 | #define DLM_LOCK_RES_DIRTY 0x00000008 |
| 286 | #define DLM_LOCK_RES_IN_PROGRESS 0x00000010 |
| 287 | #define DLM_LOCK_RES_MIGRATING 0x00000020 |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 288 | #define DLM_LOCK_RES_DROPPING_REF 0x00000040 |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 289 | #define DLM_LOCK_RES_BLOCK_DIRTY 0x00001000 |
Kurt Hackel | 3b8118c | 2007-01-17 17:05:53 -0800 | [diff] [blame] | 290 | #define DLM_LOCK_RES_SETREF_INPROG 0x00002000 |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 291 | |
Kurt Hackel | 44465a7 | 2006-01-18 17:05:38 -0800 | [diff] [blame] | 292 | /* max milliseconds to wait to sync up a network failure with a node death */ |
| 293 | #define DLM_NODE_DEATH_WAIT_MAX (5 * 1000) |
| 294 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 295 | #define DLM_PURGE_INTERVAL_MS (8 * 1000) |
| 296 | |
| 297 | struct dlm_lock_resource |
| 298 | { |
| 299 | /* WARNING: Please see the comment in dlm_init_lockres before |
| 300 | * adding fields here. */ |
Mark Fasheh | 81f2094 | 2006-02-28 17:31:22 -0800 | [diff] [blame] | 301 | struct hlist_node hash_node; |
Mark Fasheh | 65c491d | 2006-03-06 15:36:17 -0800 | [diff] [blame] | 302 | struct qstr lockname; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 303 | struct kref refs; |
| 304 | |
Kurt Hackel | 6ff06a9 | 2006-05-01 11:51:45 -0700 | [diff] [blame] | 305 | /* |
| 306 | * Please keep granted, converting, and blocked in this order, |
| 307 | * as some funcs want to iterate over all lists. |
| 308 | * |
| 309 | * All four lists are protected by the hash's reference. |
| 310 | */ |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 311 | struct list_head granted; |
| 312 | struct list_head converting; |
| 313 | struct list_head blocked; |
Kurt Hackel | 6ff06a9 | 2006-05-01 11:51:45 -0700 | [diff] [blame] | 314 | struct list_head purge; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 315 | |
Kurt Hackel | 6ff06a9 | 2006-05-01 11:51:45 -0700 | [diff] [blame] | 316 | /* |
| 317 | * These two lists require you to hold an additional reference |
| 318 | * while they are on the list. |
| 319 | */ |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 320 | struct list_head dirty; |
| 321 | struct list_head recovering; // dlm_recovery_ctxt.resources list |
| 322 | |
Sunil Mushran | 29576f8 | 2008-03-10 15:16:21 -0700 | [diff] [blame] | 323 | /* Added during init and removed during release */ |
| 324 | struct list_head tracking; /* dlm->tracking_list */ |
| 325 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 326 | /* unused lock resources have their last_used stamped and are |
| 327 | * put on a list for the dlm thread to run. */ |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 328 | unsigned long last_used; |
| 329 | |
Sunil Mushran | b0d4f817 | 2008-12-16 15:49:22 -0800 | [diff] [blame] | 330 | struct dlm_ctxt *dlm; |
| 331 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 332 | unsigned migration_pending:1; |
| 333 | atomic_t asts_reserved; |
| 334 | spinlock_t spinlock; |
| 335 | wait_queue_head_t wq; |
| 336 | u8 owner; //node which owns the lock resource, or unknown |
| 337 | u16 state; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 338 | char lvb[DLM_LVB_LEN]; |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 339 | unsigned int inflight_locks; |
| 340 | unsigned long refmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | struct dlm_migratable_lock |
| 344 | { |
| 345 | __be64 cookie; |
| 346 | |
| 347 | /* these 3 are just padding for the in-memory structure, but |
| 348 | * list and flags are actually used when sent over the wire */ |
| 349 | __be16 pad1; |
| 350 | u8 list; // 0=granted, 1=converting, 2=blocked |
| 351 | u8 flags; |
| 352 | |
| 353 | s8 type; |
| 354 | s8 convert_type; |
| 355 | s8 highest_blocked; |
| 356 | u8 node; |
| 357 | }; // 16 bytes |
| 358 | |
| 359 | struct dlm_lock |
| 360 | { |
| 361 | struct dlm_migratable_lock ml; |
| 362 | |
| 363 | struct list_head list; |
| 364 | struct list_head ast_list; |
| 365 | struct list_head bast_list; |
| 366 | struct dlm_lock_resource *lockres; |
| 367 | spinlock_t spinlock; |
| 368 | struct kref lock_refs; |
| 369 | |
| 370 | // ast and bast must be callable while holding a spinlock! |
| 371 | dlm_astlockfunc_t *ast; |
| 372 | dlm_bastlockfunc_t *bast; |
| 373 | void *astdata; |
| 374 | struct dlm_lockstatus *lksb; |
| 375 | unsigned ast_pending:1, |
| 376 | bast_pending:1, |
| 377 | convert_pending:1, |
| 378 | lock_pending:1, |
| 379 | cancel_pending:1, |
| 380 | unlock_pending:1, |
| 381 | lksb_kernel_allocated:1; |
| 382 | }; |
| 383 | |
| 384 | |
| 385 | #define DLM_LKSB_UNUSED1 0x01 |
| 386 | #define DLM_LKSB_PUT_LVB 0x02 |
| 387 | #define DLM_LKSB_GET_LVB 0x04 |
| 388 | #define DLM_LKSB_UNUSED2 0x08 |
| 389 | #define DLM_LKSB_UNUSED3 0x10 |
| 390 | #define DLM_LKSB_UNUSED4 0x20 |
| 391 | #define DLM_LKSB_UNUSED5 0x40 |
| 392 | #define DLM_LKSB_UNUSED6 0x80 |
| 393 | |
| 394 | |
| 395 | enum dlm_lockres_list { |
| 396 | DLM_GRANTED_LIST = 0, |
| 397 | DLM_CONVERTING_LIST, |
| 398 | DLM_BLOCKED_LIST |
| 399 | }; |
| 400 | |
Kurt Hackel | 8bc674c | 2006-04-27 18:02:10 -0700 | [diff] [blame] | 401 | static inline int dlm_lvb_is_empty(char *lvb) |
| 402 | { |
| 403 | int i; |
| 404 | for (i=0; i<DLM_LVB_LEN; i++) |
| 405 | if (lvb[i]) |
| 406 | return 0; |
| 407 | return 1; |
| 408 | } |
| 409 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 410 | static inline struct list_head * |
| 411 | dlm_list_idx_to_ptr(struct dlm_lock_resource *res, enum dlm_lockres_list idx) |
| 412 | { |
| 413 | struct list_head *ret = NULL; |
| 414 | if (idx == DLM_GRANTED_LIST) |
| 415 | ret = &res->granted; |
| 416 | else if (idx == DLM_CONVERTING_LIST) |
| 417 | ret = &res->converting; |
| 418 | else if (idx == DLM_BLOCKED_LIST) |
| 419 | ret = &res->blocked; |
| 420 | else |
| 421 | BUG(); |
| 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | struct dlm_node_iter |
| 429 | { |
| 430 | unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
| 431 | int curnode; |
| 432 | }; |
| 433 | |
| 434 | |
| 435 | enum { |
| 436 | DLM_MASTER_REQUEST_MSG = 500, |
| 437 | DLM_UNUSED_MSG1, /* 501 */ |
| 438 | DLM_ASSERT_MASTER_MSG, /* 502 */ |
| 439 | DLM_CREATE_LOCK_MSG, /* 503 */ |
| 440 | DLM_CONVERT_LOCK_MSG, /* 504 */ |
| 441 | DLM_PROXY_AST_MSG, /* 505 */ |
| 442 | DLM_UNLOCK_LOCK_MSG, /* 506 */ |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 443 | DLM_DEREF_LOCKRES_MSG, /* 507 */ |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 444 | DLM_MIGRATE_REQUEST_MSG, /* 508 */ |
| 445 | DLM_MIG_LOCKRES_MSG, /* 509 */ |
| 446 | DLM_QUERY_JOIN_MSG, /* 510 */ |
| 447 | DLM_ASSERT_JOINED_MSG, /* 511 */ |
| 448 | DLM_CANCEL_JOIN_MSG, /* 512 */ |
| 449 | DLM_EXIT_DOMAIN_MSG, /* 513 */ |
| 450 | DLM_MASTER_REQUERY_MSG, /* 514 */ |
| 451 | DLM_LOCK_REQUEST_MSG, /* 515 */ |
| 452 | DLM_RECO_DATA_DONE_MSG, /* 516 */ |
| 453 | DLM_BEGIN_RECO_MSG, /* 517 */ |
| 454 | DLM_FINALIZE_RECO_MSG /* 518 */ |
| 455 | }; |
| 456 | |
| 457 | struct dlm_reco_node_data |
| 458 | { |
| 459 | int state; |
| 460 | u8 node_num; |
| 461 | struct list_head list; |
| 462 | }; |
| 463 | |
| 464 | enum { |
| 465 | DLM_RECO_NODE_DATA_DEAD = -1, |
| 466 | DLM_RECO_NODE_DATA_INIT = 0, |
| 467 | DLM_RECO_NODE_DATA_REQUESTING, |
| 468 | DLM_RECO_NODE_DATA_REQUESTED, |
| 469 | DLM_RECO_NODE_DATA_RECEIVING, |
| 470 | DLM_RECO_NODE_DATA_DONE, |
| 471 | DLM_RECO_NODE_DATA_FINALIZE_SENT, |
| 472 | }; |
| 473 | |
| 474 | |
| 475 | enum { |
| 476 | DLM_MASTER_RESP_NO = 0, |
| 477 | DLM_MASTER_RESP_YES, |
| 478 | DLM_MASTER_RESP_MAYBE, |
| 479 | DLM_MASTER_RESP_ERROR |
| 480 | }; |
| 481 | |
| 482 | |
| 483 | struct dlm_master_request |
| 484 | { |
| 485 | u8 node_idx; |
| 486 | u8 namelen; |
| 487 | __be16 pad1; |
| 488 | __be32 flags; |
| 489 | |
| 490 | u8 name[O2NM_MAX_NAME_LEN]; |
| 491 | }; |
| 492 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 493 | #define DLM_ASSERT_RESPONSE_REASSERT 0x00000001 |
| 494 | #define DLM_ASSERT_RESPONSE_MASTERY_REF 0x00000002 |
| 495 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 496 | #define DLM_ASSERT_MASTER_MLE_CLEANUP 0x00000001 |
| 497 | #define DLM_ASSERT_MASTER_REQUERY 0x00000002 |
| 498 | #define DLM_ASSERT_MASTER_FINISH_MIGRATION 0x00000004 |
| 499 | struct dlm_assert_master |
| 500 | { |
| 501 | u8 node_idx; |
| 502 | u8 namelen; |
| 503 | __be16 pad1; |
| 504 | __be32 flags; |
| 505 | |
| 506 | u8 name[O2NM_MAX_NAME_LEN]; |
| 507 | }; |
| 508 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 509 | #define DLM_MIGRATE_RESPONSE_MASTERY_REF 0x00000001 |
| 510 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 511 | struct dlm_migrate_request |
| 512 | { |
| 513 | u8 master; |
| 514 | u8 new_master; |
| 515 | u8 namelen; |
| 516 | u8 pad1; |
| 517 | __be32 pad2; |
| 518 | u8 name[O2NM_MAX_NAME_LEN]; |
| 519 | }; |
| 520 | |
| 521 | struct dlm_master_requery |
| 522 | { |
| 523 | u8 pad1; |
| 524 | u8 pad2; |
| 525 | u8 node_idx; |
| 526 | u8 namelen; |
| 527 | __be32 pad3; |
| 528 | u8 name[O2NM_MAX_NAME_LEN]; |
| 529 | }; |
| 530 | |
| 531 | #define DLM_MRES_RECOVERY 0x01 |
| 532 | #define DLM_MRES_MIGRATION 0x02 |
| 533 | #define DLM_MRES_ALL_DONE 0x04 |
| 534 | |
| 535 | /* |
| 536 | * We would like to get one whole lockres into a single network |
| 537 | * message whenever possible. Generally speaking, there will be |
| 538 | * at most one dlm_lock on a lockres for each node in the cluster, |
| 539 | * plus (infrequently) any additional locks coming in from userdlm. |
| 540 | * |
| 541 | * struct _dlm_lockres_page |
| 542 | * { |
| 543 | * dlm_migratable_lockres mres; |
| 544 | * dlm_migratable_lock ml[DLM_MAX_MIGRATABLE_LOCKS]; |
| 545 | * u8 pad[DLM_MIG_LOCKRES_RESERVED]; |
| 546 | * }; |
| 547 | * |
| 548 | * from ../cluster/tcp.h |
| 549 | * NET_MAX_PAYLOAD_BYTES (4096 - sizeof(net_msg)) |
| 550 | * (roughly 4080 bytes) |
| 551 | * and sizeof(dlm_migratable_lockres) = 112 bytes |
| 552 | * and sizeof(dlm_migratable_lock) = 16 bytes |
| 553 | * |
| 554 | * Choosing DLM_MAX_MIGRATABLE_LOCKS=240 and |
| 555 | * DLM_MIG_LOCKRES_RESERVED=128 means we have this: |
| 556 | * |
| 557 | * (DLM_MAX_MIGRATABLE_LOCKS * sizeof(dlm_migratable_lock)) + |
| 558 | * sizeof(dlm_migratable_lockres) + DLM_MIG_LOCKRES_RESERVED = |
| 559 | * NET_MAX_PAYLOAD_BYTES |
| 560 | * (240 * 16) + 112 + 128 = 4080 |
| 561 | * |
| 562 | * So a lockres would need more than 240 locks before it would |
| 563 | * use more than one network packet to recover. Not too bad. |
| 564 | */ |
| 565 | #define DLM_MAX_MIGRATABLE_LOCKS 240 |
| 566 | |
| 567 | struct dlm_migratable_lockres |
| 568 | { |
| 569 | u8 master; |
| 570 | u8 lockname_len; |
| 571 | u8 num_locks; // locks sent in this structure |
| 572 | u8 flags; |
| 573 | __be32 total_locks; // locks to be sent for this migration cookie |
| 574 | __be64 mig_cookie; // cookie for this lockres migration |
| 575 | // or zero if not needed |
| 576 | // 16 bytes |
| 577 | u8 lockname[DLM_LOCKID_NAME_MAX]; |
| 578 | // 48 bytes |
| 579 | u8 lvb[DLM_LVB_LEN]; |
| 580 | // 112 bytes |
| 581 | struct dlm_migratable_lock ml[0]; // 16 bytes each, begins at byte 112 |
| 582 | }; |
| 583 | #define DLM_MIG_LOCKRES_MAX_LEN \ |
| 584 | (sizeof(struct dlm_migratable_lockres) + \ |
| 585 | (sizeof(struct dlm_migratable_lock) * \ |
| 586 | DLM_MAX_MIGRATABLE_LOCKS) ) |
| 587 | |
| 588 | /* from above, 128 bytes |
| 589 | * for some undetermined future use */ |
| 590 | #define DLM_MIG_LOCKRES_RESERVED (NET_MAX_PAYLOAD_BYTES - \ |
| 591 | DLM_MIG_LOCKRES_MAX_LEN) |
| 592 | |
| 593 | struct dlm_create_lock |
| 594 | { |
| 595 | __be64 cookie; |
| 596 | |
| 597 | __be32 flags; |
| 598 | u8 pad1; |
| 599 | u8 node_idx; |
| 600 | s8 requested_type; |
| 601 | u8 namelen; |
| 602 | |
| 603 | u8 name[O2NM_MAX_NAME_LEN]; |
| 604 | }; |
| 605 | |
| 606 | struct dlm_convert_lock |
| 607 | { |
| 608 | __be64 cookie; |
| 609 | |
| 610 | __be32 flags; |
| 611 | u8 pad1; |
| 612 | u8 node_idx; |
| 613 | s8 requested_type; |
| 614 | u8 namelen; |
| 615 | |
| 616 | u8 name[O2NM_MAX_NAME_LEN]; |
| 617 | |
| 618 | s8 lvb[0]; |
| 619 | }; |
| 620 | #define DLM_CONVERT_LOCK_MAX_LEN (sizeof(struct dlm_convert_lock)+DLM_LVB_LEN) |
| 621 | |
| 622 | struct dlm_unlock_lock |
| 623 | { |
| 624 | __be64 cookie; |
| 625 | |
| 626 | __be32 flags; |
| 627 | __be16 pad1; |
| 628 | u8 node_idx; |
| 629 | u8 namelen; |
| 630 | |
| 631 | u8 name[O2NM_MAX_NAME_LEN]; |
| 632 | |
| 633 | s8 lvb[0]; |
| 634 | }; |
| 635 | #define DLM_UNLOCK_LOCK_MAX_LEN (sizeof(struct dlm_unlock_lock)+DLM_LVB_LEN) |
| 636 | |
| 637 | struct dlm_proxy_ast |
| 638 | { |
| 639 | __be64 cookie; |
| 640 | |
| 641 | __be32 flags; |
| 642 | u8 node_idx; |
| 643 | u8 type; |
| 644 | u8 blocked_type; |
| 645 | u8 namelen; |
| 646 | |
| 647 | u8 name[O2NM_MAX_NAME_LEN]; |
| 648 | |
| 649 | s8 lvb[0]; |
| 650 | }; |
| 651 | #define DLM_PROXY_AST_MAX_LEN (sizeof(struct dlm_proxy_ast)+DLM_LVB_LEN) |
| 652 | |
| 653 | #define DLM_MOD_KEY (0x666c6172) |
Joel Becker | d24fbcd | 2008-01-25 17:02:21 -0800 | [diff] [blame] | 654 | enum dlm_query_join_response_code { |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 655 | JOIN_DISALLOW = 0, |
| 656 | JOIN_OK, |
| 657 | JOIN_OK_NO_MAP, |
Joel Becker | d24fbcd | 2008-01-25 17:02:21 -0800 | [diff] [blame] | 658 | JOIN_PROTOCOL_MISMATCH, |
| 659 | }; |
| 660 | |
Joel Becker | 0f71b7b | 2008-02-12 14:56:25 -0800 | [diff] [blame] | 661 | struct dlm_query_join_packet { |
| 662 | u8 code; /* Response code. dlm_minor and fs_minor |
| 663 | are only valid if this is JOIN_OK */ |
| 664 | u8 dlm_minor; /* The minor version of the protocol the |
| 665 | dlm is speaking. */ |
| 666 | u8 fs_minor; /* The minor version of the protocol the |
| 667 | filesystem is speaking. */ |
| 668 | u8 reserved; |
| 669 | }; |
| 670 | |
Joel Becker | d24fbcd | 2008-01-25 17:02:21 -0800 | [diff] [blame] | 671 | union dlm_query_join_response { |
| 672 | u32 intval; |
Joel Becker | 0f71b7b | 2008-02-12 14:56:25 -0800 | [diff] [blame] | 673 | struct dlm_query_join_packet packet; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 674 | }; |
| 675 | |
| 676 | struct dlm_lock_request |
| 677 | { |
| 678 | u8 node_idx; |
| 679 | u8 dead_node; |
| 680 | __be16 pad1; |
| 681 | __be32 pad2; |
| 682 | }; |
| 683 | |
| 684 | struct dlm_reco_data_done |
| 685 | { |
| 686 | u8 node_idx; |
| 687 | u8 dead_node; |
| 688 | __be16 pad1; |
| 689 | __be32 pad2; |
| 690 | |
| 691 | /* unused for now */ |
| 692 | /* eventually we can use this to attempt |
| 693 | * lvb recovery based on each node's info */ |
| 694 | u8 reco_lvb[DLM_LVB_LEN]; |
| 695 | }; |
| 696 | |
| 697 | struct dlm_begin_reco |
| 698 | { |
| 699 | u8 node_idx; |
| 700 | u8 dead_node; |
| 701 | __be16 pad1; |
| 702 | __be32 pad2; |
| 703 | }; |
| 704 | |
| 705 | |
Srinivas Eeda | 1faf289 | 2007-01-29 15:31:35 -0800 | [diff] [blame] | 706 | #define BITS_PER_BYTE 8 |
| 707 | #define BITS_TO_BYTES(bits) (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE) |
| 708 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 709 | struct dlm_query_join_request |
| 710 | { |
| 711 | u8 node_idx; |
| 712 | u8 pad1[2]; |
| 713 | u8 name_len; |
Joel Becker | d24fbcd | 2008-01-25 17:02:21 -0800 | [diff] [blame] | 714 | struct dlm_protocol_version dlm_proto; |
| 715 | struct dlm_protocol_version fs_proto; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 716 | u8 domain[O2NM_MAX_NAME_LEN]; |
Srinivas Eeda | 1faf289 | 2007-01-29 15:31:35 -0800 | [diff] [blame] | 717 | u8 node_map[BITS_TO_BYTES(O2NM_MAX_NODES)]; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 718 | }; |
| 719 | |
| 720 | struct dlm_assert_joined |
| 721 | { |
| 722 | u8 node_idx; |
| 723 | u8 pad1[2]; |
| 724 | u8 name_len; |
| 725 | u8 domain[O2NM_MAX_NAME_LEN]; |
| 726 | }; |
| 727 | |
| 728 | struct dlm_cancel_join |
| 729 | { |
| 730 | u8 node_idx; |
| 731 | u8 pad1[2]; |
| 732 | u8 name_len; |
| 733 | u8 domain[O2NM_MAX_NAME_LEN]; |
| 734 | }; |
| 735 | |
| 736 | struct dlm_exit_domain |
| 737 | { |
| 738 | u8 node_idx; |
| 739 | u8 pad1[3]; |
| 740 | }; |
| 741 | |
| 742 | struct dlm_finalize_reco |
| 743 | { |
| 744 | u8 node_idx; |
| 745 | u8 dead_node; |
Kurt Hackel | 466d1a4 | 2006-05-01 11:11:13 -0700 | [diff] [blame] | 746 | u8 flags; |
| 747 | u8 pad1; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 748 | __be32 pad2; |
| 749 | }; |
| 750 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 751 | struct dlm_deref_lockres |
| 752 | { |
| 753 | u32 pad1; |
| 754 | u16 pad2; |
| 755 | u8 node_idx; |
| 756 | u8 namelen; |
| 757 | |
| 758 | u8 name[O2NM_MAX_NAME_LEN]; |
| 759 | }; |
| 760 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 761 | static inline enum dlm_status |
| 762 | __dlm_lockres_state_to_status(struct dlm_lock_resource *res) |
| 763 | { |
| 764 | enum dlm_status status = DLM_NORMAL; |
| 765 | |
| 766 | assert_spin_locked(&res->spinlock); |
| 767 | |
| 768 | if (res->state & DLM_LOCK_RES_RECOVERING) |
| 769 | status = DLM_RECOVERING; |
| 770 | else if (res->state & DLM_LOCK_RES_MIGRATING) |
| 771 | status = DLM_MIGRATING; |
| 772 | else if (res->state & DLM_LOCK_RES_IN_PROGRESS) |
| 773 | status = DLM_FORWARD; |
| 774 | |
| 775 | return status; |
| 776 | } |
| 777 | |
Kurt Hackel | 2900485 | 2006-03-02 16:43:36 -0800 | [diff] [blame] | 778 | static inline u8 dlm_get_lock_cookie_node(u64 cookie) |
| 779 | { |
| 780 | u8 ret; |
| 781 | cookie >>= 56; |
| 782 | ret = (u8)(cookie & 0xffULL); |
| 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | static inline unsigned long long dlm_get_lock_cookie_seq(u64 cookie) |
| 787 | { |
| 788 | unsigned long long ret; |
| 789 | ret = ((unsigned long long)cookie) & 0x00ffffffffffffffULL; |
| 790 | return ret; |
| 791 | } |
| 792 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 793 | struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie, |
| 794 | struct dlm_lockstatus *lksb); |
| 795 | void dlm_lock_get(struct dlm_lock *lock); |
| 796 | void dlm_lock_put(struct dlm_lock *lock); |
| 797 | |
| 798 | void dlm_lock_attach_lockres(struct dlm_lock *lock, |
| 799 | struct dlm_lock_resource *res); |
| 800 | |
Kurt Hackel | d74c980 | 2007-01-17 17:04:25 -0800 | [diff] [blame] | 801 | int dlm_create_lock_handler(struct o2net_msg *msg, u32 len, void *data, |
| 802 | void **ret_data); |
| 803 | int dlm_convert_lock_handler(struct o2net_msg *msg, u32 len, void *data, |
| 804 | void **ret_data); |
| 805 | int dlm_proxy_ast_handler(struct o2net_msg *msg, u32 len, void *data, |
| 806 | void **ret_data); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 807 | |
| 808 | void dlm_revert_pending_convert(struct dlm_lock_resource *res, |
| 809 | struct dlm_lock *lock); |
| 810 | void dlm_revert_pending_lock(struct dlm_lock_resource *res, |
| 811 | struct dlm_lock *lock); |
| 812 | |
Kurt Hackel | d74c980 | 2007-01-17 17:04:25 -0800 | [diff] [blame] | 813 | int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data, |
| 814 | void **ret_data); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 815 | void dlm_commit_pending_cancel(struct dlm_lock_resource *res, |
| 816 | struct dlm_lock *lock); |
| 817 | void dlm_commit_pending_unlock(struct dlm_lock_resource *res, |
| 818 | struct dlm_lock *lock); |
| 819 | |
| 820 | int dlm_launch_thread(struct dlm_ctxt *dlm); |
| 821 | void dlm_complete_thread(struct dlm_ctxt *dlm); |
| 822 | int dlm_launch_recovery_thread(struct dlm_ctxt *dlm); |
| 823 | void dlm_complete_recovery_thread(struct dlm_ctxt *dlm); |
| 824 | void dlm_wait_for_recovery(struct dlm_ctxt *dlm); |
Kurt Hackel | c03872f | 2006-03-06 14:08:49 -0800 | [diff] [blame] | 825 | void dlm_kick_recovery_thread(struct dlm_ctxt *dlm); |
Kurt Hackel | e2faea4 | 2006-01-12 14:24:55 -0800 | [diff] [blame] | 826 | int dlm_is_node_dead(struct dlm_ctxt *dlm, u8 node); |
Kurt Hackel | 44465a7 | 2006-01-18 17:05:38 -0800 | [diff] [blame] | 827 | int dlm_wait_for_node_death(struct dlm_ctxt *dlm, u8 node, int timeout); |
Kurt Hackel | b7084ab | 2006-05-01 13:54:07 -0700 | [diff] [blame] | 828 | int dlm_wait_for_node_recovery(struct dlm_ctxt *dlm, u8 node, int timeout); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 829 | |
| 830 | void dlm_put(struct dlm_ctxt *dlm); |
| 831 | struct dlm_ctxt *dlm_grab(struct dlm_ctxt *dlm); |
| 832 | int dlm_domain_fully_joined(struct dlm_ctxt *dlm); |
| 833 | |
| 834 | void __dlm_lockres_calc_usage(struct dlm_ctxt *dlm, |
| 835 | struct dlm_lock_resource *res); |
| 836 | void dlm_lockres_calc_usage(struct dlm_ctxt *dlm, |
| 837 | struct dlm_lock_resource *res); |
Mark Fasheh | 95c4f58 | 2006-03-10 13:44:00 -0800 | [diff] [blame] | 838 | static inline void dlm_lockres_get(struct dlm_lock_resource *res) |
| 839 | { |
| 840 | /* This is called on every lookup, so it might be worth |
| 841 | * inlining. */ |
| 842 | kref_get(&res->refs); |
| 843 | } |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 844 | void dlm_lockres_put(struct dlm_lock_resource *res); |
| 845 | void __dlm_unhash_lockres(struct dlm_lock_resource *res); |
| 846 | void __dlm_insert_lockres(struct dlm_ctxt *dlm, |
| 847 | struct dlm_lock_resource *res); |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 848 | struct dlm_lock_resource * __dlm_lookup_lockres_full(struct dlm_ctxt *dlm, |
| 849 | const char *name, |
| 850 | unsigned int len, |
| 851 | unsigned int hash); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 852 | struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm, |
| 853 | const char *name, |
Mark Fasheh | a3d3329 | 2006-03-09 17:55:56 -0800 | [diff] [blame] | 854 | unsigned int len, |
| 855 | unsigned int hash); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 856 | struct dlm_lock_resource * dlm_lookup_lockres(struct dlm_ctxt *dlm, |
| 857 | const char *name, |
| 858 | unsigned int len); |
| 859 | |
| 860 | int dlm_is_host_down(int errno); |
| 861 | void dlm_change_lockres_owner(struct dlm_ctxt *dlm, |
| 862 | struct dlm_lock_resource *res, |
| 863 | u8 owner); |
| 864 | struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm, |
| 865 | const char *lockid, |
Mark Fasheh | 3384f3d | 2006-09-08 11:38:29 -0700 | [diff] [blame] | 866 | int namelen, |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 867 | int flags); |
| 868 | struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm, |
| 869 | const char *name, |
| 870 | unsigned int namelen); |
| 871 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 872 | #define dlm_lockres_set_refmap_bit(bit,res) \ |
| 873 | __dlm_lockres_set_refmap_bit(bit,res,__FILE__,__LINE__) |
| 874 | #define dlm_lockres_clear_refmap_bit(bit,res) \ |
| 875 | __dlm_lockres_clear_refmap_bit(bit,res,__FILE__,__LINE__) |
| 876 | |
| 877 | static inline void __dlm_lockres_set_refmap_bit(int bit, |
| 878 | struct dlm_lock_resource *res, |
| 879 | const char *file, |
| 880 | int line) |
| 881 | { |
| 882 | //printk("%s:%d:%.*s: setting bit %d\n", file, line, |
| 883 | // res->lockname.len, res->lockname.name, bit); |
| 884 | set_bit(bit, res->refmap); |
| 885 | } |
| 886 | |
| 887 | static inline void __dlm_lockres_clear_refmap_bit(int bit, |
| 888 | struct dlm_lock_resource *res, |
| 889 | const char *file, |
| 890 | int line) |
| 891 | { |
| 892 | //printk("%s:%d:%.*s: clearing bit %d\n", file, line, |
| 893 | // res->lockname.len, res->lockname.name, bit); |
| 894 | clear_bit(bit, res->refmap); |
| 895 | } |
| 896 | |
| 897 | void __dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, |
| 898 | struct dlm_lock_resource *res, |
| 899 | const char *file, |
| 900 | int line); |
| 901 | void __dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, |
| 902 | struct dlm_lock_resource *res, |
| 903 | int new_lockres, |
| 904 | const char *file, |
| 905 | int line); |
| 906 | #define dlm_lockres_drop_inflight_ref(d,r) \ |
| 907 | __dlm_lockres_drop_inflight_ref(d,r,__FILE__,__LINE__) |
| 908 | #define dlm_lockres_grab_inflight_ref(d,r) \ |
| 909 | __dlm_lockres_grab_inflight_ref(d,r,0,__FILE__,__LINE__) |
| 910 | #define dlm_lockres_grab_inflight_ref_new(d,r) \ |
| 911 | __dlm_lockres_grab_inflight_ref(d,r,1,__FILE__,__LINE__) |
| 912 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 913 | void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock); |
| 914 | void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock); |
| 915 | void dlm_do_local_ast(struct dlm_ctxt *dlm, |
| 916 | struct dlm_lock_resource *res, |
| 917 | struct dlm_lock *lock); |
| 918 | int dlm_do_remote_ast(struct dlm_ctxt *dlm, |
| 919 | struct dlm_lock_resource *res, |
| 920 | struct dlm_lock *lock); |
| 921 | void dlm_do_local_bast(struct dlm_ctxt *dlm, |
| 922 | struct dlm_lock_resource *res, |
| 923 | struct dlm_lock *lock, |
| 924 | int blocked_type); |
| 925 | int dlm_send_proxy_ast_msg(struct dlm_ctxt *dlm, |
| 926 | struct dlm_lock_resource *res, |
| 927 | struct dlm_lock *lock, |
| 928 | int msg_type, |
| 929 | int blocked_type, int flags); |
| 930 | static inline int dlm_send_proxy_bast(struct dlm_ctxt *dlm, |
| 931 | struct dlm_lock_resource *res, |
| 932 | struct dlm_lock *lock, |
| 933 | int blocked_type) |
| 934 | { |
| 935 | return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_BAST, |
| 936 | blocked_type, 0); |
| 937 | } |
| 938 | |
| 939 | static inline int dlm_send_proxy_ast(struct dlm_ctxt *dlm, |
| 940 | struct dlm_lock_resource *res, |
| 941 | struct dlm_lock *lock, |
| 942 | int flags) |
| 943 | { |
| 944 | return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_AST, |
| 945 | 0, flags); |
| 946 | } |
| 947 | |
| 948 | void dlm_print_one_lock_resource(struct dlm_lock_resource *res); |
| 949 | void __dlm_print_one_lock_resource(struct dlm_lock_resource *res); |
| 950 | |
| 951 | u8 dlm_nm_this_node(struct dlm_ctxt *dlm); |
| 952 | void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res); |
| 953 | void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res); |
| 954 | |
| 955 | |
| 956 | int dlm_nm_init(struct dlm_ctxt *dlm); |
| 957 | int dlm_heartbeat_init(struct dlm_ctxt *dlm); |
| 958 | void dlm_hb_node_down_cb(struct o2nm_node *node, int idx, void *data); |
| 959 | void dlm_hb_node_up_cb(struct o2nm_node *node, int idx, void *data); |
| 960 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 961 | int dlm_empty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 962 | int dlm_finish_migration(struct dlm_ctxt *dlm, |
| 963 | struct dlm_lock_resource *res, |
| 964 | u8 old_master); |
| 965 | void dlm_lockres_release_ast(struct dlm_ctxt *dlm, |
| 966 | struct dlm_lock_resource *res); |
| 967 | void __dlm_lockres_reserve_ast(struct dlm_lock_resource *res); |
| 968 | |
Kurt Hackel | d74c980 | 2007-01-17 17:04:25 -0800 | [diff] [blame] | 969 | int dlm_master_request_handler(struct o2net_msg *msg, u32 len, void *data, |
| 970 | void **ret_data); |
| 971 | int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data, |
| 972 | void **ret_data); |
Kurt Hackel | 3b8118c | 2007-01-17 17:05:53 -0800 | [diff] [blame] | 973 | void dlm_assert_master_post_handler(int status, void *data, void *ret_data); |
Kurt Hackel | d74c980 | 2007-01-17 17:04:25 -0800 | [diff] [blame] | 974 | int dlm_deref_lockres_handler(struct o2net_msg *msg, u32 len, void *data, |
| 975 | void **ret_data); |
| 976 | int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data, |
| 977 | void **ret_data); |
| 978 | int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data, |
| 979 | void **ret_data); |
| 980 | int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data, |
| 981 | void **ret_data); |
| 982 | int dlm_request_all_locks_handler(struct o2net_msg *msg, u32 len, void *data, |
| 983 | void **ret_data); |
| 984 | int dlm_reco_data_done_handler(struct o2net_msg *msg, u32 len, void *data, |
| 985 | void **ret_data); |
| 986 | int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data, |
| 987 | void **ret_data); |
| 988 | int dlm_finalize_reco_handler(struct o2net_msg *msg, u32 len, void *data, |
| 989 | void **ret_data); |
Kurt Hackel | c03872f | 2006-03-06 14:08:49 -0800 | [diff] [blame] | 990 | int dlm_do_master_requery(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, |
| 991 | u8 nodenum, u8 *real_master); |
Kurt Hackel | c03872f | 2006-03-06 14:08:49 -0800 | [diff] [blame] | 992 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 993 | |
| 994 | int dlm_dispatch_assert_master(struct dlm_ctxt *dlm, |
| 995 | struct dlm_lock_resource *res, |
| 996 | int ignore_higher, |
| 997 | u8 request_from, |
| 998 | u32 flags); |
| 999 | |
| 1000 | |
| 1001 | int dlm_send_one_lockres(struct dlm_ctxt *dlm, |
| 1002 | struct dlm_lock_resource *res, |
| 1003 | struct dlm_migratable_lockres *mres, |
| 1004 | u8 send_to, |
| 1005 | u8 flags); |
| 1006 | void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm, |
| 1007 | struct dlm_lock_resource *res); |
| 1008 | |
| 1009 | /* will exit holding res->spinlock, but may drop in function */ |
| 1010 | void __dlm_wait_on_lockres_flags(struct dlm_lock_resource *res, int flags); |
| 1011 | void __dlm_wait_on_lockres_flags_set(struct dlm_lock_resource *res, int flags); |
| 1012 | |
| 1013 | /* will exit holding res->spinlock, but may drop in function */ |
| 1014 | static inline void __dlm_wait_on_lockres(struct dlm_lock_resource *res) |
| 1015 | { |
| 1016 | __dlm_wait_on_lockres_flags(res, (DLM_LOCK_RES_IN_PROGRESS| |
| 1017 | DLM_LOCK_RES_RECOVERING| |
| 1018 | DLM_LOCK_RES_MIGRATING)); |
| 1019 | } |
| 1020 | |
Sunil Mushran | 1c08457 | 2009-02-26 15:00:37 -0800 | [diff] [blame] | 1021 | void __dlm_unlink_mle(struct dlm_ctxt *dlm, struct dlm_master_list_entry *mle); |
| 1022 | void __dlm_insert_mle(struct dlm_ctxt *dlm, struct dlm_master_list_entry *mle); |
| 1023 | |
Sunil Mushran | 724bdca | 2008-03-10 15:16:20 -0700 | [diff] [blame] | 1024 | /* create/destroy slab caches */ |
| 1025 | int dlm_init_master_caches(void); |
| 1026 | void dlm_destroy_master_caches(void); |
| 1027 | |
| 1028 | int dlm_init_lock_cache(void); |
| 1029 | void dlm_destroy_lock_cache(void); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1030 | |
| 1031 | int dlm_init_mle_cache(void); |
| 1032 | void dlm_destroy_mle_cache(void); |
Sunil Mushran | 724bdca | 2008-03-10 15:16:20 -0700 | [diff] [blame] | 1033 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1034 | void dlm_hb_event_notify_attached(struct dlm_ctxt *dlm, int idx, int node_up); |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 1035 | int dlm_drop_lockres_ref(struct dlm_ctxt *dlm, |
| 1036 | struct dlm_lock_resource *res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1037 | void dlm_clean_master_list(struct dlm_ctxt *dlm, |
| 1038 | u8 dead_node); |
| 1039 | int dlm_lock_basts_flushed(struct dlm_ctxt *dlm, struct dlm_lock *lock); |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 1040 | int __dlm_lockres_has_locks(struct dlm_lock_resource *res); |
Kurt Hackel | 69d72b0 | 2006-05-01 10:57:51 -0700 | [diff] [blame] | 1041 | int __dlm_lockres_unused(struct dlm_lock_resource *res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1042 | |
| 1043 | static inline const char * dlm_lock_mode_name(int mode) |
| 1044 | { |
| 1045 | switch (mode) { |
| 1046 | case LKM_EXMODE: |
| 1047 | return "EX"; |
| 1048 | case LKM_PRMODE: |
| 1049 | return "PR"; |
| 1050 | case LKM_NLMODE: |
| 1051 | return "NL"; |
| 1052 | } |
| 1053 | return "UNKNOWN"; |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | static inline int dlm_lock_compatible(int existing, int request) |
| 1058 | { |
| 1059 | /* NO_LOCK compatible with all */ |
| 1060 | if (request == LKM_NLMODE || |
| 1061 | existing == LKM_NLMODE) |
| 1062 | return 1; |
| 1063 | |
| 1064 | /* EX incompatible with all non-NO_LOCK */ |
| 1065 | if (request == LKM_EXMODE) |
| 1066 | return 0; |
| 1067 | |
| 1068 | /* request must be PR, which is compatible with PR */ |
| 1069 | if (existing == LKM_PRMODE) |
| 1070 | return 1; |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | static inline int dlm_lock_on_list(struct list_head *head, |
| 1076 | struct dlm_lock *lock) |
| 1077 | { |
| 1078 | struct list_head *iter; |
| 1079 | struct dlm_lock *tmplock; |
| 1080 | |
| 1081 | list_for_each(iter, head) { |
| 1082 | tmplock = list_entry(iter, struct dlm_lock, list); |
| 1083 | if (tmplock == lock) |
| 1084 | return 1; |
| 1085 | } |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | static inline enum dlm_status dlm_err_to_dlm_status(int err) |
| 1091 | { |
| 1092 | enum dlm_status ret; |
| 1093 | if (err == -ENOMEM) |
| 1094 | ret = DLM_SYSERR; |
| 1095 | else if (err == -ETIMEDOUT || o2net_link_down(err, NULL)) |
| 1096 | ret = DLM_NOLOCKMGR; |
| 1097 | else if (err == -EINVAL) |
| 1098 | ret = DLM_BADPARAM; |
| 1099 | else if (err == -ENAMETOOLONG) |
| 1100 | ret = DLM_IVBUFLEN; |
| 1101 | else |
| 1102 | ret = DLM_BADARGS; |
| 1103 | return ret; |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | static inline void dlm_node_iter_init(unsigned long *map, |
| 1108 | struct dlm_node_iter *iter) |
| 1109 | { |
| 1110 | memcpy(iter->node_map, map, sizeof(iter->node_map)); |
| 1111 | iter->curnode = -1; |
| 1112 | } |
| 1113 | |
| 1114 | static inline int dlm_node_iter_next(struct dlm_node_iter *iter) |
| 1115 | { |
| 1116 | int bit; |
| 1117 | bit = find_next_bit(iter->node_map, O2NM_MAX_NODES, iter->curnode+1); |
| 1118 | if (bit >= O2NM_MAX_NODES) { |
| 1119 | iter->curnode = O2NM_MAX_NODES; |
| 1120 | return -ENOENT; |
| 1121 | } |
| 1122 | iter->curnode = bit; |
| 1123 | return bit; |
| 1124 | } |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | #endif /* DLMCOMMON_H */ |