Skip to content

Commit 5c48a4e

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: target: core: Move buffer clearing hack
Move the hack to clear some buffers to transport_handle_cdb_direct() so we can eventually merge transport_handle_cdb_direct() and target_submit(). This also fixes up the comment so it's clear it was only for udev and reflects that the referenced function does not exist and we now allow more than 1 page for control CDBs. Signed-off-by: Mike Christie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ee48345 commit 5c48a4e

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

drivers/target/target_core_transport.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,27 @@ int transport_handle_cdb_direct(
15921592
*/
15931593
core_alua_check_nonop_delay(cmd);
15941594

1595+
if (cmd->t_data_nents != 0) {
1596+
/*
1597+
* This is primarily a hack for udev and tcm loop which sends
1598+
* INQUIRYs with a single page and expects the data to be
1599+
* cleared.
1600+
*/
1601+
if (!(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) &&
1602+
cmd->data_direction == DMA_FROM_DEVICE) {
1603+
struct scatterlist *sgl = cmd->t_data_sg;
1604+
unsigned char *buf = NULL;
1605+
1606+
BUG_ON(!sgl);
1607+
1608+
buf = kmap_local_page(sg_page(sgl));
1609+
if (buf) {
1610+
memset(buf + sgl->offset, 0, sgl->length);
1611+
kunmap_local(buf);
1612+
}
1613+
}
1614+
}
1615+
15951616
if (!cmd->se_lun) {
15961617
dump_stack();
15971618
pr_err("cmd->se_lun is NULL\n");
@@ -1795,34 +1816,6 @@ EXPORT_SYMBOL_GPL(target_submit_prep);
17951816
*/
17961817
void target_submit(struct se_cmd *se_cmd)
17971818
{
1798-
struct scatterlist *sgl = se_cmd->t_data_sg;
1799-
unsigned char *buf = NULL;
1800-
1801-
might_sleep();
1802-
1803-
if (se_cmd->t_data_nents != 0) {
1804-
BUG_ON(!sgl);
1805-
/*
1806-
* A work-around for tcm_loop as some userspace code via
1807-
* scsi-generic do not memset their associated read buffers,
1808-
* so go ahead and do that here for type non-data CDBs. Also
1809-
* note that this is currently guaranteed to be a single SGL
1810-
* for this case by target core in target_setup_cmd_from_cdb()
1811-
* -> transport_generic_cmd_sequencer().
1812-
*/
1813-
if (!(se_cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) &&
1814-
se_cmd->data_direction == DMA_FROM_DEVICE) {
1815-
if (sgl)
1816-
buf = kmap(sg_page(sgl)) + sgl->offset;
1817-
1818-
if (buf) {
1819-
memset(buf, 0, sgl->length);
1820-
kunmap(sg_page(sgl));
1821-
}
1822-
}
1823-
1824-
}
1825-
18261819
transport_handle_cdb_direct(se_cmd);
18271820
}
18281821
EXPORT_SYMBOL_GPL(target_submit);

0 commit comments

Comments
 (0)