rxrpc: Simplify connect() implementation and simplify sendmsg() op
Subsystems (3)
David Howells
maintainerHi Dave,
Are you okay with taking this into net-next?
I no longer take away the ability to do connect(), but now it does nothing more than specify a default address and mark the socket as being client only. As before, the default address is overridden if sendmsg() is given an address.
The other significant UAPI change is that I deal better with a race between two threads trying to register calls with the same user ID (one of them will get an error).
David
---
rxrpc: Simplify connect() implementation and simplify sendmsg() op
Simplify the RxRPC connect() implementation. It will just note the destination address it is given, and if a sendmsg() comes along with no address, this will be assigned as the address. No transport struct will be held internally, which will allow us to remove this later.
Simplify sendmsg() also. Whilst a call is active, userspace refers to it by a private unique user ID specified in a control message. When sendmsg() sees a user ID that doesn't map to an extant call, it creates a new call for that user ID and attempts to add it. If, when we try to add it, the user ID is now registered, we now reject the message with -EEXIST. We should never see this situation unless two threads are racing, trying to create a call with the same ID - which would be an error.
It also isn't required to provide sendmsg() with an address - provided the control message data holds a user ID that maps to a currently active call.
--- include/linux/rxrpc.h | 18 ++-- net/rxrpc/af_rxrpc.c | 177 +++++++++++++++---------------------------- net/rxrpc/ar-call.c | 158 +++++++++++++++------------------------ net/rxrpc/ar-connection.c | 17 ---- net/rxrpc/ar-internal.h | 22 ++--- net/rxrpc/ar-output.c | 186 +++++++++++++++++++++------------------------- 6 files changed, 234 insertions(+), 344 deletions(-)
include/linux/rxrpc.h +10 -8
@@ -40,16 +40,18 @@ struct sockaddr_rxrpc {/* * RxRPC control messages +* - If neither abort or accept are specified, the message is a data message. * - terminal messages mean that a user call ID tag can be recycled +* - s/r/- indicate whether these are applicable to sendmsg() and/or recvmsg() */ -#define RXRPC_USER_CALL_ID 1/* user call ID specifier */ -#define RXRPC_ABORT 2/* abort request / notification [terminal] */ -#define RXRPC_ACK 3/* [Server] RPC op final ACK received [terminal] */ -#define RXRPC_NET_ERROR 5/* network error received [terminal] */ -#define RXRPC_BUSY 6/* server busy received [terminal] */ -#define RXRPC_LOCAL_ERROR 7/* local error generated [terminal] */ -#define RXRPC_NEW_CALL 8/* [Server] new incoming call notification */ -#define RXRPC_ACCEPT 9/* [Server] accept request */ +#define RXRPC_USER_CALL_ID 1/* sr: user call ID specifier */ +#define RXRPC_ABORT 2/* sr: abort request / notification [terminal] */ +#define RXRPC_ACK 3/* -r: [Service] RPC op final ACK received [terminal] */ +#define RXRPC_NET_ERROR 5/* -r: network error received [terminal] */ +#define RXRPC_BUSY 6/* -r: server busy received [terminal] */ +#define RXRPC_LOCAL_ERROR 7/* -r: local error generated [terminal] */ +#define RXRPC_NEW_CALL 8/* -r: [Service] new incoming call notification */ +#define RXRPC_ACCEPT 9/* s-: [Service] accept request */ /* * RxRPC security levels
net/rxrpc/af_rxrpc.c +63 -114
335 lines not on this page · raw message
net/rxrpc/ar-call.c +62 -96
204 lines not on this page · raw message
net/rxrpc/ar-connection.c +0 -17
@@ -78,11 +78,6 @@ struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *rx,_enter ("%p{%x},%x,%hx," , rx,key_serial (key), trans->debug_id, service_id); -if (rx->trans == trans && rx->bundle) { -atomic_inc (&rx->bundle->usage); -return rx->bundle; - } -/* search the extant bundles first for one that matches the specified * user ID */ spin_lock (&trans->client_lock);
@@ -136,10 +131,6 @@ struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *rx,rb_insert_color (&bundle->node, &trans->bundles);spin_unlock (&trans->client_lock);_net ("BUNDLE new on trans %d" , trans->debug_id); -if (!rx->bundle && rx->sk.sk_state ==RXRPC_CLIENT_CONNECTED ) { -atomic_inc (&bundle->usage); - rx->bundle = bundle; - }_leave (" = %p [new]" , bundle);return bundle;
@@ -148,10 +139,6 @@ found_extant_bundle:atomic_inc (&bundle->usage);spin_unlock (&trans->client_lock);_net ("BUNDLE old on trans %d" , trans->debug_id); -if (!rx->bundle && rx->sk.sk_state ==RXRPC_CLIENT_CONNECTED ) { -atomic_inc (&bundle->usage); - rx->bundle = bundle; - }_leave (" = %p [extant %d]" , bundle,atomic_read (&bundle->usage));return bundle;
@@ -161,10 +148,6 @@ found_extant_second:spin_unlock (&trans->client_lock);kfree (candidate);_net ("BUNDLE old2 on trans %d" , trans->debug_id); -if (!rx->bundle && rx->sk.sk_state ==RXRPC_CLIENT_CONNECTED ) { -atomic_inc (&bundle->usage); - rx->bundle = bundle; - }_leave (" = %p [second %d]" , bundle,atomic_read (&bundle->usage));return bundle; }
net/rxrpc/ar-internal.h +12 -10
@@ -39,9 +39,9 @@ struct rxrpc_crypt {* sk_state for RxRPC sockets */ enum { -RXRPC_UNCONNECTED =0 , +RXRPC_UNBOUND =0 , +RXRPC_CLIENT_UNBOUND ,/* Unbound socket used as client */ RXRPC_CLIENT_BOUND ,/* client local address bound */ -RXRPC_CLIENT_CONNECTED ,/* client is connected */ RXRPC_SERVER_BOUND ,/* server local address bound */ RXRPC_SERVER_LISTENING ,/* server listening for connections */ RXRPC_CLOSE ,/* socket is being closed */
@@ -55,8 +55,6 @@ struct rxrpc_sock {struct sock sk;rxrpc_interceptor_t interceptor;/* kernel service Rx interceptor function */ struct rxrpc_local *local;/* local endpoint */ -struct rxrpc_transport *trans;/* transport handler */ -struct rxrpc_conn_bundle *bundle;/* virtual connection bundle */ struct rxrpc_connection *conn;/* exclusive virtual connection */ struct list_head listen_link;/* link in the local endpoint's listen list */ struct list_head secureq;/* calls awaiting connection security clearance */
@@ -65,11 +63,13 @@ struct rxrpc_sock {struct key *securities;/* list of server security descriptors */ struct rb_root calls;/* outstanding calls on this socket */ unsigned long flags; +#define RXRPC_SOCK_CONNECTED 0/* connect_srx is set */ #define RXRPC_SOCK_EXCLUSIVE_CONN 1/* exclusive connection for a client socket */ rwlock_t call_lock;/* lock for calls */ u32 min_sec_level;/* minimum security level */ #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPTstruct sockaddr_rxrpc srx;/* local address */ +struct sockaddr_rxrpc connect_srx;/* Default client address from connect() */ sa_family_t proto;/* protocol created with */ };
@@ -477,6 +477,10 @@ extern u32 rxrpc_epoch;extern atomic_t rxrpc_debug_id;extern struct workqueue_struct *rxrpc_workqueue; +extern struct rxrpc_transport *rxrpc_name_to_transport (struct rxrpc_sock *, +struct sockaddr *, +int ,int ,gfp_t ); +/* * ar-accept.c */
@@ -502,14 +506,14 @@ extern rwlock_t rxrpc_call_lock;struct rxrpc_call *rxrpc_find_call_hash (struct rxrpc_host_header *,void *,sa_family_t ,const void *); -struct rxrpc_call *rxrpc_get_client_call (struct rxrpc_sock *, +struct rxrpc_call *rxrpc_find_call_by_user_ID (struct rxrpc_sock *,unsigned long ); +struct rxrpc_call *rxrpc_new_client_call (struct rxrpc_sock *,struct rxrpc_transport *,struct rxrpc_conn_bundle *, -unsigned long ,int ,gfp_t ); +unsigned long ,gfp_t );struct rxrpc_call *rxrpc_incoming_call (struct rxrpc_sock *,struct rxrpc_connection *,struct rxrpc_host_header *); -struct rxrpc_call *rxrpc_find_server_call (struct rxrpc_sock *,unsigned long );void rxrpc_release_call (struct rxrpc_call *);void rxrpc_release_calls_on_socket (struct rxrpc_sock *);void __rxrpc_put_call (struct rxrpc_call *);
@@ -581,9 +585,7 @@ int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,extern unsigned int rxrpc_resend_timeout;int rxrpc_send_packet (struct rxrpc_transport *,struct sk_buff *); -int rxrpc_client_sendmsg (struct rxrpc_sock *,struct rxrpc_transport *, -struct msghdr *,size_t ); -int rxrpc_server_sendmsg (struct rxrpc_sock *,struct msghdr *,size_t ); +int rxrpc_do_sendmsg (struct rxrpc_sock *,struct msghdr *,size_t );/* * ar-peer.c
net/rxrpc/ar-output.c +87 -99
256 lines not on this page · raw message