2019-05-21 01:08:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-10-20 07:57:59 +08:00
|
|
|
/* AFS vlserver probing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include "afs_fs.h"
|
|
|
|
#include "internal.h"
|
|
|
|
#include "protocol_yfs.h"
|
|
|
|
|
2020-08-19 22:27:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle the completion of a set of probes.
|
|
|
|
*/
|
|
|
|
static void afs_finished_vl_probe(struct afs_vlserver *server)
|
2018-10-20 07:57:59 +08:00
|
|
|
{
|
2020-08-19 22:27:17 +08:00
|
|
|
if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)) {
|
|
|
|
server->rtt = UINT_MAX;
|
|
|
|
clear_bit(AFS_VLSERVER_FL_RESPONDING, &server->flags);
|
|
|
|
}
|
2018-10-20 07:57:59 +08:00
|
|
|
|
|
|
|
clear_bit_unlock(AFS_VLSERVER_FL_PROBING, &server->flags);
|
|
|
|
wake_up_bit(&server->flags, AFS_VLSERVER_FL_PROBING);
|
2020-08-19 22:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle the completion of a probe RPC call.
|
|
|
|
*/
|
|
|
|
static void afs_done_one_vl_probe(struct afs_vlserver *server, bool wake_up)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&server->probe_outstanding)) {
|
|
|
|
afs_finished_vl_probe(server);
|
|
|
|
wake_up = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wake_up)
|
|
|
|
wake_up_all(&server->probe_wq);
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the result of probing a vlserver. This is called after successful
|
|
|
|
* or failed delivery of an VL.GetCapabilities operation.
|
|
|
|
*/
|
|
|
|
void afs_vlserver_probe_result(struct afs_call *call)
|
|
|
|
{
|
|
|
|
struct afs_addr_list *alist = call->alist;
|
2019-05-10 05:22:50 +08:00
|
|
|
struct afs_vlserver *server = call->vlserver;
|
|
|
|
unsigned int server_index = call->server_index;
|
2020-05-11 21:54:34 +08:00
|
|
|
unsigned int rtt_us = 0;
|
2018-10-20 07:57:59 +08:00
|
|
|
unsigned int index = call->addr_ix;
|
|
|
|
bool have_result = false;
|
|
|
|
int ret = call->error;
|
|
|
|
|
|
|
|
_enter("%s,%u,%u,%d,%d", server->name, server_index, index, ret, call->abort_code);
|
|
|
|
|
|
|
|
spin_lock(&server->probe_lock);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
|
|
|
server->probe.error = 0;
|
|
|
|
goto responded;
|
|
|
|
case -ECONNABORTED:
|
2020-08-20 22:01:54 +08:00
|
|
|
if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)) {
|
2018-10-20 07:57:59 +08:00
|
|
|
server->probe.abort_code = call->abort_code;
|
|
|
|
server->probe.error = ret;
|
|
|
|
}
|
|
|
|
goto responded;
|
|
|
|
case -ENOMEM:
|
|
|
|
case -ENONET:
|
2020-08-19 22:27:17 +08:00
|
|
|
case -EKEYEXPIRED:
|
|
|
|
case -EKEYREVOKED:
|
|
|
|
case -EKEYREJECTED:
|
2020-08-20 22:01:54 +08:00
|
|
|
server->probe.flags |= AFS_VLSERVER_PROBE_LOCAL_FAILURE;
|
2020-08-19 22:27:17 +08:00
|
|
|
if (server->probe.error == 0)
|
|
|
|
server->probe.error = ret;
|
|
|
|
trace_afs_io_error(call->debug_id, ret, afs_io_error_vl_probe_fail);
|
2018-10-20 07:57:59 +08:00
|
|
|
goto out;
|
|
|
|
case -ECONNRESET: /* Responded, but call expired. */
|
2018-11-14 07:20:28 +08:00
|
|
|
case -ERFKILL:
|
|
|
|
case -EADDRNOTAVAIL:
|
2018-10-20 07:57:59 +08:00
|
|
|
case -ENETUNREACH:
|
|
|
|
case -EHOSTUNREACH:
|
2018-11-14 07:20:28 +08:00
|
|
|
case -EHOSTDOWN:
|
2018-10-20 07:57:59 +08:00
|
|
|
case -ECONNREFUSED:
|
|
|
|
case -ETIMEDOUT:
|
|
|
|
case -ETIME:
|
|
|
|
default:
|
|
|
|
clear_bit(index, &alist->responded);
|
|
|
|
set_bit(index, &alist->failed);
|
2020-08-20 22:01:54 +08:00
|
|
|
if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED) &&
|
2018-10-20 07:57:59 +08:00
|
|
|
(server->probe.error == 0 ||
|
|
|
|
server->probe.error == -ETIMEDOUT ||
|
|
|
|
server->probe.error == -ETIME))
|
|
|
|
server->probe.error = ret;
|
2020-08-19 22:27:17 +08:00
|
|
|
trace_afs_io_error(call->debug_id, ret, afs_io_error_vl_probe_fail);
|
2018-10-20 07:57:59 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
responded:
|
|
|
|
set_bit(index, &alist->responded);
|
|
|
|
clear_bit(index, &alist->failed);
|
|
|
|
|
|
|
|
if (call->service_id == YFS_VL_SERVICE) {
|
2020-08-20 22:01:54 +08:00
|
|
|
server->probe.flags |= AFS_VLSERVER_PROBE_IS_YFS;
|
2018-10-20 07:57:59 +08:00
|
|
|
set_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags);
|
|
|
|
alist->addrs[index].srx_service = call->service_id;
|
|
|
|
} else {
|
2020-08-20 22:01:54 +08:00
|
|
|
server->probe.flags |= AFS_VLSERVER_PROBE_NOT_YFS;
|
|
|
|
if (!(server->probe.flags & AFS_VLSERVER_PROBE_IS_YFS)) {
|
2018-10-20 07:57:59 +08:00
|
|
|
clear_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags);
|
|
|
|
alist->addrs[index].srx_service = call->service_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 22:13:00 +08:00
|
|
|
if (rxrpc_kernel_get_srtt(call->net->socket, call->rxcall, &rtt_us) &&
|
|
|
|
rtt_us < server->probe.rtt) {
|
2020-05-11 21:54:34 +08:00
|
|
|
server->probe.rtt = rtt_us;
|
2020-08-19 22:27:17 +08:00
|
|
|
server->rtt = rtt_us;
|
2018-10-20 07:57:59 +08:00
|
|
|
alist->preferred = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
smp_wmb(); /* Set rtt before responded. */
|
2020-08-20 22:01:54 +08:00
|
|
|
server->probe.flags |= AFS_VLSERVER_PROBE_RESPONDED;
|
2018-10-20 07:57:59 +08:00
|
|
|
set_bit(AFS_VLSERVER_FL_PROBED, &server->flags);
|
2020-08-19 22:27:17 +08:00
|
|
|
set_bit(AFS_VLSERVER_FL_RESPONDING, &server->flags);
|
|
|
|
have_result = true;
|
2018-10-20 07:57:59 +08:00
|
|
|
out:
|
|
|
|
spin_unlock(&server->probe_lock);
|
|
|
|
|
|
|
|
_debug("probe [%u][%u] %pISpc rtt=%u ret=%d",
|
2020-05-11 21:54:34 +08:00
|
|
|
server_index, index, &alist->addrs[index].transport, rtt_us, ret);
|
2018-10-20 07:57:59 +08:00
|
|
|
|
2020-08-19 22:27:17 +08:00
|
|
|
afs_done_one_vl_probe(server, have_result);
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe all of a vlserver's addresses to find out the best route and to
|
|
|
|
* query its capabilities.
|
|
|
|
*/
|
2018-11-14 07:20:28 +08:00
|
|
|
static bool afs_do_probe_vlserver(struct afs_net *net,
|
|
|
|
struct afs_vlserver *server,
|
|
|
|
struct key *key,
|
|
|
|
unsigned int server_index,
|
|
|
|
struct afs_error *_e)
|
2018-10-20 07:57:59 +08:00
|
|
|
{
|
|
|
|
struct afs_addr_cursor ac = {
|
|
|
|
.index = 0,
|
|
|
|
};
|
2019-04-25 21:26:50 +08:00
|
|
|
struct afs_call *call;
|
2018-11-14 07:20:28 +08:00
|
|
|
bool in_progress = false;
|
2018-10-20 07:57:59 +08:00
|
|
|
|
|
|
|
_enter("%s", server->name);
|
|
|
|
|
|
|
|
read_lock(&server->lock);
|
|
|
|
ac.alist = rcu_dereference_protected(server->addresses,
|
|
|
|
lockdep_is_held(&server->lock));
|
|
|
|
read_unlock(&server->lock);
|
|
|
|
|
|
|
|
atomic_set(&server->probe_outstanding, ac.alist->nr_addrs);
|
|
|
|
memset(&server->probe, 0, sizeof(server->probe));
|
|
|
|
server->probe.rtt = UINT_MAX;
|
|
|
|
|
|
|
|
for (ac.index = 0; ac.index < ac.alist->nr_addrs; ac.index++) {
|
2019-04-25 21:26:50 +08:00
|
|
|
call = afs_vl_get_capabilities(net, &ac, key, server,
|
|
|
|
server_index);
|
|
|
|
if (!IS_ERR(call)) {
|
|
|
|
afs_put_call(call);
|
2018-11-14 07:20:28 +08:00
|
|
|
in_progress = true;
|
2019-04-25 21:26:50 +08:00
|
|
|
} else {
|
|
|
|
afs_prioritise_error(_e, PTR_ERR(call), ac.abort_code);
|
2020-08-19 22:27:17 +08:00
|
|
|
afs_done_one_vl_probe(server, false);
|
2019-04-25 21:26:50 +08:00
|
|
|
}
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
2018-11-14 07:20:28 +08:00
|
|
|
return in_progress;
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send off probes to all unprobed servers.
|
|
|
|
*/
|
|
|
|
int afs_send_vl_probes(struct afs_net *net, struct key *key,
|
|
|
|
struct afs_vlserver_list *vllist)
|
|
|
|
{
|
|
|
|
struct afs_vlserver *server;
|
2018-11-14 07:20:28 +08:00
|
|
|
struct afs_error e;
|
|
|
|
bool in_progress = false;
|
|
|
|
int i;
|
2018-10-20 07:57:59 +08:00
|
|
|
|
2018-11-14 07:20:28 +08:00
|
|
|
e.error = 0;
|
|
|
|
e.responded = false;
|
2018-10-20 07:57:59 +08:00
|
|
|
for (i = 0; i < vllist->nr_servers; i++) {
|
|
|
|
server = vllist->servers[i].server;
|
|
|
|
if (test_bit(AFS_VLSERVER_FL_PROBED, &server->flags))
|
|
|
|
continue;
|
|
|
|
|
2018-11-14 07:20:28 +08:00
|
|
|
if (!test_and_set_bit_lock(AFS_VLSERVER_FL_PROBING, &server->flags) &&
|
|
|
|
afs_do_probe_vlserver(net, server, key, i, &e))
|
|
|
|
in_progress = true;
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
2018-11-14 07:20:28 +08:00
|
|
|
return in_progress ? 0 : e.error;
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the first as-yet untried server to respond.
|
|
|
|
*/
|
|
|
|
int afs_wait_for_vl_probes(struct afs_vlserver_list *vllist,
|
|
|
|
unsigned long untried)
|
|
|
|
{
|
|
|
|
struct wait_queue_entry *waits;
|
|
|
|
struct afs_vlserver *server;
|
2020-08-19 22:27:17 +08:00
|
|
|
unsigned int rtt = UINT_MAX, rtt_s;
|
2018-10-20 07:57:59 +08:00
|
|
|
bool have_responders = false;
|
|
|
|
int pref = -1, i;
|
|
|
|
|
|
|
|
_enter("%u,%lx", vllist->nr_servers, untried);
|
|
|
|
|
|
|
|
/* Only wait for servers that have a probe outstanding. */
|
|
|
|
for (i = 0; i < vllist->nr_servers; i++) {
|
|
|
|
if (test_bit(i, &untried)) {
|
|
|
|
server = vllist->servers[i].server;
|
|
|
|
if (!test_bit(AFS_VLSERVER_FL_PROBING, &server->flags))
|
|
|
|
__clear_bit(i, &untried);
|
2020-08-20 22:01:54 +08:00
|
|
|
if (server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)
|
2018-10-20 07:57:59 +08:00
|
|
|
have_responders = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (have_responders || !untried)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
waits = kmalloc(array_size(vllist->nr_servers, sizeof(*waits)), GFP_KERNEL);
|
|
|
|
if (!waits)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < vllist->nr_servers; i++) {
|
|
|
|
if (test_bit(i, &untried)) {
|
|
|
|
server = vllist->servers[i].server;
|
|
|
|
init_waitqueue_entry(&waits[i], current);
|
|
|
|
add_wait_queue(&server->probe_wq, &waits[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
bool still_probing = false;
|
|
|
|
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
for (i = 0; i < vllist->nr_servers; i++) {
|
|
|
|
if (test_bit(i, &untried)) {
|
|
|
|
server = vllist->servers[i].server;
|
2020-08-20 22:01:54 +08:00
|
|
|
if (server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)
|
2018-10-20 07:57:59 +08:00
|
|
|
goto stop;
|
|
|
|
if (test_bit(AFS_VLSERVER_FL_PROBING, &server->flags))
|
|
|
|
still_probing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-04 07:28:58 +08:00
|
|
|
if (!still_probing || signal_pending(current))
|
2018-10-20 07:57:59 +08:00
|
|
|
goto stop;
|
|
|
|
schedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
stop:
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
|
|
|
|
for (i = 0; i < vllist->nr_servers; i++) {
|
|
|
|
if (test_bit(i, &untried)) {
|
|
|
|
server = vllist->servers[i].server;
|
2020-08-19 22:27:17 +08:00
|
|
|
rtt_s = READ_ONCE(server->rtt);
|
|
|
|
if (test_bit(AFS_VLSERVER_FL_RESPONDING, &server->flags) &&
|
|
|
|
rtt_s < rtt) {
|
2018-10-20 07:57:59 +08:00
|
|
|
pref = i;
|
2020-08-19 22:27:17 +08:00
|
|
|
rtt = rtt_s;
|
2018-10-20 07:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
remove_wait_queue(&server->probe_wq, &waits[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(waits);
|
|
|
|
|
|
|
|
if (pref == -1 && signal_pending(current))
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
|
|
|
if (pref >= 0)
|
|
|
|
vllist->preferred = pref;
|
|
|
|
|
|
|
|
_leave(" = 0 [%u]", pref);
|
|
|
|
return 0;
|
|
|
|
}
|