Skip to content

Commit

Permalink
target: Allow control CDBs with data > 1 page
Browse files Browse the repository at this point in the history
We need to handle >1 page control cdbs, so extend the code to do a vmap
if bigger than 1 page. It seems like kmap() is still preferable if just
a page, fewer TLB shootdowns(?), so keep using that when possible.

Rename function pair for their new scope.

Signed-off-by: Andy Grover <agrover@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Andy Grover authored and Nicholas Bellinger committed Jan 18, 2012
1 parent e8904dc commit 4949314
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 54 deletions.
8 changes: 4 additions & 4 deletions drivers/target/target_core_alua.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int target_emulate_report_target_port_groups(struct se_task *task)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

spin_lock(&su_dev->t10_alua.tg_pt_gps_lock);
list_for_each_entry(tg_pt_gp, &su_dev->t10_alua.tg_pt_gps_list,
Expand Down Expand Up @@ -163,7 +163,7 @@ int target_emulate_report_target_port_groups(struct se_task *task)
buf[2] = ((rd_len >> 8) & 0xff);
buf[3] = (rd_len & 0xff);

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
Expand Down Expand Up @@ -194,7 +194,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
return -EINVAL;
}
buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

/*
* Determine if explict ALUA via SET_TARGET_PORT_GROUPS is allowed
Expand Down Expand Up @@ -351,7 +351,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
}

out:
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
return 0;
Expand Down
28 changes: 14 additions & 14 deletions drivers/target/target_core_cdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ target_emulate_inquiry_std(struct se_cmd *cmd)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

if (dev == tpg->tpg_virt_lun0.lun_se_dev) {
buf[0] = 0x3f; /* Not connected */
Expand Down Expand Up @@ -134,7 +134,7 @@ target_emulate_inquiry_std(struct se_cmd *cmd)
buf[4] = 31; /* Set additional length to 31 */

out:
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
return 0;
}

Expand Down Expand Up @@ -716,7 +716,7 @@ int target_emulate_inquiry(struct se_task *task)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

buf[0] = dev->transport->get_device_type(dev);

Expand All @@ -733,7 +733,7 @@ int target_emulate_inquiry(struct se_task *task)
ret = -EINVAL;

out_unmap:
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
out:
if (!ret) {
task->task_scsi_status = GOOD;
Expand All @@ -755,7 +755,7 @@ int target_emulate_readcapacity(struct se_task *task)
else
blocks = (u32)blocks_long;

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

buf[0] = (blocks >> 24) & 0xff;
buf[1] = (blocks >> 16) & 0xff;
Expand All @@ -771,7 +771,7 @@ int target_emulate_readcapacity(struct se_task *task)
if (dev->se_sub_dev->se_dev_attrib.emulate_tpu || dev->se_sub_dev->se_dev_attrib.emulate_tpws)
put_unaligned_be32(0xFFFFFFFF, &buf[0]);

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
Expand All @@ -785,7 +785,7 @@ int target_emulate_readcapacity_16(struct se_task *task)
unsigned char *buf;
unsigned long long blocks = dev->transport->get_blocks(dev);

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

buf[0] = (blocks >> 56) & 0xff;
buf[1] = (blocks >> 48) & 0xff;
Expand All @@ -806,7 +806,7 @@ int target_emulate_readcapacity_16(struct se_task *task)
if (dev->se_sub_dev->se_dev_attrib.emulate_tpu || dev->se_sub_dev->se_dev_attrib.emulate_tpws)
buf[14] = 0x80;

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
Expand Down Expand Up @@ -1019,9 +1019,9 @@ int target_emulate_modesense(struct se_task *task)
offset = cmd->data_length;
}

