[Devel] [PATCH VZ9 2/3] fs/fuse kio: add support for cancelling a request from userspace
Liu Kui
kui.liu at virtuozzo.com
Tue Jan 21 11:32:16 MSK 2025
When responding to the keep_wait request from a cs, client may decide to
cancel the request sent to the cs if it finds there's an alternative path
available. With kRPC, it's the userpsace that makes the decision on whether
to cancel a request which however is also waiting in kernel. So we need
to support cancelling a request from userspace. Once cancelled, the request
will be completed in error, which will be returned to userspace thus
completing the userspace request accordingly. If the request cann't be
cancelled at the moment, -EBUSY will be returned, userspace shall wait
and try again later.
Related to #VSTOR-97762
Signed-off-by: Liu Kui <kui.liu at virtuozzo.com>
---
fs/fuse/kio/pcs/pcs_krpc.c | 34 +++++++++++++++++++++++++++++++++
fs/fuse/kio/pcs/pcs_krpc_prot.h | 1 +
2 files changed, 35 insertions(+)
diff --git a/fs/fuse/kio/pcs/pcs_krpc.c b/fs/fuse/kio/pcs/pcs_krpc.c
index 2ab1450a0005..b7509069fb11 100644
--- a/fs/fuse/kio/pcs/pcs_krpc.c
+++ b/fs/fuse/kio/pcs/pcs_krpc.c
@@ -620,6 +620,37 @@ static int pcs_krpc_abort(struct pcs_krpc *krpc)
return 0;
}
+static int pcs_krpc_ioc_cancel_msg(struct pcs_krpc *krpc, u64 xid)
+{
+ int ret = -EBUSY;
+ struct krpc_req *kreq;
+ struct pcs_rpc *ep = krpc->rpc;
+
+ if (krpc->state != PCS_KRPC_STATE_CONNECTED)
+ return 0;
+
+ if (mutex_trylock(&ep->mutex)) {
+ spin_lock(&krpc->lock);
+ list_for_each_entry(kreq, &krpc->pending_queue, link) {
+ struct pcs_rpc_hdr *h = (struct pcs_rpc_hdr *)msg_inline_head(&kreq->msg);
+
+ if (h->xid.val == xid)
+ goto found;
+ }
+ kreq = NULL;
+
+found:
+ spin_unlock(&krpc->lock);
+ if (kreq)
+ ret = pcs_rpc_cancel_msg(ep, &kreq->msg);
+ else
+ ret = 0;
+ mutex_unlock(&ep->mutex);
+ }
+
+ return ret;
+}
+
static long pcs_krpc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct pcs_krpc_context *ctx = file->private_data;
@@ -654,6 +685,9 @@ static long pcs_krpc_ioctl(struct file *file, unsigned int cmd, unsigned long ar
case PCS_KRPC_IOC_ABORT:
res = pcs_krpc_abort(krpc);
break;
+ case PCS_KRPC_IOC_CANCEL_MSG:
+ res = pcs_krpc_ioc_cancel_msg(krpc, arg);
+ break;
default:
res = -ENOTTY;
break;
diff --git a/fs/fuse/kio/pcs/pcs_krpc_prot.h b/fs/fuse/kio/pcs/pcs_krpc_prot.h
index 812f778a6a06..deb17b709bde 100644
--- a/fs/fuse/kio/pcs/pcs_krpc_prot.h
+++ b/fs/fuse/kio/pcs/pcs_krpc_prot.h
@@ -18,6 +18,7 @@
#define PCS_KRPC_IOC_SEND_MSG _IO(PCS_KRPC_IOC_MAGIC, 10)
#define PCS_KRPC_IOC_RECV_MSG _IO(PCS_KRPC_IOC_MAGIC, 11)
#define PCS_KRPC_IOC_ABORT _IO(PCS_KRPC_IOC_MAGIC, 12)
+#define PCS_KRPC_IOC_CANCEL_MSG _IO(PCS_KRPC_IOC_MAGIC, 13)
#define PCS_KRPC_BUF_TYPE_MR 0
#define PCS_KRPC_BUF_TYPE_UMEM 1
--
2.39.5 (Apple Git-154)
More information about the Devel
mailing list