drbd: rcu_read_[un]lock() for all idr accesses that do not sleep

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
This commit is contained in:
Philipp Reisner 2011-04-11 22:53:32 -07:00
parent cd1d9950f6
commit 695d08fa94
5 changed files with 74 additions and 19 deletions

View File

@ -453,8 +453,10 @@ void tl_clear(struct drbd_tconn *tconn)
} }
/* ensure bit indicating barrier is required is clear */ /* ensure bit indicating barrier is required is clear */
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
clear_bit(CREATE_BARRIER, &mdev->flags); clear_bit(CREATE_BARRIER, &mdev->flags);
rcu_read_unlock();
spin_unlock_irq(&tconn->req_lock); spin_unlock_irq(&tconn->req_lock);
} }
@ -634,13 +636,15 @@ char *drbd_task_to_thread_name(struct drbd_tconn *tconn, struct task_struct *tas
int conn_lowest_minor(struct drbd_tconn *tconn) int conn_lowest_minor(struct drbd_tconn *tconn)
{ {
int vnr = 0;
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr = 0, m;
rcu_read_lock();
mdev = idr_get_next(&tconn->volumes, &vnr); mdev = idr_get_next(&tconn->volumes, &vnr);
if (!mdev) m = mdev ? mdev_to_minor(mdev) : -1;
return -1; rcu_read_unlock();
return mdev_to_minor(mdev);
return m;
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP

View File

@ -372,12 +372,14 @@ static enum drbd_fencing_p highest_fencing_policy(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
if (get_ldev_if_state(mdev, D_CONSISTENT)) { if (get_ldev_if_state(mdev, D_CONSISTENT)) {
fp = max_t(enum drbd_fencing_p, fp, mdev->ldev->dc.fencing); fp = max_t(enum drbd_fencing_p, fp, mdev->ldev->dc.fencing);
put_ldev(mdev); put_ldev(mdev);
} }
} }
rcu_read_unlock();
return fp; return fp;
} }
@ -1624,29 +1626,41 @@ int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info)
static bool conn_resync_running(struct drbd_tconn *tconn) static bool conn_resync_running(struct drbd_tconn *tconn)
{ {
struct drbd_conf *mdev; struct drbd_conf *mdev;
bool rv = false;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
if (mdev->state.conn == C_SYNC_SOURCE || if (mdev->state.conn == C_SYNC_SOURCE ||
mdev->state.conn == C_SYNC_TARGET || mdev->state.conn == C_SYNC_TARGET ||
mdev->state.conn == C_PAUSED_SYNC_S || mdev->state.conn == C_PAUSED_SYNC_S ||
mdev->state.conn == C_PAUSED_SYNC_T) mdev->state.conn == C_PAUSED_SYNC_T) {
return true; rv = true;
break;
}
} }
return false; rcu_read_unlock();
return rv;
} }
static bool conn_ov_running(struct drbd_tconn *tconn) static bool conn_ov_running(struct drbd_tconn *tconn)
{ {
struct drbd_conf *mdev; struct drbd_conf *mdev;
bool rv = false;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
if (mdev->state.conn == C_VERIFY_S || if (mdev->state.conn == C_VERIFY_S ||
mdev->state.conn == C_VERIFY_T) mdev->state.conn == C_VERIFY_T) {
return true; rv = true;
break;
}
} }
return false; rcu_read_unlock();
return rv;
} }
int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info)
@ -1858,26 +1872,28 @@ int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info)
goto fail; goto fail;
} }
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, i) { idr_for_each_entry(&tconn->volumes, mdev, i) {
if (get_ldev(mdev)) { if (get_ldev(mdev)) {
enum drbd_fencing_p fp = mdev->ldev->dc.fencing; enum drbd_fencing_p fp = mdev->ldev->dc.fencing;
put_ldev(mdev); put_ldev(mdev);
if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) { if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) {
retcode = ERR_STONITH_AND_PROT_A; retcode = ERR_STONITH_AND_PROT_A;
goto fail; goto fail_rcu_unlock;
} }
} }
if (mdev->state.role == R_PRIMARY && new_conf->want_lose) { if (mdev->state.role == R_PRIMARY && new_conf->want_lose) {
retcode = ERR_DISCARD; retcode = ERR_DISCARD;
goto fail; goto fail_rcu_unlock;
} }
if (!mdev->bitmap) { if (!mdev->bitmap) {
if(drbd_bm_init(mdev)) { if(drbd_bm_init(mdev)) {
retcode = ERR_NOMEM; retcode = ERR_NOMEM;
goto fail; goto fail_rcu_unlock;
} }
} }
} }
rcu_read_unlock();
if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A) { if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A) {
retcode = ERR_CONG_NOT_PROTO_A; retcode = ERR_CONG_NOT_PROTO_A;
@ -1991,15 +2007,19 @@ int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info)
retcode = _conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); retcode = _conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE);
spin_unlock_irq(&tconn->req_lock); spin_unlock_irq(&tconn->req_lock);
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, i) { idr_for_each_entry(&tconn->volumes, mdev, i) {
mdev->send_cnt = 0; mdev->send_cnt = 0;
mdev->recv_cnt = 0; mdev->recv_cnt = 0;
kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE); kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
} }
rcu_read_unlock();
conn_reconfig_done(tconn); conn_reconfig_done(tconn);
drbd_adm_finish(info, retcode); drbd_adm_finish(info, retcode);
return 0; return 0;
fail_rcu_unlock:
rcu_read_unlock();
fail: fail:
kfree(int_dig_in); kfree(int_dig_in);
kfree(int_dig_vv); kfree(int_dig_vv);
@ -2562,8 +2582,6 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
/* synchronize with drbd_new_tconn/drbd_free_tconn */ /* synchronize with drbd_new_tconn/drbd_free_tconn */
mutex_lock(&drbd_cfg_mutex); mutex_lock(&drbd_cfg_mutex);
/* synchronize with drbd_delete_device */
rcu_read_lock();
next_tconn: next_tconn:
/* revalidate iterator position */ /* revalidate iterator position */
list_for_each_entry(tmp, &drbd_tconns, all_tconn) { list_for_each_entry(tmp, &drbd_tconns, all_tconn) {
@ -2624,7 +2642,6 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
} }
out: out:
rcu_read_unlock();
mutex_unlock(&drbd_cfg_mutex); mutex_unlock(&drbd_cfg_mutex);
/* where to start the next iteration */ /* where to start the next iteration */
cb->args[0] = (long)pos; cb->args[0] = (long)pos;

View File

@ -4828,11 +4828,13 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
set_bit(SIGNAL_ASENDER, &tconn->flags); set_bit(SIGNAL_ASENDER, &tconn->flags);
spin_lock_irq(&tconn->req_lock); spin_lock_irq(&tconn->req_lock);
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, i) { idr_for_each_entry(&tconn->volumes, mdev, i) {
not_empty = !list_empty(&mdev->done_ee); not_empty = !list_empty(&mdev->done_ee);
if (not_empty) if (not_empty)
break; break;
} }
rcu_read_unlock();
spin_unlock_irq(&tconn->req_lock); spin_unlock_irq(&tconn->req_lock);
} while (not_empty); } while (not_empty);

View File

@ -55,15 +55,21 @@ static inline bool is_susp(union drbd_state s)
bool conn_all_vols_unconf(struct drbd_tconn *tconn) bool conn_all_vols_unconf(struct drbd_tconn *tconn)
{ {
struct drbd_conf *mdev; struct drbd_conf *mdev;
bool rv = true;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
if (mdev->state.disk != D_DISKLESS || if (mdev->state.disk != D_DISKLESS ||
mdev->state.conn != C_STANDALONE || mdev->state.conn != C_STANDALONE ||
mdev->state.role != R_SECONDARY) mdev->state.role != R_SECONDARY) {
return false; rv = false;
break;
}
} }
return true; rcu_read_unlock();
return rv;
} }
/* Unfortunately the states where not correctly ordered, when /* Unfortunately the states where not correctly ordered, when
@ -91,8 +97,10 @@ enum drbd_role conn_highest_role(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
role = max_role(role, mdev->state.role); role = max_role(role, mdev->state.role);
rcu_read_unlock();
return role; return role;
} }
@ -103,8 +111,10 @@ enum drbd_role conn_highest_peer(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
peer = max_role(peer, mdev->state.peer); peer = max_role(peer, mdev->state.peer);
rcu_read_unlock();
return peer; return peer;
} }
@ -115,8 +125,10 @@ enum drbd_disk_state conn_highest_disk(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
ds = max_t(enum drbd_disk_state, ds, mdev->state.disk); ds = max_t(enum drbd_disk_state, ds, mdev->state.disk);
rcu_read_unlock();
return ds; return ds;
} }
@ -127,8 +139,10 @@ enum drbd_disk_state conn_lowest_disk(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
ds = min_t(enum drbd_disk_state, ds, mdev->state.disk); ds = min_t(enum drbd_disk_state, ds, mdev->state.disk);
rcu_read_unlock();
return ds; return ds;
} }
@ -139,8 +153,10 @@ enum drbd_disk_state conn_highest_pdsk(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
ds = max_t(enum drbd_disk_state, ds, mdev->state.pdsk); ds = max_t(enum drbd_disk_state, ds, mdev->state.pdsk);
rcu_read_unlock();
return ds; return ds;
} }
@ -151,8 +167,10 @@ enum drbd_conns conn_lowest_conn(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
conn = min_t(enum drbd_conns, conn, mdev->state.conn); conn = min_t(enum drbd_conns, conn, mdev->state.conn);
rcu_read_unlock();
return conn; return conn;
} }
@ -1406,12 +1424,14 @@ static int w_after_conn_state_ch(struct drbd_work *w, int unused)
/* case1: The outdate peer handler is successful: */ /* case1: The outdate peer handler is successful: */
if (ns_max.pdsk <= D_OUTDATED) { if (ns_max.pdsk <= D_OUTDATED) {
tl_clear(tconn); tl_clear(tconn);
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
if (test_bit(NEW_CUR_UUID, &mdev->flags)) { if (test_bit(NEW_CUR_UUID, &mdev->flags)) {
drbd_uuid_new_current(mdev); drbd_uuid_new_current(mdev);
clear_bit(NEW_CUR_UUID, &mdev->flags); clear_bit(NEW_CUR_UUID, &mdev->flags);
} }
} }
rcu_read_unlock();
conn_request_state(tconn, conn_request_state(tconn,
(union drbd_state) { { .susp_fen = 1 } }, (union drbd_state) { { .susp_fen = 1 } },
(union drbd_state) { { .susp_fen = 0 } }, (union drbd_state) { { .susp_fen = 0 } },
@ -1419,8 +1439,10 @@ static int w_after_conn_state_ch(struct drbd_work *w, int unused)
} }
/* case2: The connection was established again: */ /* case2: The connection was established again: */
if (ns_min.conn >= C_CONNECTED) { if (ns_min.conn >= C_CONNECTED) {
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
clear_bit(NEW_CUR_UUID, &mdev->flags); clear_bit(NEW_CUR_UUID, &mdev->flags);
rcu_read_unlock();
spin_lock_irq(&tconn->req_lock); spin_lock_irq(&tconn->req_lock);
_tl_restart(tconn, RESEND); _tl_restart(tconn, RESEND);
_conn_request_state(tconn, _conn_request_state(tconn,
@ -1445,6 +1467,7 @@ void conn_old_common_state(struct drbd_tconn *tconn, union drbd_state *pcs, enum
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr, first_vol = 1; int vnr, first_vol = 1;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
os = mdev->state; os = mdev->state;
@ -1469,6 +1492,7 @@ void conn_old_common_state(struct drbd_tconn *tconn, union drbd_state *pcs, enum
if (cs.pdsk != os.pdsk) if (cs.pdsk != os.pdsk)
flags &= ~CS_DC_PDSK; flags &= ~CS_DC_PDSK;
} }
rcu_read_unlock();
*pf |= CS_DC_MASK; *pf |= CS_DC_MASK;
*pf &= flags; *pf &= flags;
@ -1484,6 +1508,7 @@ conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
os = drbd_read_state(mdev); os = drbd_read_state(mdev);
ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL); ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
@ -1509,6 +1534,7 @@ conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union
if (rv < SS_SUCCESS) if (rv < SS_SUCCESS)
break; break;
} }
rcu_read_unlock();
if (rv < SS_SUCCESS && flags & CS_VERBOSE) if (rv < SS_SUCCESS && flags & CS_VERBOSE)
print_st_err(mdev, os, ns, rv); print_st_err(mdev, os, ns, rv);
@ -1534,6 +1560,7 @@ conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state
if (mask.conn == C_MASK) if (mask.conn == C_MASK)
tconn->cstate = val.conn; tconn->cstate = val.conn;
rcu_read_lock();
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
os = drbd_read_state(mdev); os = drbd_read_state(mdev);
ns = apply_mask_val(os, mask, val); ns = apply_mask_val(os, mask, val);
@ -1559,6 +1586,7 @@ conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state
ns_min.disk = min_t(enum drbd_disk_state, ns.disk, ns_min.disk); ns_min.disk = min_t(enum drbd_disk_state, ns.disk, ns_min.disk);
ns_min.pdsk = min_t(enum drbd_disk_state, ns.pdsk, ns_min.pdsk); ns_min.pdsk = min_t(enum drbd_disk_state, ns.pdsk, ns_min.pdsk);
} }
rcu_read_unlock();
ns_min.susp = ns_max.susp = tconn->susp; ns_min.susp = ns_max.susp = tconn->susp;
ns_min.susp_nod = ns_max.susp_nod = tconn->susp_nod; ns_min.susp_nod = ns_max.susp_nod = tconn->susp_nod;

