blob: 55df0728bc88db5948a46295072958e5be928e5d [file] [log] [blame]
Philipp Reisnerb8907332011-01-27 14:07:51 +01001#ifndef DRBD_STATE_H
2#define DRBD_STATE_H
3
4struct drbd_conf;
Philipp Reisnerbbeb6412011-02-10 13:45:46 +01005struct drbd_tconn;
Philipp Reisnerb8907332011-01-27 14:07:51 +01006
7/**
8 * DOC: DRBD State macros
9 *
10 * These macros are used to express state changes in easily readable form.
11 *
12 * The NS macros expand to a mask and a value, that can be bit ored onto the
13 * current state as soon as the spinlock (req_lock) was taken.
14 *
15 * The _NS macros are used for state functions that get called with the
16 * spinlock. These macros expand directly to the new state value.
17 *
18 * Besides the basic forms NS() and _NS() additional _?NS[23] are defined
19 * to express state changes that affect more than one aspect of the state.
20 *
21 * E.g. NS2(conn, C_CONNECTED, peer, R_SECONDARY)
22 * Means that the network connection was established and that the peer
23 * is in secondary role.
24 */
25#define role_MASK R_MASK
26#define peer_MASK R_MASK
27#define disk_MASK D_MASK
28#define pdsk_MASK D_MASK
29#define conn_MASK C_MASK
30#define susp_MASK 1
31#define user_isp_MASK 1
32#define aftr_isp_MASK 1
33#define susp_nod_MASK 1
34#define susp_fen_MASK 1
35
36#define NS(T, S) \
37 ({ union drbd_state mask; mask.i = 0; mask.T = T##_MASK; mask; }), \
38 ({ union drbd_state val; val.i = 0; val.T = (S); val; })
39#define NS2(T1, S1, T2, S2) \
40 ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
41 mask.T2 = T2##_MASK; mask; }), \
42 ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
43 val.T2 = (S2); val; })
44#define NS3(T1, S1, T2, S2, T3, S3) \
45 ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
46 mask.T2 = T2##_MASK; mask.T3 = T3##_MASK; mask; }), \
47 ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
48 val.T2 = (S2); val.T3 = (S3); val; })
49
50#define _NS(D, T, S) \
51 D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T = (S); __ns; })
52#define _NS2(D, T1, S1, T2, S2) \
53 D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \
54 __ns.T2 = (S2); __ns; })
55#define _NS3(D, T1, S1, T2, S2, T3, S3) \
56 D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \
57 __ns.T2 = (S2); __ns.T3 = (S3); __ns; })
58
59enum chg_state_flags {
60 CS_HARD = 1,
61 CS_VERBOSE = 2,
62 CS_WAIT_COMPLETE = 4,
63 CS_SERIALIZE = 8,
64 CS_ORDERED = CS_WAIT_COMPLETE + CS_SERIALIZE,
Philipp Reisnerbbeb6412011-02-10 13:45:46 +010065 CS_NO_CSTATE_CHG = 16, /* Do not display changes in cstate. Internal to drbd_state.c */
Philipp Reisner047cd4a2011-02-15 11:09:33 +010066 CS_LOCAL_ONLY = 32, /* Do not consider a device pair wide state change */
Philipp Reisnerb8907332011-01-27 14:07:51 +010067};
68
69extern enum drbd_state_rv drbd_change_state(struct drbd_conf *mdev,
70 enum chg_state_flags f,
71 union drbd_state mask,
72 union drbd_state val);
73extern void drbd_force_state(struct drbd_conf *, union drbd_state,
74 union drbd_state);
75extern enum drbd_state_rv _drbd_request_state(struct drbd_conf *,
76 union drbd_state,
77 union drbd_state,
78 enum chg_state_flags);
79extern enum drbd_state_rv __drbd_set_state(struct drbd_conf *, union drbd_state,
80 enum chg_state_flags,
81 struct completion *done);
82extern void print_st_err(struct drbd_conf *, union drbd_state,
83 union drbd_state, int);
84
Philipp Reisnerbbeb6412011-02-10 13:45:46 +010085enum drbd_state_rv
86_conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
87 enum chg_state_flags flags);
88
89enum drbd_state_rv
90conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
91 enum chg_state_flags flags);
92
Philipp Reisnerb8907332011-01-27 14:07:51 +010093extern void drbd_resume_al(struct drbd_conf *mdev);
Lars Ellenbergd0456c72011-03-10 23:28:13 +010094extern bool conn_all_vols_unconf(struct drbd_tconn *tconn);
Philipp Reisnerb8907332011-01-27 14:07:51 +010095
96/**
97 * drbd_request_state() - Reqest a state change
98 * @mdev: DRBD device.
99 * @mask: mask of state bits to change.
100 * @val: value of new state bits.
101 *
102 * This is the most graceful way of requesting a state change. It is verbose
103 * quite verbose in case the state change is not possible, and all those
104 * state changes are globally serialized.
105 */
106static inline int drbd_request_state(struct drbd_conf *mdev,
107 union drbd_state mask,
108 union drbd_state val)
109{
110 return _drbd_request_state(mdev, mask, val, CS_VERBOSE + CS_ORDERED);
111}
112
113#endif