aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/reada.c
diff options
context:
space:
mode:
authorStefan Behrens <sbehrens@giantdisaster.de>2012-11-06 07:15:27 -0500
committerJosef Bacik <jbacik@fusionio.com>2012-12-12 17:15:42 -0500
commit8dabb7420f014ab0f9f04afae8ae046c0f48b270 (patch)
tree6342f353ac71003d749a776dd6dc6a18b1bd959b /fs/btrfs/reada.c
parente93c89c1aaaaaec3487c4c18dd02360371790722 (diff)
Btrfs: change core code of btrfs to support the device replace operations
This commit contains all the essential changes to the core code of Btrfs for support of the device replace procedure. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs/btrfs/reada.c')
-rw-r--r--fs/btrfs/reada.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index 9f363e17ec74..c705a48e676b 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -27,6 +27,7 @@
27#include "volumes.h" 27#include "volumes.h"
28#include "disk-io.h" 28#include "disk-io.h"
29#include "transaction.h" 29#include "transaction.h"
30#include "dev-replace.h"
30 31
31#undef DEBUG 32#undef DEBUG
32 33
@@ -331,6 +332,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
331 int nzones = 0; 332 int nzones = 0;
332 int i; 333 int i;
333 unsigned long index = logical >> PAGE_CACHE_SHIFT; 334 unsigned long index = logical >> PAGE_CACHE_SHIFT;
335 int dev_replace_is_ongoing;
334 336
335 spin_lock(&fs_info->reada_lock); 337 spin_lock(&fs_info->reada_lock);
336 re = radix_tree_lookup(&fs_info->reada_tree, index); 338 re = radix_tree_lookup(&fs_info->reada_tree, index);
@@ -392,6 +394,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
392 } 394 }
393 395
394 /* insert extent in reada_tree + all per-device trees, all or nothing */ 396 /* insert extent in reada_tree + all per-device trees, all or nothing */
397 btrfs_dev_replace_lock(&fs_info->dev_replace);
395 spin_lock(&fs_info->reada_lock); 398 spin_lock(&fs_info->reada_lock);
396 ret = radix_tree_insert(&fs_info->reada_tree, index, re); 399 ret = radix_tree_insert(&fs_info->reada_tree, index, re);
397 if (ret == -EEXIST) { 400 if (ret == -EEXIST) {
@@ -399,13 +402,17 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
399 BUG_ON(!re_exist); 402 BUG_ON(!re_exist);
400 re_exist->refcnt++; 403 re_exist->refcnt++;
401 spin_unlock(&fs_info->reada_lock); 404 spin_unlock(&fs_info->reada_lock);
405 btrfs_dev_replace_unlock(&fs_info->dev_replace);
402 goto error; 406 goto error;
403 } 407 }
404 if (ret) { 408 if (ret) {
405 spin_unlock(&fs_info->reada_lock); 409 spin_unlock(&fs_info->reada_lock);
410 btrfs_dev_replace_unlock(&fs_info->dev_replace);
406 goto error; 411 goto error;
407 } 412 }
408 prev_dev = NULL; 413 prev_dev = NULL;
414 dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(
415 &fs_info->dev_replace);
409 for (i = 0; i < nzones; ++i) { 416 for (i = 0; i < nzones; ++i) {
410 dev = bbio->stripes[i].dev; 417 dev = bbio->stripes[i].dev;
411 if (dev == prev_dev) { 418 if (dev == prev_dev) {
@@ -422,6 +429,14 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
422 /* cannot read ahead on missing device */ 429 /* cannot read ahead on missing device */
423 continue; 430 continue;
424 } 431 }
432 if (dev_replace_is_ongoing &&
433 dev == fs_info->dev_replace.tgtdev) {
434 /*
435 * as this device is selected for reading only as
436 * a last resort, skip it for read ahead.
437 */
438 continue;
439 }
425 prev_dev = dev; 440 prev_dev = dev;
426 ret = radix_tree_insert(&dev->reada_extents, index, re); 441 ret = radix_tree_insert(&dev->reada_extents, index, re);
427 if (ret) { 442 if (ret) {
@@ -434,10 +449,12 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
434 BUG_ON(fs_info == NULL); 449 BUG_ON(fs_info == NULL);
435 radix_tree_delete(&fs_info->reada_tree, index); 450 radix_tree_delete(&fs_info->reada_tree, index);
436 spin_unlock(&fs_info->reada_lock); 451 spin_unlock(&fs_info->reada_lock);
452 btrfs_dev_replace_unlock(&fs_info->dev_replace);
437 goto error; 453 goto error;
438 } 454 }
439 } 455 }
440 spin_unlock(&fs_info->reada_lock); 456 spin_unlock(&fs_info->reada_lock);
457 btrfs_dev_replace_unlock(&fs_info->dev_replace);
441 458
442 kfree(bbio); 459 kfree(bbio);
443 return re; 460 return re;