Browse Source

btrfs: return device pointer from btrfs_scan_one_device

Return device pointer (with the IS_ERR semantics) from
btrfs_scan_one_device so we don't have to return in through pointer.

And since btrfs_fs_devices can be obtained from btrfs_device, return that.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ fixed conflics after recent changes to btrfs_scan_one_device ]
Signed-off-by: David Sterba <dsterba@suse.com>
Gu Jinxiang 7 years ago
parent
commit
36350e95a2
3 changed files with 30 additions and 26 deletions
  1. 21 13
      fs/btrfs/super.c
  2. 7 11
      fs/btrfs/volumes.c
  3. 2 2
      fs/btrfs/volumes.h

+ 21 - 13
fs/btrfs/super.c

@@ -888,7 +888,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 {
 {
 	substring_t args[MAX_OPT_ARGS];
 	substring_t args[MAX_OPT_ARGS];
 	char *device_name, *opts, *orig, *p;
 	char *device_name, *opts, *orig, *p;
-	struct btrfs_fs_devices *fs_devices = NULL;
+	struct btrfs_device *device = NULL;
 	int error = 0;
 	int error = 0;
 
 
 	lockdep_assert_held(&uuid_mutex);
 	lockdep_assert_held(&uuid_mutex);
@@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 				error = -ENOMEM;
 				error = -ENOMEM;
 				goto out;
 				goto out;
 			}
 			}
-			error = btrfs_scan_one_device(device_name,
-					flags, holder, &fs_devices);
+			device = btrfs_scan_one_device(device_name, flags,
+					holder);
 			kfree(device_name);
 			kfree(device_name);
-			if (error)
+			if (IS_ERR(device)) {
+				error = PTR_ERR(device);
 				goto out;
 				goto out;
+			}
 		}
 		}
 	}
 	}
 
 
@@ -1518,6 +1520,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 {
 {
 	struct block_device *bdev = NULL;
 	struct block_device *bdev = NULL;
 	struct super_block *s;
 	struct super_block *s;
+	struct btrfs_device *device = NULL;
 	struct btrfs_fs_devices *fs_devices = NULL;
 	struct btrfs_fs_devices *fs_devices = NULL;
 	struct btrfs_fs_info *fs_info = NULL;
 	struct btrfs_fs_info *fs_info = NULL;
 	struct security_mnt_opts new_sec_opts;
 	struct security_mnt_opts new_sec_opts;
@@ -1561,12 +1564,14 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 		goto error_fs_info;
 		goto error_fs_info;
 	}
 	}
 
 
-	error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
-	if (error) {
+	device = btrfs_scan_one_device(device_name, mode, fs_type);
+	if (IS_ERR(device)) {
 		mutex_unlock(&uuid_mutex);
 		mutex_unlock(&uuid_mutex);
+		error = PTR_ERR(device);
 		goto error_fs_info;
 		goto error_fs_info;
 	}
 	}
 
 
+	fs_devices = device->fs_devices;
 	fs_info->fs_devices = fs_devices;
 	fs_info->fs_devices = fs_devices;
 
 
 	error = btrfs_open_devices(fs_devices, mode, fs_type);
 	error = btrfs_open_devices(fs_devices, mode, fs_type);
@@ -2227,7 +2232,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
 				unsigned long arg)
 				unsigned long arg)
 {
 {
 	struct btrfs_ioctl_vol_args *vol;
 	struct btrfs_ioctl_vol_args *vol;
-	struct btrfs_fs_devices *fs_devices;
+	struct btrfs_device *device = NULL;
 	int ret = -ENOTTY;
 	int ret = -ENOTTY;
 
 
 	if (!capable(CAP_SYS_ADMIN))
 	if (!capable(CAP_SYS_ADMIN))
@@ -2240,19 +2245,22 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
 	switch (cmd) {
 	switch (cmd) {
 	case BTRFS_IOC_SCAN_DEV:
 	case BTRFS_IOC_SCAN_DEV:
 		mutex_lock(&uuid_mutex);
 		mutex_lock(&uuid_mutex);
-		ret = btrfs_scan_one_device(vol->name, FMODE_READ,
-					    &btrfs_root_fs_type, &fs_devices);
+		device = btrfs_scan_one_device(vol->name, FMODE_READ,
+					       &btrfs_root_fs_type);
+		ret = PTR_ERR_OR_ZERO(device);
 		mutex_unlock(&uuid_mutex);
 		mutex_unlock(&uuid_mutex);
 		break;
 		break;
 	case BTRFS_IOC_DEVICES_READY:
 	case BTRFS_IOC_DEVICES_READY:
 		mutex_lock(&uuid_mutex);
 		mutex_lock(&uuid_mutex);
-		ret = btrfs_scan_one_device(vol->name, FMODE_READ,
-					    &btrfs_root_fs_type, &fs_devices);
-		if (ret) {
+		device = btrfs_scan_one_device(vol->name, FMODE_READ,
+					       &btrfs_root_fs_type);
+		if (IS_ERR(device)) {
 			mutex_unlock(&uuid_mutex);
 			mutex_unlock(&uuid_mutex);
+			ret = PTR_ERR(device);
 			break;
 			break;
 		}
 		}
-		ret = !(fs_devices->num_devices == fs_devices->total_devices);
+		ret = !(device->fs_devices->num_devices ==
+			device->fs_devices->total_devices);
 		mutex_unlock(&uuid_mutex);
 		mutex_unlock(&uuid_mutex);
 		break;
 		break;
 	case BTRFS_IOC_GET_SUPPORTED_FEATURES:
 	case BTRFS_IOC_GET_SUPPORTED_FEATURES:

+ 7 - 11
fs/btrfs/volumes.c

@@ -1213,15 +1213,14 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,
  * and we are not allowed to call set_blocksize during the scan. The superblock
  * and we are not allowed to call set_blocksize during the scan. The superblock
  * is read via pagecache
  * is read via pagecache
  */
  */
-int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
-			  struct btrfs_fs_devices **fs_devices_ret)
+struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags,
+					   void *holder)
 {
 {
 	struct btrfs_super_block *disk_super;
 	struct btrfs_super_block *disk_super;
 	bool new_device_added = false;
 	bool new_device_added = false;
-	struct btrfs_device *device;
+	struct btrfs_device *device = NULL;
 	struct block_device *bdev;
 	struct block_device *bdev;
 	struct page *page;
 	struct page *page;
-	int ret = 0;
 	u64 bytenr;
 	u64 bytenr;
 
 
 	lockdep_assert_held(&uuid_mutex);
 	lockdep_assert_held(&uuid_mutex);
@@ -1237,18 +1236,15 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
 
 
 	bdev = blkdev_get_by_path(path, flags, holder);
 	bdev = blkdev_get_by_path(path, flags, holder);
 	if (IS_ERR(bdev))
 	if (IS_ERR(bdev))
-		return PTR_ERR(bdev);
+		return ERR_CAST(bdev);
 
 
 	if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) {
 	if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) {
-		ret = -EINVAL;
+		device = ERR_PTR(-EINVAL);
 		goto error_bdev_put;
 		goto error_bdev_put;
 	}
 	}
 
 
 	device = device_list_add(path, disk_super, &new_device_added);
 	device = device_list_add(path, disk_super, &new_device_added);
-	if (IS_ERR(device)) {
-		ret = PTR_ERR(device);
-	} else {
-		*fs_devices_ret = device->fs_devices;
+	if (!IS_ERR(device)) {
 		if (new_device_added)
 		if (new_device_added)
 			btrfs_free_stale_devices(path, device);
 			btrfs_free_stale_devices(path, device);
 	}
 	}
@@ -1258,7 +1254,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
 error_bdev_put:
 error_bdev_put:
 	blkdev_put(bdev, flags);
 	blkdev_put(bdev, flags);
 
 
-	return ret;
+	return device;
 }
 }
 
 
 static int contains_pending_extent(struct btrfs_transaction *transaction,
 static int contains_pending_extent(struct btrfs_transaction *transaction,

+ 2 - 2
fs/btrfs/volumes.h

@@ -403,8 +403,8 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
 			   int mirror_num, int async_submit);
 			   int mirror_num, int async_submit);
 int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
 int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
 		       fmode_t flags, void *holder);
 		       fmode_t flags, void *holder);
-int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
-			  struct btrfs_fs_devices **fs_devices_ret);
+struct btrfs_device *btrfs_scan_one_device(const char *path,
+					   fmode_t flags, void *holder);
 int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
 int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
 void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
 void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
 void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,
 void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,