Skip to content

Commit

Permalink
block: implement and use {disk|part}_to_dev()
Browse files Browse the repository at this point in the history
Implement {disk|part}_to_dev() and use them to access generic device
instead of directly dereferencing {disk|part}->dev.  To make sure no
user is left behind, rename generic devices fields to __dev.

This is in preparation of unifying partition 0 handling with other
partitions.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Tejun Heo authored and Jens Axboe committed Oct 9, 2008
1 parent 870d665 commit ed9e198
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 77 deletions.
5 changes: 3 additions & 2 deletions block/blk-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
return -1;

if (kobject_init_and_add(&bi->kobj, &integrity_ktype,
&disk->dev.kobj, "%s", "integrity")) {
&disk_to_dev(disk)->kobj,
"%s", "integrity")) {
kmem_cache_free(integrity_cachep, bi);
return -1;
}
Expand Down Expand Up @@ -375,7 +376,7 @@ void blk_integrity_unregister(struct gendisk *disk)

kobject_uevent(&bi->kobj, KOBJ_REMOVE);
kobject_del(&bi->kobj);
kobject_put(&disk->dev.kobj);
kobject_put(&disk_to_dev(disk)->kobj);
kmem_cache_free(integrity_cachep, bi);
}
EXPORT_SYMBOL(blk_integrity_unregister);
4 changes: 2 additions & 2 deletions block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int blk_register_queue(struct gendisk *disk)
if (!q->request_fn)
return 0;

ret = kobject_add(&q->kobj, kobject_get(&disk->dev.kobj),
ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),
"%s", "queue");
if (ret < 0)
return ret;
Expand Down Expand Up @@ -339,6 +339,6 @@ void blk_unregister_queue(struct gendisk *disk)

kobject_uevent(&q->kobj, KOBJ_REMOVE);
kobject_del(&q->kobj);
kobject_put(&disk->dev.kobj);
kobject_put(&disk_to_dev(disk)->kobj);
}
}
27 changes: 14 additions & 13 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct hd_struct *disk_get_part(struct gendisk *disk, int partno)
rcu_read_lock();
part = rcu_dereference(disk->__part[partno - 1]);
if (part)
get_device(&part->dev);
get_device(part_to_dev(part));
rcu_read_unlock();

return part;
Expand Down Expand Up @@ -130,7 +130,7 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
if (!(piter->flags & DISK_PITER_INCL_EMPTY) && !part->nr_sects)
continue;

get_device(&part->dev);
get_device(part_to_dev(part));
piter->part = part;
piter->idx += inc;
break;
Expand Down Expand Up @@ -435,7 +435,7 @@ static struct kobject *exact_match(dev_t devt, int *partno, void *data)
{
struct gendisk *p = data;

return &p->dev.kobj;
return &disk_to_dev(p)->kobj;
}

static int exact_lock(dev_t devt, void *data)
Expand All @@ -460,15 +460,16 @@ void add_disk(struct gendisk *disk)
int retval;

disk->flags |= GENHD_FL_UP;
disk->dev.devt = MKDEV(disk->major, disk->first_minor);
disk_to_dev(disk)->devt = MKDEV(disk->major, disk->first_minor);
blk_register_region(disk_devt(disk), disk->minors, NULL,
exact_match, exact_lock, disk);
register_disk(disk);
blk_register_queue(disk);

bdi = &disk->queue->backing_dev_info;
bdi_register_dev(bdi, disk_devt(disk));
retval = sysfs_create_link(&disk->dev.kobj, &bdi->dev->kobj, "bdi");
retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
"bdi");
WARN_ON(retval);
}

Expand All @@ -477,7 +478,7 @@ EXPORT_SYMBOL(del_gendisk); /* in partitions/check.c */

void unlink_gendisk(struct gendisk *disk)
{
sysfs_remove_link(&disk->dev.kobj, "bdi");
sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
bdi_unregister(&disk->queue->backing_dev_info);
blk_unregister_queue(disk);
blk_unregister_region(disk_devt(disk), disk->minors);
Expand Down Expand Up @@ -903,7 +904,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
int cpu;

/*
if (&gp->dev.kobj.entry == block_class.devices.next)
if (&disk_to_dev(gp)->kobj.entry == block_class.devices.next)
seq_puts(seqf, "major minor name"
" rio rmerge rsect ruse wio wmerge "
"wsect wuse running use aveq"
Expand Down Expand Up @@ -972,7 +973,7 @@ static void media_change_notify_thread(struct work_struct *work)
* set enviroment vars to indicate which event this is for
* so that user space will know to go check the media status.
*/
kobject_uevent_env(&gd->dev.kobj, KOBJ_CHANGE, envp);
kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp);
put_device(gd->driverfs_dev);
}

