[SCSI] Consolidate REQ_BLOCK_PC handling path (fix ipod panic)
authorJames Bottomley <James.Bottomley@steeleye.com>
Fri, 9 Dec 2005 22:45:22 +0000 (17:45 -0500)
committerJames Bottomley <jejb@mulgrave.(none)>
Wed, 14 Dec 2005 05:29:27 +0000 (21:29 -0800)
This follows on from Jens' patch and consolidates all of the ULD
separate handlers for REQ_BLOCK_PC into a single call which has his
fix for our direction bug.

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
drivers/scsi/scsi_lib.c
drivers/scsi/sd.c
drivers/scsi/sr.c
drivers/scsi/st.c
include/scsi/scsi_cmnd.h

index 097888721ec43af6a80a9cf71e860ed86ac86d89..9be5769d44aa48db105a21de6f85ae135d58f8ea 100644 (file)
@@ -1078,6 +1078,26 @@ static void scsi_generic_done(struct scsi_cmnd *cmd)
        scsi_io_completion(cmd, cmd->result == 0 ? cmd->bufflen : 0, 0);
 }
 
+void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd, int retries)
+{
+       struct request *req = cmd->request;
+
+       BUG_ON(sizeof(req->cmd) > sizeof(cmd->cmnd));
+       memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
+       cmd->cmd_len = req->cmd_len;
+       if (!req->data_len)
+               cmd->sc_data_direction = DMA_NONE;
+       else if (rq_data_dir(req) == WRITE)
+               cmd->sc_data_direction = DMA_TO_DEVICE;
+       else
+               cmd->sc_data_direction = DMA_FROM_DEVICE;
+       
+       cmd->transfersize = req->data_len;
+       cmd->allowed = retries;
+       cmd->timeout_per_command = req->timeout;
+}
+EXPORT_SYMBOL_GPL(scsi_setup_blk_pc_cmnd);
+
 static int scsi_prep_fn(struct request_queue *q, struct request *req)
 {
        struct scsi_device *sdev = q->queuedata;
@@ -1213,18 +1233,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
                                goto kill;
                        }
                } else {
-                       memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
-                       cmd->cmd_len = req->cmd_len;
-                       if (!req->data_len)
-                               cmd->sc_data_direction = DMA_NONE;
-                       else if (rq_data_dir(req) == WRITE)
-                               cmd->sc_data_direction = DMA_TO_DEVICE;
-                       else
-                               cmd->sc_data_direction = DMA_FROM_DEVICE;
-                       
-                       cmd->transfersize = req->data_len;
-                       cmd->allowed = 3;
-                       cmd->timeout_per_command = req->timeout;
+                       scsi_setup_blk_pc_cmnd(cmd, 3);
                        cmd->done = scsi_generic_done;
                }
        }
index 8613a1317712c9d40df22c26dc546d1c8b6aea28..03fcbab30033976abcd4d21f5a2bde5016510ecd 100644 (file)
@@ -245,24 +245,10 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
         * SG_IO from block layer already setup, just copy cdb basically
         */
        if (blk_pc_request(rq)) {
-               if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
-                       return 0;
-
-               memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
-               SCpnt->cmd_len = rq->cmd_len;
-               if (rq_data_dir(rq) == WRITE)
-                       SCpnt->sc_data_direction = DMA_TO_DEVICE;
-               else if (rq->data_len)
-                       SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-               else
-                       SCpnt->sc_data_direction = DMA_NONE;
-
-               this_count = rq->data_len;
+               scsi_setup_blk_pc_cmnd(SCpnt, SD_PASSTHROUGH_RETRIES);
                if (rq->timeout)
                        timeout = rq->timeout;
 
-               SCpnt->transfersize = rq->data_len;
-               SCpnt->allowed = SD_PASSTHROUGH_RETRIES;
                goto queue;
        }
 
index d68cea753bb2222629db977d5ebf37614dc9c093..fb4012b5c1884b8117a0b2155dd634879352acd7 100644 (file)
@@ -320,25 +320,11 @@ static int sr_init_command(struct scsi_cmnd * SCpnt)
         * these are already setup, just copy cdb basically
         */
        if (SCpnt->request->flags & REQ_BLOCK_PC) {
-               struct request *rq = SCpnt->request;
+               scsi_setup_blk_pc_cmnd(SCpnt, MAX_RETRIES);
 
-               if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
-                       return 0;
-
-               memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
-               SCpnt->cmd_len = rq->cmd_len;
-               if (!rq->data_len)
-                       SCpnt->sc_data_direction = DMA_NONE;
-               else if (rq_data_dir(rq) == WRITE)
-                       SCpnt->sc_data_direction = DMA_TO_DEVICE;
-               else
-                       SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-
-               this_count = rq->data_len;
-               if (rq->timeout)
-                       timeout = rq->timeout;
+               if (SCpnt->timeout_per_command)
+                       timeout = SCpnt->timeout_per_command;
 
-               SCpnt->transfersize = rq->data_len;
                goto queue;
        }
 
index 7ac6ea141fffafcfc56c0b26b4b269e7aab61ac4..dd592f6a252962cb42f00f09ef5342651985f294 100644 (file)
@@ -4194,27 +4194,10 @@ static void st_intr(struct scsi_cmnd *SCpnt)
  */
 static int st_init_command(struct scsi_cmnd *SCpnt)
 {
-       struct request *rq;
-
        if (!(SCpnt->request->flags & REQ_BLOCK_PC))
                return 0;
 
-       rq = SCpnt->request;
-       if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
-               return 0;
-
-       memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
-       SCpnt->cmd_len = rq->cmd_len;
-
-       if (rq_data_dir(rq) == WRITE)
-               SCpnt->sc_data_direction = DMA_TO_DEVICE;
-       else if (rq->data_len)
-               SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-       else
-               SCpnt->sc_data_direction = DMA_NONE;
-
-       SCpnt->timeout_per_command = rq->timeout;
-       SCpnt->transfersize = rq->data_len;
+       scsi_setup_blk_pc_cmnd(SCpnt, 0);
        SCpnt->done = st_intr;
        return 1;
 }
index 7529f4388bb46df6655e61364217c78e2199ea18..20da282d4abbb78041fd5f1bacc868dcc1a021a2 100644 (file)
@@ -151,5 +151,6 @@ extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
 extern void scsi_put_command(struct scsi_cmnd *);
 extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int);
 extern void scsi_finish_command(struct scsi_cmnd *cmd);
+extern void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd, int retries);
 
 #endif /* _SCSI_SCSI_CMND_H */