dlm.h 5.5 KB

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