Skip to content

Commit 0b9bb32

Browse files
committed
rxrpc: Split out the call state changing functions into their own file
Split out the functions that change the state of an rxrpc call into their own file. The idea being to remove anything to do with changing the state of a call directly from the rxrpc sendmsg() and recvmsg() paths and have all that done in the I/O thread only, with the ultimate aim of removing the state lock entirely. Moving the code out of sendmsg.c and recvmsg.c makes that easier to manage. Signed-off-by: David Howells <[email protected]> cc: Marc Dionne <[email protected]> cc: [email protected]
1 parent 1bab27a commit 0b9bb32

File tree

4 files changed

+108
-89
lines changed

4 files changed

+108
-89
lines changed

net/rxrpc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rxrpc-y := \
1010
call_accept.o \
1111
call_event.o \
1212
call_object.o \
13+
call_state.o \
1314
conn_client.o \
1415
conn_event.o \
1516
conn_object.o \

net/rxrpc/ar-internal.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,24 @@ static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
885885
return !rxrpc_is_service_call(call);
886886
}
887887

888+
/*
889+
* call_state.c
890+
*/
891+
bool __rxrpc_set_call_completion(struct rxrpc_call *call,
892+
enum rxrpc_call_completion compl,
893+
u32 abort_code,
894+
int error);
895+
bool rxrpc_set_call_completion(struct rxrpc_call *call,
896+
enum rxrpc_call_completion compl,
897+
u32 abort_code,
898+
int error);
899+
bool __rxrpc_call_completed(struct rxrpc_call *call);
900+
bool rxrpc_call_completed(struct rxrpc_call *call);
901+
bool __rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
902+
u32 abort_code, int error, enum rxrpc_abort_reason why);
903+
bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
904+
u32 abort_code, int error, enum rxrpc_abort_reason why);
905+
888906
/*
889907
* conn_client.c
890908
*/
@@ -1116,14 +1134,6 @@ extern const struct seq_operations rxrpc_local_seq_ops;
11161134
* recvmsg.c
11171135
*/
11181136
void rxrpc_notify_socket(struct rxrpc_call *);
1119-
bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
1120-
bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
1121-
bool __rxrpc_call_completed(struct rxrpc_call *);
1122-
bool rxrpc_call_completed(struct rxrpc_call *);
1123-
bool __rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
1124-
u32 abort_code, int error, enum rxrpc_abort_reason why);
1125-
bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
1126-
u32 abort_code, int error, enum rxrpc_abort_reason why);
11271137
int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
11281138

11291139
/*

net/rxrpc/call_state.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/* Call state changing functions.
3+
*
4+
* Copyright (C) 2022 Red Hat, Inc. All Rights Reserved.
5+
* Written by David Howells ([email protected])
6+
*/
7+
8+
#include "ar-internal.h"
9+
10+
/*
11+
* Transition a call to the complete state.
12+
*/
13+
bool __rxrpc_set_call_completion(struct rxrpc_call *call,
14+
enum rxrpc_call_completion compl,
15+
u32 abort_code,
16+
int error)
17+
{
18+
if (call->state < RXRPC_CALL_COMPLETE) {
19+
call->abort_code = abort_code;
20+
call->error = error;
21+
call->completion = compl;
22+
call->state = RXRPC_CALL_COMPLETE;
23+
trace_rxrpc_call_complete(call);
24+
wake_up(&call->waitq);
25+
rxrpc_notify_socket(call);
26+
return true;
27+
}
28+
return false;
29+
}
30+
31+
bool rxrpc_set_call_completion(struct rxrpc_call *call,
32+
enum rxrpc_call_completion compl,
33+
u32 abort_code,
34+
int error)
35+
{
36+
bool ret = false;
37+
38+
if (call->state < RXRPC_CALL_COMPLETE) {
39+
write_lock(&call->state_lock);
40+
ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
41+
write_unlock(&call->state_lock);
42+
}
43+
return ret;
44+
}
45+
46+
/*
47+
* Record that a call successfully completed.
48+
*/
49+
bool __rxrpc_call_completed(struct rxrpc_call *call)
50+
{
51+
return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
52+
}
53+
54+
bool rxrpc_call_completed(struct rxrpc_call *call)
55+
{
56+
bool ret = false;
57+
58+
if (call->state < RXRPC_CALL_COMPLETE) {
59+
write_lock(&call->state_lock);
60+
ret = __rxrpc_call_completed(call);
61+
write_unlock(&call->state_lock);
62+
}
63+
return ret;
64+
}
65+
66+
/*
67+
* Record that a call is locally aborted.
68+
*/
69+
bool __rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
70+
u32 abort_code, int error, enum rxrpc_abort_reason why)
71+
{
72+
trace_rxrpc_abort(call->debug_id, why, call->cid, call->call_id, seq,
73+
abort_code, error);
74+
return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
75+
abort_code, error);
76+
}
77+
78+
bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
79+
u32 abort_code, int error, enum rxrpc_abort_reason why)
80+
{
81+
bool ret;
82+
83+
write_lock(&call->state_lock);
84+
ret = __rxrpc_abort_call(call, seq, abort_code, error, why);
85+
write_unlock(&call->state_lock);
86+
if (ret && test_bit(RXRPC_CALL_EXPOSED, &call->flags))
87+
rxrpc_send_abort_packet(call);
88+
return ret;
89+
}

net/rxrpc/recvmsg.c

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -58,87 +58,6 @@ void rxrpc_notify_socket(struct rxrpc_call *call)
5858
_leave("");
5959
}
6060

61-
/*
62-
* Transition a call to the complete state.
63-
*/
64-
bool __rxrpc_set_call_completion(struct rxrpc_call *call,
65-
enum rxrpc_call_completion compl,
66-
u32 abort_code,
67-
int error)
68-
{
69-
if (call->state < RXRPC_CALL_COMPLETE) {
70-
call->abort_code = abort_code;
71-
call->error = error;
72-
call->completion = compl;
73-
call->state = RXRPC_CALL_COMPLETE;
74-
trace_rxrpc_call_complete(call);
75-
wake_up(&call->waitq);
76-
rxrpc_notify_socket(call);
77-
return true;
78-
}
79-
return false;
80-
}
81-
82-
bool rxrpc_set_call_completion(struct rxrpc_call *call,
83-
enum rxrpc_call_completion compl,
84-
u32 abort_code,
85-
int error)
86-
{
87-
bool ret = false;
88-
89-
if (call->state < RXRPC_CALL_COMPLETE) {
90-
write_lock(&call->state_lock);
91-
ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
92-
write_unlock(&call->state_lock);
93-
}
94-
return ret;
95-
}
96-
97-
/*
98-
* Record that a call successfully completed.
99-
*/
100-
bool __rxrpc_call_completed(struct rxrpc_call *call)
101-
{
102-
return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
103-
}
104-
105-
bool rxrpc_call_completed(struct rxrpc_call *call)
106-
{
107-
bool ret = false;
108-
109-
if (call->state < RXRPC_CALL_COMPLETE) {
110-
write_lock(&call->state_lock);
111-
ret = __rxrpc_call_completed(call);
112-
write_unlock(&call->state_lock);
113-
}
114-
return ret;
115-
}
116-
117-
/*
118-
* Record that a call is locally aborted.
119-
*/
120-
bool __rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
121-
u32 abort_code, int error, enum rxrpc_abort_reason why)
122-
{
123-
trace_rxrpc_abort(call->debug_id, why, call->cid, call->call_id, seq,
124-
abort_code, error);
125-
return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
126-
abort_code, error);
127-
}
128-
129-
bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
130-
u32 abort_code, int error, enum rxrpc_abort_reason why)
131-
{
132-
bool ret;
133-
134-
write_lock(&call->state_lock);
135-
ret = __rxrpc_abort_call(call, seq, abort_code, error, why);
136-
write_unlock(&call->state_lock);
137-
if (ret && test_bit(RXRPC_CALL_EXPOSED, &call->flags))
138-
rxrpc_send_abort_packet(call);
139-
return ret;
140-
}
141-
14261
/*
14362
* Pass a call terminating message to userspace.
14463
*/

0 commit comments

Comments
 (0)