blob: 79e1a5f6701bed9822bb17e324740b6da13b94da [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells9cc6fc52017-11-02 15:27:50 +00002/* Handle fileserver selection and rotation.
3 *
4 * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
David Howells9cc6fc52017-11-02 15:27:50 +00006 */
7
8#include <linux/kernel.h>
9#include <linux/slab.h>
David Howellsd2ddc772017-11-02 15:27:50 +000010#include <linux/fs.h>
11#include <linux/sched.h>
12#include <linux/delay.h>
13#include <linux/sched/signal.h>
David Howells9cc6fc52017-11-02 15:27:50 +000014#include "internal.h"
David Howellsd2ddc772017-11-02 15:27:50 +000015#include "afs_fs.h"
David Howells9cc6fc52017-11-02 15:27:50 +000016
17/*
David Howellsd2ddc772017-11-02 15:27:50 +000018 * Begin iteration through a server list, starting with the vnode's last used
19 * server if possible, or the last recorded good server if not.
20 */
David Howellsa3100822020-03-20 09:32:50 +000021static bool afs_start_fs_iteration(struct afs_operation *op,
David Howellsd2ddc772017-11-02 15:27:50 +000022 struct afs_vnode *vnode)
23{
David Howells20325962020-04-30 01:03:49 +010024 struct afs_server *server;
25 void *cb_server;
David Howellsd2ddc772017-11-02 15:27:50 +000026 int i;
27
David Howellse49c7b22020-04-10 20:51:51 +010028 read_lock(&op->volume->servers_lock);
David Howells8a070a92020-04-25 10:26:02 +010029 op->server_list = afs_get_serverlist(
30 rcu_dereference_protected(op->volume->servers,
31 lockdep_is_held(&op->volume->servers_lock)));
David Howellse49c7b22020-04-10 20:51:51 +010032 read_unlock(&op->volume->servers_lock);
David Howellsd2ddc772017-11-02 15:27:50 +000033
David Howellsa3100822020-03-20 09:32:50 +000034 op->untried = (1UL << op->server_list->nr_servers) - 1;
35 op->index = READ_ONCE(op->server_list->preferred);
David Howells3bf0fb62018-10-20 00:57:59 +010036
David Howells20325962020-04-30 01:03:49 +010037 cb_server = vnode->cb_server;
38 if (cb_server) {
David Howellsd2ddc772017-11-02 15:27:50 +000039 /* See if the vnode's preferred record is still available */
David Howellsa3100822020-03-20 09:32:50 +000040 for (i = 0; i < op->server_list->nr_servers; i++) {
David Howells20325962020-04-30 01:03:49 +010041 server = op->server_list->servers[i].server;
42 if (server == cb_server) {
David Howellsa3100822020-03-20 09:32:50 +000043 op->index = i;
David Howellsd2ddc772017-11-02 15:27:50 +000044 goto found_interest;
45 }
46 }
47
48 /* If we have a lock outstanding on a server that's no longer
49 * serving this vnode, then we can't switch to another server
50 * and have to return an error.
51 */
David Howellsa3100822020-03-20 09:32:50 +000052 if (op->flags & AFS_OPERATION_CUR_ONLY) {
53 op->error = -ESTALE;
David Howellsd2ddc772017-11-02 15:27:50 +000054 return false;
55 }
56
57 /* Note that the callback promise is effectively broken */
58 write_seqlock(&vnode->cb_lock);
David Howells20325962020-04-30 01:03:49 +010059 ASSERTCMP(cb_server, ==, vnode->cb_server);
60 vnode->cb_server = NULL;
David Howellsd2ddc772017-11-02 15:27:50 +000061 if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags))
62 vnode->cb_break++;
63 write_sequnlock(&vnode->cb_lock);
David Howellsd2ddc772017-11-02 15:27:50 +000064 }
65
66found_interest:
David Howellsd2ddc772017-11-02 15:27:50 +000067 return true;
68}
69
70/*
71 * Post volume busy note.
72 */
73static void afs_busy(struct afs_volume *volume, u32 abort_code)
74{
75 const char *m;
76
77 switch (abort_code) {
78 case VOFFLINE: m = "offline"; break;
79 case VRESTARTING: m = "restarting"; break;
80 case VSALVAGING: m = "being salvaged"; break;
81 default: m = "busy"; break;
82 }
David Howells0fafdc92017-11-13 16:59:50 +000083
David Howells3b6492d2018-10-20 00:57:57 +010084 pr_notice("kAFS: Volume %llu '%s' is %s\n", volume->vid, volume->name, m);
David Howellsd2ddc772017-11-02 15:27:50 +000085}
86
87/*
88 * Sleep and retry the operation to the same fileserver.
89 */
David Howellsa3100822020-03-20 09:32:50 +000090static bool afs_sleep_and_retry(struct afs_operation *op)
David Howellsd2ddc772017-11-02 15:27:50 +000091{
David Howellse49c7b22020-04-10 20:51:51 +010092 if (!(op->flags & AFS_OPERATION_UNINTR)) {
David Howells20b83912019-05-08 16:16:31 +010093 msleep_interruptible(1000);
94 if (signal_pending(current)) {
David Howellsa3100822020-03-20 09:32:50 +000095 op->error = -ERESTARTSYS;
David Howells20b83912019-05-08 16:16:31 +010096 return false;
97 }
98 } else {
99 msleep(1000);
David Howellsd2ddc772017-11-02 15:27:50 +0000100 }
101
102 return true;
103}
104
105/*
106 * Select the fileserver to use. May be called multiple times to rotate
107 * through the fileservers.
108 */
David Howellsa3100822020-03-20 09:32:50 +0000109bool afs_select_fileserver(struct afs_operation *op)
David Howellsd2ddc772017-11-02 15:27:50 +0000110{
111 struct afs_addr_list *alist;
112 struct afs_server *server;
David Howellse49c7b22020-04-10 20:51:51 +0100113 struct afs_vnode *vnode = op->file[0].vnode;
David Howells4584ae92018-11-13 23:20:28 +0000114 struct afs_error e;
115 u32 rtt;
David Howellsa3100822020-03-20 09:32:50 +0000116 int error = op->ac.error, i;
David Howellsd2ddc772017-11-02 15:27:50 +0000117
David Howells3bf0fb62018-10-20 00:57:59 +0100118 _enter("%lx[%d],%lx[%d],%d,%d",
David Howellsa3100822020-03-20 09:32:50 +0000119 op->untried, op->index,
120 op->ac.tried, op->ac.index,
121 error, op->ac.abort_code);
David Howellsd2ddc772017-11-02 15:27:50 +0000122
David Howellsa3100822020-03-20 09:32:50 +0000123 if (op->flags & AFS_OPERATION_STOP) {
David Howellsd2ddc772017-11-02 15:27:50 +0000124 _leave(" = f [stopped]");
125 return false;
126 }
127
David Howellsa3100822020-03-20 09:32:50 +0000128 op->nr_iterations++;
David Howells744bcd72018-10-20 00:57:58 +0100129
David Howellsd2ddc772017-11-02 15:27:50 +0000130 /* Evaluate the result of the previous operation, if there was one. */
David Howellse7f680f2018-10-20 00:57:57 +0100131 switch (error) {
David Howellsd2ddc772017-11-02 15:27:50 +0000132 case SHRT_MAX:
133 goto start;
134
135 case 0:
136 default:
137 /* Success or local failure. Stop. */
David Howellsa3100822020-03-20 09:32:50 +0000138 op->error = error;
139 op->flags |= AFS_OPERATION_STOP;
David Howellse7f680f2018-10-20 00:57:57 +0100140 _leave(" = f [okay/local %d]", error);
David Howellsd2ddc772017-11-02 15:27:50 +0000141 return false;
142
143 case -ECONNABORTED:
144 /* The far side rejected the operation on some grounds. This
145 * might involve the server being busy or the volume having been moved.
146 */
David Howellsa3100822020-03-20 09:32:50 +0000147 switch (op->ac.abort_code) {
David Howellsd2ddc772017-11-02 15:27:50 +0000148 case VNOVOL:
149 /* This fileserver doesn't know about the volume.
150 * - May indicate that the VL is wrong - retry once and compare
151 * the results.
152 * - May indicate that the fileserver couldn't attach to the vol.
153 */
David Howellsa3100822020-03-20 09:32:50 +0000154 if (op->flags & AFS_OPERATION_VNOVOL) {
155 op->error = -EREMOTEIO;
David Howells3d9fa912018-05-11 22:55:59 +0100156 goto next_server;
David Howellsd2ddc772017-11-02 15:27:50 +0000157 }
158
David Howellse49c7b22020-04-10 20:51:51 +0100159 write_lock(&op->volume->servers_lock);
David Howellsa3100822020-03-20 09:32:50 +0000160 op->server_list->vnovol_mask |= 1 << op->index;
David Howellse49c7b22020-04-10 20:51:51 +0100161 write_unlock(&op->volume->servers_lock);
David Howellsd2ddc772017-11-02 15:27:50 +0000162
David Howellse49c7b22020-04-10 20:51:51 +0100163 set_bit(AFS_VOLUME_NEEDS_UPDATE, &op->volume->flags);
164 error = afs_check_volume_status(op->volume, op);
David Howellse7f680f2018-10-20 00:57:57 +0100165 if (error < 0)
166 goto failed_set_error;
David Howellsd2ddc772017-11-02 15:27:50 +0000167
David Howellse49c7b22020-04-10 20:51:51 +0100168 if (test_bit(AFS_VOLUME_DELETED, &op->volume->flags)) {
David Howellsa3100822020-03-20 09:32:50 +0000169 op->error = -ENOMEDIUM;
David Howellsd2ddc772017-11-02 15:27:50 +0000170 goto failed;
171 }
172
173 /* If the server list didn't change, then assume that
174 * it's the fileserver having trouble.
175 */
David Howells8a070a92020-04-25 10:26:02 +0100176 if (rcu_access_pointer(op->volume->servers) == op->server_list) {
David Howellsa3100822020-03-20 09:32:50 +0000177 op->error = -EREMOTEIO;
David Howells3d9fa912018-05-11 22:55:59 +0100178 goto next_server;
David Howellsd2ddc772017-11-02 15:27:50 +0000179 }
180
181 /* Try again */
David Howellsa3100822020-03-20 09:32:50 +0000182 op->flags |= AFS_OPERATION_VNOVOL;
David Howellsd2ddc772017-11-02 15:27:50 +0000183 _leave(" = t [vnovol]");
184 return true;
185
186 case VSALVAGE: /* TODO: Should this return an error or iterate? */
187 case VVOLEXISTS:
188 case VNOSERVICE:
189 case VONLINE:
190 case VDISKFULL:
191 case VOVERQUOTA:
David Howellsa3100822020-03-20 09:32:50 +0000192 op->error = afs_abort_to_error(op->ac.abort_code);
David Howellsd2ddc772017-11-02 15:27:50 +0000193 goto next_server;
194
195 case VOFFLINE:
David Howellse49c7b22020-04-10 20:51:51 +0100196 if (!test_and_set_bit(AFS_VOLUME_OFFLINE, &op->volume->flags)) {
197 afs_busy(op->volume, op->ac.abort_code);
198 clear_bit(AFS_VOLUME_BUSY, &op->volume->flags);
David Howellsd2ddc772017-11-02 15:27:50 +0000199 }
David Howellsa3100822020-03-20 09:32:50 +0000200 if (op->flags & AFS_OPERATION_NO_VSLEEP) {
201 op->error = -EADV;
David Howellsd2ddc772017-11-02 15:27:50 +0000202 goto failed;
203 }
David Howellsa3100822020-03-20 09:32:50 +0000204 if (op->flags & AFS_OPERATION_CUR_ONLY) {
205 op->error = -ESTALE;
David Howellsd2ddc772017-11-02 15:27:50 +0000206 goto failed;
207 }
208 goto busy;
209
210 case VSALVAGING:
211 case VRESTARTING:
212 case VBUSY:
213 /* Retry after going round all the servers unless we
214 * have a file lock we need to maintain.
215 */
David Howellsa3100822020-03-20 09:32:50 +0000216 if (op->flags & AFS_OPERATION_NO_VSLEEP) {
217 op->error = -EBUSY;
David Howellsd2ddc772017-11-02 15:27:50 +0000218 goto failed;
219 }
David Howellse49c7b22020-04-10 20:51:51 +0100220 if (!test_and_set_bit(AFS_VOLUME_BUSY, &op->volume->flags)) {
221 afs_busy(op->volume, op->ac.abort_code);
222 clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags);
David Howellsd2ddc772017-11-02 15:27:50 +0000223 }
224 busy:
David Howellsa3100822020-03-20 09:32:50 +0000225 if (op->flags & AFS_OPERATION_CUR_ONLY) {
226 if (!afs_sleep_and_retry(op))
David Howellsd2ddc772017-11-02 15:27:50 +0000227 goto failed;
228
229 /* Retry with same server & address */
230 _leave(" = t [vbusy]");
231 return true;
232 }
233
David Howellsa3100822020-03-20 09:32:50 +0000234 op->flags |= AFS_OPERATION_VBUSY;
David Howellsd2ddc772017-11-02 15:27:50 +0000235 goto next_server;
236
237 case VMOVED:
238 /* The volume migrated to another server. We consider
239 * consider all locks and callbacks broken and request
240 * an update from the VLDB.
241 *
242 * We also limit the number of VMOVED hops we will
243 * honour, just in case someone sets up a loop.
244 */
David Howellsa3100822020-03-20 09:32:50 +0000245 if (op->flags & AFS_OPERATION_VMOVED) {
246 op->error = -EREMOTEIO;
David Howellsd2ddc772017-11-02 15:27:50 +0000247 goto failed;
248 }
David Howellsa3100822020-03-20 09:32:50 +0000249 op->flags |= AFS_OPERATION_VMOVED;
David Howellsd2ddc772017-11-02 15:27:50 +0000250
David Howellse49c7b22020-04-10 20:51:51 +0100251 set_bit(AFS_VOLUME_WAIT, &op->volume->flags);
252 set_bit(AFS_VOLUME_NEEDS_UPDATE, &op->volume->flags);
253 error = afs_check_volume_status(op->volume, op);
David Howellse7f680f2018-10-20 00:57:57 +0100254 if (error < 0)
255 goto failed_set_error;
David Howellsd2ddc772017-11-02 15:27:50 +0000256
257 /* If the server list didn't change, then the VLDB is
258 * out of sync with the fileservers. This is hopefully
259 * a temporary condition, however, so we don't want to
260 * permanently block access to the file.
261 *
262 * TODO: Try other fileservers if we can.
263 *
264 * TODO: Retry a few times with sleeps.
265 */
David Howells8a070a92020-04-25 10:26:02 +0100266 if (rcu_access_pointer(op->volume->servers) == op->server_list) {
David Howellsa3100822020-03-20 09:32:50 +0000267 op->error = -ENOMEDIUM;
David Howellsd2ddc772017-11-02 15:27:50 +0000268 goto failed;
269 }
270
271 goto restart_from_beginning;
272
273 default:
David Howellse49c7b22020-04-10 20:51:51 +0100274 clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags);
275 clear_bit(AFS_VOLUME_BUSY, &op->volume->flags);
David Howellsa3100822020-03-20 09:32:50 +0000276 op->error = afs_abort_to_error(op->ac.abort_code);
David Howellsd2ddc772017-11-02 15:27:50 +0000277 goto failed;
278 }
279
David Howellse7f680f2018-10-20 00:57:57 +0100280 case -ETIMEDOUT:
281 case -ETIME:
David Howellsa3100822020-03-20 09:32:50 +0000282 if (op->error != -EDESTADDRREQ)
David Howellse7f680f2018-10-20 00:57:57 +0100283 goto iterate_address;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500284 fallthrough;
David Howells4584ae92018-11-13 23:20:28 +0000285 case -ERFKILL:
286 case -EADDRNOTAVAIL:
David Howellsd2ddc772017-11-02 15:27:50 +0000287 case -ENETUNREACH:
288 case -EHOSTUNREACH:
David Howells4584ae92018-11-13 23:20:28 +0000289 case -EHOSTDOWN:
David Howellsd2ddc772017-11-02 15:27:50 +0000290 case -ECONNREFUSED:
David Howellsd2ddc772017-11-02 15:27:50 +0000291 _debug("no conn");
David Howellsa3100822020-03-20 09:32:50 +0000292 op->error = error;
David Howellsd2ddc772017-11-02 15:27:50 +0000293 goto iterate_address;
David Howells1a025022018-06-03 02:17:39 +0100294
295 case -ECONNRESET:
296 _debug("call reset");
David Howellsa3100822020-03-20 09:32:50 +0000297 op->error = error;
David Howells1a025022018-06-03 02:17:39 +0100298 goto failed;
David Howellsd2ddc772017-11-02 15:27:50 +0000299 }
300
301restart_from_beginning:
302 _debug("restart");
David Howellsa3100822020-03-20 09:32:50 +0000303 afs_end_cursor(&op->ac);
David Howells20325962020-04-30 01:03:49 +0100304 op->server = NULL;
David Howellse49c7b22020-04-10 20:51:51 +0100305 afs_put_serverlist(op->net, op->server_list);
David Howellsa3100822020-03-20 09:32:50 +0000306 op->server_list = NULL;
David Howellsd2ddc772017-11-02 15:27:50 +0000307start:
308 _debug("start");
309 /* See if we need to do an update of the volume record. Note that the
310 * volume may have moved or even have been deleted.
311 */
David Howellse49c7b22020-04-10 20:51:51 +0100312 error = afs_check_volume_status(op->volume, op);
David Howellse7f680f2018-10-20 00:57:57 +0100313 if (error < 0)
314 goto failed_set_error;
David Howellsd2ddc772017-11-02 15:27:50 +0000315
David Howellsa3100822020-03-20 09:32:50 +0000316 if (!afs_start_fs_iteration(op, vnode))
David Howellsd2ddc772017-11-02 15:27:50 +0000317 goto failed;
David Howellsd2ddc772017-11-02 15:27:50 +0000318
David Howellse49c7b22020-04-10 20:51:51 +0100319 _debug("__ VOL %llx __", op->volume->vid);
David Howells3bf0fb62018-10-20 00:57:59 +0100320
321pick_server:
David Howellsa3100822020-03-20 09:32:50 +0000322 _debug("pick [%lx]", op->untried);
David Howells3bf0fb62018-10-20 00:57:59 +0100323
David Howellsa3100822020-03-20 09:32:50 +0000324 error = afs_wait_for_fs_probes(op->server_list, op->untried);
David Howells3bf0fb62018-10-20 00:57:59 +0100325 if (error < 0)
326 goto failed_set_error;
327
328 /* Pick the untried server with the lowest RTT. If we have outstanding
329 * callbacks, we stick with the server we're already using if we can.
330 */
David Howells20325962020-04-30 01:03:49 +0100331 if (op->server) {
332 _debug("server %u", op->index);
David Howellsa3100822020-03-20 09:32:50 +0000333 if (test_bit(op->index, &op->untried))
David Howells3bf0fb62018-10-20 00:57:59 +0100334 goto selected_server;
David Howells20325962020-04-30 01:03:49 +0100335 op->server = NULL;
336 _debug("no server");
David Howells3bf0fb62018-10-20 00:57:59 +0100337 }
338
David Howellsa3100822020-03-20 09:32:50 +0000339 op->index = -1;
David Howells3bf0fb62018-10-20 00:57:59 +0100340 rtt = U32_MAX;
David Howellsa3100822020-03-20 09:32:50 +0000341 for (i = 0; i < op->server_list->nr_servers; i++) {
342 struct afs_server *s = op->server_list->servers[i].server;
David Howells3bf0fb62018-10-20 00:57:59 +0100343
David Howellsf3c130e2020-05-02 13:39:57 +0100344 if (!test_bit(i, &op->untried) ||
345 !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags))
David Howells3bf0fb62018-10-20 00:57:59 +0100346 continue;
347 if (s->probe.rtt < rtt) {
David Howellsa3100822020-03-20 09:32:50 +0000348 op->index = i;
David Howells3bf0fb62018-10-20 00:57:59 +0100349 rtt = s->probe.rtt;
350 }
351 }
352
David Howellsa3100822020-03-20 09:32:50 +0000353 if (op->index == -1)
David Howells3bf0fb62018-10-20 00:57:59 +0100354 goto no_more_servers;
355
356selected_server:
David Howellsa3100822020-03-20 09:32:50 +0000357 _debug("use %d", op->index);
358 __clear_bit(op->index, &op->untried);
David Howells3bf0fb62018-10-20 00:57:59 +0100359
David Howellsd2ddc772017-11-02 15:27:50 +0000360 /* We're starting on a different fileserver from the list. We need to
361 * check it, create a callback intercept, find its address list and
362 * probe its capabilities before we use it.
363 */
David Howellsa3100822020-03-20 09:32:50 +0000364 ASSERTCMP(op->ac.alist, ==, NULL);
365 server = op->server_list->servers[op->index].server;
David Howellsd2ddc772017-11-02 15:27:50 +0000366
David Howellsa3100822020-03-20 09:32:50 +0000367 if (!afs_check_server_record(op, server))
David Howellsd2ddc772017-11-02 15:27:50 +0000368 goto failed;
369
370 _debug("USING SERVER: %pU", &server->uuid);
371
David Howells8409f672020-04-22 00:02:46 +0100372 op->flags |= AFS_OPERATION_RETRY_SERVER;
David Howells20325962020-04-30 01:03:49 +0100373 op->server = server;
374 if (vnode->cb_server != server) {
375 vnode->cb_server = server;
376 vnode->cb_s_break = server->cb_s_break;
David Howells4fe6a942021-09-02 21:51:01 +0100377 vnode->cb_fs_s_break = atomic_read(&server->cell->fs_s_break);
David Howells20325962020-04-30 01:03:49 +0100378 vnode->cb_v_break = vnode->volume->cb_v_break;
379 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
380 }
David Howellsd2ddc772017-11-02 15:27:50 +0000381
382 read_lock(&server->fs_lock);
383 alist = rcu_dereference_protected(server->addresses,
384 lockdep_is_held(&server->fs_lock));
385 afs_get_addrlist(alist);
386 read_unlock(&server->fs_lock);
387
David Howells8409f672020-04-22 00:02:46 +0100388retry_server:
David Howellsa3100822020-03-20 09:32:50 +0000389 memset(&op->ac, 0, sizeof(op->ac));
David Howellsd2ddc772017-11-02 15:27:50 +0000390
David Howellsa3100822020-03-20 09:32:50 +0000391 if (!op->ac.alist)
392 op->ac.alist = alist;
David Howellsd2ddc772017-11-02 15:27:50 +0000393 else
394 afs_put_addrlist(alist);
395
David Howellsa3100822020-03-20 09:32:50 +0000396 op->ac.index = -1;
David Howellsd2ddc772017-11-02 15:27:50 +0000397
398iterate_address:
David Howellsa3100822020-03-20 09:32:50 +0000399 ASSERT(op->ac.alist);
David Howellsd2ddc772017-11-02 15:27:50 +0000400 /* Iterate over the current server's address list to try and find an
401 * address on which it will respond to us.
402 */
David Howellsa3100822020-03-20 09:32:50 +0000403 if (!afs_iterate_addresses(&op->ac))
David Howells8409f672020-04-22 00:02:46 +0100404 goto out_of_addresses;
David Howellsd2ddc772017-11-02 15:27:50 +0000405
David Howells8409f672020-04-22 00:02:46 +0100406 _debug("address [%u] %u/%u %pISp",
407 op->index, op->ac.index, op->ac.alist->nr_addrs,
408 &op->ac.alist->addrs[op->ac.index].transport);
David Howells3bf0fb62018-10-20 00:57:59 +0100409
David Howellsfe4d7742018-02-06 06:26:30 +0000410 _leave(" = t");
411 return true;
David Howellsd2ddc772017-11-02 15:27:50 +0000412
David Howells8409f672020-04-22 00:02:46 +0100413out_of_addresses:
414 /* We've now had a failure to respond on all of a server's addresses -
415 * immediately probe them again and consider retrying the server.
416 */
417 afs_probe_fileserver(op->net, op->server);
418 if (op->flags & AFS_OPERATION_RETRY_SERVER) {
419 alist = op->ac.alist;
420 error = afs_wait_for_one_fs_probe(
421 op->server, !(op->flags & AFS_OPERATION_UNINTR));
422 switch (error) {
423 case 0:
424 op->flags &= ~AFS_OPERATION_RETRY_SERVER;
425 goto retry_server;
426 case -ERESTARTSYS:
427 goto failed_set_error;
428 case -ETIME:
429 case -EDESTADDRREQ:
430 goto next_server;
431 }
432 }
433
David Howells16280a12018-02-06 06:26:30 +0000434next_server:
435 _debug("next");
David Howellsa3100822020-03-20 09:32:50 +0000436 afs_end_cursor(&op->ac);
David Howells3bf0fb62018-10-20 00:57:59 +0100437 goto pick_server;
David Howells16280a12018-02-06 06:26:30 +0000438
David Howells3bf0fb62018-10-20 00:57:59 +0100439no_more_servers:
David Howells16280a12018-02-06 06:26:30 +0000440 /* That's all the servers poked to no good effect. Try again if some
441 * of them were busy.
442 */
David Howellsa3100822020-03-20 09:32:50 +0000443 if (op->flags & AFS_OPERATION_VBUSY)
David Howells16280a12018-02-06 06:26:30 +0000444 goto restart_from_beginning;
445
David Howells4584ae92018-11-13 23:20:28 +0000446 e.error = -EDESTADDRREQ;
447 e.responded = false;
David Howellsa3100822020-03-20 09:32:50 +0000448 for (i = 0; i < op->server_list->nr_servers; i++) {
449 struct afs_server *s = op->server_list->servers[i].server;
David Howells3bf0fb62018-10-20 00:57:59 +0100450
David Howells4584ae92018-11-13 23:20:28 +0000451 afs_prioritise_error(&e, READ_ONCE(s->probe.error),
452 s->probe.abort_code);
David Howells3bf0fb62018-10-20 00:57:59 +0100453 }
454
David Howells51eba992019-05-15 23:06:24 +0100455 error = e.error;
456
David Howellse7f680f2018-10-20 00:57:57 +0100457failed_set_error:
David Howellsa3100822020-03-20 09:32:50 +0000458 op->error = error;
David Howellsd2ddc772017-11-02 15:27:50 +0000459failed:
David Howellsa3100822020-03-20 09:32:50 +0000460 op->flags |= AFS_OPERATION_STOP;
461 afs_end_cursor(&op->ac);
462 _leave(" = f [failed %d]", op->error);
David Howellsd2ddc772017-11-02 15:27:50 +0000463 return false;
464}
465
466/*
David Howells744bcd72018-10-20 00:57:58 +0100467 * Dump cursor state in the case of the error being EDESTADDRREQ.
468 */
David Howellse49c7b22020-04-10 20:51:51 +0100469void afs_dump_edestaddrreq(const struct afs_operation *op)
David Howells744bcd72018-10-20 00:57:58 +0100470{
471 static int count;
472 int i;
473
474 if (!IS_ENABLED(CONFIG_AFS_DEBUG_CURSOR) || count > 3)
475 return;
476 count++;
477
478 rcu_read_lock();
479
480 pr_notice("EDESTADDR occurred\n");
David Howellse49c7b22020-04-10 20:51:51 +0100481 pr_notice("FC: cbb=%x cbb2=%x fl=%x err=%hd\n",
482 op->file[0].cb_break_before,
483 op->file[1].cb_break_before, op->flags, op->error);
David Howells3bf0fb62018-10-20 00:57:59 +0100484 pr_notice("FC: ut=%lx ix=%d ni=%u\n",
David Howellsa3100822020-03-20 09:32:50 +0000485 op->untried, op->index, op->nr_iterations);
David Howells744bcd72018-10-20 00:57:58 +0100486
David Howellsa3100822020-03-20 09:32:50 +0000487 if (op->server_list) {
488 const struct afs_server_list *sl = op->server_list;
David Howells3bf0fb62018-10-20 00:57:59 +0100489 pr_notice("FC: SL nr=%u pr=%u vnov=%hx\n",
490 sl->nr_servers, sl->preferred, sl->vnovol_mask);
David Howells744bcd72018-10-20 00:57:58 +0100491 for (i = 0; i < sl->nr_servers; i++) {
492 const struct afs_server *s = sl->servers[i].server;
493 pr_notice("FC: server fl=%lx av=%u %pU\n",
494 s->flags, s->addr_version, &s->uuid);
495 if (s->addresses) {
496 const struct afs_addr_list *a =
497 rcu_dereference(s->addresses);
David Howells3bf0fb62018-10-20 00:57:59 +0100498 pr_notice("FC: - av=%u nr=%u/%u/%u pr=%u\n",
David Howells744bcd72018-10-20 00:57:58 +0100499 a->version,
500 a->nr_ipv4, a->nr_addrs, a->max_addrs,
David Howells3bf0fb62018-10-20 00:57:59 +0100501 a->preferred);
David Howellsf6cbb362020-04-24 15:10:00 +0100502 pr_notice("FC: - R=%lx F=%lx\n",
503 a->responded, a->failed);
David Howellsa3100822020-03-20 09:32:50 +0000504 if (a == op->ac.alist)
David Howells744bcd72018-10-20 00:57:58 +0100505 pr_notice("FC: - current\n");
506 }
507 }
508 }
509
David Howells3bf0fb62018-10-20 00:57:59 +0100510 pr_notice("AC: t=%lx ax=%u ac=%d er=%d r=%u ni=%u\n",
David Howellsa3100822020-03-20 09:32:50 +0000511 op->ac.tried, op->ac.index, op->ac.abort_code, op->ac.error,
512 op->ac.responded, op->ac.nr_iterations);
David Howells744bcd72018-10-20 00:57:58 +0100513 rcu_read_unlock();
514}