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