Skip to content

Commit b9ca2f5

Browse files
stefano-garzarelladavem330
authored andcommitted
vsock: add vsock_create_connected() called by transports
All transports call __vsock_create() with the same parameters, most of them depending on the parent socket. In order to simplify the VSOCK core APIs exposed to the transports, this patch adds the vsock_create_connected() callable from transports to create a new socket when a connection request is received. We also unexported the __vsock_create(). Suggested-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Jorgen Hansen <[email protected]> Signed-off-by: Stefano Garzarella <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b9f2b0f commit b9ca2f5

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

include/net/af_vsock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ struct vsock_sock {
7676

7777
s64 vsock_stream_has_data(struct vsock_sock *vsk);
7878
s64 vsock_stream_has_space(struct vsock_sock *vsk);
79-
struct sock *__vsock_create(struct net *net,
80-
struct socket *sock,
81-
struct sock *parent,
82-
gfp_t priority, unsigned short type, int kern);
79+
struct sock *vsock_create_connected(struct sock *parent);
8380

8481
/**** TRANSPORT ****/
8582

net/vmw_vsock/af_vsock.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,12 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)
567567

568568
static void vsock_connect_timeout(struct work_struct *work);
569569

570-
struct sock *__vsock_create(struct net *net,
571-
struct socket *sock,
572-
struct sock *parent,
573-
gfp_t priority,
574-
unsigned short type,
575-
int kern)
570+
static struct sock *__vsock_create(struct net *net,
571+
struct socket *sock,
572+
struct sock *parent,
573+
gfp_t priority,
574+
unsigned short type,
575+
int kern)
576576
{
577577
struct sock *sk;
578578
struct vsock_sock *psk;
@@ -639,7 +639,6 @@ struct sock *__vsock_create(struct net *net,
639639

640640
return sk;
641641
}
642-
EXPORT_SYMBOL_GPL(__vsock_create);
643642

644643
static void __vsock_release(struct sock *sk, int level)
645644
{
@@ -703,6 +702,13 @@ static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
703702
return err;
704703
}
705704

705+
struct sock *vsock_create_connected(struct sock *parent)
706+
{
707+
return __vsock_create(sock_net(parent), NULL, parent, GFP_KERNEL,
708+
parent->sk_type, 0);
709+
}
710+
EXPORT_SYMBOL_GPL(vsock_create_connected);
711+
706712
s64 vsock_stream_has_data(struct vsock_sock *vsk)
707713
{
708714
return vsk->transport->stream_has_data(vsk);

net/vmw_vsock/hyperv_transport.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ static void hvs_open_connection(struct vmbus_channel *chan)
360360
if (sk->sk_ack_backlog >= sk->sk_max_ack_backlog)
361361
goto out;
362362

363-
new = __vsock_create(sock_net(sk), NULL, sk, GFP_KERNEL,
364-
sk->sk_type, 0);
363+
new = vsock_create_connected(sk);
365364
if (!new)
366365
goto out;
367366

net/vmw_vsock/virtio_transport_common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,7 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
10041004
return -ENOMEM;
10051005
}
10061006

1007-
child = __vsock_create(sock_net(sk), NULL, sk, GFP_KERNEL,
1008-
sk->sk_type, 0);
1007+
child = vsock_create_connected(sk);
10091008
if (!child) {
10101009
virtio_transport_reset(vsk, pkt);
10111010
return -ENOMEM;

net/vmw_vsock/vmci_transport.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,7 @@ static int vmci_transport_recv_listen(struct sock *sk,
10041004
return -ECONNREFUSED;
10051005
}
10061006

1007-
pending = __vsock_create(sock_net(sk), NULL, sk, GFP_KERNEL,
1008-
sk->sk_type, 0);
1007+
pending = vsock_create_connected(sk);
10091008
if (!pending) {
10101009
vmci_transport_send_reset(sk, pkt);
10111010
return -ENOMEM;

0 commit comments

Comments
 (0)