Commit bb52d82f authored by Boaz Harrosh's avatar Boaz Harrosh Committed by James Bottomley

[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: default avatarBoaz Harrosh <bharrosh@panasas.com>
Acked-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent 03e7925d
...@@ -746,7 +746,7 @@ static struct scatterlist *scsi_sg_alloc(unsigned int nents, gfp_t gfp_mask) ...@@ -746,7 +746,7 @@ static struct scatterlist *scsi_sg_alloc(unsigned int nents, gfp_t gfp_mask)
return mempool_alloc(sgp->pool, gfp_mask); return mempool_alloc(sgp->pool, gfp_mask);
} }
int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask) static int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
{ {
int ret; int ret;
...@@ -762,15 +762,11 @@ int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask) ...@@ -762,15 +762,11 @@ int scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
return ret; return ret;
} }
EXPORT_SYMBOL(scsi_alloc_sgtable); static void scsi_free_sgtable(struct scsi_cmnd *cmd)
void scsi_free_sgtable(struct scsi_cmnd *cmd)
{ {
__sg_free_table(&cmd->sg_table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free); __sg_free_table(&cmd->sg_table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
} }
EXPORT_SYMBOL(scsi_free_sgtable);
/* /*
* Function: scsi_release_buffers() * Function: scsi_release_buffers()
* *
...@@ -788,7 +784,7 @@ EXPORT_SYMBOL(scsi_free_sgtable); ...@@ -788,7 +784,7 @@ EXPORT_SYMBOL(scsi_free_sgtable);
* the scatter-gather table, and potentially any bounce * the scatter-gather table, and potentially any bounce
* buffers. * buffers.
*/ */
static void scsi_release_buffers(struct scsi_cmnd *cmd) void scsi_release_buffers(struct scsi_cmnd *cmd)
{ {
if (cmd->use_sg) if (cmd->use_sg)
scsi_free_sgtable(cmd); scsi_free_sgtable(cmd);
...@@ -800,6 +796,7 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd) ...@@ -800,6 +796,7 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd)
cmd->request_buffer = NULL; cmd->request_buffer = NULL;
cmd->request_bufflen = 0; cmd->request_bufflen = 0;
} }
EXPORT_SYMBOL(scsi_release_buffers);
/* /*
* Function: scsi_io_completion() * Function: scsi_io_completion()
...@@ -1001,7 +998,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) ...@@ -1001,7 +998,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
* Returns: 0 on success * Returns: 0 on success
* BLKPREP_DEFER if the failure is retryable * BLKPREP_DEFER if the failure is retryable
*/ */
static int scsi_init_io(struct scsi_cmnd *cmd) int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
{ {
struct request *req = cmd->request; struct request *req = cmd->request;
int count; int count;
...@@ -1016,7 +1013,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd) ...@@ -1016,7 +1013,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
/* /*
* If sg table allocation fails, requeue request later. * If sg table allocation fails, requeue request later.
*/ */
if (unlikely(scsi_alloc_sgtable(cmd, GFP_ATOMIC))) { if (unlikely(scsi_alloc_sgtable(cmd, gfp_mask))) {
scsi_unprep_request(req); scsi_unprep_request(req);
return BLKPREP_DEFER; return BLKPREP_DEFER;
} }
...@@ -1036,6 +1033,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd) ...@@ -1036,6 +1033,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
cmd->use_sg = count; cmd->use_sg = count;
return BLKPREP_OK; return BLKPREP_OK;
} }
EXPORT_SYMBOL(scsi_init_io);
static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev, static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
struct request *req) struct request *req)
...@@ -1081,7 +1079,7 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) ...@@ -1081,7 +1079,7 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
BUG_ON(!req->nr_phys_segments); BUG_ON(!req->nr_phys_segments);
ret = scsi_init_io(cmd); ret = scsi_init_io(cmd, GFP_ATOMIC);
if (unlikely(ret)) if (unlikely(ret))
return ret; return ret;
} else { } else {
...@@ -1132,7 +1130,7 @@ int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req) ...@@ -1132,7 +1130,7 @@ int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
if (unlikely(!cmd)) if (unlikely(!cmd))
return BLKPREP_DEFER; return BLKPREP_DEFER;
return scsi_init_io(cmd); return scsi_init_io(cmd, GFP_ATOMIC);
} }
EXPORT_SYMBOL(scsi_setup_fs_cmnd); EXPORT_SYMBOL(scsi_setup_fs_cmnd);
......
...@@ -331,8 +331,7 @@ static void scsi_tgt_cmd_done(struct scsi_cmnd *cmd) ...@@ -331,8 +331,7 @@ static void scsi_tgt_cmd_done(struct scsi_cmnd *cmd)
scsi_tgt_uspace_send_status(cmd, tcmd->itn_id, tcmd->tag); scsi_tgt_uspace_send_status(cmd, tcmd->itn_id, tcmd->tag);
if (scsi_sglist(cmd)) scsi_release_buffers(cmd);
scsi_free_sgtable(cmd);
queue_work(scsi_tgtd, &tcmd->work); queue_work(scsi_tgtd, &tcmd->work);
} }
...@@ -353,25 +352,6 @@ static int scsi_tgt_transfer_response(struct scsi_cmnd *cmd) ...@@ -353,25 +352,6 @@ static int scsi_tgt_transfer_response(struct scsi_cmnd *cmd)
return 0; return 0;
} }
static int scsi_tgt_init_cmd(struct scsi_cmnd *cmd, gfp_t gfp_mask)
{
struct request *rq = cmd->request;
int count;
cmd->use_sg = rq->nr_phys_segments;
if (scsi_alloc_sgtable(cmd, gfp_mask))
return -ENOMEM;
cmd->request_bufflen = rq->data_len;
dprintk("cmd %p cnt %d %lu\n", cmd, scsi_sg_count(cmd),
rq_data_dir(rq));
count = blk_rq_map_sg(rq->q, rq, scsi_sglist(cmd));
BUG_ON(count > cmd->use_sg);
cmd->use_sg = count;
return 0;
}
/* TODO: test this crap and replace bio_map_user with new interface maybe */ /* TODO: test this crap and replace bio_map_user with new interface maybe */
static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd, static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
unsigned long uaddr, unsigned int len, int rw) 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,9 +377,11 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
} }
tcmd->bio = rq->bio; tcmd->bio = rq->bio;
err = scsi_tgt_init_cmd(cmd, GFP_KERNEL); err = scsi_init_io(cmd, GFP_KERNEL);
if (err) if (err) {
scsi_release_buffers(cmd);
goto unmap_rq; goto unmap_rq;
}
return 0; return 0;
......
...@@ -127,8 +127,8 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, ...@@ -127,8 +127,8 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
size_t *offset, size_t *len); size_t *offset, size_t *len);
extern void scsi_kunmap_atomic_sg(void *virt); extern void scsi_kunmap_atomic_sg(void *virt);
extern int scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t); extern int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask);
extern void scsi_free_sgtable(struct scsi_cmnd *); extern void scsi_release_buffers(struct scsi_cmnd *cmd);
extern int scsi_dma_map(struct scsi_cmnd *cmd); extern int scsi_dma_map(struct scsi_cmnd *cmd);
extern void scsi_dma_unmap(struct scsi_cmnd *cmd); extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment