diff options
author | Mike Christie <mchristi@redhat.com> | 2017-06-23 01:18:14 -0500 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2017-07-06 23:11:38 -0700 |
commit | 85441e6b8c97964a6da72135dc21f708adbdc4d8 (patch) | |
tree | 4e03541a349d033ae4bdaf1f485a57fd4e4aa6da /drivers/target/target_core_device.c | |
parent | 0a5eee647b78e53da05e081362f42a11b4b674eb (diff) |
target: add helper to find se_device by dev_index
This adds a helper to find a se_device by dev_index. It will
be used in the next patches so tcmu's netlink interface can
execute commands on specific devices.
Signed-off-by: Mike Christie <mchristi@redhat.com>
Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target/target_core_device.c')
-rw-r--r-- | drivers/target/target_core_device.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index f10dfe7b1d54..de1131612ddc 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -880,6 +880,30 @@ sector_t target_to_linux_sector(struct se_device *dev, sector_t lb) } EXPORT_SYMBOL(target_to_linux_sector); +/** + * target_find_device - find a se_device by its dev_index + * @id: dev_index + * @do_depend: true if caller needs target_depend_item to be done + * + * If do_depend is true, the caller must do a target_undepend_item + * when finished using the device. + * + * If do_depend is false, the caller must be called in a configfs + * callback or during removal. + */ +struct se_device *target_find_device(int id, bool do_depend) +{ + struct se_device *dev; + + mutex_lock(&g_device_mutex); + dev = idr_find(&devices_idr, id); + if (dev && do_depend && target_depend_item(&dev->dev_group.cg_item)) + dev = NULL; + mutex_unlock(&g_device_mutex); + return dev; +} +EXPORT_SYMBOL(target_find_device); + int target_configure_device(struct se_device *dev) { struct se_hba *hba = dev->se_hba; |