Skip to content

Commit 90290c4

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-next
Pull btrfs fixes from Josef Bacik: "I'm playing the role of Chris Mason this week while he's on vacation. There are a few critical fixes for btrfs here, all regressions and have been tested well" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-next: Btrfs: fix wrong write offset when replacing a device Btrfs: re-add root to dead root list if we stop dropping it Btrfs: fix lock leak when resuming snapshot deletion Btrfs: update drop progress before stopping snapshot dropping
2 parents d471ce5 + 115930c commit 90290c4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

fs/btrfs/extent-tree.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7466,6 +7466,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
74667466
int err = 0;
74677467
int ret;
74687468
int level;
7469+
bool root_dropped = false;
74697470

74707471
path = btrfs_alloc_path();
74717472
if (!path) {
@@ -7523,6 +7524,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
75237524
while (1) {
75247525
btrfs_tree_lock(path->nodes[level]);
75257526
btrfs_set_lock_blocking(path->nodes[level]);
7527+
path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
75267528

75277529
ret = btrfs_lookup_extent_info(trans, root,
75287530
path->nodes[level]->start,
@@ -7538,6 +7540,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
75387540
break;
75397541

75407542
btrfs_tree_unlock(path->nodes[level]);
7543+
path->locks[level] = 0;
75417544
WARN_ON(wc->refs[level] != 1);
75427545
level--;
75437546
}
@@ -7552,11 +7555,6 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
75527555
wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root);
75537556

75547557
while (1) {
7555-
if (!for_reloc && btrfs_need_cleaner_sleep(root)) {
7556-
pr_debug("btrfs: drop snapshot early exit\n");
7557-
err = -EAGAIN;
7558-
goto out_end_trans;
7559-
}
75607558

75617559
ret = walk_down_tree(trans, root, path, wc);
75627560
if (ret < 0) {
@@ -7584,7 +7582,8 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
75847582
}
75857583

75867584
BUG_ON(wc->level == 0);
7587-
if (btrfs_should_end_transaction(trans, tree_root)) {
7585+
if (btrfs_should_end_transaction(trans, tree_root) ||
7586+
(!for_reloc && btrfs_need_cleaner_sleep(root))) {
75887587
ret = btrfs_update_root(trans, tree_root,
75897588
&root->root_key,
75907589
root_item);
@@ -7595,6 +7594,12 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
75957594
}
75967595

75977596
btrfs_end_transaction_throttle(trans, tree_root);
7597+
if (!for_reloc && btrfs_need_cleaner_sleep(root)) {
7598+
pr_debug("btrfs: drop snapshot early exit\n");
7599+
err = -EAGAIN;
7600+
goto out_free;
7601+
}
7602+
75987603
trans = btrfs_start_transaction(tree_root, 0);
75997604
if (IS_ERR(trans)) {
76007605
err = PTR_ERR(trans);
@@ -7639,12 +7644,22 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
76397644
free_extent_buffer(root->commit_root);
76407645
btrfs_put_fs_root(root);
76417646
}
7647+
root_dropped = true;
76427648
out_end_trans:
76437649
btrfs_end_transaction_throttle(trans, tree_root);
76447650
out_free:
76457651
kfree(wc);
76467652
btrfs_free_path(path);
76477653
out:
7654+
/*
7655+
* So if we need to stop dropping the snapshot for whatever reason we
7656+
* need to make sure to add it back to the dead root list so that we
7657+
* keep trying to do the work later. This also cleans up roots if we
7658+
* don't have it in the radix (like when we recover after a power fail
7659+
* or unmount) so we don't leak memory.
7660+
*/
7661+
if (root_dropped == false)
7662+
btrfs_add_dead_root(root);
76487663
if (err)
76497664
btrfs_std_error(root->fs_info, err);
76507665
return err;

fs/btrfs/scrub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
24952495
ret = scrub_extent(sctx, extent_logical, extent_len,
24962496
extent_physical, extent_dev, flags,
24972497
generation, extent_mirror_num,
2498-
extent_physical);
2498+
extent_logical - logical + physical);
24992499
if (ret)
25002500
goto out;
25012501

0 commit comments

Comments
 (0)