Skip to content

Commit

Permalink
afs: Fold the afs_addr_cursor struct in
Browse files Browse the repository at this point in the history
Fold the afs_addr_cursor struct into the afs_operation struct and the
afs_vl_cursor struct and fold its operations into their callers also.

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 e38f299 commit 98f9fda
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 214 deletions.
53 changes: 0 additions & 53 deletions fs/afs/addr_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,56 +375,3 @@ int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *alist,
alist->nr_addrs++;
return 0;
}

/*
* Get an address to try.
*/
bool afs_iterate_addresses(struct afs_addr_cursor *ac)
{
unsigned long set, failed;
int index;

if (!ac->alist)
return false;

set = ac->alist->responded;
failed = ac->alist->probe_failed;
_enter("%lx-%lx-%lx,%d", set, failed, ac->tried, ac->index);

ac->nr_iterations++;

set &= ~(failed | ac->tried);

if (!set)
return false;

index = READ_ONCE(ac->alist->preferred);
if (test_bit(index, &set))
goto selected;

index = __ffs(set);

selected:
ac->index = index;
set_bit(index, &ac->tried);
ac->call_responded = false;
return true;
}

/*
* Release an address list cursor.
*/
void afs_end_cursor(struct afs_addr_cursor *ac)
{
struct afs_addr_list *alist;

alist = ac->alist;
if (alist) {
if (ac->call_responded &&
ac->index != alist->preferred &&
test_bit(ac->alist->preferred, &ac->tried))
WRITE_ONCE(alist->preferred, ac->index);
afs_put_addrlist(alist, afs_alist_trace_put_end_cursor);
ac->alist = NULL;
}
}
21 changes: 17 additions & 4 deletions fs/afs/fs_operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void afs_wait_for_operation(struct afs_operation *op)
_enter("");

