Skip to contentSkip to conversation

Introduce sysfs API for resend pending requests

PATCH RESEND In review Zhao Chen 2 participants 7 messages Nov 29, 2023 – Nov 30, 2023

Subsystems (2)
lore
Share & tools
lore

Zhao Chen

author
#0 lore raw

v2 cover Introduce sysfs API for resend pending requests

After the FUSE daemon crashes, the fuse mount point becomes inaccessible. In some production environments, a watchdog daemon is used to preserve the FUSE connection's file descriptor (fd). When the FUSE daemon crashes, a new FUSE daemon is started and takes over the fd from the watchdog daemon, allowing it to continue providing services.

However, if any inflight requests are lost during the crash, the user process becomes stuck as it does not receive any replies.

To resolve this issue, this patchset introduces a sysfs API that enable resending these pending requests to the FUSE daemon again, allowing the stuck user process to recover.

When using the resend API, FUSE daemon needs to ensure proper recording and avoidance of processing duplicate non-idempotent requests to prevent potential consistency issues. The high bit of the fuse request id is utilized for indicating the resend request.

---
v1->v2:
- remove flush sysfs API in the original mail
- add using high bit of request ID for indicating resend requests
- add wakeup in fuse_resend_pqueue()

Peng Tao (1):
fuse: Introduce sysfs API for resend pending reque

Zhao Chen (1):
fuse: Use the high bit of request ID for indicating resend requests

 fs/fuse/control.c         | 20 +++++++++++
 fs/fuse/dev.c             | 70 ++++++++++++++++++++++++++++++++++++---
 fs/fuse/fuse_i.h          |  5 ++-
 fs/fuse/inode.c           |  3 +-
 include/uapi/linux/fuse.h | 11 ++++++
 5 files changed, 103 insertions(+), 6 deletions(-)
Signature · 1 line
2.32.0.3.g01195cf9f
author
#1 lore raw

PATCH RESEND v2 1/2 fuse: Introduce sysfs API for resend pending reque

From: Peng Tao <[email protected]>

When a FUSE daemon panic and failover, we aim to minimize the impact on applications by reusing the existing FUSE connection. During this process, another daemon is employed to preserve the FUSE connection's file descriptor.

However, it is possible for some inflight requests to be lost and never returned. As a result, applications awaiting replies would become stuck forever. To address this, we can resend these pending requests to the FUSE daemon, which is done by fuse_resend_pqueue(), ensuring they are properly processed again.

---
 fs/fuse/control.c | 20 ++++++++++++++++
 fs/fuse/dev.c     | 59 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_i.h  |  5 +++-
 3 files changed, 83 insertions(+), 1 deletion(-)
fs/fuse/control.c +20 -0
index 284a35006462..fd2258d701dd 100644
@@ -44,6 +44,18 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf,
 	return count;
 }
 
+static ssize_t fuse_conn_resend_write(struct file *file, const char __user *buf,
+				      size_t count, loff_t *ppos)
+{
+	struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
+
+	if (fc) {
+		fuse_resend_pqueue(fc);
+		fuse_conn_put(fc);
+	}
+	return count;
+}
+
 static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
 				      size_t len, loff_t *ppos)
 {
@@ -190,6 +202,12 @@ static const struct file_operations fuse_ctl_abort_ops = {
 	.llseek = no_llseek,
 };
 
+static const struct file_operations fuse_ctl_resend_ops = {
+	.open = nonseekable_open,
+	.write = fuse_conn_resend_write,
+	.llseek = no_llseek,
+};
+
 static const struct file_operations fuse_ctl_waiting_ops = {
 	.open = nonseekable_open,
 	.read = fuse_conn_waiting_read,
@@ -274,6 +292,8 @@ int fuse_ctl_add_conn(struct fuse_conn *fc)
 				 NULL, &fuse_ctl_waiting_ops) ||
 	    !fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 1,
 				 NULL, &fuse_ctl_abort_ops) ||
