]> granicus.if.org Git - zfs/commit
Fix /etc/hostid on root pool deadlock
authorBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 10 Sep 2019 20:42:30 +0000 (13:42 -0700)
committerTony Hutter <hutter2@llnl.gov>
Wed, 25 Sep 2019 18:27:51 +0000 (11:27 -0700)
commit97d4986214e2f1a003f60a931bb6c9dafdead7bf
treee0c6fd07ecfbfddf160168ec09a613c45b515c1f
parent0ae5f0c8d29f2dff2470779cd7e1b4c3cfeaf12b
Fix /etc/hostid on root pool deadlock

Accidentally introduced by dc04a8c which now takes the SCL_VDEV lock
as a reader in zfs_blkptr_verify().  A deadlock can occur if the
/etc/hostid file resides on a dataset in the same pool.  This is
because reading the /etc/hostid file may occur while the caller is
holding the SCL_VDEV lock as a writer.  For example, to perform a
`zpool attach` as shown in the abbreviated stack below.

To resolve the issue we cache the system's hostid when initializing
the spa_t, or when modifying the multihost property.  The cached
value is then relied upon for subsequent accesses.

Call Trace:
    spa_config_enter+0x1e8/0x350 [zfs]
    zfs_blkptr_verify+0x33c/0x4f0 [zfs] <--- trying read lock
    zio_read+0x6c/0x140 [zfs]
    ...
    vfs_read+0xfc/0x1e0
    kernel_read+0x50/0x90
    ...
    spa_get_hostid+0x1c/0x38 [zfs]
    spa_config_generate+0x1a0/0x610 [zfs]
    vdev_label_init+0xa0/0xc80 [zfs]
    vdev_create+0x98/0xe0 [zfs]
    spa_vdev_attach+0x14c/0xb40 [zfs] <--- grabbed write lock

Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #9256
Closes #9285
include/sys/spa.h
include/sys/spa_impl.h
module/zfs/spa.c
module/zfs/spa_config.c
module/zfs/spa_misc.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/mmp/Makefile.am
tests/zfs-tests/tests/functional/mmp/mmp_hostid.ksh [new file with mode: 0755]