aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-05-13 13:46:40 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:03 -0400
commitdfe25020689bb2d318782d2c9c7141203583fc70 (patch)
treee106059546d7755af0d3b86bf47c113ca8927d7d /fs/btrfs/volumes.c
parent1259ab75c62462b8ffad90067b5e1f6312786a18 (diff)
Btrfs: Add mount -o degraded to allow mounts to continue with missing devices
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c279
1 files changed, 201 insertions, 78 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5fc7fb481474..43f74d17bcea 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -73,6 +73,7 @@ int btrfs_cleanup_fs_uuids(void)
73 close_bdev_excl(dev->bdev); 73 close_bdev_excl(dev->bdev);
74 } 74 }
75 list_del(&dev->dev_list); 75 list_del(&dev->dev_list);
76 kfree(dev->name);
76 kfree(dev); 77 kfree(dev);
77 } 78 }
78 } 79 }
@@ -127,7 +128,6 @@ static int device_list_add(const char *path,
127 memcpy(fs_devices->fsid, disk_super->fsid, BTRFS_FSID_SIZE); 128 memcpy(fs_devices->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
128 fs_devices->latest_devid = devid; 129 fs_devices->latest_devid = devid;
129 fs_devices->latest_trans = found_transid; 130 fs_devices->latest_trans = found_transid;
130 fs_devices->lowest_devid = (u64)-1;
131 fs_devices->num_devices = 0; 131 fs_devices->num_devices = 0;
132 device = NULL; 132 device = NULL;
133 } else { 133 } else {
@@ -159,13 +159,35 @@ static int device_list_add(const char *path,
159 fs_devices->latest_devid = devid; 159 fs_devices->latest_devid = devid;
160 fs_devices->latest_trans = found_transid; 160 fs_devices->latest_trans = found_transid;
161 } 161 }
162 if (fs_devices->lowest_devid > devid) {
163 fs_devices->lowest_devid = devid;
164 }
165 *fs_devices_ret = fs_devices; 162 *fs_devices_ret = fs_devices;
166 return 0; 163 return 0;
167} 164}
168 165
166int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices)
167{
168 struct list_head *head = &fs_devices->devices;
169 struct list_head *cur;
170 struct btrfs_device *device;
171
172 mutex_lock(&uuid_mutex);
173again:
174 list_for_each(cur, head) {
175 device = list_entry(cur, struct btrfs_device, dev_list);
176 if (!device->in_fs_metadata) {
177printk("getting rid of extra dev %s\n", device->name);
178 if (device->bdev)
179 close_bdev_excl(device->bdev);
180 list_del(&device->dev_list);
181 list_del(&device->dev_alloc_list);
182 fs_devices->num_devices--;
183 kfree(device->name);
184 kfree(device);
185 goto again;
186 }
187 }
188 mutex_unlock(&uuid_mutex);
189 return 0;
190}
169int btrfs_close_devices(struct btrfs_fs_devices *fs_devices) 191int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
170{ 192{
171 struct list_head *head = &fs_devices->devices; 193 struct list_head *head = &fs_devices->devices;
@@ -179,6 +201,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
179 close_bdev_excl(device->bdev); 201 close_bdev_excl(device->bdev);
180 } 202 }
181 device->bdev = NULL; 203 device->bdev = NULL;
204 device->in_fs_metadata = 0;
182 } 205 }
183 mutex_unlock(&uuid_mutex); 206 mutex_unlock(&uuid_mutex);
184 return 0; 207 return 0;
@@ -199,6 +222,9 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
199 if (device->bdev) 222 if (device->bdev)
200 continue; 223 continue;
201 224
225 if (!device->name)
226 continue;
227
202 bdev = open_bdev_excl(device->name, flags, holder); 228 bdev = open_bdev_excl(device->name, flags, holder);
203 229
204 if (IS_ERR(bdev)) { 230 if (IS_ERR(bdev)) {
@@ -209,10 +235,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
209 set_blocksize(bdev, 4096); 235 set_blocksize(bdev, 4096);
210 if (device->devid == fs_devices->latest_devid) 236 if (device->devid == fs_devices->latest_devid)
211 fs_devices->latest_bdev = bdev; 237 fs_devices->latest_bdev = bdev;
212 if (device->devid == fs_devices->lowest_devid) {
213 fs_devices->lowest_bdev = bdev;
214 }
215 device->bdev = bdev; 238 device->bdev = bdev;
239 device->in_fs_metadata = 0;
216 240
217 } 241 }
218 mutex_unlock(&uuid_mutex); 242 mutex_unlock(&uuid_mutex);
@@ -439,7 +463,8 @@ int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
439 } 463 }
440 BUG_ON(ret); 464 BUG_ON(ret);
441 465
442 device->bytes_used -= btrfs_dev_extent_length(leaf, extent); 466 if (device->bytes_used > 0)
467 device->bytes_used -= btrfs_dev_extent_length(leaf, extent);
443 ret = btrfs_del_item(trans, root, path); 468 ret = btrfs_del_item(trans, root, path);
444 BUG_ON(ret); 469 BUG_ON(ret);
445 470
@@ -460,6 +485,7 @@ int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
460 struct extent_buffer *leaf; 485 struct extent_buffer *leaf;
461 struct btrfs_key key; 486 struct btrfs_key key;
462 487
488 WARN_ON(!device->in_fs_metadata);
463 path = btrfs_alloc_path(); 489 path = btrfs_alloc_path();
464 if (!path) 490 if (!path)
465 return -ENOMEM; 491 return -ENOMEM;
@@ -674,8 +700,6 @@ static int btrfs_rm_dev_item(struct btrfs_root *root,
674 700
675 next_dev = list_entry(fs_devices->devices.next, struct btrfs_device, 701 next_dev = list_entry(fs_devices->devices.next, struct btrfs_device,
676 dev_list); 702 dev_list);
677 if (bdev == fs_devices->lowest_bdev)
678 fs_devices->lowest_bdev = next_dev->bdev;
679 if (bdev == root->fs_info->sb->s_bdev) 703 if (bdev == root->fs_info->sb->s_bdev)
680 root->fs_info->sb->s_bdev = next_dev->bdev; 704 root->fs_info->sb->s_bdev = next_dev->bdev;
681 if (bdev == fs_devices->latest_bdev) 705 if (bdev == fs_devices->latest_bdev)
@@ -698,7 +722,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
698{ 722{
699 struct btrfs_device *device; 723 struct btrfs_device *device;
700 struct block_device *bdev; 724 struct block_device *bdev;
701 struct buffer_head *bh; 725 struct buffer_head *bh = NULL;
702 struct btrfs_super_block *disk_super; 726 struct btrfs_super_block *disk_super;
703 u64 all_avail; 727 u64 all_avail;
704 u64 devid; 728 u64 devid;
@@ -712,47 +736,73 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
712 root->fs_info->avail_metadata_alloc_bits; 736 root->fs_info->avail_metadata_alloc_bits;
713 737
714 if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && 738 if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) &&
715 root->fs_info->fs_devices->num_devices <= 4) { 739 btrfs_super_num_devices(&root->fs_info->super_copy) <= 4) {
716 printk("btrfs: unable to go below four devices on raid10\n"); 740 printk("btrfs: unable to go below four devices on raid10\n");
717 ret = -EINVAL; 741 ret = -EINVAL;
718 goto out; 742 goto out;
719 } 743 }
720 744
721 if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && 745 if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) &&
722 root->fs_info->fs_devices->num_devices <= 2) { 746 btrfs_super_num_devices(&root->fs_info->super_copy) <= 2) {
723 printk("btrfs: unable to go below two devices on raid1\n"); 747 printk("btrfs: unable to go below two devices on raid1\n");
724 ret = -EINVAL; 748 ret = -EINVAL;
725 goto out; 749 goto out;
726 } 750 }
727 751
728 bdev = open_bdev_excl(device_path, 0, root->fs_info->bdev_holder); 752 if (strcmp(device_path, "missing") == 0) {
729 if (IS_ERR(bdev)) { 753 struct list_head *cur;
730 ret = PTR_ERR(bdev); 754 struct list_head *devices;
731 goto out; 755 struct btrfs_device *tmp;
732 }
733 756
734 bh = __bread(bdev, BTRFS_SUPER_INFO_OFFSET / 4096, 4096); 757 device = NULL;
735 if (!bh) { 758 devices = &root->fs_info->fs_devices->devices;
736 ret = -EIO; 759 list_for_each(cur, devices) {
737 goto error_close; 760 tmp = list_entry(cur, struct btrfs_device, dev_list);
738 } 761 if (tmp->in_fs_metadata && !tmp->bdev) {
739 disk_super = (struct btrfs_super_block *)bh->b_data; 762 device = tmp;
740 if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC, 763 break;
741 sizeof(disk_super->magic))) { 764 }
742 ret = -ENOENT; 765 }
743 goto error_brelse; 766 bdev = NULL;
744 } 767 bh = NULL;
745 if (memcmp(disk_super->fsid, root->fs_info->fsid, BTRFS_FSID_SIZE)) { 768 disk_super = NULL;
746 ret = -ENOENT; 769 if (!device) {
747 goto error_brelse; 770 printk("btrfs: no missing devices found to remove\n");
748 } 771 goto out;
749 devid = le64_to_cpu(disk_super->dev_item.devid); 772 }
750 device = btrfs_find_device(root, devid, NULL); 773
751 if (!device) { 774 } else {
752 ret = -ENOENT; 775 bdev = open_bdev_excl(device_path, 0,
753 goto error_brelse; 776 root->fs_info->bdev_holder);
754 } 777 if (IS_ERR(bdev)) {
778 ret = PTR_ERR(bdev);
779 goto out;
780 }
781
782 bh = __bread(bdev, BTRFS_SUPER_INFO_OFFSET / 4096, 4096);
783 if (!bh) {
784 ret = -EIO;
785 goto error_close;
786 }
787 disk_super = (struct btrfs_super_block *)bh->b_data;
788 if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
789 sizeof(disk_super->magic))) {
790 ret = -ENOENT;
791 goto error_brelse;
792 }
793 if (memcmp(disk_super->fsid, root->fs_info->fsid,
794 BTRFS_FSID_SIZE)) {
795 ret = -ENOENT;
796 goto error_brelse;
797 }
798 devid = le64_to_cpu(disk_super->dev_item.devid);
799 device = btrfs_find_device(root, devid, NULL);
800 if (!device) {
801 ret = -ENOENT;
802 goto error_brelse;
803 }
755 804
805 }
756 root->fs_info->fs_devices->num_devices--; 806 root->fs_info->fs_devices->num_devices--;
757 807
758 ret = btrfs_shrink_device(device, 0); 808 ret = btrfs_shrink_device(device, 0);
@@ -764,19 +814,25 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
764 if (ret) 814 if (ret)
765 goto error_brelse; 815 goto error_brelse;
766 816
767 /* make sure this device isn't detected as part of the FS anymore */ 817 if (bh) {
768 memset(&disk_super->magic, 0, sizeof(disk_super->magic)); 818 /* make sure this device isn't detected as part of
769 set_buffer_dirty(bh); 819 * the FS anymore
770 sync_dirty_buffer(bh); 820 */
771 821 memset(&disk_super->magic, 0, sizeof(disk_super->magic));
772 brelse(bh); 822 set_buffer_dirty(bh);
773 823 sync_dirty_buffer(bh);
774 /* one close for the device struct or super_block */
775 close_bdev_excl(device->bdev);
776 824
777 /* one close for us */ 825 brelse(bh);
778 close_bdev_excl(device->bdev); 826 }
779 827
828 if (device->bdev) {
829 /* one close for the device struct or super_block */
830 close_bdev_excl(device->bdev);
831 }
832 if (bdev) {
833 /* one close for us */
834 close_bdev_excl(bdev);
835 }
780 kfree(device->name); 836 kfree(device->name);
781 kfree(device); 837 kfree(device);
782 ret = 0; 838 ret = 0;
@@ -785,7 +841,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
785error_brelse: 841error_brelse:
786 brelse(bh); 842 brelse(bh);
787error_close: 843error_close:
788 close_bdev_excl(bdev); 844 if (bdev)
845 close_bdev_excl(bdev);
789out: 846out:
790 mutex_unlock(&uuid_mutex); 847 mutex_unlock(&uuid_mutex);
791 mutex_unlock(&root->fs_info->fs_mutex); 848 mutex_unlock(&root->fs_info->fs_mutex);
@@ -839,6 +896,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
839 device->total_bytes = i_size_read(bdev->bd_inode); 896 device->total_bytes = i_size_read(bdev->bd_inode);
840 device->dev_root = root->fs_info->dev_root; 897 device->dev_root = root->fs_info->dev_root;
841 device->bdev = bdev; 898 device->bdev = bdev;
899 device->in_fs_metadata = 1;
842 900
843 ret = btrfs_add_device(trans, root, device); 901 ret = btrfs_add_device(trans, root, device);
844 if (ret) 902 if (ret)
@@ -1041,8 +1099,10 @@ int btrfs_relocate_chunk(struct btrfs_root *root,
1041 map->stripes[i].physical); 1099 map->stripes[i].physical);
1042 BUG_ON(ret); 1100 BUG_ON(ret);
1043 1101
1044 ret = btrfs_update_device(trans, map->stripes[i].dev); 1102 if (map->stripes[i].dev) {
1045 BUG_ON(ret); 1103 ret = btrfs_update_device(trans, map->stripes[i].dev);
1104 BUG_ON(ret);
1105 }
1046 } 1106 }
1047 ret = btrfs_free_chunk(trans, root, chunk_tree, chunk_objectid, 1107 ret = btrfs_free_chunk(trans, root, chunk_tree, chunk_objectid,
1048 chunk_offset); 1108 chunk_offset);
@@ -1415,10 +1475,13 @@ again:
1415 while(index < num_stripes) { 1475 while(index < num_stripes) {
1416 device = list_entry(cur, struct btrfs_device, dev_alloc_list); 1476 device = list_entry(cur, struct btrfs_device, dev_alloc_list);
1417 1477
1418 avail = device->total_bytes - device->bytes_used; 1478 if (device->total_bytes > device->bytes_used)
1479 avail = device->total_bytes - device->bytes_used;
1480 else
1481 avail = 0;
1419 cur = cur->next; 1482 cur = cur->next;
1420 1483
1421 if (avail >= min_free) { 1484 if (device->in_fs_metadata && avail >= min_free) {
1422 u64 ignored_start = 0; 1485 u64 ignored_start = 0;
1423 ret = find_free_dev_extent(trans, device, path, 1486 ret = find_free_dev_extent(trans, device, path,
1424 min_free, 1487 min_free,
@@ -1430,7 +1493,7 @@ again:
1430 if (type & BTRFS_BLOCK_GROUP_DUP) 1493 if (type & BTRFS_BLOCK_GROUP_DUP)
1431 index++; 1494 index++;
1432 } 1495 }
1433 } else if (avail > max_avail) 1496 } else if (device->in_fs_metadata && avail > max_avail)
1434 max_avail = avail; 1497 max_avail = avail;
1435 if (cur == dev_list) 1498 if (cur == dev_list)
1436 break; 1499 break;
@@ -1610,6 +1673,22 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
1610 return ret; 1673 return ret;
1611} 1674}
1612 1675
1676static int find_live_mirror(struct map_lookup *map, int first, int num,
1677 int optimal)
1678{
1679 int i;
1680 if (map->stripes[optimal].dev->bdev)
1681 return optimal;
1682 for (i = first; i < first + num; i++) {
1683 if (map->stripes[i].dev->bdev)
1684 return i;
1685 }
1686 /* we couldn't find one that doesn't fail. Just return something
1687 * and the io error handling code will clean up eventually
1688 */
1689 return optimal;
1690}
1691
1613static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, 1692static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
1614 u64 logical, u64 *length, 1693 u64 logical, u64 *length,
1615 struct btrfs_multi_bio **multi_ret, 1694 struct btrfs_multi_bio **multi_ret,
@@ -1712,8 +1791,11 @@ again:
1712 num_stripes = map->num_stripes; 1791 num_stripes = map->num_stripes;
1713 else if (mirror_num) 1792 else if (mirror_num)
1714 stripe_index = mirror_num - 1; 1793 stripe_index = mirror_num - 1;
1715 else 1794 else {
1716 stripe_index = current->pid % map->num_stripes; 1795 stripe_index = find_live_mirror(map, 0,
1796 map->num_stripes,
1797 current->pid % map->num_stripes);
1798 }
1717 1799
1718 } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { 1800 } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
1719 if (rw & (1 << BIO_RW)) 1801 if (rw & (1 << BIO_RW))
@@ -1731,8 +1813,11 @@ again:
1731 num_stripes = map->sub_stripes; 1813 num_stripes = map->sub_stripes;
1732 else if (mirror_num) 1814 else if (mirror_num)
1733 stripe_index += mirror_num - 1; 1815 stripe_index += mirror_num - 1;
1734 else 1816 else {
1735 stripe_index += current->pid % map->sub_stripes; 1817 stripe_index = find_live_mirror(map, stripe_index,
1818 map->sub_stripes, stripe_index +
1819 current->pid % map->sub_stripes);
1820 }
1736 } else { 1821 } else {
1737 /* 1822 /*
1738 * after this do_div call, stripe_nr is the number of stripes 1823 * after this do_div call, stripe_nr is the number of stripes
@@ -1749,9 +1834,11 @@ again:
1749 struct backing_dev_info *bdi; 1834 struct backing_dev_info *bdi;
1750 1835
1751 device = map->stripes[stripe_index].dev; 1836 device = map->stripes[stripe_index].dev;
1752 bdi = blk_get_backing_dev_info(device->bdev); 1837 if (device->bdev) {
1753 if (bdi->unplug_io_fn) { 1838 bdi = blk_get_backing_dev_info(device->bdev);
1754 bdi->unplug_io_fn(bdi, unplug_page); 1839 if (bdi->unplug_io_fn) {
1840 bdi->unplug_io_fn(bdi, unplug_page);
1841 }
1755 } 1842 }
1756 } else { 1843 } else {
1757 multi->stripes[i].physical = 1844 multi->stripes[i].physical =
@@ -1880,12 +1967,21 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
1880 } 1967 }
1881 bio->bi_sector = multi->stripes[dev_nr].physical >> 9; 1968 bio->bi_sector = multi->stripes[dev_nr].physical >> 9;
1882 dev = multi->stripes[dev_nr].dev; 1969 dev = multi->stripes[dev_nr].dev;
1883 1970 if (dev && dev->bdev) {
1884 bio->bi_bdev = dev->bdev; 1971 bio->bi_bdev = dev->bdev;
1885 spin_lock(&dev->io_lock); 1972 spin_lock(&dev->io_lock);
1886 dev->total_ios++; 1973 dev->total_ios++;
1887 spin_unlock(&dev->io_lock); 1974 spin_unlock(&dev->io_lock);
1888 submit_bio(rw, bio); 1975 submit_bio(rw, bio);
1976 } else {
1977 bio->bi_bdev = root->fs_info->fs_devices->latest_bdev;
1978 bio->bi_sector = logical >> 9;
1979#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
1980 bio_endio(bio, bio->bi_size, -EIO);
1981#else
1982 bio_endio(bio, -EIO);
1983#endif
1984 }
1889 dev_nr++; 1985 dev_nr++;
1890 } 1986 }
1891 if (total_devs == 1) 1987 if (total_devs == 1)
@@ -1901,6 +1997,27 @@ struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid,
1901 return __find_device(head, devid, uuid); 1997 return __find_device(head, devid, uuid);
1902} 1998}
1903 1999
2000static struct btrfs_device *add_missing_dev(struct btrfs_root *root,
2001 u64 devid, u8 *dev_uuid)
2002{
2003 struct btrfs_device *device;
2004 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
2005
2006 device = kzalloc(sizeof(*device), GFP_NOFS);
2007 list_add(&device->dev_list,
2008 &fs_devices->devices);
2009 list_add(&device->dev_alloc_list,
2010 &fs_devices->alloc_list);
2011 device->barriers = 1;
2012 device->dev_root = root->fs_info->dev_root;
2013 device->devid = devid;
2014 fs_devices->num_devices++;
2015 spin_lock_init(&device->io_lock);
2016 memcpy(device->uuid, dev_uuid, BTRFS_UUID_SIZE);
2017 return device;
2018}
2019
2020
1904static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, 2021static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
1905 struct extent_buffer *leaf, 2022 struct extent_buffer *leaf,
1906 struct btrfs_chunk *chunk) 2023 struct btrfs_chunk *chunk)
@@ -1965,11 +2082,22 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
1965 btrfs_stripe_dev_uuid_nr(chunk, i), 2082 btrfs_stripe_dev_uuid_nr(chunk, i),
1966 BTRFS_UUID_SIZE); 2083 BTRFS_UUID_SIZE);
1967 map->stripes[i].dev = btrfs_find_device(root, devid, uuid); 2084 map->stripes[i].dev = btrfs_find_device(root, devid, uuid);
1968 if (!map->stripes[i].dev) { 2085
2086 if (!map->stripes[i].dev && !btrfs_test_opt(root, DEGRADED)) {
1969 kfree(map); 2087 kfree(map);
1970 free_extent_map(em); 2088 free_extent_map(em);
1971 return -EIO; 2089 return -EIO;
1972 } 2090 }
2091 if (!map->stripes[i].dev) {
2092 map->stripes[i].dev =
2093 add_missing_dev(root, devid, uuid);
2094 if (!map->stripes[i].dev) {
2095 kfree(map);
2096 free_extent_map(em);
2097 return -EIO;
2098 }
2099 }
2100 map->stripes[i].dev->in_fs_metadata = 1;
1973 } 2101 }
1974 2102
1975 spin_lock(&map_tree->map_tree.lock); 2103 spin_lock(&map_tree->map_tree.lock);
@@ -2016,20 +2144,15 @@ static int read_one_dev(struct btrfs_root *root,
2016 BTRFS_UUID_SIZE); 2144 BTRFS_UUID_SIZE);
2017 device = btrfs_find_device(root, devid, dev_uuid); 2145 device = btrfs_find_device(root, devid, dev_uuid);
2018 if (!device) { 2146 if (!device) {
2019 printk("warning devid %Lu not found already\n", devid); 2147 printk("warning devid %Lu missing\n", devid);
2020 device = kzalloc(sizeof(*device), GFP_NOFS); 2148 device = add_missing_dev(root, devid, dev_uuid);
2021 if (!device) 2149 if (!device)
2022 return -ENOMEM; 2150 return -ENOMEM;
2023 list_add(&device->dev_list,
2024 &root->fs_info->fs_devices->devices);
2025 list_add(&device->dev_alloc_list,
2026 &root->fs_info->fs_devices->alloc_list);
2027 device->barriers = 1;
2028 spin_lock_init(&device->io_lock);
2029 } 2151 }
2030 2152
2031 fill_device_from_item(leaf, dev_item, device); 2153 fill_device_from_item(leaf, dev_item, device);
2032 device->dev_root = root->fs_info->dev_root; 2154 device->dev_root = root->fs_info->dev_root;
2155 device->in_fs_metadata = 1;
2033 ret = 0; 2156 ret = 0;
2034#if 0 2157#if 0
2035 ret = btrfs_open_device(device); 2158 ret = btrfs_open_device(device);