12522fe45SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2e7fd4179SDavid Teigland /****************************************************************************** 3e7fd4179SDavid Teigland ******************************************************************************* 4e7fd4179SDavid Teigland ** 5e7fd4179SDavid Teigland ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 660f98d18SDavid Teigland ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. 7e7fd4179SDavid Teigland ** 8e7fd4179SDavid Teigland ** 9e7fd4179SDavid Teigland ******************************************************************************* 10e7fd4179SDavid Teigland ******************************************************************************/ 11e7fd4179SDavid Teigland 12e7fd4179SDavid Teigland #ifndef __DLM_INTERNAL_DOT_H__ 13e7fd4179SDavid Teigland #define __DLM_INTERNAL_DOT_H__ 14e7fd4179SDavid Teigland 15e7fd4179SDavid Teigland /* 16e7fd4179SDavid Teigland * This is the main header file to be included in each DLM source file. 17e7fd4179SDavid Teigland */ 18e7fd4179SDavid Teigland 19e7fd4179SDavid Teigland #include <linux/slab.h> 20e7fd4179SDavid Teigland #include <linux/sched.h> 21e7fd4179SDavid Teigland #include <linux/types.h> 22e7fd4179SDavid Teigland #include <linux/ctype.h> 23e7fd4179SDavid Teigland #include <linux/spinlock.h> 24e7fd4179SDavid Teigland #include <linux/vmalloc.h> 25e7fd4179SDavid Teigland #include <linux/list.h> 26e7fd4179SDavid Teigland #include <linux/errno.h> 27e7fd4179SDavid Teigland #include <linux/random.h> 28e7fd4179SDavid Teigland #include <linux/delay.h> 29e7fd4179SDavid Teigland #include <linux/socket.h> 30e7fd4179SDavid Teigland #include <linux/kthread.h> 31e7fd4179SDavid Teigland #include <linux/kobject.h> 32e7fd4179SDavid Teigland #include <linux/kref.h> 33e7fd4179SDavid Teigland #include <linux/kernel.h> 34e7fd4179SDavid Teigland #include <linux/jhash.h> 35597d0caeSDavid Teigland #include <linux/miscdevice.h> 3690135925SDavid Teigland #include <linux/mutex.h> 373d6aa675SDavid Teigland #include <linux/idr.h> 38d6e24788SDavid Teigland #include <linux/ratelimit.h> 397c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 40e7fd4179SDavid Teigland 41e7fd4179SDavid Teigland #include <linux/dlm.h> 4299fc6487SDavid Teigland #include "config.h" 43e7fd4179SDavid Teigland 44e7fd4179SDavid Teigland struct dlm_ls; 45e7fd4179SDavid Teigland struct dlm_lkb; 46e7fd4179SDavid Teigland struct dlm_rsb; 47e7fd4179SDavid Teigland struct dlm_member; 48e7fd4179SDavid Teigland struct dlm_rsbtable; 49e7fd4179SDavid Teigland struct dlm_recover; 50e7fd4179SDavid Teigland struct dlm_header; 51e7fd4179SDavid Teigland struct dlm_message; 52e7fd4179SDavid Teigland struct dlm_rcom; 53e7fd4179SDavid Teigland struct dlm_mhandle; 548f2dc78dSAlexander Aring struct dlm_msg; 55e7fd4179SDavid Teigland 56e7fd4179SDavid Teigland #define log_print(fmt, args...) \ 57e7fd4179SDavid Teigland printk(KERN_ERR "dlm: "fmt"\n" , ##args) 582df6b762SAlexander Aring #define log_print_ratelimited(fmt, args...) \ 592df6b762SAlexander Aring printk_ratelimited(KERN_ERR "dlm: "fmt"\n", ##args) 60e7fd4179SDavid Teigland #define log_error(ls, fmt, args...) \ 61e7fd4179SDavid Teigland printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args) 62505ee528SZhilong Liu 63075f0177SDavid Teigland #define log_rinfo(ls, fmt, args...) \ 64505ee528SZhilong Liu do { \ 65505ee528SZhilong Liu if (dlm_config.ci_log_info) \ 66505ee528SZhilong Liu printk(KERN_INFO "dlm: %s: " fmt "\n", \ 67505ee528SZhilong Liu (ls)->ls_name, ##args); \ 68505ee528SZhilong Liu else if (dlm_config.ci_log_debug) \ 69505ee528SZhilong Liu printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ 70505ee528SZhilong Liu (ls)->ls_name , ##args); \ 71505ee528SZhilong Liu } while (0) 72e7fd4179SDavid Teigland 7399fc6487SDavid Teigland #define log_debug(ls, fmt, args...) \ 7499fc6487SDavid Teigland do { \ 7599fc6487SDavid Teigland if (dlm_config.ci_log_debug) \ 7699fc6487SDavid Teigland printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ 7799fc6487SDavid Teigland (ls)->ls_name , ##args); \ 7899fc6487SDavid Teigland } while (0) 79e7fd4179SDavid Teigland 80d6e24788SDavid Teigland #define log_limit(ls, fmt, args...) \ 81d6e24788SDavid Teigland do { \ 82d6e24788SDavid Teigland if (dlm_config.ci_log_debug) \ 83d6e24788SDavid Teigland printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \ 84d6e24788SDavid Teigland (ls)->ls_name , ##args); \ 85d6e24788SDavid Teigland } while (0) 86d6e24788SDavid Teigland 87e7fd4179SDavid Teigland #define DLM_ASSERT(x, do) \ 88e7fd4179SDavid Teigland { \ 89e7fd4179SDavid Teigland if (!(x)) \ 90e7fd4179SDavid Teigland { \ 91e7fd4179SDavid Teigland printk(KERN_ERR "\nDLM: Assertion failed on line %d of file %s\n" \ 92e7fd4179SDavid Teigland "DLM: assertion: \"%s\"\n" \ 93e7fd4179SDavid Teigland "DLM: time = %lu\n", \ 94e7fd4179SDavid Teigland __LINE__, __FILE__, #x, jiffies); \ 95e7fd4179SDavid Teigland {do} \ 96e7fd4179SDavid Teigland printk("\n"); \ 97e7fd4179SDavid Teigland panic("DLM: Record message above and reboot.\n"); \ 98e7fd4179SDavid Teigland } \ 99e7fd4179SDavid Teigland } 100e7fd4179SDavid Teigland 101e7fd4179SDavid Teigland 10246d6e722SAlexander Aring #define DLM_RTF_SHRINK_BIT 0 103f1172283SDavid Teigland 104e7fd4179SDavid Teigland struct dlm_rsbtable { 1059beb3bf5SBob Peterson struct rb_root keep; 1069beb3bf5SBob Peterson struct rb_root toss; 107c7be761aSDavid Teigland spinlock_t lock; 10846d6e722SAlexander Aring unsigned long flags; 109e7fd4179SDavid Teigland }; 110e7fd4179SDavid Teigland 111e7fd4179SDavid Teigland 112e7fd4179SDavid Teigland /* 113e7fd4179SDavid Teigland * Lockspace member (per node in a ls) 114e7fd4179SDavid Teigland */ 115e7fd4179SDavid Teigland 116e7fd4179SDavid Teigland struct dlm_member { 117e7fd4179SDavid Teigland struct list_head list; 118e7fd4179SDavid Teigland int nodeid; 119e7fd4179SDavid Teigland int weight; 120757a4271SDavid Teigland int slot; 121757a4271SDavid Teigland int slot_prev; 12260f98d18SDavid Teigland int comm_seq; 123757a4271SDavid Teigland uint32_t generation; 124757a4271SDavid Teigland }; 125757a4271SDavid Teigland 126757a4271SDavid Teigland /* 127e7fd4179SDavid Teigland * Save and manage recovery state for a lockspace. 128e7fd4179SDavid Teigland */ 129e7fd4179SDavid Teigland 130e7fd4179SDavid Teigland struct dlm_recover { 131e7fd4179SDavid Teigland struct list_head list; 13260f98d18SDavid Teigland struct dlm_config_node *nodes; 13360f98d18SDavid Teigland int nodes_count; 134e7fd4179SDavid Teigland uint64_t seq; 135e7fd4179SDavid Teigland }; 136e7fd4179SDavid Teigland 137e7fd4179SDavid Teigland /* 138e7fd4179SDavid Teigland * Pass input args to second stage locking function. 139e7fd4179SDavid Teigland */ 140e7fd4179SDavid Teigland 141e7fd4179SDavid Teigland struct dlm_args { 142e7fd4179SDavid Teigland uint32_t flags; 143e5dae548SDavid Teigland void (*astfn) (void *astparam); 144e5dae548SDavid Teigland void *astparam; 145e5dae548SDavid Teigland void (*bastfn) (void *astparam, int mode); 146e7fd4179SDavid Teigland int mode; 147e7fd4179SDavid Teigland struct dlm_lksb *lksb; 148e7fd4179SDavid Teigland }; 149e7fd4179SDavid Teigland 150e7fd4179SDavid Teigland 151e7fd4179SDavid Teigland /* 152e7fd4179SDavid Teigland * Lock block 153e7fd4179SDavid Teigland * 154e7fd4179SDavid Teigland * A lock can be one of three types: 155e7fd4179SDavid Teigland * 156e7fd4179SDavid Teigland * local copy lock is mastered locally 157e7fd4179SDavid Teigland * (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set) 158e7fd4179SDavid Teigland * process copy lock is mastered on a remote node 159e7fd4179SDavid Teigland * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set) 160e7fd4179SDavid Teigland * master copy master node's copy of a lock owned by remote node 161e7fd4179SDavid Teigland * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set) 162e7fd4179SDavid Teigland * 163e7fd4179SDavid Teigland * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or 164e7fd4179SDavid Teigland * dlm_unlock. The dlm does not modify these or use any private flags in 165e7fd4179SDavid Teigland * this field; it only contains DLM_LKF_ flags from dlm.h. These flags 166e7fd4179SDavid Teigland * are sent as-is to the remote master when the lock is remote. 167e7fd4179SDavid Teigland * 168e7fd4179SDavid Teigland * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h. 169e7fd4179SDavid Teigland * Some internal flags are shared between the master and process nodes; 170e7fd4179SDavid Teigland * these shared flags are kept in the lower two bytes. One of these 171e7fd4179SDavid Teigland * flags set on the master copy will be propagated to the process copy 172e7fd4179SDavid Teigland * and v.v. Other internal flags are private to the master or process 173e7fd4179SDavid Teigland * node (e.g. DLM_IFL_MSTCPY). These are kept in the high two bytes. 174e7fd4179SDavid Teigland * 175e7fd4179SDavid Teigland * lkb_sbflags: status block flags. These flags are copied directly into 176e7fd4179SDavid Teigland * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion 177e7fd4179SDavid Teigland * ast. All defined in dlm.h with DLM_SBF_ prefix. 178e7fd4179SDavid Teigland * 179e7fd4179SDavid Teigland * lkb_status: the lock status indicates which rsb queue the lock is 180e7fd4179SDavid Teigland * on, grant, convert, or wait. DLM_LKSTS_ WAITING/GRANTED/CONVERT 181e7fd4179SDavid Teigland * 182e7fd4179SDavid Teigland * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a 183e7fd4179SDavid Teigland * reply is needed. Only set when the lkb is on the lockspace waiters 184e7fd4179SDavid Teigland * list awaiting a reply from a remote node. 185e7fd4179SDavid Teigland * 186e7fd4179SDavid Teigland * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb 187e7fd4179SDavid Teigland * is a master copy, nodeid specifies the remote lock holder, when the 188e7fd4179SDavid Teigland * lkb is a process copy, the nodeid specifies the lock master. 189e7fd4179SDavid Teigland */ 190e7fd4179SDavid Teigland 191e7fd4179SDavid Teigland /* lkb_status */ 192e7fd4179SDavid Teigland 193e7fd4179SDavid Teigland #define DLM_LKSTS_WAITING 1 194e7fd4179SDavid Teigland #define DLM_LKSTS_GRANTED 2 195e7fd4179SDavid Teigland #define DLM_LKSTS_CONVERT 3 196e7fd4179SDavid Teigland 197e1af8728SAlexander Aring /* lkb_iflags */ 198e7fd4179SDavid Teigland 199e1af8728SAlexander Aring #define DLM_IFL_MSTCPY_BIT 16 200e1af8728SAlexander Aring #define __DLM_IFL_MIN_BIT DLM_IFL_MSTCPY_BIT 201e1af8728SAlexander Aring #define DLM_IFL_RESEND_BIT 17 202e1af8728SAlexander Aring #define DLM_IFL_DEAD_BIT 18 203e1af8728SAlexander Aring #define DLM_IFL_OVERLAP_UNLOCK_BIT 19 204e1af8728SAlexander Aring #define DLM_IFL_OVERLAP_CANCEL_BIT 20 205e1af8728SAlexander Aring #define DLM_IFL_ENDOFLIFE_BIT 21 206e1af8728SAlexander Aring #define DLM_IFL_DEADLOCK_CANCEL_BIT 24 207e1af8728SAlexander Aring #define DLM_IFL_CB_PENDING_BIT 25 208e1af8728SAlexander Aring #define __DLM_IFL_MAX_BIT DLM_IFL_CB_PENDING_BIT 209a034c137SAlexander Aring 2108c11ba64SAlexander Aring /* lkb_dflags */ 2118c11ba64SAlexander Aring 2128a39dcd9SAlexander Aring #define DLM_DFL_USER_BIT 0 2138a39dcd9SAlexander Aring #define __DLM_DFL_MIN_BIT DLM_DFL_USER_BIT 2148a39dcd9SAlexander Aring #define DLM_DFL_ORPHAN_BIT 1 2158a39dcd9SAlexander Aring #define __DLM_DFL_MAX_BIT DLM_DFL_ORPHAN_BIT 216e7fd4179SDavid Teigland 2178304d6f2SDavid Teigland #define DLM_CB_CAST 0x00000001 2188304d6f2SDavid Teigland #define DLM_CB_BAST 0x00000002 2198304d6f2SDavid Teigland 2208304d6f2SDavid Teigland struct dlm_callback { 2218304d6f2SDavid Teigland uint32_t flags; /* DLM_CBF_ */ 2228304d6f2SDavid Teigland int sb_status; /* copy to lksb status */ 2238304d6f2SDavid Teigland uint8_t sb_flags; /* copy to lksb flags */ 2248304d6f2SDavid Teigland int8_t mode; /* rq mode of bast, gr mode of cast */ 225*bc236ebcSAlexander Aring int copy_lvb; 22661bed0baSAlexander Aring 22761bed0baSAlexander Aring struct list_head list; 22861bed0baSAlexander Aring struct kref ref; 2298304d6f2SDavid Teigland }; 2308304d6f2SDavid Teigland 231e7fd4179SDavid Teigland struct dlm_lkb { 232e7fd4179SDavid Teigland struct dlm_rsb *lkb_resource; /* the rsb */ 233e7fd4179SDavid Teigland struct kref lkb_ref; 234e7fd4179SDavid Teigland int lkb_nodeid; /* copied from rsb */ 235e7fd4179SDavid Teigland int lkb_ownpid; /* pid of lock owner */ 236e7fd4179SDavid Teigland uint32_t lkb_id; /* our lock ID */ 237e7fd4179SDavid Teigland uint32_t lkb_remid; /* lock ID on remote partner */ 238e7fd4179SDavid Teigland uint32_t lkb_exflags; /* external flags from caller */ 2391361737fSAlexander Aring unsigned long lkb_sbflags; /* lksb flags */ 2408a39dcd9SAlexander Aring unsigned long lkb_dflags; /* distributed flags */ 241a034c137SAlexander Aring unsigned long lkb_iflags; /* internal flags */ 242e7fd4179SDavid Teigland uint32_t lkb_lvbseq; /* lvb sequence number */ 243e7fd4179SDavid Teigland 244e7fd4179SDavid Teigland int8_t lkb_status; /* granted, waiting, convert */ 245e7fd4179SDavid Teigland int8_t lkb_rqmode; /* requested lock mode */ 246e7fd4179SDavid Teigland int8_t lkb_grmode; /* granted lock mode */ 247e7fd4179SDavid Teigland int8_t lkb_highbast; /* highest mode bast sent for */ 2487fe2b319SDavid Teigland 249e7fd4179SDavid Teigland int8_t lkb_wait_type; /* type of reply waiting for */ 25075a7d601SAlexander Aring atomic_t lkb_wait_count; 251c6ff669bSDavid Teigland int lkb_wait_nodeid; /* for debugging */ 252e7fd4179SDavid Teigland 253e7fd4179SDavid Teigland struct list_head lkb_statequeue; /* rsb g/c/w list */ 254e7fd4179SDavid Teigland struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */ 255e7fd4179SDavid Teigland struct list_head lkb_wait_reply; /* waiting for remote reply */ 256597d0caeSDavid Teigland struct list_head lkb_ownqueue; /* list of locks for a process */ 257eeda418dSDavid Teigland ktime_t lkb_timestamp; 2586b0afc0cSAlexander Aring 25992e95733SAlexander Aring spinlock_t lkb_cb_lock; 26023e8e1aaSDavid Teigland struct work_struct lkb_cb_work; 26123e8e1aaSDavid Teigland struct list_head lkb_cb_list; /* for ls_cb_delay or proc->asts */ 26261bed0baSAlexander Aring struct list_head lkb_callbacks; 26361bed0baSAlexander Aring struct dlm_callback *lkb_last_cast; 26461bed0baSAlexander Aring struct dlm_callback *lkb_last_cb; 26561bed0baSAlexander Aring int lkb_last_bast_mode; 2668304d6f2SDavid Teigland ktime_t lkb_last_cast_time; /* for debugging */ 2678304d6f2SDavid Teigland ktime_t lkb_last_bast_time; /* for debugging */ 2688304d6f2SDavid Teigland 2694875647aSDavid Teigland uint64_t lkb_recover_seq; /* from ls_recover_seq */ 2704875647aSDavid Teigland 271e7fd4179SDavid Teigland char *lkb_lvbptr; 272e7fd4179SDavid Teigland struct dlm_lksb *lkb_lksb; /* caller's status block */ 273e5dae548SDavid Teigland void (*lkb_astfn) (void *astparam); 274e5dae548SDavid Teigland void (*lkb_bastfn) (void *astparam, int mode); 275d292c0ccSDavid Teigland union { 276e5dae548SDavid Teigland void *lkb_astparam; /* caller's ast arg */ 277d292c0ccSDavid Teigland struct dlm_user_args *lkb_ua; 278d292c0ccSDavid Teigland }; 279e7fd4179SDavid Teigland }; 280e7fd4179SDavid Teigland 281c04fecb4SDavid Teigland /* 282c04fecb4SDavid Teigland * res_master_nodeid is "normal": 0 is unset/invalid, non-zero is the real 283c04fecb4SDavid Teigland * nodeid, even when nodeid is our_nodeid. 284c04fecb4SDavid Teigland * 285c04fecb4SDavid Teigland * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid, 286c04fecb4SDavid Teigland * greater than zero when another nodeid. 287c04fecb4SDavid Teigland * 288c04fecb4SDavid Teigland * (TODO: remove res_nodeid and only use res_master_nodeid) 289c04fecb4SDavid Teigland */ 290e7fd4179SDavid Teigland 291e7fd4179SDavid Teigland struct dlm_rsb { 292e7fd4179SDavid Teigland struct dlm_ls *res_ls; /* the lockspace */ 293e7fd4179SDavid Teigland struct kref res_ref; 29490135925SDavid Teigland struct mutex res_mutex; 295e7fd4179SDavid Teigland unsigned long res_flags; 296e7fd4179SDavid Teigland int res_length; /* length of rsb name */ 297e7fd4179SDavid Teigland int res_nodeid; 298c04fecb4SDavid Teigland int res_master_nodeid; 299c04fecb4SDavid Teigland int res_dir_nodeid; 3001d7c484eSDavid Teigland int res_id; /* for ls_recover_idr */ 301e7fd4179SDavid Teigland uint32_t res_lvbseq; 302e7fd4179SDavid Teigland uint32_t res_hash; 303e7fd4179SDavid Teigland uint32_t res_bucket; /* rsbtbl */ 304e7fd4179SDavid Teigland unsigned long res_toss_time; 305e7fd4179SDavid Teigland uint32_t res_first_lkid; 306e7fd4179SDavid Teigland struct list_head res_lookup; /* lkbs waiting on first */ 3079beb3bf5SBob Peterson union { 3089beb3bf5SBob Peterson struct list_head res_hashchain; 3099beb3bf5SBob Peterson struct rb_node res_hashnode; /* rsbtbl */ 3109beb3bf5SBob Peterson }; 311e7fd4179SDavid Teigland struct list_head res_grantqueue; 312e7fd4179SDavid Teigland struct list_head res_convertqueue; 313e7fd4179SDavid Teigland struct list_head res_waitqueue; 314e7fd4179SDavid Teigland 315e7fd4179SDavid Teigland struct list_head res_root_list; /* used for recovery */ 316e7fd4179SDavid Teigland struct list_head res_recover_list; /* used for recovery */ 317e7fd4179SDavid Teigland int res_recover_locks_count; 318e7fd4179SDavid Teigland 319e7fd4179SDavid Teigland char *res_lvbptr; 3203881ac04SDavid Teigland char res_name[DLM_RESNAME_MAXLEN+1]; 321e7fd4179SDavid Teigland }; 322e7fd4179SDavid Teigland 323c04fecb4SDavid Teigland /* dlm_master_lookup() flags */ 324c04fecb4SDavid Teigland 325c04fecb4SDavid Teigland #define DLM_LU_RECOVER_DIR 1 326c04fecb4SDavid Teigland #define DLM_LU_RECOVER_MASTER 2 327c04fecb4SDavid Teigland 328c04fecb4SDavid Teigland /* dlm_master_lookup() results */ 329c04fecb4SDavid Teigland 330c04fecb4SDavid Teigland #define DLM_LU_MATCH 1 331c04fecb4SDavid Teigland #define DLM_LU_ADD 2 332c04fecb4SDavid Teigland 333e7fd4179SDavid Teigland /* find_rsb() flags */ 334e7fd4179SDavid Teigland 335c04fecb4SDavid Teigland #define R_REQUEST 0x00000001 336c04fecb4SDavid Teigland #define R_RECEIVE_REQUEST 0x00000002 337c04fecb4SDavid Teigland #define R_RECEIVE_RECOVER 0x00000004 338e7fd4179SDavid Teigland 339e7fd4179SDavid Teigland /* rsb_flags */ 340e7fd4179SDavid Teigland 341e7fd4179SDavid Teigland enum rsb_flags { 342e7fd4179SDavid Teigland RSB_MASTER_UNCERTAIN, 343e7fd4179SDavid Teigland RSB_VALNOTVALID, 344e7fd4179SDavid Teigland RSB_VALNOTVALID_PREV, 345e7fd4179SDavid Teigland RSB_NEW_MASTER, 346e7fd4179SDavid Teigland RSB_NEW_MASTER2, 347e7fd4179SDavid Teigland RSB_RECOVER_CONVERT, 3484875647aSDavid Teigland RSB_RECOVER_GRANT, 349da8c6663SDavid Teigland RSB_RECOVER_LVB_INVAL, 350e7fd4179SDavid Teigland }; 351e7fd4179SDavid Teigland 352e7fd4179SDavid Teigland static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag) 353e7fd4179SDavid Teigland { 354e7fd4179SDavid Teigland __set_bit(flag, &r->res_flags); 355e7fd4179SDavid Teigland } 356e7fd4179SDavid Teigland 357e7fd4179SDavid Teigland static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag) 358e7fd4179SDavid Teigland { 359e7fd4179SDavid Teigland __clear_bit(flag, &r->res_flags); 360e7fd4179SDavid Teigland } 361e7fd4179SDavid Teigland 362e7fd4179SDavid Teigland static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag) 363e7fd4179SDavid Teigland { 364e7fd4179SDavid Teigland return test_bit(flag, &r->res_flags); 365e7fd4179SDavid Teigland } 366e7fd4179SDavid Teigland 367e7fd4179SDavid Teigland 368e7fd4179SDavid Teigland /* dlm_header is first element of all structs sent between nodes */ 369e7fd4179SDavid Teigland 37038aa8b0cSDavid Teigland #define DLM_HEADER_MAJOR 0x00030000 371489d8e55SAlexander Aring #define DLM_HEADER_MINOR 0x00000002 372489d8e55SAlexander Aring 373489d8e55SAlexander Aring #define DLM_VERSION_3_1 0x00030001 374489d8e55SAlexander Aring #define DLM_VERSION_3_2 0x00030002 375757a4271SDavid Teigland 376757a4271SDavid Teigland #define DLM_HEADER_SLOTS 0x00000001 377e7fd4179SDavid Teigland 378e7fd4179SDavid Teigland #define DLM_MSG 1 379e7fd4179SDavid Teigland #define DLM_RCOM 2 380489d8e55SAlexander Aring #define DLM_OPTS 3 381489d8e55SAlexander Aring #define DLM_ACK 4 382489d8e55SAlexander Aring #define DLM_FIN 5 383e7fd4179SDavid Teigland 384e7fd4179SDavid Teigland struct dlm_header { 3853428785aSAlexander Aring __le32 h_version; 3868e2e4086SAlexander Aring union { 3878e2e4086SAlexander Aring /* for DLM_MSG and DLM_RCOM */ 3883428785aSAlexander Aring __le32 h_lockspace; 389489d8e55SAlexander Aring /* for DLM_ACK and DLM_OPTS */ 3903428785aSAlexander Aring __le32 h_seq; 3918e2e4086SAlexander Aring } u; 3923428785aSAlexander Aring __le32 h_nodeid; /* nodeid of sender */ 3933428785aSAlexander Aring __le16 h_length; 394e7fd4179SDavid Teigland uint8_t h_cmd; /* DLM_MSG, DLM_RCOM */ 395e7fd4179SDavid Teigland uint8_t h_pad; 396e7fd4179SDavid Teigland }; 397e7fd4179SDavid Teigland 398e7fd4179SDavid Teigland #define DLM_MSG_REQUEST 1 399e7fd4179SDavid Teigland #define DLM_MSG_CONVERT 2 400e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK 3 401e7fd4179SDavid Teigland #define DLM_MSG_CANCEL 4 402e7fd4179SDavid Teigland #define DLM_MSG_REQUEST_REPLY 5 403e7fd4179SDavid Teigland #define DLM_MSG_CONVERT_REPLY 6 404e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK_REPLY 7 405e7fd4179SDavid Teigland #define DLM_MSG_CANCEL_REPLY 8 406e7fd4179SDavid Teigland #define DLM_MSG_GRANT 9 407e7fd4179SDavid Teigland #define DLM_MSG_BAST 10 408e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP 11 409e7fd4179SDavid Teigland #define DLM_MSG_REMOVE 12 410e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP_REPLY 13 4118499137dSDavid Teigland #define DLM_MSG_PURGE 14 412e7fd4179SDavid Teigland 413e7fd4179SDavid Teigland struct dlm_message { 414e7fd4179SDavid Teigland struct dlm_header m_header; 41500e99ccdSAlexander Aring __le32 m_type; /* DLM_MSG_ */ 41600e99ccdSAlexander Aring __le32 m_nodeid; 41700e99ccdSAlexander Aring __le32 m_pid; 41800e99ccdSAlexander Aring __le32 m_lkid; /* lkid on sender */ 41900e99ccdSAlexander Aring __le32 m_remid; /* lkid on receiver */ 42000e99ccdSAlexander Aring __le32 m_parent_lkid; 42100e99ccdSAlexander Aring __le32 m_parent_remid; 42200e99ccdSAlexander Aring __le32 m_exflags; 42300e99ccdSAlexander Aring __le32 m_sbflags; 42400e99ccdSAlexander Aring __le32 m_flags; 42500e99ccdSAlexander Aring __le32 m_lvbseq; 42600e99ccdSAlexander Aring __le32 m_hash; 42700e99ccdSAlexander Aring __le32 m_status; 42800e99ccdSAlexander Aring __le32 m_grmode; 42900e99ccdSAlexander Aring __le32 m_rqmode; 43000e99ccdSAlexander Aring __le32 m_bastmode; 43100e99ccdSAlexander Aring __le32 m_asts; 43200e99ccdSAlexander Aring __le32 m_result; /* 0 or -EXXX */ 433a4e439a6SGustavo A. R. Silva char m_extra[]; /* name or lvb */ 434e7fd4179SDavid Teigland }; 435e7fd4179SDavid Teigland 436e7fd4179SDavid Teigland 437e7fd4179SDavid Teigland #define DLM_RS_NODES 0x00000001 438e7fd4179SDavid Teigland #define DLM_RS_NODES_ALL 0x00000002 439e7fd4179SDavid Teigland #define DLM_RS_DIR 0x00000004 440e7fd4179SDavid Teigland #define DLM_RS_DIR_ALL 0x00000008 441e7fd4179SDavid Teigland #define DLM_RS_LOCKS 0x00000010 442e7fd4179SDavid Teigland #define DLM_RS_LOCKS_ALL 0x00000020 443e7fd4179SDavid Teigland #define DLM_RS_DONE 0x00000040 444e7fd4179SDavid Teigland #define DLM_RS_DONE_ALL 0x00000080 445e7fd4179SDavid Teigland 446e7fd4179SDavid Teigland #define DLM_RCOM_STATUS 1 447e7fd4179SDavid Teigland #define DLM_RCOM_NAMES 2 448e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP 3 449e7fd4179SDavid Teigland #define DLM_RCOM_LOCK 4 450e7fd4179SDavid Teigland #define DLM_RCOM_STATUS_REPLY 5 451e7fd4179SDavid Teigland #define DLM_RCOM_NAMES_REPLY 6 452e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP_REPLY 7 453e7fd4179SDavid Teigland #define DLM_RCOM_LOCK_REPLY 8 454e7fd4179SDavid Teigland 455e7fd4179SDavid Teigland struct dlm_rcom { 456e7fd4179SDavid Teigland struct dlm_header rc_header; 4572f9dbedaSAlexander Aring __le32 rc_type; /* DLM_RCOM_ */ 4582f9dbedaSAlexander Aring __le32 rc_result; /* multi-purpose */ 4592f9dbedaSAlexander Aring __le64 rc_id; /* match reply with request */ 4602f9dbedaSAlexander Aring __le64 rc_seq; /* sender's ls_recover_seq */ 4612f9dbedaSAlexander Aring __le64 rc_seq_reply; /* remote ls_recover_seq */ 462a4e439a6SGustavo A. R. Silva char rc_buf[]; 463e7fd4179SDavid Teigland }; 464e7fd4179SDavid Teigland 465489d8e55SAlexander Aring struct dlm_opt_header { 466d9efd005SAlexander Aring __le16 t_type; 467d9efd005SAlexander Aring __le16 t_length; 468d9efd005SAlexander Aring __le32 t_pad; 469489d8e55SAlexander Aring /* need to be 8 byte aligned */ 470489d8e55SAlexander Aring char t_value[]; 471489d8e55SAlexander Aring }; 472489d8e55SAlexander Aring 473489d8e55SAlexander Aring /* encapsulation header */ 474489d8e55SAlexander Aring struct dlm_opts { 475489d8e55SAlexander Aring struct dlm_header o_header; 476489d8e55SAlexander Aring uint8_t o_nextcmd; 477489d8e55SAlexander Aring uint8_t o_pad; 478d9efd005SAlexander Aring __le16 o_optlen; 479d9efd005SAlexander Aring __le32 o_pad2; 480489d8e55SAlexander Aring char o_opts[]; 481489d8e55SAlexander Aring }; 482489d8e55SAlexander Aring 483eef7d739SAl Viro union dlm_packet { 484eef7d739SAl Viro struct dlm_header header; /* common to other two */ 485eef7d739SAl Viro struct dlm_message message; 486eef7d739SAl Viro struct dlm_rcom rcom; 487489d8e55SAlexander Aring struct dlm_opts opts; 488eef7d739SAl Viro }; 489eef7d739SAl Viro 490757a4271SDavid Teigland #define DLM_RSF_NEED_SLOTS 0x00000001 491757a4271SDavid Teigland 492757a4271SDavid Teigland /* RCOM_STATUS data */ 493757a4271SDavid Teigland struct rcom_status { 494757a4271SDavid Teigland __le32 rs_flags; 495757a4271SDavid Teigland __le32 rs_unused1; 496757a4271SDavid Teigland __le64 rs_unused2; 497757a4271SDavid Teigland }; 498757a4271SDavid Teigland 499757a4271SDavid Teigland /* RCOM_STATUS_REPLY data */ 500e7fd4179SDavid Teigland struct rcom_config { 50193ff2971SAl Viro __le32 rf_lvblen; 50293ff2971SAl Viro __le32 rf_lsflags; 503757a4271SDavid Teigland 504757a4271SDavid Teigland /* DLM_HEADER_SLOTS adds: */ 505757a4271SDavid Teigland __le32 rf_flags; 506757a4271SDavid Teigland __le16 rf_our_slot; 507757a4271SDavid Teigland __le16 rf_num_slots; 508757a4271SDavid Teigland __le32 rf_generation; 509757a4271SDavid Teigland __le32 rf_unused1; 510757a4271SDavid Teigland __le64 rf_unused2; 511757a4271SDavid Teigland }; 512757a4271SDavid Teigland 513757a4271SDavid Teigland struct rcom_slot { 514757a4271SDavid Teigland __le32 ro_nodeid; 515757a4271SDavid Teigland __le16 ro_slot; 516757a4271SDavid Teigland __le16 ro_unused1; 517757a4271SDavid Teigland __le64 ro_unused2; 518e7fd4179SDavid Teigland }; 519e7fd4179SDavid Teigland 520e7fd4179SDavid Teigland struct rcom_lock { 521163a1859SAl Viro __le32 rl_ownpid; 522163a1859SAl Viro __le32 rl_lkid; 523163a1859SAl Viro __le32 rl_remid; 524163a1859SAl Viro __le32 rl_parent_lkid; 525163a1859SAl Viro __le32 rl_parent_remid; 526163a1859SAl Viro __le32 rl_exflags; 527163a1859SAl Viro __le32 rl_flags; 528163a1859SAl Viro __le32 rl_lvbseq; 529163a1859SAl Viro __le32 rl_result; 530e7fd4179SDavid Teigland int8_t rl_rqmode; 531e7fd4179SDavid Teigland int8_t rl_grmode; 532e7fd4179SDavid Teigland int8_t rl_status; 533e7fd4179SDavid Teigland int8_t rl_asts; 534163a1859SAl Viro __le16 rl_wait_type; 535163a1859SAl Viro __le16 rl_namelen; 536e7fd4179SDavid Teigland char rl_name[DLM_RESNAME_MAXLEN]; 537a4e439a6SGustavo A. R. Silva char rl_lvb[]; 538e7fd4179SDavid Teigland }; 539e7fd4179SDavid Teigland 54005c32f47SDavid Teigland /* 54105c32f47SDavid Teigland * The max number of resources per rsbtbl bucket that shrink will attempt 54205c32f47SDavid Teigland * to remove in each iteration. 54305c32f47SDavid Teigland */ 54405c32f47SDavid Teigland 54505c32f47SDavid Teigland #define DLM_REMOVE_NAMES_MAX 8 54605c32f47SDavid Teigland 547e7fd4179SDavid Teigland struct dlm_ls { 548e7fd4179SDavid Teigland struct list_head ls_list; /* list of lockspaces */ 549597d0caeSDavid Teigland dlm_lockspace_t *ls_local_handle; 550e7fd4179SDavid Teigland uint32_t ls_global_id; /* global unique lockspace ID */ 551757a4271SDavid Teigland uint32_t ls_generation; 552e7fd4179SDavid Teigland uint32_t ls_exflags; 553e7fd4179SDavid Teigland int ls_lvblen; 5543cb5977cSAlexander Aring atomic_t ls_count; /* refcount of processes in 5550f8e0d9aSDavid Teigland the dlm using this ls */ 5563cb5977cSAlexander Aring wait_queue_head_t ls_count_wait; 5570f8e0d9aSDavid Teigland int ls_create_count; /* create/release refcount */ 558e7fd4179SDavid Teigland unsigned long ls_flags; /* LSFL_ */ 559c1dcf65fSDavid Teigland unsigned long ls_scan_time; 560e7fd4179SDavid Teigland struct kobject ls_kobj; 561e7fd4179SDavid Teigland 5623d6aa675SDavid Teigland struct idr ls_lkbidr; 5633d6aa675SDavid Teigland spinlock_t ls_lkbidr_spin; 5643d6aa675SDavid Teigland 565e7fd4179SDavid Teigland struct dlm_rsbtable *ls_rsbtbl; 566e7fd4179SDavid Teigland uint32_t ls_rsbtbl_size; 567e7fd4179SDavid Teigland 56890135925SDavid Teigland struct mutex ls_waiters_mutex; 569e7fd4179SDavid Teigland struct list_head ls_waiters; /* lkbs needing a reply */ 570e7fd4179SDavid Teigland 571ef0c2bb0SDavid Teigland struct mutex ls_orphans_mutex; 572ef0c2bb0SDavid Teigland struct list_head ls_orphans; 573ef0c2bb0SDavid Teigland 5743881ac04SDavid Teigland spinlock_t ls_new_rsb_spin; 5753881ac04SDavid Teigland int ls_new_rsb_count; 5763881ac04SDavid Teigland struct list_head ls_new_rsb; /* new rsb structs */ 5773881ac04SDavid Teigland 57805c32f47SDavid Teigland char *ls_remove_names[DLM_REMOVE_NAMES_MAX]; 57905c32f47SDavid Teigland int ls_remove_lens[DLM_REMOVE_NAMES_MAX]; 58005c32f47SDavid Teigland 581e7fd4179SDavid Teigland struct list_head ls_nodes; /* current nodes in ls */ 582e7fd4179SDavid Teigland struct list_head ls_nodes_gone; /* dead node list, recovery */ 583e7fd4179SDavid Teigland int ls_num_nodes; /* number of nodes in ls */ 584e7fd4179SDavid Teigland int ls_low_nodeid; 585e7fd4179SDavid Teigland int ls_total_weight; 586e7fd4179SDavid Teigland int *ls_node_array; 587e7fd4179SDavid Teigland 588757a4271SDavid Teigland int ls_slot; 589757a4271SDavid Teigland int ls_num_slots; 590757a4271SDavid Teigland int ls_slots_size; 591757a4271SDavid Teigland struct dlm_slot *ls_slots; 592757a4271SDavid Teigland 593a7e7ffacSAlexander Aring struct dlm_rsb ls_local_rsb; /* for returning errors */ 594a7e7ffacSAlexander Aring struct dlm_lkb ls_local_lkb; /* for returning errors */ 595a7e7ffacSAlexander Aring struct dlm_message ls_local_ms; /* for faking a reply */ 596e7fd4179SDavid Teigland 5975de6319bSDavid Teigland struct dentry *ls_debug_rsb_dentry; /* debugfs */ 5985de6319bSDavid Teigland struct dentry *ls_debug_waiters_dentry; /* debugfs */ 599ac90a255SDavid Teigland struct dentry *ls_debug_locks_dentry; /* debugfs */ 600d022509dSDavid Teigland struct dentry *ls_debug_all_dentry; /* debugfs */ 601c04fecb4SDavid Teigland struct dentry *ls_debug_toss_dentry; /* debugfs */ 602541adb0dSAlexander Aring struct dentry *ls_debug_queued_asts_dentry; /* debugfs */ 603e7fd4179SDavid Teigland 604e7fd4179SDavid Teigland wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ 605e7fd4179SDavid Teigland int ls_uevent_result; 606682bb91bSAlexander Aring struct completion ls_recovery_done; 607682bb91bSAlexander Aring int ls_recovery_result; 608e7fd4179SDavid Teigland 609597d0caeSDavid Teigland struct miscdevice ls_device; 610597d0caeSDavid Teigland 61123e8e1aaSDavid Teigland struct workqueue_struct *ls_callback_wq; 61223e8e1aaSDavid Teigland 613e7fd4179SDavid Teigland /* recovery related */ 614e7fd4179SDavid Teigland 615a4c0352bSAlexander Aring spinlock_t ls_cb_lock; 61623e8e1aaSDavid Teigland struct list_head ls_cb_delay; /* save for queue_work later */ 617e7fd4179SDavid Teigland struct timer_list ls_timer; 618e7fd4179SDavid Teigland struct task_struct *ls_recoverd_task; 61990135925SDavid Teigland struct mutex ls_recoverd_active; 620e7fd4179SDavid Teigland spinlock_t ls_recover_lock; 6213ae1acf9SDavid Teigland unsigned long ls_recover_begin; /* jiffies timestamp */ 622e7fd4179SDavid Teigland uint32_t ls_recover_status; /* DLM_RS_ */ 623e7fd4179SDavid Teigland uint64_t ls_recover_seq; 624e7fd4179SDavid Teigland struct dlm_recover *ls_recover_args; 625e7fd4179SDavid Teigland struct rw_semaphore ls_in_recovery; /* block local requests */ 626c36258b5SDavid Teigland struct rw_semaphore ls_recv_active; /* block dlm_recv */ 627e7fd4179SDavid Teigland struct list_head ls_requestqueue;/* queue remote requests */ 628164d88abSAlexander Aring atomic_t ls_requestqueue_cnt; 629164d88abSAlexander Aring wait_queue_head_t ls_requestqueue_wait; 63090135925SDavid Teigland struct mutex ls_requestqueue_mutex; 6314007685cSAl Viro struct dlm_rcom *ls_recover_buf; 632faa0f267SDavid Teigland int ls_recover_nodeid; /* for debugging */ 633c04fecb4SDavid Teigland unsigned int ls_recover_dir_sent_res; /* for log info */ 634c04fecb4SDavid Teigland unsigned int ls_recover_dir_sent_msg; /* for log info */ 6354875647aSDavid Teigland unsigned int ls_recover_locks_in; /* for log info */ 6364a99c3d9SDavid Teigland uint64_t ls_rcom_seq; 63798f176fbSDavid Teigland spinlock_t ls_rcom_spin; 638e7fd4179SDavid Teigland struct list_head ls_recover_list; 639e7fd4179SDavid Teigland spinlock_t ls_recover_list_lock; 640e7fd4179SDavid Teigland int ls_recover_list_count; 6411d7c484eSDavid Teigland struct idr ls_recover_idr; 6421d7c484eSDavid Teigland spinlock_t ls_recover_idr_lock; 643e7fd4179SDavid Teigland wait_queue_head_t ls_wait_general; 644475f230cSDavid Teigland wait_queue_head_t ls_recover_lock_wait; 645296d9d1eSAlexander Aring spinlock_t ls_clear_proc_locks; 646e7fd4179SDavid Teigland 647e7fd4179SDavid Teigland struct list_head ls_root_list; /* root resources */ 648e7fd4179SDavid Teigland struct rw_semaphore ls_root_sem; /* protect root_list */ 649e7fd4179SDavid Teigland 65060f98d18SDavid Teigland const struct dlm_lockspace_ops *ls_ops; 65160f98d18SDavid Teigland void *ls_ops_arg; 65260f98d18SDavid Teigland 653e7fd4179SDavid Teigland int ls_namelen; 654d96d0f96SPaulo Miguel Almeida char ls_name[DLM_LOCKSPACE_LEN + 1]; 655e7fd4179SDavid Teigland }; 656e7fd4179SDavid Teigland 657475f230cSDavid Teigland /* 658475f230cSDavid Teigland * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines 659475f230cSDavid Teigland * that they should abort what they're doing so new recovery can be started. 660475f230cSDavid Teigland * 661475f230cSDavid Teigland * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it 662475f230cSDavid Teigland * should do down_write() on the in_recovery rw_semaphore. (doing down_write 663475f230cSDavid Teigland * within dlm_ls_stop causes complaints about the lock acquired/released 664475f230cSDavid Teigland * in different contexts.) 665475f230cSDavid Teigland * 666475f230cSDavid Teigland * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore. 667475f230cSDavid Teigland * It sets this after it is done with down_write() on the in_recovery 668475f230cSDavid Teigland * rw_semaphore and clears it after it has released the rw_semaphore. 669475f230cSDavid Teigland * 670475f230cSDavid Teigland * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it 671475f230cSDavid Teigland * should begin recovery of the lockspace. 672475f230cSDavid Teigland * 673475f230cSDavid Teigland * LSFL_RUNNING - set when normal locking activity is enabled. 674475f230cSDavid Teigland * dlm_ls_stop() clears this to tell dlm locking routines that they should 675475f230cSDavid Teigland * quit what they are doing so recovery can run. dlm_recoverd sets 676475f230cSDavid Teigland * this after recovery is finished. 677475f230cSDavid Teigland */ 678475f230cSDavid Teigland 679475f230cSDavid Teigland #define LSFL_RECOVER_STOP 0 680475f230cSDavid Teigland #define LSFL_RECOVER_DOWN 1 681475f230cSDavid Teigland #define LSFL_RECOVER_LOCK 2 682475f230cSDavid Teigland #define LSFL_RECOVER_WORK 3 683475f230cSDavid Teigland #define LSFL_RUNNING 4 684475f230cSDavid Teigland 685475f230cSDavid Teigland #define LSFL_RCOM_READY 5 686475f230cSDavid Teigland #define LSFL_RCOM_WAIT 6 687475f230cSDavid Teigland #define LSFL_UEVENT_WAIT 7 688475f230cSDavid Teigland #define LSFL_CB_DELAY 9 689475f230cSDavid Teigland #define LSFL_NODIR 10 690e7fd4179SDavid Teigland 691597d0caeSDavid Teigland /* much of this is just saving user space pointers associated with the 692597d0caeSDavid Teigland lock that we pass back to the user lib with an ast */ 693597d0caeSDavid Teigland 694597d0caeSDavid Teigland struct dlm_user_args { 695597d0caeSDavid Teigland struct dlm_user_proc *proc; /* each process that opens the lockspace 696597d0caeSDavid Teigland device has private data 697597d0caeSDavid Teigland (dlm_user_proc) on the struct file, 698597d0caeSDavid Teigland the process's locks point back to it*/ 699597d0caeSDavid Teigland struct dlm_lksb lksb; 700597d0caeSDavid Teigland struct dlm_lksb __user *user_lksb; 701597d0caeSDavid Teigland void __user *castparam; 702597d0caeSDavid Teigland void __user *castaddr; 703597d0caeSDavid Teigland void __user *bastparam; 704597d0caeSDavid Teigland void __user *bastaddr; 705d7db923eSDavid Teigland uint64_t xid; 706597d0caeSDavid Teigland }; 707597d0caeSDavid Teigland 708597d0caeSDavid Teigland #define DLM_PROC_FLAGS_CLOSING 1 709597d0caeSDavid Teigland #define DLM_PROC_FLAGS_COMPAT 2 710597d0caeSDavid Teigland 711597d0caeSDavid Teigland /* locks list is kept so we can remove all a process's locks when it 712597d0caeSDavid Teigland exits (or orphan those that are persistent) */ 713597d0caeSDavid Teigland 714597d0caeSDavid Teigland struct dlm_user_proc { 715597d0caeSDavid Teigland dlm_lockspace_t *lockspace; 716597d0caeSDavid Teigland unsigned long flags; /* DLM_PROC_FLAGS */ 717597d0caeSDavid Teigland struct list_head asts; 718597d0caeSDavid Teigland spinlock_t asts_spin; 719597d0caeSDavid Teigland struct list_head locks; 720597d0caeSDavid Teigland spinlock_t locks_spin; 721a1bc86e6SDavid Teigland struct list_head unlocking; 722597d0caeSDavid Teigland wait_queue_head_t wait; 723597d0caeSDavid Teigland }; 724597d0caeSDavid Teigland 725e7fd4179SDavid Teigland static inline int dlm_locking_stopped(struct dlm_ls *ls) 726e7fd4179SDavid Teigland { 727e7fd4179SDavid Teigland return !test_bit(LSFL_RUNNING, &ls->ls_flags); 728e7fd4179SDavid Teigland } 729e7fd4179SDavid Teigland 730e7fd4179SDavid Teigland static inline int dlm_recovery_stopped(struct dlm_ls *ls) 731e7fd4179SDavid Teigland { 732475f230cSDavid Teigland return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags); 733e7fd4179SDavid Teigland } 734e7fd4179SDavid Teigland 735e7fd4179SDavid Teigland static inline int dlm_no_directory(struct dlm_ls *ls) 736e7fd4179SDavid Teigland { 7374875647aSDavid Teigland return test_bit(LSFL_NODIR, &ls->ls_flags); 738e7fd4179SDavid Teigland } 739e7fd4179SDavid Teigland 7408a39dcd9SAlexander Aring /* takes a snapshot from dlm atomic flags */ 7418a39dcd9SAlexander Aring static inline uint32_t dlm_flags_val(const unsigned long *addr, 7428a39dcd9SAlexander Aring uint32_t min, uint32_t max) 7438a39dcd9SAlexander Aring { 7448a39dcd9SAlexander Aring uint32_t bit = min, val = 0; 7458a39dcd9SAlexander Aring 7468a39dcd9SAlexander Aring for_each_set_bit_from(bit, addr, max + 1) { 7478a39dcd9SAlexander Aring val |= BIT(bit); 7488a39dcd9SAlexander Aring } 7498a39dcd9SAlexander Aring 7508a39dcd9SAlexander Aring return val; 7518a39dcd9SAlexander Aring } 7528a39dcd9SAlexander Aring 753e1af8728SAlexander Aring static inline uint32_t dlm_iflags_val(const struct dlm_lkb *lkb) 754e1af8728SAlexander Aring { 755e1af8728SAlexander Aring return dlm_flags_val(&lkb->lkb_iflags, __DLM_IFL_MIN_BIT, 756e1af8728SAlexander Aring __DLM_IFL_MAX_BIT); 757e1af8728SAlexander Aring } 758e1af8728SAlexander Aring 7598a39dcd9SAlexander Aring static inline uint32_t dlm_dflags_val(const struct dlm_lkb *lkb) 7608a39dcd9SAlexander Aring { 7618a39dcd9SAlexander Aring return dlm_flags_val(&lkb->lkb_dflags, __DLM_DFL_MIN_BIT, 7628a39dcd9SAlexander Aring __DLM_DFL_MAX_BIT); 7638a39dcd9SAlexander Aring } 7648a39dcd9SAlexander Aring 7651361737fSAlexander Aring /* coming from UAPI header 7661361737fSAlexander Aring * 7671361737fSAlexander Aring * TODO: 7681361737fSAlexander Aring * Move this to UAPI header and let other values point to them and use BIT() 7691361737fSAlexander Aring */ 7701361737fSAlexander Aring #define DLM_SBF_DEMOTED_BIT 0 7711361737fSAlexander Aring #define __DLM_SBF_MIN_BIT DLM_SBF_DEMOTED_BIT 7721361737fSAlexander Aring #define DLM_SBF_VALNOTVALID_BIT 1 7731361737fSAlexander Aring #define DLM_SBF_ALTMODE_BIT 2 7741361737fSAlexander Aring #define __DLM_SBF_MAX_BIT DLM_SBF_ALTMODE_BIT 7751361737fSAlexander Aring 7761361737fSAlexander Aring static inline uint32_t dlm_sbflags_val(const struct dlm_lkb *lkb) 7771361737fSAlexander Aring { 7781361737fSAlexander Aring /* be sure the next person updates this */ 7791361737fSAlexander Aring BUILD_BUG_ON(BIT(__DLM_SBF_MAX_BIT) != DLM_SBF_ALTMODE); 7801361737fSAlexander Aring 7811361737fSAlexander Aring return dlm_flags_val(&lkb->lkb_sbflags, __DLM_SBF_MIN_BIT, 7821361737fSAlexander Aring __DLM_SBF_MAX_BIT); 7831361737fSAlexander Aring } 7841361737fSAlexander Aring 7858a39dcd9SAlexander Aring static inline void dlm_set_flags_val(unsigned long *addr, uint32_t val, 7868a39dcd9SAlexander Aring uint32_t min, uint32_t max) 7878a39dcd9SAlexander Aring { 7888a39dcd9SAlexander Aring uint32_t bit; 7898a39dcd9SAlexander Aring 7908a39dcd9SAlexander Aring for (bit = min; bit < (max + 1); bit++) { 7918a39dcd9SAlexander Aring if (val & BIT(bit)) 7928a39dcd9SAlexander Aring set_bit(bit, addr); 7938a39dcd9SAlexander Aring else 7948a39dcd9SAlexander Aring clear_bit(bit, addr); 7958a39dcd9SAlexander Aring } 7968a39dcd9SAlexander Aring } 7978a39dcd9SAlexander Aring 7988a39dcd9SAlexander Aring static inline void dlm_set_dflags_val(struct dlm_lkb *lkb, uint32_t val) 7998a39dcd9SAlexander Aring { 8008a39dcd9SAlexander Aring dlm_set_flags_val(&lkb->lkb_dflags, val, __DLM_DFL_MIN_BIT, 8018a39dcd9SAlexander Aring __DLM_DFL_MAX_BIT); 8028a39dcd9SAlexander Aring } 8038a39dcd9SAlexander Aring 8041361737fSAlexander Aring static inline void dlm_set_sbflags_val(struct dlm_lkb *lkb, uint32_t val) 8051361737fSAlexander Aring { 8061361737fSAlexander Aring dlm_set_flags_val(&lkb->lkb_sbflags, val, __DLM_SBF_MIN_BIT, 8071361737fSAlexander Aring __DLM_SBF_MAX_BIT); 8081361737fSAlexander Aring } 8091361737fSAlexander Aring 8102402211aSDavid Teigland int dlm_plock_init(void); 8112402211aSDavid Teigland void dlm_plock_exit(void); 812e028398dSAdrian Bunk 813e028398dSAdrian Bunk #ifdef CONFIG_DLM_DEBUG 814a48f9721SGreg Kroah-Hartman void dlm_register_debugfs(void); 815e028398dSAdrian Bunk void dlm_unregister_debugfs(void); 816a48f9721SGreg Kroah-Hartman void dlm_create_debug_file(struct dlm_ls *ls); 817e028398dSAdrian Bunk void dlm_delete_debug_file(struct dlm_ls *ls); 8185b2f981fSAlexander Aring void *dlm_create_debug_comms_file(int nodeid, void *data); 8195b2f981fSAlexander Aring void dlm_delete_debug_comms_file(void *ctx); 820e028398dSAdrian Bunk #else 821a48f9721SGreg Kroah-Hartman static inline void dlm_register_debugfs(void) { } 822e028398dSAdrian Bunk static inline void dlm_unregister_debugfs(void) { } 823a48f9721SGreg Kroah-Hartman static inline void dlm_create_debug_file(struct dlm_ls *ls) { } 824e028398dSAdrian Bunk static inline void dlm_delete_debug_file(struct dlm_ls *ls) { } 8255b2f981fSAlexander Aring static inline void *dlm_create_debug_comms_file(int nodeid, void *data) { return NULL; } 8265b2f981fSAlexander Aring static inline void dlm_delete_debug_comms_file(void *ctx) { } 827e028398dSAdrian Bunk #endif 828e028398dSAdrian Bunk 829e7fd4179SDavid Teigland #endif /* __DLM_INTERNAL_DOT_H__ */ 830e7fd4179SDavid Teigland 831