HomeFreeBSD

Do not hold spa_config in ZIL while blocked on IO

Description

Do not hold spa_config in ZIL while blocked on IO

Otherwise, we can get a deadlock that looks like this:

  1. fsync() grabs spa_config_enter(zilog->zl_spa, SCL_STATE, lwb,

RW_READER) as part of zil_lwb_write_issue() . It then blocks on the
txg_sync when a flush fails from a drive power cycling.

  1. The txg_sync then blocks on the pool suspending due to the loss of

too many disks.

  1. zpool clear then blocks on spa_config_enter(spa, SCL_STATE |

SCL_L2ARC | SCL_ZIO, spa, RW_WRITER) because it is a writer.

The disks cannot be brought online due to fsync() holding that lock and
the user gets upset since fsync() is uninterruptibly blocked inside the
kernel.

We need to grab the lock for vdev_lookup_top(), but we do not need to
hold it while there is outstanding IO.

This fixes a regression introduced by
1ce23dcaff6c3d777cb0d9a4a2cf02b43f777d78.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@klarasystems.com>
Sponsored-By: Wasabi Technology, Inc.
Closes #14519