rbuf = transport_kmap_first_data_page(cmd);
rbuf = transport_kmap_data_sg(cmd);
memcpy(rbuf, buf, offset);
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
Expand All @@ -1043,7 +1043,7 @@ int target_emulate_request_sense(struct se_task *task)
return -ENOSYS;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) {
/*
Expand Down Expand Up @@ -1089,7 +1089,7 @@ int target_emulate_request_sense(struct se_task *task)
}

end:
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
return 0;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ int target_emulate_unmap(struct se_task *task)
dl = get_unaligned_be16(&cdb[0]);
bd_dl = get_unaligned_be16(&cdb[2]);

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

ptr = &buf[offset];
pr_debug("UNMAP: Sub: %s Using dl: %hu bd_dl: %hu size: %hu"
Expand All @@ -1147,7 +1147,7 @@ int target_emulate_unmap(struct se_task *task)
}

err:
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
if (!ret) {
task->task_scsi_status = GOOD;
transport_complete_task(task, 1);
Expand Down
4 changes: 2 additions & 2 deletions drivers/target/target_core_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ int target_report_luns(struct se_task *se_task)
unsigned char *buf;
u32 cdb_offset = 0, lun_count = 0, offset = 8, i;

buf = transport_kmap_first_data_page(se_cmd);
buf = (unsigned char *) transport_kmap_data_sg(se_cmd);

/*
* If no struct se_session pointer is present, this struct se_cmd is
Expand Down Expand Up @@ -695,7 +695,7 @@ int target_report_luns(struct se_task *se_task)
* See SPC3 r07, page 159.
*/
done:
transport_kunmap_first_data_page(se_cmd);
transport_kunmap_data_sg(se_cmd);
lun_count *= 8;
buf[0] = ((lun_count >> 24) & 0xff);
buf[1] = ((lun_count >> 16) & 0xff);
Expand Down
38 changes: 19 additions & 19 deletions drivers/target/target_core_pr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ static int core_scsi3_decode_spec_i_port(
tidh_new->dest_local_nexus = 1;
list_add_tail(&tidh_new->dest_list, &tid_dest_list);

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);
/*
* For a PERSISTENT RESERVE OUT specify initiator ports payload,
* first extract TransportID Parameter Data Length, and make sure
Expand Down Expand Up @@ -1786,7 +1786,7 @@ static int core_scsi3_decode_spec_i_port(

}

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

/*
* Go ahead and create a registrations from tid_dest_list for the
Expand Down Expand Up @@ -1834,7 +1834,7 @@ static int core_scsi3_decode_spec_i_port(

return 0;
out:
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
/*
* For the failure case, release everything from tid_dest_list
* including *dest_pr_reg and the configfs dependances..
Expand Down Expand Up @@ -3411,14 +3411,14 @@ static int core_scsi3_emulate_pro_register_and_move(
* will be moved to for the TransportID containing SCSI initiator WWN
* information.
*/
buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);
rtpi = (buf[18] & 0xff) << 8;
rtpi |= buf[19] & 0xff;
tid_len = (buf[20] & 0xff) << 24;
tid_len |= (buf[21] & 0xff) << 16;
tid_len |= (buf[22] & 0xff) << 8;
tid_len |= buf[23] & 0xff;
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
buf = NULL;

if ((tid_len + 24) != cmd->data_length) {
Expand Down Expand Up @@ -3470,7 +3470,7 @@ static int core_scsi3_emulate_pro_register_and_move(
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);
proto_ident = (buf[24] & 0x0f);
#if 0
pr_debug("SPC-3 PR REGISTER_AND_MOVE: Extracted Protocol Identifier:"
Expand Down Expand Up @@ -3504,7 +3504,7 @@ static int core_scsi3_emulate_pro_register_and_move(
goto out;
}

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
buf = NULL;

pr_debug("SPC-3 PR [%s] Extracted initiator %s identifier: %s"
Expand Down Expand Up @@ -3769,13 +3769,13 @@ static int core_scsi3_emulate_pro_register_and_move(
" REGISTER_AND_MOVE\n");
}

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

core_scsi3_put_pr_reg(dest_pr_reg);
return 0;
out:
if (buf)
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
if (dest_se_deve)
core_scsi3_lunacl_undepend_item(dest_se_deve);
if (dest_node_acl)
Expand Down Expand Up @@ -3849,7 +3849,7 @@ int target_scsi3_emulate_pr_out(struct se_task *task)
scope = (cdb[2] & 0xf0);
type = (cdb[2] & 0x0f);

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);
/*
* From PERSISTENT_RESERVE_OUT parameter list (payload)
*/
Expand All @@ -3867,7 +3867,7 @@ int target_scsi3_emulate_pr_out(struct se_task *task)
aptpl = (buf[17] & 0x01);
unreg = (buf[17] & 0x02);
}
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);
buf = NULL;

