dlm.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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_FS
  54. * The lockspace user is in the kernel (i.e. filesystem). Enables
  55. * direct bast/cast callbacks.
  56. * DLM_LSFL_NEWEXCL
  57. * dlm_new_lockspace() should return -EEXIST if the lockspace exists.
  58. *
  59. * lvblen: length of lvb in bytes. Must be multiple of 8.
  60. * dlm_new_lockspace() returns an error if this does not match
  61. * what other nodes are using.
  62. *
  63. * ops: callbacks that indicate lockspace recovery points so the
  64. * caller can coordinate its recovery and know lockspace members.
  65. * This is only used by the initial dlm_new_lockspace() call.
  66. * Optional.
  67. *
  68. * ops_arg: arg for ops callbacks.
  69. *
  70. * ops_result: tells caller if the ops callbacks (if provided) will
  71. * be used or not. 0: will be used, -EXXX will not be used.
  72. * -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled.
  73. *
  74. * lockspace: handle for dlm functions
  75. */
  76. int dlm_new_lockspace(const char *name, const char *cluster,
  77. uint32_t flags, int lvblen,
  78. const struct dlm_lockspace_ops *ops, void *ops_arg,
  79. int *ops_result, dlm_lockspace_t **lockspace);
  80. /*
  81. * dlm_release_lockspace
  82. *
  83. * Stop a lockspace.
  84. */
  85. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  86. /*
  87. * dlm_lock
  88. *
  89. * Make an asynchronous request to acquire or convert a lock on a named
  90. * resource.
  91. *
  92. * lockspace: context for the request
  93. * mode: the requested mode of the lock (DLM_LOCK_)
  94. * lksb: lock status block for input and async return values
  95. * flags: input flags (DLM_LKF_)
  96. * name: name of the resource to lock, can be binary
  97. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  98. * parent: the lock ID of a parent lock or 0 if none
  99. * lockast: function DLM executes when it completes processing the request
  100. * astarg: argument passed to lockast and bast functions
  101. * bast: function DLM executes when this lock later blocks another request
  102. *
  103. * Returns:
  104. * 0 if request is successfully queued for processing
  105. * -EINVAL if any input parameters are invalid
  106. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  107. * -ENOMEM if there is no memory to process request
  108. * -ENOTCONN if there is a communication error
  109. *
  110. * If the call to dlm_lock returns an error then the operation has failed and
  111. * the AST routine will not be called. If dlm_lock returns 0 it is still
  112. * possible that the lock operation will fail. The AST routine will be called
  113. * when the locking is complete and the status is returned in the lksb.
  114. *
  115. * If the AST routines or parameter are passed to a conversion operation then
  116. * they will overwrite those values that were passed to a previous dlm_lock
  117. * call.
  118. *
  119. * AST routines should not block (at least not for long), but may make
  120. * any locking calls they please.
  121. */
  122. int dlm_lock(dlm_lockspace_t *lockspace,
  123. int mode,
  124. struct dlm_lksb *lksb,
  125. uint32_t flags,
  126. void *name,
  127. unsigned int namelen,
  128. uint32_t parent_lkid,
  129. void (*lockast) (void *astarg),
  130. void *astarg,
  131. void (*bast) (void *astarg, int mode));
  132. /*
  133. * dlm_unlock
  134. *
  135. * Asynchronously release a lock on a resource. The AST routine is called
  136. * when the resource is successfully unlocked.
  137. *
  138. * lockspace: context for the request
  139. * lkid: the lock ID as returned in the lksb
  140. * flags: input flags (DLM_LKF_)
  141. * lksb: if NULL the lksb parameter passed to last lock request is used
  142. * astarg: the arg used with the completion ast for the unlock
  143. *
  144. * Returns:
  145. * 0 if request is successfully queued for processing
  146. * -EINVAL if any input parameters are invalid
  147. * -ENOTEMPTY if the lock still has sublocks
  148. * -EBUSY if the lock is waiting for a remote lock operation
  149. * -ENOTCONN if there is a communication error
  150. */
  151. int dlm_unlock(dlm_lockspace_t *lockspace,
  152. uint32_t lkid,
  153. uint32_t flags,
  154. struct dlm_lksb *lksb,
  155. void *astarg);
  156. #endif /* __DLM_DOT_H__ */