+	    !fuse_ctl_add_dentry(parent, fc, "resend", S_IFREG | 0200, 1,
+				 NULL, &fuse_ctl_resend_ops) ||
 	    !fuse_ctl_add_dentry(parent, fc, "max_background", S_IFREG | 0600,
 				 1, NULL, &fuse_conn_max_background_ops) ||
 	    !fuse_ctl_add_dentry(parent, fc, "congestion_threshold",
fs/fuse/dev.c +59 -0

65 lines not on this page · raw message

fs/fuse/fuse_i.h +4 -1
index 1df83eebda92..5142537c3471 100644
@@ -45,7 +45,7 @@
 #define FUSE_NAME_MAX 1024
 
 /** Number of dentries for each connection in the control filesystem */
-#define FUSE_CTL_NUM_DENTRIES 5
+#define FUSE_CTL_NUM_DENTRIES 6
 
 /** List of active connections */
 extern struct list_head fuse_conn_list;
@@ -1122,6 +1122,9 @@ void fuse_request_end(struct fuse_req *req);
 void fuse_abort_conn(struct fuse_conn *fc);
 void fuse_wait_aborted(struct fuse_conn *fc);
 
+/* Resend all requests in processing queue so they can represent to userspace */
+void fuse_resend_pqueue(struct fuse_conn *fc);
+
 /**
  * Invalidate inode attributes
  */
Signature · 1 line
2.32.0.3.g01195cf9f
maintainer
#2 lore raw

Re: [PATCH v2 RESEND 1/2] fuse: Introduce sysfs API for resend pending reque

Quoted 32 lines · Zhao Chen

From: Peng Tao <[email protected]>

When a FUSE daemon panic and failover, we aim to minimize the impact on applications by reusing the existing FUSE connection. During this process, another daemon is employed to preserve the FUSE connection's file descriptor.

However, it is possible for some inflight requests to be lost and never returned. As a result, applications awaiting replies would become stuck forever. To address this, we can resend these pending requests to the FUSE daemon, which is done by fuse_resend_pqueue(), ensuring they are properly processed again.

---
 fs/fuse/control.c | 20 ++++++++++++++++
 fs/fuse/dev.c     | 59 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_i.h  |  5 +++-
 3 files changed, 83 insertions(+), 1 deletion(-)
fs/fuse/control.c +2 -0
index 284a35006462..fd2258d701dd 100644
@@ -44,6 +44,18 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf,
        return count;
 }
 
+static ssize_t fuse_conn_resend_write(struct file *file, const char __user *buf,
+                                     size_t count, loff_t *ppos)

fs/fuse/control.c static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf, · line 58

Quoted 10 lines
fs/fuse/control.c +10 -0
+{
+       struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
+
+       if (fc) {
+               fuse_resend_pqueue(fc);
+               fuse_conn_put(fc);
+       }
+       return count;
+}
+

How about triggering this with a notification (FUSE_NOTIFY_RESEND)?

Thanks,
Miklos

author
#3 lore raw

Re: [PATCH v2 RESEND 1/2] fuse: Introduce sysfs API for resend pending reque

Quoted 46 lines · Miklos Szeredi
Quoted 32 lines · Zhao Chen

From: Peng Tao <[email protected]>

When a FUSE daemon panic and failover, we aim to minimize the impact on applications by reusing the existing FUSE connection. During this process, another daemon is employed to preserve the FUSE connection's file descriptor.

However, it is possible for some inflight requests to be lost and never returned. As a result, applications awaiting replies would become stuck forever. To address this, we can resend these pending requests to the FUSE daemon, which is done by fuse_resend_pqueue(), ensuring they are properly processed again.

---
  fs/fuse/control.c | 20 ++++++++++++++++
  fs/fuse/dev.c     | 59 +++++++++++++++++++++++++++++++++++++++++++++++
  fs/fuse/fuse_i.h  |  5 +++-
  3 files changed, 83 insertions(+), 1 deletion(-)
fs/fuse/control.c +2 -0
index 284a35006462..fd2258d701dd 100644
@@ -44,6 +44,18 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf,
         return count;
  }
 
+static ssize_t fuse_conn_resend_write(struct file *file, const char __user *buf,
+                                     size_t count, loff_t *ppos)

fs/fuse/control.c static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf, · line 58

