Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit735e4ae

Browse files
jtlaytontorvalds
authored andcommitted
vfs: track per-sb writeback errors and report them to syncfs
Patch series "vfs: have syncfs() return error when there are writebackerrors", v6.Currently, syncfs does not return errors when one of the inodes fails tobe written back. It will return errors based on the legacy AS_EIO andAS_ENOSPC flags when syncing out the block device fails, but that's notparticularly helpful for filesystems that aren't backed by a blockdev.It's also possible for a stray sync to lose those errors.The basic idea in this set is to track writeback errors at thesuperblock level, so that we can quickly and easily check whethersomething bad happened without having to fsync each file individually.syncfs is then changed to reliably report writeback errors after theyoccur, much in the same fashion as fsync does now.This patch (of 2):Usually we suggest that applications call fsync when they want to ensurethat all data written to the file has made it to the backing store, butthat can be inefficient when there are a lot of open files.Calling syncfs on the filesystem can be more efficient in somesituations, but the error reporting doesn't currently work the way mostpeople expect. If a single inode on a filesystem reports a writebackerror, syncfs won't necessarily return an error. syncfs only returns anerror if __sync_blockdev fails, and on some filesystems that's a no-op.It would be better if syncfs reported an error if there were anywriteback failures. Then applications could call syncfs to see if thereare any errors on any open files, and could then call fsync on all ofthe other descriptors to figure out which one failed.This patch adds a new errseq_t to struct super_block, and hasmapping_set_error also record writeback errors there.To report those errors, we also need to keep an errseq_t in struct fileto act as a cursor. This patch adds a dedicated field for that purpose,which slots nicely into 4 bytes of padding at the end of struct file onx86_64.An earlier version of this patch used an O_PATH file descriptor to cuethe kernel that the open file should track the superblock error and notthe inode's writeback error.I think that API is just too weird though. This is simpler and shouldmake syncfs error reporting "just work" even if someone is multiplexingfsync and syncfs on the same fds.Signed-off-by: Jeff Layton <jlayton@kernel.org>Signed-off-by: Andrew Morton <akpm@linux-foundation.org>Reviewed-by: Jan Kara <jack@suse.cz>Cc: Andres Freund <andres@anarazel.de>Cc: Matthew Wilcox <willy@infradead.org>Cc: Al Viro <viro@zeniv.linux.org.uk>Cc: Christoph Hellwig <hch@infradead.org>Cc: Dave Chinner <david@fromorbit.com>Cc: David Howells <dhowells@redhat.com>Link:http://lkml.kernel.org/r/20200428135155.19223-1-jlayton@kernel.orgLink:http://lkml.kernel.org/r/20200428135155.19223-2-jlayton@kernel.orgSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent78128fa commit735e4ae

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

‎drivers/dax/device.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ static int dax_open(struct inode *inode, struct file *filp)
377377
inode->i_mapping->a_ops=&dev_dax_aops;
378378
filp->f_mapping=inode->i_mapping;
379379
filp->f_wb_err=filemap_sample_wb_err(filp->f_mapping);
380+
filp->f_sb_err=file_sample_sb_err(filp);
380381
filp->private_data=dev_dax;
381382
inode->i_flags=S_DAX;
382383

‎fs/file_table.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ static struct file *alloc_file(const struct path *path, int flags,
198198
file->f_inode=path->dentry->d_inode;
199199
file->f_mapping=path->dentry->d_inode->i_mapping;
200200
file->f_wb_err=filemap_sample_wb_err(file->f_mapping);
201+
file->f_sb_err=file_sample_sb_err(file);
201202
if ((file->f_mode&FMODE_READ)&&
202203
likely(fop->read||fop->read_iter))
203204
file->f_mode |=FMODE_CAN_READ;

‎fs/open.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,8 @@ static int do_dentry_open(struct file *f,
743743
path_get(&f->f_path);
744744
f->f_inode=inode;
745745
f->f_mapping=inode->i_mapping;
746-
747-
/* Ensure that we skip any errors that predate opening of the file */
748746
f->f_wb_err=filemap_sample_wb_err(f->f_mapping);
747+
f->f_sb_err=file_sample_sb_err(f);
749748

750749
if (unlikely(f->f_flags&O_PATH)) {
751750
f->f_mode=FMODE_PATH |FMODE_OPENED;

‎fs/sync.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ SYSCALL_DEFINE1(syncfs, int, fd)
161161
{
162162
structfdf=fdget(fd);
163163
structsuper_block*sb;
164-
intret;
164+
intret,ret2;
165165

166166
if (!f.file)
167167
return-EBADF;
@@ -171,8 +171,10 @@ SYSCALL_DEFINE1(syncfs, int, fd)
171171
ret=sync_filesystem(sb);
172172
up_read(&sb->s_umount);
173173

174+
ret2=errseq_check_and_advance(&sb->s_wb_err,&f.file->f_sb_err);
175+
174176
fdput(f);
175-
returnret;
177+
returnret ?ret :ret2;
176178
}
177179

178180
/**

‎include/linux/fs.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ struct file {
976976
#endif/* #ifdef CONFIG_EPOLL */
977977
structaddress_space*f_mapping;
978978
errseq_tf_wb_err;
979+
errseq_tf_sb_err;/* for syncfs */
979980
}__randomize_layout
980981
__attribute__((aligned(4)));/* lest something weird decides that 2 is OK */
981982

@@ -1520,6 +1521,9 @@ struct super_block {
15201521
/* Being remounted read-only */
15211522
ints_readonly_remount;
15221523

1524+
/* per-sb errseq_t for reporting writeback errors via syncfs */
1525+
errseq_ts_wb_err;
1526+
15231527
/* AIO completions deferred from interrupt context */
15241528
structworkqueue_struct*s_dio_done_wq;
15251529
structhlist_heads_pins;
@@ -2827,6 +2831,18 @@ static inline errseq_t filemap_sample_wb_err(struct address_space *mapping)
28272831
returnerrseq_sample(&mapping->wb_err);
28282832
}
28292833

2834+
/**
2835+
* file_sample_sb_err - sample the current errseq_t to test for later errors
2836+
* @mapping: mapping to be sampled
2837+
*
2838+
* Grab the most current superblock-level errseq_t value for the given
2839+
* struct file.
2840+
*/
2841+
staticinlineerrseq_tfile_sample_sb_err(structfile*file)
2842+
{
2843+
returnerrseq_sample(&file->f_path.dentry->d_sb->s_wb_err);
2844+
}
2845+
28302846
staticinlineintfilemap_nr_thps(structaddress_space*mapping)
28312847
{
28322848
#ifdefCONFIG_READ_ONLY_THP_FOR_FS

‎include/linux/pagemap.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ static inline void mapping_set_error(struct address_space *mapping, int error)
5151
return;
5252

5353
/* Record in wb_err for checkers using errseq_t based tracking */
54-
filemap_set_wb_err(mapping,error);
54+
__filemap_set_wb_err(mapping,error);
55+
56+
/* Record it in superblock */
57+
errseq_set(&mapping->host->i_sb->s_wb_err,error);
5558

5659
/* Record it in flags for now, for legacy callers */
5760
if (error==-ENOSPC)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp