^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* AFS vlserver probing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "afs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "protocol_yfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Handle the completion of a set of probes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static void afs_finished_vl_probe(struct afs_vlserver *server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) server->rtt = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) clear_bit(AFS_VLSERVER_FL_RESPONDING, &server->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) clear_bit_unlock(AFS_VLSERVER_FL_PROBING, &server->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) wake_up_bit(&server->flags, AFS_VLSERVER_FL_PROBING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Handle the completion of a probe RPC call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void afs_done_one_vl_probe(struct afs_vlserver *server, bool wake_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (atomic_dec_and_test(&server->probe_outstanding)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) afs_finished_vl_probe(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) wake_up = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (wake_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) wake_up_all(&server->probe_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Process the result of probing a vlserver. This is called after successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * or failed delivery of an VL.GetCapabilities operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void afs_vlserver_probe_result(struct afs_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct afs_addr_list *alist = call->alist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct afs_vlserver *server = call->vlserver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned int server_index = call->server_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned int rtt_us = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned int index = call->addr_ix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) bool have_result = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int ret = call->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) _enter("%s,%u,%u,%d,%d", server->name, server_index, index, ret, call->abort_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) spin_lock(&server->probe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) server->probe.error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto responded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) case -ECONNABORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) server->probe.abort_code = call->abort_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) server->probe.error = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) goto responded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) case -ENOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case -ENONET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) case -EKEYEXPIRED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) case -EKEYREVOKED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) case -EKEYREJECTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) server->probe.flags |= AFS_VLSERVER_PROBE_LOCAL_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (server->probe.error == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) server->probe.error = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) trace_afs_io_error(call->debug_id, ret, afs_io_error_vl_probe_fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) case -ECONNRESET: /* Responded, but call expired. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) case -ERFKILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) case -EADDRNOTAVAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) case -ENETUNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) case -EHOSTUNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) case -EHOSTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) case -ECONNREFUSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) case -ETIMEDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) case -ETIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) clear_bit(index, &alist->responded);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) set_bit(index, &alist->failed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) (server->probe.error == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) server->probe.error == -ETIMEDOUT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) server->probe.error == -ETIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) server->probe.error = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) trace_afs_io_error(call->debug_id, ret, afs_io_error_vl_probe_fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) responded:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) set_bit(index, &alist->responded);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) clear_bit(index, &alist->failed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (call->service_id == YFS_VL_SERVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) server->probe.flags |= AFS_VLSERVER_PROBE_IS_YFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) set_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) alist->addrs[index].srx_service = call->service_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) server->probe.flags |= AFS_VLSERVER_PROBE_NOT_YFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (!(server->probe.flags & AFS_VLSERVER_PROBE_IS_YFS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) clear_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) alist->addrs[index].srx_service = call->service_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (rxrpc_kernel_get_srtt(call->net->socket, call->rxcall, &rtt_us) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) rtt_us < server->probe.rtt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) server->probe.rtt = rtt_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) server->rtt = rtt_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) alist->preferred = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) smp_wmb(); /* Set rtt before responded. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) server->probe.flags |= AFS_VLSERVER_PROBE_RESPONDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) set_bit(AFS_VLSERVER_FL_PROBED, &server->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) set_bit(AFS_VLSERVER_FL_RESPONDING, &server->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) have_result = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) spin_unlock(&server->probe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) _debug("probe [%u][%u] %pISpc rtt=%u ret=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) server_index, index, &alist->addrs[index].transport, rtt_us, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) afs_done_one_vl_probe(server, have_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * Probe all of a vlserver's addresses to find out the best route and to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * query its capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static bool afs_do_probe_vlserver(struct afs_net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct afs_vlserver *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct key *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsigned int server_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct afs_error *_e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct afs_addr_cursor ac = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct afs_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) bool in_progress = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) _enter("%s", server->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) read_lock(&server->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ac.alist = rcu_dereference_protected(server->addresses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) lockdep_is_held(&server->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) read_unlock(&server->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) atomic_set(&server->probe_outstanding, ac.alist->nr_addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) memset(&server->probe, 0, sizeof(server->probe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) server->probe.rtt = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) for (ac.index = 0; ac.index < ac.alist->nr_addrs; ac.index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) call = afs_vl_get_capabilities(net, &ac, key, server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) server_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!IS_ERR(call)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) afs_put_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) in_progress = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) afs_prioritise_error(_e, PTR_ERR(call), ac.abort_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) afs_done_one_vl_probe(server, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return in_progress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * Send off probes to all unprobed servers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int afs_send_vl_probes(struct afs_net *net, struct key *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct afs_vlserver_list *vllist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct afs_vlserver *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct afs_error e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bool in_progress = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) e.error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) e.responded = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) for (i = 0; i < vllist->nr_servers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) server = vllist->servers[i].server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (test_bit(AFS_VLSERVER_FL_PROBED, &server->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!test_and_set_bit_lock(AFS_VLSERVER_FL_PROBING, &server->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) afs_do_probe_vlserver(net, server, key, i, &e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) in_progress = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return in_progress ? 0 : e.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * Wait for the first as-yet untried server to respond.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int afs_wait_for_vl_probes(struct afs_vlserver_list *vllist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) unsigned long untried)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct wait_queue_entry *waits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct afs_vlserver *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned int rtt = UINT_MAX, rtt_s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) bool have_responders = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int pref = -1, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) _enter("%u,%lx", vllist->nr_servers, untried);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Only wait for servers that have a probe outstanding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) for (i = 0; i < vllist->nr_servers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (test_bit(i, &untried)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) server = vllist->servers[i].server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (!test_bit(AFS_VLSERVER_FL_PROBING, &server->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) __clear_bit(i, &untried);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) have_responders = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (have_responders || !untried)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) waits = kmalloc(array_size(vllist->nr_servers, sizeof(*waits)), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!waits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) for (i = 0; i < vllist->nr_servers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (test_bit(i, &untried)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) server = vllist->servers[i].server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) init_waitqueue_entry(&waits[i], current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) add_wait_queue(&server->probe_wq, &waits[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) bool still_probing = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) for (i = 0; i < vllist->nr_servers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (test_bit(i, &untried)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) server = vllist->servers[i].server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (test_bit(AFS_VLSERVER_FL_PROBING, &server->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) still_probing = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (!still_probing || signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) goto stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) for (i = 0; i < vllist->nr_servers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (test_bit(i, &untried)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) server = vllist->servers[i].server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) rtt_s = READ_ONCE(server->rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (test_bit(AFS_VLSERVER_FL_RESPONDING, &server->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) rtt_s < rtt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) pref = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) rtt = rtt_s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) remove_wait_queue(&server->probe_wq, &waits[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) kfree(waits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (pref == -1 && signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (pref >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) vllist->preferred = pref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) _leave(" = 0 [%u]", pref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }