12522fe45SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2e7fd4179SDavid Teigland /****************************************************************************** 3e7fd4179SDavid Teigland ******************************************************************************* 4e7fd4179SDavid Teigland ** 5e7fd4179SDavid Teigland ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 660f98d18SDavid Teigland ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. 7e7fd4179SDavid Teigland ** 8e7fd4179SDavid Teigland ** 9e7fd4179SDavid Teigland ******************************************************************************* 10e7fd4179SDavid Teigland ******************************************************************************/ 11e7fd4179SDavid Teigland #ifndef __DLM_DOT_H__ 12e7fd4179SDavid Teigland #define __DLM_DOT_H__ 13e7fd4179SDavid Teigland 14607ca46eSDavid Howells #include <uapi/linux/dlm.h> 15e7fd4179SDavid Teigland 16e7fd4179SDavid Teigland 1760f98d18SDavid Teigland struct dlm_slot { 1860f98d18SDavid Teigland int nodeid; /* 1 to MAX_INT */ 1960f98d18SDavid Teigland int slot; /* 1 to MAX_INT */ 2060f98d18SDavid Teigland }; 2160f98d18SDavid Teigland 2260f98d18SDavid Teigland /* 2360f98d18SDavid Teigland * recover_prep: called before the dlm begins lock recovery. 2460f98d18SDavid Teigland * Notfies lockspace user that locks from failed members will be granted. 2560f98d18SDavid Teigland * recover_slot: called after recover_prep and before recover_done. 2660f98d18SDavid Teigland * Identifies a failed lockspace member. 2760f98d18SDavid Teigland * recover_done: called after the dlm completes lock recovery. 2860f98d18SDavid Teigland * Identifies lockspace members and lockspace generation number. 2960f98d18SDavid Teigland */ 3060f98d18SDavid Teigland 3160f98d18SDavid Teigland struct dlm_lockspace_ops { 3260f98d18SDavid Teigland void (*recover_prep) (void *ops_arg); 3360f98d18SDavid Teigland void (*recover_slot) (void *ops_arg, struct dlm_slot *slot); 3460f98d18SDavid Teigland void (*recover_done) (void *ops_arg, struct dlm_slot *slots, 3560f98d18SDavid Teigland int num_slots, int our_slot, uint32_t generation); 3660f98d18SDavid Teigland }; 3760f98d18SDavid Teigland 38*f328a26eSAlexander Aring /* only relevant for kernel lockspaces, will be removed in future */ 39*f328a26eSAlexander Aring #define DLM_LSFL_SOFTIRQ __DLM_LSFL_RESERVED0 40*f328a26eSAlexander Aring 41e7fd4179SDavid Teigland /* 42e7fd4179SDavid Teigland * dlm_new_lockspace 43e7fd4179SDavid Teigland * 4460f98d18SDavid Teigland * Create/join a lockspace. 4560f98d18SDavid Teigland * 4660f98d18SDavid Teigland * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not 4760f98d18SDavid Teigland * including terminating null). 4860f98d18SDavid Teigland * 4960f98d18SDavid Teigland * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not 5060f98d18SDavid Teigland * including terminating null). Optional. When cluster is null, it 5160f98d18SDavid Teigland * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster 5260f98d18SDavid Teigland * is not equal to the dlm cluster name. 5360f98d18SDavid Teigland * 5460f98d18SDavid Teigland * flags: 5560f98d18SDavid Teigland * DLM_LSFL_NODIR 5660f98d18SDavid Teigland * The dlm should not use a resource directory, but statically assign 5760f98d18SDavid Teigland * resource mastery to nodes based on the name hash that is otherwise 5860f98d18SDavid Teigland * used to select the directory node. Must be the same on all nodes. 5960f98d18SDavid Teigland * DLM_LSFL_NEWEXCL 6060f98d18SDavid Teigland * dlm_new_lockspace() should return -EEXIST if the lockspace exists. 61*f328a26eSAlexander Aring * DLM_LSFL_SOFTIRQ 62*f328a26eSAlexander Aring * dlm request callbacks (ast, bast) are softirq safe. Flag should be 63*f328a26eSAlexander Aring * preferred by users. Will be default in some future. If set the 64*f328a26eSAlexander Aring * strongest context for ast, bast callback is softirq as it avoids 65*f328a26eSAlexander Aring * an additional context switch. 6660f98d18SDavid Teigland * 6760f98d18SDavid Teigland * lvblen: length of lvb in bytes. Must be multiple of 8. 6860f98d18SDavid Teigland * dlm_new_lockspace() returns an error if this does not match 6960f98d18SDavid Teigland * what other nodes are using. 7060f98d18SDavid Teigland * 7160f98d18SDavid Teigland * ops: callbacks that indicate lockspace recovery points so the 7260f98d18SDavid Teigland * caller can coordinate its recovery and know lockspace members. 7360f98d18SDavid Teigland * This is only used by the initial dlm_new_lockspace() call. 7460f98d18SDavid Teigland * Optional. 7560f98d18SDavid Teigland * 7660f98d18SDavid Teigland * ops_arg: arg for ops callbacks. 7760f98d18SDavid Teigland * 7860f98d18SDavid Teigland * ops_result: tells caller if the ops callbacks (if provided) will 7960f98d18SDavid Teigland * be used or not. 0: will be used, -EXXX will not be used. 8060f98d18SDavid Teigland * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled. 8160f98d18SDavid Teigland * 8260f98d18SDavid Teigland * lockspace: handle for dlm functions 83e7fd4179SDavid Teigland */ 84e7fd4179SDavid Teigland 8560f98d18SDavid Teigland int dlm_new_lockspace(const char *name, const char *cluster, 8660f98d18SDavid Teigland uint32_t flags, int lvblen, 8760f98d18SDavid Teigland const struct dlm_lockspace_ops *ops, void *ops_arg, 8860f98d18SDavid Teigland int *ops_result, dlm_lockspace_t **lockspace); 89e7fd4179SDavid Teigland 90e7fd4179SDavid Teigland /* 91e7fd4179SDavid Teigland * dlm_release_lockspace 92e7fd4179SDavid Teigland * 93e7fd4179SDavid Teigland * Stop a lockspace. 94e7fd4179SDavid Teigland */ 95e7fd4179SDavid Teigland 96e7fd4179SDavid Teigland int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); 97e7fd4179SDavid Teigland 98e7fd4179SDavid Teigland /* 99e7fd4179SDavid Teigland * dlm_lock 100e7fd4179SDavid Teigland * 101b3834be5SAdam Buchbinder * Make an asynchronous request to acquire or convert a lock on a named 102e7fd4179SDavid Teigland * resource. 103e7fd4179SDavid Teigland * 104e7fd4179SDavid Teigland * lockspace: context for the request 105e7fd4179SDavid Teigland * mode: the requested mode of the lock (DLM_LOCK_) 106e7fd4179SDavid Teigland * lksb: lock status block for input and async return values 107e7fd4179SDavid Teigland * flags: input flags (DLM_LKF_) 108e7fd4179SDavid Teigland * name: name of the resource to lock, can be binary 109e7fd4179SDavid Teigland * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN) 110e7fd4179SDavid Teigland * parent: the lock ID of a parent lock or 0 if none 111e7fd4179SDavid Teigland * lockast: function DLM executes when it completes processing the request 112e7fd4179SDavid Teigland * astarg: argument passed to lockast and bast functions 113e7fd4179SDavid Teigland * bast: function DLM executes when this lock later blocks another request 114e7fd4179SDavid Teigland * 115e7fd4179SDavid Teigland * Returns: 116e7fd4179SDavid Teigland * 0 if request is successfully queued for processing 117e7fd4179SDavid Teigland * -EINVAL if any input parameters are invalid 118e7fd4179SDavid Teigland * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE 119e7fd4179SDavid Teigland * -ENOMEM if there is no memory to process request 120e7fd4179SDavid Teigland * -ENOTCONN if there is a communication error 121e7fd4179SDavid Teigland * 122e7fd4179SDavid Teigland * If the call to dlm_lock returns an error then the operation has failed and 123e7fd4179SDavid Teigland * the AST routine will not be called. If dlm_lock returns 0 it is still 124e7fd4179SDavid Teigland * possible that the lock operation will fail. The AST routine will be called 125e7fd4179SDavid Teigland * when the locking is complete and the status is returned in the lksb. 126e7fd4179SDavid Teigland * 127e7fd4179SDavid Teigland * If the AST routines or parameter are passed to a conversion operation then 128e7fd4179SDavid Teigland * they will overwrite those values that were passed to a previous dlm_lock 129e7fd4179SDavid Teigland * call. 130e7fd4179SDavid Teigland * 131e7fd4179SDavid Teigland * AST routines should not block (at least not for long), but may make 132*f328a26eSAlexander Aring * any locking calls they please. If DLM_LSFL_SOFTIRQ for kernel 133*f328a26eSAlexander Aring * users of dlm_new_lockspace() is passed the ast and bast callbacks 134*f328a26eSAlexander Aring * can be processed in softirq context. Also some of the callback 135*f328a26eSAlexander Aring * contexts are in the same context as the DLM lock request API, users 136*f328a26eSAlexander Aring * must not hold locks while calling dlm lock request API and trying 137*f328a26eSAlexander Aring * to acquire this lock in the callback again, this will end in a 138*f328a26eSAlexander Aring * lock recursion. For newer implementation the DLM_LSFL_SOFTIRQ 139*f328a26eSAlexander Aring * should be used. 140e7fd4179SDavid Teigland */ 141e7fd4179SDavid Teigland 142e7fd4179SDavid Teigland int dlm_lock(dlm_lockspace_t *lockspace, 143e7fd4179SDavid Teigland int mode, 144e7fd4179SDavid Teigland struct dlm_lksb *lksb, 145e7fd4179SDavid Teigland uint32_t flags, 14656171e0dSAlexander Aring const void *name, 147e7fd4179SDavid Teigland unsigned int namelen, 148e7fd4179SDavid Teigland uint32_t parent_lkid, 149e7fd4179SDavid Teigland void (*lockast) (void *astarg), 150e7fd4179SDavid Teigland void *astarg, 1513bcd3687SDavid Teigland void (*bast) (void *astarg, int mode)); 152e7fd4179SDavid Teigland 153e7fd4179SDavid Teigland /* 154e7fd4179SDavid Teigland * dlm_unlock 155e7fd4179SDavid Teigland * 156e7fd4179SDavid Teigland * Asynchronously release a lock on a resource. The AST routine is called 157e7fd4179SDavid Teigland * when the resource is successfully unlocked. 158e7fd4179SDavid Teigland * 159e7fd4179SDavid Teigland * lockspace: context for the request 160e7fd4179SDavid Teigland * lkid: the lock ID as returned in the lksb 161e7fd4179SDavid Teigland * flags: input flags (DLM_LKF_) 162e7fd4179SDavid Teigland * lksb: if NULL the lksb parameter passed to last lock request is used 163e7fd4179SDavid Teigland * astarg: the arg used with the completion ast for the unlock 164e7fd4179SDavid Teigland * 165e7fd4179SDavid Teigland * Returns: 166e7fd4179SDavid Teigland * 0 if request is successfully queued for processing 167e7fd4179SDavid Teigland * -EINVAL if any input parameters are invalid 168e7fd4179SDavid Teigland * -ENOTEMPTY if the lock still has sublocks 169e7fd4179SDavid Teigland * -EBUSY if the lock is waiting for a remote lock operation 170e7fd4179SDavid Teigland * -ENOTCONN if there is a communication error 171e7fd4179SDavid Teigland */ 172e7fd4179SDavid Teigland 173e7fd4179SDavid Teigland int dlm_unlock(dlm_lockspace_t *lockspace, 174e7fd4179SDavid Teigland uint32_t lkid, 175e7fd4179SDavid Teigland uint32_t flags, 176e7fd4179SDavid Teigland struct dlm_lksb *lksb, 177e7fd4179SDavid Teigland void *astarg); 178e7fd4179SDavid Teigland 179e7fd4179SDavid Teigland #endif /* __DLM_DOT_H__ */ 180