drbd: Introduced drbd_read_state()
authorPhilipp Reisner <philipp.reisner@linbit.com>
Mon, 28 Mar 2011 13:40:12 +0000 (15:40 +0200)
committerPhilipp Reisner <philipp.reisner@linbit.com>
Thu, 8 Nov 2012 15:45:03 +0000 (16:45 +0100)
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
drivers/block/drbd/drbd_int.h
drivers/block/drbd/drbd_nl.c
drivers/block/drbd/drbd_receiver.c
drivers/block/drbd/drbd_state.c
drivers/block/drbd/drbd_state.h
drivers/block/drbd/drbd_worker.c

index 2dbffb3b548520b71dc206f10126bc18de0c36da..24aed86e73642e0ee9103d421c98212f233aae3a 100644 (file)
@@ -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)
 {
index 85290a9beb6d79523932d7c33d39def37db83a44..75caac70aaae3b8561e2fdea14363b51e119dfc9 100644 (file)
@@ -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)
index c456a141eeec5c19c53a3d21dfa4e8047d10aff0..28cb19c8e264f31379ca23260619a509d865a9d7 100644 (file)
@@ -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) {
index ca77da38a0dcd3c1170c9f8e385aa53f88f280bb..411d05f885e108ce9fae08f0d2d196ca8f802d03 100644 (file)
@@ -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);
 
index c0331f18371a1eac1cb360d38a1658923cf877d2..fdcfab9c1d84c89c28c7ee0df251e77213233f21 100644 (file)
@@ -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 {
index ab73aa2fb4ee5ebed4e319657930d396406233d1..7350466ff30c29100c7beb63bbdba26da208dd81 100644 (file)
@@ -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;