Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: syncfs(2) should sync all cached files #16818

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/os/linux/zfs/sys/zpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ extern const struct inode_operations zpl_special_inode_operations;
extern const struct address_space_operations zpl_address_space_operations;
extern const struct file_operations zpl_file_operations;
extern const struct file_operations zpl_dir_file_operations;
extern int zpl_writepages(struct address_space *mapping,
struct writeback_control *wbc);

/* zpl_super.c */
extern void zpl_prune_sb(uint64_t nr_to_scan, void *arg);
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/zfs/zpl_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ zpl_write_cache_pages(struct address_space *mapping,
return (result);
}

static int
int
zpl_writepages(struct address_space *mapping, struct writeback_control *wbc)
{
znode_t *zp = ITOZ(mapping->host);
Expand Down
20 changes: 19 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,29 @@ 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;
struct writeback_control wbc = {
.sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE,
.nr_to_write = LONG_MAX,
.range_start = 0,
.range_end = LLONG_MAX,
};
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 = zpl_writepages(ZTOI(zp)->i_mapping, &wbc);
if (error != 0)
break;
}
mutex_exit(&zfsvfs->z_znodes_lock);
if (error == 0)
error = -zfs_sync(sb, wait, cr);
Comment on lines +124 to +134
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without looking on anything else, I wonder if it would be better to sync as much as we can even in case of errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably yeah, I'll just need to figure out a way that doesn't call zil_commit at all, because that can deadlock if there's an IO error, apparently

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The (admittedly rare) situation of my external USB drive cages occasionally dropping a connection to a disk, causing an I/O error, which then freezes the pool and leaves me unable to reboot without a power cycle, isn't great, so thank you for trying to avoid deadlocks on IO errors.

spl_fstrans_unmark(cookie);
crfree(cr);
ASSERT3S(error, <=, 0);
Expand Down
Loading