This adds functions to get and put a spare device from the list. So that hot repace code can pick a spare device when needed.
Signed-off-by: Anand Jain <anand.j...@oracle.com> --- fs/btrfs/super.c | 9 +++++++++ fs/btrfs/volumes.c | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 48 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d495790..29836ca 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2035,6 +2035,15 @@ static int btrfs_control_open(struct inode *inode, struct file *file) return 0; } +void btrfs_put_spare_device(char *path) +{ + struct btrfs_fs_devices *fs_devices; + + if (btrfs_scan_one_device(path, FMODE_READ, + &btrfs_fs_type, &fs_devices)) + printk(KERN_INFO "failed to return spare device\n"); +} + /* * used by btrfsctl to scan devices when no FS is mounted */ diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 28f549d..3b90690 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7017,3 +7017,40 @@ void btrfs_force_device_close(struct btrfs_device *dev, char *why) rcu_str_deref(dev->name), why); rcu_read_unlock(); } + +int btrfs_get_spare_device(char **path) +{ + int ret = 1; + struct btrfs_fs_devices *fs_devices; + struct btrfs_device *device; + struct list_head *fs_uuids = btrfs_get_fs_uuids(); + + mutex_lock(&uuid_mutex); + list_for_each_entry(fs_devices, fs_uuids, list) { + if (!fs_devices->spare) + continue; + + /* as of now there is only one device in the spare fs_devices */ + device = list_entry(fs_devices->devices.next, + struct btrfs_device, dev_list); + + if (!device || !device->name) + continue; + + fs_devices->spare = 0; + rcu_read_lock(); + *path = kstrdup(device->name->str, GFP_NOFS); + rcu_read_unlock(); + ret = 0; + break; + } + + if (!ret) { + btrfs_sysfs_remove_fsid(fs_devices); + list_del(&fs_devices->list); + free_fs_devices(fs_devices); + } + mutex_unlock(&uuid_mutex); + + return ret; +} diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 3d995b7..36184ec 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -577,5 +577,7 @@ void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info); void btrfs_close_one_device(struct btrfs_device *device); int btrfs_check_degradable(struct btrfs_fs_info *fs_info, unsigned flags); void btrfs_force_device_close(struct btrfs_device *dev, char *why); +int btrfs_get_spare_device(char **path); +void btrfs_put_spare_device(char *path); #endif -- 2.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html