Whamcloud - gitweb
LU-13121 llite: fix deadlock in ll_update_lsm_md() 25/37325/3
authorLai Siyao <lai.siyao@whamcloud.com>
Wed, 22 Jan 2020 05:55:27 +0000 (13:55 +0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 8 Feb 2020 05:28:29 +0000 (05:28 +0000)
commited1391adec4a10075a72b21c506293c6cf9ece95
tree436c42b923533a53a8adb5add15a0846d530347a
parent1cd76f66ce06fb588a6125ebad52da597b032030
LU-13121 llite: fix deadlock in ll_update_lsm_md()

Deadlock may happen in in following senario: a lookup process called
ll_update_lsm_md(), it found lli->lli_lsm_md is NULL, then
down_write(&lli->lli_lsm_sem). but another lookup process initialized
lli->lli_lsm_md after this check and before write lock, so the first
lookup process called up_read(&lli->lli_lsm_sem) and return, so the
write lock is never released, which cause subsequent lookups deadlock.

Rearrange the code to simplify the locking:
1. take read lock.
2. if lsm was initialized and unchanged, release read lock and return.
3. otherwise release read lock and take write lock.
4. free current lsm and initialize with new lsm.
5. release write lock.
6. initialize stripes with read lock.

Lustre-change: https://review.whamcloud.com/37182
Lustre-commit: 3746550282c865deebb07bfd92bcb4d1dabdc675

Signed-off-by: Lai Siyao <lai.siyao@whamcloud.com>
Change-Id: Ifcc25a957983512db6f29105b5ca5b6ec914cb4b
Reviewed-on: https://review.whamcloud.com/37325
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/llite_lib.c