while (afs_select_fileserver(op)) {
op->call_responded = false;
op->call_error = 0;
op->call_abort_code = 0;
op->cb_s_break = op->server->cb_s_break;
Expand All @@ -191,17 +192,19 @@ void afs_wait_for_operation(struct afs_operation *op)
op->call_error = -ENOTSUPP;

if (op->call) {
afs_wait_for_call_to_complete(op->call, &op->ac);
afs_wait_for_call_to_complete(op->call);
op->call_abort_code = op->call->abort_code;
op->call_error = op->call->error;
op->call_responded = op->call->responded;
op->ac.call_responded = true;
WRITE_ONCE(op->ac.alist->addrs[op->ac.index].last_error,
WRITE_ONCE(op->alist->addrs[op->addr_index].last_error,
op->call_error);
afs_put_call(op->call);
}
}

if (op->call_responded)
set_bit(AFS_SERVER_FL_RESPONDING, &op->server->flags);

if (!afs_op_error(op)) {
_debug("success");
op->ops->success(op);
Expand All @@ -227,6 +230,7 @@ void afs_wait_for_operation(struct afs_operation *op)
*/
int afs_put_operation(struct afs_operation *op)
{
struct afs_addr_list *alist;
int i, ret = afs_op_error(op);

_enter("op=%08x,%d", op->debug_id, ret);
Expand All @@ -249,7 +253,16 @@ int afs_put_operation(struct afs_operation *op)
kfree(op->more_files);
}

afs_end_cursor(&op->ac);
alist = op->alist;
if (alist) {
if (op->call_responded &&
op->addr_index != alist->preferred &&
test_bit(alist->preferred, &op->addr_tried))
WRITE_ONCE(alist->preferred, op->addr_index);
afs_put_addrlist(alist, afs_alist_trace_put_operation);
op->alist = NULL;
}

afs_put_serverlist(op->net, op->server_list);
afs_put_volume(op->net, op->volume, afs_volume_trace_put_put_op);
key_put(op->key);
Expand Down
41 changes: 19 additions & 22 deletions fs/afs/fs_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ static void afs_done_one_fs_probe(struct afs_net *net, struct afs_server *server
*/
static void afs_fs_probe_not_done(struct afs_net *net,
struct afs_server *server,
struct afs_addr_cursor *ac)
struct afs_addr_list *alist,
int index)
{
struct afs_addr_list *alist = ac->alist;
unsigned int index = ac->index;

_enter("");

trace_afs_io_error(0, -ENOMEM, afs_io_error_fs_probe_fail);
Expand All @@ -100,10 +98,10 @@ static void afs_fs_probe_not_done(struct afs_net *net,
*/
void afs_fileserver_probe_result(struct afs_call *call)
{
struct afs_addr_list *alist = call->alist;
struct afs_address *addr = &alist->addrs[call->addr_ix];
struct afs_addr_list *alist = call->probe_alist;
struct afs_address *addr = &alist->addrs[call->probe_index];
struct afs_server *server = call->server;
unsigned int index = call->addr_ix;
unsigned int index = call->probe_index;
unsigned int rtt_us = 0, cap0;
int ret = call->error;

Expand Down Expand Up @@ -196,37 +194,36 @@ void afs_fileserver_probe_result(struct afs_call *call)
void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
struct key *key, bool all)
{
struct afs_addr_cursor ac = {
.index = 0,
};
struct afs_addr_list *alist;
unsigned int index;

_enter("%pU", &server->uuid);

read_lock(&server->fs_lock);
ac.alist = rcu_dereference_protected(server->addresses,
lockdep_is_held(&server->fs_lock));
afs_get_addrlist(ac.alist, afs_alist_trace_get_probe);
alist = rcu_dereference_protected(server->addresses,
lockdep_is_held(&server->fs_lock));
afs_get_addrlist(alist, afs_alist_trace_get_probe);
read_unlock(&server->fs_lock);

server->probed_at = jiffies;
atomic_set(&server->probe_outstanding, all ? ac.alist->nr_addrs : 1);
atomic_set(&server->probe_outstanding, all ? alist->nr_addrs : 1);
memset(&server->probe, 0, sizeof(server->probe));
server->probe.rtt = UINT_MAX;

ac.index = ac.alist->preferred;
if (ac.index < 0 || ac.index >= ac.alist->nr_addrs)
index = alist->preferred;
if (index < 0 || index >= alist->nr_addrs)
all = true;

if (all) {
for (ac.index = 0; ac.index < ac.alist->nr_addrs; ac.index++)
if (!afs_fs_get_capabilities(net, server, &ac, key))
afs_fs_probe_not_done(net, server, &ac);
for (index = 0; index < alist->nr_addrs; index++)
if (!afs_fs_get_capabilities(net, server, alist, index, key))
afs_fs_probe_not_done(net, server, alist, index);
} else {
if (!afs_fs_get_capabilities(net, server, &ac, key))
afs_fs_probe_not_done(net, server, &ac);
if (!afs_fs_get_capabilities(net, server, alist, index, key))
afs_fs_probe_not_done(net, server, alist, index);
}

afs_put_addrlist(ac.alist, afs_alist_trace_put_probe);
afs_put_addrlist(alist, afs_alist_trace_put_probe);
}

/*
Expand Down
31 changes: 20 additions & 11 deletions fs/afs/fsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1605,10 +1605,8 @@ static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
/*
* Flush all the callbacks we have on a server.
*/
int afs_fs_give_up_all_callbacks(struct afs_net *net,
struct afs_server *server,
struct afs_addr_cursor *ac,
struct key *key)
int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
struct afs_address *addr, struct key *key)
{
struct afs_call *call;
__be32 *bp;
Expand All @@ -1621,17 +1619,19 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net,
return -ENOMEM;

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

/* marshall the parameters */
bp = call->request;
*bp++ = htonl(FSGIVEUPALLCALLBACKS);

call->server = afs_use_server(server, afs_server_trace_give_up_cb);
afs_make_call(ac, call, GFP_NOFS);
afs_wait_for_call_to_complete(call, ac);
afs_make_call(call, GFP_NOFS);
afs_wait_for_call_to_complete(call);
ret = call->error;
if (call->responded)
set_bit(AFS_SERVER_FL_RESPONDING, &server->flags);
afs_put_call(call);
return ret;
}
Expand Down Expand Up @@ -1695,6 +1695,12 @@ static int afs_deliver_fs_get_capabilities(struct afs_call *call)
return 0;
}

static void afs_fs_get_capabilities_destructor(struct afs_call *call)
{
afs_put_addrlist(call->probe_alist, afs_alist_trace_put_getcaps);
afs_flat_call_destructor(call);
}

/*
* FS.GetCapabilities operation type
*/
Expand All @@ -1703,7 +1709,7 @@ static const struct afs_call_type afs_RXFSGetCapabilities = {
.op = afs_FS_GetCapabilities,
.deliver = afs_deliver_fs_get_capabilities,
.done = afs_fileserver_probe_result,
.destructor = afs_flat_call_destructor,
.destructor = afs_fs_get_capabilities_destructor,
};

/*
Expand All @@ -1713,7 +1719,8 @@ static const struct afs_call_type afs_RXFSGetCapabilities = {
* ->done() - otherwise we return false to indicate we didn't even try.
*/
bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
struct afs_addr_cursor *ac, struct key *key)
struct afs_addr_list *alist, unsigned int addr_index,
struct key *key)
{
struct afs_call *call;
__be32 *bp;
Expand All @@ -1726,7 +1733,9 @@ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,

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->peer = rxrpc_kernel_get_peer(alist->addrs[addr_index].peer);
call->probe_alist = afs_get_addrlist(alist, afs_alist_trace_get_getcaps);
call->probe_index = addr_index;
call->service_id = server->service_id;
call->upgrade = true;
call->async = true;
Expand All @@ -1737,7 +1746,7 @@ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
*bp++ = htonl(FSGETCAPABILITIES);

trace_afs_make_fs_call(call, NULL);
afs_make_call(ac, call, GFP_NOFS);
afs_make_call(call, GFP_NOFS);
afs_put_call(call);
return true;
}
Expand Down
Loading

0 comments on commit 98f9fda

Please sign in to comment.