Commit 56707f9e authored by Philipp Reisner's avatar Philipp Reisner

drbd: Code de-duplication; new function apply_mask_val()

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 4308a0a3
...@@ -69,17 +69,24 @@ static int cl_wide_st_chg(struct drbd_conf *mdev, ...@@ -69,17 +69,24 @@ static int cl_wide_st_chg(struct drbd_conf *mdev,
(os.conn == C_CONNECTED && ns.conn == C_VERIFY_S); (os.conn == C_CONNECTED && ns.conn == C_VERIFY_S);
} }
static union drbd_state
apply_mask_val(union drbd_state os, union drbd_state mask, union drbd_state val)
{
union drbd_state ns;
ns.i = (os.i & ~mask.i) | val.i;
return ns;
}
enum drbd_state_rv enum drbd_state_rv
drbd_change_state(struct drbd_conf *mdev, enum chg_state_flags f, drbd_change_state(struct drbd_conf *mdev, enum chg_state_flags f,
union drbd_state mask, union drbd_state val) union drbd_state mask, union drbd_state val)
{ {
unsigned long flags; unsigned long flags;
union drbd_state os, ns; union drbd_state ns;
enum drbd_state_rv rv; enum drbd_state_rv rv;
spin_lock_irqsave(&mdev->tconn->req_lock, flags); spin_lock_irqsave(&mdev->tconn->req_lock, flags);
os = mdev->state; ns = apply_mask_val(mdev->state, mask, val);
ns.i = (os.i & ~mask.i) | val.i;
rv = _drbd_set_state(mdev, ns, f, NULL); rv = _drbd_set_state(mdev, ns, f, NULL);
ns = mdev->state; ns = mdev->state;
spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); spin_unlock_irqrestore(&mdev->tconn->req_lock, flags);
...@@ -115,8 +122,7 @@ _req_st_cond(struct drbd_conf *mdev, union drbd_state mask, ...@@ -115,8 +122,7 @@ _req_st_cond(struct drbd_conf *mdev, union drbd_state mask,
spin_lock_irqsave(&mdev->tconn->req_lock, flags); spin_lock_irqsave(&mdev->tconn->req_lock, flags);
os = mdev->state; os = mdev->state;
ns.i = (os.i & ~mask.i) | val.i; ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
ns = sanitize_state(mdev, ns, NULL);
rv = is_valid_transition(os, ns); rv = is_valid_transition(os, ns);
if (rv == SS_SUCCESS) if (rv == SS_SUCCESS)
rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */
...@@ -162,8 +168,7 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask, ...@@ -162,8 +168,7 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask,
spin_lock_irqsave(&mdev->tconn->req_lock, flags); spin_lock_irqsave(&mdev->tconn->req_lock, flags);
os = mdev->state; os = mdev->state;
ns.i = (os.i & ~mask.i) | val.i; ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
ns = sanitize_state(mdev, ns, NULL);
rv = is_valid_transition(os, ns); rv = is_valid_transition(os, ns);
if (rv < SS_SUCCESS) if (rv < SS_SUCCESS)
goto abort; goto abort;
...@@ -199,8 +204,7 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask, ...@@ -199,8 +204,7 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask,
goto abort; goto abort;
} }
spin_lock_irqsave(&mdev->tconn->req_lock, flags); spin_lock_irqsave(&mdev->tconn->req_lock, flags);
os = mdev->state; ns = apply_mask_val(mdev->state, mask, val);
ns.i = (os.i & ~mask.i) | val.i;
rv = _drbd_set_state(mdev, ns, f, &done); rv = _drbd_set_state(mdev, ns, f, &done);
drbd_state_unlock(mdev); drbd_state_unlock(mdev);
} else { } else {
......
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