btrfs: move btrfs_init_dev_replace_tgtdev to dev-replace.c and make static
authorDavid Sterba <dsterba@suse.com>
Tue, 20 Mar 2018 15:09:48 +0000 (16:09 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 May 2018 16:07:24 +0000 (18:07 +0200)
The function logically belongs there and there's only a single caller,
no need to export it. No code changes.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index e3ec0eb5789b7b6b10c2c5c7d4743fe318c32a9f..8531b5dae777286fd9d342e6819d13d05ad3578b 100644 (file)
@@ -176,6 +176,105 @@ out:
        return ret;
 }
 
+/*
+ * Initialize a new device for device replace target from a given source dev
+ * and path.
+ *
+ * Return 0 and new device in @device_out, otherwise return < 0
+ */
+static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
+                                 const char *device_path,
+                                 struct btrfs_device *srcdev,
+                                 struct btrfs_device **device_out)
+{
+       struct btrfs_device *device;
+       struct block_device *bdev;
+       struct list_head *devices;
+       struct rcu_string *name;
+       u64 devid = BTRFS_DEV_REPLACE_DEVID;
+       int ret = 0;
+
+       *device_out = NULL;
+       if (fs_info->fs_devices->seeding) {
+               btrfs_err(fs_info, "the filesystem is a seed filesystem!");
+               return -EINVAL;
+       }
+
+       bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
+                                 fs_info->bdev_holder);
+       if (IS_ERR(bdev)) {
+               btrfs_err(fs_info, "target device %s is invalid!", device_path);
+               return PTR_ERR(bdev);
+       }
+
+       filemap_write_and_wait(bdev->bd_inode->i_mapping);
+
+       devices = &fs_info->fs_devices->devices;
+       list_for_each_entry(device, devices, dev_list) {
+               if (device->bdev == bdev) {
+                       btrfs_err(fs_info,
+                                 "target device is in the filesystem!");
+                       ret = -EEXIST;
+                       goto error;
+               }
+       }
+
+
+       if (i_size_read(bdev->bd_inode) <
+           btrfs_device_get_total_bytes(srcdev)) {
+               btrfs_err(fs_info,
+                         "target device is smaller than source device!");
+               ret = -EINVAL;
+               goto error;
+       }
+
+
+       device = btrfs_alloc_device(NULL, &devid, NULL);
+       if (IS_ERR(device)) {
+               ret = PTR_ERR(device);
+               goto error;
+       }
+
+       name = rcu_string_strdup(device_path, GFP_KERNEL);
+       if (!name) {
+               btrfs_free_device(device);
+               ret = -ENOMEM;
+               goto error;
+       }
+       rcu_assign_pointer(device->name, name);
+
+       mutex_lock(&fs_info->fs_devices->device_list_mutex);
+       set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
+       device->generation = 0;
+       device->io_width = fs_info->sectorsize;
+       device->io_align = fs_info->sectorsize;
+       device->sector_size = fs_info->sectorsize;
+       device->total_bytes = btrfs_device_get_total_bytes(srcdev);
+       device->disk_total_bytes = btrfs_device_get_disk_total_bytes(srcdev);
+       device->bytes_used = btrfs_device_get_bytes_used(srcdev);
+       device->commit_total_bytes = srcdev->commit_total_bytes;
+       device->commit_bytes_used = device->bytes_used;
+       device->fs_info = fs_info;
+       device->bdev = bdev;
+       set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
+       set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
+       device->mode = FMODE_EXCL;
+       device->dev_stats_valid = 1;
+       set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
+       device->fs_devices = fs_info->fs_devices;
+       list_add(&device->dev_list, &fs_info->fs_devices->devices);
+       fs_info->fs_devices->num_devices++;
+       fs_info->fs_devices->open_devices++;
+       mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+
+       *device_out = device;
+       return 0;
+
+error:
+       blkdev_put(bdev, FMODE_EXCL);
+       return ret;
+}
+
 /*
  * called from commit_transaction. Writes changed device replace state to
  * disk.
index 364f4e7206f4d4c28f1fcaa3a4de8d6107ac282d..488935e66779faf064fc71782dbd22f5104b225d 100644 (file)
@@ -2612,105 +2612,6 @@ error:
        return ret;
 }
 
-/*
- * Initialize a new device for device replace target from a given source dev
- * and path.
- *
- * Return 0 and new device in @device_out, otherwise return < 0
- */
-int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
-                                 const char *device_path,
-                                 struct btrfs_device *srcdev,
-                                 struct btrfs_device **device_out)
-{
-       struct btrfs_device *device;
-       struct block_device *bdev;
-       struct list_head *devices;
-       struct rcu_string *name;
-       u64 devid = BTRFS_DEV_REPLACE_DEVID;
-       int ret = 0;
-
-       *device_out = NULL;
-       if (fs_info->fs_devices->seeding) {
-               btrfs_err(fs_info, "the filesystem is a seed filesystem!");
-               return -EINVAL;
-       }
-
-       bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
-                                 fs_info->bdev_holder);
-       if (IS_ERR(bdev)) {
-               btrfs_err(fs_info, "target device %s is invalid!", device_path);
-               return PTR_ERR(bdev);
-       }
-
-       filemap_write_and_wait(bdev->bd_inode->i_mapping);
-
-       devices = &fs_info->fs_devices->devices;
-       list_for_each_entry(device, devices, dev_list) {
-               if (device->bdev == bdev) {
-                       btrfs_err(fs_info,
-                                 "target device is in the filesystem!");
-                       ret = -EEXIST;
-                       goto error;
-               }
-       }
-
-
-       if (i_size_read(bdev->bd_inode) <
-           btrfs_device_get_total_bytes(srcdev)) {
-               btrfs_err(fs_info,
-                         "target device is smaller than source device!");
-               ret = -EINVAL;
-               goto error;
-       }
-
-
-       device = btrfs_alloc_device(NULL, &devid, NULL);
-       if (IS_ERR(device)) {
-               ret = PTR_ERR(device);
-               goto error;
-       }
-
-       name = rcu_string_strdup(device_path, GFP_KERNEL);
-       if (!name) {
-               btrfs_free_device(device);
-               ret = -ENOMEM;
-               goto error;
-       }
-       rcu_assign_pointer(device->name, name);
-
-       mutex_lock(&fs_info->fs_devices->device_list_mutex);
-       set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
-       device->generation = 0;
-       device->io_width = fs_info->sectorsize;
-       device->io_align = fs_info->sectorsize;
-       device->sector_size = fs_info->sectorsize;
-       device->total_bytes = btrfs_device_get_total_bytes(srcdev);
-       device->disk_total_bytes = btrfs_device_get_disk_total_bytes(srcdev);
-       device->bytes_used = btrfs_device_get_bytes_used(srcdev);
-       device->commit_total_bytes = srcdev->commit_total_bytes;
-       device->commit_bytes_used = device->bytes_used;
-       device->fs_info = fs_info;
-       device->bdev = bdev;
-       set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
-       set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
-       device->mode = FMODE_EXCL;
-       device->dev_stats_valid = 1;
-       set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
-       device->fs_devices = fs_info->fs_devices;
-       list_add(&device->dev_list, &fs_info->fs_devices->devices);
-       fs_info->fs_devices->num_devices++;
-       fs_info->fs_devices->open_devices++;
-       mutex_unlock(&fs_info->fs_devices->device_list_mutex);
-
-       *device_out = device;
-       return 0;
-
-error:
-       blkdev_put(bdev, FMODE_EXCL);
-       return ret;
-}
-
 static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
                                        struct btrfs_device *device)
 {
index 316cce159969e32607c9f2a8699a3cee0563597b..5737e6e68f8b454ce2e767e2eb9b310e608b47ff 100644 (file)
@@ -432,10 +432,6 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
                                       u8 *uuid, u8 *fsid);
 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
 int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
-int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
-                                 const char *device_path,
-                                 struct btrfs_device *srcdev,
-                                 struct btrfs_device **device_out);
 int btrfs_balance(struct btrfs_balance_control *bctl,
                  struct btrfs_ioctl_balance_args *bargs);
 int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);