dlm.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2007 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. * Interface to Distributed Lock Manager (DLM)
  17. * routines and structures to use DLM lockspaces
  18. */
  19. /*
  20. * Lock Modes
  21. */
  22. #define DLM_LOCK_IV -1 /* invalid */
  23. #define DLM_LOCK_NL 0 /* null */
  24. #define DLM_LOCK_CR 1 /* concurrent read */
  25. #define DLM_LOCK_CW 2 /* concurrent write */
  26. #define DLM_LOCK_PR 3 /* protected read */
  27. #define DLM_LOCK_PW 4 /* protected write */
  28. #define DLM_LOCK_EX 5 /* exclusive */
  29. /*
  30. * Maximum size in bytes of a dlm_lock name
  31. */
  32. #define DLM_RESNAME_MAXLEN 64
  33. /*
  34. * Flags to dlm_lock
  35. *
  36. * DLM_LKF_NOQUEUE
  37. *
  38. * Do not queue the lock request on the wait queue if it cannot be granted
  39. * immediately. If the lock cannot be granted because of this flag, DLM will
  40. * either return -EAGAIN from the dlm_lock call or will return 0 from
  41. * dlm_lock and -EAGAIN in the lock status block when the AST is executed.
  42. *
  43. * DLM_LKF_CANCEL
  44. *
  45. * Used to cancel a pending lock request or conversion. A converting lock is
  46. * returned to its previously granted mode.
  47. *
  48. * DLM_LKF_CONVERT
  49. *
  50. * Indicates a lock conversion request. For conversions the name and namelen
  51. * are ignored and the lock ID in the LKSB is used to identify the lock.
  52. *
  53. * DLM_LKF_VALBLK
  54. *
  55. * Requests DLM to return the current contents of the lock value block in the
  56. * lock status block. When this flag is set in a lock conversion from PW or EX
  57. * modes, DLM assigns the value specified in the lock status block to the lock
  58. * value block of the lock resource. The LVB is a DLM_LVB_LEN size array
  59. * containing application-specific information.
  60. *
  61. * DLM_LKF_QUECVT
  62. *
  63. * Force a conversion request to be queued, even if it is compatible with
  64. * the granted modes of other locks on the same resource.
  65. *
  66. * DLM_LKF_IVVALBLK
  67. *
  68. * Invalidate the lock value block.
  69. *
  70. * DLM_LKF_CONVDEADLK
  71. *
  72. * Allows the dlm to resolve conversion deadlocks internally by demoting the
  73. * granted mode of a converting lock to NL. The DLM_SBF_DEMOTED flag is
  74. * returned for a conversion that's been effected by this.
  75. *
  76. * DLM_LKF_PERSISTENT
  77. *
  78. * Only relevant to locks originating in userspace. A persistent lock will not
  79. * be removed if the process holding the lock exits.
  80. *
  81. * DLM_LKF_NODLCKWT
  82. *
  83. * Do not cancel the lock if it gets into conversion deadlock.
  84. * Exclude this lock from being monitored due to DLM_LSFL_TIMEWARN.
  85. *
  86. * DLM_LKF_NODLCKBLK
  87. *
  88. * net yet implemented
  89. *
  90. * DLM_LKF_EXPEDITE
  91. *
  92. * Used only with new requests for NL mode locks. Tells the lock manager
  93. * to grant the lock, ignoring other locks in convert and wait queues.
  94. *
  95. * DLM_LKF_NOQUEUEBAST
  96. *
  97. * Send blocking AST's before returning -EAGAIN to the caller. It is only
  98. * used along with the NOQUEUE flag. Blocking AST's are not sent for failed
  99. * NOQUEUE requests otherwise.
  100. *
  101. * DLM_LKF_HEADQUE
  102. *
  103. * Add a lock to the head of the convert or wait queue rather than the tail.
  104. *
  105. * DLM_LKF_NOORDER
  106. *
  107. * Disregard the standard grant order rules and grant a lock as soon as it
  108. * is compatible with other granted locks.
  109. *
  110. * DLM_LKF_ORPHAN
  111. *
  112. * not yet implemented
  113. *
  114. * DLM_LKF_ALTPR
  115. *
  116. * If the requested mode cannot be granted immediately, try to grant the lock
  117. * in PR mode instead. If this alternate mode is granted instead of the
  118. * requested mode, DLM_SBF_ALTMODE is returned in the lksb.
  119. *
  120. * DLM_LKF_ALTCW
  121. *
  122. * The same as ALTPR, but the alternate mode is CW.
  123. *
  124. * DLM_LKF_FORCEUNLOCK
  125. *
  126. * Unlock the lock even if it is converting or waiting or has sublocks.
  127. * Only really for use by the userland device.c code.
  128. *
  129. */
  130. #define DLM_LKF_NOQUEUE 0x00000001
  131. #define DLM_LKF_CANCEL 0x00000002
  132. #define DLM_LKF_CONVERT 0x00000004
  133. #define DLM_LKF_VALBLK 0x00000008
  134. #define DLM_LKF_QUECVT 0x00000010
  135. #define DLM_LKF_IVVALBLK 0x00000020
  136. #define DLM_LKF_CONVDEADLK 0x00000040
  137. #define DLM_LKF_PERSISTENT 0x00000080
  138. #define DLM_LKF_NODLCKWT 0x00000100
  139. #define DLM_LKF_NODLCKBLK 0x00000200
  140. #define DLM_LKF_EXPEDITE 0x00000400
  141. #define DLM_LKF_NOQUEUEBAST 0x00000800
  142. #define DLM_LKF_HEADQUE 0x00001000
  143. #define DLM_LKF_NOORDER 0x00002000
  144. #define DLM_LKF_ORPHAN 0x00004000
  145. #define DLM_LKF_ALTPR 0x00008000
  146. #define DLM_LKF_ALTCW 0x00010000
  147. #define DLM_LKF_FORCEUNLOCK 0x00020000
  148. #define DLM_LKF_TIMEOUT 0x00040000
  149. /*
  150. * Some return codes that are not in errno.h
  151. */
  152. #define DLM_ECANCEL 0x10001
  153. #define DLM_EUNLOCK 0x10002
  154. typedef void dlm_lockspace_t;
  155. /*
  156. * Lock status block
  157. *
  158. * Use this structure to specify the contents of the lock value block. For a
  159. * conversion request, this structure is used to specify the lock ID of the
  160. * lock. DLM writes the status of the lock request and the lock ID assigned
  161. * to the request in the lock status block.
  162. *
  163. * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests.
  164. * It is available when dlm_lock returns.
  165. *
  166. * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules
  167. * shown for the DLM_LKF_VALBLK flag.
  168. *
  169. * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock,
  170. * it was first demoted to NL to avoid conversion deadlock.
  171. * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid.
  172. *
  173. * sb_status: the returned status of the lock request set prior to AST
  174. * execution. Possible return values:
  175. *
  176. * 0 if lock request was successful
  177. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  178. * -ENOMEM if there is no memory to process request
  179. * -EINVAL if there are invalid parameters
  180. * -DLM_EUNLOCK if unlock request was successful
  181. * -DLM_ECANCEL if a cancel completed successfully
  182. */
  183. #define DLM_SBF_DEMOTED 0x01
  184. #define DLM_SBF_VALNOTVALID 0x02
  185. #define DLM_SBF_ALTMODE 0x04
  186. struct dlm_lksb {
  187. int sb_status;
  188. uint32_t sb_lkid;
  189. char sb_flags;
  190. char * sb_lvbptr;
  191. };
  192. #define DLM_LSFL_NODIR 0x00000001
  193. #define DLM_LSFL_TIMEWARN 0x00000002
  194. #define DLM_LSFL_FS 0x00000004
  195. #ifdef __KERNEL__
  196. /*
  197. * dlm_new_lockspace
  198. *
  199. * Starts a lockspace with the given name. If the named lockspace exists in
  200. * the cluster, the calling node joins it.
  201. */
  202. int dlm_new_lockspace(char *name, int namelen, dlm_lockspace_t **lockspace,
  203. uint32_t flags, int lvblen);
  204. /*
  205. * dlm_release_lockspace
  206. *
  207. * Stop a lockspace.
  208. */
  209. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  210. /*
  211. * dlm_lock
  212. *
  213. * Make an asyncronous request to acquire or convert a lock on a named
  214. * resource.
  215. *
  216. * lockspace: context for the request
  217. * mode: the requested mode of the lock (DLM_LOCK_)
  218. * lksb: lock status block for input and async return values
  219. * flags: input flags (DLM_LKF_)
  220. * name: name of the resource to lock, can be binary
  221. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  222. * parent: the lock ID of a parent lock or 0 if none
  223. * lockast: function DLM executes when it completes processing the request
  224. * astarg: argument passed to lockast and bast functions
  225. * bast: function DLM executes when this lock later blocks another request
  226. *
  227. * Returns:
  228. * 0 if request is successfully queued for processing
  229. * -EINVAL if any input parameters are invalid
  230. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  231. * -ENOMEM if there is no memory to process request
  232. * -ENOTCONN if there is a communication error
  233. *
  234. * If the call to dlm_lock returns an error then the operation has failed and
  235. * the AST routine will not be called. If dlm_lock returns 0 it is still
  236. * possible that the lock operation will fail. The AST routine will be called
  237. * when the locking is complete and the status is returned in the lksb.
  238. *
  239. * If the AST routines or parameter are passed to a conversion operation then
  240. * they will overwrite those values that were passed to a previous dlm_lock
  241. * call.
  242. *
  243. * AST routines should not block (at least not for long), but may make
  244. * any locking calls they please.
  245. */
  246. int dlm_lock(dlm_lockspace_t *lockspace,
  247. int mode,
  248. struct dlm_lksb *lksb,
  249. uint32_t flags,
  250. void *name,
  251. unsigned int namelen,
  252. uint32_t parent_lkid,
  253. void (*lockast) (void *astarg),
  254. void *astarg,
  255. void (*bast) (void *astarg, int mode));
  256. /*
  257. * dlm_unlock
  258. *
  259. * Asynchronously release a lock on a resource. The AST routine is called
  260. * when the resource is successfully unlocked.
  261. *
  262. * lockspace: context for the request
  263. * lkid: the lock ID as returned in the lksb
  264. * flags: input flags (DLM_LKF_)
  265. * lksb: if NULL the lksb parameter passed to last lock request is used
  266. * astarg: the arg used with the completion ast for the unlock
  267. *
  268. * Returns:
  269. * 0 if request is successfully queued for processing
  270. * -EINVAL if any input parameters are invalid
  271. * -ENOTEMPTY if the lock still has sublocks
  272. * -EBUSY if the lock is waiting for a remote lock operation
  273. * -ENOTCONN if there is a communication error
  274. */
  275. int dlm_unlock(dlm_lockspace_t *lockspace,
  276. uint32_t lkid,
  277. uint32_t flags,
  278. struct dlm_lksb *lksb,
  279. void *astarg);
  280. #endif /* __KERNEL__ */
  281. #endif /* __DLM_DOT_H__ */