git: 52da74743361 - stable/14 - virtio_p9fs: Simplify vt9p_req_wait() a bit

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 13 Aug 2025 12:02:03 UTC
The branch stable/14 has been updated by markj:

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

commit 52da74743361aee74de93052346bf1c951def73e
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-10-25 17:52:52 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-08-13 11:56:21 +0000

    virtio_p9fs: Simplify vt9p_req_wait() a bit
    
    Remove an always-false check for whether the request has already
    completed before sleeping.  Even if the request is complete, the
    response tag is updated while holding the channel lock, which is also
    held here.
    
    No functional change intended.
    
    Sponsored by:   Klara, Inc.
    
    (cherry picked from commit 28c9b13b236d25512cfe4e1902411ff421a14b64)
---
 sys/dev/virtio/p9fs/virtio_p9fs.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/sys/dev/virtio/p9fs/virtio_p9fs.c b/sys/dev/virtio/p9fs/virtio_p9fs.c
index 24d4542e4e48..1d9b847717b7 100644
--- a/sys/dev/virtio/p9fs/virtio_p9fs.c
+++ b/sys/dev/virtio/p9fs/virtio_p9fs.c
@@ -110,20 +110,20 @@ SYSCTL_UINT(_vfs_9p, OID_AUTO, ackmaxidle, CTLFLAG_RW, &vt9p_ackmaxidle, 0,
 static int
 vt9p_req_wait(struct vt9p_softc *chan, struct p9_req_t *req)
 {
-	if (req->tc->tag != req->rc->tag) {
-		if (msleep(req, VT9P_MTX(chan), 0, "chan lock",
-		    vt9p_ackmaxidle * hz)) {
-			/*
-			 * Waited for 120s. No response from host.
-			 * Can't wait for ever..
-			 */
-			P9_DEBUG(ERROR, "Timeout after waiting %u seconds"
-			    "for an ack from host\n", vt9p_ackmaxidle);
-			return (EIO);
-		}
-		KASSERT(req->tc->tag == req->rc->tag,
-		    ("Spurious event on p9 req"));
+	KASSERT(req->tc->tag != req->rc->tag,
+	    ("%s: request %p already completed", __func__, req));
+
+	if (msleep(req, VT9P_MTX(chan), 0, "chan lock", vt9p_ackmaxidle * hz)) {
+		/*
+		 * Waited for 120s. No response from host.
+		 * Can't wait for ever..
+		 */
+		P9_DEBUG(ERROR, "Timeout after waiting %u seconds"
+		    "for an ack from host\n", vt9p_ackmaxidle);
+		return (EIO);
 	}
+	KASSERT(req->tc->tag == req->rc->tag,
+	    ("%s spurious event on request %p", __func__, req));
 	return (0);
 }