From e1c207b3e7cdfd98ce1120a38c979d748e95f958 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 12 Oct 2021 09:22:27 +0800 Subject: [PATCH] fuse: add a dev ioctl for recovery For a simple read-only file system, as long as the connection is not broken, the recovery of the user-mode read-only file system process can be realized by putting the request of the processing list back into the pending list. Signed-off-by: Peng Hao --- fs/fuse/dev.c | 24 ++++++++++++++++++++++++ include/uapi/linux/fuse.h | 1 + 2 files changed, 25 insertions(+) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 40c262b3f..adc8e6b5e 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2255,6 +2255,30 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd, } } } + if (cmd == FUSE_DEV_IOC_RECOVERY) { + struct fuse_dev *fud = fuse_get_dev(file); + struct fuse_iqueue *fiq = &fud->fc->iq; + struct fuse_pqueue *fpq = &fud->pq; + struct fuse_req *req, *next; + LIST_HEAD(recovery); + unsigned int i; + + spin_lock(&fpq->lock); + for (i = 0; i < FUSE_PQ_HASH_SIZE; i++) + list_splice_tail_init(&fpq->processing[i], + &recovery); + spin_unlock(&fpq->lock); + + list_for_each_entry_safe(req, next, &recovery, list) { + clear_bit(FR_SENT, &req->flags); + set_bit(FR_PENDING, &req->flags); + } + + spin_lock(&fiq->lock); + list_splice(&recovery, &fiq->pending); + spin_unlock(&fiq->lock); + err = 0; + } return err; } diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index 373cada89..3ebc07e2e 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -870,6 +870,7 @@ struct fuse_notify_retrieve_in { /* Device ioctls: */ #define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t) +#define FUSE_DEV_IOC_RECOVERY _IOR(230, 0, uint32_t) struct fuse_lseek_in { uint64_t fh;