dlm.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2005 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_NODLKWT
  82. * DLM_LKF_NODLCKBLK
  83. *
  84. * net yet implemented
  85. *
  86. * DLM_LKF_EXPEDITE
  87. *
  88. * Used only with new requests for NL mode locks. Tells the lock manager
  89. * to grant the lock, ignoring other locks in convert and wait queues.
  90. *
  91. * DLM_LKF_NOQUEUEBAST
  92. *
  93. * Send blocking AST's before returning -EAGAIN to the caller. It is only
  94. * used along with the NOQUEUE flag. Blocking AST's are not sent for failed
  95. * NOQUEUE requests otherwise.
  96. *
  97. * DLM_LKF_HEADQUE
  98. *
  99. * Add a lock to the head of the convert or wait queue rather than the tail.
  100. *
  101. * DLM_LKF_NOORDER
  102. *
  103. * Disregard the standard grant order rules and grant a lock as soon as it
  104. * is compatible with other granted locks.
  105. *
  106. * DLM_LKF_ORPHAN
  107. *
  108. * not yet implemented
  109. *
  110. * DLM_LKF_ALTPR
  111. *
  112. * If the requested mode cannot be granted immediately, try to grant the lock
  113. * in PR mode instead. If this alternate mode is granted instead of the
  114. * requested mode, DLM_SBF_ALTMODE is returned in the lksb.
  115. *
  116. * DLM_LKF_ALTCW
  117. *
  118. * The same as ALTPR, but the alternate mode is CW.
  119. *
  120. * DLM_LKF_FORCEUNLOCK
  121. *
  122. * Unlock the lock even if it is converting or waiting or has sublocks.
  123. * Only really for use by the userland device.c code.
  124. *
  125. */
  126. #define DLM_LKF_NOQUEUE 0x00000001
  127. #define DLM_LKF_CANCEL 0x00000002
  128. #define DLM_LKF_CONVERT 0x00000004
  129. #define DLM_LKF_VALBLK 0x00000008
  130. #define DLM_LKF_QUECVT 0x00000010
  131. #define DLM_LKF_IVVALBLK 0x00000020
  132. #define DLM_LKF_CONVDEADLK 0x00000040
  133. #define DLM_LKF_PERSISTENT 0x00000080
  134. #define DLM_LKF_NODLCKWT 0x00000100
  135. #define DLM_LKF_NODLCKBLK 0x00000200
  136. #define DLM_LKF_EXPEDITE 0x00000400
  137. #define DLM_LKF_NOQUEUEBAST 0x00000800
  138. #define DLM_LKF_HEADQUE 0x00001000
  139. #define DLM_LKF_NOORDER 0x00002000
  140. #define DLM_LKF_ORPHAN 0x00004000
  141. #define DLM_LKF_ALTPR 0x00008000
  142. #define DLM_LKF_ALTCW 0x00010000
  143. #define DLM_LKF_FORCEUNLOCK 0x00020000
  144. /*
  145. * Some return codes that are not in errno.h
  146. */
  147. #define DLM_ECANCEL 0x10001
  148. #define DLM_EUNLOCK 0x10002
  149. typedef void dlm_lockspace_t;
  150. /*
  151. * Lock status block
  152. *
  153. * Use this structure to specify the contents of the lock value block. For a
  154. * conversion request, this structure is used to specify the lock ID of the
  155. * lock. DLM writes the status of the lock request and the lock ID assigned
  156. * to the request in the lock status block.
  157. *
  158. * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests.
  159. * It is available when dlm_lock returns.
  160. *
  161. * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules
  162. * shown for the DLM_LKF_VALBLK flag.
  163. *
  164. * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock,
  165. * it was first demoted to NL to avoid conversion deadlock.
  166. * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid.
  167. *
  168. * sb_status: the returned status of the lock request set prior to AST
  169. * execution. Possible return values:
  170. *
  171. * 0 if lock request was successful
  172. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  173. * -ENOMEM if there is no memory to process request
  174. * -EINVAL if there are invalid parameters
  175. * -DLM_EUNLOCK if unlock request was successful
  176. * -DLM_ECANCEL if a cancel completed successfully
  177. */
  178. #define DLM_SBF_DEMOTED 0x01
  179. #define DLM_SBF_VALNOTVALID 0x02
  180. #define DLM_SBF_ALTMODE 0x04
  181. struct dlm_lksb {
  182. int sb_status;
  183. uint32_t sb_lkid;
  184. char sb_flags;
  185. char * sb_lvbptr;
  186. };
  187. #ifdef __KERNEL__
  188. #define DLM_LSFL_NODIR 0x00000001
  189. /*
  190. * dlm_new_lockspace
  191. *
  192. * Starts a lockspace with the given name. If the named lockspace exists in
  193. * the cluster, the calling node joins it.
  194. */
  195. int dlm_new_lockspace(char *name, int namelen, dlm_lockspace_t **lockspace,
  196. uint32_t flags, int lvblen);
  197. /*
  198. * dlm_release_lockspace
  199. *
  200. * Stop a lockspace.
  201. */
  202. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  203. /*
  204. * dlm_lock
  205. *
  206. * Make an asyncronous request to acquire or convert a lock on a named
  207. * resource.
  208. *
  209. * lockspace: context for the request
  210. * mode: the requested mode of the lock (DLM_LOCK_)
  211. * lksb: lock status block for input and async return values
  212. * flags: input flags (DLM_LKF_)
  213. * name: name of the resource to lock, can be binary
  214. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  215. * parent: the lock ID of a parent lock or 0 if none
  216. * lockast: function DLM executes when it completes processing the request
  217. * astarg: argument passed to lockast and bast functions
  218. * bast: function DLM executes when this lock later blocks another request
  219. *
  220. * Returns:
  221. * 0 if request is successfully queued for processing
  222. * -EINVAL if any input parameters are invalid
  223. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  224. * -ENOMEM if there is no memory to process request
  225. * -ENOTCONN if there is a communication error
  226. *
  227. * If the call to dlm_lock returns an error then the operation has failed and
  228. * the AST routine will not be called. If dlm_lock returns 0 it is still
  229. * possible that the lock operation will fail. The AST routine will be called
  230. * when the locking is complete and the status is returned in the lksb.
  231. *
  232. * If the AST routines or parameter are passed to a conversion operation then
  233. * they will overwrite those values that were passed to a previous dlm_lock
  234. * call.
  235. *
  236. * AST routines should not block (at least not for long), but may make
  237. * any locking calls they please.
  238. */
  239. int dlm_lock(dlm_lockspace_t *lockspace,
  240. int mode,
  241. struct dlm_lksb *lksb,
  242. uint32_t flags,
  243. void *name,
  244. unsigned int namelen,
  245. uint32_t parent_lkid,
  246. void (*lockast) (void *astarg),
  247. void *astarg,
  248. void (*bast) (void *astarg, int mode));
  249. /*
  250. * dlm_unlock
  251. *
  252. * Asynchronously release a lock on a resource. The AST routine is called
  253. * when the resource is successfully unlocked.
  254. *
  255. * lockspace: context for the request
  256. * lkid: the lock ID as returned in the lksb
  257. * flags: input flags (DLM_LKF_)
  258. * lksb: if NULL the lksb parameter passed to last lock request is used
  259. * astarg: the arg used with the completion ast for the unlock
  260. *
  261. * Returns:
  262. * 0 if request is successfully queued for processing
  263. * -EINVAL if any input parameters are invalid
  264. * -ENOTEMPTY if the lock still has sublocks
  265. * -EBUSY if the lock is waiting for a remote lock operation
  266. * -ENOTCONN if there is a communication error
  267. */
  268. int dlm_unlock(dlm_lockspace_t *lockspace,
  269. uint32_t lkid,
  270. uint32_t flags,
  271. struct dlm_lksb *lksb,
  272. void *astarg);
  273. #endif /* __KERNEL__ */
  274. #endif /* __DLM_DOT_H__ */