Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For next #265

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7861728
target: Add target_alloc_session() helper function
Jan 9, 2016
8b00965
target: Convert demo-mode only drivers to target_alloc_session
Jan 9, 2016
1ccafc1
vhost/scsi: Convert to target_alloc_session usage
Jan 9, 2016
910e0c6
tcm_qla2xxx: Convert to target_alloc_session usage
Jan 9, 2016
869525a
tcm_fc: Convert to target_alloc_session usage
Jan 10, 2016
d74a601
ib_srpt: Convert to target_alloc_session usage
Jan 10, 2016
e7741b0
sbp-target: Conversion to percpu_ida tag pre-allocation
Jan 23, 2016
a778862
sbp-target: Convert to TARGET_SCF_ACK_KREF I/O krefs
Jan 25, 2016
1fdf5f7
usb-gadget/tcm: Conversion to percpu_ida tag pre-allocation
Jan 23, 2016
c4468d4
usb-gadget/tcm: Convert to TARGET_SCF_ACK_KREF I/O krefs
Jan 25, 2016
194509e
xen-scsiback: Convert to percpu_ida tag allocation
Jan 25, 2016
130e8a2
xen-scsiback: Convert to TARGET_SCF_ACK_KREF I/O krefs
Jan 25, 2016
c8d336d
tcm_fc: Convert to TARGET_SCF_ACK_KREF I/O + TMR krefs
Jan 30, 2016
1335b45
ib_srpt: Convert to percpu_ida tag allocation
Jan 30, 2016
1d5c042
qla2xxx: Add DebugFS node for target sess list.
Feb 4, 2016
b609cc1
iser-target: Fix identification of login rx descriptor type
jennyj-mellanox Feb 24, 2016
eb2770e
iser-target: Add new state ISER_CONN_BOUND to isert_conn
jennyj-mellanox Feb 24, 2016
cd7f942
iser-target: Separate flows for np listeners and connections cma events
jennyj-mellanox Feb 24, 2016
ff93150
iser-target: Rework connection termination
jennyj-mellanox Feb 24, 2016
c3d141c
iser-target: Remove redundant wait in release_conn
jennyj-mellanox Feb 24, 2016
2e54a93
iser-target: Remove impossible condition from isert_wait_conn
jennyj-mellanox Feb 24, 2016
a6324f7
iser-target: Remove ISER_RECV_DATA_SEG_LEN
Feb 24, 2016
7e2f756
iser-target: Split and properly type the login buffer
Feb 24, 2016
c3ddb7f
iser-target: Convert to new CQ API
Feb 24, 2016
fd625eb
iser-target: Kill struct isert_rdma_wr
Feb 24, 2016
2866108
iser-target: Kill the ->isert_cmd back pointer in struct iser_tx_desc
Feb 24, 2016
cf12009
target/iblock: pass WRITE_SAME to device if possible
Feb 24, 2016
0a95b29
target: Remove enum transport_lunflags_table
Feb 25, 2016
ba6b96e
target/user: Use iovec[] to describe continuous area
yasker Feb 26, 2016
62e7b25
target/user: Free data ring in unified function
yasker Feb 26, 2016
a1171a3
target/user: Introduce data_bitmap, replace data_length/data_head/dat…
yasker Feb 26, 2016
dbfc15a
target/user: Don't free expired command when time out
yasker Feb 26, 2016
27d5306
target/user: Fix size_t format-spec build warning
Feb 28, 2016
01d6eea
target/user: Report capability of handling out-of-order completions t…
yasker Mar 1, 2016
2654cf3
target: Avoid DataIN transfers for non-GOOD SAM status
Mar 5, 2016
f630dbf
target/iblock: Use -EAGAIN/-ENOMEM to propigate SAM BUSY/TASK_SET_FULL
Feb 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
target: Remove enum transport_lunflags_table
se_dev_entry.lun_flags and se_lun.lun_access are only used for keeping
track of read-write vs. read-only state. Since this is an either/or thing
we can represent it as bool, and remove the unneeded enum
transport_lunflags_table, which is left over from when there were more
flags.

Change code that uses this enum to just use true/false, and make it clear
through variable and param names that true means read-only, false means
read-write.

Signed-off-by: Andy Grover <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Nicholas Bellinger <[email protected]>
  • Loading branch information
Andy Grover authored and Nicholas Bellinger committed Mar 5, 2016
commit 0a95b2911d03ead8a1e501cbfb60488ccc048b53
41 changes: 14 additions & 27 deletions drivers/target/target_core_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
se_cmd->lun_ref_active = true;

