drbd_state.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef DRBD_STATE_H
  2. #define DRBD_STATE_H
  3. struct drbd_conf;
  4. struct drbd_tconn;
  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.i = D->state.i; __ns.T = (S); __ns; })
  48. #define _NS2(D, T1, S1, T2, S2) \
  49. D, ({ union drbd_state __ns; __ns.i = D->state.i; __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.i = D->state.i; __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_MASK = CS_DC_ROLE + CS_DC_PEER + CS_DC_CONN + CS_DC_DISK + CS_DC_PDSK,
  67. };
  68. extern enum drbd_state_rv drbd_change_state(struct drbd_conf *mdev,
  69. enum chg_state_flags f,
  70. union drbd_state mask,
  71. union drbd_state val);
  72. extern void drbd_force_state(struct drbd_conf *, union drbd_state,
  73. union drbd_state);
  74. extern enum drbd_state_rv _drbd_request_state(struct drbd_conf *,
  75. union drbd_state,
  76. union drbd_state,
  77. enum chg_state_flags);
  78. extern enum drbd_state_rv __drbd_set_state(struct drbd_conf *, union drbd_state,
  79. enum chg_state_flags,
  80. struct completion *done);
  81. extern void print_st_err(struct drbd_conf *, union drbd_state,
  82. union drbd_state, int);
  83. enum drbd_state_rv
  84. _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
  85. enum chg_state_flags flags);
  86. enum drbd_state_rv
  87. conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
  88. enum chg_state_flags flags);
  89. extern void drbd_resume_al(struct drbd_conf *mdev);
  90. extern bool conn_all_vols_unconf(struct drbd_tconn *tconn);
  91. /**
  92. * drbd_request_state() - Reqest a state change
  93. * @mdev: DRBD device.
  94. * @mask: mask of state bits to change.
  95. * @val: value of new state bits.
  96. *
  97. * This is the most graceful way of requesting a state change. It is verbose
  98. * quite verbose in case the state change is not possible, and all those
  99. * state changes are globally serialized.
  100. */
  101. static inline int drbd_request_state(struct drbd_conf *mdev,
  102. union drbd_state mask,
  103. union drbd_state val)
  104. {
  105. return _drbd_request_state(mdev, mask, val, CS_VERBOSE + CS_ORDERED);
  106. }
  107. enum drbd_role conn_highest_role(struct drbd_tconn *tconn);
  108. enum drbd_role conn_highest_peer(struct drbd_tconn *tconn);
  109. enum drbd_disk_state conn_highest_disk(struct drbd_tconn *tconn);
  110. enum drbd_disk_state conn_highest_pdsk(struct drbd_tconn *tconn);
  111. #endif