Skip to content

Commit

Permalink
afs: Use peer + service_id as call address
Browse files Browse the repository at this point in the history
Use the rxrpc_peer plus the service ID as the call address instead of
passing in a sockaddr_srx down to rxrpc.  The peer record is obtained by
using rxrpc_kernel_get_peer().  This avoids the need to repeatedly look up
the peer and allows rxrpc to hold on to resources for it.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
  • Loading branch information
David Howells committed Dec 24, 2023
1 parent 905b861 commit e38f299
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 32 deletions.
10 changes: 3 additions & 7 deletions fs/afs/addr_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_ali
/*
* Allocate an address list.
*/
struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id)
struct afs_addr_list *afs_alloc_addrlist(unsigned int nr)
{
struct afs_addr_list *alist;
unsigned int i;
static atomic_t debug_id;

_enter("%u,%u", nr, service_id);
_enter("%u", nr);

if (nr > AFS_MAX_ADDRESSES)
nr = AFS_MAX_ADDRESSES;
Expand All @@ -74,9 +73,6 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id)
refcount_set(&alist->usage, 1);
alist->max_addrs = nr;
alist->debug_id = atomic_inc_return(&debug_id);

for (i = 0; i < nr; i++)
alist->addrs[i].service_id = service_id;
trace_afs_alist(alist->debug_id, 1, afs_alist_trace_alloc);
return alist;
}
Expand Down Expand Up @@ -150,7 +146,7 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *net,
if (!vllist->servers[0].server)
goto error_vl;

alist = afs_alloc_addrlist(nr, service);
alist = afs_alloc_addrlist(nr);
if (!alist)
goto error;

Expand Down
4 changes: 2 additions & 2 deletions fs/afs/fs_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ void afs_fileserver_probe_result(struct afs_call *call)
if (call->service_id == YFS_FS_SERVICE) {
server->probe.is_yfs = true;
set_bit(AFS_SERVER_FL_IS_YFS, &server->flags);
addr->service_id = call->service_id;
server->service_id = call->service_id;
} else {
server->probe.not_yfs = true;
if (!server->probe.is_yfs) {
clear_bit(AFS_SERVER_FL_IS_YFS, &server->flags);
addr->service_id = call->service_id;
server->service_id = call->service_id;
}
cap0 = ntohl(call->tmp);
if (cap0 & AFS3_VICED_CAPABILITY_64BITFILES)
Expand Down
14 changes: 9 additions & 5 deletions fs/afs/fsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,9 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net,
if (!call)
return -ENOMEM;

call->key = key;
call->key = key;
call->peer = rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer);
call->service_id = server->service_id;

/* marshall the parameters */
bp = call->request;
Expand Down Expand Up @@ -1722,10 +1724,12 @@ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
if (!call)
return false;

call->key = key;
call->server = afs_use_server(server, afs_server_trace_get_caps);
call->upgrade = true;
call->async = true;
call->key = key;
call->server = afs_use_server(server, afs_server_trace_get_caps);
call->peer = rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer);
call->service_id = server->service_id;
call->upgrade = true;
call->async = true;
call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;