if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
(deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) {
deve->lun_access_ro) {
pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
" Access for 0x%08llx\n",
se_cmd->se_tfo->get_fabric_name(),
Expand Down Expand Up @@ -199,7 +199,7 @@ bool target_lun_is_rdonly(struct se_cmd *cmd)

rcu_read_lock();
deve = target_nacl_find_deve(se_sess->se_node_acl, cmd->orig_fe_lun);
ret = (deve && deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY);
ret = deve && deve->lun_access_ro;
rcu_read_unlock();

return ret;
Expand Down Expand Up @@ -258,22 +258,15 @@ void core_free_device_list_for_node(

void core_update_device_list_access(
u64 mapped_lun,
u32 lun_access,
bool lun_access_ro,
struct se_node_acl *nacl)
{
struct se_dev_entry *deve;

mutex_lock(&nacl->lun_entry_mutex);
deve = target_nacl_find_deve(nacl, mapped_lun);
if (deve) {
if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) {
deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY;
deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE;
} else {
deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
}
}
if (deve)
deve->lun_access_ro = lun_access_ro;
mutex_unlock(&nacl->lun_entry_mutex);
}

Expand Down Expand Up @@ -319,7 +312,7 @@ int core_enable_device_list_for_node(
struct se_lun *lun,
struct se_lun_acl *lun_acl,
u64 mapped_lun,
u32 lun_access,
bool lun_access_ro,
struct se_node_acl *nacl,
struct se_portal_group *tpg)
{
Expand All @@ -340,11 +333,7 @@ int core_enable_device_list_for_node(
kref_init(&new->pr_kref);
init_completion(&new->pr_comp);

if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE)
new->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE;
else
new->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;

new->lun_access_ro = lun_access_ro;
new->creation_time = get_jiffies_64();
new->attach_count++;

Expand Down Expand Up @@ -433,7 +422,7 @@ void core_disable_device_list_for_node(

hlist_del_rcu(&orig->link);
clear_bit(DEF_PR_REG_ACTIVE, &orig->deve_flags);
orig->lun_flags = 0;
orig->lun_access_ro = false;
orig->creation_time = 0;
orig->attach_count--;
/*
Expand Down Expand Up @@ -558,8 +547,7 @@ int core_dev_add_lun(
{
int rc;

rc = core_tpg_add_lun(tpg, lun,
TRANSPORT_LUNFLAGS_READ_WRITE, dev);
rc = core_tpg_add_lun(tpg, lun, false, dev);
if (rc < 0)
return rc;

Expand Down Expand Up @@ -635,7 +623,7 @@ int core_dev_add_initiator_node_lun_acl(
struct se_portal_group *tpg,
struct se_lun_acl *lacl,
struct se_lun *lun,
u32 lun_access)
bool lun_access_ro)
{
struct se_node_acl *nacl = lacl->se_lun_nacl;
/*
Expand All @@ -647,20 +635,19 @@ int core_dev_add_initiator_node_lun_acl(
if (!nacl)
return -EINVAL;

if ((lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) &&
(lun_access & TRANSPORT_LUNFLAGS_READ_WRITE))
lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
if (lun->lun_access_ro)
lun_access_ro = true;

lacl->se_lun = lun;

if (core_enable_device_list_for_node(lun, lacl, lacl->mapped_lun,
lun_access, nacl, tpg) < 0)
lun_access_ro, nacl, tpg) < 0)
return -EINVAL;

pr_debug("%s_TPG[%hu]_LUN[%llu->%llu] - Added %s ACL for "
" InitiatorNode: %s\n", tpg->se_tpg_tfo->get_fabric_name(),
tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, lacl->mapped_lun,
(lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) ? "RW" : "RO",
lun_access_ro ? "RO" : "RW",
nacl->initiatorname);
/*
* Check to see if there are any existing persistent reservation APTPL
Expand Down
32 changes: 14 additions & 18 deletions drivers/target/target_core_fabric_configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static int target_fabric_mappedlun_link(
struct se_lun_acl, se_lun_group);
struct se_portal_group *se_tpg;
struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s;
int lun_access;
bool lun_access_ro;

if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) {
pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:"
Expand Down Expand Up @@ -115,27 +115,26 @@ static int target_fabric_mappedlun_link(
}
/*
* If this struct se_node_acl was dynamically generated with
* tpg_1/attrib/generate_node_acls=1, use the existing deve->lun_flags,
* which be will write protected (READ-ONLY) when
* tpg_1/attrib/generate_node_acls=1, use the existing
* deve->lun_access_ro value, which will be true when
* tpg_1/attrib/demo_mode_write_protect=1
*/
rcu_read_lock();
deve = target_nacl_find_deve(lacl->se_lun_nacl, lacl->mapped_lun);
if (deve)
lun_access = deve->lun_flags;
lun_access_ro = deve->lun_access_ro;
else
lun_access =
lun_access_ro =
(se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect(
se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY :
TRANSPORT_LUNFLAGS_READ_WRITE;
se_tpg)) ? true : false;
rcu_read_unlock();
/*
* Determine the actual mapped LUN value user wants..
*
* This value is what the SCSI Initiator actually sees the
* $FABRIC/$WWPN/$TPGT/lun/lun_* as on their SCSI Initiator Ports.
*/
return core_dev_add_initiator_node_lun_acl(se_tpg, lacl, lun, lun_access);
return core_dev_add_initiator_node_lun_acl(se_tpg, lacl, lun, lun_access_ro);
}

static int target_fabric_mappedlun_unlink(
Expand Down Expand Up @@ -167,8 +166,7 @@ static ssize_t target_fabric_mappedlun_write_protect_show(
rcu_read_lock();
deve = target_nacl_find_deve(se_nacl, lacl->mapped_lun);
if (deve) {
len = sprintf(page, "%d\n",
(deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ? 1 : 0);
len = sprintf(page, "%d\n", deve->lun_access_ro);
}
rcu_read_unlock();

Expand All @@ -181,25 +179,23 @@ static ssize_t target_fabric_mappedlun_write_protect_store(
struct se_lun_acl *lacl = item_to_lun_acl(item);
struct se_node_acl *se_nacl = lacl->se_lun_nacl;
struct se_portal_group *se_tpg = se_nacl->se_tpg;
unsigned long op;
unsigned long wp;
int ret;

ret = kstrtoul(page, 0, &op);
ret = kstrtoul(page, 0, &wp);
if (ret)
return ret;

if ((op != 1) && (op != 0))
if ((wp != 1) && (wp != 0))
return -EINVAL;

core_update_device_list_access(lacl->mapped_lun, (op) ?
TRANSPORT_LUNFLAGS_READ_ONLY :
TRANSPORT_LUNFLAGS_READ_WRITE,
lacl->se_lun_nacl);
/* wp=1 means lun_access_ro=true */
core_update_device_list_access(lacl->mapped_lun, wp, lacl->se_lun_nacl);

pr_debug("%s_ConfigFS: Changed Initiator ACL: %s"
" Mapped LUN: %llu Write Protect bit to %s\n",
se_tpg->se_tpg_tfo->get_fabric_name(),
se_nacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF");
se_nacl->initiatorname, lacl->mapped_lun, (wp) ? "ON" : "OFF");

return count;

Expand Down
8 changes: 4 additions & 4 deletions drivers/target/target_core_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16);
void target_pr_kref_release(struct kref *);
void core_free_device_list_for_node(struct se_node_acl *,
struct se_portal_group *);
void core_update_device_list_access(u64, u32, struct se_node_acl *);
void core_update_device_list_access(u64, bool, struct se_node_acl *);
struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *, u64);
int core_enable_device_list_for_node(struct se_lun *, struct se_lun_acl *,
u64, u32, struct se_node_acl *, struct se_portal_group *);
u64, bool, struct se_node_acl *, struct se_portal_group *);
void core_disable_device_list_for_node(struct se_lun *, struct se_dev_entry *,
struct se_node_acl *, struct se_portal_group *);
void core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *);
Expand All @@ -73,7 +73,7 @@ void core_dev_del_lun(struct se_portal_group *, struct se_lun *);
struct se_lun_acl *core_dev_init_initiator_node_lun_acl(struct se_portal_group *,
struct se_node_acl *, u64, int *);
int core_dev_add_initiator_node_lun_acl(struct se_portal_group *,
struct se_lun_acl *, struct se_lun *lun, u32);
struct se_lun_acl *, struct se_lun *lun, bool);
int core_dev_del_initiator_node_lun_acl(struct se_lun *,
struct se_lun_acl *);
void core_dev_free_initiator_node_lun_acl(struct se_portal_group *,
Expand Down Expand Up @@ -119,7 +119,7 @@ void core_tpg_add_node_to_devs(struct se_node_acl *, struct se_portal_group *,
void core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *);
struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u64);
int core_tpg_add_lun(struct se_portal_group *, struct se_lun *,
u32, struct se_device *);
bool, struct se_device *);
void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *);
struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg,
const char *initiatorname);
Expand Down
3 changes: 1 addition & 2 deletions drivers/target/target_core_spc.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
int length = 0;
int ret;
int i;
bool read_only = target_lun_is_rdonly(cmd);;

