1e7fd4179SDavid Teigland /****************************************************************************** 2e7fd4179SDavid Teigland ******************************************************************************* 3e7fd4179SDavid Teigland ** 4e7fd4179SDavid Teigland ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5ef0c2bb0SDavid Teigland ** Copyright (C) 2004-2007 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> 40e7fd4179SDavid Teigland #include <asm/semaphore.h> 41e7fd4179SDavid Teigland #include <asm/uaccess.h> 42e7fd4179SDavid Teigland 43e7fd4179SDavid Teigland #include <linux/dlm.h> 4499fc6487SDavid Teigland #include "config.h" 45e7fd4179SDavid Teigland 46e7fd4179SDavid Teigland #define DLM_LOCKSPACE_LEN 64 47e7fd4179SDavid Teigland 48e7fd4179SDavid Teigland /* Size of the temp buffer midcomms allocates on the stack. 49e7fd4179SDavid Teigland We try to make this large enough so most messages fit. 50e7fd4179SDavid Teigland FIXME: should sctp make this unnecessary? */ 51e7fd4179SDavid Teigland 52e7fd4179SDavid Teigland #define DLM_INBUF_LEN 148 53e7fd4179SDavid Teigland 54e7fd4179SDavid Teigland struct dlm_ls; 55e7fd4179SDavid Teigland struct dlm_lkb; 56e7fd4179SDavid Teigland struct dlm_rsb; 57e7fd4179SDavid Teigland struct dlm_member; 58e7fd4179SDavid Teigland struct dlm_lkbtable; 59e7fd4179SDavid Teigland struct dlm_rsbtable; 60e7fd4179SDavid Teigland struct dlm_dirtable; 61e7fd4179SDavid Teigland struct dlm_direntry; 62e7fd4179SDavid Teigland struct dlm_recover; 63e7fd4179SDavid Teigland struct dlm_header; 64e7fd4179SDavid Teigland struct dlm_message; 65e7fd4179SDavid Teigland struct dlm_rcom; 66e7fd4179SDavid Teigland struct dlm_mhandle; 67e7fd4179SDavid Teigland 68e7fd4179SDavid Teigland #define log_print(fmt, args...) \ 69e7fd4179SDavid Teigland printk(KERN_ERR "dlm: "fmt"\n" , ##args) 70e7fd4179SDavid Teigland #define log_error(ls, fmt, args...) \ 71e7fd4179SDavid Teigland printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args) 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 80e7fd4179SDavid Teigland #define DLM_ASSERT(x, do) \ 81e7fd4179SDavid Teigland { \ 82e7fd4179SDavid Teigland if (!(x)) \ 83e7fd4179SDavid Teigland { \ 84e7fd4179SDavid Teigland printk(KERN_ERR "\nDLM: Assertion failed on line %d of file %s\n" \ 85e7fd4179SDavid Teigland "DLM: assertion: \"%s\"\n" \ 86e7fd4179SDavid Teigland "DLM: time = %lu\n", \ 87e7fd4179SDavid Teigland __LINE__, __FILE__, #x, jiffies); \ 88e7fd4179SDavid Teigland {do} \ 89e7fd4179SDavid Teigland printk("\n"); \ 90e7fd4179SDavid Teigland BUG(); \ 91e7fd4179SDavid Teigland panic("DLM: Record message above and reboot.\n"); \ 92e7fd4179SDavid Teigland } \ 93e7fd4179SDavid Teigland } 94e7fd4179SDavid Teigland 9532f105a1SDavid Teigland #define DLM_FAKE_USER_AST ERR_PTR(-EINVAL) 9632f105a1SDavid Teigland 97e7fd4179SDavid Teigland 98e7fd4179SDavid Teigland struct dlm_direntry { 99e7fd4179SDavid Teigland struct list_head list; 100e7fd4179SDavid Teigland uint32_t master_nodeid; 101e7fd4179SDavid Teigland uint16_t length; 102e7fd4179SDavid Teigland char name[1]; 103e7fd4179SDavid Teigland }; 104e7fd4179SDavid Teigland 105e7fd4179SDavid Teigland struct dlm_dirtable { 106e7fd4179SDavid Teigland struct list_head list; 107e7fd4179SDavid Teigland rwlock_t lock; 108e7fd4179SDavid Teigland }; 109e7fd4179SDavid Teigland 110e7fd4179SDavid Teigland struct dlm_rsbtable { 111e7fd4179SDavid Teigland struct list_head list; 112e7fd4179SDavid Teigland struct list_head toss; 113e7fd4179SDavid Teigland rwlock_t lock; 114e7fd4179SDavid Teigland }; 115e7fd4179SDavid Teigland 116e7fd4179SDavid Teigland struct dlm_lkbtable { 117e7fd4179SDavid Teigland struct list_head list; 118e7fd4179SDavid Teigland rwlock_t lock; 119e7fd4179SDavid Teigland uint16_t counter; 120e7fd4179SDavid Teigland }; 121e7fd4179SDavid Teigland 122e7fd4179SDavid Teigland /* 123e7fd4179SDavid Teigland * Lockspace member (per node in a ls) 124e7fd4179SDavid Teigland */ 125e7fd4179SDavid Teigland 126e7fd4179SDavid Teigland struct dlm_member { 127e7fd4179SDavid Teigland struct list_head list; 128e7fd4179SDavid Teigland int nodeid; 129e7fd4179SDavid Teigland int weight; 130e7fd4179SDavid Teigland }; 131e7fd4179SDavid Teigland 132e7fd4179SDavid Teigland /* 133e7fd4179SDavid Teigland * Save and manage recovery state for a lockspace. 134e7fd4179SDavid Teigland */ 135e7fd4179SDavid Teigland 136e7fd4179SDavid Teigland struct dlm_recover { 137e7fd4179SDavid Teigland struct list_head list; 138e7fd4179SDavid Teigland int *nodeids; 139e7fd4179SDavid Teigland int node_count; 140e7fd4179SDavid Teigland uint64_t seq; 141e7fd4179SDavid Teigland }; 142e7fd4179SDavid Teigland 143e7fd4179SDavid Teigland /* 144e7fd4179SDavid Teigland * Pass input args to second stage locking function. 145e7fd4179SDavid Teigland */ 146e7fd4179SDavid Teigland 147e7fd4179SDavid Teigland struct dlm_args { 148e7fd4179SDavid Teigland uint32_t flags; 149e7fd4179SDavid Teigland void *astaddr; 150e7fd4179SDavid Teigland long astparam; 151e7fd4179SDavid Teigland void *bastaddr; 152e7fd4179SDavid Teigland int mode; 153e7fd4179SDavid Teigland struct dlm_lksb *lksb; 154e7fd4179SDavid Teigland }; 155e7fd4179SDavid Teigland 156e7fd4179SDavid Teigland 157e7fd4179SDavid Teigland /* 158e7fd4179SDavid Teigland * Lock block 159e7fd4179SDavid Teigland * 160e7fd4179SDavid Teigland * A lock can be one of three types: 161e7fd4179SDavid Teigland * 162e7fd4179SDavid Teigland * local copy lock is mastered locally 163e7fd4179SDavid Teigland * (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set) 164e7fd4179SDavid Teigland * process copy lock is mastered on a remote node 165e7fd4179SDavid Teigland * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set) 166e7fd4179SDavid Teigland * master copy master node's copy of a lock owned by remote node 167e7fd4179SDavid Teigland * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set) 168e7fd4179SDavid Teigland * 169e7fd4179SDavid Teigland * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or 170e7fd4179SDavid Teigland * dlm_unlock. The dlm does not modify these or use any private flags in 171e7fd4179SDavid Teigland * this field; it only contains DLM_LKF_ flags from dlm.h. These flags 172e7fd4179SDavid Teigland * are sent as-is to the remote master when the lock is remote. 173e7fd4179SDavid Teigland * 174e7fd4179SDavid Teigland * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h. 175e7fd4179SDavid Teigland * Some internal flags are shared between the master and process nodes; 176e7fd4179SDavid Teigland * these shared flags are kept in the lower two bytes. One of these 177e7fd4179SDavid Teigland * flags set on the master copy will be propagated to the process copy 178e7fd4179SDavid Teigland * and v.v. Other internal flags are private to the master or process 179e7fd4179SDavid Teigland * node (e.g. DLM_IFL_MSTCPY). These are kept in the high two bytes. 180e7fd4179SDavid Teigland * 181e7fd4179SDavid Teigland * lkb_sbflags: status block flags. These flags are copied directly into 182e7fd4179SDavid Teigland * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion 183e7fd4179SDavid Teigland * ast. All defined in dlm.h with DLM_SBF_ prefix. 184e7fd4179SDavid Teigland * 185e7fd4179SDavid Teigland * lkb_status: the lock status indicates which rsb queue the lock is 186e7fd4179SDavid Teigland * on, grant, convert, or wait. DLM_LKSTS_ WAITING/GRANTED/CONVERT 187e7fd4179SDavid Teigland * 188e7fd4179SDavid Teigland * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a 189e7fd4179SDavid Teigland * reply is needed. Only set when the lkb is on the lockspace waiters 190e7fd4179SDavid Teigland * list awaiting a reply from a remote node. 191e7fd4179SDavid Teigland * 192e7fd4179SDavid Teigland * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb 193e7fd4179SDavid Teigland * is a master copy, nodeid specifies the remote lock holder, when the 194e7fd4179SDavid Teigland * lkb is a process copy, the nodeid specifies the lock master. 195e7fd4179SDavid Teigland */ 196e7fd4179SDavid Teigland 197e7fd4179SDavid Teigland /* lkb_ast_type */ 198e7fd4179SDavid Teigland 199e7fd4179SDavid Teigland #define AST_COMP 1 200e7fd4179SDavid Teigland #define AST_BAST 2 201e7fd4179SDavid Teigland 202e7fd4179SDavid Teigland /* lkb_status */ 203e7fd4179SDavid Teigland 204e7fd4179SDavid Teigland #define DLM_LKSTS_WAITING 1 205e7fd4179SDavid Teigland #define DLM_LKSTS_GRANTED 2 206e7fd4179SDavid Teigland #define DLM_LKSTS_CONVERT 3 207e7fd4179SDavid Teigland 208e7fd4179SDavid Teigland /* lkb_flags */ 209e7fd4179SDavid Teigland 210e7fd4179SDavid Teigland #define DLM_IFL_MSTCPY 0x00010000 211e7fd4179SDavid Teigland #define DLM_IFL_RESEND 0x00020000 212597d0caeSDavid Teigland #define DLM_IFL_DEAD 0x00040000 213ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_UNLOCK 0x00080000 214ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_CANCEL 0x00100000 215ef0c2bb0SDavid Teigland #define DLM_IFL_ENDOFLIFE 0x00200000 216597d0caeSDavid Teigland #define DLM_IFL_USER 0x00000001 217597d0caeSDavid Teigland #define DLM_IFL_ORPHAN 0x00000002 218e7fd4179SDavid Teigland 219e7fd4179SDavid Teigland struct dlm_lkb { 220e7fd4179SDavid Teigland struct dlm_rsb *lkb_resource; /* the rsb */ 221e7fd4179SDavid Teigland struct kref lkb_ref; 222e7fd4179SDavid Teigland int lkb_nodeid; /* copied from rsb */ 223e7fd4179SDavid Teigland int lkb_ownpid; /* pid of lock owner */ 224e7fd4179SDavid Teigland uint32_t lkb_id; /* our lock ID */ 225e7fd4179SDavid Teigland uint32_t lkb_remid; /* lock ID on remote partner */ 226e7fd4179SDavid Teigland uint32_t lkb_exflags; /* external flags from caller */ 227e7fd4179SDavid Teigland uint32_t lkb_sbflags; /* lksb flags */ 228e7fd4179SDavid Teigland uint32_t lkb_flags; /* internal flags */ 229e7fd4179SDavid Teigland uint32_t lkb_lvbseq; /* lvb sequence number */ 230e7fd4179SDavid Teigland 231e7fd4179SDavid Teigland int8_t lkb_status; /* granted, waiting, convert */ 232e7fd4179SDavid Teigland int8_t lkb_rqmode; /* requested lock mode */ 233e7fd4179SDavid Teigland int8_t lkb_grmode; /* granted lock mode */ 234e7fd4179SDavid Teigland int8_t lkb_bastmode; /* requested mode */ 235e7fd4179SDavid Teigland int8_t lkb_highbast; /* highest mode bast sent for */ 236e7fd4179SDavid Teigland int8_t lkb_wait_type; /* type of reply waiting for */ 237ef0c2bb0SDavid Teigland int8_t lkb_wait_count; 238e7fd4179SDavid Teigland int8_t lkb_ast_type; /* type of ast queued for */ 239e7fd4179SDavid Teigland 240e7fd4179SDavid Teigland struct list_head lkb_idtbl_list; /* lockspace lkbtbl */ 241e7fd4179SDavid Teigland struct list_head lkb_statequeue; /* rsb g/c/w list */ 242e7fd4179SDavid Teigland struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */ 243e7fd4179SDavid Teigland struct list_head lkb_wait_reply; /* waiting for remote reply */ 244e7fd4179SDavid Teigland struct list_head lkb_astqueue; /* need ast to be sent */ 245597d0caeSDavid Teigland struct list_head lkb_ownqueue; /* list of locks for a process */ 246e7fd4179SDavid Teigland 247e7fd4179SDavid Teigland char *lkb_lvbptr; 248e7fd4179SDavid Teigland struct dlm_lksb *lkb_lksb; /* caller's status block */ 249e7fd4179SDavid Teigland void *lkb_astaddr; /* caller's ast function */ 250e7fd4179SDavid Teigland void *lkb_bastaddr; /* caller's bast function */ 251e7fd4179SDavid Teigland long lkb_astparam; /* caller's ast arg */ 252e7fd4179SDavid Teigland }; 253e7fd4179SDavid Teigland 254e7fd4179SDavid Teigland 255e7fd4179SDavid Teigland struct dlm_rsb { 256e7fd4179SDavid Teigland struct dlm_ls *res_ls; /* the lockspace */ 257e7fd4179SDavid Teigland struct kref res_ref; 25890135925SDavid Teigland struct mutex res_mutex; 259e7fd4179SDavid Teigland unsigned long res_flags; 260e7fd4179SDavid Teigland int res_length; /* length of rsb name */ 261e7fd4179SDavid Teigland int res_nodeid; 262e7fd4179SDavid Teigland uint32_t res_lvbseq; 263e7fd4179SDavid Teigland uint32_t res_hash; 264e7fd4179SDavid Teigland uint32_t res_bucket; /* rsbtbl */ 265e7fd4179SDavid Teigland unsigned long res_toss_time; 266e7fd4179SDavid Teigland uint32_t res_first_lkid; 267e7fd4179SDavid Teigland struct list_head res_lookup; /* lkbs waiting on first */ 268e7fd4179SDavid Teigland struct list_head res_hashchain; /* rsbtbl */ 269e7fd4179SDavid Teigland struct list_head res_grantqueue; 270e7fd4179SDavid Teigland struct list_head res_convertqueue; 271e7fd4179SDavid Teigland struct list_head res_waitqueue; 272e7fd4179SDavid Teigland 273e7fd4179SDavid Teigland struct list_head res_root_list; /* used for recovery */ 274e7fd4179SDavid Teigland struct list_head res_recover_list; /* used for recovery */ 275e7fd4179SDavid Teigland int res_recover_locks_count; 276e7fd4179SDavid Teigland 277e7fd4179SDavid Teigland char *res_lvbptr; 278e7fd4179SDavid Teigland char res_name[1]; 279e7fd4179SDavid Teigland }; 280e7fd4179SDavid Teigland 281e7fd4179SDavid Teigland /* find_rsb() flags */ 282e7fd4179SDavid Teigland 283e7fd4179SDavid Teigland #define R_MASTER 1 /* only return rsb if it's a master */ 284e7fd4179SDavid Teigland #define R_CREATE 2 /* create/add rsb if not found */ 285e7fd4179SDavid Teigland 286e7fd4179SDavid Teigland /* rsb_flags */ 287e7fd4179SDavid Teigland 288e7fd4179SDavid Teigland enum rsb_flags { 289e7fd4179SDavid Teigland RSB_MASTER_UNCERTAIN, 290e7fd4179SDavid Teigland RSB_VALNOTVALID, 291e7fd4179SDavid Teigland RSB_VALNOTVALID_PREV, 292e7fd4179SDavid Teigland RSB_NEW_MASTER, 293e7fd4179SDavid Teigland RSB_NEW_MASTER2, 294e7fd4179SDavid Teigland RSB_RECOVER_CONVERT, 29597a35d1eSDavid Teigland RSB_LOCKS_PURGED, 296e7fd4179SDavid Teigland }; 297e7fd4179SDavid Teigland 298e7fd4179SDavid Teigland static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag) 299e7fd4179SDavid Teigland { 300e7fd4179SDavid Teigland __set_bit(flag, &r->res_flags); 301e7fd4179SDavid Teigland } 302e7fd4179SDavid Teigland 303e7fd4179SDavid Teigland static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag) 304e7fd4179SDavid Teigland { 305e7fd4179SDavid Teigland __clear_bit(flag, &r->res_flags); 306e7fd4179SDavid Teigland } 307e7fd4179SDavid Teigland 308e7fd4179SDavid Teigland static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag) 309e7fd4179SDavid Teigland { 310e7fd4179SDavid Teigland return test_bit(flag, &r->res_flags); 311e7fd4179SDavid Teigland } 312e7fd4179SDavid Teigland 313e7fd4179SDavid Teigland 314e7fd4179SDavid Teigland /* dlm_header is first element of all structs sent between nodes */ 315e7fd4179SDavid Teigland 31638aa8b0cSDavid Teigland #define DLM_HEADER_MAJOR 0x00030000 31738aa8b0cSDavid Teigland #define DLM_HEADER_MINOR 0x00000000 318e7fd4179SDavid Teigland 319e7fd4179SDavid Teigland #define DLM_MSG 1 320e7fd4179SDavid Teigland #define DLM_RCOM 2 321e7fd4179SDavid Teigland 322e7fd4179SDavid Teigland struct dlm_header { 323e7fd4179SDavid Teigland uint32_t h_version; 324e7fd4179SDavid Teigland uint32_t h_lockspace; 325e7fd4179SDavid Teigland uint32_t h_nodeid; /* nodeid of sender */ 326e7fd4179SDavid Teigland uint16_t h_length; 327e7fd4179SDavid Teigland uint8_t h_cmd; /* DLM_MSG, DLM_RCOM */ 328e7fd4179SDavid Teigland uint8_t h_pad; 329e7fd4179SDavid Teigland }; 330e7fd4179SDavid Teigland 331e7fd4179SDavid Teigland 332e7fd4179SDavid Teigland #define DLM_MSG_REQUEST 1 333e7fd4179SDavid Teigland #define DLM_MSG_CONVERT 2 334e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK 3 335e7fd4179SDavid Teigland #define DLM_MSG_CANCEL 4 336e7fd4179SDavid Teigland #define DLM_MSG_REQUEST_REPLY 5 337e7fd4179SDavid Teigland #define DLM_MSG_CONVERT_REPLY 6 338e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK_REPLY 7 339e7fd4179SDavid Teigland #define DLM_MSG_CANCEL_REPLY 8 340e7fd4179SDavid Teigland #define DLM_MSG_GRANT 9 341e7fd4179SDavid Teigland #define DLM_MSG_BAST 10 342e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP 11 343e7fd4179SDavid Teigland #define DLM_MSG_REMOVE 12 344e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP_REPLY 13 345*8499137dSDavid Teigland #define DLM_MSG_PURGE 14 346e7fd4179SDavid Teigland 347e7fd4179SDavid Teigland struct dlm_message { 348e7fd4179SDavid Teigland struct dlm_header m_header; 349e7fd4179SDavid Teigland uint32_t m_type; /* DLM_MSG_ */ 350e7fd4179SDavid Teigland uint32_t m_nodeid; 351e7fd4179SDavid Teigland uint32_t m_pid; 352e7fd4179SDavid Teigland uint32_t m_lkid; /* lkid on sender */ 353e7fd4179SDavid Teigland uint32_t m_remid; /* lkid on receiver */ 354e7fd4179SDavid Teigland uint32_t m_parent_lkid; 355e7fd4179SDavid Teigland uint32_t m_parent_remid; 356e7fd4179SDavid Teigland uint32_t m_exflags; 357e7fd4179SDavid Teigland uint32_t m_sbflags; 358e7fd4179SDavid Teigland uint32_t m_flags; 359e7fd4179SDavid Teigland uint32_t m_lvbseq; 360e7fd4179SDavid Teigland uint32_t m_hash; 361e7fd4179SDavid Teigland int m_status; 362e7fd4179SDavid Teigland int m_grmode; 363e7fd4179SDavid Teigland int m_rqmode; 364e7fd4179SDavid Teigland int m_bastmode; 365e7fd4179SDavid Teigland int m_asts; 366e7fd4179SDavid Teigland int m_result; /* 0 or -EXXX */ 367e7fd4179SDavid Teigland char m_extra[0]; /* name or lvb */ 368e7fd4179SDavid Teigland }; 369e7fd4179SDavid Teigland 370e7fd4179SDavid Teigland 371e7fd4179SDavid Teigland #define DLM_RS_NODES 0x00000001 372e7fd4179SDavid Teigland #define DLM_RS_NODES_ALL 0x00000002 373e7fd4179SDavid Teigland #define DLM_RS_DIR 0x00000004 374e7fd4179SDavid Teigland #define DLM_RS_DIR_ALL 0x00000008 375e7fd4179SDavid Teigland #define DLM_RS_LOCKS 0x00000010 376e7fd4179SDavid Teigland #define DLM_RS_LOCKS_ALL 0x00000020 377e7fd4179SDavid Teigland #define DLM_RS_DONE 0x00000040 378e7fd4179SDavid Teigland #define DLM_RS_DONE_ALL 0x00000080 379e7fd4179SDavid Teigland 380e7fd4179SDavid Teigland #define DLM_RCOM_STATUS 1 381e7fd4179SDavid Teigland #define DLM_RCOM_NAMES 2 382e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP 3 383e7fd4179SDavid Teigland #define DLM_RCOM_LOCK 4 384e7fd4179SDavid Teigland #define DLM_RCOM_STATUS_REPLY 5 385e7fd4179SDavid Teigland #define DLM_RCOM_NAMES_REPLY 6 386e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP_REPLY 7 387e7fd4179SDavid Teigland #define DLM_RCOM_LOCK_REPLY 8 388e7fd4179SDavid Teigland 389e7fd4179SDavid Teigland struct dlm_rcom { 390e7fd4179SDavid Teigland struct dlm_header rc_header; 391e7fd4179SDavid Teigland uint32_t rc_type; /* DLM_RCOM_ */ 392e7fd4179SDavid Teigland int rc_result; /* multi-purpose */ 393e7fd4179SDavid Teigland uint64_t rc_id; /* match reply with request */ 39438aa8b0cSDavid Teigland uint64_t rc_seq; /* sender's ls_recover_seq */ 39538aa8b0cSDavid Teigland uint64_t rc_seq_reply; /* remote ls_recover_seq */ 396e7fd4179SDavid Teigland char rc_buf[0]; 397e7fd4179SDavid Teigland }; 398e7fd4179SDavid Teigland 399e7fd4179SDavid Teigland struct rcom_config { 400e7fd4179SDavid Teigland uint32_t rf_lvblen; 401e7fd4179SDavid Teigland uint32_t rf_lsflags; 402e7fd4179SDavid Teigland uint64_t rf_unused; 403e7fd4179SDavid Teigland }; 404e7fd4179SDavid Teigland 405e7fd4179SDavid Teigland struct rcom_lock { 406e7fd4179SDavid Teigland uint32_t rl_ownpid; 407e7fd4179SDavid Teigland uint32_t rl_lkid; 408e7fd4179SDavid Teigland uint32_t rl_remid; 409e7fd4179SDavid Teigland uint32_t rl_parent_lkid; 410e7fd4179SDavid Teigland uint32_t rl_parent_remid; 411e7fd4179SDavid Teigland uint32_t rl_exflags; 412e7fd4179SDavid Teigland uint32_t rl_flags; 413e7fd4179SDavid Teigland uint32_t rl_lvbseq; 414e7fd4179SDavid Teigland int rl_result; 415e7fd4179SDavid Teigland int8_t rl_rqmode; 416e7fd4179SDavid Teigland int8_t rl_grmode; 417e7fd4179SDavid Teigland int8_t rl_status; 418e7fd4179SDavid Teigland int8_t rl_asts; 419e7fd4179SDavid Teigland uint16_t rl_wait_type; 420e7fd4179SDavid Teigland uint16_t rl_namelen; 421e7fd4179SDavid Teigland char rl_name[DLM_RESNAME_MAXLEN]; 422e7fd4179SDavid Teigland char rl_lvb[0]; 423e7fd4179SDavid Teigland }; 424e7fd4179SDavid Teigland 425e7fd4179SDavid Teigland struct dlm_ls { 426e7fd4179SDavid Teigland struct list_head ls_list; /* list of lockspaces */ 427597d0caeSDavid Teigland dlm_lockspace_t *ls_local_handle; 428e7fd4179SDavid Teigland uint32_t ls_global_id; /* global unique lockspace ID */ 429e7fd4179SDavid Teigland uint32_t ls_exflags; 430e7fd4179SDavid Teigland int ls_lvblen; 431e7fd4179SDavid Teigland int ls_count; /* reference count */ 432e7fd4179SDavid Teigland unsigned long ls_flags; /* LSFL_ */ 433e7fd4179SDavid Teigland struct kobject ls_kobj; 434e7fd4179SDavid Teigland 435e7fd4179SDavid Teigland struct dlm_rsbtable *ls_rsbtbl; 436e7fd4179SDavid Teigland uint32_t ls_rsbtbl_size; 437e7fd4179SDavid Teigland 438e7fd4179SDavid Teigland struct dlm_lkbtable *ls_lkbtbl; 439e7fd4179SDavid Teigland uint32_t ls_lkbtbl_size; 440e7fd4179SDavid Teigland 441e7fd4179SDavid Teigland struct dlm_dirtable *ls_dirtbl; 442e7fd4179SDavid Teigland uint32_t ls_dirtbl_size; 443e7fd4179SDavid Teigland 44490135925SDavid Teigland struct mutex ls_waiters_mutex; 445e7fd4179SDavid Teigland struct list_head ls_waiters; /* lkbs needing a reply */ 446e7fd4179SDavid Teigland 447ef0c2bb0SDavid Teigland struct mutex ls_orphans_mutex; 448ef0c2bb0SDavid Teigland struct list_head ls_orphans; 449ef0c2bb0SDavid Teigland 450e7fd4179SDavid Teigland struct list_head ls_nodes; /* current nodes in ls */ 451e7fd4179SDavid Teigland struct list_head ls_nodes_gone; /* dead node list, recovery */ 452e7fd4179SDavid Teigland int ls_num_nodes; /* number of nodes in ls */ 453e7fd4179SDavid Teigland int ls_low_nodeid; 454e7fd4179SDavid Teigland int ls_total_weight; 455e7fd4179SDavid Teigland int *ls_node_array; 456e7fd4179SDavid Teigland 457e7fd4179SDavid Teigland struct dlm_rsb ls_stub_rsb; /* for returning errors */ 458e7fd4179SDavid Teigland struct dlm_lkb ls_stub_lkb; /* for returning errors */ 459e7fd4179SDavid Teigland struct dlm_message ls_stub_ms; /* for faking a reply */ 460e7fd4179SDavid Teigland 4615de6319bSDavid Teigland struct dentry *ls_debug_rsb_dentry; /* debugfs */ 4625de6319bSDavid Teigland struct dentry *ls_debug_waiters_dentry; /* debugfs */ 463e7fd4179SDavid Teigland 464e7fd4179SDavid Teigland wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ 465e7fd4179SDavid Teigland int ls_uevent_result; 466e7fd4179SDavid Teigland 467597d0caeSDavid Teigland struct miscdevice ls_device; 468597d0caeSDavid Teigland 469e7fd4179SDavid Teigland /* recovery related */ 470e7fd4179SDavid Teigland 471e7fd4179SDavid Teigland struct timer_list ls_timer; 472e7fd4179SDavid Teigland struct task_struct *ls_recoverd_task; 47390135925SDavid Teigland struct mutex ls_recoverd_active; 474e7fd4179SDavid Teigland spinlock_t ls_recover_lock; 475e7fd4179SDavid Teigland uint32_t ls_recover_status; /* DLM_RS_ */ 476e7fd4179SDavid Teigland uint64_t ls_recover_seq; 477e7fd4179SDavid Teigland struct dlm_recover *ls_recover_args; 478e7fd4179SDavid Teigland struct rw_semaphore ls_in_recovery; /* block local requests */ 479e7fd4179SDavid Teigland struct list_head ls_requestqueue;/* queue remote requests */ 48090135925SDavid Teigland struct mutex ls_requestqueue_mutex; 481e7fd4179SDavid Teigland char *ls_recover_buf; 482faa0f267SDavid Teigland int ls_recover_nodeid; /* for debugging */ 4834a99c3d9SDavid Teigland uint64_t ls_rcom_seq; 48498f176fbSDavid Teigland spinlock_t ls_rcom_spin; 485e7fd4179SDavid Teigland struct list_head ls_recover_list; 486e7fd4179SDavid Teigland spinlock_t ls_recover_list_lock; 487e7fd4179SDavid Teigland int ls_recover_list_count; 488e7fd4179SDavid Teigland wait_queue_head_t ls_wait_general; 489597d0caeSDavid Teigland struct mutex ls_clear_proc_locks; 490e7fd4179SDavid Teigland 491e7fd4179SDavid Teigland struct list_head ls_root_list; /* root resources */ 492e7fd4179SDavid Teigland struct rw_semaphore ls_root_sem; /* protect root_list */ 493e7fd4179SDavid Teigland 494e7fd4179SDavid Teigland int ls_namelen; 495e7fd4179SDavid Teigland char ls_name[1]; 496e7fd4179SDavid Teigland }; 497e7fd4179SDavid Teigland 498e7fd4179SDavid Teigland #define LSFL_WORK 0 499e7fd4179SDavid Teigland #define LSFL_RUNNING 1 500e7fd4179SDavid Teigland #define LSFL_RECOVERY_STOP 2 501e7fd4179SDavid Teigland #define LSFL_RCOM_READY 3 50298f176fbSDavid Teigland #define LSFL_RCOM_WAIT 4 50398f176fbSDavid Teigland #define LSFL_UEVENT_WAIT 5 504e7fd4179SDavid Teigland 505597d0caeSDavid Teigland /* much of this is just saving user space pointers associated with the 506597d0caeSDavid Teigland lock that we pass back to the user lib with an ast */ 507597d0caeSDavid Teigland 508597d0caeSDavid Teigland struct dlm_user_args { 509597d0caeSDavid Teigland struct dlm_user_proc *proc; /* each process that opens the lockspace 510597d0caeSDavid Teigland device has private data 511597d0caeSDavid Teigland (dlm_user_proc) on the struct file, 512597d0caeSDavid Teigland the process's locks point back to it*/ 513597d0caeSDavid Teigland struct dlm_lksb lksb; 514597d0caeSDavid Teigland int old_mode; 515597d0caeSDavid Teigland int update_user_lvb; 516597d0caeSDavid Teigland struct dlm_lksb __user *user_lksb; 517597d0caeSDavid Teigland void __user *castparam; 518597d0caeSDavid Teigland void __user *castaddr; 519597d0caeSDavid Teigland void __user *bastparam; 520597d0caeSDavid Teigland void __user *bastaddr; 521597d0caeSDavid Teigland }; 522597d0caeSDavid Teigland 523597d0caeSDavid Teigland #define DLM_PROC_FLAGS_CLOSING 1 524597d0caeSDavid Teigland #define DLM_PROC_FLAGS_COMPAT 2 525597d0caeSDavid Teigland 526597d0caeSDavid Teigland /* locks list is kept so we can remove all a process's locks when it 527597d0caeSDavid Teigland exits (or orphan those that are persistent) */ 528597d0caeSDavid Teigland 529597d0caeSDavid Teigland struct dlm_user_proc { 530597d0caeSDavid Teigland dlm_lockspace_t *lockspace; 531597d0caeSDavid Teigland unsigned long flags; /* DLM_PROC_FLAGS */ 532597d0caeSDavid Teigland struct list_head asts; 533597d0caeSDavid Teigland spinlock_t asts_spin; 534597d0caeSDavid Teigland struct list_head locks; 535597d0caeSDavid Teigland spinlock_t locks_spin; 536a1bc86e6SDavid Teigland struct list_head unlocking; 537597d0caeSDavid Teigland wait_queue_head_t wait; 538597d0caeSDavid Teigland }; 539597d0caeSDavid Teigland 540e7fd4179SDavid Teigland static inline int dlm_locking_stopped(struct dlm_ls *ls) 541e7fd4179SDavid Teigland { 542e7fd4179SDavid Teigland return !test_bit(LSFL_RUNNING, &ls->ls_flags); 543e7fd4179SDavid Teigland } 544e7fd4179SDavid Teigland 545e7fd4179SDavid Teigland static inline int dlm_recovery_stopped(struct dlm_ls *ls) 546e7fd4179SDavid Teigland { 547e7fd4179SDavid Teigland return test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); 548e7fd4179SDavid Teigland } 549e7fd4179SDavid Teigland 550e7fd4179SDavid Teigland static inline int dlm_no_directory(struct dlm_ls *ls) 551e7fd4179SDavid Teigland { 552e7fd4179SDavid Teigland return (ls->ls_exflags & DLM_LSFL_NODIR) ? 1 : 0; 553e7fd4179SDavid Teigland } 554e7fd4179SDavid Teigland 555e7fd4179SDavid Teigland #endif /* __DLM_INTERNAL_DOT_H__ */ 556e7fd4179SDavid Teigland 557