Commit 87949eee7e15471a42f06ae534847264a41be647
1 parent
e4200f8ee3
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
sd: split sd_init_command
Factor out a function to initialize regular read/write commands and leave sd_init_command as a simple dispatcher to the different prepare routines. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Hannes Reinecke <hare@suse.de>
Showing 1 changed file with 29 additions and 29 deletions Side-by-side Diff
drivers/scsi/sd.c
... | ... | @@ -884,23 +884,9 @@ |
884 | 884 | return BLKPREP_OK; |
885 | 885 | } |
886 | 886 | |
887 | -static void sd_uninit_command(struct scsi_cmnd *SCpnt) | |
887 | +static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) | |
888 | 888 | { |
889 | 889 | struct request *rq = SCpnt->request; |
890 | - | |
891 | - if (rq->cmd_flags & REQ_DISCARD) | |
892 | - __free_page(rq->completion_data); | |
893 | - | |
894 | - if (SCpnt->cmnd != rq->cmd) { | |
895 | - mempool_free(SCpnt->cmnd, sd_cdb_pool); | |
896 | - SCpnt->cmnd = NULL; | |
897 | - SCpnt->cmd_len = 0; | |
898 | - } | |
899 | -} | |
900 | - | |
901 | -static int sd_init_command(struct scsi_cmnd *SCpnt) | |
902 | -{ | |
903 | - struct request *rq = SCpnt->request; | |
904 | 890 | struct scsi_device *sdp = SCpnt->device; |
905 | 891 | struct gendisk *disk = rq->rq_disk; |
906 | 892 | struct scsi_disk *sdkp; |
... | ... | @@ -910,20 +896,6 @@ |
910 | 896 | int ret, host_dif; |
911 | 897 | unsigned char protect; |
912 | 898 | |
913 | - /* | |
914 | - * Discard request come in as REQ_TYPE_FS but we turn them into | |
915 | - * block PC requests to make life easier. | |
916 | - */ | |
917 | - if (rq->cmd_flags & REQ_DISCARD) { | |
918 | - ret = sd_setup_discard_cmnd(SCpnt); | |
919 | - goto out; | |
920 | - } else if (rq->cmd_flags & REQ_WRITE_SAME) { | |
921 | - ret = sd_setup_write_same_cmnd(SCpnt); | |
922 | - goto out; | |
923 | - } else if (rq->cmd_flags & REQ_FLUSH) { | |
924 | - ret = sd_setup_flush_cmnd(SCpnt); | |
925 | - goto out; | |
926 | - } | |
927 | 899 | ret = scsi_init_io(SCpnt, GFP_ATOMIC); |
928 | 900 | if (ret != BLKPREP_OK) |
929 | 901 | goto out; |
... | ... | @@ -1153,6 +1125,34 @@ |
1153 | 1125 | ret = BLKPREP_OK; |
1154 | 1126 | out: |
1155 | 1127 | return ret; |
1128 | +} | |
1129 | + | |
1130 | +static int sd_init_command(struct scsi_cmnd *cmd) | |
1131 | +{ | |
1132 | + struct request *rq = cmd->request; | |
1133 | + | |
1134 | + if (rq->cmd_flags & REQ_DISCARD) | |
1135 | + return sd_setup_discard_cmnd(cmd); | |
1136 | + else if (rq->cmd_flags & REQ_WRITE_SAME) | |
1137 | + return sd_setup_write_same_cmnd(cmd); | |
1138 | + else if (rq->cmd_flags & REQ_FLUSH) | |
1139 | + return sd_setup_flush_cmnd(cmd); | |
1140 | + else | |
1141 | + return sd_setup_read_write_cmnd(cmd); | |
1142 | +} | |
1143 | + | |
1144 | +static void sd_uninit_command(struct scsi_cmnd *SCpnt) | |
1145 | +{ | |
1146 | + struct request *rq = SCpnt->request; | |
1147 | + | |
1148 | + if (rq->cmd_flags & REQ_DISCARD) | |
1149 | + __free_page(rq->completion_data); | |
1150 | + | |
1151 | + if (SCpnt->cmnd != rq->cmd) { | |
1152 | + mempool_free(SCpnt->cmnd, sd_cdb_pool); | |
1153 | + SCpnt->cmnd = NULL; | |
1154 | + SCpnt->cmd_len = 0; | |
1155 | + } | |
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |