scsi: bidi support
PATCH 29/30 scsi: bidi support
From: Boaz Harrosh <[email protected]>
At the block level bidi request uses req->next_rq pointer for a second bidi_read request.
At Scsi-midlayer a second scsi_data_buffer structure is used for the bidi_read part. This bidi scsi_data_buffer is put on request->next_rq->special. Struct scsi_cmnd is not changed.
- Define scsi_bidi_cmnd() to return true if it is a bidi request and a second sgtable was allocated.
- Define scsi_in()/scsi_out() to return the in or out scsi_data_buffer from this command This API is to isolate users from the mechanics of bidi.
- Define scsi_end_bidi_request() to do what scsi_end_request() does but for a bidi request. This is necessary because bidi commands are a bit tricky here. (See comments in body)
- scsi_release_buffers() will also release the bidi_read scsi_data_buffer
- scsi_io_completion() on bidi commands will now call scsi_end_bidi_request() and return.
- The previous work done in scsi_init_io() is now done in a new scsi_init_sgtable() (which is 99% identical to old scsi_init_io()) The new scsi_init_io() will call the above twice if needed also for the bidi_read command. Only at this point is a command bidi.
- In scsi_error.c at scsi_eh_prep/restore_cmnd() make sure bidi-lld is not confused by a get-sense command that looks like bidi. This is done by puting NULL at request->next_rq, and restoring.
---
drivers/scsi/scsi_error.c | 3 drivers/scsi/scsi_lib.c | 144 ++++++++++++++++++++++++++++-------- include/scsi/scsi_cmnd.h | 23 +++++ include/scsi/scsi_eh.h | 1 4 files changed, 141 insertions(+), 30 deletions(-)
drivers/scsi/scsi_error.c renamed from drivers/scsi/scsi_error.c~scsi-bidi-support +3 -0
@@ -618,9 +618,11 @@ void scsi_eh_prep_cmnd(struct scsi_cmndmemcpy (ses->cmnd, scmd->cmnd,sizeof (scmd->cmnd)); ses->data_direction = scmd->sc_data_direction; ses->sdb = scmd->sdb; + ses->next_rq = scmd->request->next_rq; ses->result = scmd->result;memset (&scmd->sdb,0 ,sizeof (scmd->sdb)); + scmd->request->next_rq =NULL ;if (sense_bytes) { scmd->sdb.length = min_t(unsigned,
@@ -673,6 +675,7 @@ void scsi_eh_restore_cmnd(struct scsi_cmmemcpy (scmd->cmnd, ses->cmnd,sizeof (scmd->cmnd)); scmd->sc_data_direction = ses->data_direction; scmd->sdb = ses->sdb; + scmd->request->next_rq = ses->next_rq; scmd->result = ses->result; }EXPORT_SYMBOL (scsi_eh_restore_cmnd);
drivers/scsi/scsi_lib.c renamed from drivers/scsi/scsi_lib.c~scsi-bidi-support +115 -29
208 lines not on this page · raw message
include/scsi/scsi_cmnd.h renamed from include/scsi/scsi_cmnd.h~scsi-bidi-support +22 -1
@@ -2,12 +2,12 @@#define _SCSI_SCSI_CMND_H#include <linux/dma-mapping.h> +#include <linux/blkdev.h> #include <linux/list.h> #include <linux/types.h> #include <linux/timer.h> #include <linux/scatterlist.h> -struct request ;struct scatterlist ;struct Scsi_Host ;struct scsi_device ;
@@ -162,4 +162,25 @@ static inline int scsi_get_resid(struct#define scsi_for_each_sg (cmd, sg, nseg, __i) \ for_each_sg(scsi_sglist(cmd), sg, nseg, __i) +static inline int scsi_bidi_cmnd (struct scsi_cmnd *cmd) +{ +return blk_bidi_rq (cmd->request) && + (cmd->request->next_rq->special !=NULL ); +} + +static inline struct scsi_data_buffer *scsi_in (struct scsi_cmnd *cmd) +{ +WARN_ON ((cmd->sc_data_direction !=DMA_FROM_DEVICE ) && + !scsi_bidi_cmnd (cmd)); +return scsi_bidi_cmnd (cmd) ? + cmd->request->next_rq->special : &cmd->sdb; +} + +static inline struct scsi_data_buffer *scsi_out (struct scsi_cmnd *cmd) +{ +WARN_ON ((cmd->sc_data_direction !=DMA_TO_DEVICE ) && + !scsi_bidi_cmnd (cmd)); +return &cmd->sdb; +} +#endif /* _SCSI_SCSI_CMND_H */
include/scsi/scsi_eh.h renamed from include/scsi/scsi_eh.h~scsi-bidi-support +1 -0
@@ -74,6 +74,7 @@ struct scsi_eh_save {unsigned char cmd_len;unsigned char cmnd[MAX_COMMAND_SIZE ];struct scsi_data_buffer sdb; +struct request *next_rq;/* new command support */ struct scatterlist sense_sgl;
_