dlm.h 5.8 KB

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