dlm.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2007 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. #define DLM_RESNAME_MAXLEN 64
  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. * -ENOMEM if there is no memory to process request
  47. * -EINVAL if there are invalid parameters
  48. * -DLM_EUNLOCK if unlock request was successful
  49. * -DLM_ECANCEL if a cancel completed successfully
  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. uint32_t sb_lkid;
  57. char sb_flags;
  58. char * sb_lvbptr;
  59. };
  60. #define DLM_LSFL_NODIR 0x00000001
  61. #define DLM_LSFL_TIMEWARN 0x00000002
  62. #define DLM_LSFL_FS 0x00000004
  63. #ifdef __KERNEL__
  64. /*
  65. * dlm_new_lockspace
  66. *
  67. * Starts a lockspace with the given name. If the named lockspace exists in
  68. * the cluster, the calling node joins it.
  69. */
  70. int dlm_new_lockspace(char *name, int namelen, dlm_lockspace_t **lockspace,
  71. uint32_t flags, int lvblen);
  72. /*
  73. * dlm_release_lockspace
  74. *
  75. * Stop a lockspace.
  76. */
  77. int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  78. /*
  79. * dlm_lock
  80. *
  81. * Make an asyncronous request to acquire or convert a lock on a named
  82. * resource.
  83. *
  84. * lockspace: context for the request
  85. * mode: the requested mode of the lock (DLM_LOCK_)
  86. * lksb: lock status block for input and async return values
  87. * flags: input flags (DLM_LKF_)
  88. * name: name of the resource to lock, can be binary
  89. * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
  90. * parent: the lock ID of a parent lock or 0 if none
  91. * lockast: function DLM executes when it completes processing the request
  92. * astarg: argument passed to lockast and bast functions
  93. * bast: function DLM executes when this lock later blocks another request
  94. *
  95. * Returns:
  96. * 0 if request is successfully queued for processing
  97. * -EINVAL if any input parameters are invalid
  98. * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
  99. * -ENOMEM if there is no memory to process request
  100. * -ENOTCONN if there is a communication error
  101. *
  102. * If the call to dlm_lock returns an error then the operation has failed and
  103. * the AST routine will not be called. If dlm_lock returns 0 it is still
  104. * possible that the lock operation will fail. The AST routine will be called
  105. * when the locking is complete and the status is returned in the lksb.
  106. *
  107. * If the AST routines or parameter are passed to a conversion operation then
  108. * they will overwrite those values that were passed to a previous dlm_lock
  109. * call.
  110. *
  111. * AST routines should not block (at least not for long), but may make
  112. * any locking calls they please.
  113. */
  114. int dlm_lock(dlm_lockspace_t *lockspace,
  115. int mode,
  116. struct dlm_lksb *lksb,
  117. uint32_t flags,
  118. void *name,
  119. unsigned int namelen,
  120. uint32_t parent_lkid,
  121. void (*lockast) (void *astarg),
  122. void *astarg,
  123. void (*bast) (void *astarg, int mode));
  124. /*
  125. * dlm_unlock
  126. *
  127. * Asynchronously release a lock on a resource. The AST routine is called
  128. * when the resource is successfully unlocked.
  129. *
  130. * lockspace: context for the request
  131. * lkid: the lock ID as returned in the lksb
  132. * flags: input flags (DLM_LKF_)
  133. * lksb: if NULL the lksb parameter passed to last lock request is used
  134. * astarg: the arg used with the completion ast for the unlock
  135. *
  136. * Returns:
  137. * 0 if request is successfully queued for processing
  138. * -EINVAL if any input parameters are invalid
  139. * -ENOTEMPTY if the lock still has sublocks
  140. * -EBUSY if the lock is waiting for a remote lock operation
  141. * -ENOTCONN if there is a communication error
  142. */
  143. int dlm_unlock(dlm_lockspace_t *lockspace,
  144. uint32_t lkid,
  145. uint32_t flags,
  146. struct dlm_lksb *lksb,
  147. void *astarg);
  148. #endif /* __KERNEL__ */
  149. #endif /* __DLM_DOT_H__ */