From f5b732d44d3b1aba3a14f18cee955a750e1609ed Mon Sep 17 00:00:00 2001 From: Pavel Snajdr Date: Fri, 29 Nov 2024 23:11:44 +0100 Subject: [PATCH] Linux: syncfs(2) should sync all cached files While debugging problem with data not being synced on umount, we've noticed that even syncfs(2) doesn't help to get the data written out. It is because it doesn't actually sync any of the live znodes. Signed-off-by: Pavel Snajdr --- module/os/linux/zfs/zpl_super.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/module/os/linux/zfs/zpl_super.c b/module/os/linux/zfs/zpl_super.c index b97b701b7460..a3337cd64356 100644 --- a/module/os/linux/zfs/zpl_super.c +++ b/module/os/linux/zfs/zpl_super.c @@ -109,11 +109,23 @@ zpl_sync_fs(struct super_block *sb, int wait) { fstrans_cookie_t cookie; cred_t *cr = CRED(); + znode_t *zp; + zfsvfs_t *zfsvfs = sb->s_fs_info; int error; crhold(cr); cookie = spl_fstrans_mark(); - error = -zfs_sync(sb, wait, cr); + mutex_enter(&zfsvfs->z_znodes_lock); + for (zp = list_head(&zfsvfs->z_all_znodes); zp; + zp = list_next(&zfsvfs->z_all_znodes, zp)) { + if (zp->z_sa_hdl) + error = filemap_write_and_wait(ZTOI(zp)->i_mapping); + if (error != 0) + break; + } + mutex_exit(&zfsvfs->z_znodes_lock); + if (error == 0) + error = -zfs_sync(sb, wait, cr); spl_fstrans_unmark(cookie); crfree(cr); ASSERT3S(error, <=, 0);