aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Jain <Anand.Jain@oracle.com>2018-01-18 09:00:34 -0500
committerDavid Sterba <dsterba@suse.com>2018-01-22 14:25:47 -0500
commit38cf665d338fca33af4b16f9ec7cad6637fc0fec (patch)
tree7090eab239f1d9fc9c2f1ba0bf3743f961bb5a04
parenta848b3e547d167692483ff08622bb56dd3e4a9d6 (diff)
btrfs: make btrfs_free_stale_device() to iterate all stales
Let the list iterator iterate further and find other stale devices and delete it. This is in preparation to add support for user land request-able stale devices cleanup. Also rename btrfs_free_stale_device() to btrfs_free_stale_devices(). Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/volumes.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 011bb9b116e6..207014fce7ea 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -605,21 +605,22 @@ static void pending_bios_fn(struct btrfs_work *work)
605} 605}
606 606
607 607
608static void btrfs_free_stale_device(struct btrfs_device *cur_dev) 608static void btrfs_free_stale_devices(struct btrfs_device *cur_dev)
609{ 609{
610 struct btrfs_fs_devices *fs_devs; 610 struct btrfs_fs_devices *fs_devs, *tmp_fs_devs;
611 struct btrfs_device *dev; 611 struct btrfs_device *dev, *tmp_dev;
612 612
613 if (!cur_dev->name) 613 if (!cur_dev->name)
614 return; 614 return;
615 615
616 list_for_each_entry(fs_devs, &fs_uuids, list) { 616 list_for_each_entry_safe(fs_devs, tmp_fs_devs, &fs_uuids, list) {
617 int del = 1;
618 617
619 if (fs_devs->opened) 618 if (fs_devs->opened)
620 continue; 619 continue;
621 620
622 list_for_each_entry(dev, &fs_devs->devices, dev_list) { 621 list_for_each_entry_safe(dev, tmp_dev,
622 &fs_devs->devices, dev_list) {
623 int not_found;
623 624
624 if (dev == cur_dev) 625 if (dev == cur_dev)
625 continue; 626 continue;
@@ -633,14 +634,12 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)
633 * either use mapper or non mapper path throughout. 634 * either use mapper or non mapper path throughout.
634 */ 635 */
635 rcu_read_lock(); 636 rcu_read_lock();
636 del = strcmp(rcu_str_deref(dev->name), 637 not_found = strcmp(rcu_str_deref(dev->name),
637 rcu_str_deref(cur_dev->name)); 638 rcu_str_deref(cur_dev->name));
638 rcu_read_unlock(); 639 rcu_read_unlock();
639 if (!del) 640 if (not_found)
640 break; 641 continue;
641 }
642 642
643 if (!del) {
644 /* delete the stale device */ 643 /* delete the stale device */
645 if (fs_devs->num_devices == 1) { 644 if (fs_devs->num_devices == 1) {
646 btrfs_sysfs_remove_fsid(fs_devs); 645 btrfs_sysfs_remove_fsid(fs_devs);
@@ -651,7 +650,6 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)
651 list_del(&dev->dev_list); 650 list_del(&dev->dev_list);
652 free_device(dev); 651 free_device(dev);
653 } 652 }
654 break;
655 } 653 }
656 } 654 }
657} 655}
@@ -779,7 +777,7 @@ static noinline int device_list_add(const char *path,
779 777
780 ret = 1; 778 ret = 1;
781 device->fs_devices = fs_devices; 779 device->fs_devices = fs_devices;
782 btrfs_free_stale_device(device); 780 btrfs_free_stale_devices(device);
783 } else if (!device->name || strcmp(device->name->str, path)) { 781 } else if (!device->name || strcmp(device->name->str, path)) {
784 /* 782 /*
785 * When FS is already mounted. 783 * When FS is already mounted.