Commit 0fb5b1fb authored by Martin K. Petersen's avatar Martin K. Petersen

block/sd: Return -EREMOTEIO when WRITE SAME and DISCARD are disabled

When a storage device rejects a WRITE SAME command we will disable write
same functionality for the device and return -EREMOTEIO to the block
layer. -EREMOTEIO will in turn prevent DM from retrying the I/O and/or
failing the path.

Yiwen Jiang discovered a small race where WRITE SAME requests issued
simultaneously would cause -EIO to be returned. This happened because
any requests being prepared after WRITE SAME had been disabled for the
device caused us to return BLKPREP_KILL. The latter caused the block
layer to return -EIO upon completion.

To overcome this we introduce BLKPREP_INVALID which indicates that this
is an invalid request for the device. blk_peek_request() is modified to
return -EREMOTEIO in that case.
Reported-by: default avatarYiwen Jiang <jiangyiwen@huawei.com>
Suggested-by: default avatarMike Snitzer <snitzer@redhat.com>
Reviewed-by: default avatarHannes Reinicke <hare@suse.de>
Reviewed-by: default avatarEwan Milne <emilne@redhat.com>
Reviewed-by: default avatarYiwen Jiang <jiangyiwen@huawei.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 82c43310
...@@ -2447,14 +2447,16 @@ struct request *blk_peek_request(struct request_queue *q) ...@@ -2447,14 +2447,16 @@ struct request *blk_peek_request(struct request_queue *q)
rq = NULL; rq = NULL;
break; break;
} else if (ret == BLKPREP_KILL) { } else if (ret == BLKPREP_KILL || ret == BLKPREP_INVALID) {
int err = (ret == BLKPREP_INVALID) ? -EREMOTEIO : -EIO;
rq->cmd_flags |= REQ_QUIET; rq->cmd_flags |= REQ_QUIET;
/* /*
* Mark this request as started so we don't trigger * Mark this request as started so we don't trigger
* any debug logic in the end I/O path. * any debug logic in the end I/O path.
*/ */
blk_start_request(rq); blk_start_request(rq);
__blk_end_request_all(rq, -EIO); __blk_end_request_all(rq, err);
} else { } else {
printk(KERN_ERR "%s: bad return=%d\n", __func__, ret); printk(KERN_ERR "%s: bad return=%d\n", __func__, ret);
break; break;
......
...@@ -761,7 +761,7 @@ static int sd_setup_discard_cmnd(struct scsi_cmnd *cmd) ...@@ -761,7 +761,7 @@ static int sd_setup_discard_cmnd(struct scsi_cmnd *cmd)
break; break;
default: default:
ret = BLKPREP_KILL; ret = BLKPREP_INVALID;
goto out; goto out;
} }
...@@ -839,7 +839,7 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) ...@@ -839,7 +839,7 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
int ret; int ret;
if (sdkp->device->no_write_same) if (sdkp->device->no_write_same)
return BLKPREP_KILL; return BLKPREP_INVALID;
BUG_ON(bio_offset(bio) || bio_iovec(bio).bv_len != sdp->sector_size); BUG_ON(bio_offset(bio) || bio_iovec(bio).bv_len != sdp->sector_size);
......
...@@ -681,9 +681,12 @@ static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b) ...@@ -681,9 +681,12 @@ static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
/* /*
* q->prep_rq_fn return values * q->prep_rq_fn return values
*/ */
#define BLKPREP_OK 0 /* serve it */ enum {
#define BLKPREP_KILL 1 /* fatal error, kill */ BLKPREP_OK, /* serve it */
#define BLKPREP_DEFER 2 /* leave on queue */ BLKPREP_KILL, /* fatal error, kill, return -EIO */
BLKPREP_DEFER, /* leave on queue */
BLKPREP_INVALID, /* invalid command, kill, return -EREMOTEIO */
};
extern unsigned long blk_max_low_pfn, blk_max_pfn; extern unsigned long blk_max_low_pfn, blk_max_pfn;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment