public inbox for [email protected]
 help / color / mirror / Atom feed
From: Kanchan Joshi <[email protected]>
To: [email protected], [email protected], [email protected],
	[email protected]
Cc: [email protected], [email protected],
	[email protected], [email protected],
	[email protected], [email protected],
	Kanchan Joshi <[email protected]>
Subject: [RFC PATCH v4 1/2] io_uring: add helpers for io_uring_cmd completion in submitter-task.
Date: Thu, 25 Mar 2021 22:35:39 +0530	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Completion of io_uring_cmd ioctl may involve referencing certain
ioctl-specefic fields, requiring original submitter-context.
Introduce two APIs for that purpose:
a. io_uring_cmd_complete_in_task
b. io_uring_cbh_to_io_uring_cmd

The APIs facilitate reusing task-work infra, while driver gets to
implement ioctl-specific handling in a callback.

Signed-off-by: Kanchan Joshi  <[email protected]>
Signed-off-by: Anuj Gupta <[email protected]>
---
 fs/io_uring.c            | 23 +++++++++++++++++++++++
 include/linux/io_uring.h | 12 ++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index b6e1b6b51c5f..a8629c460bdd 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2079,6 +2079,29 @@ static void io_req_task_submit(struct callback_head *cb)
 	__io_req_task_submit(req);
 }
 
+struct io_uring_cmd *io_uring_cbh_to_io_uring_cmd(struct callback_head *cb)
+{
+	return &container_of(cb, struct io_kiocb, task_work)->uring_cmd;
+}
+EXPORT_SYMBOL_GPL(io_uring_cbh_to_io_uring_cmd);
+
+int io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
+			void (*driver_cb)(struct callback_head *))
+{
+	int ret;
+	struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd);
+
+	req->task_work.func = driver_cb;
+	ret = io_req_task_work_add(req);
+	if (unlikely(ret)) {
+		req->result = -ECANCELED;
+		percpu_ref_get(&req->ctx->refs);
+		io_req_task_work_add_fallback(req, io_req_task_cancel);
+	}
+	return ret;
+}
+EXPORT_SYMBOL_GPL(io_uring_cmd_complete_in_task);
+
 static void io_req_task_queue_fail(struct io_kiocb *req, int ret)
 {
 	req->result = ret;
diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h
index 9956c0f5f9d0..526bc58dea25 100644
--- a/include/linux/io_uring.h
+++ b/include/linux/io_uring.h
@@ -19,6 +19,9 @@ struct io_uring_cmd {
 
 #if defined(CONFIG_IO_URING)
 void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret);
+int io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
+			void (*driver_cb)(struct callback_head *));
+struct io_uring_cmd *io_uring_cbh_to_io_uring_cmd(struct callback_head *cbh);
 struct sock *io_uring_get_socket(struct file *file);
 void __io_uring_task_cancel(void);
 void __io_uring_files_cancel(struct files_struct *files);
@@ -43,6 +46,15 @@ static inline void io_uring_free(struct task_struct *tsk)
 static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret)
 {
 }
+int io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
+			void (*driver_cb)(struct callback_head *))
+{
+	return -1;
+}
+struct io_uring_cmd *io_uring_cbh_to_io_uring_cmd(struct callback_head *)
+{
+	return NULL;
+}
 static inline struct sock *io_uring_get_socket(struct file *file)
 {
 	return NULL;
-- 
2.25.1


  parent reply	other threads:[~2021-03-25 17:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210325170659epcas5p314b54d01c60189f899f67aaeb9d87a13@epcas5p3.samsung.com>
2021-03-25 17:05 ` [RFC PATCH v4 0/2] Async nvme passthrough via io_uring Kanchan Joshi
     [not found]   ` <CGME20210325170704epcas5p3aafad4845b9ea1a545d643121a0ee1e5@epcas5p3.samsung.com>
2021-03-25 17:05     ` Kanchan Joshi [this message]
     [not found]   ` <CGME20210325170708epcas5p259755feb9f0a769e7390a3b6eebc0e01@epcas5p2.samsung.com>
2021-03-25 17:05     ` [RFC PATCH v4 2/2] nvme: wire up support for async passthrough Kanchan Joshi

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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