fuse: Use the high bit of request ID for indicating resend requests
authorZhao Chen <winters.zc@antgroup.com>
Tue, 9 Jan 2024 09:24:43 +0000 (17:24 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 6 Mar 2024 08:56:35 +0000 (09:56 +0100)
Some FUSE daemons want to know if the received request is a resend
request. The high bit of the fuse request ID is utilized for indicating
this, enabling the receiver to perform appropriate handling.

The init flag "FUSE_HAS_RESEND" is added to indicate this feature.

Signed-off-by: Zhao Chen <winters.zc@antgroup.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev.c
fs/fuse/inode.c
include/uapi/linux/fuse.h

index 3c15a6b7f6f24ed2cc3e7feb394adca88eba6b9e..3ec8bb5e68ff59497481a84e4038fee093f08be8 100644 (file)
@@ -1814,6 +1814,8 @@ static void fuse_resend(struct fuse_conn *fc)
 
        list_for_each_entry_safe(req, next, &to_queue, list) {
                __set_bit(FR_PENDING, &req->flags);
+               /* mark the request as resend request */
+               req->in.h.unique |= FUSE_UNIQUE_RESEND;
        }
 
        spin_lock(&fiq->lock);
index ca5fad57bfa400c6ef9b7ccf19b5d86de88cc44f..02869edf72f3ef6abb37f78a782a0ba9807016b3 100644 (file)
@@ -1370,7 +1370,7 @@ void fuse_send_init(struct fuse_mount *fm)
                FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT | FUSE_INIT_EXT |
                FUSE_SECURITY_CTX | FUSE_CREATE_SUPP_GROUP |
                FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP |
-               FUSE_NO_EXPORT_SUPPORT;
+               FUSE_NO_EXPORT_SUPPORT | FUSE_HAS_RESEND;
 #ifdef CONFIG_FUSE_DAX
        if (fm->fc->dax)
                flags |= FUSE_MAP_ALIGNMENT;
index 659932eb35e174ce2e41cfdf889607fd9ad92d89..d08b99d60f6fd6d0d072d01ad6bcc1b48da0a242 100644 (file)
  *  - add max_stack_depth to fuse_init_out, add FUSE_PASSTHROUGH init flag
  *  - add backing_id to fuse_open_out, add FOPEN_PASSTHROUGH open flag
  *  - add FUSE_NO_EXPORT_SUPPORT init flag
- *  - add FUSE_NOTIFY_RESEND
+ *  - add FUSE_NOTIFY_RESEND, add FUSE_HAS_RESEND init flag
  */
 
 #ifndef _LINUX_FUSE_H
@@ -419,6 +419,8 @@ struct fuse_file_lock {
  * FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
  * FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
  * FUSE_NO_EXPORT_SUPPORT: explicitly disable export support
+ * FUSE_HAS_RESEND: kernel supports resending pending requests, and the high bit
+ *                 of the request ID indicates resend requests
  */
 #define FUSE_ASYNC_READ                (1 << 0)
 #define FUSE_POSIX_LOCKS       (1 << 1)
@@ -460,6 +462,7 @@ struct fuse_file_lock {
 #define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
 #define FUSE_PASSTHROUGH       (1ULL << 37)
 #define FUSE_NO_EXPORT_SUPPORT (1ULL << 38)
+#define FUSE_HAS_RESEND                (1ULL << 39)
 
 /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
 #define FUSE_DIRECT_IO_RELAX   FUSE_DIRECT_IO_ALLOW_MMAP
@@ -973,6 +976,14 @@ struct fuse_fallocate_in {
        uint32_t        padding;
 };
 
+/**
+ * FUSE request unique ID flag
+ *
+ * Indicates whether this is a resend request. The receiver should handle this
+ * request accordingly.
+ */
+#define FUSE_UNIQUE_RESEND (1ULL << 63)
+
 struct fuse_in_header {
        uint32_t        len;
        uint32_t        opcode;