1e7fd4179SDavid Teigland /****************************************************************************** 2e7fd4179SDavid Teigland ******************************************************************************* 3e7fd4179SDavid Teigland ** 4e7fd4179SDavid Teigland ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 57fe2b319SDavid Teigland ** Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. 6e7fd4179SDavid Teigland ** 7e7fd4179SDavid Teigland ** This copyrighted material is made available to anyone wishing to use, 8e7fd4179SDavid Teigland ** modify, copy, or redistribute it subject to the terms and conditions 9e7fd4179SDavid Teigland ** of the GNU General Public License v.2. 10e7fd4179SDavid Teigland ** 11e7fd4179SDavid Teigland ******************************************************************************* 12e7fd4179SDavid Teigland ******************************************************************************/ 13e7fd4179SDavid Teigland 14e7fd4179SDavid Teigland #ifndef __DLM_INTERNAL_DOT_H__ 15e7fd4179SDavid Teigland #define __DLM_INTERNAL_DOT_H__ 16e7fd4179SDavid Teigland 17e7fd4179SDavid Teigland /* 18e7fd4179SDavid Teigland * This is the main header file to be included in each DLM source file. 19e7fd4179SDavid Teigland */ 20e7fd4179SDavid Teigland 21e7fd4179SDavid Teigland #include <linux/module.h> 22e7fd4179SDavid Teigland #include <linux/slab.h> 23e7fd4179SDavid Teigland #include <linux/sched.h> 24e7fd4179SDavid Teigland #include <linux/types.h> 25e7fd4179SDavid Teigland #include <linux/ctype.h> 26e7fd4179SDavid Teigland #include <linux/spinlock.h> 27e7fd4179SDavid Teigland #include <linux/vmalloc.h> 28e7fd4179SDavid Teigland #include <linux/list.h> 29e7fd4179SDavid Teigland #include <linux/errno.h> 30e7fd4179SDavid Teigland #include <linux/random.h> 31e7fd4179SDavid Teigland #include <linux/delay.h> 32e7fd4179SDavid Teigland #include <linux/socket.h> 33e7fd4179SDavid Teigland #include <linux/kthread.h> 34e7fd4179SDavid Teigland #include <linux/kobject.h> 35e7fd4179SDavid Teigland #include <linux/kref.h> 36e7fd4179SDavid Teigland #include <linux/kernel.h> 37e7fd4179SDavid Teigland #include <linux/jhash.h> 38597d0caeSDavid Teigland #include <linux/miscdevice.h> 3990135925SDavid Teigland #include <linux/mutex.h> 403d6aa675SDavid Teigland #include <linux/idr.h> 41e7fd4179SDavid Teigland #include <asm/uaccess.h> 42e7fd4179SDavid Teigland 43e7fd4179SDavid Teigland #include <linux/dlm.h> 4499fc6487SDavid Teigland #include "config.h" 45e7fd4179SDavid Teigland 46e7fd4179SDavid Teigland /* Size of the temp buffer midcomms allocates on the stack. 47e7fd4179SDavid Teigland We try to make this large enough so most messages fit. 48e7fd4179SDavid Teigland FIXME: should sctp make this unnecessary? */ 49e7fd4179SDavid Teigland 50e7fd4179SDavid Teigland #define DLM_INBUF_LEN 148 51e7fd4179SDavid Teigland 52e7fd4179SDavid Teigland struct dlm_ls; 53e7fd4179SDavid Teigland struct dlm_lkb; 54e7fd4179SDavid Teigland struct dlm_rsb; 55e7fd4179SDavid Teigland struct dlm_member; 56e7fd4179SDavid Teigland struct dlm_rsbtable; 57e7fd4179SDavid Teigland struct dlm_dirtable; 58e7fd4179SDavid Teigland struct dlm_direntry; 59e7fd4179SDavid Teigland struct dlm_recover; 60e7fd4179SDavid Teigland struct dlm_header; 61e7fd4179SDavid Teigland struct dlm_message; 62e7fd4179SDavid Teigland struct dlm_rcom; 63e7fd4179SDavid Teigland struct dlm_mhandle; 64e7fd4179SDavid Teigland 65e7fd4179SDavid Teigland #define log_print(fmt, args...) \ 66e7fd4179SDavid Teigland printk(KERN_ERR "dlm: "fmt"\n" , ##args) 67e7fd4179SDavid Teigland #define log_error(ls, fmt, args...) \ 68e7fd4179SDavid Teigland printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args) 69e7fd4179SDavid Teigland 7099fc6487SDavid Teigland #define log_debug(ls, fmt, args...) \ 7199fc6487SDavid Teigland do { \ 7299fc6487SDavid Teigland if (dlm_config.ci_log_debug) \ 7399fc6487SDavid Teigland printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ 7499fc6487SDavid Teigland (ls)->ls_name , ##args); \ 7599fc6487SDavid Teigland } while (0) 76e7fd4179SDavid Teigland 77e7fd4179SDavid Teigland #define DLM_ASSERT(x, do) \ 78e7fd4179SDavid Teigland { \ 79e7fd4179SDavid Teigland if (!(x)) \ 80e7fd4179SDavid Teigland { \ 81e7fd4179SDavid Teigland printk(KERN_ERR "\nDLM: Assertion failed on line %d of file %s\n" \ 82e7fd4179SDavid Teigland "DLM: assertion: \"%s\"\n" \ 83e7fd4179SDavid Teigland "DLM: time = %lu\n", \ 84e7fd4179SDavid Teigland __LINE__, __FILE__, #x, jiffies); \ 85e7fd4179SDavid Teigland {do} \ 86e7fd4179SDavid Teigland printk("\n"); \ 87e7fd4179SDavid Teigland BUG(); \ 88e7fd4179SDavid Teigland panic("DLM: Record message above and reboot.\n"); \ 89e7fd4179SDavid Teigland } \ 90e7fd4179SDavid Teigland } 91e7fd4179SDavid Teigland 92e7fd4179SDavid Teigland 93e7fd4179SDavid Teigland struct dlm_direntry { 94e7fd4179SDavid Teigland struct list_head list; 95e7fd4179SDavid Teigland uint32_t master_nodeid; 96e7fd4179SDavid Teigland uint16_t length; 97e7fd4179SDavid Teigland char name[1]; 98e7fd4179SDavid Teigland }; 99e7fd4179SDavid Teigland 100e7fd4179SDavid Teigland struct dlm_dirtable { 101e7fd4179SDavid Teigland struct list_head list; 102305a47b1SSteven Whitehouse spinlock_t lock; 103e7fd4179SDavid Teigland }; 104e7fd4179SDavid Teigland 105e7fd4179SDavid Teigland struct dlm_rsbtable { 106e7fd4179SDavid Teigland struct list_head list; 107e7fd4179SDavid Teigland struct list_head toss; 108c7be761aSDavid Teigland spinlock_t lock; 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; 120e7fd4179SDavid Teigland }; 121e7fd4179SDavid Teigland 122e7fd4179SDavid Teigland /* 123e7fd4179SDavid Teigland * Save and manage recovery state for a lockspace. 124e7fd4179SDavid Teigland */ 125e7fd4179SDavid Teigland 126e7fd4179SDavid Teigland struct dlm_recover { 127e7fd4179SDavid Teigland struct list_head list; 128d44e0fc7SDavid Teigland int *nodeids; /* nodeids of all members */ 129e7fd4179SDavid Teigland int node_count; 130d44e0fc7SDavid Teigland int *new; /* nodeids of new members */ 131d44e0fc7SDavid Teigland int new_count; 132e7fd4179SDavid Teigland uint64_t seq; 133e7fd4179SDavid Teigland }; 134e7fd4179SDavid Teigland 135e7fd4179SDavid Teigland /* 136e7fd4179SDavid Teigland * Pass input args to second stage locking function. 137e7fd4179SDavid Teigland */ 138e7fd4179SDavid Teigland 139e7fd4179SDavid Teigland struct dlm_args { 140e7fd4179SDavid Teigland uint32_t flags; 141e5dae548SDavid Teigland void (*astfn) (void *astparam); 142e5dae548SDavid Teigland void *astparam; 143e5dae548SDavid Teigland void (*bastfn) (void *astparam, int mode); 144e7fd4179SDavid Teigland int mode; 145e7fd4179SDavid Teigland struct dlm_lksb *lksb; 146d7db923eSDavid Teigland unsigned long timeout; 147e7fd4179SDavid Teigland }; 148e7fd4179SDavid Teigland 149e7fd4179SDavid Teigland 150e7fd4179SDavid Teigland /* 151e7fd4179SDavid Teigland * Lock block 152e7fd4179SDavid Teigland * 153e7fd4179SDavid Teigland * A lock can be one of three types: 154e7fd4179SDavid Teigland * 155e7fd4179SDavid Teigland * local copy lock is mastered locally 156e7fd4179SDavid Teigland * (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set) 157e7fd4179SDavid Teigland * process copy lock is mastered on a remote node 158e7fd4179SDavid Teigland * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set) 159e7fd4179SDavid Teigland * master copy master node's copy of a lock owned by remote node 160e7fd4179SDavid Teigland * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set) 161e7fd4179SDavid Teigland * 162e7fd4179SDavid Teigland * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or 163e7fd4179SDavid Teigland * dlm_unlock. The dlm does not modify these or use any private flags in 164e7fd4179SDavid Teigland * this field; it only contains DLM_LKF_ flags from dlm.h. These flags 165e7fd4179SDavid Teigland * are sent as-is to the remote master when the lock is remote. 166e7fd4179SDavid Teigland * 167e7fd4179SDavid Teigland * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h. 168e7fd4179SDavid Teigland * Some internal flags are shared between the master and process nodes; 169e7fd4179SDavid Teigland * these shared flags are kept in the lower two bytes. One of these 170e7fd4179SDavid Teigland * flags set on the master copy will be propagated to the process copy 171e7fd4179SDavid Teigland * and v.v. Other internal flags are private to the master or process 172e7fd4179SDavid Teigland * node (e.g. DLM_IFL_MSTCPY). These are kept in the high two bytes. 173e7fd4179SDavid Teigland * 174e7fd4179SDavid Teigland * lkb_sbflags: status block flags. These flags are copied directly into 175e7fd4179SDavid Teigland * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion 176e7fd4179SDavid Teigland * ast. All defined in dlm.h with DLM_SBF_ prefix. 177e7fd4179SDavid Teigland * 178e7fd4179SDavid Teigland * lkb_status: the lock status indicates which rsb queue the lock is 179e7fd4179SDavid Teigland * on, grant, convert, or wait. DLM_LKSTS_ WAITING/GRANTED/CONVERT 180e7fd4179SDavid Teigland * 181e7fd4179SDavid Teigland * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a 182e7fd4179SDavid Teigland * reply is needed. Only set when the lkb is on the lockspace waiters 183e7fd4179SDavid Teigland * list awaiting a reply from a remote node. 184e7fd4179SDavid Teigland * 185e7fd4179SDavid Teigland * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb 186e7fd4179SDavid Teigland * is a master copy, nodeid specifies the remote lock holder, when the 187e7fd4179SDavid Teigland * lkb is a process copy, the nodeid specifies the lock master. 188e7fd4179SDavid Teigland */ 189e7fd4179SDavid Teigland 190e7fd4179SDavid Teigland /* lkb_status */ 191e7fd4179SDavid Teigland 192e7fd4179SDavid Teigland #define DLM_LKSTS_WAITING 1 193e7fd4179SDavid Teigland #define DLM_LKSTS_GRANTED 2 194e7fd4179SDavid Teigland #define DLM_LKSTS_CONVERT 3 195e7fd4179SDavid Teigland 196e7fd4179SDavid Teigland /* lkb_flags */ 197e7fd4179SDavid Teigland 198e7fd4179SDavid Teigland #define DLM_IFL_MSTCPY 0x00010000 199e7fd4179SDavid Teigland #define DLM_IFL_RESEND 0x00020000 200597d0caeSDavid Teigland #define DLM_IFL_DEAD 0x00040000 201ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_UNLOCK 0x00080000 202ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_CANCEL 0x00100000 203ef0c2bb0SDavid Teigland #define DLM_IFL_ENDOFLIFE 0x00200000 2043ae1acf9SDavid Teigland #define DLM_IFL_WATCH_TIMEWARN 0x00400000 20584d8cd69SDavid Teigland #define DLM_IFL_TIMEOUT_CANCEL 0x00800000 2068b4021faSDavid Teigland #define DLM_IFL_DEADLOCK_CANCEL 0x01000000 2072a7ce0edSDavid Teigland #define DLM_IFL_STUB_MS 0x02000000 /* magic number for m_flags */ 208597d0caeSDavid Teigland #define DLM_IFL_USER 0x00000001 209597d0caeSDavid Teigland #define DLM_IFL_ORPHAN 0x00000002 210e7fd4179SDavid Teigland 2118304d6f2SDavid Teigland #define DLM_CALLBACKS_SIZE 6 2128304d6f2SDavid Teigland 2138304d6f2SDavid Teigland #define DLM_CB_CAST 0x00000001 2148304d6f2SDavid Teigland #define DLM_CB_BAST 0x00000002 2158304d6f2SDavid Teigland #define DLM_CB_SKIP 0x00000004 2168304d6f2SDavid Teigland 2178304d6f2SDavid Teigland struct dlm_callback { 2188304d6f2SDavid Teigland uint64_t seq; 2198304d6f2SDavid Teigland uint32_t flags; /* DLM_CBF_ */ 2208304d6f2SDavid Teigland int sb_status; /* copy to lksb status */ 2218304d6f2SDavid Teigland uint8_t sb_flags; /* copy to lksb flags */ 2228304d6f2SDavid Teigland int8_t mode; /* rq mode of bast, gr mode of cast */ 2238304d6f2SDavid Teigland }; 2248304d6f2SDavid Teigland 225e7fd4179SDavid Teigland struct dlm_lkb { 226e7fd4179SDavid Teigland struct dlm_rsb *lkb_resource; /* the rsb */ 227e7fd4179SDavid Teigland struct kref lkb_ref; 228e7fd4179SDavid Teigland int lkb_nodeid; /* copied from rsb */ 229e7fd4179SDavid Teigland int lkb_ownpid; /* pid of lock owner */ 230e7fd4179SDavid Teigland uint32_t lkb_id; /* our lock ID */ 231e7fd4179SDavid Teigland uint32_t lkb_remid; /* lock ID on remote partner */ 232e7fd4179SDavid Teigland uint32_t lkb_exflags; /* external flags from caller */ 233e7fd4179SDavid Teigland uint32_t lkb_sbflags; /* lksb flags */ 234e7fd4179SDavid Teigland uint32_t lkb_flags; /* internal flags */ 235e7fd4179SDavid Teigland uint32_t lkb_lvbseq; /* lvb sequence number */ 236e7fd4179SDavid Teigland 237e7fd4179SDavid Teigland int8_t lkb_status; /* granted, waiting, convert */ 238e7fd4179SDavid Teigland int8_t lkb_rqmode; /* requested lock mode */ 239e7fd4179SDavid Teigland int8_t lkb_grmode; /* granted lock mode */ 240e7fd4179SDavid Teigland int8_t lkb_highbast; /* highest mode bast sent for */ 2417fe2b319SDavid Teigland 242e7fd4179SDavid Teigland int8_t lkb_wait_type; /* type of reply waiting for */ 243ef0c2bb0SDavid Teigland int8_t lkb_wait_count; 244c6ff669bSDavid Teigland int lkb_wait_nodeid; /* for debugging */ 245e7fd4179SDavid Teigland 246e7fd4179SDavid Teigland struct list_head lkb_statequeue; /* rsb g/c/w list */ 247e7fd4179SDavid Teigland struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */ 248e7fd4179SDavid Teigland struct list_head lkb_wait_reply; /* waiting for remote reply */ 249597d0caeSDavid Teigland struct list_head lkb_ownqueue; /* list of locks for a process */ 2503ae1acf9SDavid Teigland struct list_head lkb_time_list; 251eeda418dSDavid Teigland ktime_t lkb_timestamp; 252c6ff669bSDavid Teigland ktime_t lkb_wait_time; 2533ae1acf9SDavid Teigland unsigned long lkb_timeout_cs; 254e7fd4179SDavid Teigland 255*23e8e1aaSDavid Teigland struct mutex lkb_cb_mutex; 256*23e8e1aaSDavid Teigland struct work_struct lkb_cb_work; 257*23e8e1aaSDavid Teigland struct list_head lkb_cb_list; /* for ls_cb_delay or proc->asts */ 2588304d6f2SDavid Teigland struct dlm_callback lkb_callbacks[DLM_CALLBACKS_SIZE]; 2598304d6f2SDavid Teigland struct dlm_callback lkb_last_cast; 2608304d6f2SDavid Teigland struct dlm_callback lkb_last_bast; 2618304d6f2SDavid Teigland ktime_t lkb_last_cast_time; /* for debugging */ 2628304d6f2SDavid Teigland ktime_t lkb_last_bast_time; /* for debugging */ 2638304d6f2SDavid Teigland 264e7fd4179SDavid Teigland char *lkb_lvbptr; 265e7fd4179SDavid Teigland struct dlm_lksb *lkb_lksb; /* caller's status block */ 266e5dae548SDavid Teigland void (*lkb_astfn) (void *astparam); 267e5dae548SDavid Teigland void (*lkb_bastfn) (void *astparam, int mode); 268d292c0ccSDavid Teigland union { 269e5dae548SDavid Teigland void *lkb_astparam; /* caller's ast arg */ 270d292c0ccSDavid Teigland struct dlm_user_args *lkb_ua; 271d292c0ccSDavid Teigland }; 272e7fd4179SDavid Teigland }; 273e7fd4179SDavid Teigland 274e7fd4179SDavid Teigland 275e7fd4179SDavid Teigland struct dlm_rsb { 276e7fd4179SDavid Teigland struct dlm_ls *res_ls; /* the lockspace */ 277e7fd4179SDavid Teigland struct kref res_ref; 27890135925SDavid Teigland struct mutex res_mutex; 279e7fd4179SDavid Teigland unsigned long res_flags; 280e7fd4179SDavid Teigland int res_length; /* length of rsb name */ 281e7fd4179SDavid Teigland int res_nodeid; 282e7fd4179SDavid Teigland uint32_t res_lvbseq; 283e7fd4179SDavid Teigland uint32_t res_hash; 284e7fd4179SDavid Teigland uint32_t res_bucket; /* rsbtbl */ 285e7fd4179SDavid Teigland unsigned long res_toss_time; 286e7fd4179SDavid Teigland uint32_t res_first_lkid; 287e7fd4179SDavid Teigland struct list_head res_lookup; /* lkbs waiting on first */ 288e7fd4179SDavid Teigland struct list_head res_hashchain; /* rsbtbl */ 289e7fd4179SDavid Teigland struct list_head res_grantqueue; 290e7fd4179SDavid Teigland struct list_head res_convertqueue; 291e7fd4179SDavid Teigland struct list_head res_waitqueue; 292e7fd4179SDavid Teigland 293e7fd4179SDavid Teigland struct list_head res_root_list; /* used for recovery */ 294e7fd4179SDavid Teigland struct list_head res_recover_list; /* used for recovery */ 295e7fd4179SDavid Teigland int res_recover_locks_count; 296e7fd4179SDavid Teigland 297e7fd4179SDavid Teigland char *res_lvbptr; 2983881ac04SDavid Teigland char res_name[DLM_RESNAME_MAXLEN+1]; 299e7fd4179SDavid Teigland }; 300e7fd4179SDavid Teigland 301e7fd4179SDavid Teigland /* find_rsb() flags */ 302e7fd4179SDavid Teigland 303e7fd4179SDavid Teigland #define R_MASTER 1 /* only return rsb if it's a master */ 304e7fd4179SDavid Teigland #define R_CREATE 2 /* create/add rsb if not found */ 305e7fd4179SDavid Teigland 306e7fd4179SDavid Teigland /* rsb_flags */ 307e7fd4179SDavid Teigland 308e7fd4179SDavid Teigland enum rsb_flags { 309e7fd4179SDavid Teigland RSB_MASTER_UNCERTAIN, 310e7fd4179SDavid Teigland RSB_VALNOTVALID, 311e7fd4179SDavid Teigland RSB_VALNOTVALID_PREV, 312e7fd4179SDavid Teigland RSB_NEW_MASTER, 313e7fd4179SDavid Teigland RSB_NEW_MASTER2, 314e7fd4179SDavid Teigland RSB_RECOVER_CONVERT, 31597a35d1eSDavid Teigland RSB_LOCKS_PURGED, 316e7fd4179SDavid Teigland }; 317e7fd4179SDavid Teigland 318e7fd4179SDavid Teigland static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag) 319e7fd4179SDavid Teigland { 320e7fd4179SDavid Teigland __set_bit(flag, &r->res_flags); 321e7fd4179SDavid Teigland } 322e7fd4179SDavid Teigland 323e7fd4179SDavid Teigland static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag) 324e7fd4179SDavid Teigland { 325e7fd4179SDavid Teigland __clear_bit(flag, &r->res_flags); 326e7fd4179SDavid Teigland } 327e7fd4179SDavid Teigland 328e7fd4179SDavid Teigland static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag) 329e7fd4179SDavid Teigland { 330e7fd4179SDavid Teigland return test_bit(flag, &r->res_flags); 331e7fd4179SDavid Teigland } 332e7fd4179SDavid Teigland 333e7fd4179SDavid Teigland 334e7fd4179SDavid Teigland /* dlm_header is first element of all structs sent between nodes */ 335e7fd4179SDavid Teigland 33638aa8b0cSDavid Teigland #define DLM_HEADER_MAJOR 0x00030000 33738aa8b0cSDavid Teigland #define DLM_HEADER_MINOR 0x00000000 338e7fd4179SDavid Teigland 339e7fd4179SDavid Teigland #define DLM_MSG 1 340e7fd4179SDavid Teigland #define DLM_RCOM 2 341e7fd4179SDavid Teigland 342e7fd4179SDavid Teigland struct dlm_header { 343e7fd4179SDavid Teigland uint32_t h_version; 344e7fd4179SDavid Teigland uint32_t h_lockspace; 345e7fd4179SDavid Teigland uint32_t h_nodeid; /* nodeid of sender */ 346e7fd4179SDavid Teigland uint16_t h_length; 347e7fd4179SDavid Teigland uint8_t h_cmd; /* DLM_MSG, DLM_RCOM */ 348e7fd4179SDavid Teigland uint8_t h_pad; 349e7fd4179SDavid Teigland }; 350e7fd4179SDavid Teigland 351e7fd4179SDavid Teigland 352e7fd4179SDavid Teigland #define DLM_MSG_REQUEST 1 353e7fd4179SDavid Teigland #define DLM_MSG_CONVERT 2 354e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK 3 355e7fd4179SDavid Teigland #define DLM_MSG_CANCEL 4 356e7fd4179SDavid Teigland #define DLM_MSG_REQUEST_REPLY 5 357e7fd4179SDavid Teigland #define DLM_MSG_CONVERT_REPLY 6 358e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK_REPLY 7 359e7fd4179SDavid Teigland #define DLM_MSG_CANCEL_REPLY 8 360e7fd4179SDavid Teigland #define DLM_MSG_GRANT 9 361e7fd4179SDavid Teigland #define DLM_MSG_BAST 10 362e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP 11 363e7fd4179SDavid Teigland #define DLM_MSG_REMOVE 12 364e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP_REPLY 13 3658499137dSDavid Teigland #define DLM_MSG_PURGE 14 366e7fd4179SDavid Teigland 367e7fd4179SDavid Teigland struct dlm_message { 368e7fd4179SDavid Teigland struct dlm_header m_header; 369e7fd4179SDavid Teigland uint32_t m_type; /* DLM_MSG_ */ 370e7fd4179SDavid Teigland uint32_t m_nodeid; 371e7fd4179SDavid Teigland uint32_t m_pid; 372e7fd4179SDavid Teigland uint32_t m_lkid; /* lkid on sender */ 373e7fd4179SDavid Teigland uint32_t m_remid; /* lkid on receiver */ 374e7fd4179SDavid Teigland uint32_t m_parent_lkid; 375e7fd4179SDavid Teigland uint32_t m_parent_remid; 376e7fd4179SDavid Teigland uint32_t m_exflags; 377e7fd4179SDavid Teigland uint32_t m_sbflags; 378e7fd4179SDavid Teigland uint32_t m_flags; 379e7fd4179SDavid Teigland uint32_t m_lvbseq; 380e7fd4179SDavid Teigland uint32_t m_hash; 381e7fd4179SDavid Teigland int m_status; 382e7fd4179SDavid Teigland int m_grmode; 383e7fd4179SDavid Teigland int m_rqmode; 384e7fd4179SDavid Teigland int m_bastmode; 385e7fd4179SDavid Teigland int m_asts; 386e7fd4179SDavid Teigland int m_result; /* 0 or -EXXX */ 387e7fd4179SDavid Teigland char m_extra[0]; /* name or lvb */ 388e7fd4179SDavid Teigland }; 389e7fd4179SDavid Teigland 390e7fd4179SDavid Teigland 391e7fd4179SDavid Teigland #define DLM_RS_NODES 0x00000001 392e7fd4179SDavid Teigland #define DLM_RS_NODES_ALL 0x00000002 393e7fd4179SDavid Teigland #define DLM_RS_DIR 0x00000004 394e7fd4179SDavid Teigland #define DLM_RS_DIR_ALL 0x00000008 395e7fd4179SDavid Teigland #define DLM_RS_LOCKS 0x00000010 396e7fd4179SDavid Teigland #define DLM_RS_LOCKS_ALL 0x00000020 397e7fd4179SDavid Teigland #define DLM_RS_DONE 0x00000040 398e7fd4179SDavid Teigland #define DLM_RS_DONE_ALL 0x00000080 399e7fd4179SDavid Teigland 400e7fd4179SDavid Teigland #define DLM_RCOM_STATUS 1 401e7fd4179SDavid Teigland #define DLM_RCOM_NAMES 2 402e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP 3 403e7fd4179SDavid Teigland #define DLM_RCOM_LOCK 4 404e7fd4179SDavid Teigland #define DLM_RCOM_STATUS_REPLY 5 405e7fd4179SDavid Teigland #define DLM_RCOM_NAMES_REPLY 6 406e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP_REPLY 7 407e7fd4179SDavid Teigland #define DLM_RCOM_LOCK_REPLY 8 408e7fd4179SDavid Teigland 409e7fd4179SDavid Teigland struct dlm_rcom { 410e7fd4179SDavid Teigland struct dlm_header rc_header; 411e7fd4179SDavid Teigland uint32_t rc_type; /* DLM_RCOM_ */ 412e7fd4179SDavid Teigland int rc_result; /* multi-purpose */ 413e7fd4179SDavid Teigland uint64_t rc_id; /* match reply with request */ 41438aa8b0cSDavid Teigland uint64_t rc_seq; /* sender's ls_recover_seq */ 41538aa8b0cSDavid Teigland uint64_t rc_seq_reply; /* remote ls_recover_seq */ 416e7fd4179SDavid Teigland char rc_buf[0]; 417e7fd4179SDavid Teigland }; 418e7fd4179SDavid Teigland 419eef7d739SAl Viro union dlm_packet { 420eef7d739SAl Viro struct dlm_header header; /* common to other two */ 421eef7d739SAl Viro struct dlm_message message; 422eef7d739SAl Viro struct dlm_rcom rcom; 423eef7d739SAl Viro }; 424eef7d739SAl Viro 425e7fd4179SDavid Teigland struct rcom_config { 42693ff2971SAl Viro __le32 rf_lvblen; 42793ff2971SAl Viro __le32 rf_lsflags; 42893ff2971SAl Viro __le64 rf_unused; 429e7fd4179SDavid Teigland }; 430e7fd4179SDavid Teigland 431e7fd4179SDavid Teigland struct rcom_lock { 432163a1859SAl Viro __le32 rl_ownpid; 433163a1859SAl Viro __le32 rl_lkid; 434163a1859SAl Viro __le32 rl_remid; 435163a1859SAl Viro __le32 rl_parent_lkid; 436163a1859SAl Viro __le32 rl_parent_remid; 437163a1859SAl Viro __le32 rl_exflags; 438163a1859SAl Viro __le32 rl_flags; 439163a1859SAl Viro __le32 rl_lvbseq; 440163a1859SAl Viro __le32 rl_result; 441e7fd4179SDavid Teigland int8_t rl_rqmode; 442e7fd4179SDavid Teigland int8_t rl_grmode; 443e7fd4179SDavid Teigland int8_t rl_status; 444e7fd4179SDavid Teigland int8_t rl_asts; 445163a1859SAl Viro __le16 rl_wait_type; 446163a1859SAl Viro __le16 rl_namelen; 447e7fd4179SDavid Teigland char rl_name[DLM_RESNAME_MAXLEN]; 448e7fd4179SDavid Teigland char rl_lvb[0]; 449e7fd4179SDavid Teigland }; 450e7fd4179SDavid Teigland 451e7fd4179SDavid Teigland struct dlm_ls { 452e7fd4179SDavid Teigland struct list_head ls_list; /* list of lockspaces */ 453597d0caeSDavid Teigland dlm_lockspace_t *ls_local_handle; 454e7fd4179SDavid Teigland uint32_t ls_global_id; /* global unique lockspace ID */ 455e7fd4179SDavid Teigland uint32_t ls_exflags; 456e7fd4179SDavid Teigland int ls_lvblen; 4570f8e0d9aSDavid Teigland int ls_count; /* refcount of processes in 4580f8e0d9aSDavid Teigland the dlm using this ls */ 4590f8e0d9aSDavid Teigland int ls_create_count; /* create/release refcount */ 460e7fd4179SDavid Teigland unsigned long ls_flags; /* LSFL_ */ 461c1dcf65fSDavid Teigland unsigned long ls_scan_time; 462e7fd4179SDavid Teigland struct kobject ls_kobj; 463e7fd4179SDavid Teigland 4643d6aa675SDavid Teigland struct idr ls_lkbidr; 4653d6aa675SDavid Teigland spinlock_t ls_lkbidr_spin; 4663d6aa675SDavid Teigland 467e7fd4179SDavid Teigland struct dlm_rsbtable *ls_rsbtbl; 468e7fd4179SDavid Teigland uint32_t ls_rsbtbl_size; 469e7fd4179SDavid Teigland 470e7fd4179SDavid Teigland struct dlm_dirtable *ls_dirtbl; 471e7fd4179SDavid Teigland uint32_t ls_dirtbl_size; 472e7fd4179SDavid Teigland 47390135925SDavid Teigland struct mutex ls_waiters_mutex; 474e7fd4179SDavid Teigland struct list_head ls_waiters; /* lkbs needing a reply */ 475e7fd4179SDavid Teigland 476ef0c2bb0SDavid Teigland struct mutex ls_orphans_mutex; 477ef0c2bb0SDavid Teigland struct list_head ls_orphans; 478ef0c2bb0SDavid Teigland 4793ae1acf9SDavid Teigland struct mutex ls_timeout_mutex; 4803ae1acf9SDavid Teigland struct list_head ls_timeout; 4813ae1acf9SDavid Teigland 4823881ac04SDavid Teigland spinlock_t ls_new_rsb_spin; 4833881ac04SDavid Teigland int ls_new_rsb_count; 4843881ac04SDavid Teigland struct list_head ls_new_rsb; /* new rsb structs */ 4853881ac04SDavid Teigland 486e7fd4179SDavid Teigland struct list_head ls_nodes; /* current nodes in ls */ 487e7fd4179SDavid Teigland struct list_head ls_nodes_gone; /* dead node list, recovery */ 488e7fd4179SDavid Teigland int ls_num_nodes; /* number of nodes in ls */ 489e7fd4179SDavid Teigland int ls_low_nodeid; 490e7fd4179SDavid Teigland int ls_total_weight; 491e7fd4179SDavid Teigland int *ls_node_array; 492e7fd4179SDavid Teigland 493e7fd4179SDavid Teigland struct dlm_rsb ls_stub_rsb; /* for returning errors */ 494e7fd4179SDavid Teigland struct dlm_lkb ls_stub_lkb; /* for returning errors */ 495e7fd4179SDavid Teigland struct dlm_message ls_stub_ms; /* for faking a reply */ 496e7fd4179SDavid Teigland 4975de6319bSDavid Teigland struct dentry *ls_debug_rsb_dentry; /* debugfs */ 4985de6319bSDavid Teigland struct dentry *ls_debug_waiters_dentry; /* debugfs */ 499ac90a255SDavid Teigland struct dentry *ls_debug_locks_dentry; /* debugfs */ 500d022509dSDavid Teigland struct dentry *ls_debug_all_dentry; /* debugfs */ 501e7fd4179SDavid Teigland 502e7fd4179SDavid Teigland wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ 503e7fd4179SDavid Teigland int ls_uevent_result; 5048b0e7b2cSDavid Teigland struct completion ls_members_done; 5058b0e7b2cSDavid Teigland int ls_members_result; 506e7fd4179SDavid Teigland 507597d0caeSDavid Teigland struct miscdevice ls_device; 508597d0caeSDavid Teigland 509*23e8e1aaSDavid Teigland struct workqueue_struct *ls_callback_wq; 510*23e8e1aaSDavid Teigland 511e7fd4179SDavid Teigland /* recovery related */ 512e7fd4179SDavid Teigland 513*23e8e1aaSDavid Teigland struct mutex ls_cb_mutex; 514*23e8e1aaSDavid Teigland struct list_head ls_cb_delay; /* save for queue_work later */ 515e7fd4179SDavid Teigland struct timer_list ls_timer; 516e7fd4179SDavid Teigland struct task_struct *ls_recoverd_task; 51790135925SDavid Teigland struct mutex ls_recoverd_active; 518e7fd4179SDavid Teigland spinlock_t ls_recover_lock; 5193ae1acf9SDavid Teigland unsigned long ls_recover_begin; /* jiffies timestamp */ 520e7fd4179SDavid Teigland uint32_t ls_recover_status; /* DLM_RS_ */ 521e7fd4179SDavid Teigland uint64_t ls_recover_seq; 522e7fd4179SDavid Teigland struct dlm_recover *ls_recover_args; 523e7fd4179SDavid Teigland struct rw_semaphore ls_in_recovery; /* block local requests */ 524c36258b5SDavid Teigland struct rw_semaphore ls_recv_active; /* block dlm_recv */ 525e7fd4179SDavid Teigland struct list_head ls_requestqueue;/* queue remote requests */ 52690135925SDavid Teigland struct mutex ls_requestqueue_mutex; 5274007685cSAl Viro struct dlm_rcom *ls_recover_buf; 528faa0f267SDavid Teigland int ls_recover_nodeid; /* for debugging */ 5294a99c3d9SDavid Teigland uint64_t ls_rcom_seq; 53098f176fbSDavid Teigland spinlock_t ls_rcom_spin; 531e7fd4179SDavid Teigland struct list_head ls_recover_list; 532e7fd4179SDavid Teigland spinlock_t ls_recover_list_lock; 533e7fd4179SDavid Teigland int ls_recover_list_count; 534e7fd4179SDavid Teigland wait_queue_head_t ls_wait_general; 535597d0caeSDavid Teigland struct mutex ls_clear_proc_locks; 536e7fd4179SDavid Teigland 537e7fd4179SDavid Teigland struct list_head ls_root_list; /* root resources */ 538e7fd4179SDavid Teigland struct rw_semaphore ls_root_sem; /* protect root_list */ 539e7fd4179SDavid Teigland 540e7fd4179SDavid Teigland int ls_namelen; 541e7fd4179SDavid Teigland char ls_name[1]; 542e7fd4179SDavid Teigland }; 543e7fd4179SDavid Teigland 544e7fd4179SDavid Teigland #define LSFL_WORK 0 545e7fd4179SDavid Teigland #define LSFL_RUNNING 1 546e7fd4179SDavid Teigland #define LSFL_RECOVERY_STOP 2 547e7fd4179SDavid Teigland #define LSFL_RCOM_READY 3 54898f176fbSDavid Teigland #define LSFL_RCOM_WAIT 4 54998f176fbSDavid Teigland #define LSFL_UEVENT_WAIT 5 5503ae1acf9SDavid Teigland #define LSFL_TIMEWARN 6 551*23e8e1aaSDavid Teigland #define LSFL_CB_DELAY 7 552e7fd4179SDavid Teigland 553597d0caeSDavid Teigland /* much of this is just saving user space pointers associated with the 554597d0caeSDavid Teigland lock that we pass back to the user lib with an ast */ 555597d0caeSDavid Teigland 556597d0caeSDavid Teigland struct dlm_user_args { 557597d0caeSDavid Teigland struct dlm_user_proc *proc; /* each process that opens the lockspace 558597d0caeSDavid Teigland device has private data 559597d0caeSDavid Teigland (dlm_user_proc) on the struct file, 560597d0caeSDavid Teigland the process's locks point back to it*/ 561597d0caeSDavid Teigland struct dlm_lksb lksb; 562597d0caeSDavid Teigland struct dlm_lksb __user *user_lksb; 563597d0caeSDavid Teigland void __user *castparam; 564597d0caeSDavid Teigland void __user *castaddr; 565597d0caeSDavid Teigland void __user *bastparam; 566597d0caeSDavid Teigland void __user *bastaddr; 567d7db923eSDavid Teigland uint64_t xid; 568597d0caeSDavid Teigland }; 569597d0caeSDavid Teigland 570597d0caeSDavid Teigland #define DLM_PROC_FLAGS_CLOSING 1 571597d0caeSDavid Teigland #define DLM_PROC_FLAGS_COMPAT 2 572597d0caeSDavid Teigland 573597d0caeSDavid Teigland /* locks list is kept so we can remove all a process's locks when it 574597d0caeSDavid Teigland exits (or orphan those that are persistent) */ 575597d0caeSDavid Teigland 576597d0caeSDavid Teigland struct dlm_user_proc { 577597d0caeSDavid Teigland dlm_lockspace_t *lockspace; 578597d0caeSDavid Teigland unsigned long flags; /* DLM_PROC_FLAGS */ 579597d0caeSDavid Teigland struct list_head asts; 580597d0caeSDavid Teigland spinlock_t asts_spin; 581597d0caeSDavid Teigland struct list_head locks; 582597d0caeSDavid Teigland spinlock_t locks_spin; 583a1bc86e6SDavid Teigland struct list_head unlocking; 584597d0caeSDavid Teigland wait_queue_head_t wait; 585597d0caeSDavid Teigland }; 586597d0caeSDavid Teigland 587e7fd4179SDavid Teigland static inline int dlm_locking_stopped(struct dlm_ls *ls) 588e7fd4179SDavid Teigland { 589e7fd4179SDavid Teigland return !test_bit(LSFL_RUNNING, &ls->ls_flags); 590e7fd4179SDavid Teigland } 591e7fd4179SDavid Teigland 592e7fd4179SDavid Teigland static inline int dlm_recovery_stopped(struct dlm_ls *ls) 593e7fd4179SDavid Teigland { 594e7fd4179SDavid Teigland return test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); 595e7fd4179SDavid Teigland } 596e7fd4179SDavid Teigland 597e7fd4179SDavid Teigland static inline int dlm_no_directory(struct dlm_ls *ls) 598e7fd4179SDavid Teigland { 599e7fd4179SDavid Teigland return (ls->ls_exflags & DLM_LSFL_NODIR) ? 1 : 0; 600e7fd4179SDavid Teigland } 601e7fd4179SDavid Teigland 602e028398dSAdrian Bunk int dlm_netlink_init(void); 603e028398dSAdrian Bunk void dlm_netlink_exit(void); 604e028398dSAdrian Bunk void dlm_timeout_warn(struct dlm_lkb *lkb); 6052402211aSDavid Teigland int dlm_plock_init(void); 6062402211aSDavid Teigland void dlm_plock_exit(void); 607e028398dSAdrian Bunk 608e028398dSAdrian Bunk #ifdef CONFIG_DLM_DEBUG 609e028398dSAdrian Bunk int dlm_register_debugfs(void); 610e028398dSAdrian Bunk void dlm_unregister_debugfs(void); 611e028398dSAdrian Bunk int dlm_create_debug_file(struct dlm_ls *ls); 612e028398dSAdrian Bunk void dlm_delete_debug_file(struct dlm_ls *ls); 613e028398dSAdrian Bunk #else 614e028398dSAdrian Bunk static inline int dlm_register_debugfs(void) { return 0; } 615e028398dSAdrian Bunk static inline void dlm_unregister_debugfs(void) { } 616e028398dSAdrian Bunk static inline int dlm_create_debug_file(struct dlm_ls *ls) { return 0; } 617e028398dSAdrian Bunk static inline void dlm_delete_debug_file(struct dlm_ls *ls) { } 618e028398dSAdrian Bunk #endif 619e028398dSAdrian Bunk 620e7fd4179SDavid Teigland #endif /* __DLM_INTERNAL_DOT_H__ */ 621e7fd4179SDavid Teigland 622