Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef DRBD_STATE_H
0003 #define DRBD_STATE_H
0004 
0005 struct drbd_device;
0006 struct drbd_connection;
0007 
0008 /**
0009  * DOC: DRBD State macros
0010  *
0011  * These macros are used to express state changes in easily readable form.
0012  *
0013  * The NS macros expand to a mask and a value, that can be bit ored onto the
0014  * current state as soon as the spinlock (req_lock) was taken.
0015  *
0016  * The _NS macros are used for state functions that get called with the
0017  * spinlock. These macros expand directly to the new state value.
0018  *
0019  * Besides the basic forms NS() and _NS() additional _?NS[23] are defined
0020  * to express state changes that affect more than one aspect of the state.
0021  *
0022  * E.g. NS2(conn, C_CONNECTED, peer, R_SECONDARY)
0023  * Means that the network connection was established and that the peer
0024  * is in secondary role.
0025  */
0026 #define role_MASK R_MASK
0027 #define peer_MASK R_MASK
0028 #define disk_MASK D_MASK
0029 #define pdsk_MASK D_MASK
0030 #define conn_MASK C_MASK
0031 #define susp_MASK 1
0032 #define user_isp_MASK 1
0033 #define aftr_isp_MASK 1
0034 #define susp_nod_MASK 1
0035 #define susp_fen_MASK 1
0036 
0037 #define NS(T, S) \
0038     ({ union drbd_state mask; mask.i = 0; mask.T = T##_MASK; mask; }), \
0039     ({ union drbd_state val; val.i = 0; val.T = (S); val; })
0040 #define NS2(T1, S1, T2, S2) \
0041     ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
0042       mask.T2 = T2##_MASK; mask; }), \
0043     ({ union drbd_state val; val.i = 0; val.T1 = (S1); \
0044       val.T2 = (S2); val; })
0045 #define NS3(T1, S1, T2, S2, T3, S3) \
0046     ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \
0047       mask.T2 = T2##_MASK; mask.T3 = T3##_MASK; mask; }), \
0048     ({ union drbd_state val;  val.i = 0; val.T1 = (S1); \
0049       val.T2 = (S2); val.T3 = (S3); val; })
0050 
0051 #define _NS(D, T, S) \
0052     D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T = (S); __ns; })
0053 #define _NS2(D, T1, S1, T2, S2) \
0054     D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T1 = (S1); \
0055     __ns.T2 = (S2); __ns; })
0056 #define _NS3(D, T1, S1, T2, S2, T3, S3) \
0057     D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T1 = (S1); \
0058     __ns.T2 = (S2); __ns.T3 = (S3); __ns; })
0059 
0060 enum chg_state_flags {
0061     CS_HARD          = 1 << 0,
0062     CS_VERBOSE       = 1 << 1,
0063     CS_WAIT_COMPLETE = 1 << 2,
0064     CS_SERIALIZE     = 1 << 3,
0065     CS_ORDERED       = CS_WAIT_COMPLETE + CS_SERIALIZE,
0066     CS_LOCAL_ONLY    = 1 << 4, /* Do not consider a device pair wide state change */
0067     CS_DC_ROLE       = 1 << 5, /* DC = display as connection state change */
0068     CS_DC_PEER       = 1 << 6,
0069     CS_DC_CONN       = 1 << 7,
0070     CS_DC_DISK       = 1 << 8,
0071     CS_DC_PDSK       = 1 << 9,
0072     CS_DC_SUSP       = 1 << 10,
0073     CS_DC_MASK       = CS_DC_ROLE + CS_DC_PEER + CS_DC_CONN + CS_DC_DISK + CS_DC_PDSK,
0074     CS_IGN_OUTD_FAIL = 1 << 11,
0075 
0076     /* Make sure no meta data IO is in flight, by calling
0077      * drbd_md_get_buffer().  Used for graceful detach. */
0078     CS_INHIBIT_MD_IO = 1 << 12,
0079 };
0080 
0081 /* drbd_dev_state and drbd_state are different types. This is to stress the
0082    small difference. There is no suspended flag (.susp), and no suspended
0083    while fence handler runs flas (susp_fen). */
0084 union drbd_dev_state {
0085     struct {
0086 #if defined(__LITTLE_ENDIAN_BITFIELD)
0087         unsigned role:2 ;   /* 3/4   primary/secondary/unknown */
0088         unsigned peer:2 ;   /* 3/4   primary/secondary/unknown */
0089         unsigned conn:5 ;   /* 17/32     cstates */
0090         unsigned disk:4 ;   /* 8/16  from D_DISKLESS to D_UP_TO_DATE */
0091         unsigned pdsk:4 ;   /* 8/16  from D_DISKLESS to D_UP_TO_DATE */
0092         unsigned _unused:1 ;
0093         unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
0094         unsigned peer_isp:1 ;
0095         unsigned user_isp:1 ;
0096         unsigned _pad:11;   /* 0     unused */
0097 #elif defined(__BIG_ENDIAN_BITFIELD)
0098         unsigned _pad:11;
0099         unsigned user_isp:1 ;
0100         unsigned peer_isp:1 ;
0101         unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
0102         unsigned _unused:1 ;
0103         unsigned pdsk:4 ;   /* 8/16  from D_DISKLESS to D_UP_TO_DATE */
0104         unsigned disk:4 ;   /* 8/16  from D_DISKLESS to D_UP_TO_DATE */
0105         unsigned conn:5 ;   /* 17/32     cstates */
0106         unsigned peer:2 ;   /* 3/4   primary/secondary/unknown */
0107         unsigned role:2 ;   /* 3/4   primary/secondary/unknown */
0108 #else
0109 # error "this endianess is not supported"
0110 #endif
0111     };
0112     unsigned int i;
0113 };
0114 
0115 extern enum drbd_state_rv drbd_change_state(struct drbd_device *device,
0116                         enum chg_state_flags f,
0117                         union drbd_state mask,
0118                         union drbd_state val);
0119 extern void drbd_force_state(struct drbd_device *, union drbd_state,
0120             union drbd_state);
0121 extern enum drbd_state_rv _drbd_request_state(struct drbd_device *,
0122                           union drbd_state,
0123                           union drbd_state,
0124                           enum chg_state_flags);
0125 
0126 extern enum drbd_state_rv
0127 _drbd_request_state_holding_state_mutex(struct drbd_device *, union drbd_state,
0128                     union drbd_state, enum chg_state_flags);
0129 
0130 extern enum drbd_state_rv _drbd_set_state(struct drbd_device *, union drbd_state,
0131                       enum chg_state_flags,
0132                       struct completion *done);
0133 extern void print_st_err(struct drbd_device *, union drbd_state,
0134             union drbd_state, enum drbd_state_rv);
0135 
0136 enum drbd_state_rv
0137 _conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
0138             enum chg_state_flags flags);
0139 
0140 enum drbd_state_rv
0141 conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
0142            enum chg_state_flags flags);
0143 
0144 extern void drbd_resume_al(struct drbd_device *device);
0145 extern bool conn_all_vols_unconf(struct drbd_connection *connection);
0146 
0147 /**
0148  * drbd_request_state() - Request a state change
0149  * @device: DRBD device.
0150  * @mask:   mask of state bits to change.
0151  * @val:    value of new state bits.
0152  *
0153  * This is the most graceful way of requesting a state change. It is verbose
0154  * quite verbose in case the state change is not possible, and all those
0155  * state changes are globally serialized.
0156  */
0157 static inline int drbd_request_state(struct drbd_device *device,
0158                      union drbd_state mask,
0159                      union drbd_state val)
0160 {
0161     return _drbd_request_state(device, mask, val, CS_VERBOSE + CS_ORDERED);
0162 }
0163 
0164 /* for use in adm_detach() (drbd_adm_detach(), drbd_adm_down()) */
0165 int drbd_request_detach_interruptible(struct drbd_device *device);
0166 
0167 enum drbd_role conn_highest_role(struct drbd_connection *connection);
0168 enum drbd_role conn_highest_peer(struct drbd_connection *connection);
0169 enum drbd_disk_state conn_highest_disk(struct drbd_connection *connection);
0170 enum drbd_disk_state conn_lowest_disk(struct drbd_connection *connection);
0171 enum drbd_disk_state conn_highest_pdsk(struct drbd_connection *connection);
0172 enum drbd_conns conn_lowest_conn(struct drbd_connection *connection);
0173 
0174 #endif