File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -836,6 +836,7 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
836
836
struct bio * bio = rq -> bio ;
837
837
sector_t sector = blk_rq_pos (rq );
838
838
unsigned int nr_sectors = blk_rq_sectors (rq );
839
+ unsigned int nr_bytes = blk_rq_bytes (rq );
839
840
int ret ;
840
841
841
842
if (sdkp -> device -> no_write_same )
@@ -868,7 +869,21 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
868
869
869
870
cmd -> transfersize = sdp -> sector_size ;
870
871
cmd -> allowed = SD_MAX_RETRIES ;
871
- return scsi_init_io (cmd );
872
+
873
+ /*
874
+ * For WRITE SAME the data transferred via the DATA OUT buffer is
875
+ * different from the amount of data actually written to the target.
876
+ *
877
+ * We set up __data_len to the amount of data transferred via the
878
+ * DATA OUT buffer so that blk_rq_map_sg sets up the proper S/G list
879
+ * to transfer a single sector of data first, but then reset it to
880
+ * the amount of data to be written right after so that the I/O path
881
+ * knows how much to actually write.
882
+ */
883
+ rq -> __data_len = sdp -> sector_size ;
884
+ ret = scsi_init_io (cmd );
885
+ rq -> __data_len = nr_bytes ;
886
+ return ret ;
872
887
}
873
888
874
889
static int sd_setup_flush_cmnd (struct scsi_cmnd * cmd )
You can’t perform that action at this time.
0 commit comments