From: Bernd Schubert <bschubert@ddn.com>
To: linux-fsdevel@vger.kernel.org
Cc: Dharmendra Singh <dsingh@ddn.com>,
Bernd Schubert <bschubert@ddn.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Amir Goldstein <amir73il@gmail.com>,
fuse-devel@lists.sourceforge.net
Subject: [PATCH 09/13] fuse: Add wait stop ioctl support to the ring
Date: Tue, 21 Mar 2023 02:10:43 +0100 [thread overview]
Message-ID: <20230321011047.3425786-10-bschubert@ddn.com> (raw)
In-Reply-To: <20230321011047.3425786-1-bschubert@ddn.com>
This is an optional ioctl to avoid running the stop monitor
(delayed workq) at run time in intervals - saves cpu cycles.
When the FUSE_DEV_IOC_URING ioctl with subcommand
FUSE_URING_IOCTL_CMD_WAIT is received it cancels the stop monitor
(delayed workq) and then goes into a an interruptible waitq - on
process termination it gets woken up and schedules the stop monitor
again.
As the submitting thread is waiting forever in a waitq,
userspace daemon side has to create a separate thread for it.
The additional ioctl subcommand FUSE_URING_IOCTL_CMD_STOP exits
to let userspace explicitly initiate fuse uring shutdown and to wake up
the FUSE_URING_IOCTL_CMD_WAIT waiting thread.
Signed-off-by: Bernd Schubert <bschubert@ddn.com>
cc: Miklos Szeredi <miklos@szeredi.hu>
cc: linux-fsdevel@vger.kernel.org
cc: Amir Goldstein <amir73il@gmail.com>
cc: fuse-devel@lists.sourceforge.net
---
fs/fuse/dev_uring.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
index ade341d86c03..e19c652e7071 100644
--- a/fs/fuse/dev_uring.c
+++ b/fs/fuse/dev_uring.c
@@ -425,6 +425,49 @@ static int fuse_uring_cfg(struct fuse_conn *fc, unsigned int qid,
return rc;
}
+/**
+ * Wait until uring shall be destructed and then release uring resources
+ */
+static int fuse_uring_wait_stop(struct fuse_conn *fc)
+{
+ struct fuse_iqueue *fiq = &fc->iq;
+
+ pr_devel("%s stop_requested=%d", __func__, fc->ring.stop_requested);
+
+ if (fc->ring.stop_requested)
+ return -EINTR;
+
+ /* This userspace thread can stop uring on process stop, no need
+ * for the interval worker
+ */
+ pr_devel("%s cancel stop monitor\n", __func__);
+ cancel_delayed_work_sync(&fc->ring.stop_monitor);
+
+ wait_event_interruptible(fc->ring.stop_waitq,
+ !fiq->connected ||
+ fc->ring.stop_requested);
+
+ /* The userspace task gets scheduled to back userspace, we need
+ * the interval worker again. It runs immediately for quick cleanup
+ * in shutdown/process kill.
+ */
+
+ mutex_lock(&fc->ring.start_stop_lock);
+ if (!fc->ring.queues_stopped)
+ mod_delayed_work(system_wq, &fc->ring.stop_monitor, 0);
+ mutex_unlock(&fc->ring.start_stop_lock);
+
+ return 0;
+}
+
+static int fuse_uring_shutdown_wakeup(struct fuse_conn *fc)
+{
+ fc->ring.stop_requested = 1;
+ wake_up_all(&fc->ring.stop_waitq);
+
+ return 0;
+}
+
int fuse_uring_ioctl(struct file *file, struct fuse_uring_cfg *cfg)
{
struct fuse_dev *fud = fuse_get_dev(file);
@@ -443,6 +486,10 @@ int fuse_uring_ioctl(struct file *file, struct fuse_uring_cfg *cfg)
switch (cfg->cmd) {
case FUSE_URING_IOCTL_CMD_QUEUE_CFG:
return fuse_uring_cfg(fc, cfg->qid, cfg);
+ case FUSE_URING_IOCTL_CMD_WAIT:
+ return fuse_uring_wait_stop(fc);
+ case FUSE_URING_IOCTL_CMD_STOP:
+ return fuse_uring_shutdown_wakeup(fc);
default:
return -EINVAL;
}
--
2.37.2
next prev parent reply other threads:[~2023-03-21 1:13 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 1:10 [RFC PATCH 00/13] fuse uring communication Bernd Schubert
2023-03-21 1:10 ` [PATCH 01/13] fuse: Add uring data structures and documentation Bernd Schubert
2023-03-21 1:10 ` [PATCH 02/13] fuse: rename to fuse_dev_end_requests and make non-static Bernd Schubert
2023-03-21 1:10 ` [PATCH 03/13] fuse: Move fuse_get_dev to header file Bernd Schubert
2023-03-21 1:10 ` [PATCH 04/13] Add a vmalloc_node_user function Bernd Schubert
2023-03-21 21:21 ` Andrew Morton
2023-03-21 1:10 ` [PATCH 05/13] fuse: Add a uring config ioctl and ring destruction Bernd Schubert
2023-03-21 1:10 ` [PATCH 06/13] fuse: Add an interval ring stop worker/monitor Bernd Schubert
2023-03-23 10:27 ` Miklos Szeredi
2023-03-23 11:04 ` Bernd Schubert
2023-03-23 12:35 ` Miklos Szeredi
2023-03-23 13:18 ` Bernd Schubert
2023-03-23 20:51 ` Bernd Schubert
2023-03-27 13:22 ` Pavel Begunkov
2023-03-27 14:02 ` Bernd Schubert
2023-03-23 13:26 ` Ming Lei
2023-03-21 1:10 ` [PATCH 07/13] fuse: Add uring mmap method Bernd Schubert
2023-03-21 1:10 ` [PATCH 08/13] fuse: Move request bits Bernd Schubert
2023-03-21 1:10 ` Bernd Schubert [this message]
2023-03-21 1:10 ` [PATCH 10/13] fuse: Handle SQEs - register commands Bernd Schubert
2023-03-21 1:10 ` [PATCH 11/13] fuse: Add support to copy from/to the ring buffer Bernd Schubert
2023-03-21 1:10 ` [PATCH 12/13] fuse: Add uring sqe commit and fetch support Bernd Schubert
2023-03-21 1:10 ` [PATCH 13/13] fuse: Allow to queue to the ring Bernd Schubert
2023-03-21 1:26 ` [RFC PATCH 00/13] fuse uring communication Bernd Schubert
2023-03-21 9:35 ` Amir Goldstein
2023-03-23 11:18 ` Bernd Schubert
2023-03-23 11:55 ` Amir Goldstein
2023-06-07 14:20 ` Miklos Szeredi
2023-06-08 21:31 ` Bernd Schubert
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=20230321011047.3425786-10-bschubert@ddn.com \
--to=bschubert@ddn.com \
--cc=amir73il@gmail.com \
--cc=dsingh@ddn.com \
--cc=fuse-devel@lists.sourceforge.net \
--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).