/*
Expand Down Expand Up @@ -3967,7 +3967,7 @@ static int core_scsi3_pri_read_keys(struct se_cmd *cmd)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);
buf[0] = ((su_dev->t10_pr.pr_generation >> 24) & 0xff);
buf[1] = ((su_dev->t10_pr.pr_generation >> 16) & 0xff);
buf[2] = ((su_dev->t10_pr.pr_generation >> 8) & 0xff);
Expand Down Expand Up @@ -4001,7 +4001,7 @@ static int core_scsi3_pri_read_keys(struct se_cmd *cmd)
buf[6] = ((add_len >> 8) & 0xff);
buf[7] = (add_len & 0xff);

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

return 0;
}
Expand All @@ -4027,7 +4027,7 @@ static int core_scsi3_pri_read_reservation(struct se_cmd *cmd)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);
buf[0] = ((su_dev->t10_pr.pr_generation >> 24) & 0xff);
buf[1] = ((su_dev->t10_pr.pr_generation >> 16) & 0xff);
buf[2] = ((su_dev->t10_pr.pr_generation >> 8) & 0xff);
Expand Down Expand Up @@ -4086,7 +4086,7 @@ static int core_scsi3_pri_read_reservation(struct se_cmd *cmd)

err:
spin_unlock(&se_dev->dev_reservation_lock);
transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

return 0;
}
Expand All @@ -4110,7 +4110,7 @@ static int core_scsi3_pri_report_capabilities(struct se_cmd *cmd)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

buf[0] = ((add_len << 8) & 0xff);
buf[1] = (add_len & 0xff);
Expand Down Expand Up @@ -4142,7 +4142,7 @@ static int core_scsi3_pri_report_capabilities(struct se_cmd *cmd)
buf[4] |= 0x02; /* PR_TYPE_WRITE_EXCLUSIVE */
buf[5] |= 0x01; /* PR_TYPE_EXCLUSIVE_ACCESS_ALLREG */

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

return 0;
}
Expand Down Expand Up @@ -4172,7 +4172,7 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
return -EINVAL;
}

buf = transport_kmap_first_data_page(cmd);
buf = transport_kmap_data_sg(cmd);

buf[0] = ((su_dev->t10_pr.pr_generation >> 24) & 0xff);
buf[1] = ((su_dev->t10_pr.pr_generation >> 16) & 0xff);
Expand Down Expand Up @@ -4293,7 +4293,7 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
buf[6] = ((add_len >> 8) & 0xff);
buf[7] = (add_len & 0xff);

transport_kunmap_first_data_page(cmd);
transport_kunmap_data_sg(cmd);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/target/target_core_pscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ static int pscsi_transport_complete(struct se_task *task)

if (task->task_se_cmd->se_deve->lun_flags &
TRANSPORT_LUNFLAGS_READ_ONLY) {
unsigned char *buf = transport_kmap_first_data_page(task->task_se_cmd);
unsigned char *buf = transport_kmap_data_sg(task->task_se_cmd);

if (cdb[0] == MODE_SENSE_10) {
if (!(buf[3] & 0x80))
Expand All @@ -703,7 +703,7 @@ static int pscsi_transport_complete(struct se_task *task)
buf[2] |= 0x80;
}

transport_kunmap_first_data_page(task->task_se_cmd);
transport_kunmap_data_sg(task->task_se_cmd);
}
}
after_mode_sense:
Expand Down
Loading

0 comments on commit 4949314

Please sign in to comment.