git: afcd1210246b - main - geom_gate: Distinguish between classes of errors

From: Peter Jeremy <peterj_at_FreeBSD.org>
Date: Sat, 29 Jan 2022 10:17:14 UTC
The branch main has been updated by peterj:

URL: https://cgit.FreeBSD.org/src/commit/?id=afcd1210246bebd8ed9bdaf31bd5218630af4cdc

commit afcd1210246bebd8ed9bdaf31bd5218630af4cdc
Author:     Peter Jeremy <peterj@FreeBSD.org>
AuthorDate: 2022-01-29 10:15:51 +0000
Commit:     Peter Jeremy <peterj@FreeBSD.org>
CommitDate: 2022-01-29 10:15:51 +0000

    geom_gate: Distinguish between classes of errors
    
    The geom_gate API provides 2 distinct paths for exchanging error
    details between the kernel and the userland client: Including an error
    code in the g_gate_ctl_io structure passed in the ioctl(2) call or
    having the ioctl(2) call return -1 with an error code in errno. The
    latter reflects errors in the ioctl(2) call itself whilst the former
    reflects errors within the geom_gate instance.
    
    The G_GATE_CMD_START ioctl blocks waiting for an I/O request to be
    directed to the geom_gate instance and the wait can fail
    (necessitating an error return) if the geom_gate instance is destroyed
    or if the msleep(9) fails. The code previously treated both error
    cases indentically: Returning ECANCELED as a geom_gate instance error
    (which the ggatec treats as a fatal error).  Whilst this is the correct
    behaviour if the geom_gate instance is destroyed, a msleep(9) failure
    is unrelated to the geom_gate instance itself and should be reported
    as an ioctl(2) "failure".  The distinction is important because
    msleep(9) can return ERESTART, which means the system call should be
    retried (and this will occur automatically as part of the generic
    syscall return processing).
    
    This change alters the msleep(9) handling to directly return the error
    code from msleep(9), which ensures ERESTART is correctly handled,
    rather than being treated as a fatal error.
    
    Reviewed by:    Johannes Totz <jo@bruelltuete.com>
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D33996
---
 sys/geom/gate/g_gate.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sys/geom/gate/g_gate.c b/sys/geom/gate/g_gate.c
index 14ec0cc2e9d2..4e98d78c1e43 100644
--- a/sys/geom/gate/g_gate.c
+++ b/sys/geom/gate/g_gate.c
@@ -861,11 +861,10 @@ g_gate_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct threa
 				mtx_unlock(&sc->sc_queue_mtx);
 				goto start_end;
 			}
-			if (msleep(sc, &sc->sc_queue_mtx,
-			    PPAUSE | PDROP | PCATCH, "ggwait", 0) != 0) {
-				ggio->gctl_error = ECANCELED;
+			error = msleep(sc, &sc->sc_queue_mtx,
+				PPAUSE | PDROP | PCATCH, "ggwait", 0);
+			if (error != 0)
 				goto start_end;
-			}
 		}
 		ggio->gctl_cmd = bp->bio_cmd;
 		if (bp->bio_cmd == BIO_WRITE &&