@@ -1959,7 +1959,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_trans_handle *trans;
struct btrfs_log_ctx ctx;
- int ret = 0;
+ int ret = 0, wb_ret;
bool full_sync = 0;
u64 len;
errseq_t wb_since = READ_ONCE(file->f_wb_err);
@@ -2143,9 +2143,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
* therefore we need to check for errors in the ordered operations,
* which are indicated by ctx.io_err.
*/
- if (ctx.io_err) {
+ wb_ret = filemap_check_wb_error(inode->i_mapping, ctx.io_err);
+ if (wb_ret) {
+ ret = wb_ret;
btrfs_end_transaction(trans);
- ret = ctx.io_err;
goto out;
}
@@ -4079,11 +4079,6 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
if (ret)
return ret;
- if (ordered_io_err) {
- ctx->io_err = -EIO;
- return 0;
- }
-
btrfs_init_map_token(&token);
ret = __btrfs_drop_extents(trans, log, &inode->vfs_inode, path, em->start,
@@ -4165,7 +4160,6 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
u64 test_gen;
int ret = 0;
int num = 0;
- errseq_t since = filemap_sample_wb_error(inode->vfs_inode.i_mapping);
INIT_LIST_HEAD(&extents);
@@ -4199,19 +4193,6 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
list_sort(NULL, &extents, extent_cmp);
btrfs_get_logged_extents(inode, logged_list, start, end);
- /*
- * Some ordered extents started by fsync might have completed
- * before we could collect them into the list logged_list, which
- * means they're gone, not in our logged_list nor in the inode's
- * ordered tree. We want the application/user space to know an
- * error happened while attempting to persist file data so that
- * it can take proper action. If such error happened, we leave
- * without writing to the log tree and the fsync must report the
- * file data write error and not commit the current transaction.
- */
- ret = filemap_check_wb_error(inode->vfs_inode.i_mapping, since);
- if (ret)
- ctx->io_err = ret;
process:
while (!list_empty(&extents)) {
em = list_entry(extents.next, struct extent_map, list);
@@ -42,6 +42,8 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
ctx->io_err = 0;
ctx->log_new_dentries = false;
ctx->inode = inode;
+ if (inode)
+ ctx->io_err = filemap_sample_wb_error(inode->i_mapping);
INIT_LIST_HEAD(&ctx->list);
}