dlm.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2011 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. /* Lock levels and flags are here */
  20. #include <linux/dlmconstants.h>
  21. #include <linux/types.h>
  22. typedef void dlm_lockspace_t;
  23. /*
  24. * Lock status block
  25. *
  26. * Use this structure to specify the contents of the lock value block. For a
  27. * conversion request, this structure is used to specify the lock ID of the
  28. * lock. DLM writes the status of the lock request and the lock ID assigned
  29. * to the request in the lock status block.
  30. *
  31. * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests.
  32. * It is available when dlm_lock returns.
  33. *
  34. * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules
  35. * shown for the DLM_LKF_VALBLK flag.
  36. *
  37. * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock,
  38. * it was first demoted to NL to avoid conversion deadlock.
  39. * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid.
  40. *
  41. * sb_status: the returned status of the lock request set prior to AST
  42. * execution. Possible return values:
  43. *
  44. * 0 if lock request was successful
  45. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  46. * -DLM_EUNLOCK if unlock request was successful
  47. * -DLM_ECANCEL if a cancel completed successfully
  48. * -EDEADLK if a deadlock was detected
  49. * -ETIMEDOUT if the lock request was canceled due to a timeout
  50. */
  51. #define DLM_SBF_DEMOTED 0x01
  52. #define DLM_SBF_VALNOTVALID 0x02
  53. #define DLM_SBF_ALTMODE 0x04
  54. struct dlm_lksb {
  55. int sb_status;
  56. __u32 sb_lkid;
  57. char sb_flags;
  58. char * sb_lvbptr;
  59. };
  60. /* dlm_new_lockspace() flags */
  61. #define DLM_LSFL_NODIR 0x00000001
  62. #define DLM_LSFL_TIMEWARN 0x00000002
  63. #define DLM_LSFL_FS 0x00000004
  64. #define DLM_LSFL_NEWEXCL 0x00000008
  65. #ifdef __KERNEL__
  66. struct dlm_slot {
  67. int nodeid; /* 1 to MAX_INT */
  68. int slot; /* 1 to MAX_INT */
  69. };
  70. /*
  71. * recover_prep: called before the dlm begins lock recovery.
  72. * Notfies lockspace user that locks from failed members will be granted.
  73. * recover_slot: called after recover_prep and before recover_done.
  74. * Identifies a failed lockspace member.
  75. * recover_done: called after the dlm completes lock recovery.
  76. * Identifies lockspace members and lockspace generation number.
  77. */
  78. struct dlm_lockspace_ops {
  79. void (*recover_prep) (void *ops_arg);
  80. void (*recover_slot) (void *ops_arg, struct dlm_slot *slot);
  81. void (*recover_done) (void *ops_arg, struct dlm_slot *slots,
  82. int num_slots, int our_slot, uint32_t generation);
  83. };
  84. /*
  85. * dlm_new_lockspace
  86. *
  87. * Create/join a lockspace.
  88. *
  89. * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not
  90. * including terminating null).
  91. *
  92. * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not
  93. * including terminating null). Optional. When cluster is null, it
  94. * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster
  95. * is not equal to the dlm cluster name.
  96. *
  97. * flags:
  98. * DLM_LSFL_NODIR
  99. * The dlm should not use a resource directory, but statically assign
  100. * resource mastery to nodes based on the name hash that is otherwise
  101. * used to select the directory node. Must be the same on all nodes.
  102. * DLM_LSFL_TIMEWARN
  103. * The dlm should emit netlink messages if locks have been waiting
  104. * for a configurable amount of time. (Unused.)
  105. * DLM_LSFL_FS
  106. * The lockspace user is in the kernel (i.e. filesystem). Enables
  107. * direct bast/cast callbacks.
  108. * DLM_LSFL_NEWEXCL
  109. * dlm_new_lockspace() should return -EEXIST if the lockspace exists.
  110. *
  111. * lvblen: length of lvb in bytes. Must be multiple of 8.
  112. * dlm_new_lockspace() returns an error if this does not match
  113. * what other nodes are using.
  114. *
  115. * ops: callbacks that indicate lockspace recovery points so the
  116. * caller can coordinate its recovery and know lockspace members.
  117. * This is only used by the initial dlm_new_lockspace() call.
  118. * Optional.
  119. *
  120. * ops_arg: arg for ops callbacks.
  121. *
  122. * ops_result: tells caller if the ops callbacks (if provided) will
  123. * be used or not. 0: will be used, -EXXX will not be used.
  124. * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled.
  125. *
  126. * lockspace: handle for dlm functions
  127. */
  128. int dlm_new_lockspace(const char *name, const char *cluster,
  129. uint32_t flags, int lvblen,
  130. const struct dlm_lockspace_ops *ops, void *ops_arg,
  131. int *ops_result, dlm_lockspace_t **lockspace);
  132. /*
  133. * dlm_release_lockspace
  134. *
  135. * Stop a lockspace.
  136. */
  137. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  138. /*
  139. * dlm_lock
  140. *
  141. * Make an asyncronous request to acquire or convert a lock on a named
  142. * resource.
  143. *
  144. * lockspace: context for the request
  145. * mode: the requested mode of the lock (DLM_LOCK_)
  146. * lksb: lock status block for input and async return values
  147. * flags: input flags (DLM_LKF_)
  148. * name: name of the resource to lock, can be binary
  149. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  150. * parent: the lock ID of a parent lock or 0 if none
  151. * lockast: function DLM executes when it completes processing the request
  152. * astarg: argument passed to lockast and bast functions
  153. * bast: function DLM executes when this lock later blocks another request
  154. *
  155. * Returns:
  156. * 0 if request is successfully queued for processing
  157. * -EINVAL if any input parameters are invalid
  158. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  159. * -ENOMEM if there is no memory to process request
  160. * -ENOTCONN if there is a communication error
  161. *
  162. * If the call to dlm_lock returns an error then the operation has failed and
  163. * the AST routine will not be called. If dlm_lock returns 0 it is still
  164. * possible that the lock operation will fail. The AST routine will be called
  165. * when the locking is complete and the status is returned in the lksb.
  166. *
  167. * If the AST routines or parameter are passed to a conversion operation then
  168. * they will overwrite those values that were passed to a previous dlm_lock
  169. * call.
  170. *
  171. * AST routines should not block (at least not for long), but may make
  172. * any locking calls they please.
  173. */
  174. int dlm_lock(dlm_lockspace_t *lockspace,
  175. int mode,
  176. struct dlm_lksb *lksb,
  177. uint32_t flags,
  178. void *name,
  179. unsigned int namelen,
  180. uint32_t parent_lkid,
  181. void (*lockast) (void *astarg),
  182. void *astarg,
  183. void (*bast) (void *astarg, int mode));
  184. /*
  185. * dlm_unlock
  186. *
  187. * Asynchronously release a lock on a resource. The AST routine is called
  188. * when the resource is successfully unlocked.
  189. *
  190. * lockspace: context for the request
  191. * lkid: the lock ID as returned in the lksb
  192. * flags: input flags (DLM_LKF_)
  193. * lksb: if NULL the lksb parameter passed to last lock request is used
  194. * astarg: the arg used with the completion ast for the unlock
  195. *
  196. * Returns:
  197. * 0 if request is successfully queued for processing
  198. * -EINVAL if any input parameters are invalid
  199. * -ENOTEMPTY if the lock still has sublocks
  200. * -EBUSY if the lock is waiting for a remote lock operation
  201. * -ENOTCONN if there is a communication error
  202. */
  203. int dlm_unlock(dlm_lockspace_t *lockspace,
  204. uint32_t lkid,
  205. uint32_t flags,
  206. struct dlm_lksb *lksb,
  207. void *astarg);
  208. #endif /* __KERNEL__ */
  209. #endif /* __DLM_DOT_H__ */