drbd_state.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef DRBD_STATE_H
  2. #define DRBD_STATE_H
  3. struct drbd_conf;
  4. /**
  5. * DOC: DRBD State macros
  6. *
  7. * These macros are used to express state changes in easily readable form.
  8. *
  9. * The NS macros expand to a mask and a value, that can be bit ored onto the
  10. * current state as soon as the spinlock (req_lock) was taken.
  11. *
  12. * The _NS macros are used for state functions that get called with the
  13. * spinlock. These macros expand directly to the new state value.
  14. *
  15. * Besides the basic forms NS() and _NS() additional _?NS[23] are defined
  16. * to express state changes that affect more than one aspect of the state.
  17. *
  18. * E.g. NS2(conn, C_CONNECTED, peer, R_SECONDARY)
  19. * Means that the network connection was established and that the peer
  20. * is in secondary role.
  21. */
  22. #define role_MASK R_MASK
  23. #define peer_MASK R_MASK
  24. #define disk_MASK D_MASK
  25. #define pdsk_MASK D_MASK
  26. #define conn_MASK C_MASK
  27. #define susp_MASK 1
  28. #define user_isp_MASK 1
  29. #define aftr_isp_MASK 1
  30. #define susp_nod_MASK 1
  31. #define susp_fen_MASK 1
  32. #define NS(T, S) \
  33. ({ union drbd_state mask; mask.i = 0; mask.T = T##_MASK; mask; }), \
  34. ({ union drbd_state val; val.i = 0; val.T = (S); val; })
  35. #define NS2(T1, S1, T2, S2) \
  36. ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
  37. mask.T2 = T2##_MASK; mask; }), \
  38. ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
  39. val.T2 = (S2); val; })
  40. #define NS3(T1, S1, T2, S2, T3, S3) \
  41. ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
  42. mask.T2 = T2##_MASK; mask.T3 = T3##_MASK; mask; }), \
  43. ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
  44. val.T2 = (S2); val.T3 = (S3); val; })
  45. #define _NS(D, T, S) \
  46. D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T = (S); __ns; })
  47. #define _NS2(D, T1, S1, T2, S2) \
  48. D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \
  49. __ns.T2 = (S2); __ns; })
  50. #define _NS3(D, T1, S1, T2, S2, T3, S3) \
  51. D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \
  52. __ns.T2 = (S2); __ns.T3 = (S3); __ns; })
  53. enum chg_state_flags {
  54. CS_HARD = 1,
  55. CS_VERBOSE = 2,
  56. CS_WAIT_COMPLETE = 4,
  57. CS_SERIALIZE = 8,
  58. CS_ORDERED = CS_WAIT_COMPLETE + CS_SERIALIZE,
  59. };
  60. extern enum drbd_state_rv drbd_change_state(struct drbd_conf *mdev,
  61. enum chg_state_flags f,
  62. union drbd_state mask,
  63. union drbd_state val);
  64. extern void drbd_force_state(struct drbd_conf *, union drbd_state,
  65. union drbd_state);
  66. extern enum drbd_state_rv _drbd_request_state(struct drbd_conf *,
  67. union drbd_state,
  68. union drbd_state,
  69. enum chg_state_flags);
  70. extern enum drbd_state_rv __drbd_set_state(struct drbd_conf *, union drbd_state,
  71. enum chg_state_flags,
  72. struct completion *done);
  73. extern void print_st_err(struct drbd_conf *, union drbd_state,
  74. union drbd_state, int);
  75. extern void drbd_resume_al(struct drbd_conf *mdev);
  76. /**
  77. * drbd_request_state() - Reqest a state change
  78. * @mdev: DRBD device.
  79. * @mask: mask of state bits to change.
  80. * @val: value of new state bits.
  81. *
  82. * This is the most graceful way of requesting a state change. It is verbose
  83. * quite verbose in case the state change is not possible, and all those
  84. * state changes are globally serialized.
  85. */
  86. static inline int drbd_request_state(struct drbd_conf *mdev,
  87. union drbd_state mask,
  88. union drbd_state val)
  89. {
  90. return _drbd_request_state(mdev, mask, val, CS_VERBOSE + CS_ORDERED);
  91. }
  92. #endif