drbd_state.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef DRBD_STATE_H
  2. #define DRBD_STATE_H
  3. struct drbd_device;
  4. struct drbd_connection;
  5. /**
  6. * DOC: DRBD State macros
  7. *
  8. * These macros are used to express state changes in easily readable form.
  9. *
  10. * The NS macros expand to a mask and a value, that can be bit ored onto the
  11. * current state as soon as the spinlock (req_lock) was taken.
  12. *
  13. * The _NS macros are used for state functions that get called with the
  14. * spinlock. These macros expand directly to the new state value.
  15. *
  16. * Besides the basic forms NS() and _NS() additional _?NS[23] are defined
  17. * to express state changes that affect more than one aspect of the state.
  18. *
  19. * E.g. NS2(conn, C_CONNECTED, peer, R_SECONDARY)
  20. * Means that the network connection was established and that the peer
  21. * is in secondary role.
  22. */
  23. #define role_MASK R_MASK
  24. #define peer_MASK R_MASK
  25. #define disk_MASK D_MASK
  26. #define pdsk_MASK D_MASK
  27. #define conn_MASK C_MASK
  28. #define susp_MASK 1
  29. #define user_isp_MASK 1
  30. #define aftr_isp_MASK 1
  31. #define susp_nod_MASK 1
  32. #define susp_fen_MASK 1
  33. #define NS(T, S) \
  34. ({ union drbd_state mask; mask.i = 0; mask.T = T##_MASK; mask; }), \
  35. ({ union drbd_state val; val.i = 0; val.T = (S); val; })
  36. #define NS2(T1, S1, T2, S2) \
  37. ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
  38. mask.T2 = T2##_MASK; mask; }), \
  39. ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
  40. val.T2 = (S2); val; })
  41. #define NS3(T1, S1, T2, S2, T3, S3) \
  42. ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
  43. mask.T2 = T2##_MASK; mask.T3 = T3##_MASK; mask; }), \
  44. ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
  45. val.T2 = (S2); val.T3 = (S3); val; })
  46. #define _NS(D, T, S) \
  47. D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T = (S); __ns; })
  48. #define _NS2(D, T1, S1, T2, S2) \
  49. D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T1 = (S1); \
  50. __ns.T2 = (S2); __ns; })
  51. #define _NS3(D, T1, S1, T2, S2, T3, S3) \
  52. D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T1 = (S1); \
  53. __ns.T2 = (S2); __ns.T3 = (S3); __ns; })
  54. enum chg_state_flags {
  55. CS_HARD = 1 << 0,
  56. CS_VERBOSE = 1 << 1,
  57. CS_WAIT_COMPLETE = 1 << 2,
  58. CS_SERIALIZE = 1 << 3,
  59. CS_ORDERED = CS_WAIT_COMPLETE + CS_SERIALIZE,
  60. CS_LOCAL_ONLY = 1 << 4, /* Do not consider a device pair wide state change */
  61. CS_DC_ROLE = 1 << 5, /* DC = display as connection state change */
  62. CS_DC_PEER = 1 << 6,
  63. CS_DC_CONN = 1 << 7,
  64. CS_DC_DISK = 1 << 8,
  65. CS_DC_PDSK = 1 << 9,
  66. CS_DC_SUSP = 1 << 10,
  67. CS_DC_MASK = CS_DC_ROLE + CS_DC_PEER + CS_DC_CONN + CS_DC_DISK + CS_DC_PDSK,
  68. CS_IGN_OUTD_FAIL = 1 << 11,
  69. };
  70. /* drbd_dev_state and drbd_state are different types. This is to stress the
  71. small difference. There is no suspended flag (.susp), and no suspended
  72. while fence handler runs flas (susp_fen). */
  73. union drbd_dev_state {
  74. struct {
  75. #if defined(__LITTLE_ENDIAN_BITFIELD)
  76. unsigned role:2 ; /* 3/4 primary/secondary/unknown */
  77. unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
  78. unsigned conn:5 ; /* 17/32 cstates */
  79. unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  80. unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  81. unsigned _unused:1 ;
  82. unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
  83. unsigned peer_isp:1 ;
  84. unsigned user_isp:1 ;
  85. unsigned _pad:11; /* 0 unused */
  86. #elif defined(__BIG_ENDIAN_BITFIELD)
  87. unsigned _pad:11;
  88. unsigned user_isp:1 ;
  89. unsigned peer_isp:1 ;
  90. unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
  91. unsigned _unused:1 ;
  92. unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  93. unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  94. unsigned conn:5 ; /* 17/32 cstates */
  95. unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
  96. unsigned role:2 ; /* 3/4 primary/secondary/unknown */
  97. #else
  98. # error "this endianess is not supported"
  99. #endif
  100. };
  101. unsigned int i;
  102. };
  103. extern enum drbd_state_rv drbd_change_state(struct drbd_device *device,
  104. enum chg_state_flags f,
  105. union drbd_state mask,
  106. union drbd_state val);
  107. extern void drbd_force_state(struct drbd_device *, union drbd_state,
  108. union drbd_state);
  109. extern enum drbd_state_rv _drbd_request_state(struct drbd_device *,
  110. union drbd_state,
  111. union drbd_state,
  112. enum chg_state_flags);
  113. extern enum drbd_state_rv
  114. _drbd_request_state_holding_state_mutex(struct drbd_device *, union drbd_state,
  115. union drbd_state, enum chg_state_flags);
  116. extern enum drbd_state_rv _drbd_set_state(struct drbd_device *, union drbd_state,
  117. enum chg_state_flags,
  118. struct completion *done);
  119. extern void print_st_err(struct drbd_device *, union drbd_state,
  120. union drbd_state, int);
  121. enum drbd_state_rv
  122. _conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
  123. enum chg_state_flags flags);
  124. enum drbd_state_rv
  125. conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
  126. enum chg_state_flags flags);
  127. extern void drbd_resume_al(struct drbd_device *device);
  128. extern bool conn_all_vols_unconf(struct drbd_connection *connection);
  129. /**
  130. * drbd_request_state() - Request a state change
  131. * @device: DRBD device.
  132. * @mask: mask of state bits to change.
  133. * @val: value of new state bits.
  134. *
  135. * This is the most graceful way of requesting a state change. It is verbose
  136. * quite verbose in case the state change is not possible, and all those
  137. * state changes are globally serialized.
  138. */
  139. static inline int drbd_request_state(struct drbd_device *device,
  140. union drbd_state mask,
  141. union drbd_state val)
  142. {
  143. return _drbd_request_state(device, mask, val, CS_VERBOSE + CS_ORDERED);
  144. }
  145. enum drbd_role conn_highest_role(struct drbd_connection *connection);
  146. enum drbd_role conn_highest_peer(struct drbd_connection *connection);
  147. enum drbd_disk_state conn_highest_disk(struct drbd_connection *connection);
  148. enum drbd_disk_state conn_lowest_disk(struct drbd_connection *connection);
  149. enum drbd_disk_state conn_highest_pdsk(struct drbd_connection *connection);
  150. enum drbd_conns conn_lowest_conn(struct drbd_connection *connection);
  151. #endif