Quoted 10 lines
fs/fuse/control.c +10 -0
+{
+       struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
+
+       if (fc) {
+               fuse_resend_pqueue(fc);
+               fuse_conn_put(fc);
+       }
+       return count;
+}
+

How about triggering this with a notification (FUSE_NOTIFY_RESEND)?

Quoted 2 lines

Thanks,
Miklos

Yes, I think using notification is better, I will try to implement it in v3. Thank you for the review!

Regards,
Zhao Chen

author
#4 lore raw

PATCH RESEND v2 2/2 fuse: Use the high bit of request ID for indicating resend requests

In reply to Zhao Chen

Some FUSE daemons want to know if the received request is a resend request, after writing to the sysfs resend API. The high bit of the fuse request id is utilized for indicating this, enabling the receiver to perform appropriate handling.

An init flag is added to indicate this feature.

---
 fs/fuse/dev.c             | 11 +++++++----
 fs/fuse/inode.c           |  3 ++-
 include/uapi/linux/fuse.h | 11 +++++++++++
 3 files changed, 20 insertions(+), 5 deletions(-)
fs/fuse/dev.c +7 -4
index c91cb2bd511b..8a90a41b9a17 100644
@@ -28,6 +28,7 @@ MODULE_ALIAS("devname:fuse");
 /* Ordinary requests have even IDs, while interrupts IDs are odd */
 #define FUSE_INT_REQ_BIT (1ULL << 0)
 #define FUSE_REQ_ID_STEP (1ULL << 1)
+#define FUSE_REQ_ID_MASK (~(FUSE_INT_REQ_BIT | FUSE_REQ_ID_RESEND_BIT))
 
 static struct kmem_cache *fuse_req_cachep;
 
@@ -194,14 +195,14 @@ EXPORT_SYMBOL_GPL(fuse_len_args);
 
 u64 fuse_get_unique(struct fuse_iqueue *fiq)
 {
-	fiq->reqctr += FUSE_REQ_ID_STEP;
+	fiq->reqctr = (fiq->reqctr + FUSE_REQ_ID_STEP) & FUSE_REQ_ID_MASK;
 	return fiq->reqctr;
 }
 EXPORT_SYMBOL_GPL(fuse_get_unique);
 
 static unsigned int fuse_req_hash(u64 unique)
 {
-	return hash_long(unique & ~FUSE_INT_REQ_BIT, FUSE_PQ_HASH_BITS);
+	return hash_long(unique & FUSE_REQ_ID_MASK, FUSE_PQ_HASH_BITS);
 }
 
 /*
@@ -1813,7 +1814,7 @@ static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique)
 	struct fuse_req *req;
 
 	list_for_each_entry(req, &fpq->processing[hash], list) {
-		if (req->in.h.unique == unique)
+		if ((req->in.h.unique & FUSE_REQ_ID_MASK) == unique)
 			return req;
 	}
 	return NULL;
@@ -1884,7 +1885,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
 	spin_lock(&fpq->lock);
 	req = NULL;
 	if (fpq->connected)
-		req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT);
+		req = request_find(fpq, oh.unique & FUSE_REQ_ID_MASK);
 
 	err = -ENOENT;
 	if (!req) {
@@ -2274,6 +2275,8 @@ void fuse_resend_pqueue(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_REQ_ID_RESEND_BIT;
 	}
 
 	spin_lock(&fiq->lock);
fs/fuse/inode.c +2 -1
index 2a6d44f91729..e774865fbfa3 100644
@@ -1330,7 +1330,8 @@ void fuse_send_init(struct fuse_mount *fm)
 		FUSE_NO_OPENDIR_SUPPORT | FUSE_EXPLICIT_INVAL_DATA |
 		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_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP |
+		FUSE_UID_HAS_RESEND_BIT;
 #ifdef CONFIG_FUSE_DAX
 	if (fm->fc->dax)
 		flags |= FUSE_MAP_ALIGNMENT;
include/uapi/linux/fuse.h +11 -0
index e7418d15fe39..ecfb7cbcfe30 100644
@@ -410,6 +410,8 @@ struct fuse_file_lock {
  *			symlink and mknod (single group that matches parent)
  * FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
  * FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
+ * FUSE_UID_HAS_RESEND_BIT: use high bit of request ID for indicating resend
+ *			    requests
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -449,6 +451,7 @@ struct fuse_file_lock {
 #define FUSE_CREATE_SUPP_GROUP	(1ULL << 34)
 #define FUSE_HAS_EXPIRE_ONLY	(1ULL << 35)
 #define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
+#define FUSE_UID_HAS_RESEND_BIT (1ULL << 37)
 
 /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
 #define FUSE_DIRECT_IO_RELAX	FUSE_DIRECT_IO_ALLOW_MMAP
@@ -960,6 +963,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_REQ_ID_RESEND_BIT (1ULL << 63)
+
 struct fuse_in_header {
 	uint32_t	len;
 	uint32_t	opcode;
Signature · 1 line
2.32.0.3.g01195cf9f
maintainer
#5 lore raw

Re: [PATCH v2 RESEND 2/2] fuse: Use the high bit of request ID for indicating resend requests

Quoted 31 lines · Zhao Chen

Some FUSE daemons want to know if the received request is a resend request, after writing to the sysfs resend API. The high bit of the fuse request id is utilized for indicating this, enabling the receiver to perform appropriate handling.

An init flag is added to indicate this feature.

---
 fs/fuse/dev.c             | 11 +++++++----
 fs/fuse/inode.c           |  3 ++-
 include/uapi/linux/fuse.h | 11 +++++++++++
 3 files changed, 20 insertions(+), 5 deletions(-)
fs/fuse/dev.c +1 -0
index c91cb2bd511b..8a90a41b9a17 100644
@@ -28,6 +28,7 @@ MODULE_ALIAS("devname:fuse");
 /* Ordinary requests have even IDs, while interrupts IDs are odd */
 #define FUSE_INT_REQ_BIT (1ULL << 0)
 #define FUSE_REQ_ID_STEP (1ULL << 1)
