diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-10-01 20:23:22 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-10-02 17:16:08 -0400 |
commit | a026757ff56365b4aa3875c14f1bd5733e0e8bb2 (patch) | |
tree | c9cd1990da5bc8cc11808a78067e96923091e006 | |
parent | 38b11bae6ba02da352340aff12ee25755977b222 (diff) |
target: Add target_submit_cmd_map_sgls for SGL fabric memory passthrough
This patch adds a new target_submit_cmd_map_sgls() to pass pre-allocated
SGL memory using transport_generic_map_mem_to_cmd() logic into the generic
target submit I/O codepath.
It also adds a target_submit_cmd() wrapper around target_submit_cmd_map_sgls()
for existing fabric code that already assumes internal target-core SGL memory
allocation.
(v2: Rename to target_submit_cmd_map_sgls + drop TARGET_SCF_MAP_MEM flag
in favor of non zero sgl_count check)
Reported-by: Christoph Hellwig <hch@lst.de>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r-- | drivers/target/target_core_transport.c | 65 | ||||
-rw-r--r-- | include/target/target_core_fabric.h | 3 |
2 files changed, 62 insertions, 6 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 221f67f3427c..d96d9aa3a496 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -1455,8 +1455,9 @@ int transport_handle_cdb_direct( | |||
1455 | } | 1455 | } |
1456 | EXPORT_SYMBOL(transport_handle_cdb_direct); | 1456 | EXPORT_SYMBOL(transport_handle_cdb_direct); |
1457 | 1457 | ||
1458 | /** | 1458 | /* |
1459 | * target_submit_cmd - lookup unpacked lun and submit uninitialized se_cmd | 1459 | * target_submit_cmd_map_sgls - lookup unpacked lun and submit uninitialized |
1460 | * se_cmd + use pre-allocated SGL memory. | ||
1460 | * | 1461 | * |
1461 | * @se_cmd: command descriptor to submit | 1462 | * @se_cmd: command descriptor to submit |
1462 | * @se_sess: associated se_sess for endpoint | 1463 | * @se_sess: associated se_sess for endpoint |
@@ -1467,6 +1468,10 @@ EXPORT_SYMBOL(transport_handle_cdb_direct); | |||
1467 | * @task_addr: SAM task attribute | 1468 | * @task_addr: SAM task attribute |
1468 | * @data_dir: DMA data direction | 1469 | * @data_dir: DMA data direction |
1469 | * @flags: flags for command submission from target_sc_flags_tables | 1470 | * @flags: flags for command submission from target_sc_flags_tables |
1471 | * @sgl: struct scatterlist memory for unidirectional mapping | ||
1472 | * @sgl_count: scatterlist count for unidirectional mapping | ||
1473 | * @sgl_bidi: struct scatterlist memory for bidirectional READ mapping | ||
1474 | * @sgl_bidi_count: scatterlist count for bidirectional READ mapping | ||
1470 | * | 1475 | * |
1471 | * Returns non zero to signal active I/O shutdown failure. All other | 1476 | * Returns non zero to signal active I/O shutdown failure. All other |
1472 | * setup exceptions will be returned as a SCSI CHECK_CONDITION response, | 1477 | * setup exceptions will be returned as a SCSI CHECK_CONDITION response, |
@@ -1474,10 +1479,12 @@ EXPORT_SYMBOL(transport_handle_cdb_direct); | |||
1474 | * | 1479 | * |
1475 | * This may only be called from process context, and also currently | 1480 | * This may only be called from process context, and also currently |
1476 | * assumes internal allocation of fabric payload buffer by target-core. | 1481 | * assumes internal allocation of fabric payload buffer by target-core. |
1477 | **/ | 1482 | */ |
1478 | int target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, | 1483 | int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess, |
1479 | unsigned char *cdb, unsigned char *sense, u32 unpacked_lun, | 1484 | unsigned char *cdb, unsigned char *sense, u32 unpacked_lun, |
1480 | u32 data_length, int task_attr, int data_dir, int flags) | 1485 | u32 data_length, int task_attr, int data_dir, int flags, |
1486 | struct scatterlist *sgl, u32 sgl_count, | ||
1487 | struct scatterlist *sgl_bidi, u32 sgl_bidi_count) | ||
1481 | { | 1488 | { |
1482 | struct se_portal_group *se_tpg; | 1489 | struct se_portal_group *se_tpg; |
1483 | int rc; | 1490 | int rc; |
@@ -1524,7 +1531,21 @@ int target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, | |||
1524 | transport_generic_request_failure(se_cmd); | 1531 | transport_generic_request_failure(se_cmd); |
1525 | return 0; | 1532 | return 0; |
1526 | } | 1533 | } |
1527 | 1534 | /* | |
1535 | * When a non zero sgl_count has been passed perform SGL passthrough | ||
1536 | * mapping for pre-allocated fabric memory instead of having target | ||
1537 | * core perform an internal SGL allocation.. | ||
1538 | */ | ||
1539 | if (sgl_count != 0) { | ||
1540 | BUG_ON(!sgl); | ||
1541 | |||
1542 | rc = transport_generic_map_mem_to_cmd(se_cmd, sgl, sgl_count, | ||
1543 | sgl_bidi, sgl_bidi_count); | ||
1544 | if (rc != 0) { | ||
1545 | transport_generic_request_failure(se_cmd); | ||
1546 | return 0; | ||
1547 | } | ||
1548 | } | ||
1528 | /* | 1549 | /* |
1529 | * Check if we need to delay processing because of ALUA | 1550 | * Check if we need to delay processing because of ALUA |
1530 | * Active/NonOptimized primary access state.. | 1551 | * Active/NonOptimized primary access state.. |
@@ -1534,6 +1555,38 @@ int target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, | |||
1534 | transport_handle_cdb_direct(se_cmd); | 1555 | transport_handle_cdb_direct(se_cmd); |
1535 | return 0; | 1556 | return 0; |
1536 | } | 1557 | } |
1558 | EXPORT_SYMBOL(target_submit_cmd_map_sgls); | ||
1559 | |||
1560 | /* | ||
1561 | * target_submit_cmd - lookup unpacked lun and submit uninitialized se_cmd | ||
1562 | * | ||
1563 | * @se_cmd: command descriptor to submit | ||
1564 | * @se_sess: associated se_sess for endpoint | ||
1565 | * @cdb: pointer to SCSI CDB | ||
1566 | * @sense: pointer to SCSI sense buffer | ||
1567 | * @unpacked_lun: unpacked LUN to reference for struct se_lun | ||
1568 | * @data_length: fabric expected data transfer length | ||
1569 | * @task_addr: SAM task attribute | ||
1570 | * @data_dir: DMA data direction | ||
1571 | * @flags: flags for command submission from target_sc_flags_tables | ||
1572 | * | ||
1573 | * Returns non zero to signal active I/O shutdown failure. All other | ||
1574 | * setup exceptions will be returned as a SCSI CHECK_CONDITION response, | ||
1575 | * but still return zero here. | ||
1576 | * | ||
1577 | * This may only be called from process context, and also currently | ||
1578 | * assumes internal allocation of fabric payload buffer by target-core. | ||
1579 | * | ||
1580 | * It also assumes interal target core SGL memory allocation. | ||
1581 | */ | ||
1582 | int target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, | ||
1583 | unsigned char *cdb, unsigned char *sense, u32 unpacked_lun, | ||
1584 | u32 data_length, int task_attr, int data_dir, int flags) | ||
1585 | { | ||
1586 | return target_submit_cmd_map_sgls(se_cmd, se_sess, cdb, sense, | ||
1587 | unpacked_lun, data_length, task_attr, data_dir, | ||
1588 | flags, NULL, 0, NULL, 0); | ||
1589 | } | ||
1537 | EXPORT_SYMBOL(target_submit_cmd); | 1590 | EXPORT_SYMBOL(target_submit_cmd); |
1538 | 1591 | ||
1539 | static void target_complete_tmr_failure(struct work_struct *work) | 1592 | static void target_complete_tmr_failure(struct work_struct *work) |
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 85a5d7a99543..81ddb4ae6c3f 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h | |||
@@ -100,6 +100,9 @@ void transport_init_se_cmd(struct se_cmd *, struct target_core_fabric_ops *, | |||
100 | struct se_session *, u32, int, int, unsigned char *); | 100 | struct se_session *, u32, int, int, unsigned char *); |
101 | int transport_lookup_cmd_lun(struct se_cmd *, u32); | 101 | int transport_lookup_cmd_lun(struct se_cmd *, u32); |
102 | int target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); | 102 | int target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); |
103 | int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *, | ||
104 | unsigned char *, unsigned char *, u32, u32, int, int, int, | ||
105 | struct scatterlist *, u32, struct scatterlist *, u32); | ||
103 | int target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *, | 106 | int target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *, |
104 | unsigned char *, u32, u32, int, int, int); | 107 | unsigned char *, u32, u32, int, int, int); |
105 | int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, | 108 | int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, |