For hot update. If it is possible it should be pushed to customers as kpatch.

It was forgotten at kernel implementation since connect
has been move to kernel. See commit b94eed73ce781976a7006f6ddb49fdb26f5d6ef1

The result are accidental lockups at kernel level.
Plain luck this happens not so frequently. It is necessary
that a CS dies, its port was taken by another service, which
does not respond to garbage messages, and that kernel decided
to connect to CS without reacquiring new map, which is also
rather an exception. Yet we were hit bad after 2 years.

Affects: #VSTOR-62165
https://pmc.acronis.work/browse/VSTOR-62165

Signed-off-by: Alexey Kuznetsov <kuz...@acronis.com>
From bf6c6385836fe41b88e7b16ed5376bb7cac3cfc7 Mon Sep 17 00:00:00 2001
From: Alexey Kuznetsov <kuz...@acronis.com>
Date: Tue, 17 Jan 2023 15:14:02 +0200
Subject: fuse: pcs: missing timeout at authentication phase

It was forgotten at kernel implementation since connect
has been move to kernel. See commit b94eed73ce781976a7006f6ddb49fdb26f5d6ef1

The result are accidental lockups at kernel level.
Plain luck this happens not so frequently. It is necessary
that a CS dies, its port was taken by another service, which
does not respond to garbage messages, and that kernel decided
to connect to CS without reacquiring new map, which is also
rather an exception. Yet we were hit bad after 2 years.

Affects: #VSTOR-62165
https://pmc.acronis.work/browse/VSTOR-62165

Signed-off-by: Alexey Kuznetsov <kuz...@acronis.com>
---
 fs/fuse/kio/pcs/pcs_sock_io.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/kio/pcs/pcs_sock_io.c b/fs/fuse/kio/pcs/pcs_sock_io.c
index f159ca0..5a15329 100644
--- a/fs/fuse/kio/pcs/pcs_sock_io.c
+++ b/fs/fuse/kio/pcs/pcs_sock_io.c
@@ -758,6 +758,22 @@ static int pcs_sock_send_buf(struct socket *sock, void *buf, size_t size)
 	return ret < 0 ? ret : 0;
 }
 
+static int pcs_sock_set_rcv_timeo(struct socket * sock, int tmo)
+{
+	if (sock->sk == NULL)
+		return -EINVAL;
+
+	/* No need to lock the socket. We own it and this option does not affect protocol */
+
+	if (tmo <= 0) {
+		sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
+	} else {
+		sock->sk->sk_rcvtimeo = tmo;
+	}
+
+	return 0;
+}
+
 static int pcs_sock_recv_buf(struct socket *sock, void *buf, size_t size)
 {
 	struct msghdr msg = {
@@ -784,16 +800,22 @@ static int pcs_sock_sync_send(struct pcs_netio *netio, struct pcs_msg *msg)
 static int pcs_sock_sync_recv(struct pcs_netio *netio, struct pcs_msg **msg)
 {
 	struct pcs_sockio *sio = sio_from_netio(netio);
+	struct pcs_rpc *ep = netio->parent;
 	struct pcs_rpc_hdr hdr;
 	int err;
 
-	err = pcs_sock_recv_buf(sio->socket, &hdr, sizeof(hdr));
+	err = pcs_sock_set_rcv_timeo(sio->socket, ep->params.connect_timeout);
 	if (err)
 		return err;
 
+	err = pcs_sock_recv_buf(sio->socket, &hdr, sizeof(hdr));
+	if (err)
+		goto out;
+
+	err = -ENOMEM;
 	*msg = pcs_rpc_alloc_output_msg(hdr.len);
 	if (!*msg)
-		return -ENOMEM;
+		goto out;
 
 	memcpy((*msg)->_inline_buffer, &hdr, sizeof(hdr));
 
@@ -802,10 +824,11 @@ static int pcs_sock_sync_recv(struct pcs_netio *netio, struct pcs_msg **msg)
 	if (err) {
 		pcs_free_msg(*msg);
 		*msg = NULL;
-		return err;
 	}
 
-	return 0;
+out:
+	(void)pcs_sock_set_rcv_timeo(sio->socket, -1);
+	return err;
 }
 
 struct pcs_netio_tops pcs_sock_netio_tops = {
-- 
1.8.3.1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to