There are quite a lot of filesystems doing their verification work done
at endio hook or hook before submitting bio.

Normally such verification returns -EUCLEAN to indicate something
unexpected, and some of such verification either uses bio->bi_status or
users bio->bi_endio to return their value.

In such case, the missing of such corresponding BLK_STS_UCLEAN can lower
the severity just like:
  In endio function:
        return errno_to_blk_status(-EUCLEAN);
        ^^^ -EUCLEAN gets interpreted to BLK_STS_IOERR

  In the filesystem code:
        ret = blk_status_to_errno(bi->bi_status);
        ^^^ BLK_STS_IOERR gets interpreted to -EIO;

This lowers the severity, making the filesystem layer to believe it's
just an ordinary error.

This patch will add a new BLK_STS_UCLEAN, to allow -EUCLEAN to be
converted to BLK_STS_UCLEAN, and then converted back to -EUCLEAN without
losing anything.

Signed-off-by: Qu Wenruo <[email protected]>
---
Changlog:
v2:
- Use BLK_STS_UCLEAN to replace the previous stupid naming scheme.
v3:
- Use "filesystem is corrupted" as error string.
- Add explanation about why filesystem code needs such status.
---
 block/blk-core.c          | 1 +
 include/linux/blk_types.h | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/block/blk-core.c b/block/blk-core.c
index a55389ba8779..427528950dcc 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -135,6 +135,7 @@ static const struct {
        [BLK_STS_RESOURCE]      = { -ENOMEM,    "kernel resource" },
        [BLK_STS_DEV_RESOURCE]  = { -EBUSY,     "device resource" },
        [BLK_STS_AGAIN]         = { -EAGAIN,    "nonblocking retry" },
+       [BLK_STS_UCLEAN]        = { -EUCLEAN,   "filesystem is corrupted" },
 
        /* device mapper special case, should not leak out: */
        [BLK_STS_DM_REQUEUE]    = { -EREMCHG, "dm internal retry" },
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 791fee35df88..df0c470147c1 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -63,6 +63,9 @@ typedef u8 __bitwise blk_status_t;
  */
 #define BLK_STS_DEV_RESOURCE   ((__force blk_status_t)13)
 
+/* Normally filesystem layer generated error */
+#define BLK_STS_UCLEAN         ((__force blk_status_t)14)
+
 /**
  * blk_path_error - returns true if error may be path related
  * @error: status the request was completed with
-- 
2.21.0

Reply via email to