The commit is pushed to "branch-rh9-5.14.0-427.44.1.vz9.80.x-ovz" and will 
appear at g...@bitbucket.org:openvz/vzkernel.git
after rh9-5.14.0-427.44.1.vz9.80.4
------>
commit ebc07215c5c227572010de59cfcdfa87354f6a41
Author: Liu Kui <kui....@virtuozzo.com>
Date:   Wed Jan 22 17:44:35 2025 +0800

    fs/fuse kio: add support for cancelling a request from userspace
    
    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
    https://virtuozzo.atlassian.net/browse/VSTOR-97762
    
    Signed-off-by: Liu Kui <kui....@virtuozzo.com>
    Acked-by: Alexey Kuznetsov <kuz...@virtuozzo.com>
    
    Feature: fuse: kRPC - single RPC for kernel and userspace
---
 fs/fuse/kio/pcs/pcs_krpc.c      | 33 +++++++++++++++++++++++++++++++++
 fs/fuse/kio/pcs/pcs_krpc_prot.h |  1 +
 2 files changed, 34 insertions(+)

diff --git a/fs/fuse/kio/pcs/pcs_krpc.c b/fs/fuse/kio/pcs/pcs_krpc.c
index 2a359f910904..c549120e3bcb 100644
--- a/fs/fuse/kio/pcs/pcs_krpc.c
+++ b/fs/fuse/kio/pcs/pcs_krpc.c
@@ -688,6 +688,36 @@ 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;
+
+       mutex_lock(&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;
@@ -722,6 +752,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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to