Skip to content

Commit ff023aa

Browse files
Stefan BehrensJosef Bacik
authored andcommitted
Btrfs: add code to scrub to copy read data to another disk
The device replace procedure makes use of the scrub code. The scrub code is the most efficient code to read the allocated data of a disk, i.e. it reads sequentially in order to avoid disk head movements, it skips unallocated blocks, it uses read ahead mechanisms, and it contains all the code to detect and repair defects. This commit adds code to scrub to allow the scrub code to copy read data to another disk. One goal is to be able to perform as fast as possible. Therefore the write requests are collected until huge bios are built, and the write process is decoupled from the read process with some kind of flow control, of course, in order to limit the allocated memory. The best performance on spinning disks could by reached when the head movements are avoided as much as possible. Therefore a single worker is used to interface the read process with the write process. The regular scrub operation works as fast as before, it is not negatively influenced and actually it is more or less unchanged. Signed-off-by: Stefan Behrens <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 6189192 commit ff023aa

File tree

5 files changed

+851
-73
lines changed

5 files changed

+851
-73
lines changed

fs/btrfs/ctree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,8 @@ struct btrfs_fs_info {
14831483
struct rw_semaphore scrub_super_lock;
14841484
int scrub_workers_refcnt;
14851485
struct btrfs_workers scrub_workers;
1486+
struct btrfs_workers scrub_wr_completion_workers;
1487+
struct btrfs_workers scrub_nocow_workers;
14861488

14871489
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
14881490
u32 check_integrity_print_mask;

fs/btrfs/dev-replace.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) STRATO AG 2012. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public
6+
* License v2 as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public
14+
* License along with this program; if not, write to the
15+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16+
* Boston, MA 021110-1307, USA.
17+
*/
18+
19+
#if !defined(__BTRFS_DEV_REPLACE__)
20+
#define __BTRFS_DEV_REPLACE__
21+
22+
static inline void btrfs_dev_replace_stats_inc(atomic64_t *stat_value)
23+
{
24+
atomic64_inc(stat_value);
25+
}
26+
#endif

fs/btrfs/reada.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,17 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
418418
*/
419419
continue;
420420
}
421+
if (!dev->bdev) {
422+
/* cannot read ahead on missing device */
423+
continue;
424+
}
421425
prev_dev = dev;
422426
ret = radix_tree_insert(&dev->reada_extents, index, re);
423427
if (ret) {
424428
while (--i >= 0) {
425429
dev = bbio->stripes[i].dev;
426430
BUG_ON(dev == NULL);
431+
/* ignore whether the entry was inserted */
427432
radix_tree_delete(&dev->reada_extents, index);
428433
}
429434
BUG_ON(fs_info == NULL);
@@ -914,7 +919,10 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root,
914919
generation = btrfs_header_generation(node);
915920
free_extent_buffer(node);
916921

917-
reada_add_block(rc, start, &max_key, level, generation);
922+
if (reada_add_block(rc, start, &max_key, level, generation)) {
923+
kfree(rc);
924+
return ERR_PTR(-ENOMEM);
925+
}
918926

919927
reada_start_machine(root->fs_info);
920928

0 commit comments

Comments
 (0)