md: rewrite md_setup_drive to avoid ioctls

md_setup_drive knows it works with md devices, so it is rather pointless
to open a file descriptor and issue ioctls.  Just call directly into the
relevant low-level md routines after getting a handle to the device using
blkdev_get_by_dev instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: NeilBrown <neilb@suse.de>
Acked-by: Song Liu <song@kernel.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Christoph Hellwig
2020-06-07 17:31:19 +02:00
parent d1100488c3
commit 7e0adbfc20
3 changed files with 81 additions and 85 deletions

View File

@@ -326,8 +326,6 @@ static struct ctl_table raid_root_table[] = {
{ }
};
static const struct block_device_operations md_fops;
static int start_readonly;
/*
@@ -4368,7 +4366,6 @@ array_state_show(struct mddev *mddev, char *page)
static int do_md_stop(struct mddev *mddev, int ro, struct block_device *bdev);
static int md_set_readonly(struct mddev *mddev, struct block_device *bdev);
static int do_md_run(struct mddev *mddev);
static int restart_array(struct mddev *mddev);
static ssize_t
@@ -6015,7 +6012,7 @@ abort:
}
EXPORT_SYMBOL_GPL(md_run);
static int do_md_run(struct mddev *mddev)
int do_md_run(struct mddev *mddev)
{
int err;
@@ -6651,7 +6648,7 @@ static int get_disk_info(struct mddev *mddev, void __user * arg)
return 0;
}
static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info)
{
char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
struct md_rdev *rdev;
@@ -6697,7 +6694,7 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
}
/*
* add_new_disk can be used once the array is assembled
* md_add_new_disk can be used once the array is assembled
* to add "hot spares". They must already have a superblock
* written
*/
@@ -6810,7 +6807,7 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
return err;
}
/* otherwise, add_new_disk is only allowed
/* otherwise, md_add_new_disk is only allowed
* for major_version==0 superblocks
*/
if (mddev->major_version != 0) {
@@ -7055,7 +7052,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
}
/*
* set_array_info is used two different ways
* md_set_array_info is used two different ways
* The original usage is when creating a new array.
* In this usage, raid_disks is > 0 and it together with
* level, size, not_persistent,layout,chunksize determine the
@@ -7067,9 +7064,8 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
* The minor and patch _version numbers are also kept incase the
* super_block handler wishes to interpret them.
*/
static int set_array_info(struct mddev *mddev, mdu_array_info_t *info)
int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
{
if (info->raid_disks == 0) {
/* just setting version number for superblock loading */
if (info->major_version < 0 ||
@@ -7560,7 +7556,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
err = -EBUSY;
goto unlock;
}
err = set_array_info(mddev, &info);
err = md_set_array_info(mddev, &info);
if (err) {
pr_warn("md: couldn't set array info. %d\n", err);
goto unlock;
@@ -7614,7 +7610,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
/* Need to clear read-only for this */
break;
else
err = add_new_disk(mddev, &info);
err = md_add_new_disk(mddev, &info);
goto unlock;
}
break;
@@ -7682,7 +7678,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
if (copy_from_user(&info, argp, sizeof(info)))
err = -EFAULT;
else
err = add_new_disk(mddev, &info);
err = md_add_new_disk(mddev, &info);
goto unlock;
}
@@ -7808,7 +7804,7 @@ static int md_revalidate(struct gendisk *disk)
mddev->changed = 0;
return 0;
}
static const struct block_device_operations md_fops =
const struct block_device_operations md_fops =
{
.owner = THIS_MODULE,
.open = md_open,