Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
exfat: flush dirty metadata in fsync
Browse files Browse the repository at this point in the history
generic_file_fsync() exfat used could not guarantee the consistency of
a file because it has flushed not dirty metadata but only dirty data pages
for a file.

Instead of that, use exfat_file_fsync() for files and directories so that
it guarantees to commit both the metadata and data pages for a file.

Signed-off-by: Sungjong Seo <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
Signed-off-by: Park Ju Hyung <[email protected]>
  • Loading branch information
Sungjong Seo authored and arter97 committed Jun 30, 2020
1 parent d22017b commit de5cb23
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const struct file_operations exfat_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.iterate = exfat_iterate,
.fsync = generic_file_fsync,
.fsync = exfat_file_fsync,
};

int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu)
Expand Down
1 change: 1 addition & 0 deletions exfat_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ int exfat_getattr(const struct path *path, struct kstat *stat,
#else
int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
#endif
int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);

/* namei.c */
extern const struct dentry_operations exfat_dentry_ops;
Expand Down
19 changes: 18 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/slab.h>
#include <linux/cred.h>
#include <linux/buffer_head.h>
#include <linux/blkdev.h>

#include "exfat_fs.h"

Expand Down Expand Up @@ -367,12 +368,28 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
return error;
}

int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
{
struct inode *inode = filp->f_mapping->host;
int err;

err = __generic_file_fsync(filp, start, end, datasync);
if (err)
return err;

err = sync_blockdev(inode->i_sb->s_bdev);
if (err)
return err;

return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
}

const struct file_operations exfat_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
.mmap = generic_file_mmap,
.fsync = generic_file_fsync,
.fsync = exfat_file_fsync,
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
};
Expand Down

0 comments on commit de5cb23

Please sign in to comment.