+#define FUSE_REQ_ID_MASK (~(FUSE_INT_REQ_BIT | FUSE_REQ_ID_RESEND_BIT))
 
 static struct kmem_cache *fuse_req_cachep;
 
@@ -194,14 +195,14 @@ EXPORT_SYMBOL_GPL(fuse_len_args);
 
 u64 fuse_get_unique(struct fuse_iqueue *fiq)
 {

fs/fuse/dev.c EXPORT_SYMBOL_GPL(fuse_len_args); · line 205

Quoted 10 lines
fs/fuse/dev.c +2 -2
-       fiq->reqctr += FUSE_REQ_ID_STEP;
+       fiq->reqctr = (fiq->reqctr + FUSE_REQ_ID_STEP) & FUSE_REQ_ID_MASK;
        return fiq->reqctr;
 }
 EXPORT_SYMBOL_GPL(fuse_get_unique);
 
 static unsigned int fuse_req_hash(u64 unique)
 {
-       return hash_long(unique & ~FUSE_INT_REQ_BIT, FUSE_PQ_HASH_BITS);
+       return hash_long(unique & FUSE_REQ_ID_MASK, FUSE_PQ_HASH_BITS);

Possible simplification if FUSE_REQ_ID_RESEND_BIT is not used as a separate flag, but as a part of the unique request ID. That way there's no need to mask it out.

fs/fuse/dev.c static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique) · line 1817

Quoted 9 lines
fs/fuse/dev.c +1 -1
 }
 
 /*
@@ -1813,7 +1814,7 @@ static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique)
        struct fuse_req *req;
 
        list_for_each_entry(req, &fpq->processing[hash], list) {
-               if (req->in.h.unique == unique)
+               if ((req->in.h.unique & FUSE_REQ_ID_MASK) == unique)

Same here.

Quoted 49 lines
fs/fuse/dev.c +3 -1
                        return req;
        }
        return NULL;
@@ -1884,7 +1885,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
        spin_lock(&fpq->lock);
        req = NULL;
        if (fpq->connected)
-               req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT);
+               req = request_find(fpq, oh.unique & FUSE_REQ_ID_MASK);
 
        err = -ENOENT;
        if (!req) {
@@ -2274,6 +2275,8 @@ void fuse_resend_pqueue(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_REQ_ID_RESEND_BIT;
        }
 
        spin_lock(&fiq->lock);
fs/fuse/inode.c +2 -1
index 2a6d44f91729..e774865fbfa3 100644
@@ -1330,7 +1330,8 @@ void fuse_send_init(struct fuse_mount *fm)
                FUSE_NO_OPENDIR_SUPPORT | FUSE_EXPLICIT_INVAL_DATA |
                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_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP |
+               FUSE_UID_HAS_RESEND_BIT;
 #ifdef CONFIG_FUSE_DAX
        if (fm->fc->dax)
                flags |= FUSE_MAP_ALIGNMENT;
include/uapi/linux/fuse.h +2 -0
index e7418d15fe39..ecfb7cbcfe30 100644
@@ -410,6 +410,8 @@ struct fuse_file_lock {
  *                     symlink and mknod (single group that matches parent)
  * FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
  * FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
+ * FUSE_UID_HAS_RESEND_BIT: use high bit of request ID for indicating resend
+ *                         requests
  */
 #define FUSE_ASYNC_READ                (1 << 0)
 #define FUSE_POSIX_LOCKS       (1 << 1)

