Commit 181011e0 authored by Mike Christie's avatar Mike Christie Committed by James Bottomley

[SCSI] tgt: rm bio hacks in scsi tgt

scsi tgt breaks up a command into multple scatterlists
if we cannot fit all the data in one. This was because
the block rq helpers did not support large requests and
because we can get a command of any old size so it is
hard to preallocate pages for scatterlist large enough
(we cannot really preallocate pages with the bio map
user path). In 2.6.20, we added large request support to
the block layer helper, blk_rq_map_user. And at LSF,
we talked about increasing SCSI_MAX_PHYS_SEGMENTS for
scsi tgt if we want to support really really :) large
(greater than 256 * PAGE_SIZE in the worst mapping case)
requests.

The only target currently implemented does not even support
the multiple scatterlists stuff and only supports smaller
requests, so this patch just coverts scsi tgt to use
blk_rq_map_user.
Signed-off-by: default avatarMike Christie <michaelc@cs.wisc.edu>
Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 0f238418
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <scsi/scsi_device.h> #include <scsi/scsi_device.h>
#include <scsi/scsi_host.h> #include <scsi/scsi_host.h>
#include <scsi/scsi_tgt.h> #include <scsi/scsi_tgt.h>
#include <../drivers/md/dm-bio-list.h>
#include "scsi_tgt_priv.h" #include "scsi_tgt_priv.h"
...@@ -42,9 +41,8 @@ static struct kmem_cache *scsi_tgt_cmd_cache; ...@@ -42,9 +41,8 @@ static struct kmem_cache *scsi_tgt_cmd_cache;
struct scsi_tgt_cmd { struct scsi_tgt_cmd {
/* TODO replace work with James b's code */ /* TODO replace work with James b's code */
struct work_struct work; struct work_struct work;
/* TODO replace the lists with a large bio */ /* TODO fix limits of some drivers */
struct bio_list xfer_done_list; struct bio *bio;
struct bio_list xfer_list;
struct list_head hash_list; struct list_head hash_list;
struct request *rq; struct request *rq;
...@@ -93,7 +91,12 @@ struct scsi_cmnd *scsi_host_get_command(struct Scsi_Host *shost, ...@@ -93,7 +91,12 @@ struct scsi_cmnd *scsi_host_get_command(struct Scsi_Host *shost,
if (!tcmd) if (!tcmd)
goto put_dev; goto put_dev;
rq = blk_get_request(shost->uspace_req_q, write, gfp_mask); /*
* The blk helpers are used to the READ/WRITE requests
* transfering data from a initiator point of view. Since
* we are in target mode we want the opposite.
*/
rq = blk_get_request(shost->uspace_req_q, !write, gfp_mask);
if (!rq) if (!rq)
goto free_tcmd; goto free_tcmd;
...@@ -111,8 +114,6 @@ struct scsi_cmnd *scsi_host_get_command(struct Scsi_Host *shost, ...@@ -111,8 +114,6 @@ struct scsi_cmnd *scsi_host_get_command(struct Scsi_Host *shost,
rq->cmd_flags |= REQ_TYPE_BLOCK_PC; rq->cmd_flags |= REQ_TYPE_BLOCK_PC;
rq->end_io_data = tcmd; rq->end_io_data = tcmd;
bio_list_init(&tcmd->xfer_list);
bio_list_init(&tcmd->xfer_done_list);
tcmd->rq = rq; tcmd->rq = rq;
return cmd; return cmd;
...@@ -157,22 +158,6 @@ void scsi_host_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd) ...@@ -157,22 +158,6 @@ void scsi_host_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
} }
EXPORT_SYMBOL_GPL(scsi_host_put_command); EXPORT_SYMBOL_GPL(scsi_host_put_command);
static void scsi_unmap_user_pages(struct scsi_tgt_cmd *tcmd)
{
struct bio *bio;
/* must call bio_endio in case bio was bounced */
while ((bio = bio_list_pop(&tcmd->xfer_done_list))) {
bio_endio(bio, bio->bi_size, 0);
bio_unmap_user(bio);
}
while ((bio = bio_list_pop(&tcmd->xfer_list))) {
bio_endio(bio, bio->bi_size, 0);
bio_unmap_user(bio);
}
}
static void cmd_hashlist_del(struct scsi_cmnd *cmd) static void cmd_hashlist_del(struct scsi_cmnd *cmd)
{ {
struct request_queue *q = cmd->request->q; struct request_queue *q = cmd->request->q;
...@@ -185,6 +170,11 @@ static void cmd_hashlist_del(struct scsi_cmnd *cmd) ...@@ -185,6 +170,11 @@ static void cmd_hashlist_del(struct scsi_cmnd *cmd)
spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags); spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
} }
static void scsi_unmap_user_pages(struct scsi_tgt_cmd *tcmd)
{
blk_rq_unmap_user(tcmd->bio);
}
static void scsi_tgt_cmd_destroy(struct work_struct *work) static void scsi_tgt_cmd_destroy(struct work_struct *work)
{ {
struct scsi_tgt_cmd *tcmd = struct scsi_tgt_cmd *tcmd =
...@@ -193,16 +183,6 @@ static void scsi_tgt_cmd_destroy(struct work_struct *work) ...@@ -193,16 +183,6 @@ static void scsi_tgt_cmd_destroy(struct work_struct *work)
dprintk("cmd %p %d %lu\n", cmd, cmd->sc_data_direction, dprintk("cmd %p %d %lu\n", cmd, cmd->sc_data_direction,
rq_data_dir(cmd->request)); rq_data_dir(cmd->request));
/*
* We fix rq->cmd_flags here since when we told bio_map_user
* to write vm for WRITE commands, blk_rq_bio_prep set
* rq_data_dir the flags to READ.
*/
if (cmd->sc_data_direction == DMA_TO_DEVICE)
cmd->request->cmd_flags |= REQ_RW;
else
cmd->request->cmd_flags &= ~REQ_RW;
scsi_unmap_user_pages(tcmd); scsi_unmap_user_pages(tcmd);
scsi_host_put_command(scsi_tgt_cmd_to_host(cmd), cmd); scsi_host_put_command(scsi_tgt_cmd_to_host(cmd), cmd);
} }
...@@ -215,6 +195,7 @@ static void init_scsi_tgt_cmd(struct request *rq, struct scsi_tgt_cmd *tcmd, ...@@ -215,6 +195,7 @@ static void init_scsi_tgt_cmd(struct request *rq, struct scsi_tgt_cmd *tcmd,
struct list_head *head; struct list_head *head;
tcmd->tag = tag; tcmd->tag = tag;
tcmd->bio = NULL;
INIT_WORK(&tcmd->work, scsi_tgt_cmd_destroy); INIT_WORK(&tcmd->work, scsi_tgt_cmd_destroy);
spin_lock_irqsave(&qdata->cmd_hash_lock, flags); spin_lock_irqsave(&qdata->cmd_hash_lock, flags);
head = &qdata->cmd_hash[cmd_hashfn(tag)]; head = &qdata->cmd_hash[cmd_hashfn(tag)];
...@@ -419,52 +400,33 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd, ...@@ -419,52 +400,33 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
struct request *rq = cmd->request; struct request *rq = cmd->request;
void *uaddr = tcmd->buffer; void *uaddr = tcmd->buffer;
unsigned int len = tcmd->bufflen; unsigned int len = tcmd->bufflen;
struct bio *bio;
int err; int err;
while (len > 0) {
dprintk("%lx %u\n", (unsigned long) uaddr, len); dprintk("%lx %u\n", (unsigned long) uaddr, len);
bio = bio_map_user(q, NULL, (unsigned long) uaddr, len, rw); err = blk_rq_map_user(q, rq, uaddr, len);
if (IS_ERR(bio)) { if (err) {
err = PTR_ERR(bio);
dprintk("fail to map %lx %u %d %x\n",
(unsigned long) uaddr, len, err, cmd->cmnd[0]);
goto unmap_bios;
}
uaddr += bio->bi_size;
len -= bio->bi_size;
/* /*
* The first bio is added and merged. We could probably * TODO: need to fixup sg_tablesize, max_segment_size,
* try to add others using scsi_merge_bio() but for now * max_sectors, etc for modern HW and software drivers
* we keep it simple. The first bio should be pretty large * where this value is bogus.
* (either hitting the 1 MB bio pages limit or a queue limit) *
* already but for really large IO we may want to try and * TODO2: we can alloc a reserve buffer of max size
* merge these. * we can handle and do the slow copy path for really large
* IO.
*/ */
if (!rq->bio) { eprintk("Could not handle request of size %u.\n", len);
blk_rq_bio_prep(q, rq, bio); return err;
rq->data_len = bio->bi_size;
} else
/* put list of bios to transfer in next go around */
bio_list_add(&tcmd->xfer_list, bio);
} }
cmd->offset = 0; tcmd->bio = rq->bio;
err = scsi_tgt_init_cmd(cmd, GFP_KERNEL); err = scsi_tgt_init_cmd(cmd, GFP_KERNEL);
if (err) if (err)
goto unmap_bios; goto unmap_rq;
return 0; return 0;
unmap_bios: unmap_rq:
if (rq->bio) { scsi_unmap_user_pages(tcmd);
bio_unmap_user(rq->bio);
while ((bio = bio_list_pop(&tcmd->xfer_list)))
bio_unmap_user(bio);
}
return err; return err;
} }
...@@ -473,12 +435,10 @@ static int scsi_tgt_transfer_data(struct scsi_cmnd *); ...@@ -473,12 +435,10 @@ static int scsi_tgt_transfer_data(struct scsi_cmnd *);
static void scsi_tgt_data_transfer_done(struct scsi_cmnd *cmd) static void scsi_tgt_data_transfer_done(struct scsi_cmnd *cmd)
{ {
struct scsi_tgt_cmd *tcmd = cmd->request->end_io_data; struct scsi_tgt_cmd *tcmd = cmd->request->end_io_data;
struct bio *bio;
int err; int err;
/* should we free resources here on error ? */ /* should we free resources here on error ? */
if (cmd->result) { if (cmd->result) {
send_uspace_err:
err = scsi_tgt_uspace_send_status(cmd, tcmd->tag); err = scsi_tgt_uspace_send_status(cmd, tcmd->tag);
if (err <= 0) if (err <= 0)
/* the tgt uspace eh will have to pick this up */ /* the tgt uspace eh will have to pick this up */
...@@ -490,34 +450,8 @@ static void scsi_tgt_data_transfer_done(struct scsi_cmnd *cmd) ...@@ -490,34 +450,8 @@ static void scsi_tgt_data_transfer_done(struct scsi_cmnd *cmd)
cmd, cmd->request_bufflen, tcmd->bufflen); cmd, cmd->request_bufflen, tcmd->bufflen);
scsi_free_sgtable(cmd->request_buffer, cmd->sglist_len); scsi_free_sgtable(cmd->request_buffer, cmd->sglist_len);
bio_list_add(&tcmd->xfer_done_list, cmd->request->bio);
tcmd->buffer += cmd->request_bufflen; tcmd->buffer += cmd->request_bufflen;
cmd->offset += cmd->request_bufflen;
if (!tcmd->xfer_list.head) {
scsi_tgt_transfer_response(cmd); scsi_tgt_transfer_response(cmd);
return;
}
dprintk("cmd2 %p request_bufflen %u bufflen %u\n",
cmd, cmd->request_bufflen, tcmd->bufflen);
bio = bio_list_pop(&tcmd->xfer_list);
BUG_ON(!bio);
blk_rq_bio_prep(cmd->request->q, cmd->request, bio);
cmd->request->data_len = bio->bi_size;
err = scsi_tgt_init_cmd(cmd, GFP_ATOMIC);
if (err) {
cmd->result = DID_ERROR << 16;
goto send_uspace_err;
}
if (scsi_tgt_transfer_data(cmd)) {
cmd->result = DID_NO_CONNECT << 16;
goto send_uspace_err;
}
} }
static int scsi_tgt_transfer_data(struct scsi_cmnd *cmd) static int scsi_tgt_transfer_data(struct scsi_cmnd *cmd)
...@@ -617,8 +551,9 @@ int scsi_tgt_kspace_exec(int host_no, u64 tag, int result, u32 len, ...@@ -617,8 +551,9 @@ int scsi_tgt_kspace_exec(int host_no, u64 tag, int result, u32 len,
} }
cmd = rq->special; cmd = rq->special;
dprintk("cmd %p result %d len %d bufflen %u %lu %x\n", cmd, dprintk("cmd %p scb %x result %d len %d bufflen %u %lu %x\n",
result, len, cmd->request_bufflen, rq_data_dir(rq), cmd->cmnd[0]); cmd, cmd->cmnd[0], result, len, cmd->request_bufflen,
rq_data_dir(rq), cmd->cmnd[0]);
if (result == TASK_ABORTED) { if (result == TASK_ABORTED) {
scsi_tgt_abort_cmd(shost, cmd); scsi_tgt_abort_cmd(shost, cmd);
......
...@@ -73,9 +73,6 @@ struct scsi_cmnd { ...@@ -73,9 +73,6 @@ struct scsi_cmnd {
unsigned short use_sg; /* Number of pieces of scatter-gather */ unsigned short use_sg; /* Number of pieces of scatter-gather */
unsigned short sglist_len; /* size of malloc'd scatter-gather list */ unsigned short sglist_len; /* size of malloc'd scatter-gather list */
/* offset in cmd we are at (for multi-transfer tgt cmds) */
unsigned offset;
unsigned underflow; /* Return error if less than unsigned underflow; /* Return error if less than
this amount is transferred */ this amount is transferred */
......
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