提交 d3fcb490 编写于 作者: P Philipp Reisner

drbd: protect all idr accesses that might sleep with drbd_cfg_rwsem

With this commit the locking for all accesses to IDRs is complete:

 * Non sleeping read accesses are protected by RCU
 * sleeping read accesses are protocted by a read lock on drbd_cfg_rwsem
 * accesses that add anything are protected by a write lock
 * accesses that remove an object are protoected by a write lock
   and a call to synchronize_rcu() after it is removed from the IDR
   and before the object is actually free()ed.
Signed-off-by: NPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: NLars Ellenberg <lars.ellenberg@linbit.com>
上级 ef356262
...@@ -172,7 +172,7 @@ extern struct ratelimit_state drbd_ratelimit_state; ...@@ -172,7 +172,7 @@ extern struct ratelimit_state drbd_ratelimit_state;
extern struct idr minors; extern struct idr minors;
extern struct list_head drbd_tconns; extern struct list_head drbd_tconns;
extern struct rw_semaphore drbd_cfg_rwsem; extern struct rw_semaphore drbd_cfg_rwsem;
/* drbd_cfg_rwsem protects: drbd_tconns list, /* drbd_cfg_rwsem protects: drbd_tconns list, minors idr, tconn->volumes idr
note: non sleeping iterations over the idrs are protoected by RCU */ note: non sleeping iterations over the idrs are protoected by RCU */
/* on the wire */ /* on the wire */
......
...@@ -2266,8 +2266,10 @@ static void drbd_cleanup(void) ...@@ -2266,8 +2266,10 @@ static void drbd_cleanup(void)
drbd_genl_unregister(); drbd_genl_unregister();
down_write(&drbd_cfg_rwsem);
idr_for_each_entry(&minors, mdev, i) idr_for_each_entry(&minors, mdev, i)
drbd_delete_device(mdev); drbd_delete_device(mdev);
up_write(&drbd_cfg_rwsem);
drbd_destroy_mempools(); drbd_destroy_mempools();
unregister_blkdev(DRBD_MAJOR, "drbd"); unregister_blkdev(DRBD_MAJOR, "drbd");
......
...@@ -328,8 +328,10 @@ static void conn_md_sync(struct drbd_tconn *tconn) ...@@ -328,8 +328,10 @@ static void conn_md_sync(struct drbd_tconn *tconn)
struct drbd_conf *mdev; struct drbd_conf *mdev;
int vnr; int vnr;
down_read(&drbd_cfg_rwsem);
idr_for_each_entry(&tconn->volumes, mdev, vnr) idr_for_each_entry(&tconn->volumes, mdev, vnr)
drbd_md_sync(mdev); drbd_md_sync(mdev);
up_read(&drbd_cfg_rwsem);
} }
int conn_khelper(struct drbd_tconn *tconn, char *cmd) int conn_khelper(struct drbd_tconn *tconn, char *cmd)
...@@ -2865,7 +2867,9 @@ int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info) ...@@ -2865,7 +2867,9 @@ int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
down_write(&drbd_cfg_rwsem);
retcode = conn_new_minor(adm_ctx.tconn, dh->minor, adm_ctx.volume); retcode = conn_new_minor(adm_ctx.tconn, dh->minor, adm_ctx.volume);
up_write(&drbd_cfg_rwsem);
out: out:
drbd_adm_finish(info, retcode); drbd_adm_finish(info, retcode);
return 0; return 0;
......
...@@ -227,6 +227,7 @@ static int drbd_seq_show(struct seq_file *seq, void *v) ...@@ -227,6 +227,7 @@ static int drbd_seq_show(struct seq_file *seq, void *v)
oos .. known out-of-sync kB oos .. known out-of-sync kB
*/ */
down_read(&drbd_cfg_rwsem);
idr_for_each_entry(&minors, mdev, i) { idr_for_each_entry(&minors, mdev, i) {
if (prev_i != i - 1) if (prev_i != i - 1)
seq_printf(seq, "\n"); seq_printf(seq, "\n");
...@@ -293,6 +294,7 @@ static int drbd_seq_show(struct seq_file *seq, void *v) ...@@ -293,6 +294,7 @@ static int drbd_seq_show(struct seq_file *seq, void *v)
} }
} }
} }
up_read(&drbd_cfg_rwsem);
return 0; return 0;
} }
......
...@@ -964,7 +964,10 @@ static int drbd_connect(struct drbd_tconn *tconn) ...@@ -964,7 +964,10 @@ static int drbd_connect(struct drbd_tconn *tconn)
if (drbd_send_protocol(tconn) == -EOPNOTSUPP) if (drbd_send_protocol(tconn) == -EOPNOTSUPP)
return -1; return -1;
return !idr_for_each(&tconn->volumes, drbd_connected, tconn); down_read(&drbd_cfg_rwsem);
h = !idr_for_each(&tconn->volumes, drbd_connected, tconn);
up_read(&drbd_cfg_rwsem);
return h;
out_release_sockets: out_release_sockets:
if (tconn->data.socket) { if (tconn->data.socket) {
...@@ -4084,7 +4087,9 @@ static void drbd_disconnect(struct drbd_tconn *tconn) ...@@ -4084,7 +4087,9 @@ static void drbd_disconnect(struct drbd_tconn *tconn)
drbd_thread_stop(&tconn->asender); drbd_thread_stop(&tconn->asender);
drbd_free_sock(tconn); drbd_free_sock(tconn);
down_read(&drbd_cfg_rwsem);
idr_for_each(&tconn->volumes, drbd_disconnected, tconn); idr_for_each(&tconn->volumes, drbd_disconnected, tconn);
up_read(&drbd_cfg_rwsem);
conn_info(tconn, "Connection closed\n"); conn_info(tconn, "Connection closed\n");
if (conn_highest_role(tconn) == R_PRIMARY && conn_highest_pdsk(tconn) >= D_UNKNOWN) if (conn_highest_role(tconn) == R_PRIMARY && conn_highest_pdsk(tconn) >= D_UNKNOWN)
...@@ -4821,10 +4826,14 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn) ...@@ -4821,10 +4826,14 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
do { do {
clear_bit(SIGNAL_ASENDER, &tconn->flags); clear_bit(SIGNAL_ASENDER, &tconn->flags);
flush_signals(current); flush_signals(current);
down_read(&drbd_cfg_rwsem);
idr_for_each_entry(&tconn->volumes, mdev, i) { idr_for_each_entry(&tconn->volumes, mdev, i) {
if (drbd_finish_peer_reqs(mdev)) if (drbd_finish_peer_reqs(mdev)) {
up_read(&drbd_cfg_rwsem);
return 1; /* error */ return 1; /* error */
}
} }
up_read(&drbd_cfg_rwsem);
set_bit(SIGNAL_ASENDER, &tconn->flags); set_bit(SIGNAL_ASENDER, &tconn->flags);
spin_lock_irq(&tconn->req_lock); spin_lock_irq(&tconn->req_lock);
......
...@@ -1731,12 +1731,14 @@ int drbd_worker(struct drbd_thread *thi) ...@@ -1731,12 +1731,14 @@ int drbd_worker(struct drbd_thread *thi)
spin_unlock_irq(&tconn->data.work.q_lock); spin_unlock_irq(&tconn->data.work.q_lock);
drbd_thread_stop(&tconn->receiver); drbd_thread_stop(&tconn->receiver);
down_read(&drbd_cfg_rwsem);
idr_for_each_entry(&tconn->volumes, mdev, vnr) { idr_for_each_entry(&tconn->volumes, mdev, vnr) {
D_ASSERT(mdev->state.disk == D_DISKLESS && mdev->state.conn == C_STANDALONE); D_ASSERT(mdev->state.disk == D_DISKLESS && mdev->state.conn == C_STANDALONE);
/* _drbd_set_state only uses stop_nowait. /* _drbd_set_state only uses stop_nowait.
* wait here for the exiting receiver. */ * wait here for the exiting receiver. */
drbd_mdev_cleanup(mdev); drbd_mdev_cleanup(mdev);
} }
up_read(&drbd_cfg_rwsem);
clear_bit(OBJECT_DYING, &tconn->flags); clear_bit(OBJECT_DYING, &tconn->flags);
clear_bit(CONFIG_PENDING, &tconn->flags); clear_bit(CONFIG_PENDING, &tconn->flags);
wake_up(&tconn->ping_wait); wake_up(&tconn->ping_wait);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册