/* marshall the parameters */
Expand Down
18 changes: 11 additions & 7 deletions fs/afs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ enum afs_call_state {

struct afs_address {
struct rxrpc_peer *peer;
u16 service_id;
short last_error; /* Last error from this address */
};

Expand Down Expand Up @@ -108,6 +107,7 @@ struct afs_call {
struct work_struct async_work; /* async I/O processor */
struct work_struct work; /* actual work processor */
struct rxrpc_call *rxcall; /* RxRPC call handle */
struct rxrpc_peer *peer; /* Remote endpoint */
struct key *key; /* security for this call */
struct afs_net *net; /* The network namespace */
struct afs_server *server; /* The fileserver record if fs op (pins ref) */
Expand Down Expand Up @@ -435,6 +435,7 @@ struct afs_vlserver {
#define AFS_VLSERVER_PROBE_LOCAL_FAILURE 0x08 /* A local failure prevented a probe */
} probe;

u16 service_id; /* Service ID we're using */
u16 port;
u16 name_len; /* Length of name */
char name[]; /* Server name, case-flattened */
Expand Down Expand Up @@ -527,6 +528,7 @@ struct afs_server {
refcount_t ref; /* Object refcount */
atomic_t active; /* Active user count */
u32 addr_version; /* Address list version */
u16 service_id; /* Service ID we're using. */
unsigned int rtt; /* Server's current RTT in uS */
unsigned int debug_id; /* Debugging ID for traces */

Expand Down Expand Up @@ -971,7 +973,7 @@ static inline bool afs_is_folio_dirty_mmapped(unsigned long priv)
* addr_list.c
*/
struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id);
extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr);
extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
const char *, size_t, char,
Expand Down Expand Up @@ -1318,11 +1320,13 @@ extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
gfp_t gfp)
{
op->call = call;
op->type = call->type;
call->op = op;
call->key = op->key;
call->intr = !(op->flags & AFS_OPERATION_UNINTR);
op->call = call;
op->type = call->type;
call->op = op;
call->key = op->key;
call->intr = !(op->flags & AFS_OPERATION_UNINTR);
call->peer = rxrpc_kernel_get_peer(op->ac.alist->addrs[op->ac.index].peer);
call->service_id = op->server->service_id;
afs_make_call(&op->ac, call, gfp);
}

Expand Down
12 changes: 6 additions & 6 deletions fs/afs/rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ void afs_put_call(struct afs_call *call)
ASSERT(!work_pending(&call->async_work));
ASSERT(call->type->name != NULL);

rxrpc_kernel_put_peer(call->peer);

if (call->rxcall) {
rxrpc_kernel_shutdown_call(net->socket, call->rxcall);
rxrpc_kernel_put_call(net->socket, call->rxcall);
Expand Down Expand Up @@ -296,16 +298,14 @@ static void afs_notify_end_request_tx(struct sock *sock,
*/
void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
{
struct afs_address *addr = &ac->alist->addrs[ac->index];
struct rxrpc_peer *peer = addr->peer;
struct rxrpc_call *rxcall;
struct msghdr msg;
struct kvec iov[1];
size_t len;
s64 tx_total_len;
int ret;

_enter(",{%pISp},", rxrpc_kernel_remote_addr(addr->peer));
_enter(",{%pISp+%u},", rxrpc_kernel_remote_addr(call->peer), call->service_id);

ASSERT(call->type != NULL);
ASSERT(call->type->name != NULL);
Expand Down Expand Up @@ -334,15 +334,15 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
}

/* create a call */
rxcall = rxrpc_kernel_begin_call(call->net->socket, peer, call->key,
rxcall = rxrpc_kernel_begin_call(call->net->socket, call->peer, call->key,
(unsigned long)call,
tx_total_len,
call->max_lifespan,
gfp,
(call->async ?
afs_wake_up_async_call :
afs_wake_up_call_waiter),
addr->service_id,
call->service_id,
call->upgrade,
(call->intr ? RXRPC_PREINTERRUPTIBLE :
RXRPC_UNINTERRUPTIBLE),
Expand Down Expand Up @@ -462,7 +462,7 @@ static void afs_log_error(struct afs_call *call, s32 remote_abort)
max = m + 1;
pr_notice("kAFS: Peer reported %s failure on %s [%pISp]\n",
msg, call->type->name,
rxrpc_kernel_remote_addr(call->alist->addrs[call->addr_ix].peer));
rxrpc_kernel_remote_addr(call->peer));
}
}

Expand Down
1 change: 1 addition & 0 deletions fs/afs/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ static struct afs_server *afs_alloc_server(struct afs_cell *cell,
spin_lock_init(&server->probe_lock);
server->cell = cell;
server->rtt = UINT_MAX;
server->service_id = FS_SERVICE;

afs_inc_servers_outstanding(net);
trace_afs_server(server->debug_id, 1, 1, afs_server_trace_alloc);
Expand Down
3 changes: 2 additions & 1 deletion fs/afs/vl_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct afs_vlserver *afs_alloc_vlserver(const char *name, size_t name_len,
spin_lock_init(&vlserver->probe_lock);
vlserver->rtt = UINT_MAX;
vlserver->name_len = name_len;
vlserver->service_id = VL_SERVICE;
vlserver->port = port;
memcpy(vlserver->name, name, name_len);
}
Expand Down Expand Up @@ -92,7 +93,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net,
const u8 *b = *_b;
int ret = -EINVAL;

alist = afs_alloc_addrlist(nr_addrs, VL_SERVICE);
alist = afs_alloc_addrlist(nr_addrs);
if (!alist)
return ERR_PTR(-ENOMEM);
if (nr_addrs == 0)
Expand Down
4 changes: 2 additions & 2 deletions fs/afs/vl_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ void afs_vlserver_probe_result(struct afs_call *call)
if (call->service_id == YFS_VL_SERVICE) {
server->probe.flags |= AFS_VLSERVER_PROBE_IS_YFS;
set_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags);
addr->service_id = call->service_id;
server->service_id = call->service_id;
} else {
server->probe.flags |= AFS_VLSERVER_PROBE_NOT_YFS;
if (!(server->probe.flags & AFS_VLSERVER_PROBE_IS_YFS)) {
clear_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags);
addr->service_id = call->service_id;
server->service_id = call->service_id;
}
}

