aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/zfs_vfsops.c
diff options
context:
space:
mode:
authorTom Caputi <[email protected]>2018-08-20 16:42:17 -0400
committerBrian Behlendorf <[email protected]>2018-08-27 10:16:28 -0700
commit47ab01a18f55f89be7b3f340b6ec9101bf9e231c (patch)
treed76615b0403fdd1ba8439b1d57c2e76a0ff8639b /module/zfs/zfs_vfsops.c
parent8c4fb36a24d4fd88382e454b13751a5adfea0806 (diff)
Always wait for txg sync when umounting dataset
Currently, when unmounting a filesystem, ZFS will only wait for a txg sync if the dataset is dirty and not readonly. However, this can be problematic in cases where a dataset is remounted readonly immediately before being unmounted, which often happens when the system is being shut down. Since encrypted datasets require that all I/O is completed before the dataset is disowned, this issue causes problems when write I/Os leak into the txgs after the dataset is disowned, which can happen when sync=disabled. While looking into fixes for this issue, it was discovered that dsl_dataset_is_dirty() does not return B_TRUE when the dataset has been removed from the txg dirty datasets list, but has not actually been processed yet. Furthermore, the implementation is comletely different from dmu_objset_is_dirty(), adding to the confusion. Rather than relying on this function, this patch forces the umount code path (and the remount readonly code path) to always perform a txg sync on read-write datasets and removes the function altogether. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Tom Caputi <[email protected]> Closes #7753 Closes #7795
Diffstat (limited to 'module/zfs/zfs_vfsops.c')
-rw-r--r--module/zfs/zfs_vfsops.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/module/zfs/zfs_vfsops.c b/module/zfs/zfs_vfsops.c
index 488eaa4f2..8ae2ef929 100644
--- a/module/zfs/zfs_vfsops.c
+++ b/module/zfs/zfs_vfsops.c
@@ -1745,10 +1745,10 @@ zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
zfs_unregister_callbacks(zfsvfs);
/*
- * Evict cached data
+ * Evict cached data. We must write out any dirty data before
+ * disowning the dataset.
*/
- if (dsl_dataset_is_dirty(dmu_objset_ds(zfsvfs->z_os)) &&
- !zfs_is_readonly(zfsvfs))
+ if (!zfs_is_readonly(zfsvfs))
txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
dmu_objset_evict_dbufs(zfsvfs->z_os);
@@ -1970,6 +1970,9 @@ zfs_remount(struct super_block *sb, int *flags, zfs_mnt_t *zm)
if (error)
return (error);
+ if (!zfs_is_readonly(zfsvfs) && (*flags & MS_RDONLY))
+ txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
+
zfs_unregister_callbacks(zfsvfs);
zfsvfs_vfs_free(zfsvfs->z_vfs);