mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fuse: add hang check in request_wait_answer()
@ 2025-12-23  6:21 Zhang Tianci
  2025-12-23 23:16 ` Joanne Koong
  0 siblings, 1 reply; 11+ messages in thread
From: Zhang Tianci @ 2025-12-23  6:21 UTC (permalink / raw)
  To: miklos
  Cc: linux-fsdevel, linux-kernel, xieyongji, zhujia.zj, Zhang Tianci,
	Jiachen Zhang

If the FUSEDaemon fails to respond to FUSE requests
due to certain reasons (e.g., deadlock), the kernel
can detect this situation and issue an alert via logging.
Based on monitoring of such alerts in the kernel logs,
we can configure hang event alerts for large-scale deployed
FUSEDaemon clusters.

Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
Signed-off-by: Zhang Tianci <zhangtianci.1997@bytedance.com>
---
 fs/fuse/dev.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 6d59cbc877c6a..7b3d4160647a2 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -30,6 +30,9 @@
 MODULE_ALIAS_MISCDEV(FUSE_MINOR);
 MODULE_ALIAS("devname:fuse");
 
+static unsigned long hang_complain_secs = 60;
+module_param(hang_complain_secs, ulong, 0644);
+
 static struct kmem_cache *fuse_req_cachep;
 
 const unsigned long fuse_timeout_timer_freq =
@@ -545,14 +548,24 @@ static void request_wait_answer(struct fuse_req *req)
 {
 	struct fuse_conn *fc = req->fm->fc;
 	struct fuse_iqueue *fiq = &fc->iq;
+	unsigned int hang_check_time = 0;
 	int err;
 
 	if (!fc->no_interrupt) {
-		/* Any signal may interrupt this */
-		err = wait_event_interruptible(req->waitq,
-					test_bit(FR_FINISHED, &req->flags));
-		if (!err)
-			return;
+		while (true) {
+			/* Any signal may interrupt this */
+			err = wait_event_interruptible_timeout(
+				req->waitq, test_bit(FR_FINISHED, &req->flags),
+				READ_ONCE(hang_complain_secs) * HZ);
+			if (err > 0)
+				goto out;
+			if (err == -ERESTARTSYS)
+				break;
+			if (hang_check_time++ == 0) {
+				pr_debug("fuse conn %u req %llu (opcode %u) may hang.\n",
+					fc->dev, req->in.h.unique, req->args->opcode);
+			}
+		}
 
 		set_bit(FR_INTERRUPTED, &req->flags);
 		/* matches barrier in fuse_dev_do_read() */
@@ -568,21 +581,38 @@ static void request_wait_answer(struct fuse_req *req)
 		err = wait_event_killable(req->waitq,
 					test_bit(FR_FINISHED, &req->flags));
 		if (!err)
-			return;
+			goto out;
 
 		if (test_bit(FR_URING, &req->flags))
 			removed = fuse_uring_remove_pending_req(req);
 		else
 			removed = fuse_remove_pending_req(req, &fiq->lock);
 		if (removed)
-			return;
+			goto out;
 	}
 
 	/*
 	 * Either request is already in userspace, or it was forced.
 	 * Wait it out.
 	 */
-	wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags));
+	while (true) {
+		err = wait_event_timeout(req->waitq, test_bit(FR_FINISHED, &req->flags),
+				 READ_ONCE(hang_complain_secs) * HZ);
+		if (err > 0)
+			goto out;
+		if (err == -ERESTARTSYS)
+			break;
+		if (hang_check_time++ == 0) {
+			pr_debug("fuse conn %u req %llu (opcode %u) may hang.\n",
+				fc->dev, req->in.h.unique, req->args->opcode);
+		}
+	}
+out:
+	if (hang_check_time) {
+		pr_debug("fuse conn %u req %llu (opcode %u) recovery after %lu seconds\n",
+			fc->dev, req->in.h.unique, req->args->opcode,
+			hang_check_time * READ_ONCE(hang_complain_secs));
+	}
 }
 
 static void __fuse_request_send(struct fuse_req *req)
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-01-08 22:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-23  6:21 [PATCH] fuse: add hang check in request_wait_answer() Zhang Tianci
2025-12-23 23:16 ` Joanne Koong
2025-12-24  3:04   ` [External] " Zhang Tianci
2025-12-29 19:28     ` Joanne Koong
2026-01-04  7:22       ` Zhang Tianci
2026-01-05 22:30         ` Joanne Koong
2026-01-07  2:43           ` Zhang Tianci
2026-01-08  0:00             ` Joanne Koong
2026-01-08  2:25               ` Zhang Tianci
2026-01-08 22:57                 ` Joanne Koong
2026-01-08 13:19               ` Bernd Schubert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®