Skip to content

Commit

Permalink
scsi: target: add helper to check if dev is configured
Browse files Browse the repository at this point in the history
This just adds a helper function to check if a device is configured and it
converts the target users to use it. The next patch will add a backend
module user so those types of modules do not have to know the lio core
details.

Signed-off-by: Mike Christie <[email protected]>
Reviewed-by: Xiubo Li <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
Mike Christie authored and martinkpetersen committed Jul 31, 2018
1 parent ff07e4a commit cb0f32e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions drivers/target/target_core_configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ static ssize_t pi_prot_type_store(struct config_item *item,
dev->transport->name);
return -ENOSYS;
}
if (!(dev->dev_flags & DF_CONFIGURED)) {
if (!target_dev_configured(dev)) {
pr_err("DIF protection requires device to be configured\n");
return -ENODEV;
}
Expand Down Expand Up @@ -859,7 +859,7 @@ static ssize_t pi_prot_format_store(struct config_item *item,
dev->transport->name);
return -ENOSYS;
}
if (!(dev->dev_flags & DF_CONFIGURED)) {
if (!target_dev_configured(dev)) {
pr_err("DIF protection format requires device to be configured\n");
return -ENODEV;
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ static ssize_t target_dev_enable_show(struct config_item *item, char *page)
{
struct se_device *dev = to_device(item);

return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED));
return snprintf(page, PAGE_SIZE, "%d\n", target_dev_configured(dev));
}

static ssize_t target_dev_enable_store(struct config_item *item,
Expand Down Expand Up @@ -2473,7 +2473,7 @@ static ssize_t target_tg_pt_gp_alua_access_state_store(struct config_item *item,
" tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id);
return -EINVAL;
}
if (!(dev->dev_flags & DF_CONFIGURED)) {
if (!target_dev_configured(dev)) {
pr_err("Unable to set alua_access_state while device is"
" not configured\n");
return -ENODEV;
Expand Down
6 changes: 3 additions & 3 deletions drivers/target/target_core_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ static int target_devices_idr_iter(int id, void *p, void *data)
* to allow other callers to access partially setup devices,
* so we skip them here.
*/
if (!(dev->dev_flags & DF_CONFIGURED))
if (!target_dev_configured(dev))
return 0;

iter->prev_item = config_item_get_unless_zero(&dev->dev_group.cg_item);
Expand Down Expand Up @@ -940,7 +940,7 @@ int target_configure_device(struct se_device *dev)
struct se_hba *hba = dev->se_hba;
int ret, id;

if (dev->dev_flags & DF_CONFIGURED) {
if (target_dev_configured(dev)) {
pr_err("se_dev->se_dev_ptr already set for storage"
" object\n");
return -EEXIST;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ void target_free_device(struct se_device *dev)

WARN_ON(!list_empty(&dev->dev_sep_list));

if (dev->dev_flags & DF_CONFIGURED) {
if (target_dev_configured(dev)) {
destroy_workqueue(dev->tmr_wq);

dev->transport->destroy_device(dev);
Expand Down
3 changes: 2 additions & 1 deletion drivers/target/target_core_fabric_configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <linux/configfs.h>

#include <target/target_core_base.h>
#include <target/target_core_backend.h>
#include <target/target_core_fabric.h>

#include "target_core_internal.h"
Expand Down Expand Up @@ -642,7 +643,7 @@ static int target_fabric_port_link(
}
dev = container_of(to_config_group(se_dev_ci), struct se_device, dev_group);

if (!(dev->dev_flags & DF_CONFIGURED)) {
if (!target_dev_configured(dev)) {
pr_err("se_device not configured yet, cannot port link\n");
return -ENODEV;
}
Expand Down
4 changes: 4 additions & 0 deletions include/target/target_core_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ sector_t target_to_linux_sector(struct se_device *dev, sector_t lb);
bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
struct request_queue *q);

static inline bool target_dev_configured(struct se_device *se_dev)
{
return !!(se_dev->dev_flags & DF_CONFIGURED);
}

/* Only use get_unaligned_be24() if reading p - 1 is allowed. */
static inline uint32_t get_unaligned_be24(const uint8_t *const p)
Expand Down

0 comments on commit cb0f32e

Please sign in to comment.