Skip to contentSkip to conversation

nvme: honour O_NONBLOCK during resetting

PATCH In review Hannes Reinecke 3 participants 5 messages Nov 11, 2021 – Nov 16, 2021 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: honour O_NONBLOCK during resetting

When opening a controller device node we should honour the O_NONBLOCK flag to allow the device to be openend even if it's in state 'resetting' or 'connecting'. This allows user-space applications to use a call to 'open' to figure out if the controller is present, even if it's currently undergoing a reset.

---
 drivers/nvme/host/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/host/core.c +5 -0
index 74980a1cf89e..67cde3eaf5b0 100644
@@ -3136,6 +3136,11 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
 	switch (ctrl->state) {
 	case NVME_CTRL_LIVE:
 		break;
+	case NVME_CTRL_RESETTING:
+	case NVME_CTRL_CONNECTING:
+		if (file->f_flags & O_NONBLOCK)
+			break;
+		fallthrough;
 	default:
 		return -EWOULDBLOCK;
 	}
Signature · 1 line
2.29.2
#1 lore raw
Quoted 7 lines · Hannes Reinecke

When opening a controller device node we should honour the O_NONBLOCK flag to allow the device to be openend even if it's in state 'resetting' or 'connecting'. This allows user-space applications to use a call to 'open' to figure out if the controller is present, even if it's currently undergoing a reset.

Will resetting and connecting ever result is deleting the controller due to error cases present in that path ?

If yes then application will have handle for something that might go away in the future, should allow such a semantic ?

-ck

maintainer
#2 lore raw
Quoted 7 lines · Chaitanya Kulkarni
Quoted 6 lines · Hannes Reinecke

When opening a controller device node we should honour the O_NONBLOCK flag to allow the device to be openend even if it's in state 'resetting' or 'connecting'. This allows user-space applications to use a call to 'open' to figure out if the controller is present, even if it's currently undergoing a reset.

Quoted 7 lines
Quoted 1 line

Will resetting and connecting ever result is deleting the controller due to error cases present in that path ?

If yes then application will have handle for something that might go away in the future, should allow such a semantic ?

Resets can happen at any time, so they already have to handle it even if the controller was live when they opened it. Perhaps the open should succeed for any non-terminal state.

#4 lore raw
In reply to Chaitanya Kulkarni
Quoted 7 lines · Chaitanya Kulkarni
Quoted 6 lines · Hannes Reinecke

When opening a controller device node we should honour the O_NONBLOCK flag to allow the device to be openend even if it's in state 'resetting' or 'connecting'. This allows user-space applications to use a call to 'open' to figure out if the controller is present, even if it's currently undergoing a reset.

Quoted 5 lines
Quoted 1 line

Will resetting and connecting ever result is deleting the controller due to error cases present in that path ?

Yes, of course this might happen.

Quoted 3 lines

If yes then application will have handle for something that might go away in the future, should allow such a semantic ?
I am not sure I follow.

Even today an application can open the device, and even now error recovery can result in the device now going away. And even today it'll be possible that error recovery sets the device
to 'RESETTING' after the open call.

So I don't think that we need to treat things special because of this patch.

Whether or not the call to nvme_dev_ioctl() should be protected by an explicit state check is a different point, though; that does have some benefits seeing that the timing between open() and ioctl() is pretty much up to the application, and hence we shouldn't assume that the state doesn't change in between. But really it should be done in a different patch.

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
#3 lore raw
In reply to Keith Busch
Quoted 13 lines · Keith Busch
Quoted 12 lines · Chaitanya Kulkarni
Quoted 7 lines · Hannes Reinecke

When opening a controller device node we should honour the O_NONBLOCK flag to allow the device to be openend even if it's in state 'resetting' or 'connecting'. This allows user-space applications to use a call to 'open' to figure out if the controller is present, even if it's currently undergoing a reset.

Will resetting and connecting ever result is deleting the controller due to error cases present in that path ?

Quoted 7 lines
Quoted 2 lines

If yes then application will have handle for something that might go away in the future, should allow such a semantic ?

Resets can happen at any time, so they already have to handle it even if the controller was live when they opened it. Perhaps the open should succeed for any non-terminal state.

Indeed. And we should add a state check for the ioctl itself, returning an error when the device is not running.

I'll be sending an updated patchset.

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