Skip to contentSkip to conversation

block: scsi: introduce and use BLK_STS_OFFLINE

PATCH Applied Song Liu 4 participants 8 messages Feb 3, 2022 – Feb 4, 2022

Subsystems (2)
lore
Share & tools
lore

Song Liu

author
#0 lore raw

v2 cover block: scsi: introduce and use BLK_STS_OFFLINE

Changes v1 => v2:
1. Add patch 2/3 to change user visible return value to -ENODEV. (Hannes)
2. In the commit log, explain the reason to keep EIO in 1/3.

We have a use case where HDDs are regularly power on/off to perserve power. When a drive is being removed, we often see errors like

   [  172.803279] I/O error, dev sda, sector 3137184

These messages are confusing for automations that grep dmesg, as they look very similar to real HDD error.

Solve this issue with a new block state BLK_STS_OFFLINE. After the change, the error message looks like

   [  172.803279] device offline error, dev sda, sector 3137184

so that the automations won't confuse them with real I/O error.

Song Liu (3):
block: introduce BLK_STS_OFFLINE
block: return -ENODEV for BLK_STS_OFFLINE
scsi: use BLK_STS_OFFLINE for not fully online devices

 block/blk-core.c          | 1 +
 drivers/scsi/scsi_lib.c   | 2 +-
 include/linux/blk_types.h | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)

--
2.30.2

author
#1 lore raw

PATCH v2 1/3 block: introduce BLK_STS_OFFLINE

Currently, drivers reports BLK_STS_IOERR for devices that are not full online or being removed. This behavior could cause confusion for users, as they are not really I/O errors from the device.

Solve this issue with a new state BLK_STS_OFFLINE, which reports "device offline error" in dmesg instead of "I/O error".

EIO is intentionally kept to not change user visible return value.

---
 block/blk-core.c          | 1 +
 include/linux/blk_types.h | 7 +++++++
 2 files changed, 8 insertions(+)
block/blk-core.c +1 -0
index 61f6a0dc4511..24035dd2eef1 100644
@@ -164,6 +164,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_OFFLINE]	= { -EIO,	"device offline" },
 
 	/* device mapper special case, should not leak out: */
 	[BLK_STS_DM_REQUEUE]	= { -EREMCHG, "dm internal retry" },
include/linux/blk_types.h +7 -0
index fe065c394fff..5561e58d158a 100644
@@ -153,6 +153,13 @@ typedef u8 __bitwise blk_status_t;
  */
 #define BLK_STS_ZONE_ACTIVE_RESOURCE	((__force blk_status_t)16)
 
+/*
+ * BLK_STS_OFFLINE is returned from the driver when the target device is offline
+ * or is being taken offline. This could help differentiate the case where a
+ * device is intentionally being shut down from a real I/O error.
+ */
+#define BLK_STS_OFFLINE		((__force blk_status_t)17)
+
 /**
  * blk_path_error - returns true if error may be path related
  * @error: status the request was completed with
Signature · 1 line
2.30.2
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] block: introduce BLK_STS_OFFLINE

Quoted 7 lines · Song Liu

Currently, drivers reports BLK_STS_IOERR for devices that are not full online or being removed. This behavior could cause confusion for users, as they are not really I/O errors from the device.

Solve this issue with a new state BLK_STS_OFFLINE, which reports "device offline error" in dmesg instead of "I/O error".

Quoted 8 lines

EIO is intentionally kept to not change user visible return value.

---
  block/blk-core.c          | 1 +
  include/linux/blk_types.h | 7 +++++++
  2 files changed, 8 insertions(+)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
author
#3 lore raw

PATCH v2 2/3 block: return -ENODEV for BLK_STS_OFFLINE

In reply to Song Liu

Change the user visible return value for BLK_STS_OFFLINE to -ENODEV, which is more descriptive than existing -EIO.

---
 block/blk-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-core.c +1 -1
index 24035dd2eef1..be8812f5489d 100644
@@ -164,7 +164,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_OFFLINE]	= { -EIO,	"device offline" },
+	[BLK_STS_OFFLINE]	= { -ENODEV,	"device offline" },
 
 	/* device mapper special case, should not leak out: */
 	[BLK_STS_DM_REQUEUE]	= { -EREMCHG, "dm internal retry" },
Signature · 1 line
2.30.2
Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] block: return -ENODEV for BLK_STS_OFFLINE

Quoted 8 lines · Song Liu

Change the user visible return value for BLK_STS_OFFLINE to -ENODEV, which is more descriptive than existing -EIO.

---
  block/blk-core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
author
#5 lore raw

PATCH v2 3/3 scsi: use BLK_STS_OFFLINE for not fully online devices

In reply to Song Liu

The new error message for such case looks like

[  172.809565] device offline error, dev sda, sector 3138208 ...

which will not be confused with regular I/O error (BLK_STS_IOERR).

---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +1 -1
index 0a70aa763a96..e30bc51578e9 100644
@@ -1276,7 +1276,7 @@ scsi_device_state_check(struct scsi_device *sdev, struct request *req)
 		 * power management commands.
 		 */
 		if (req && !(req->rq_flags & RQF_PM))
-			return BLK_STS_IOERR;
+			return BLK_STS_OFFLINE;
 		return BLK_STS_OK;
 	}
 }
Signature · 1 line
2.30.2
Reviewed-by on the v2 series
#6 lore raw
In reply to Song Liu

Song,

Quoted 8 lines

We have a use case where HDDs are regularly power on/off to perserve power. When a drive is being removed, we often see errors like

   [  172.803279] I/O error, dev sda, sector 3137184

These messages are confusing for automations that grep dmesg, as they look very similar to real HDD error.

Quoted 6 lines

Solve this issue with a new block state BLK_STS_OFFLINE. After the change, the error message looks like

   [  172.803279] device offline error, dev sda, sector 3137184

so that the automations won't confuse them with real I/O error.

Looks OK to me.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer Applied
#7 lore raw
In reply to Song Liu
Quoted 8 lines · Song Liu

Changes v1 => v2:
1. Add patch 2/3 to change user visible return value to -ENODEV. (Hannes)
2. In the commit log, explain the reason to keep EIO in 1/3.

We have a use case where HDDs are regularly power on/off to perserve power. When a drive is being removed, we often see errors like

[...]

Applied, thanks!

[1/3] block: introduce BLK_STS_OFFLINE

      commit: 2651bf680bc2ad9a078b7222b0873145ab4ece07
[2/3] block: return -ENODEV for BLK_STS_OFFLINE
      commit: 7d32c027a21ef7aa0a400763397644d44b3576a9
[3/3] scsi: use BLK_STS_OFFLINE for not fully online devices
      commit: 9574d43479e16352e75bc875c9952ed8e129c9b2

Best regards,

Signature · 1 line
Jens Axboe