Skip to content

Commit 65ae689

Browse files
committed
Merge tag 'for-5.1-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - fsync fixes: i_size for truncate vs fsync, dio vs buffered during snapshotting, remove complicated but incomplete assertion - removed excessive warnigs, misreported device stats updates - fix raid56 page mapping for 32bit arch - fixes reported by static analyzer * tag 'for-5.1-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: Btrfs: fix assertion failure on fsync with NO_HOLES enabled btrfs: Avoid possible qgroup_rsv_size overflow in btrfs_calculate_inode_block_rsv_size btrfs: Fix bound checking in qgroup_trace_new_subtree_blocks btrfs: raid56: properly unmap parity page in finish_parity_scrub() btrfs: don't report readahead errors and don't update statistics Btrfs: fix file corruption after snapshotting due to mix of buffered/DIO writes btrfs: remove WARN_ON in log_dir_items Btrfs: fix incorrect file size after shrinking truncate and fsync
2 parents 26a3b01 + 0ccc387 commit 65ae689

6 files changed

Lines changed: 72 additions & 21 deletions

File tree

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6174,7 +6174,7 @@ static void btrfs_calculate_inode_block_rsv_size(struct btrfs_fs_info *fs_info,
61746174
*
61756175
* This is overestimating in most cases.
61766176
*/
6177-
qgroup_rsv_size = outstanding_extents * fs_info->nodesize;
6177+
qgroup_rsv_size = (u64)outstanding_extents * fs_info->nodesize;
61786178

61796179
spin_lock(&block_rsv->lock);
61806180
block_rsv->size = reserve_size;

fs/btrfs/qgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,8 +1922,8 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,
19221922
int i;
19231923

19241924
/* Level sanity check */
1925-
if (cur_level < 0 || cur_level >= BTRFS_MAX_LEVEL ||
1926-
root_level < 0 || root_level >= BTRFS_MAX_LEVEL ||
1925+
if (cur_level < 0 || cur_level >= BTRFS_MAX_LEVEL - 1 ||
1926+
root_level < 0 || root_level >= BTRFS_MAX_LEVEL - 1 ||
19271927
root_level < cur_level) {
19281928
btrfs_err_rl(fs_info,
19291929
"%s: bad levels, cur_level=%d root_level=%d",

fs/btrfs/raid56.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,8 +2430,9 @@ static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio,
24302430
bitmap_clear(rbio->dbitmap, pagenr, 1);
24312431
kunmap(p);
24322432

2433-
for (stripe = 0; stripe < rbio->real_stripes; stripe++)
2433+
for (stripe = 0; stripe < nr_data; stripe++)
24342434
kunmap(page_in_rbio(rbio, stripe, pagenr, 0));
2435+
kunmap(p_page);
24352436
}
24362437

24372438
__free_page(p_page);

fs/btrfs/transaction.c

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,8 +1886,10 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
18861886
}
18871887
}
18881888

1889-
static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
1889+
static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans)
18901890
{
1891+
struct btrfs_fs_info *fs_info = trans->fs_info;
1892+
18911893
/*
18921894
* We use writeback_inodes_sb here because if we used
18931895
* btrfs_start_delalloc_roots we would deadlock with fs freeze.
@@ -1897,15 +1899,50 @@ static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
18971899
* from already being in a transaction and our join_transaction doesn't
18981900
* have to re-take the fs freeze lock.
18991901
*/
1900-
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
1902+
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
19011903
writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
1904+
} else {
1905+
struct btrfs_pending_snapshot *pending;
1906+
struct list_head *head = &trans->transaction->pending_snapshots;
1907+
1908+
/*
1909+
* Flush dellaloc for any root that is going to be snapshotted.
1910+
* This is done to avoid a corrupted version of files, in the
1911+
* snapshots, that had both buffered and direct IO writes (even
1912+
* if they were done sequentially) due to an unordered update of
1913+
* the inode's size on disk.
1914+
*/
1915+
list_for_each_entry(pending, head, list) {
1916+
int ret;
1917+
1918+
ret = btrfs_start_delalloc_snapshot(pending->root);
1919+
if (ret)
1920+
return ret;
1921+
}
1922+
}
19021923
return 0;
19031924
}
19041925