Expand Down
14 changes: 12 additions & 2 deletions fs/afs/vlclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
call->key = vc->key;
call->ret_vldb = entry;
call->max_lifespan = AFS_VL_MAX_LIFESPAN;
call->peer = rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].peer);
call->service_id = vc->server->service_id;

/* Marshall the parameters */
bp = call->request;
Expand Down Expand Up @@ -211,7 +213,7 @@ static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
count = ntohl(*bp);

nentries = min(nentries, count);
alist = afs_alloc_addrlist(nentries, FS_SERVICE);
alist = afs_alloc_addrlist(nentries);
if (!alist)
return -ENOMEM;
alist->version = uniquifier;
Expand Down Expand Up @@ -288,6 +290,8 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
call->key = vc->key;
call->ret_alist = NULL;
call->max_lifespan = AFS_VL_MAX_LIFESPAN;
call->peer = rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].peer);
call->service_id = vc->server->service_id;

/* Marshall the parameters */
bp = call->request;
Expand Down Expand Up @@ -407,6 +411,8 @@ struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
call->key = key;
call->vlserver = afs_get_vlserver(server);
call->server_index = server_index;
call->peer = rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer);
call->service_id = server->service_id;
call->upgrade = true;
call->async = true;
call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
Expand Down Expand Up @@ -462,7 +468,7 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
if (call->count > YFS_MAXENDPOINTS)
return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num);

alist = afs_alloc_addrlist(call->count, FS_SERVICE);
alist = afs_alloc_addrlist(call->count);
if (!alist)
return -ENOMEM;
alist->version = uniquifier;
Expand Down Expand Up @@ -652,6 +658,8 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
call->key = vc->key;
call->ret_alist = NULL;
call->max_lifespan = AFS_VL_MAX_LIFESPAN;
call->peer = rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].peer);
call->service_id = vc->server->service_id;

/* Marshall the parameters */
bp = call->request;
Expand Down Expand Up @@ -769,6 +777,8 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc)
call->key = vc->key;
call->ret_str = NULL;
call->max_lifespan = AFS_VL_MAX_LIFESPAN;
call->peer = rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].peer);
call->service_id = vc->server->service_id;

/* marshall the parameters */
bp = call->request;
Expand Down

0 comments on commit e38f299

Please sign in to comment.