mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-24 05:01:03 +02:00
block: add a bdev_kobj helper
Add a little helper to find the kobject for a struct block_device. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Acked-by: Tejun Heo <tj@kernel.org> Acked-by: Coly Li <colyli@suse.de> [bcache] Acked-by: David Sterba <dsterba@suse.com> [btrfs] Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
3f50b95e0e
commit
8d65269fe8
@@ -1447,8 +1447,7 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
|
|||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
err = "error creating kobject";
|
err = "error creating kobject";
|
||||||
if (kobject_add(&dc->disk.kobj, &part_to_dev(bdev->bd_part)->kobj,
|
if (kobject_add(&dc->disk.kobj, bdev_kobj(bdev), "bcache"))
|
||||||
"bcache"))
|
|
||||||
goto err;
|
goto err;
|
||||||
if (bch_cache_accounting_add_kobjs(&dc->accounting, &dc->disk.kobj))
|
if (bch_cache_accounting_add_kobjs(&dc->accounting, &dc->disk.kobj))
|
||||||
goto err;
|
goto err;
|
||||||
@@ -2342,9 +2341,7 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kobject_add(&ca->kobj,
|
if (kobject_add(&ca->kobj, bdev_kobj(bdev), "bcache")) {
|
||||||
&part_to_dev(bdev->bd_part)->kobj,
|
|
||||||
"bcache")) {
|
|
||||||
err = "error calling kobject_add";
|
err = "error calling kobject_add";
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
|
@@ -2414,7 +2414,6 @@ EXPORT_SYMBOL(md_integrity_add_rdev);
|
|||||||
static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
|
static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
|
||||||
{
|
{
|
||||||
char b[BDEVNAME_SIZE];
|
char b[BDEVNAME_SIZE];
|
||||||
struct kobject *ko;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* prevent duplicates */
|
/* prevent duplicates */
|
||||||
@@ -2477,9 +2476,8 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
|
|||||||
if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
|
if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
|
|
||||||
/* failure here is OK */
|
/* failure here is OK */
|
||||||
err = sysfs_create_link(&rdev->kobj, ko, "block");
|
err = sysfs_create_link(&rdev->kobj, bdev_kobj(rdev->bdev), "block");
|
||||||
rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state");
|
rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state");
|
||||||
rdev->sysfs_unack_badblocks =
|
rdev->sysfs_unack_badblocks =
|
||||||
sysfs_get_dirent_safe(rdev->kobj.sd, "unacknowledged_bad_blocks");
|
sysfs_get_dirent_safe(rdev->kobj.sd, "unacknowledged_bad_blocks");
|
||||||
|
@@ -1242,7 +1242,7 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
|
|||||||
holder->disk = disk;
|
holder->disk = disk;
|
||||||
holder->refcnt = 1;
|
holder->refcnt = 1;
|
||||||
|
|
||||||
ret = add_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
|
ret = add_symlink(disk->slave_dir, bdev_kobj(bdev));
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
|
||||||
@@ -1259,7 +1259,7 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
|
|||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
out_del:
|
out_del:
|
||||||
del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
|
del_symlink(disk->slave_dir, bdev_kobj(bdev));
|
||||||
out_free:
|
out_free:
|
||||||
kfree(holder);
|
kfree(holder);
|
||||||
out_unlock:
|
out_unlock:
|
||||||
@@ -1287,7 +1287,7 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
|
|||||||
holder = bd_find_holder_disk(bdev, disk);
|
holder = bd_find_holder_disk(bdev, disk);
|
||||||
|
|
||||||
if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
|
if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
|
||||||
del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
|
del_symlink(disk->slave_dir, bdev_kobj(bdev));
|
||||||
del_symlink(bdev->bd_part->holder_dir,
|
del_symlink(bdev->bd_part->holder_dir,
|
||||||
&disk_to_dev(disk)->kobj);
|
&disk_to_dev(disk)->kobj);
|
||||||
kobject_put(bdev->bd_part->holder_dir);
|
kobject_put(bdev->bd_part->holder_dir);
|
||||||
|
@@ -1232,8 +1232,6 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
|
|||||||
|
|
||||||
void btrfs_sysfs_remove_device(struct btrfs_device *device)
|
void btrfs_sysfs_remove_device(struct btrfs_device *device)
|
||||||
{
|
{
|
||||||
struct hd_struct *disk;
|
|
||||||
struct kobject *disk_kobj;
|
|
||||||
struct kobject *devices_kobj;
|
struct kobject *devices_kobj;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1243,11 +1241,8 @@ void btrfs_sysfs_remove_device(struct btrfs_device *device)
|
|||||||
devices_kobj = device->fs_info->fs_devices->devices_kobj;
|
devices_kobj = device->fs_info->fs_devices->devices_kobj;
|
||||||
ASSERT(devices_kobj);
|
ASSERT(devices_kobj);
|
||||||
|
|
||||||
if (device->bdev) {
|
if (device->bdev)
|
||||||
disk = device->bdev->bd_part;
|
sysfs_remove_link(devices_kobj, bdev_kobj(device->bdev)->name);
|
||||||
disk_kobj = &part_to_dev(disk)->kobj;
|
|
||||||
sysfs_remove_link(devices_kobj, disk_kobj->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device->devid_kobj.state_initialized) {
|
if (device->devid_kobj.state_initialized) {
|
||||||
kobject_del(&device->devid_kobj);
|
kobject_del(&device->devid_kobj);
|
||||||
@@ -1353,11 +1348,7 @@ int btrfs_sysfs_add_device(struct btrfs_device *device)
|
|||||||
nofs_flag = memalloc_nofs_save();
|
nofs_flag = memalloc_nofs_save();
|
||||||
|
|
||||||
if (device->bdev) {
|
if (device->bdev) {
|
||||||
struct hd_struct *disk;
|
struct kobject *disk_kobj = bdev_kobj(device->bdev);
|
||||||
struct kobject *disk_kobj;
|
|
||||||
|
|
||||||
disk = device->bdev->bd_part;
|
|
||||||
disk_kobj = &part_to_dev(disk)->kobj;
|
|
||||||
|
|
||||||
ret = sysfs_create_link(devices_kobj, disk_kobj, disk_kobj->name);
|
ret = sysfs_create_link(devices_kobj, disk_kobj, disk_kobj->name);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@@ -49,6 +49,9 @@ struct block_device {
|
|||||||
struct super_block *bd_fsfreeze_sb;
|
struct super_block *bd_fsfreeze_sb;
|
||||||
} __randomize_layout;
|
} __randomize_layout;
|
||||||
|
|
||||||
|
#define bdev_kobj(_bdev) \
|
||||||
|
(&part_to_dev((_bdev)->bd_part)->kobj)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Block error status values. See block/blk-core:blk_errors for the details.
|
* Block error status values. See block/blk-core:blk_errors for the details.
|
||||||
* Alpha cannot write a byte atomically, so we need to use 32-bit value.
|
* Alpha cannot write a byte atomically, so we need to use 32-bit value.
|
||||||
|
Reference in New Issue
Block a user