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 #ifndef __DLM_DOT_H__ 14 #define __DLM_DOT_H__ 15 16 #include <uapi/linux/dlm.h> 17 18 19 struct dlm_slot { 20 int nodeid; /* 1 to MAX_INT */ 21 int slot; /* 1 to MAX_INT */ 22 }; 23 24 /* 25 * recover_prep: called before the dlm begins lock recovery. 26 * Notfies lockspace user that locks from failed members will be granted. 27 * recover_slot: called after recover_prep and before recover_done. 28 * Identifies a failed lockspace member. 29 * recover_done: called after the dlm completes lock recovery. 30 * Identifies lockspace members and lockspace generation number. 31 */ 32 33 struct dlm_lockspace_ops { 34 void (*recover_prep) (void *ops_arg); 35 void (*recover_slot) (void *ops_arg, struct dlm_slot *slot); 36 void (*recover_done) (void *ops_arg, struct dlm_slot *slots, 37 int num_slots, int our_slot, uint32_t generation); 38 }; 39 40 /* 41 * dlm_new_lockspace 42 * 43 * Create/join a lockspace. 44 * 45 * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not 46 * including terminating null). 47 * 48 * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not 49 * including terminating null). Optional. When cluster is null, it 50 * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster 51 * is not equal to the dlm cluster name. 52 * 53 * flags: 54 * DLM_LSFL_NODIR 55 * The dlm should not use a resource directory, but statically assign 56 * resource mastery to nodes based on the name hash that is otherwise 57 * used to select the directory node. Must be the same on all nodes. 58 * DLM_LSFL_TIMEWARN 59 * The dlm should emit netlink messages if locks have been waiting 60 * for a configurable amount of time. (Unused.) 61 * DLM_LSFL_FS 62 * The lockspace user is in the kernel (i.e. filesystem). Enables 63 * direct bast/cast callbacks. 64 * DLM_LSFL_NEWEXCL 65 * dlm_new_lockspace() should return -EEXIST if the lockspace exists. 66 * 67 * lvblen: length of lvb in bytes. Must be multiple of 8. 68 * dlm_new_lockspace() returns an error if this does not match 69 * what other nodes are using. 70 * 71 * ops: callbacks that indicate lockspace recovery points so the 72 * caller can coordinate its recovery and know lockspace members. 73 * This is only used by the initial dlm_new_lockspace() call. 74 * Optional. 75 * 76 * ops_arg: arg for ops callbacks. 77 * 78 * ops_result: tells caller if the ops callbacks (if provided) will 79 * be used or not. 0: will be used, -EXXX will not be used. 80 * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled. 81 * 82 * lockspace: handle for dlm functions 83 */ 84 85 int dlm_new_lockspace(const char *name, const char *cluster, 86 uint32_t flags, int lvblen, 87 const struct dlm_lockspace_ops *ops, void *ops_arg, 88 int *ops_result, dlm_lockspace_t **lockspace); 89 90 /* 91 * dlm_release_lockspace 92 * 93 * Stop a lockspace. 94 */ 95 96 int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); 97 98 /* 99 * dlm_lock 100 * 101 * Make an asynchronous request to acquire or convert a lock on a named 102 * resource. 103 * 104 * lockspace: context for the request 105 * mode: the requested mode of the lock (DLM_LOCK_) 106 * lksb: lock status block for input and async return values 107 * flags: input flags (DLM_LKF_) 108 * name: name of the resource to lock, can be binary 109 * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN) 110 * parent: the lock ID of a parent lock or 0 if none 111 * lockast: function DLM executes when it completes processing the request 112 * astarg: argument passed to lockast and bast functions 113 * bast: function DLM executes when this lock later blocks another request 114 * 115 * Returns: 116 * 0 if request is successfully queued for processing 117 * -EINVAL if any input parameters are invalid 118 * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE 119 * -ENOMEM if there is no memory to process request 120 * -ENOTCONN if there is a communication error 121 * 122 * If the call to dlm_lock returns an error then the operation has failed and 123 * the AST routine will not be called. If dlm_lock returns 0 it is still 124 * possible that the lock operation will fail. The AST routine will be called 125 * when the locking is complete and the status is returned in the lksb. 126 * 127 * If the AST routines or parameter are passed to a conversion operation then 128 * they will overwrite those values that were passed to a previous dlm_lock 129 * call. 130 * 131 * AST routines should not block (at least not for long), but may make 132 * any locking calls they please. 133 */ 134 135 int dlm_lock(dlm_lockspace_t *lockspace, 136 int mode, 137 struct dlm_lksb *lksb, 138 uint32_t flags, 139 void *name, 140 unsigned int namelen, 141 uint32_t parent_lkid, 142 void (*lockast) (void *astarg), 143 void *astarg, 144 void (*bast) (void *astarg, int mode)); 145 146 /* 147 * dlm_unlock 148 * 149 * Asynchronously release a lock on a resource. The AST routine is called 150 * when the resource is successfully unlocked. 151 * 152 * lockspace: context for the request 153 * lkid: the lock ID as returned in the lksb 154 * flags: input flags (DLM_LKF_) 155 * lksb: if NULL the lksb parameter passed to last lock request is used 156 * astarg: the arg used with the completion ast for the unlock 157 * 158 * Returns: 159 * 0 if request is successfully queued for processing 160 * -EINVAL if any input parameters are invalid 161 * -ENOTEMPTY if the lock still has sublocks 162 * -EBUSY if the lock is waiting for a remote lock operation 163 * -ENOTCONN if there is a communication error 164 */ 165 166 int dlm_unlock(dlm_lockspace_t *lockspace, 167 uint32_t lkid, 168 uint32_t flags, 169 struct dlm_lksb *lksb, 170 void *astarg); 171 172 #endif /* __DLM_DOT_H__ */ 173