Skip to content

Commit 76341ca

Browse files
committed
jbd2: don't clear and reset errors after waiting on writeback
Resetting this flag is almost certainly racy, and will be problematic with some coming changes. Make filemap_fdatawait_keep_errors return int, but not clear the flag(s). Have jbd2 call it instead of filemap_fdatawait and don't attempt to re-set the error flag if it fails. Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: Jeff Layton <jlayton@redhat.com>
1 parent 87354e5 commit 76341ca

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

‎fs/jbd2/commit.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,10 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
263263
continue;
264264
jinode->i_flags |= JI_COMMIT_RUNNING;
265265
spin_unlock(&journal->j_list_lock);
266-
err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
267-
if (err) {
268-
/*
269-
* Because AS_EIO is cleared by
270-
* filemap_fdatawait_range(), set it again so
271-
* that user process can get -EIO from fsync().
272-
*/
273-
mapping_set_error(jinode->i_vfs_inode->i_mapping, -EIO);
274-
275-
if (!ret)
276-
ret = err;
277-
}
266+
err = filemap_fdatawait_keep_errors(
267+
jinode->i_vfs_inode->i_mapping);
268+
if (!ret)
269+
ret = err;
278270
spin_lock(&journal->j_list_lock);
279271
jinode->i_flags &= ~JI_COMMIT_RUNNING;
280272
smp_mb();

‎include/linux/fs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ extern int write_inode_now(struct inode *, int);
25142514
extern int filemap_fdatawrite(struct address_space *);
25152515
extern int filemap_flush(struct address_space *);
25162516
extern int filemap_fdatawait(struct address_space *);
2517-
extern void filemap_fdatawait_keep_errors(struct address_space *);
2517+
extern int filemap_fdatawait_keep_errors(struct address_space *mapping);
25182518
extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
25192519
loff_t lend);
25202520
extern int filemap_write_and_wait(struct address_space *mapping);

‎mm/filemap.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ int filemap_check_errors(struct address_space *mapping)
309309
}
310310
EXPORT_SYMBOL(filemap_check_errors);
311311

312+
static int filemap_check_and_keep_errors(struct address_space *mapping)
313+
{
314+
/* Check for outstanding write errors */
315+
if (test_bit(AS_EIO, &mapping->flags))
316+
return -EIO;
317+
if (test_bit(AS_ENOSPC, &mapping->flags))
318+
return -ENOSPC;
319+
return 0;
320+
}
321+
312322
/**
313323
* __filemap_fdatawrite_range - start writeback on mapping dirty pages in range
314324
* @mapping: address space structure to write
@@ -453,15 +463,17 @@ EXPORT_SYMBOL(filemap_fdatawait_range);
453463
* call sites are system-wide / filesystem-wide data flushers: e.g. sync(2),
454464
* fsfreeze(8)
455465
*/
456-
void filemap_fdatawait_keep_errors(struct address_space *mapping)
466+
int filemap_fdatawait_keep_errors(struct address_space *mapping)
457467
{
458468
loff_t i_size = i_size_read(mapping->host);
459469

460470
if (i_size == 0)
461-
return;
471+
return 0;
462472

463473
__filemap_fdatawait_range(mapping, 0, i_size - 1);
474+
return filemap_check_and_keep_errors(mapping);
464475
}
476+
EXPORT_SYMBOL(filemap_fdatawait_keep_errors);
465477

466478
/**
467479
* filemap_fdatawait - wait for all under-writeback pages to complete

0 commit comments

Comments
 (0)