bcachefs: thread_with_stdio: suppress hung task warning
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 9 Feb 2024 01:41:34 +0000 (20:41 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 14 Mar 2024 01:22:04 +0000 (21:22 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/thread_with_file.c

index 83186e824e8843e707e71c849266772990970dc7..96ac2b2c60e122a09e7e18e872e3e5da6aa1c06c 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/kthread.h>
 #include <linux/pagemap.h>
 #include <linux/poll.h>
+#include <linux/sched/sysctl.h>
 
 void bch2_thread_with_file_exit(struct thread_with_file *thr)
 {
@@ -264,7 +265,15 @@ int bch2_stdio_redirect_read(struct stdio_redirect *stdio, char *ubuf, size_t le
 {
        struct stdio_buf *buf = &stdio->input;
 
-       wait_event(buf->wait, stdio_redirect_has_input(stdio));
+       /*
+        * we're waiting on user input (or for the file descriptor to be
+        * closed), don't want a hung task warning:
+        */
+       do {
+               wait_event_timeout(buf->wait, stdio_redirect_has_input(stdio),
+                                  sysctl_hung_task_timeout_secs * HZ / 2);
+       } while (!stdio_redirect_has_input(stdio));
+
        if (stdio->done)
                return -1;
 
@@ -287,7 +296,11 @@ int bch2_stdio_redirect_readline(struct stdio_redirect *stdio, char *ubuf, size_
        size_t copied = 0;
        ssize_t ret = 0;
 again:
-       wait_event(buf->wait, stdio_redirect_has_input(stdio));
+       do {
+               wait_event_timeout(buf->wait, stdio_redirect_has_input(stdio),
+                                  sysctl_hung_task_timeout_secs * HZ / 2);
+       } while (!stdio_redirect_has_input(stdio));
+
        if (stdio->done) {
                ret = -1;
                goto out;