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....@virtuozzo.com> --- 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 2ab1450a0005..bcb11e40e419 100644 --- a/fs/fuse/kio/pcs/pcs_krpc.c +++ b/fs/fuse/kio/pcs/pcs_krpc.c @@ -620,6 +620,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; @@ -654,6 +684,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) _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel