Commit ba32929a authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

block: make add_partition() return pointer to hd_struct

Make add_partition() return pointer to the new hd_struct on success
and ERR_PTR() value on failure.  This change will be used to fix md
autodetection bug.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent eb60fa10
...@@ -18,7 +18,6 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -18,7 +18,6 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
struct disk_part_iter piter; struct disk_part_iter piter;
long long start, length; long long start, length;
int partno; int partno;
int err;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
...@@ -61,10 +60,10 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -61,10 +60,10 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
/* all seems OK */ /* all seems OK */
err = add_partition(disk, partno, start, length, part = add_partition(disk, partno, start, length,
ADDPART_FLAG_NONE); ADDPART_FLAG_NONE);
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
return err; return IS_ERR(part) ? PTR_ERR(part) : 0;
case BLKPG_DEL_PARTITION: case BLKPG_DEL_PARTITION:
part = disk_get_part(disk, partno); part = disk_get_part(disk, partno);
if (!part) if (!part)
......
...@@ -348,8 +348,8 @@ static ssize_t whole_disk_show(struct device *dev, ...@@ -348,8 +348,8 @@ static ssize_t whole_disk_show(struct device *dev,
static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH,
whole_disk_show, NULL); whole_disk_show, NULL);
int add_partition(struct gendisk *disk, int partno, struct hd_struct *add_partition(struct gendisk *disk, int partno,
sector_t start, sector_t len, int flags) sector_t start, sector_t len, int flags)
{ {
struct hd_struct *p; struct hd_struct *p;
dev_t devt = MKDEV(0, 0); dev_t devt = MKDEV(0, 0);
...@@ -361,15 +361,15 @@ int add_partition(struct gendisk *disk, int partno, ...@@ -361,15 +361,15 @@ int add_partition(struct gendisk *disk, int partno,
err = disk_expand_part_tbl(disk, partno); err = disk_expand_part_tbl(disk, partno);
if (err) if (err)
return err; return ERR_PTR(err);
ptbl = disk->part_tbl; ptbl = disk->part_tbl;
if (ptbl->part[partno]) if (ptbl->part[partno])
return -EBUSY; return ERR_PTR(-EBUSY);
p = kzalloc(sizeof(*p), GFP_KERNEL); p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) if (!p)
return -ENOMEM; return ERR_PTR(-EBUSY);
if (!init_part_stats(p)) { if (!init_part_stats(p)) {
err = -ENOMEM; err = -ENOMEM;
...@@ -424,20 +424,20 @@ int add_partition(struct gendisk *disk, int partno, ...@@ -424,20 +424,20 @@ int add_partition(struct gendisk *disk, int partno,
if (!ddev->uevent_suppress) if (!ddev->uevent_suppress)
kobject_uevent(&pdev->kobj, KOBJ_ADD); kobject_uevent(&pdev->kobj, KOBJ_ADD);
return 0; return p;
out_free_stats: out_free_stats:
free_part_stats(p); free_part_stats(p);
out_free: out_free:
kfree(p); kfree(p);
return err; return ERR_PTR(err);
out_del: out_del:
kobject_put(p->holder_dir); kobject_put(p->holder_dir);
device_del(pdev); device_del(pdev);
out_put: out_put:
put_device(pdev); put_device(pdev);
blk_free_devt(devt); blk_free_devt(devt);
return err; return ERR_PTR(err);
} }
/* Not exported, helper to add_disk(). */ /* Not exported, helper to add_disk(). */
...@@ -568,10 +568,11 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -568,10 +568,11 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
disk->disk_name, p, (unsigned long long) size); disk->disk_name, p, (unsigned long long) size);
size = get_capacity(disk) - from; size = get_capacity(disk) - from;
} }
res = add_partition(disk, p, from, size, state->parts[p].flags); part = add_partition(disk, p, from, size,
if (res) { state->parts[p].flags);
printk(KERN_ERR " %s: p%d could not be added: %d\n", if (IS_ERR(part)) {
disk->disk_name, p, -res); printk(KERN_ERR " %s: p%d could not be added: %ld\n",
disk->disk_name, p, -PTR_ERR(part));
continue; continue;
} }
#ifdef CONFIG_BLK_DEV_MD #ifdef CONFIG_BLK_DEV_MD
......
...@@ -522,7 +522,9 @@ extern char *disk_name (struct gendisk *hd, int partno, char *buf); ...@@ -522,7 +522,9 @@ extern char *disk_name (struct gendisk *hd, int partno, char *buf);
extern int disk_expand_part_tbl(struct gendisk *disk, int target); extern int disk_expand_part_tbl(struct gendisk *disk, int target);
extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev); extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
extern int __must_check add_partition(struct gendisk *, int, sector_t, sector_t, int); extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
int partno, sector_t start,
sector_t len, int flags);
extern void delete_partition(struct gendisk *, int); extern void delete_partition(struct gendisk *, int);
extern void printk_all_partitions(void); extern void printk_all_partitions(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment