dlm.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_TIMEWARN 0x00000002
  62. #define DLM_LSFL_FS 0x00000004
  63. #define DLM_LSFL_NEWEXCL 0x00000008
  64. #ifdef __KERNEL__
  65. struct dlm_slot {
  66. int nodeid; /* 1 to MAX_INT */
  67. int slot; /* 1 to MAX_INT */
  68. };
  69. /*
  70. * recover_prep: called before the dlm begins lock recovery.
  71. * Notfies lockspace user that locks from failed members will be granted.
  72. * recover_slot: called after recover_prep and before recover_done.
  73. * Identifies a failed lockspace member.
  74. * recover_done: called after the dlm completes lock recovery.
  75. * Identifies lockspace members and lockspace generation number.
  76. */
  77. struct dlm_lockspace_ops {
  78. void (*recover_prep) (void *ops_arg);
  79. void (*recover_slot) (void *ops_arg, struct dlm_slot *slot);
  80. void (*recover_done) (void *ops_arg, struct dlm_slot *slots,
  81. int num_slots, int our_slot, uint32_t generation);
  82. };
  83. /*
  84. * dlm_new_lockspace
  85. *
  86. * Create/join a lockspace.
  87. *
  88. * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not
  89. * including terminating null).
  90. *
  91. * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not
  92. * including terminating null). Optional. When cluster is null, it
  93. * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster
  94. * is not equal to the dlm cluster name.
  95. *
  96. * flags:
  97. * DLM_LSFL_NODIR
  98. * The dlm should not use a resource directory, but statically assign
  99. * resource mastery to nodes based on the name hash that is otherwise
  100. * used to select the directory node. Must be the same on all nodes.
  101. * DLM_LSFL_TIMEWARN
  102. * The dlm should emit netlink messages if locks have been waiting
  103. * for a configurable amount of time. (Unused.)
  104. * DLM_LSFL_FS
  105. * The lockspace user is in the kernel (i.e. filesystem). Enables
  106. * direct bast/cast callbacks.
  107. * DLM_LSFL_NEWEXCL
  108. * dlm_new_lockspace() should return -EEXIST if the lockspace exists.
  109. *
  110. * lvblen: length of lvb in bytes. Must be multiple of 8.
  111. * dlm_new_lockspace() returns an error if this does not match
  112. * what other nodes are using.
  113. *
  114. * ops: callbacks that indicate lockspace recovery points so the
  115. * caller can coordinate its recovery and know lockspace members.
  116. * This is only used by the initial dlm_new_lockspace() call.
  117. * Optional.
  118. *
  119. * ops_arg: arg for ops callbacks.
  120. *
  121. * ops_result: tells caller if the ops callbacks (if provided) will
  122. * be used or not. 0: will be used, -EXXX will not be used.
  123. * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled.
  124. *
  125. * lockspace: handle for dlm functions
  126. */
  127. int dlm_new_lockspace(const char *name, const char *cluster,
  128. uint32_t flags, int lvblen,
  129. const struct dlm_lockspace_ops *ops, void *ops_arg,
  130. int *ops_result, dlm_lockspace_t **lockspace);
  131. /*
  132. * dlm_release_lockspace
  133. *
  134. * Stop a lockspace.
  135. */
  136. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  137. /*
  138. * dlm_lock
  139. *
  140. * Make an asyncronous request to acquire or convert a lock on a named
  141. * resource.
  142. *
  143. * lockspace: context for the request
  144. * mode: the requested mode of the lock (DLM_LOCK_)
  145. * lksb: lock status block for input and async return values
  146. * flags: input flags (DLM_LKF_)
  147. * name: name of the resource to lock, can be binary
  148. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  149. * parent: the lock ID of a parent lock or 0 if none
  150. * lockast: function DLM executes when it completes processing the request
  151. * astarg: argument passed to lockast and bast functions
  152. * bast: function DLM executes when this lock later blocks another request
  153. *
  154. * Returns:
  155. * 0 if request is successfully queued for processing
  156. * -EINVAL if any input parameters are invalid
  157. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  158. * -ENOMEM if there is no memory to process request
  159. * -ENOTCONN if there is a communication error
  160. *
  161. * If the call to dlm_lock returns an error then the operation has failed and
  162. * the AST routine will not be called. If dlm_lock returns 0 it is still
  163. * possible that the lock operation will fail. The AST routine will be called
  164. * when the locking is complete and the status is returned in the lksb.
  165. *
  166. * If the AST routines or parameter are passed to a conversion operation then
  167. * they will overwrite those values that were passed to a previous dlm_lock
  168. * call.
  169. *
  170. * AST routines should not block (at least not for long), but may make
  171. * any locking calls they please.
  172. */
  173. int dlm_lock(dlm_lockspace_t *lockspace,
  174. int mode,
  175. struct dlm_lksb *lksb,
  176. uint32_t flags,
  177. void *name,
  178. unsigned int namelen,
  179. uint32_t parent_lkid,
  180. void (*lockast) (void *astarg),
  181. void *astarg,
  182. void (*bast) (void *astarg, int mode));
  183. /*
  184. * dlm_unlock
  185. *
  186. * Asynchronously release a lock on a resource. The AST routine is called
  187. * when the resource is successfully unlocked.
  188. *
  189. * lockspace: context for the request
  190. * lkid: the lock ID as returned in the lksb
  191. * flags: input flags (DLM_LKF_)
  192. * lksb: if NULL the lksb parameter passed to last lock request is used
  193. * astarg: the arg used with the completion ast for the unlock
  194. *
  195. * Returns:
  196. * 0 if request is successfully queued for processing
  197. * -EINVAL if any input parameters are invalid
  198. * -ENOTEMPTY if the lock still has sublocks
  199. * -EBUSY if the lock is waiting for a remote lock operation
  200. * -ENOTCONN if there is a communication error
  201. */
  202. int dlm_unlock(dlm_lockspace_t *lockspace,
  203. uint32_t lkid,
  204. uint32_t flags,
  205. struct dlm_lksb *lksb,
  206. void *astarg);
  207. #endif /* __KERNEL__ */
  208. #endif /* __DLM_DOT_H__ */