David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | ******************************************************************************* |
| 3 | ** |
| 4 | ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
David Teigland | 60f98d1 | 2011-11-02 14:30:58 -0500 | [diff] [blame] | 5 | ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 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 | |
Joel Becker | d69a3ad | 2007-10-05 14:31:44 -0700 | [diff] [blame] | 22 | /* Lock levels and flags are here */ |
| 23 | #include <linux/dlmconstants.h> |
Mike Frysinger | c1c7674 | 2008-04-21 11:35:39 -0500 | [diff] [blame] | 24 | #include <linux/types.h> |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 25 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 26 | typedef void dlm_lockspace_t; |
| 27 | |
| 28 | /* |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 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 |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 51 | * -DLM_EUNLOCK if unlock request was successful |
| 52 | * -DLM_ECANCEL if a cancel completed successfully |
Steven Whitehouse | 269cddd | 2010-09-07 14:17:10 -0500 | [diff] [blame] | 53 | * -EDEADLK if a deadlock was detected |
| 54 | * -ETIMEDOUT if the lock request was canceled due to a timeout |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 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; |
Mike Frysinger | c1c7674 | 2008-04-21 11:35:39 -0500 | [diff] [blame] | 63 | __u32 sb_lkid; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 64 | char sb_flags; |
| 65 | char * sb_lvbptr; |
| 66 | }; |
| 67 | |
David Teigland | 0f8e0d9 | 2008-08-06 13:30:24 -0500 | [diff] [blame] | 68 | /* dlm_new_lockspace() flags */ |
| 69 | |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 70 | #define DLM_LSFL_TIMEWARN 0x00000002 |
Patrick Caulfield | 44f487a | 2007-06-06 09:21:22 -0500 | [diff] [blame] | 71 | #define DLM_LSFL_FS 0x00000004 |
David Teigland | 0f8e0d9 | 2008-08-06 13:30:24 -0500 | [diff] [blame] | 72 | #define DLM_LSFL_NEWEXCL 0x00000008 |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 73 | |
| 74 | #ifdef __KERNEL__ |
| 75 | |
David Teigland | 60f98d1 | 2011-11-02 14:30:58 -0500 | [diff] [blame] | 76 | struct dlm_slot { |
| 77 | int nodeid; /* 1 to MAX_INT */ |
| 78 | int slot; /* 1 to MAX_INT */ |
| 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * recover_prep: called before the dlm begins lock recovery. |
| 83 | * Notfies lockspace user that locks from failed members will be granted. |
| 84 | * recover_slot: called after recover_prep and before recover_done. |
| 85 | * Identifies a failed lockspace member. |
| 86 | * recover_done: called after the dlm completes lock recovery. |
| 87 | * Identifies lockspace members and lockspace generation number. |
| 88 | */ |
| 89 | |
| 90 | struct dlm_lockspace_ops { |
| 91 | void (*recover_prep) (void *ops_arg); |
| 92 | void (*recover_slot) (void *ops_arg, struct dlm_slot *slot); |
| 93 | void (*recover_done) (void *ops_arg, struct dlm_slot *slots, |
| 94 | int num_slots, int our_slot, uint32_t generation); |
| 95 | }; |
| 96 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 97 | /* |
| 98 | * dlm_new_lockspace |
| 99 | * |
David Teigland | 60f98d1 | 2011-11-02 14:30:58 -0500 | [diff] [blame] | 100 | * Create/join a lockspace. |
| 101 | * |
| 102 | * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not |
| 103 | * including terminating null). |
| 104 | * |
| 105 | * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not |
| 106 | * including terminating null). Optional. When cluster is null, it |
| 107 | * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster |
| 108 | * is not equal to the dlm cluster name. |
| 109 | * |
| 110 | * flags: |
| 111 | * DLM_LSFL_NODIR |
| 112 | * The dlm should not use a resource directory, but statically assign |
| 113 | * resource mastery to nodes based on the name hash that is otherwise |
| 114 | * used to select the directory node. Must be the same on all nodes. |
| 115 | * DLM_LSFL_TIMEWARN |
| 116 | * The dlm should emit netlink messages if locks have been waiting |
| 117 | * for a configurable amount of time. (Unused.) |
| 118 | * DLM_LSFL_FS |
| 119 | * The lockspace user is in the kernel (i.e. filesystem). Enables |
| 120 | * direct bast/cast callbacks. |
| 121 | * DLM_LSFL_NEWEXCL |
| 122 | * dlm_new_lockspace() should return -EEXIST if the lockspace exists. |
| 123 | * |
| 124 | * lvblen: length of lvb in bytes. Must be multiple of 8. |
| 125 | * dlm_new_lockspace() returns an error if this does not match |
| 126 | * what other nodes are using. |
| 127 | * |
| 128 | * ops: callbacks that indicate lockspace recovery points so the |
| 129 | * caller can coordinate its recovery and know lockspace members. |
| 130 | * This is only used by the initial dlm_new_lockspace() call. |
| 131 | * Optional. |
| 132 | * |
| 133 | * ops_arg: arg for ops callbacks. |
| 134 | * |
| 135 | * ops_result: tells caller if the ops callbacks (if provided) will |
| 136 | * be used or not. 0: will be used, -EXXX will not be used. |
| 137 | * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled. |
| 138 | * |
| 139 | * lockspace: handle for dlm functions |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 140 | */ |
| 141 | |
David Teigland | 60f98d1 | 2011-11-02 14:30:58 -0500 | [diff] [blame] | 142 | int dlm_new_lockspace(const char *name, const char *cluster, |
| 143 | uint32_t flags, int lvblen, |
| 144 | const struct dlm_lockspace_ops *ops, void *ops_arg, |
| 145 | int *ops_result, dlm_lockspace_t **lockspace); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 146 | |
| 147 | /* |
| 148 | * dlm_release_lockspace |
| 149 | * |
| 150 | * Stop a lockspace. |
| 151 | */ |
| 152 | |
| 153 | int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); |
| 154 | |
| 155 | /* |
| 156 | * dlm_lock |
| 157 | * |
| 158 | * Make an asyncronous request to acquire or convert a lock on a named |
| 159 | * resource. |
| 160 | * |
| 161 | * lockspace: context for the request |
| 162 | * mode: the requested mode of the lock (DLM_LOCK_) |
| 163 | * lksb: lock status block for input and async return values |
| 164 | * flags: input flags (DLM_LKF_) |
| 165 | * name: name of the resource to lock, can be binary |
| 166 | * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN) |
| 167 | * parent: the lock ID of a parent lock or 0 if none |
| 168 | * lockast: function DLM executes when it completes processing the request |
| 169 | * astarg: argument passed to lockast and bast functions |
| 170 | * bast: function DLM executes when this lock later blocks another request |
| 171 | * |
| 172 | * Returns: |
| 173 | * 0 if request is successfully queued for processing |
| 174 | * -EINVAL if any input parameters are invalid |
| 175 | * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE |
| 176 | * -ENOMEM if there is no memory to process request |
| 177 | * -ENOTCONN if there is a communication error |
| 178 | * |
| 179 | * If the call to dlm_lock returns an error then the operation has failed and |
| 180 | * the AST routine will not be called. If dlm_lock returns 0 it is still |
| 181 | * possible that the lock operation will fail. The AST routine will be called |
| 182 | * when the locking is complete and the status is returned in the lksb. |
| 183 | * |
| 184 | * If the AST routines or parameter are passed to a conversion operation then |
| 185 | * they will overwrite those values that were passed to a previous dlm_lock |
| 186 | * call. |
| 187 | * |
| 188 | * AST routines should not block (at least not for long), but may make |
| 189 | * any locking calls they please. |
| 190 | */ |
| 191 | |
| 192 | int dlm_lock(dlm_lockspace_t *lockspace, |
| 193 | int mode, |
| 194 | struct dlm_lksb *lksb, |
| 195 | uint32_t flags, |
| 196 | void *name, |
| 197 | unsigned int namelen, |
| 198 | uint32_t parent_lkid, |
| 199 | void (*lockast) (void *astarg), |
| 200 | void *astarg, |
David Teigland | 3bcd368 | 2006-02-23 09:56:38 +0000 | [diff] [blame] | 201 | void (*bast) (void *astarg, int mode)); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * dlm_unlock |
| 205 | * |
| 206 | * Asynchronously release a lock on a resource. The AST routine is called |
| 207 | * when the resource is successfully unlocked. |
| 208 | * |
| 209 | * lockspace: context for the request |
| 210 | * lkid: the lock ID as returned in the lksb |
| 211 | * flags: input flags (DLM_LKF_) |
| 212 | * lksb: if NULL the lksb parameter passed to last lock request is used |
| 213 | * astarg: the arg used with the completion ast for the unlock |
| 214 | * |
| 215 | * Returns: |
| 216 | * 0 if request is successfully queued for processing |
| 217 | * -EINVAL if any input parameters are invalid |
| 218 | * -ENOTEMPTY if the lock still has sublocks |
| 219 | * -EBUSY if the lock is waiting for a remote lock operation |
| 220 | * -ENOTCONN if there is a communication error |
| 221 | */ |
| 222 | |
| 223 | int dlm_unlock(dlm_lockspace_t *lockspace, |
| 224 | uint32_t lkid, |
| 225 | uint32_t flags, |
| 226 | struct dlm_lksb *lksb, |
| 227 | void *astarg); |
| 228 | |
| 229 | #endif /* __KERNEL__ */ |
| 230 | |
| 231 | #endif /* __DLM_DOT_H__ */ |
| 232 | |