aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoaz Harrosh <bharrosh@panasas.com>2007-12-13 19:14:27 -0500
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-01-30 14:03:40 -0500
commitbb52d82f45df3a2661d88befba7c79a7db8be496 (patch)
tree875af65ede88fe724fb350e43000fe99262fec9f
parent03e7925d0737d99086acee6263424dafa34e45ae (diff)
[SCSI] tgt: use scsi_init_io instead of scsi_alloc_sgtable
If we export scsi_init_io()/scsi_release_buffers() instead of scsi_{alloc,free}_sgtable() from scsi_lib than tgt code is much more insulated from scsi_lib changes. As a bonus it will also gain bidi capability when it comes. [jejb: rebase on to sg_table and fix up rejections] Signed-off-by: Boaz Harrosh <bharrosh@panasas.com> Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--drivers/scsi/scsi_lib.c20
-rw-r--r--drivers/scsi/scsi_tgt_lib.c28
-rw-r--r--include/scsi/scsi_cmnd.h4
3 files changed, 16 insertions, 36 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 7c4c889c5221..69fd62183bab 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -746,7 +746,7 @@ static struct scatterlist *scsi_sg_alloc(unsigned int nents, gfp_t gfp_mask)
746 return mempool_alloc(sgp->pool, gfp_mask); 746 return mempool_alloc(sgp->pool, gfp_mask);
747} 747}
748 748
749int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask) 749static int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
750{ 750{
751 int ret; 751 int ret;
752 752
@@ -762,15 +762,11 @@ int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
762 return ret; 762 return ret;
763} 763}
764 764
765EXPORT_SYMBOL(scsi_alloc_sgtable); 765static void scsi_free_sgtable(struct scsi_cmnd *cmd)
766
767void scsi_free_sgtable(struct scsi_cmnd *cmd)
768{ 766{
769 __sg_free_table(&cmd->sg_table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free); 767 __sg_free_table(&cmd->sg_table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
770} 768}
771 769
772EXPORT_SYMBOL(scsi_free_sgtable);
773
774/* 770/*
775 * Function: scsi_release_buffers() 771 * Function: scsi_release_buffers()
776 * 772 *
@@ -788,7 +784,7 @@ EXPORT_SYMBOL(scsi_free_sgtable);
788 * the scatter-gather table, and potentially any bounce 784 * the scatter-gather table, and potentially any bounce
789 * buffers. 785 * buffers.
790 */ 786 */
791static void scsi_release_buffers(struct scsi_cmnd *cmd) 787void scsi_release_buffers(struct scsi_cmnd *cmd)
792{ 788{
793 if (cmd->use_sg) 789 if (cmd->use_sg)
794 scsi_free_sgtable(cmd); 790 scsi_free_sgtable(cmd);
@@ -800,6 +796,7 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd)
800 cmd->request_buffer = NULL; 796 cmd->request_buffer = NULL;
801 cmd->request_bufflen = 0; 797 cmd->request_bufflen = 0;
802} 798}
799EXPORT_SYMBOL(scsi_release_buffers);
803 800
804/* 801/*
805 * Function: scsi_io_completion() 802 * Function: scsi_io_completion()
@@ -1001,7 +998,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1001 * Returns: 0 on success 998 * Returns: 0 on success
1002 * BLKPREP_DEFER if the failure is retryable 999 * BLKPREP_DEFER if the failure is retryable
1003 */ 1000 */
1004static int scsi_init_io(struct scsi_cmnd *cmd) 1001int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1005{ 1002{
1006 struct request *req = cmd->request; 1003 struct request *req = cmd->request;
1007 int count; 1004 int count;
@@ -1016,7 +1013,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
1016 /* 1013 /*
1017 * If sg table allocation fails, requeue request later. 1014 * If sg table allocation fails, requeue request later.
1018 */ 1015 */
1019 if (unlikely(scsi_alloc_sgtable(cmd, GFP_ATOMIC))) { 1016 if (unlikely(scsi_alloc_sgtable(cmd, gfp_mask))) {
1020 scsi_unprep_request(req); 1017 scsi_unprep_request(req);
1021 return BLKPREP_DEFER; 1018 return BLKPREP_DEFER;
1022 } 1019 }
@@ -1036,6 +1033,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
1036 cmd->use_sg = count; 1033 cmd->use_sg = count;
1037 return BLKPREP_OK; 1034 return BLKPREP_OK;
1038} 1035}
1036EXPORT_SYMBOL(scsi_init_io);
1039 1037
1040static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev, 1038static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
1041 struct request *req) 1039 struct request *req)
@@ -1081,7 +1079,7 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
1081 1079
1082 BUG_ON(!req->nr_phys_segments); 1080 BUG_ON(!req->nr_phys_segments);
1083 1081
1084 ret = scsi_init_io(cmd); 1082 ret = scsi_init_io(cmd, GFP_ATOMIC);
1085 if (unlikely(ret)) 1083 if (unlikely(ret))
1086 return ret; 1084 return ret;
1087 } else { 1085 } else {
@@ -1132,7 +1130,7 @@ int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
1132 if (unlikely(!cmd)) 1130 if (unlikely(!cmd))
1133 return BLKPREP_DEFER; 1131 return BLKPREP_DEFER;
1134 1132
1135 return scsi_init_io(cmd); 1133 return scsi_init_io(cmd, GFP_ATOMIC);
1136} 1134}
1137EXPORT_SYMBOL(scsi_setup_fs_cmnd); 1135EXPORT_SYMBOL(scsi_setup_fs_cmnd);
1138 1136
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
index 01e03f3f6ffa..91630baea532 100644
--- a/drivers/scsi/scsi_tgt_lib.c
+++ b/drivers/scsi/scsi_tgt_lib.c
@@ -331,8 +331,7 @@ static void scsi_tgt_cmd_done(struct scsi_cmnd *cmd)
331 331
332 scsi_tgt_uspace_send_status(cmd, tcmd->itn_id, tcmd->tag); 332 scsi_tgt_uspace_send_status(cmd, tcmd->itn_id, tcmd->tag);
333 333
334 if (scsi_sglist(cmd)) 334 scsi_release_buffers(cmd);
335 scsi_free_sgtable(cmd);
336 335
337 queue_work(scsi_tgtd, &tcmd->work); 336 queue_work(scsi_tgtd, &tcmd->work);
338} 337}
@@ -353,25 +352,6 @@ static int scsi_tgt_transfer_response(struct scsi_cmnd *cmd)
353 return 0; 352 return 0;
354} 353}
355 354
356static int scsi_tgt_init_cmd(struct scsi_cmnd *cmd, gfp_t gfp_mask)
357{
358 struct request *rq = cmd->request;
359 int count;
360
361 cmd->use_sg = rq->nr_phys_segments;
362 if (scsi_alloc_sgtable(cmd, gfp_mask))
363 return -ENOMEM;
364
365 cmd->request_bufflen = rq->data_len;
366
367 dprintk("cmd %p cnt %d %lu\n", cmd, scsi_sg_count(cmd),
368 rq_data_dir(rq));
369 count = blk_rq_map_sg(rq->q, rq, scsi_sglist(cmd));
370 BUG_ON(count > cmd->use_sg);
371 cmd->use_sg = count;
372 return 0;
373}
374
375/* TODO: test this crap and replace bio_map_user with new interface maybe */ 355/* TODO: test this crap and replace bio_map_user with new interface maybe */
376static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd, 356static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
377 unsigned long uaddr, unsigned int len, int rw) 357 unsigned long uaddr, unsigned int len, int rw)
@@ -397,9 +377,11 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
397 } 377 }
398 378
399 tcmd->bio = rq->bio; 379 tcmd->bio = rq->bio;
400 err = scsi_tgt_init_cmd(cmd, GFP_KERNEL); 380 err = scsi_init_io(cmd, GFP_KERNEL);
401 if (err) 381 if (err) {
382 scsi_release_buffers(cmd);
402 goto unmap_rq; 383 goto unmap_rq;
384 }
403 385
404 return 0; 386 return 0;
405 387
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index a457fca66f61..09d44f91dbdb 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -127,8 +127,8 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
127 size_t *offset, size_t *len); 127 size_t *offset, size_t *len);
128extern void scsi_kunmap_atomic_sg(void *virt); 128extern void scsi_kunmap_atomic_sg(void *virt);
129 129
130extern int scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t); 130extern int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask);
131extern void scsi_free_sgtable(struct scsi_cmnd *); 131extern void scsi_release_buffers(struct scsi_cmnd *cmd);
132 132
133extern int scsi_dma_map(struct scsi_cmnd *cmd); 133extern int scsi_dma_map(struct scsi_cmnd *cmd);
134extern void scsi_dma_unmap(struct scsi_cmnd *cmd); 134extern void scsi_dma_unmap(struct scsi_cmnd *cmd);