@@ -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
*/
@@ -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;
+}
@@ -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
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.jain@oracle.com> --- fs/btrfs/super.c | 9 +++++++++ fs/btrfs/volumes.c | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 48 insertions(+)