diff --git a/module/zfs/zfs_vfsops.c b/module/zfs/zfs_vfsops.c index 3c9a8476c476..27c133798140 100644 --- a/module/zfs/zfs_vfsops.c +++ b/module/zfs/zfs_vfsops.c @@ -1415,6 +1415,21 @@ zfs_preumount(struct super_block *sb) if (zsb) zfsctl_destroy(sb->s_fs_info); + /* + * wait for iput_async before entering evict_inodes in + * generic_shutdown_super. The reason we must finish before + * evict_inodes is iput when lazytime and zfs_purgedir calling + * zfs_zget would bump i_count from 0 to 1. This would race with the + * i_count check in evict_inodes, so it could destroy the inode while + * we are still using it. + * + * We wait for two pass, first pass are xattr dirs, second pass are + * xattr entries. + */ + taskq_wait_outstanding(dsl_pool_iput_taskq( + dmu_objset_pool(zsb->z_os)), 0); + taskq_wait_outstanding(dsl_pool_iput_taskq( + dmu_objset_pool(zsb->z_os)), 0); } EXPORT_SYMBOL(zfs_preumount);