View File

@ -1348,6 +1348,7 @@ static int _drbd_pause_after(struct drbd_conf *mdev)
struct drbd_conf *odev; struct drbd_conf *odev;
int i, rv = 0; int i, rv = 0;
rcu_read_lock();
idr_for_each_entry(&minors, odev, i) { idr_for_each_entry(&minors, odev, i) {
if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS)
continue; continue;
@ -1355,6 +1356,7 @@ static int _drbd_pause_after(struct drbd_conf *mdev)
rv |= (__drbd_set_state(_NS(odev, aftr_isp, 1), CS_HARD, NULL) rv |= (__drbd_set_state(_NS(odev, aftr_isp, 1), CS_HARD, NULL)
!= SS_NOTHING_TO_DO); != SS_NOTHING_TO_DO);
} }
rcu_read_unlock();
return rv; return rv;
} }
@ -1370,6 +1372,7 @@ static int _drbd_resume_next(struct drbd_conf *mdev)
struct drbd_conf *odev; struct drbd_conf *odev;
int i, rv = 0; int i, rv = 0;
rcu_read_lock();
idr_for_each_entry(&minors, odev, i) { idr_for_each_entry(&minors, odev, i) {
if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS)
continue; continue;
@ -1380,6 +1383,7 @@ static int _drbd_resume_next(struct drbd_conf *mdev)
!= SS_NOTHING_TO_DO) ; != SS_NOTHING_TO_DO) ;
} }
} }
rcu_read_unlock();
return rv; return rv;
} }