1905-
static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info)
1926+
static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans)
19061927
{
1907-
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
1928+
struct btrfs_fs_info *fs_info = trans->fs_info;
1929+
1930+
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
19081931
btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
1932+
} else {
1933+
struct btrfs_pending_snapshot *pending;
1934+
struct list_head *head = &trans->transaction->pending_snapshots;
1935+
1936+
/*
1937+
* Wait for any dellaloc that we started previously for the roots
1938+
* that are going to be snapshotted. This is to avoid a corrupted
1939+
* version of files in the snapshots that had both buffered and
1940+
* direct IO writes (even if they were done sequentially).
1941+
*/
1942+
list_for_each_entry(pending, head, list)
1943+
btrfs_wait_ordered_extents(pending->root,
1944+
U64_MAX, 0, U64_MAX);
1945+
}
19091946
}
19101947

19111948
int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
@@ -2023,7 +2060,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
20232060

20242061
extwriter_counter_dec(cur_trans, trans->type);
20252062

2026-
ret = btrfs_start_delalloc_flush(fs_info);
2063+
ret = btrfs_start_delalloc_flush(trans);
20272064
if (ret)
20282065
goto cleanup_transaction;
20292066

@@ -2039,7 +2076,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
20392076
if (ret)
20402077
goto cleanup_transaction;
20412078

2042-
btrfs_wait_delalloc_flush(fs_info);
2079+
btrfs_wait_delalloc_flush(trans);
20432080

20442081
btrfs_scrub_pause(fs_info);
20452082
/*

fs/btrfs/tree-log.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,9 +3578,16 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
35783578
}
35793579
btrfs_release_path(path);
35803580

3581-
/* find the first key from this transaction again */
3581+
/*
3582+
* Find the first key from this transaction again. See the note for
3583+
* log_new_dir_dentries, if we're logging a directory recursively we
3584+
* won't be holding its i_mutex, which means we can modify the directory
3585+
* while we're logging it. If we remove an entry between our first
3586+
* search and this search we'll not find the key again and can just
3587+
* bail.
3588+
*/
35823589
ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0);
3583-
if (WARN_ON(ret != 0))
3590+
if (ret != 0)
35843591
goto done;
35853592

35863593
/*
@@ -4544,6 +4551,19 @@ static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode,
45444551
item = btrfs_item_ptr(path->nodes[0], path->slots[0],
45454552
struct btrfs_inode_item);
45464553
*size_ret = btrfs_inode_size(path->nodes[0], item);
4554+
/*
4555+
* If the in-memory inode's i_size is smaller then the inode
4556+
* size stored in the btree, return the inode's i_size, so
4557+
* that we get a correct inode size after replaying the log
4558+
* when before a power failure we had a shrinking truncate
4559+
* followed by addition of a new name (rename / new hard link).
4560+
* Otherwise return the inode size from the btree, to avoid
4561+
* data loss when replaying a log due to previously doing a
4562+
* write that expands the inode's size and logging a new name
4563+
* immediately after.
4564+
*/
4565+
if (*size_ret > inode->vfs_inode.i_size)
4566+
*size_ret = inode->vfs_inode.i_size;
45474567
}
45484568

45494569
btrfs_release_path(path);
@@ -4705,15 +4725,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans,
47054725
struct btrfs_file_extent_item);
47064726

47074727
if (btrfs_file_extent_type(leaf, extent) ==
4708-
BTRFS_FILE_EXTENT_INLINE) {
4709-
len = btrfs_file_extent_ram_bytes(leaf, extent);
4710-
ASSERT(len == i_size ||
4711-
(len == fs_info->sectorsize &&
4712-
btrfs_file_extent_compression(leaf, extent) !=
4713-
BTRFS_COMPRESS_NONE) ||
4714-
(len < i_size && i_size < fs_info->sectorsize));
4728+
BTRFS_FILE_EXTENT_INLINE)
47154729
return 0;
4716-
}
47174730

47184731
len = btrfs_file_extent_num_bytes(leaf, extent);
47194732
/* Last extent goes beyond i_size, no need to log a hole. */

fs/btrfs/volumes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6407,7 +6407,7 @@ static void btrfs_end_bio(struct bio *bio)
64076407
if (bio_op(bio) == REQ_OP_WRITE)
64086408
btrfs_dev_stat_inc_and_print(dev,
64096409
BTRFS_DEV_STAT_WRITE_ERRS);
6410-
else
6410+
else if (!(bio->bi_opf & REQ_RAHEAD))
64116411
btrfs_dev_stat_inc_and_print(dev,
64126412
BTRFS_DEV_STAT_READ_ERRS);
64136413
if (bio->bi_opf & REQ_PREFLUSH)

0 commit comments

Comments
 (0)