dlm.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #include <uapi/linux/dlm.h>
  16. struct dlm_slot {
  17. int nodeid; /* 1 to MAX_INT */
  18. int slot; /* 1 to MAX_INT */
  19. };
  20. /*
  21. * recover_prep: called before the dlm begins lock recovery.
  22. * Notfies lockspace user that locks from failed members will be granted.
  23. * recover_slot: called after recover_prep and before recover_done.
  24. * Identifies a failed lockspace member.
  25. * recover_done: called after the dlm completes lock recovery.
  26. * Identifies lockspace members and lockspace generation number.
  27. */
  28. struct dlm_lockspace_ops {
  29. void (*recover_prep) (void *ops_arg);
  30. void (*recover_slot) (void *ops_arg, struct dlm_slot *slot);
  31. void (*recover_done) (void *ops_arg, struct dlm_slot *slots,
  32. int num_slots, int our_slot, uint32_t generation);
  33. };
  34. /*
  35. * dlm_new_lockspace
  36. *
  37. * Create/join a lockspace.
  38. *
  39. * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not
  40. * including terminating null).
  41. *
  42. * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not
  43. * including terminating null). Optional. When cluster is null, it
  44. * is not used. When set, dlm_new_lockspace() returns -EBADR if cluster
  45. * is not equal to the dlm cluster name.
  46. *
  47. * flags:
  48. * DLM_LSFL_NODIR
  49. * The dlm should not use a resource directory, but statically assign
  50. * resource mastery to nodes based on the name hash that is otherwise
  51. * used to select the directory node. Must be the same on all nodes.
  52. * DLM_LSFL_TIMEWARN
  53. * The dlm should emit netlink messages if locks have been waiting
  54. * for a configurable amount of time. (Unused.)
  55. * DLM_LSFL_FS
  56. * The lockspace user is in the kernel (i.e. filesystem). Enables
  57. * direct bast/cast callbacks.
  58. * DLM_LSFL_NEWEXCL
  59. * dlm_new_lockspace() should return -EEXIST if the lockspace exists.
  60. *
  61. * lvblen: length of lvb in bytes. Must be multiple of 8.
  62. * dlm_new_lockspace() returns an error if this does not match
  63. * what other nodes are using.
  64. *
  65. * ops: callbacks that indicate lockspace recovery points so the
  66. * caller can coordinate its recovery and know lockspace members.
  67. * This is only used by the initial dlm_new_lockspace() call.
  68. * Optional.
  69. *
  70. * ops_arg: arg for ops callbacks.
  71. *
  72. * ops_result: tells caller if the ops callbacks (if provided) will
  73. * be used or not. 0: will be used, -EXXX will not be used.
  74. * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled.
  75. *
  76. * lockspace: handle for dlm functions
  77. */
  78. int dlm_new_lockspace(const char *name, const char *cluster,
  79. uint32_t flags, int lvblen,
  80. const struct dlm_lockspace_ops *ops, void *ops_arg,
  81. int *ops_result, dlm_lockspace_t **lockspace);
  82. /*
  83. * dlm_release_lockspace
  84. *
  85. * Stop a lockspace.
  86. */
  87. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  88. /*
  89. * dlm_lock
  90. *
  91. * Make an asynchronous request to acquire or convert a lock on a named
  92. * resource.
  93. *
  94. * lockspace: context for the request
  95. * mode: the requested mode of the lock (DLM_LOCK_)
  96. * lksb: lock status block for input and async return values
  97. * flags: input flags (DLM_LKF_)
  98. * name: name of the resource to lock, can be binary
  99. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  100. * parent: the lock ID of a parent lock or 0 if none
  101. * lockast: function DLM executes when it completes processing the request
  102. * astarg: argument passed to lockast and bast functions
  103. * bast: function DLM executes when this lock later blocks another request
  104. *
  105. * Returns:
  106. * 0 if request is successfully queued for processing
  107. * -EINVAL if any input parameters are invalid
  108. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  109. * -ENOMEM if there is no memory to process request
  110. * -ENOTCONN if there is a communication error
  111. *
  112. * If the call to dlm_lock returns an error then the operation has failed and
  113. * the AST routine will not be called. If dlm_lock returns 0 it is still
  114. * possible that the lock operation will fail. The AST routine will be called
  115. * when the locking is complete and the status is returned in the lksb.
  116. *
  117. * If the AST routines or parameter are passed to a conversion operation then
  118. * they will overwrite those values that were passed to a previous dlm_lock
  119. * call.
  120. *
  121. * AST routines should not block (at least not for long), but may make
  122. * any locking calls they please.
  123. */
  124. int dlm_lock(dlm_lockspace_t *lockspace,
  125. int mode,
  126. struct dlm_lksb *lksb,
  127. uint32_t flags,
  128. void *name,
  129. unsigned int namelen,
  130. uint32_t parent_lkid,
  131. void (*lockast) (void *astarg),
  132. void *astarg,
  133. void (*bast) (void *astarg, int mode));
  134. /*
  135. * dlm_unlock
  136. *
  137. * Asynchronously release a lock on a resource. The AST routine is called
  138. * when the resource is successfully unlocked.
  139. *
  140. * lockspace: context for the request
  141. * lkid: the lock ID as returned in the lksb
  142. * flags: input flags (DLM_LKF_)
  143. * lksb: if NULL the lksb parameter passed to last lock request is used
  144. * astarg: the arg used with the completion ast for the unlock
  145. *
  146. * Returns:
  147. * 0 if request is successfully queued for processing
  148. * -EINVAL if any input parameters are invalid
  149. * -ENOTEMPTY if the lock still has sublocks
  150. * -EBUSY if the lock is waiting for a remote lock operation
  151. * -ENOTCONN if there is a communication error
  152. */
  153. int dlm_unlock(dlm_lockspace_t *lockspace,
  154. uint32_t lkid,
  155. uint32_t flags,
  156. struct dlm_lksb *lksb,
  157. void *astarg);
  158. #endif /* __DLM_DOT_H__ */