Commit 78bae59b authored by Philipp Reisner's avatar Philipp Reisner

drbd: Introduced drbd_read_state()

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent e15766e9
......@@ -1682,6 +1682,15 @@ _drbd_set_state(struct drbd_conf *mdev, union drbd_state ns,
return rv;
}
static inline union drbd_state drbd_read_state(struct drbd_conf *mdev)
{
union drbd_state rv;
rv = mdev->state;
return rv;
}
#define __drbd_chk_io_error(m,f) __drbd_chk_io_error_(m,f, __func__)
static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, int forcedetach, const char *where)
{
......
......@@ -1503,8 +1503,8 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
drbd_suspend_al(mdev); /* IO is still suspended here... */
spin_lock_irq(&mdev->tconn->req_lock);
os = mdev->state;
ns.i = os.i;
os = drbd_read_state(mdev);
ns = os;
/* If MDF_CONSISTENT is not set go into inconsistent state,
otherwise investigate MDF_WasUpToDate...
If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state,
......@@ -1546,7 +1546,6 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
}
rv = _drbd_set_state(mdev, ns, CS_VERBOSE, NULL);
ns = mdev->state;
spin_unlock_irq(&mdev->tconn->req_lock);
if (rv < SS_SUCCESS)
......
......@@ -3473,7 +3473,7 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi)
spin_lock_irq(&mdev->tconn->req_lock);
retry:
os = ns = mdev->state;
os = ns = drbd_read_state(mdev);
spin_unlock_irq(&mdev->tconn->req_lock);
/* peer says his disk is uptodate, while we think it is inconsistent,
......@@ -3559,7 +3559,7 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi)
}
spin_lock_irq(&mdev->tconn->req_lock);
if (mdev->state.i != os.i)
if (os.i != drbd_read_state(mdev).i)
goto retry;
clear_bit(CONSIDER_RESYNC, &mdev->flags);
ns.peer = peer_state.role;
......@@ -3581,7 +3581,7 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi)
return -EIO;
}
rv = _drbd_set_state(mdev, ns, cs_flags, NULL);
ns = mdev->state;
ns = drbd_read_state(mdev);
spin_unlock_irq(&mdev->tconn->req_lock);
if (rv < SS_SUCCESS) {
......
......@@ -163,9 +163,8 @@ drbd_change_state(struct drbd_conf *mdev, enum chg_state_flags f,
enum drbd_state_rv rv;
spin_lock_irqsave(&mdev->tconn->req_lock, flags);
ns = apply_mask_val(mdev->state, mask, val);
ns = apply_mask_val(drbd_read_state(mdev), mask, val);
rv = _drbd_set_state(mdev, ns, f, NULL);
ns = mdev->state;
spin_unlock_irqrestore(&mdev->tconn->req_lock, flags);
return rv;
......@@ -198,7 +197,7 @@ _req_st_cond(struct drbd_conf *mdev, union drbd_state mask,
return SS_CW_FAILED_BY_PEER;
spin_lock_irqsave(&mdev->tconn->req_lock, flags);
os = mdev->state;
os = drbd_read_state(mdev);
ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
rv = is_valid_transition(os, ns);
if (rv == SS_SUCCESS)
......@@ -244,7 +243,7 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask,
mutex_lock(mdev->state_mutex);
spin_lock_irqsave(&mdev->tconn->req_lock, flags);
os = mdev->state;
os = drbd_read_state(mdev);
ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
rv = is_valid_transition(os, ns);
if (rv < SS_SUCCESS) {
......@@ -280,7 +279,7 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask,
goto abort;
}
spin_lock_irqsave(&mdev->tconn->req_lock, flags);
ns = apply_mask_val(mdev->state, mask, val);
ns = apply_mask_val(drbd_read_state(mdev), mask, val);
rv = _drbd_set_state(mdev, ns, f, &done);
} else {
rv = _drbd_set_state(mdev, ns, f, &done);
......@@ -812,7 +811,7 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns,
const char *warn_sync_abort = NULL;
struct after_state_chg_work *ascw;
os = mdev->state;
os = drbd_read_state(mdev);
ns = sanitize_state(mdev, ns, &warn_sync_abort);
if (ns.i == os.i)
......@@ -1430,7 +1429,7 @@ conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union
int vnr;
idr_for_each_entry(&tconn->volumes, mdev, vnr) {
os = mdev->state;
os = drbd_read_state(mdev);
ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED)
......@@ -1474,7 +1473,7 @@ conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state
tconn->cstate = val.conn;
idr_for_each_entry(&tconn->volumes, mdev, vnr) {
os = mdev->state;
os = drbd_read_state(mdev);
ns = apply_mask_val(os, mask, val);
ns = sanitize_state(mdev, ns, NULL);
......
......@@ -48,12 +48,12 @@ struct drbd_tconn;
val.T2 = (S2); val.T3 = (S3); val; })
#define _NS(D, T, S) \
D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T = (S); __ns; })
D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T = (S); __ns; })
#define _NS2(D, T1, S1, T2, S2) \
D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \
D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T1 = (S1); \
__ns.T2 = (S2); __ns; })
#define _NS3(D, T1, S1, T2, S2, T3, S3) \
D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \
D, ({ union drbd_state __ns; __ns = drbd_read_state(D); __ns.T1 = (S1); \
__ns.T2 = (S2); __ns.T3 = (S3); __ns; })
enum chg_state_flags {
......
......@@ -781,7 +781,7 @@ int drbd_resync_finished(struct drbd_conf *mdev)
ping_peer(mdev);
spin_lock_irq(&mdev->tconn->req_lock);
os = mdev->state;
os = drbd_read_state(mdev);
verify_done = (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T);
......@@ -1546,7 +1546,7 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side)
}
write_lock_irq(&global_state_lock);
ns = mdev->state;
ns = drbd_read_state(mdev);
ns.aftr_isp = !_drbd_may_sync_now(mdev);
......@@ -1558,7 +1558,7 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side)
ns.pdsk = D_INCONSISTENT;
r = __drbd_set_state(mdev, ns, CS_VERBOSE, NULL);
ns = mdev->state;
ns = drbd_read_state(mdev);
if (ns.conn < C_CONNECTED)
r = SS_UNKNOWN_ERROR;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment