Commit 0b207d0
committed
rbd: take header_rwsem in rbd_dev_refresh() only when updating
rbd_dev_refresh() has been holding header_rwsem across header and
parent info read-in unnecessarily for ages. With commit 870611e
("rbd: get snapshot context after exclusive lock is ensured to be
held"), the potential for deadlocks became much more real owning to
a) header_rwsem now nesting inside lock_rwsem and b) rw_semaphores
not allowing new readers after a writer is registered.
For example, assuming that I/O request 1, I/O request 2 and header
read-in request all target the same OSD:
1. I/O request 1 comes in and gets submitted
2. watch error occurs
3. rbd_watch_errcb() takes lock_rwsem for write, clears owner_cid and
releases lock_rwsem
4. after reestablishing the watch, rbd_reregister_watch() calls
rbd_dev_refresh() which takes header_rwsem for write and submits
a header read-in request
5. I/O request 2 comes in: after taking lock_rwsem for read in
__rbd_img_handle_request(), it blocks trying to take header_rwsem
for read in rbd_img_object_requests()
6. another watch error occurs
7. rbd_watch_errcb() blocks trying to take lock_rwsem for write
8. I/O request 1 completion is received by the messenger but can't be
processed because lock_rwsem won't be granted anymore
9. header read-in request completion can't be received, let alone
processed, because the messenger is stranded
Change rbd_dev_refresh() to take header_rwsem only for actually
updating rbd_dev->header. Header and parent info read-in don't need
any locking.
Cc: stable@vger.kernel.org # 0b03540: rbd: move rbd_dev_refresh() definition
Cc: stable@vger.kernel.org # 510a733: rbd: decouple header read-in from updating rbd_dev->header
Cc: stable@vger.kernel.org # c103117: rbd: decouple parent info read-in from updating rbd_dev
Cc: stable@vger.kernel.org
Fixes: 870611e ("rbd: get snapshot context after exclusive lock is ensured to be held")
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn>1 parent c103117 commit 0b207d0
1 file changed
Lines changed: 11 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6986 | 6986 | | |
6987 | 6987 | | |
6988 | 6988 | | |
6989 | | - | |
| 6989 | + | |
| 6990 | + | |
| 6991 | + | |
| 6992 | + | |
| 6993 | + | |
| 6994 | + | |
| 6995 | + | |
| 6996 | + | |
6990 | 6997 | | |
6991 | 6998 | | |
6992 | 6999 | | |
| |||
7044 | 7051 | | |
7045 | 7052 | | |
7046 | 7053 | | |
7047 | | - | |
7048 | 7054 | | |
7049 | 7055 | | |
7050 | | - | |
7051 | | - | |
| 7056 | + | |
7052 | 7057 | | |
7053 | 7058 | | |
7054 | 7059 | | |
| |||
7064 | 7069 | | |
7065 | 7070 | | |
7066 | 7071 | | |
| 7072 | + | |
7067 | 7073 | | |
7068 | 7074 | | |
7069 | 7075 | | |
7070 | | - | |
7071 | | - | |
7072 | | - | |
7073 | | - | |
7074 | | - | |
7075 | 7076 | | |
7076 | | - | |
7077 | | - | |
7078 | 7077 | | |
| 7078 | + | |
7079 | 7079 | | |
7080 | 7080 | | |
7081 | 7081 | | |
| |||
0 commit comments