summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/thread_with_file.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-02-03 15:43:16 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-03-13 18:39:13 -0400
commit032b3fd0571a8d7e22c7d8c97bdfc76f17717de2 (patch)
tree4140658db8c7651f4f6733400262c46bb5a56c0a /fs/bcachefs/thread_with_file.h
parentf704f108af79c1ccbc1984cf0fd5e9f30102a718 (diff)
downloadlinux-032b3fd0571a8d7e22c7d8c97bdfc76f17717de2.tar.gz
linux-032b3fd0571a8d7e22c7d8c97bdfc76f17717de2.tar.bz2
linux-032b3fd0571a8d7e22c7d8c97bdfc76f17717de2.zip
bcachefs: Thread with file documentation
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/thread_with_file.h')
-rw-r--r--fs/bcachefs/thread_with_file.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/fs/bcachefs/thread_with_file.h b/fs/bcachefs/thread_with_file.h
index 66212fcae226..f06f8ff19a79 100644
--- a/fs/bcachefs/thread_with_file.h
+++ b/fs/bcachefs/thread_with_file.h
@@ -4,6 +4,38 @@
#include "thread_with_file_types.h"
+/*
+ * Thread with file: Run a kthread and connect it to a file descriptor, so that
+ * it can be interacted with via fd read/write methods and closing the file
+ * descriptor stops the kthread.
+ *
+ * We have two different APIs:
+ *
+ * thread_with_file, the low level version.
+ * You get to define the full file_operations, including your release function,
+ * which means that you must call bch2_thread_with_file_exit() from your
+ * .release method
+ *
+ * thread_with_stdio, the higher level version
+ * This implements full piping of input and output, including .poll.
+ *
+ * Notes on behaviour:
+ * - kthread shutdown behaves like writing or reading from a pipe that has been
+ * closed
+ * - Input and output buffers are 4096 bytes, although buffers may in some
+ * situations slightly exceed that limit so as to avoid chopping off a
+ * message in the middle in nonblocking mode.
+ * - Input/output buffers are lazily allocated, with GFP_NOWAIT allocations -
+ * should be fine but might change in future revisions.
+ * - Output buffer may grow past 4096 bytes to deal with messages that are
+ * bigger than 4096 bytes
+ * - Writing may be done blocking or nonblocking; in nonblocking mode, we only
+ * drop entire messages.
+ *
+ * To write, use stdio_redirect_printf()
+ * To read, use stdio_redirect_read() or stdio_redirect_readline()
+ */
+
struct task_struct;
struct thread_with_file {