1 /****************************************************************************** 2 ******************************************************************************* 3 ** 4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5 ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. 6 ** 7 ** This copyrighted material is made available to anyone wishing to use, 8 ** modify, copy, or redistribute it subject to the terms and conditions 9 ** of the GNU General Public License v.2. 10 ** 11 ******************************************************************************* 12 ******************************************************************************/ 13 14 #ifndef __DLM_DOT_H__ 15 #define __DLM_DOT_H__ 16 17 /* 18 * Interface to Distributed Lock Manager (DLM) 19 * routines and structures to use DLM lockspaces 20 */ 21 22 /* Lock levels and flags are here */ 23 #include <linux/dlmconstants.h> 24 #include <linux/types.h> 25 26 typedef void dlm_lockspace_t; 27 28 /* 29 * Lock status block 30 * 31 * Use this structure to specify the contents of the lock value block. For a 32 * conversion request, this structure is used to specify the lock ID of the 33 * lock. DLM writes the status of the lock request and the lock ID assigned 34 * to the request in the lock status block. 35 * 36 * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests. 37 * It is available when dlm_lock returns. 38 * 39 * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules 40 * shown for the DLM_LKF_VALBLK flag. 41 * 42 * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock, 43 * it was first demoted to NL to avoid conversion deadlock. 44 * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid. 45 * 46 * sb_status: the returned status of the lock request set prior to AST 47 * execution. Possible return values: 48 * 49 * 0 if lock request was successful 50 * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE 51 * -DLM_EUNLOCK if unlock request was successful 52 * -DLM_ECANCEL if a cancel completed successfully 53 * -EDEADLK if a deadlock was detected 54 * -ETIMEDOUT if the lock request was canceled due to a timeout 55 */ 56 57 #define DLM_SBF_DEMOTED 0x01 58 #define DLM_SBF_VALNOTVALID 0x02 59 #define DLM_SBF_ALTMODE 0x04 60 61 struct dlm_lksb { 62 int sb_status; 63 __u32 sb_lkid; 64 char sb_flags; 65 char * sb_lvbptr; 66 }; 67 68 /* dlm_new_lockspace() flags */ 69 70 #define DLM_LSFL_NODIR 0x00000001 71 #define DLM_LSFL_TIMEWARN 0x00000002 72 #define DLM_LSFL_FS 0x00000004 73 #define DLM_LSFL_NEWEXCL 0x00000008 74 75 #ifdef __KERNEL__ 76 77 struct dlm_slot { 78 int nodeid; /* 1 to MAX_INT */ 79 int slot; /* 1 to MAX_INT */ 80 }; 81 82 /* 83 * recover_prep: called before the dlm begins lock recovery. 84 * Notfies lockspace user that locks from failed members will be granted. 85 * recover_slot: called after recover_prep and before recover_done. 86 * Identifies a failed lockspace member. 87 * recover_done: called after the dlm completes lock recovery. 88 * Identifies lockspace members and lockspace generation number. 89 */ 90 91 struct dlm_lockspace_ops { 92 void (*recover_prep) (void *ops_arg); 93 void (*recover_slot) (void *ops_arg, struct dlm_slot *slot); 94 void (*recover_done) (void *ops_arg, struct dlm_slot *slots, 95 int num_slots, int our_slot, uint32_t generation); 96 }; 97 98 /* 99 * dlm_new_lockspace 100 * 101 * Create/join a lockspace. 102 * 103 * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not 104 * including terminating null). 105 * 106 * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not 107 * including terminating null). Optional. When cluster is null, it 108 * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster 109 * is not equal to the dlm cluster name. 110 * 111 * flags: 112 * DLM_LSFL_NODIR 113 * The dlm should not use a resource directory, but statically assign 114 * resource mastery to nodes based on the name hash that is otherwise 115 * used to select the directory node. Must be the same on all nodes. 116 * DLM_LSFL_TIMEWARN 117 * The dlm should emit netlink messages if locks have been waiting 118 * for a configurable amount of time. (Unused.) 119 * DLM_LSFL_FS 120 * The lockspace user is in the kernel (i.e. filesystem). Enables 121 * direct bast/cast callbacks. 122 * DLM_LSFL_NEWEXCL 123 * dlm_new_lockspace() should return -EEXIST if the lockspace exists. 124 * 125 * lvblen: length of lvb in bytes. Must be multiple of 8. 126 * dlm_new_lockspace() returns an error if this does not match 127 * what other nodes are using. 128 * 129 * ops: callbacks that indicate lockspace recovery points so the 130 * caller can coordinate its recovery and know lockspace members. 131 * This is only used by the initial dlm_new_lockspace() call. 132 * Optional. 133 * 134 * ops_arg: arg for ops callbacks. 135 * 136 * ops_result: tells caller if the ops callbacks (if provided) will 137 * be used or not. 0: will be used, -EXXX will not be used. 138 * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled. 139 * 140 * lockspace: handle for dlm functions 141 */ 142 143 int dlm_new_lockspace(const char *name, const char *cluster, 144 uint32_t flags, int lvblen, 145 const struct dlm_lockspace_ops *ops, void *ops_arg, 146 int *ops_result, dlm_lockspace_t **lockspace); 147 148 /* 149 * dlm_release_lockspace 150 * 151 * Stop a lockspace. 152 */ 153 154 int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); 155 156 /* 157 * dlm_lock 158 * 159 * Make an asyncronous request to acquire or convert a lock on a named 160 * resource. 161 * 162 * lockspace: context for the request 163 * mode: the requested mode of the lock (DLM_LOCK_) 164 * lksb: lock status block for input and async return values 165 * flags: input flags (DLM_LKF_) 166 * name: name of the resource to lock, can be binary 167 * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN) 168 * parent: the lock ID of a parent lock or 0 if none 169 * lockast: function DLM executes when it completes processing the request 170 * astarg: argument passed to lockast and bast functions 171 * bast: function DLM executes when this lock later blocks another request 172 * 173 * Returns: 174 * 0 if request is successfully queued for processing 175 * -EINVAL if any input parameters are invalid 176 * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE 177 * -ENOMEM if there is no memory to process request 178 * -ENOTCONN if there is a communication error 179 * 180 * If the call to dlm_lock returns an error then the operation has failed and 181 * the AST routine will not be called. If dlm_lock returns 0 it is still 182 * possible that the lock operation will fail. The AST routine will be called 183 * when the locking is complete and the status is returned in the lksb. 184 * 185 * If the AST routines or parameter are passed to a conversion operation then 186 * they will overwrite those values that were passed to a previous dlm_lock 187 * call. 188 * 189 * AST routines should not block (at least not for long), but may make 190 * any locking calls they please. 191 */ 192 193 int dlm_lock(dlm_lockspace_t *lockspace, 194 int mode, 195 struct dlm_lksb *lksb, 196 uint32_t flags, 197 void *name, 198 unsigned int namelen, 199 uint32_t parent_lkid, 200 void (*lockast) (void *astarg), 201 void *astarg, 202 void (*bast) (void *astarg, int mode)); 203 204 /* 205 * dlm_unlock 206 * 207 * Asynchronously release a lock on a resource. The AST routine is called 208 * when the resource is successfully unlocked. 209 * 210 * lockspace: context for the request 211 * lkid: the lock ID as returned in the lksb 212 * flags: input flags (DLM_LKF_) 213 * lksb: if NULL the lksb parameter passed to last lock request is used 214 * astarg: the arg used with the completion ast for the unlock 215 * 216 * Returns: 217 * 0 if request is successfully queued for processing 218 * -EINVAL if any input parameters are invalid 219 * -ENOTEMPTY if the lock still has sublocks 220 * -EBUSY if the lock is waiting for a remote lock operation 221 * -ENOTCONN if there is a communication error 222 */ 223 224 int dlm_unlock(dlm_lockspace_t *lockspace, 225 uint32_t lkid, 226 uint32_t flags, 227 struct dlm_lksb *lksb, 228 void *astarg); 229 230 #endif /* __KERNEL__ */ 231 232 #endif /* __DLM_DOT_H__ */ 233 234