Skip to contentSkip to conversation

block/loop: handle discard/zeroout error

PATCH Superseded Shaohua Li 2 participants 8 messages Sep 7, 2017 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

v2 cover block/loop: handle discard/zeroout error

From: Shaohua Li <[email protected]>

Fix some problems when setting up loop device with a block device as back file and create/mount ext4 in the loop device.

BTW: blkdev_issue_zeroout retries if we immediately find the device doesn't support zeroout, but it doesn't retry if submit_bio_wait returns -EOPNOTSUPP. Is this correct behavior?

Thanks,
Shaohua

Shaohua Li (3):
block/loop: don't hijack error number
block/loop: use FALLOC_FL_ZERO_RANGE for REQ_OP_WRITE_ZEROES block/loop: suppress discard IO error message

 drivers/block/loop.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.9.5
author
#1 lore raw

PATCH v2 1/3 block/loop: don't hijack error number

From: Shaohua Li <[email protected]>

If the bio returns -EOPNOTSUPP, we shouldn't hijack it and return -EIO

---
 drivers/block/loop.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/loop.c +3 -3
index 85de673..715b762 100644
@@ -460,7 +460,7 @@ static void lo_complete_rq(struct request *rq)
 		zero_fill_bio(bio);
 	}
 
-	blk_mq_end_request(rq, cmd->ret < 0 ? BLK_STS_IOERR : BLK_STS_OK);
+	blk_mq_end_request(rq, errno_to_blk_status(cmd->ret));
 }
 
 static void lo_rw_aio_do_completion(struct loop_cmd *cmd)
@@ -476,7 +476,7 @@ static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2)
 {
 	struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb);
 
-	cmd->ret = ret;
+	cmd->ret = ret > 0 ? 0 : ret;
 	lo_rw_aio_do_completion(cmd);
 }
 
@@ -1706,7 +1706,7 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
  failed:
 	/* complete non-aio request */
 	if (!cmd->use_aio || ret) {
-		cmd->ret = ret ? -EIO : 0;
+		cmd->ret = ret;
 		blk_mq_complete_request(cmd->rq);
 	}
 }
Signature · 1 line
2.9.5
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH V2 1/3] block/loop: don't hijack error number

Quoted 41 lines · Shaohua Li

From: Shaohua Li <[email protected]>

If the bio returns -EOPNOTSUPP, we shouldn't hijack it and return -EIO

---
 drivers/block/loop.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/loop.c +3 -4
index 85de673..715b762 100644
@@ -460,7 +460,7 @@ static void lo_complete_rq(struct request *rq)
                zero_fill_bio(bio);
        }
 
-       blk_mq_end_request(rq, cmd->ret < 0 ? BLK_STS_IOERR : BLK_STS_OK);
+       blk_mq_end_request(rq, errno_to_blk_status(cmd->ret));
 }
 
 static void lo_rw_aio_do_completion(struct loop_cmd *cmd)
@@ -476,7 +476,7 @@ static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2)
 {
        struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb);
 
-       cmd->ret = ret;
+       cmd->ret = ret > 0 ? 0 : ret;
        lo_rw_aio_do_completion(cmd);
 }
 
@@ -1706,7 +1706,7 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
  failed:
        /* complete non-aio request */
        if (!cmd->use_aio || ret) {
-               cmd->ret = ret ? -EIO : 0;
+               cmd->ret = ret;
                blk_mq_complete_request(cmd->rq);
        }
 }
--
Quoted 2 lines

2.9.5

Looks fine:

Signature · 1 line
Ming Lei
author
#3 lore raw

PATCH v2 2/3 block/loop: use FALLOC_FL_ZERO_RANGE for REQ_OP_WRITE_ZEROES

In reply to Shaohua Li

From: Shaohua Li <[email protected]>

REQ_OP_WRITE_ZEROES really means zero the data. And in blkdev_fallocate, FALLOC_FL_ZERO_RANGE will retry but FALLOC_FL_PUNCH_HOLE not, even loop request doesn't have BLKDEV_ZERO_NOFALLBACK set.

