[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240710212555.1617795-3-amery.hung@bytedance.com>
Date: Wed, 10 Jul 2024 21:25:43 +0000
From: Amery Hung <ameryhung@...il.com>
To: stefanha@...hat.com,
sgarzare@...hat.com,
mst@...hat.com,
jasowang@...hat.com,
xuanzhuo@...ux.alibaba.com,
davem@...emloft.net,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
kys@...rosoft.com,
haiyangz@...rosoft.com,
wei.liu@...nel.org,
decui@...rosoft.com,
bryantan@...are.com,
vdasa@...are.com,
pv-drivers@...are.com
Cc: dan.carpenter@...aro.org,
simon.horman@...igine.com,
oxffffaa@...il.com,
kvm@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-hyperv@...r.kernel.org,
bpf@...r.kernel.org,
bobby.eshleman@...edance.com,
jiang.wang@...edance.com,
amery.hung@...edance.com,
ameryhung@...il.com,
xiyou.wangcong@...il.com
Subject: [RFC PATCH net-next v6 02/14] af_vsock: refactor transport lookup code
From: Bobby Eshleman <bobby.eshleman@...edance.com>
Introduce new reusable function vsock_connectible_lookup_transport()
that performs the transport lookup logic.
No functional change intended.
Reviewed-by: Stefano Garzarella <sgarzare@...hat.com>
Signed-off-by: Bobby Eshleman <bobby.eshleman@...edance.com>
---
net/vmw_vsock/af_vsock.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 5e7d4d99ea2c..98d10cd30483 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -424,6 +424,22 @@ static void vsock_deassign_transport(struct vsock_sock *vsk)
vsk->transport = NULL;
}
+static const struct vsock_transport *
+vsock_connectible_lookup_transport(unsigned int cid, __u8 flags)
+{
+ const struct vsock_transport *transport;
+
+ if (vsock_use_local_transport(cid))
+ transport = transport_local;
+ else if (cid <= VMADDR_CID_HOST || !transport_h2g ||
+ (flags & VMADDR_FLAG_TO_HOST))
+ transport = transport_g2h;
+ else
+ transport = transport_h2g;
+
+ return transport;
+}
+
/* Assign a transport to a socket and call the .init transport callback.
*
* Note: for connection oriented socket this must be called when vsk->remote_addr
@@ -464,13 +480,8 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
break;
case SOCK_STREAM:
case SOCK_SEQPACKET:
- if (vsock_use_local_transport(remote_cid))
- new_transport = transport_local;
- else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g ||
- (remote_flags & VMADDR_FLAG_TO_HOST))
- new_transport = transport_g2h;
- else
- new_transport = transport_h2g;
+ new_transport = vsock_connectible_lookup_transport(remote_cid,
+ remote_flags);
break;
default:
return -ESOCKTNOSUPPORT;
--
2.20.1
Powered by blists - more mailing lists