zbd: Fix potential deadlock on read operations
authorDamien Le Moal <damien.lemoal@wdc.com>
Fri, 8 May 2020 07:56:40 +0000 (16:56 +0900)
committerJens Axboe <axboe@kernel.dk>
Fri, 15 May 2020 13:41:34 +0000 (07:41 -0600)
commitc8e28d8f0c75d14c41d8ae9d0598d16d24f704a6
treef7a7f1b689e13109578ffe3019e75d9646aab673
parentd087d28fc4ed967836f561884e4154d2c437a9d5
zbd: Fix potential deadlock on read operations

For read-only workloads, zbd_find_zone() has a similar zone locking
behavior as for write IOs: zones to be read are locked when an IO is
prepared and unlocked when the IO completes. With an asynchronous IO
engine, this can create deadlocks if 2 threads are trying to read the
same 2 zones. For instance, if thread A already has a lock on zone 1
and is waiting for a lock on zone 2 while thread B already has a lock
on zone 2 and waiting for a lock on zone 1.

The fix is similar to previous fixes for this potential deadlock,
namely, use zone_lock() instead of directly calling pthread_mutex_lock()
to ensure that a thread issues the IOs it already has prepared if it
encounters a locked zone, doing so ensuring forward progress.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
zbd.c