diff options
author | Christoph Hellwig <hch@infradead.org> | 2012-02-02 17:04:41 -0500 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-02-25 17:37:48 -0500 |
commit | afe2cb7fb111ac52ec95ab2bfb19d9d9e0d52ed8 (patch) | |
tree | f4ae15c8e06727b90e81405776d32d59c71aafcc /drivers/target | |
parent | f872c9f417a38a08b6ffe46e1f937d3db1d22775 (diff) |
tcm_loop: defer all command submissions to workqueue
Apply the qla2xxx model of submitting all commands from a workqueue.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/loopback/tcm_loop.c | 97 | ||||
-rw-r--r-- | drivers/target/loopback/tcm_loop.h | 2 |
2 files changed, 58 insertions, 41 deletions
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index b1edc517f4e3..cb8893f303a5 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c | |||
@@ -44,6 +44,7 @@ | |||
44 | /* Local pointer to allocated TCM configfs fabric module */ | 44 | /* Local pointer to allocated TCM configfs fabric module */ |
45 | static struct target_fabric_configfs *tcm_loop_fabric_configfs; | 45 | static struct target_fabric_configfs *tcm_loop_fabric_configfs; |
46 | 46 | ||
47 | static struct workqueue_struct *tcm_loop_workqueue; | ||
47 | static struct kmem_cache *tcm_loop_cmd_cache; | 48 | static struct kmem_cache *tcm_loop_cmd_cache; |
48 | 49 | ||
49 | static int tcm_loop_hba_no_cnt; | 50 | static int tcm_loop_hba_no_cnt; |
@@ -206,32 +207,19 @@ static int tcm_loop_sam_attr(struct scsi_cmnd *sc) | |||
206 | return MSG_SIMPLE_TAG; | 207 | return MSG_SIMPLE_TAG; |
207 | } | 208 | } |
208 | 209 | ||
209 | /* | 210 | static void tcm_loop_submission_work(struct work_struct *work) |
210 | * Main entry point from struct scsi_host_template for incoming SCSI CDB+Data | ||
211 | * from Linux/SCSI subsystem for SCSI low level device drivers (LLDs) | ||
212 | */ | ||
213 | static int tcm_loop_queuecommand( | ||
214 | struct Scsi_Host *sh, | ||
215 | struct scsi_cmnd *sc) | ||
216 | { | 211 | { |
217 | struct se_cmd *se_cmd; | 212 | struct tcm_loop_cmd *tl_cmd = |
218 | struct se_portal_group *se_tpg; | 213 | container_of(work, struct tcm_loop_cmd, work); |
214 | struct se_cmd *se_cmd = &tl_cmd->tl_se_cmd; | ||
215 | struct scsi_cmnd *sc = tl_cmd->sc; | ||
216 | struct tcm_loop_nexus *tl_nexus; | ||
219 | struct tcm_loop_hba *tl_hba; | 217 | struct tcm_loop_hba *tl_hba; |
220 | struct tcm_loop_tpg *tl_tpg; | 218 | struct tcm_loop_tpg *tl_tpg; |
221 | struct se_session *se_sess; | ||
222 | struct tcm_loop_nexus *tl_nexus; | ||
223 | struct tcm_loop_cmd *tl_cmd; | ||
224 | |||
225 | 219 | ||
226 | pr_debug("tcm_loop_queuecommand() %d:%d:%d:%d got CDB: 0x%02x" | ||
227 | " scsi_buf_len: %u\n", sc->device->host->host_no, | ||
228 | sc->device->id, sc->device->channel, sc->device->lun, | ||
229 | sc->cmnd[0], scsi_bufflen(sc)); | ||
230 | /* | ||
231 | * Locate the tcm_loop_hba_t pointer | ||
232 | */ | ||
233 | tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); | 220 | tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); |
234 | tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; | 221 | tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; |
222 | |||
235 | /* | 223 | /* |
236 | * Ensure that this tl_tpg reference from the incoming sc->device->id | 224 | * Ensure that this tl_tpg reference from the incoming sc->device->id |
237 | * has already been configured via tcm_loop_make_naa_tpg(). | 225 | * has already been configured via tcm_loop_make_naa_tpg(). |
@@ -240,7 +228,6 @@ static int tcm_loop_queuecommand( | |||
240 | set_host_byte(sc, DID_NO_CONNECT); | 228 | set_host_byte(sc, DID_NO_CONNECT); |
241 | goto out_done; | 229 | goto out_done; |
242 | } | 230 | } |
243 | se_tpg = &tl_tpg->tl_se_tpg; | ||
244 | 231 | ||
245 | tl_nexus = tl_hba->tl_nexus; | 232 | tl_nexus = tl_hba->tl_nexus; |
246 | if (!tl_nexus) { | 233 | if (!tl_nexus) { |
@@ -249,18 +236,9 @@ static int tcm_loop_queuecommand( | |||
249 | set_host_byte(sc, DID_ERROR); | 236 | set_host_byte(sc, DID_ERROR); |
250 | goto out_done; | 237 | goto out_done; |
251 | } | 238 | } |
252 | se_sess = tl_nexus->se_sess; | ||
253 | |||
254 | tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC); | ||
255 | if (!tl_cmd) { | ||
256 | pr_err("Unable to allocate struct tcm_loop_cmd\n"); | ||
257 | set_host_byte(sc, DID_ERROR); | ||
258 | goto out_done; | ||
259 | } | ||
260 | se_cmd = &tl_cmd->tl_se_cmd; | ||
261 | tl_cmd->sc = sc; | ||
262 | 239 | ||
263 | transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, | 240 | transport_init_se_cmd(se_cmd, tl_tpg->tl_se_tpg.se_tpg_tfo, |
241 | tl_nexus->se_sess, | ||
264 | scsi_bufflen(sc), sc->sc_data_direction, | 242 | scsi_bufflen(sc), sc->sc_data_direction, |
265 | tcm_loop_sam_attr(sc), &tl_cmd->tl_sense_buf[0]); | 243 | tcm_loop_sam_attr(sc), &tl_cmd->tl_sense_buf[0]); |
266 | 244 | ||
@@ -274,10 +252,37 @@ static int tcm_loop_queuecommand( | |||
274 | } | 252 | } |
275 | 253 | ||
276 | transport_generic_handle_cdb_map(se_cmd); | 254 | transport_generic_handle_cdb_map(se_cmd); |
277 | return 0; | 255 | return; |
278 | 256 | ||
279 | out_done: | 257 | out_done: |
280 | sc->scsi_done(sc); | 258 | sc->scsi_done(sc); |
259 | return; | ||
260 | } | ||
261 | |||
262 | /* | ||
263 | * ->queuecommand can be and usually is called from interrupt context, so | ||
264 | * defer the actual submission to a workqueue. | ||
265 | */ | ||
266 | static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc) | ||
267 | { | ||
268 | struct tcm_loop_cmd *tl_cmd; | ||
269 | |||
270 | pr_debug("tcm_loop_queuecommand() %d:%d:%d:%d got CDB: 0x%02x" | ||
271 | " scsi_buf_len: %u\n", sc->device->host->host_no, | ||
272 | sc->device->id, sc->device->channel, sc->device->lun, | ||
273 | sc->cmnd[0], scsi_bufflen(sc)); | ||
274 | |||
275 | tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC); | ||
276 | if (!tl_cmd) { | ||
277 | pr_err("Unable to allocate struct tcm_loop_cmd\n"); | ||
278 | set_host_byte(sc, DID_ERROR); | ||
279 | sc->scsi_done(sc); | ||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | tl_cmd->sc = sc; | ||
284 | INIT_WORK(&tl_cmd->work, tcm_loop_submission_work); | ||
285 | queue_work(tcm_loop_workqueue, &tl_cmd->work); | ||
281 | return 0; | 286 | return 0; |
282 | } | 287 | } |
283 | 288 | ||
@@ -1458,7 +1463,11 @@ static void tcm_loop_deregister_configfs(void) | |||
1458 | 1463 | ||
1459 | static int __init tcm_loop_fabric_init(void) | 1464 | static int __init tcm_loop_fabric_init(void) |
1460 | { | 1465 | { |
1461 | int ret; | 1466 | int ret = -ENOMEM; |
1467 | |||
1468 | tcm_loop_workqueue = alloc_workqueue("tcm_loop", 0, 0); | ||
1469 | if (!tcm_loop_workqueue) | ||
1470 | goto out; | ||
1462 | 1471 | ||
1463 | tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache", | 1472 | tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache", |
1464 | sizeof(struct tcm_loop_cmd), | 1473 | sizeof(struct tcm_loop_cmd), |
@@ -1467,20 +1476,27 @@ static int __init tcm_loop_fabric_init(void) | |||
1467 | if (!tcm_loop_cmd_cache) { | 1476 | if (!tcm_loop_cmd_cache) { |
1468 | pr_debug("kmem_cache_create() for" | 1477 | pr_debug("kmem_cache_create() for" |
1469 | " tcm_loop_cmd_cache failed\n"); | 1478 | " tcm_loop_cmd_cache failed\n"); |
1470 | return -ENOMEM; | 1479 | goto out_destroy_workqueue; |
1471 | } | 1480 | } |
1472 | 1481 | ||
1473 | ret = tcm_loop_alloc_core_bus(); | 1482 | ret = tcm_loop_alloc_core_bus(); |
1474 | if (ret) | 1483 | if (ret) |
1475 | return ret; | 1484 | goto out_destroy_cache; |
1476 | 1485 | ||
1477 | ret = tcm_loop_register_configfs(); | 1486 | ret = tcm_loop_register_configfs(); |
1478 | if (ret) { | 1487 | if (ret) |
1479 | tcm_loop_release_core_bus(); | 1488 | goto out_release_core_bus; |
1480 | return ret; | ||
1481 | } | ||
1482 | 1489 | ||
1483 | return 0; | 1490 | return 0; |
1491 | |||
1492 | out_release_core_bus: | ||
1493 | tcm_loop_release_core_bus(); | ||
1494 | out_destroy_cache: | ||
1495 | kmem_cache_destroy(tcm_loop_cmd_cache); | ||
1496 | out_destroy_workqueue: | ||
1497 | destroy_workqueue(tcm_loop_workqueue); | ||
1498 | out: | ||
1499 | return ret; | ||
1484 | } | 1500 | } |
1485 | 1501 | ||
1486 | static void __exit tcm_loop_fabric_exit(void) | 1502 | static void __exit tcm_loop_fabric_exit(void) |
@@ -1488,6 +1504,7 @@ static void __exit tcm_loop_fabric_exit(void) | |||
1488 | tcm_loop_deregister_configfs(); | 1504 | tcm_loop_deregister_configfs(); |
1489 | tcm_loop_release_core_bus(); | 1505 | tcm_loop_release_core_bus(); |
1490 | kmem_cache_destroy(tcm_loop_cmd_cache); | 1506 | kmem_cache_destroy(tcm_loop_cmd_cache); |
1507 | destroy_workqueue(tcm_loop_workqueue); | ||
1491 | } | 1508 | } |
1492 | 1509 | ||
1493 | MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module"); | 1510 | MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module"); |
diff --git a/drivers/target/loopback/tcm_loop.h b/drivers/target/loopback/tcm_loop.h index 15a036441471..fc9bade9641b 100644 --- a/drivers/target/loopback/tcm_loop.h +++ b/drivers/target/loopback/tcm_loop.h | |||
@@ -12,9 +12,9 @@ struct tcm_loop_cmd { | |||
12 | u32 sc_cmd_state; | 12 | u32 sc_cmd_state; |
13 | /* Pointer to the CDB+Data descriptor from Linux/SCSI subsystem */ | 13 | /* Pointer to the CDB+Data descriptor from Linux/SCSI subsystem */ |
14 | struct scsi_cmnd *sc; | 14 | struct scsi_cmnd *sc; |
15 | struct list_head *tl_cmd_list; | ||
16 | /* The TCM I/O descriptor that is accessed via container_of() */ | 15 | /* The TCM I/O descriptor that is accessed via container_of() */ |
17 | struct se_cmd tl_se_cmd; | 16 | struct se_cmd tl_se_cmd; |
17 | struct work_struct work; | ||
18 | /* Sense buffer that will be mapped into outgoing status */ | 18 | /* Sense buffer that will be mapped into outgoing status */ |
19 | unsigned char tl_sense_buf[TRANSPORT_SENSE_BUFFER]; | 19 | unsigned char tl_sense_buf[TRANSPORT_SENSE_BUFFER]; |
20 | }; | 20 | }; |