memset(buf, 0, SE_MODE_PAGE_BUF);

Expand All @@ -1008,7 +1007,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
length = ten ? 3 : 2;

/* DEVICE-SPECIFIC PARAMETER */
if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) || read_only)
if (cmd->se_lun->lun_access_ro || target_lun_is_rdonly(cmd))
spc_modesense_write_protect(&buf[length], type);

/*
Expand Down
21 changes: 10 additions & 11 deletions drivers/target/target_core_tpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void core_tpg_add_node_to_devs(
struct se_portal_group *tpg,
struct se_lun *lun_orig)
{
u32 lun_access = 0;
bool lun_access_ro = true;
struct se_lun *lun;
struct se_device *dev;

Expand All @@ -137,27 +137,26 @@ void core_tpg_add_node_to_devs(
* demo_mode_write_protect is ON, or READ_ONLY;
*/
if (!tpg->se_tpg_tfo->tpg_check_demo_mode_write_protect(tpg)) {
lun_access = TRANSPORT_LUNFLAGS_READ_WRITE;
lun_access_ro = false;
} else {
/*
* Allow only optical drives to issue R/W in default RO
* demo mode.
*/
if (dev->transport->get_device_type(dev) == TYPE_DISK)
lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
lun_access_ro = true;
else
lun_access = TRANSPORT_LUNFLAGS_READ_WRITE;
lun_access_ro = false;
}

pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%llu] - Adding %s"
" access for LUN in Demo Mode\n",
tpg->se_tpg_tfo->get_fabric_name(),
tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
(lun_access == TRANSPORT_LUNFLAGS_READ_WRITE) ?
"READ-WRITE" : "READ-ONLY");
lun_access_ro ? "READ-ONLY" : "READ-WRITE");

core_enable_device_list_for_node(lun, NULL, lun->unpacked_lun,
lun_access, acl, tpg);
lun_access_ro, acl, tpg);
/*
* Check to see if there are any existing persistent reservation
* APTPL pre-registrations that need to be enabled for this dynamic
Expand Down Expand Up @@ -522,7 +521,7 @@ int core_tpg_register(
return PTR_ERR(se_tpg->tpg_virt_lun0);

ret = core_tpg_add_lun(se_tpg, se_tpg->tpg_virt_lun0,
TRANSPORT_LUNFLAGS_READ_ONLY, g_lun0_dev);
true, g_lun0_dev);
if (ret < 0) {
kfree(se_tpg->tpg_virt_lun0);
return ret;
Expand Down Expand Up @@ -616,7 +615,7 @@ struct se_lun *core_tpg_alloc_lun(
int core_tpg_add_lun(
struct se_portal_group *tpg,
struct se_lun *lun,
u32 lun_access,
bool lun_access_ro,
struct se_device *dev)
{
int ret;
Expand Down Expand Up @@ -644,9 +643,9 @@ int core_tpg_add_lun(
spin_unlock(&dev->se_port_lock);

if (dev->dev_flags & DF_READ_ONLY)
lun->lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
lun->lun_access_ro = true;
else
lun->lun_access = lun_access;
lun->lun_access_ro = lun_access_ro;
if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE))
hlist_add_head_rcu(&lun->link, &tpg->tpg_lun_hlist);
mutex_unlock(&tpg->tpg_lun_mutex);
Expand Down
11 changes: 2 additions & 9 deletions include/target/target_core_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ enum se_cmd_flags_table {
SCF_USE_CPUID = 0x00800000,
};

/* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
enum transport_lunflags_table {
TRANSPORT_LUNFLAGS_READ_ONLY = 0x01,
TRANSPORT_LUNFLAGS_READ_WRITE = 0x02,
};

/*
* Used by transport_send_check_condition_and_sense()
* to signal which ASC/ASCQ sense payload should be built.
Expand Down Expand Up @@ -634,11 +628,10 @@ struct se_lun_acl {
};

struct se_dev_entry {
/* See transport_lunflags_table */
u64 mapped_lun;
u64 pr_res_key;
u64 creation_time;
u32 lun_flags;
bool lun_access_ro;
u32 attach_count;
atomic_long_t total_cmds;
atomic_long_t read_bytes;
Expand Down Expand Up @@ -712,7 +705,7 @@ struct se_lun {
u64 unpacked_lun;
#define SE_LUN_LINK_MAGIC 0xffff7771
u32 lun_link_magic;
u32 lun_access;
bool lun_access_ro;
u32 lun_index;

/* RELATIVE TARGET PORT IDENTIFER */
Expand Down