Skip to content

Commit 142b507

Browse files
committed
Merge tag 'for-5.13-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "First batch of various fixes, here's a list of notable ones: - fix unmountable seed device after fstrim - fix silent data loss in zoned mode due to ordered extent splitting - fix race leading to unpersisted data and metadata on fsync - fix deadlock when cloning inline extents and using qgroups" * tag 'for-5.13-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: initialize return variable in cleanup_free_space_cache_v1 btrfs: zoned: sanity check zone type btrfs: fix unmountable seed device after fstrim btrfs: fix deadlock when cloning inline extents and using qgroups btrfs: fix race leading to unpersisted data and metadata on fsync btrfs: do not consider send context as valid when trying to flush qgroups btrfs: zoned: fix silent data loss after failure splitting ordered extent
2 parents 0aa099a + 77364fa commit 142b507

File tree

11 files changed

+55
-26
lines changed

11 files changed

+55
-26
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
31273127
struct btrfs_inode *inode, u64 new_size,
31283128
u32 min_type);
31293129

3130-
int btrfs_start_delalloc_snapshot(struct btrfs_root *root);
3130+
int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context);
31313131
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
31323132
bool in_reclaim_context);
31333133
int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,

fs/btrfs/extent-tree.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,12 +1340,16 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
13401340
stripe = bbio->stripes;
13411341
for (i = 0; i < bbio->num_stripes; i++, stripe++) {
13421342
u64 bytes;
1343+
struct btrfs_device *device = stripe->dev;
13431344

1344-
if (!stripe->dev->bdev) {
1345+
if (!device->bdev) {
13451346
ASSERT(btrfs_test_opt(fs_info, DEGRADED));
13461347
continue;
13471348
}
13481349

1350+
if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state))
1351+
continue;
1352+
13491353
ret = do_discard_extent(stripe, &bytes);
13501354
if (!ret) {
13511355
discarded_bytes += bytes;

fs/btrfs/file.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,30 @@ static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
20672067
return ret;
20682068
}
20692069

