Skip to content

Commit

Permalink
Linux: syncfs(2) should sync all open files
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
snajpa committed Nov 28, 2024
1 parent d53602d commit 8fc424e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 6 additions & 6 deletions module/os/linux/zfs/zfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1551,12 +1551,12 @@ zfs_preumount(struct super_block *sb)
/* zfsvfs is NULL when zfs_domount fails during mount */
if (zfsvfs) {
/*
* Since we have to disable zpl_prune_sb when umounting,
* because the shrinker gets freed before zpl_kill_sb is
* ever called, the umount might be unable to sync open files.
*
* Let's do it here.
*/
* Since we have to disable zpl_prune_sb when umounting,
* because the shrinker gets freed before zpl_kill_sb is
* ever called, the umount might be unable to sync open files.
*
* Let's do it here.
*/
mutex_enter(&zfsvfs->z_znodes_lock);
list_for_each_entry(zp, &zfsvfs->z_all_znodes, z_link_node) {
if (zp->z_sa_hdl)
Expand Down
14 changes: 13 additions & 1 deletion module/os/linux/zfs/zpl_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = -zfs_fsync(zp, wait, cr);
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);
Expand Down

0 comments on commit 8fc424e

Please sign in to comment.