scsi: convert discard to REQ_TYPE_FS from REQ_TYPE_BLOCK_PC
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Wed, 21 Jul 2010 01:29:37 +0000 (10:29 +0900)
committerJens Axboe <jaxboe@fusionio.com>
Sat, 7 Aug 2010 16:52:31 +0000 (18:52 +0200)
Jens, any reason why this isn't included in your for-2.6.36 yet?

=
From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Subject: [PATCH resend] scsi: convert discard to REQ_TYPE_FS from REQ_TYPE_BLOCK_PC

The block layer (file systems) sends discard requests as REQ_TYPE_FS
(the role of REQ_TYPE_FS is that setting up commands and interpreting
the results). But SCSI-ml treats discard requests as
REQ_TYPE_BLOCK_PC.

scsi-ml can handle discard requests as REQ_TYPE_FS
easily. scsi_setup_discard_cmnd() sets up struct request and the bio
nicely. Only remaining issue is that discard requests can't be
completed partially so we need to modify sd_done.

This conversion also fixes the problem that discard requests aren't
retried when possible (e.g. UNIT ATTENTION).

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
drivers/scsi/sd.c

index fc5d69a84af5ff66ca39fbed2e1496b3b6453f28..e63b85ac8cd12453c8deeb22081807571999f831 100644 (file)
@@ -434,7 +434,6 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
                nr_sectors >>= 3;
        }
 
-       rq->cmd_type = REQ_TYPE_BLOCK_PC;
        rq->timeout = SD_TIMEOUT;
 
        memset(rq->cmd, 0, rq->cmd_len);
@@ -1200,6 +1199,12 @@ static int sd_done(struct scsi_cmnd *SCpnt)
        int sense_valid = 0;
        int sense_deferred = 0;
 
+       if (SCpnt->request->cmd_flags & REQ_DISCARD) {
+               if (!result)
+                       scsi_set_resid(SCpnt, 0);
+               return good_bytes;
+       }
+
        if (result) {
                sense_valid = scsi_command_normalize_sense(SCpnt, &sshdr);
                if (sense_valid)