---
 drivers/block/loop.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -0
index 715b762..8934e25 100644
@@ -426,6 +426,9 @@ static int lo_discard(struct loop_device *lo, struct request *rq, loff_t pos)
 	int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
 	int ret;
 
+	if (req_op(rq) == REQ_OP_WRITE_ZEROES)
+		mode = FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE;
+
 	if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) {
 		ret = -EOPNOTSUPP;
 		goto out;
Signature · 1 line
2.9.5
Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH V2 2/3] block/loop: use FALLOC_FL_ZERO_RANGE for REQ_OP_WRITE_ZEROES

Quoted 26 lines · Shaohua Li

From: Shaohua Li <[email protected]>

REQ_OP_WRITE_ZEROES really means zero the data. And in blkdev_fallocate, FALLOC_FL_ZERO_RANGE will retry but FALLOC_FL_PUNCH_HOLE not, even loop request doesn't have BLKDEV_ZERO_NOFALLBACK set.

---
 drivers/block/loop.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -1
index 715b762..8934e25 100644
@@ -426,6 +426,9 @@ static int lo_discard(struct loop_device *lo, struct request *rq, loff_t pos)
        int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
        int ret;
 
+       if (req_op(rq) == REQ_OP_WRITE_ZEROES)
+               mode = FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE;
+
        if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) {
                ret = -EOPNOTSUPP;
                goto out;
--
Quoted 2 lines

2.9.5

Looks fine,

Signature · 1 line
Ming Lei
author
#5 lore raw

PATCH v2 3/3 block/loop: suppress discard IO error message

In reply to Shaohua Li

From: Shaohua Li <[email protected]>

We don't know if fallocate really supports FALLOC_FL_PUNCH_HOLE till fallocate is called. If it doesn't support, loop will return -EOPNOTSUPP and we see a lot of error message printed by blk_update_request. Failure for discard IO isn't a big problem, so we just return 0 in loop which will suppress the IO error message.

---
 drivers/block/loop.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -0
index 8934e25..9d4545f 100644
@@ -437,6 +437,9 @@ static int lo_discard(struct loop_device *lo, struct request *rq, loff_t pos)
 	ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq));
 	if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP))
 		ret = -EIO;
+
+	if (req_op(rq) == REQ_OP_DISCARD && ret == -EOPNOTSUPP)
+		ret = 0;
  out:
 	return ret;
 }
Signature · 1 line
2.9.5
#6 lore raw

Re: [PATCH V2 3/3] block/loop: suppress discard IO error message

Quoted 7 lines · Shaohua Li

From: Shaohua Li <[email protected]>

We don't know if fallocate really supports FALLOC_FL_PUNCH_HOLE till fallocate is called. If it doesn't support, loop will return -EOPNOTSUPP and we see a lot of error message printed by blk_update_request. Failure for discard IO isn't a big problem, so we just return 0 in loop which will suppress the IO error message.

Setting RQF_QUIET for discard IO should be more clean for suppressing error, and upper layer can get the failure notification too.

Signature · 1 line
Ming Lei
author
#7 lore raw

Re: [PATCH V2 3/3] block/loop: suppress discard IO error message

Quoted 11 lines · Ming Lei
Quoted 7 lines · Shaohua Li

From: Shaohua Li <[email protected]>

We don't know if fallocate really supports FALLOC_FL_PUNCH_HOLE till fallocate is called. If it doesn't support, loop will return -EOPNOTSUPP and we see a lot of error message printed by blk_update_request. Failure for discard IO isn't a big problem, so we just return 0 in loop which will suppress the IO error message.

Setting RQF_QUIET for discard IO should be more clean for suppressing error, and upper layer can get the failure notification too.

Hmm, forgot why I didn't do this, did consider it before. Probably because nobody check the return value of discard request. Probably we should skip the error message for all discard IO in block layer.

I'll repost a patch to fix this issue.

Thanks,
Shaohua