Commit 178a16c9 authored by Anand Jain's avatar Anand Jain Committed by David Sterba

btrfs: add btrfs_sysfs_add_device helper

btrfs_sysfs_add_devices_dir() adds device link and devid kobject
(sysfs entries) for a device or all the devices in the btrfs_fs_devices.
In preparation to add these sysfs entries for the seed as well, add
a btrfs_sysfs_add_device() helper function and avoid code duplication.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent c6a5d954
......@@ -1312,44 +1312,70 @@ static struct kobj_type devid_ktype = {
.release = btrfs_release_devid_kobj,
};
int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices,
struct btrfs_device *one_device)
static int btrfs_sysfs_add_device(struct btrfs_device *device)
{
int error = 0;
struct btrfs_device *dev;
int ret;
unsigned int nofs_flag;
struct kobject *devices_kobj;
struct kobject *devinfo_kobj;
/*
* Make sure we use the fs_info::fs_devices to fetch the kobjects even
* for the seed fs_devices
*/
devices_kobj = device->fs_info->fs_devices->devices_kobj;
devinfo_kobj = device->fs_info->fs_devices->devinfo_kobj;
ASSERT(devices_kobj);
ASSERT(devinfo_kobj);
nofs_flag = memalloc_nofs_save();
list_for_each_entry(dev, &fs_devices->devices, dev_list) {
if (one_device && one_device != dev)
continue;
if (device->bdev) {
struct hd_struct *disk;
struct kobject *disk_kobj;
if (dev->bdev) {
struct hd_struct *disk;
struct kobject *disk_kobj;
disk = device->bdev->bd_part;
disk_kobj = &part_to_dev(disk)->kobj;
disk = dev->bdev->bd_part;
disk_kobj = &part_to_dev(disk)->kobj;
error = sysfs_create_link(fs_devices->devices_kobj,
disk_kobj, disk_kobj->name);
if (error)
break;
ret = sysfs_create_link(devices_kobj, disk_kobj, disk_kobj->name);
if (ret) {
btrfs_warn(device->fs_info,
"creating sysfs device link for devid %llu failed: %d",
device->devid, ret);
goto out;
}
}
init_completion(&dev->kobj_unregister);
error = kobject_init_and_add(&dev->devid_kobj, &devid_ktype,
fs_devices->devinfo_kobj, "%llu",
dev->devid);
if (error) {
kobject_put(&dev->devid_kobj);
break;
}
init_completion(&device->kobj_unregister);
ret = kobject_init_and_add(&device->devid_kobj, &devid_ktype,
devinfo_kobj, "%llu", device->devid);
if (ret) {
kobject_put(&device->devid_kobj);
btrfs_warn(device->fs_info,
"devinfo init for devid %llu failed: %d",
device->devid, ret);
}
out:
memalloc_nofs_restore(nofs_flag);
return ret;
}
return error;
int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices,
struct btrfs_device *device)
{
int ret;
if (device)
return btrfs_sysfs_add_device(device);
list_for_each_entry(device, &fs_devices->devices, dev_list) {
ret = btrfs_sysfs_add_device(device);
if (ret)
return ret;
}
return 0;
}
void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)
......
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