2070+
static inline bool skip_inode_logging(const struct btrfs_log_ctx *ctx)
2071+
{
2072+
struct btrfs_inode *inode = BTRFS_I(ctx->inode);
2073+
struct btrfs_fs_info *fs_info = inode->root->fs_info;
2074+
2075+
if (btrfs_inode_in_log(inode, fs_info->generation) &&
2076+
list_empty(&ctx->ordered_extents))
2077+
return true;
2078+
2079+
/*
2080+
* If we are doing a fast fsync we can not bail out if the inode's
2081+
* last_trans is <= then the last committed transaction, because we only
2082+
* update the last_trans of the inode during ordered extent completion,
2083+
* and for a fast fsync we don't wait for that, we only wait for the
2084+
* writeback to complete.
2085+
*/
2086+
if (inode->last_trans <= fs_info->last_trans_committed &&
2087+
(test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) ||
2088+
list_empty(&ctx->ordered_extents)))
2089+
return true;
2090+
2091+
return false;
2092+
}
2093+
20702094
/*
20712095
* fsync call for both files and directories. This logs the inode into
20722096
* the tree log instead of forcing full commits whenever possible.
@@ -2185,17 +2209,8 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
21852209

21862210
atomic_inc(&root->log_batch);
21872211

2188-
/*
2189-
* If we are doing a fast fsync we can not bail out if the inode's
2190-
* last_trans is <= then the last committed transaction, because we only
2191-
* update the last_trans of the inode during ordered extent completion,
2192-
* and for a fast fsync we don't wait for that, we only wait for the
2193-
* writeback to complete.
2194-
*/
21952212
smp_mb();
2196-
if (btrfs_inode_in_log(BTRFS_I(inode), fs_info->generation) ||
2197-
(BTRFS_I(inode)->last_trans <= fs_info->last_trans_committed &&
2198-
(full_sync || list_empty(&ctx.ordered_extents)))) {
2213+
if (skip_inode_logging(&ctx)) {
21992214
/*
22002215
* We've had everything committed since the last time we were
22012216
* modified so clear this flag in case it was set for whatever

fs/btrfs/free-space-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3949,7 +3949,7 @@ static int cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info,
39493949
{
39503950
struct btrfs_block_group *block_group;
39513951
struct rb_node *node;
3952-
int ret;
3952+
int ret = 0;
39533953

39543954
btrfs_info(fs_info, "cleaning free space cache v1");
39553955

fs/btrfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9678,7 +9678,7 @@ static int start_delalloc_inodes(struct btrfs_root *root,
96789678
return ret;
96799679
}
96809680

9681-
int btrfs_start_delalloc_snapshot(struct btrfs_root *root)
9681+
int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context)
96829682
{
96839683
struct writeback_control wbc = {
96849684
.nr_to_write = LONG_MAX,
@@ -9691,7 +9691,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root)
96919691
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
96929692
return -EROFS;
96939693

9694-
return start_delalloc_inodes(root, &wbc, true, false);
9694+
return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
96959695
}
96969696

96979697
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,

fs/btrfs/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ static noinline int btrfs_mksnapshot(const struct path *parent,
907907
*/
908908
btrfs_drew_read_lock(&root->snapshot_lock);
909909

910-
ret = btrfs_start_delalloc_snapshot(root);
910+
ret = btrfs_start_delalloc_snapshot(root, false);
911911
if (ret)
912912
goto out;
913913

fs/btrfs/ordered-data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
984984

985985
if (pre)
986986
ret = clone_ordered_extent(ordered, 0, pre);
987-
if (post)
987+
if (ret == 0 && post)
988988
ret = clone_ordered_extent(ordered, pre + ordered->disk_num_bytes,
989989
post);
990990

fs/btrfs/qgroup.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,11 +3545,15 @@ static int try_flush_qgroup(struct btrfs_root *root)
35453545
struct btrfs_trans_handle *trans;
35463546
int ret;
35473547

3548-
/* Can't hold an open transaction or we run the risk of deadlocking */
3549-
ASSERT(current->journal_info == NULL ||
3550-
current->journal_info == BTRFS_SEND_TRANS_STUB);
3551-
if (WARN_ON(current->journal_info &&
3552-
current->journal_info != BTRFS_SEND_TRANS_STUB))
3548+
/*
3549+
* Can't hold an open transaction or we run the risk of deadlocking,
3550+
* and can't either be under the context of a send operation (where
3551+
* current->journal_info is set to BTRFS_SEND_TRANS_STUB), as that
3552+
* would result in a crash when starting a transaction and does not
3553+
* make sense either (send is a read-only operation).
3554+
*/
3555+
ASSERT(current->journal_info == NULL);
3556+
if (WARN_ON(current->journal_info))
35533557
return 0;
35543558

35553559
/*
@@ -3562,7 +3566,7 @@ static int try_flush_qgroup(struct btrfs_root *root)
35623566
return 0;
35633567
}
35643568

3565-
ret = btrfs_start_delalloc_snapshot(root);
3569+
ret = btrfs_start_delalloc_snapshot(root, true);
35663570
if (ret < 0)
35673571
goto out;
35683572
btrfs_wait_ordered_extents(root, U64_MAX, 0, (u64)-1);

fs/btrfs/send.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7170,15 +7170,15 @@ static int flush_delalloc_roots(struct send_ctx *sctx)
71707170
int i;
71717171

71727172
if (root) {
7173-
ret = btrfs_start_delalloc_snapshot(root);
7173+
ret = btrfs_start_delalloc_snapshot(root, false);
71747174
if (ret)
71757175
return ret;
71767176
btrfs_wait_ordered_extents(root, U64_MAX, 0, U64_MAX);
71777177
}
71787178

71797179
for (i = 0; i < sctx->clone_roots_cnt; i++) {
71807180
root = sctx->clone_roots[i].root;
7181-
ret = btrfs_start_delalloc_snapshot(root);
7181+
ret = btrfs_start_delalloc_snapshot(root, false);
71827182
if (ret)
71837183
return ret;
71847184
btrfs_wait_ordered_extents(root, U64_MAX, 0, U64_MAX);

fs/btrfs/tree-log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6061,7 +6061,8 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
60616061
* (since logging them is pointless, a link count of 0 means they
60626062
* will never be accessible).
60636063
*/
6064-
if (btrfs_inode_in_log(inode, trans->transid) ||
6064+
if ((btrfs_inode_in_log(inode, trans->transid) &&
6065+
list_empty(&ctx->ordered_extents)) ||
60656066
inode->vfs_inode.i_nlink == 0) {
60666067
ret = BTRFS_NO_LOG_SYNC;
60676068
goto end_no_trans;

0 commit comments

Comments
 (0)