Expand Down Expand Up @@ -1062,9 +1063,9 @@ struct gendisk *alloc_disk_ext_node(int minors, int ext_minors, int node_id)
disk->minors = minors;
disk->ext_minors = ext_minors;
rand_initialize_disk(disk);
disk->dev.class = &block_class;
disk->dev.type = &disk_type;
device_initialize(&disk->dev);
disk_to_dev(disk)->class = &block_class;
disk_to_dev(disk)->type = &disk_type;
device_initialize(disk_to_dev(disk));
INIT_WORK(&disk->async_notify,
media_change_notify_thread);
}
Expand All @@ -1086,7 +1087,7 @@ struct kobject *get_disk(struct gendisk *disk)
owner = disk->fops->owner;
if (owner && !try_module_get(owner))
return NULL;
kobj = kobject_get(&disk->dev.kobj);
kobj = kobject_get(&disk_to_dev(disk)->kobj);
if (kobj == NULL) {
module_put(owner);
return NULL;
Expand All @@ -1100,7 +1101,7 @@ EXPORT_SYMBOL(get_disk);
void put_disk(struct gendisk *disk)
{
if (disk)
kobject_put(&disk->dev.kobj);
kobject_put(&disk_to_dev(disk)->kobj);
}

EXPORT_SYMBOL(put_disk);
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/aoe/aoeblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ static const struct attribute_group attr_group = {
static int
aoedisk_add_sysfs(struct aoedev *d)
{
return sysfs_create_group(&d->gd->dev.kobj, &attr_group);
return sysfs_create_group(&disk_to_dev(d->gd)->kobj, &attr_group);
}
void
aoedisk_rm_sysfs(struct aoedev *d)
{
sysfs_remove_group(&d->gd->dev.kobj, &attr_group);
sysfs_remove_group(&disk_to_dev(d->gd)->kobj, &attr_group);
}

static int
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static int nbd_do_it(struct nbd_device *lo)
BUG_ON(lo->magic != LO_MAGIC);

lo->pid = current->pid;
ret = sysfs_create_file(&lo->disk->dev.kobj, &pid_attr.attr);
ret = sysfs_create_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
if (ret) {
printk(KERN_ERR "nbd: sysfs_create_file failed!");
return ret;
Expand All @@ -412,7 +412,7 @@ static int nbd_do_it(struct nbd_device *lo)
while ((req = nbd_read_stat(lo)) != NULL)
nbd_end_request(req);

sysfs_remove_file(&lo->disk->dev.kobj, &pid_attr.attr);
sysfs_remove_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/ide/ide-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
{
struct gendisk *p = data;
*part &= (1 << PARTN_BITS) - 1;
return &p->dev.kobj;
return &disk_to_dev(p)->kobj;
}

static int exact_lock(dev_t dev, void *data)
Expand Down
4 changes: 2 additions & 2 deletions drivers/md/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ static void event_callback(void *context)
list_splice_init(&md->uevent_list, &uevents);
spin_unlock_irqrestore(&md->uevent_lock, flags);

dm_send_uevents(&uevents, &md->disk->dev.kobj);
dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);

atomic_inc(&md->event_nr);
wake_up(&md->eventq);
Expand Down Expand Up @@ -1643,7 +1643,7 @@ int dm_resume(struct mapped_device *md)
*---------------------------------------------------------------*/
void dm_kobject_uevent(struct mapped_device *md)
{
kobject_uevent(&md->disk->dev.kobj, KOBJ_CHANGE);
kobject_uevent(&disk_to_dev(md->disk)->kobj, KOBJ_CHANGE);
}

uint32_t dm_next_uevent_seq(struct mapped_device *md)
Expand Down
10 changes: 5 additions & 5 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,9 +1465,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
goto fail;

if (rdev->bdev->bd_part)
ko = &rdev->bdev->bd_part->dev.kobj;
ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
else
ko = &rdev->bdev->bd_disk->dev.kobj;
ko = &disk_to_dev(rdev->bdev->bd_disk)->kobj;
if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
kobject_del(&rdev->kobj);
goto fail;
Expand Down Expand Up @@ -3470,8 +3470,8 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
disk->queue = mddev->queue;
add_disk(disk);
mddev->gendisk = disk;
error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
"%s", "md");
error = kobject_init_and_add(&mddev->kobj, &md_ktype,
&disk_to_dev(disk)->kobj, "%s", "md");
mutex_unlock(&disks_mutex);
if (error)
printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
Expand Down Expand Up @@ -3761,7 +3761,7 @@ static int do_md_run(mddev_t * mddev)
sysfs_notify(&mddev->kobj, NULL, "array_state");
sysfs_notify(&mddev->kobj, NULL, "sync_action");
sysfs_notify(&mddev->kobj, NULL, "degraded");
kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ EXPORT_SYMBOL(bd_release);
static struct kobject *bdev_get_kobj(struct block_device *bdev)
{
if (bdev->bd_contains != bdev)
return kobject_get(&bdev->bd_part->dev.kobj);
return kobject_get(&part_to_dev(bdev->bd_part)->kobj);
else
return kobject_get(&bdev->bd_disk->dev.kobj);
return kobject_get(&disk_to_dev(bdev->bd_disk)->kobj);
}

static struct kobject *bdev_get_holder(struct block_device *bdev)
Expand Down
Loading

0 comments on commit ed9e198

Please sign in to comment.