linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Hao <flyingpenghao@gmail.com>
To: miklos@szeredi.hu
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH v2] fuse: add a dev ioctl for recovery
Date: Wed,  8 Sep 2021 16:44:41 +0800	[thread overview]
Message-ID: <20210908084441.48476-1-flyingpeng@tencent.com> (raw)

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 <flyingpeng@tencent.com>
---
 fs/fuse/dev.c             | 31 ++++++++++++++++++++++++++++++-
 include/uapi/linux/fuse.h |  1 +
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 491c092d427b..9b0f34468494 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2239,7 +2239,7 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new)
 static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 			   unsigned long arg)
 {
-	int res;
+	int res = 0;
 	int oldfd;
 	struct fuse_dev *fud = NULL;
 
@@ -2268,6 +2268,35 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
 			}
 		}
 		break;
+
+	case FUSE_DEV_IOC_RECOVERY:
+	{
+		struct fuse_iqueue *fiq;
+		struct fuse_pqueue *fpq;
+		struct fuse_req *req, *next;
+		LIST_HEAD(recovery);
+		unsigned int i;
+
+		fud = fuse_get_dev(file);
+		fiq = &fud->fc->iq;
+		fpq = &fud->pq;
+
+		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);
+		break;
+	}
 	default:
 		res = -ENOTTY;
 		break;
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 36ed092227fa..fc07324efa9d 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -923,6 +923,7 @@ struct fuse_notify_retrieve_in {
 /* Device ioctls: */
 #define FUSE_DEV_IOC_MAGIC		229
 #define FUSE_DEV_IOC_CLONE		_IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
+#define FUSE_DEV_IOC_RECOVERY		_IOR(FUSE_DEV_IOC_MAGIC+1, 0, uint32_t)
 
 struct fuse_lseek_in {
 	uint64_t	fh;
-- 
2.27.0


                 reply	other threads:[~2021-09-08  8:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210908084441.48476-1-flyingpeng@tencent.com \
    --to=flyingpenghao@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).