Skip to content

Commit 82d2a34

Browse files
committed
Merge branch 'for-linus-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs fixes from Chris Mason: "This has a few fixes Dave Sterba had queued up. These are all pretty small, but since they were tested I decided against waiting for more" * 'for-linus-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: btrfs: transaction_kthread() is not freezable btrfs: cleaner_kthread() doesn't need explicit freeze btrfs: do not write corrupted metadata blocks to disk btrfs: csum_tree_block: return proper errno value
2 parents 22fed39 + 232cad8 commit 82d2a34

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

fs/btrfs/disk-io.c

+25-20
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/buffer_head.h>
2626
#include <linux/workqueue.h>
2727
#include <linux/kthread.h>
28-
#include <linux/freezer.h>
2928
#include <linux/slab.h>
3029
#include <linux/migrate.h>
3130
#include <linux/ratelimit.h>
@@ -303,7 +302,7 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
303302
err = map_private_extent_buffer(buf, offset, 32,
304303
&kaddr, &map_start, &map_len);
305304
if (err)
306-
return 1;
305+
return err;
307306
cur_len = min(len, map_len - (offset - map_start));
308307
crc = btrfs_csum_data(kaddr + offset - map_start,
309308
crc, cur_len);
@@ -313,7 +312,7 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
313312
if (csum_size > sizeof(inline_result)) {
314313
result = kzalloc(csum_size, GFP_NOFS);
315314
if (!result)
316-
return 1;
315+
return -ENOMEM;
317316
} else {
318317
result = (char *)&inline_result;
319318
}
@@ -334,7 +333,7 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
334333
val, found, btrfs_header_level(buf));
335334
if (result != (char *)&inline_result)
336335
kfree(result);
337-
return 1;
336+
return -EUCLEAN;
338337
}
339338
} else {
340339
write_extent_buffer(buf, result, 0, csum_size);
@@ -513,11 +512,21 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)
513512
eb = (struct extent_buffer *)page->private;
514513
if (page != eb->pages[0])
515514
return 0;
515+
516516
found_start = btrfs_header_bytenr(eb);
517-
if (WARN_ON(found_start != start || !PageUptodate(page)))
518-
return 0;
519-
csum_tree_block(fs_info, eb, 0);
520-
return 0;
517+
/*
518+
* Please do not consolidate these warnings into a single if.
519+
* It is useful to know what went wrong.
520+
*/
521+
if (WARN_ON(found_start != start))
522+
return -EUCLEAN;
523+
if (WARN_ON(!PageUptodate(page)))
524+
return -EUCLEAN;
525+
526+
ASSERT(memcmp_extent_buffer(eb, fs_info->fsid,
527+
btrfs_header_fsid(), BTRFS_FSID_SIZE) == 0);
528+
529+
return csum_tree_block(fs_info, eb, 0);
521530
}
522531

523532
static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
@@ -661,10 +670,8 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
661670
eb, found_level);
662671

663672
ret = csum_tree_block(fs_info, eb, 1);
664-
if (ret) {
665-
ret = -EIO;
673+
if (ret)
666674
goto err;
667-
}
668675

669676
/*
670677
* If this is a leaf block and it is corrupt, set the corrupt bit so
@@ -1831,7 +1838,7 @@ static int cleaner_kthread(void *arg)
18311838
*/
18321839
btrfs_delete_unused_bgs(root->fs_info);
18331840
sleep:
1834-
if (!try_to_freeze() && !again) {
1841+
if (!again) {
18351842
set_current_state(TASK_INTERRUPTIBLE);
18361843
if (!kthread_should_stop())
18371844
schedule();
@@ -1921,14 +1928,12 @@ static int transaction_kthread(void *arg)
19211928
if (unlikely(test_bit(BTRFS_FS_STATE_ERROR,
19221929
&root->fs_info->fs_state)))
19231930
btrfs_cleanup_transaction(root);
1924-
if (!try_to_freeze()) {
1925-
set_current_state(TASK_INTERRUPTIBLE);
1926-
if (!kthread_should_stop() &&
1927-
(!btrfs_transaction_blocked(root->fs_info) ||
1928-
cannot_commit))
1929-
schedule_timeout(delay);
1930-
__set_current_state(TASK_RUNNING);
1931-
}
1931+
set_current_state(TASK_INTERRUPTIBLE);
1932+
if (!kthread_should_stop() &&
1933+
(!btrfs_transaction_blocked(root->fs_info) ||
1934+
cannot_commit))
1935+
schedule_timeout(delay);
1936+
__set_current_state(TASK_RUNNING);
19321937
} while (!kthread_should_stop());
19331938
return 0;
19341939
}

0 commit comments

Comments
 (0)