include/uapi/linux/fuse.h struct fuse_file_lock { · line 454

Quoted 4 lines
include/uapi/linux/fuse.h +1 -0
@@ -449,6 +451,7 @@ struct fuse_file_lock {
 #define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
 #define FUSE_HAS_EXPIRE_ONLY   (1ULL << 35)
 #define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
+#define FUSE_UID_HAS_RESEND_BIT (1ULL << 37)

"FUSE_HAS_RESEND" should be sufficiently descriptive.

Quoted 4 lines
include/uapi/linux/fuse.h +0 -0
 /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
 #define FUSE_DIRECT_IO_RELAX   FUSE_DIRECT_IO_ALLOW_MMAP

include/uapi/linux/fuse.h struct fuse_fallocate_in { · line 972

Quoted 10 lines
include/uapi/linux/fuse.h +7 -0
@@ -960,6 +963,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_REQ_ID_RESEND_BIT (1ULL << 63)

How about "FUSE_UNIQUE_RESEND"?

Thanks,
Miklos

author
#6 lore raw

Re: [PATCH v2 RESEND 2/2] fuse: Use the high bit of request ID for indicating resend requests

Quoted 38 lines · Miklos Szeredi
Quoted 37 lines · Zhao Chen

Some FUSE daemons want to know if the received request is a resend request, after writing to the sysfs resend API. The high bit of the fuse request id is utilized for indicating this, enabling the receiver to perform appropriate handling.

An init flag is added to indicate this feature.

---
  fs/fuse/dev.c             | 11 +++++++----
  fs/fuse/inode.c           |  3 ++-
  include/uapi/linux/fuse.h | 11 +++++++++++
  3 files changed, 20 insertions(+), 5 deletions(-)
fs/fuse/dev.c +2 -1
index c91cb2bd511b..8a90a41b9a17 100644
@@ -28,6 +28,7 @@ MODULE_ALIAS("devname:fuse");
  /* Ordinary requests have even IDs, while interrupts IDs are odd */
  #define FUSE_INT_REQ_BIT (1ULL << 0)
  #define FUSE_REQ_ID_STEP (1ULL << 1)
+#define FUSE_REQ_ID_MASK (~(FUSE_INT_REQ_BIT | FUSE_REQ_ID_RESEND_BIT))
 
  static struct kmem_cache *fuse_req_cachep;
 
@@ -194,14 +195,14 @@ EXPORT_SYMBOL_GPL(fuse_len_args);
 
  u64 fuse_get_unique(struct fuse_iqueue *fiq)
  {
-       fiq->reqctr += FUSE_REQ_ID_STEP;
+       fiq->reqctr = (fiq->reqctr + FUSE_REQ_ID_STEP) & FUSE_REQ_ID_MASK;
         return fiq->reqctr;
  }
  EXPORT_SYMBOL_GPL(fuse_get_unique);
 
Quoted 8 lines

fs/fuse/dev.c EXPORT_SYMBOL_GPL(fuse_len_args); · line 205

Quoted 4 lines
fs/fuse/dev.c +1 -1
  static unsigned int fuse_req_hash(u64 unique)
  {
-       return hash_long(unique & ~FUSE_INT_REQ_BIT, FUSE_PQ_HASH_BITS);
+       return hash_long(unique & FUSE_REQ_ID_MASK, FUSE_PQ_HASH_BITS);

Possible simplification if FUSE_REQ_ID_RESEND_BIT is not used as a separate flag, but as a part of the unique request ID. That way there's no need to mask it out.

Yes, I will simplify it in v3.

Quoted 7 lines
Quoted 7 lines
fs/fuse/dev.c +0 -0
  }
 
  /*
@@ -1813,7 +1814,7 @@ static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique)
         struct fuse_req *req;
 
Quoted 5 lines

fs/fuse/dev.c static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique) · line 1817

Quoted 3 lines
fs/fuse/dev.c +1 -1
         list_for_each_entry(req, &fpq->processing[hash], list) {
-               if (req->in.h.unique == unique)
+               if ((req->in.h.unique & FUSE_REQ_ID_MASK) == unique)

Same here.

OK.

Quoted 49 lines
Quoted 49 lines
fs/fuse/dev.c +3 -1
                         return req;
         }
         return NULL;
@@ -1884,7 +1885,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
         spin_lock(&fpq->lock);
         req = NULL;
         if (fpq->connected)
-               req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT);
+               req = request_find(fpq, oh.unique & FUSE_REQ_ID_MASK);
 
         err = -ENOENT;
         if (!req) {
@@ -2274,6 +2275,8 @@ void fuse_resend_pqueue(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_REQ_ID_RESEND_BIT;
         }
 
         spin_lock(&fiq->lock);
fs/fuse/inode.c +2 -1
index 2a6d44f91729..e774865fbfa3 100644
@@ -1330,7 +1330,8 @@ void fuse_send_init(struct fuse_mount *fm)
                 FUSE_NO_OPENDIR_SUPPORT | FUSE_EXPLICIT_INVAL_DATA |
                 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_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP |
+               FUSE_UID_HAS_RESEND_BIT;
  #ifdef CONFIG_FUSE_DAX
         if (fm->fc->dax)
                 flags |= FUSE_MAP_ALIGNMENT;
include/uapi/linux/fuse.h +2 -0
index e7418d15fe39..ecfb7cbcfe30 100644
@@ -410,6 +410,8 @@ struct fuse_file_lock {
   *                     symlink and mknod (single group that matches parent)
   * FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
   * FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
+ * FUSE_UID_HAS_RESEND_BIT: use high bit of request ID for indicating resend
+ *                         requests
   */
  #define FUSE_ASYNC_READ                (1 << 0)
Quoted 8 lines

include/uapi/linux/fuse.h struct fuse_file_lock { · line 454

Quoted 6 lines
include/uapi/linux/fuse.h +1 -0
  #define FUSE_POSIX_LOCKS       (1 << 1)
@@ -449,6 +451,7 @@ struct fuse_file_lock {
  #define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
  #define FUSE_HAS_EXPIRE_ONLY   (1ULL << 35)
  #define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
+#define FUSE_UID_HAS_RESEND_BIT (1ULL << 37)

"FUSE_HAS_RESEND" should be sufficiently descriptive.

Yes, "FUSE_HAS_RESEND" is better.

Quoted 17 lines
Quoted 4 lines
include/uapi/linux/fuse.h +0 -0
  /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
  #define FUSE_DIRECT_IO_RELAX   FUSE_DIRECT_IO_ALLOW_MMAP

include/uapi/linux/fuse.h struct fuse_fallocate_in { · line 972

Quoted 10 lines
include/uapi/linux/fuse.h +7 -0
@@ -960,6 +963,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_REQ_ID_RESEND_BIT (1ULL << 63)

How about "FUSE_UNIQUE_RESEND"?

Quoted 2 lines

Thanks,
Miklos

Yes, "FUSE_UNIQUE_RESEND" is better. Thank you for your patient review!

Regards,
Zhao Chen