Skip to contentSkip to conversation

fs: Return EOPNOTSUPP if block layer does not support REQ_NOWAIT

PATCH In review Goldwyn Rodrigues 5 participants 18 messages Dec 13, 2018 – Jul 31, 2020 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: Return EOPNOTSUPP if block layer does not support REQ_NOWAIT

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

---
 fs/direct-io.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/direct-io.c +7 -4
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
 	blk_status_t err = bio->bi_status;
 
 	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;
+		dio->io_error = -EIO;
+		if (bio->bi_opf & REQ_NOWAIT) {
+			if (err == BLK_STS_AGAIN)
+				dio->io_error = -EAGAIN;
+			else if (err == BLK_STS_NOTSUPP)
+				dio->io_error = -EOPNOTSUPP;
+		}
 	}
 
 	if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) {
Signature · 1 line
2.16.4
#1 lore raw
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Cc stable@?
Quoted 17 lines
---
  fs/direct-io.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
fs/direct-io.c +0 -4
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
  	blk_status_t err = bio->bi_status;
 
  	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 554

Quoted 10 lines
fs/direct-io.c +7 -0
+		dio->io_error = -EIO;
+		if (bio->bi_opf & REQ_NOWAIT) {
+			if (err == BLK_STS_AGAIN)
+				dio->io_error = -EAGAIN;
+			else if (err == BLK_STS_NOTSUPP)
+				dio->io_error = -EOPNOTSUPP;
+		}
  	}
 
  	if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) {

Looks good. I wonder why it only shows up so rarely. Is there an alternative path that generates EOPNOTSUPP, that works most of the time?

#2 lore raw
Quoted 13 lines · Avi Kivity
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Cc stable@?
Quoted 5 lines
---
  fs/direct-io.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 7 lines

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 543

Quoted 7 lines
fs/direct-io.c +0 -0
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
  	blk_status_t err = bio->bi_status;
  	if (err) {

I think this just need to become:

	if (err)
		dio->io_error = blk_status_to_errno(bio->bi_status);

And Avi, you really should be using XFS ;-)

#3 lore raw
Quoted 24 lines · Christoph Hellwig
Quoted 13 lines · Avi Kivity
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Cc stable@?
Quoted 5 lines
---
  fs/direct-io.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 7 lines

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 543

Quoted 7 lines
fs/direct-io.c +0 -0
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
  	blk_status_t err = bio->bi_status;
  	if (err) {

I think this just need to become:

Quoted 3 lines
	if (err)
		dio->io_error = blk_status_to_errno(bio->bi_status);

Ahh.. Din't of it's existence. Yes, the function is much more elaborate.

Thanks!

Signature · 1 line
Goldwyn
#4 lore raw
In reply to Christoph Hellwig
Quoted 15 lines · Christoph Hellwig
Quoted 6 lines
Quoted 6 lines
---
   fs/direct-io.c | 11 +++++++----
   1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 7 lines

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 543

Quoted 7 lines
fs/direct-io.c +0 -0
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
   	blk_status_t err = bio->bi_status;
   	if (err) {

I think this just need to become:

Quoted 4 lines
	if (err)
		dio->io_error = blk_status_to_errno(bio->bi_status);

And Avi, you really should be using XFS ;-)

I did see this on XFS too. The whole thing bothers me, it doesn't happen consistently in some setups, which I don't understand. Either it should trigger always or never.

#5 lore raw
Quoted 3 lines · Avi Kivity

I did see this on XFS too. The whole thing bothers me, it doesn't happen consistently in some setups, which I don't understand. Either it should trigger always or never.

Well, if it also happens in XFS the above change isn't going to fix it alone, there must be another issue hiding in addition to the error conversion problems.

#6 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Avi Kivity

I did see this on XFS too. The whole thing bothers me, it doesn't happen consistently in some setups, which I don't understand. Either it should trigger always or never.

Well, if it also happens in XFS the above change isn't going to fix it alone, there must be another issue hiding in addition to the error conversion problems.

Are you using multi-device setup as your block device? That could make it return EOPNOTSUPP since we never got to a point where we could merge code which supported bio based devices.

Signature · 1 line
Goldwyn
#7 lore raw
Quoted 5 lines · Goldwyn Rodrigues
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · Avi Kivity

I did see this on XFS too. The whole thing bothers me, it doesn't happen consistently in some setups, which I don't understand. Either it should trigger always or never.

Quoted 7 lines
Quoted 3 lines

Well, if it also happens in XFS the above change isn't going to fix it alone, there must be another issue hiding in addition to the error conversion problems.

Are you using multi-device setup as your block device? That could make it return EOPNOTSUPP since we never got to a point where we could merge code which supported bio based devices.

Yes, an lvm linear device on top of a single SATA SSD.

#8 lore raw
In reply to Goldwyn Rodrigues
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Why is EOPNOTSUPP the "correct" error code? That's a networking error, not a block layer error.

#9 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Why is EOPNOTSUPP the "correct" error code? That's a networking error, not a block layer error.

No. We return EOPNOTSUPP in filesystems as well, in case RWF_NOWAIT is not supported.

Signature · 1 line
Goldwyn
#10 lore raw
In reply to Goldwyn Rodrigues
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Say what?

Does this mean that if a filesystem supports RWF_NOWAIT, but the underlying block device/storage stack doesn't support it, then we'll getting EIO/EOPNOTSUPP errors returned to userspace?

Isn't that highly unfriendly to userspace applications? i.e. instead of just ignoring RWF_NOWAIT in this case and having the AIO succeed, we return a /fatal/ error from deep in the guts of the IO subsystem that the user has no obvious way of tracking down?

I'm also concerned that this is highly hardware dependent - two identical filesystems on different storage hardware on the same machine could behave differently. i.e. it works on one filesystem but not on the other, and there's no way to tell when it will work or fail apart from trying to use RWF_NOWAIT?

I'd also like to point out that this errori (whether EIO or EOPNOTSUPP) is completely undocumented in the preadv2/pwritev2 man page, so application developers that get bug reports about EOPNOTSUPP errors are going to be rather confused....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#11 lore raw
Quoted 6 lines · Dave Chinner
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Say what?

Quoted 8 lines

Does this mean that if a filesystem supports RWF_NOWAIT, but the underlying block device/storage stack doesn't support it, then we'll getting EIO/EOPNOTSUPP errors returned to userspace?

Isn't that highly unfriendly to userspace applications? i.e. instead of just ignoring RWF_NOWAIT in this case and having the AIO succeed, we return a /fatal/ error from deep in the guts of the IO subsystem that the user has no obvious way of tracking down?

Well, if it is not supported, we'd rather let users decide how they want to handle it rather than manipulating the request in the kernel. For all you know, it could be a probe call to understand if RWF_NOWAIT is supported or not.

Quoted 6 lines

I'm also concerned that this is highly hardware dependent - two identical filesystems on different storage hardware on the same machine could behave differently. i.e. it works on one filesystem but not on the other, and there's no way to tell when it will work or fail apart from trying to use RWF_NOWAIT?

I was not too happy getting it all the way down to block layer either. The multi-devices makes it worse. However, here we are and we need to tell the user that RWF_NOWAIT is not supported in this environment.

Quoted 5 lines

I'd also like to point out that this errori (whether EIO or EOPNOTSUPP) is completely undocumented in the preadv2/pwritev2 man page, so application developers that get bug reports about EOPNOTSUPP errors are going to be rather confused....

Yes, I will send a patch to update the man page.

Signature · 1 line
Goldwyn
#12 lore raw
Quoted 16 lines · Goldwyn Rodrigues
Quoted 6 lines · Dave Chinner
Quoted 2 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

Say what?

Quoted 8 lines

Does this mean that if a filesystem supports RWF_NOWAIT, but the underlying block device/storage stack doesn't support it, then we'll getting EIO/EOPNOTSUPP errors returned to userspace?

Isn't that highly unfriendly to userspace applications? i.e. instead of just ignoring RWF_NOWAIT in this case and having the AIO succeed, we return a /fatal/ error from deep in the guts of the IO subsystem that the user has no obvious way of tracking down?

Quoted 4 lines

Well, if it is not supported, we'd rather let users decide how they want to handle it rather than manipulating the request in the kernel. For all you know, it could be a probe call to understand if RWF_NOWAIT is supported or not.

So even though the filesystem supports it and the app can avaoid blocking on filesystem locks (the biggest problem they have by far), we're going to prevent the filesystems from being non-blocking because the underlying block device isn't non blocking?

That amkes no sense to me at all.

Quoted 9 lines
Quoted 5 lines

I'm also concerned that this is highly hardware dependent - two identical filesystems on different storage hardware on the same machine could behave differently. i.e. it works on one filesystem but not on the other, and there's no way to tell when it will work or fail apart from trying to use RWF_NOWAIT?

I was not too happy getting it all the way down to block layer either. The multi-devices makes it worse. However, here we are and we need to tell the user that RWF_NOWAIT is not supported in this environment.

RWF_NOWAIT matters for filesystems much more than the underlying block device. If the application is accessing the blockd evice directly, then yes, RWF_NOWAIT support in the block device matters. But when the IO is being done through the filesystem it's far more important to avoid blocking on filesystem locks that whatever the block device does....

Hence I think that if the bio is coming from a filesystem, REQ_NOWAIT should always be accepted or bounced with EAGAIN and never failed with EOPNOTSUPP. It just makes no sense at all for filesytsem based IO....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#13 lore raw
Quoted 12 lines · Dave Chinner
Quoted 4 lines

I was not too happy getting it all the way down to block layer either. The multi-devices makes it worse. However, here we are and we need to tell the user that RWF_NOWAIT is not supported in this environment.

RWF_NOWAIT matters for filesystems much more than the underlying block device. If the application is accessing the blockd evice directly, then yes, RWF_NOWAIT support in the block device matters. But when the IO is being done through the filesystem it's far more important to avoid blocking on filesystem locks that whatever the block device does....

Quoted 4 lines

Hence I think that if the bio is coming from a filesystem, REQ_NOWAIT should always be accepted or bounced with EAGAIN and never failed with EOPNOTSUPP. It just makes no sense at all for filesytsem based IO....

It was initially suggested where the block layer would retry getting a bio in get_request(). While request based devices were fine, the bio based ones such as MD needed extra work. However, when I actually got down to writing code for multi-device, it got more hurdles than solutions primarily in the area of bio merging.

RWF_NOWAIT should have been restricted to filesystems and I think we should do away (or at least ignore) REQ_NOWAIT for now.

Signature · 1 line
Goldwyn
#14 lore raw
In reply to Goldwyn Rodrigues
Quoted 20 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

---
  fs/direct-io.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
fs/direct-io.c +0 -4
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
  	blk_status_t err = bio->bi_status;
 
  	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 554

Quoted 10 lines
fs/direct-io.c +7 -0
+		dio->io_error = -EIO;
+		if (bio->bi_opf & REQ_NOWAIT) {
+			if (err == BLK_STS_AGAIN)
+				dio->io_error = -EAGAIN;
+			else if (err == BLK_STS_NOTSUPP)
+				dio->io_error = -EOPNOTSUPP;
+		}
  	}
 
  	if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) {

In the end, did this or some alternative get applied? I'd like to enable RWF_NOWAIT support, but EIO scares me and my application.

#15 lore raw
Quoted 26 lines · Avi Kivity
Quoted 24 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

---
  fs/direct-io.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
fs/direct-io.c +5 -4
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
  	blk_status_t err = bio->bi_status;
  	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;
+		dio->io_error = -EIO;
+		if (bio->bi_opf & REQ_NOWAIT) {
+			if (err == BLK_STS_AGAIN)
+				dio->io_error = -EAGAIN;
+			else if (err == BLK_STS_NOTSUPP)
Quoted 9 lines

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 554

Quoted 4 lines
fs/direct-io.c +2 -0
+				dio->io_error = -EOPNOTSUPP;
+		}
  	}
  	if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) {

In the end, did this or some alternative get applied? I'd like to enable RWF_NOWAIT support, but EIO scares me and my application.

No, it was not. There were lot of objections to return error from the block layer for a filesystem nowait request.

Signature · 1 line
Goldwyn
#16 lore raw
Quoted 34 lines · Goldwyn Rodrigues
Quoted 24 lines · Avi Kivity
Quoted 23 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

---
   fs/direct-io.c | 11 +++++++----
   1 file changed, 7 insertions(+), 4 deletions(-)
fs/direct-io.c +4 -4
index 41a0e97252ae..77adf33916b8 100644
@@ -542,10 +542,13 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
   	blk_status_t err = bio->bi_status;
   	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;
+		dio->io_error = -EIO;
+		if (bio->bi_opf & REQ_NOWAIT) {
+			if (err == BLK_STS_AGAIN)
+				dio->io_error = -EAGAIN;
Quoted 9 lines

fs/direct-io.c static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) · line 554

Quoted 5 lines
fs/direct-io.c +3 -0
+			else if (err == BLK_STS_NOTSUPP)
+				dio->io_error = -EOPNOTSUPP;
+		}
   	}
   	if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) {

In the end, did this or some alternative get applied? I'd like to enable RWF_NOWAIT support, but EIO scares me and my application.

Quoted 3 lines

No, it was not. There were lot of objections to return error from the block layer for a filesystem nowait request.

I see. For me, it makes RWF_NOWAIT unusable, since I have no way to distinguish between real EIO and EIO due to this bug.

Maybe the filesystem should ask the block device if it supports nowait ahead of time (during mounting), and not pass REQ_NOWAIT at all in those cases.

#17 lore raw
In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Goldwyn Rodrigues

For AIO+DIO with RWF_NOWAIT, if the block layer does not support REQ_NOWAIT, it returns EIO. Return EOPNOTSUPP to represent the correct error code.

I think the main problem is the EOPNOTSUPP return value. Everywhere else we treat the lack of support as BLK_STS_AGAIN / -EAGAIN, so it should return that. Independ of that the legacy direct I/O code really should just use blk_status_to_errno like most of the other infrastructure instead of havings it's own conversion and dropping the detailed error status on the floor.