Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 9cc6fc5 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 2 | /* 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 Howells | 9cc6fc5 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/slab.h> |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 10 | #include <linux/fs.h> |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/sched/signal.h> |
David Howells | 9cc6fc5 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 14 | #include "internal.h" |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 15 | #include "afs_fs.h" |
David Howells | 9cc6fc5 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 16 | |
| 17 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 18 | * 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 21 | static bool afs_start_fs_iteration(struct afs_operation *op, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 22 | struct afs_vnode *vnode) |
| 23 | { |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 24 | struct afs_server *server; |
| 25 | void *cb_server; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 26 | int i; |
| 27 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 28 | read_lock(&op->volume->servers_lock); |
David Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 29 | op->server_list = afs_get_serverlist( |
| 30 | rcu_dereference_protected(op->volume->servers, |
| 31 | lockdep_is_held(&op->volume->servers_lock))); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 32 | read_unlock(&op->volume->servers_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 33 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 34 | op->untried = (1UL << op->server_list->nr_servers) - 1; |
| 35 | op->index = READ_ONCE(op->server_list->preferred); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 36 | |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 37 | cb_server = vnode->cb_server; |
| 38 | if (cb_server) { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 39 | /* See if the vnode's preferred record is still available */ |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 40 | for (i = 0; i < op->server_list->nr_servers; i++) { |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 41 | server = op->server_list->servers[i].server; |
| 42 | if (server == cb_server) { |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 43 | op->index = i; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 44 | 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 52 | if (op->flags & AFS_OPERATION_CUR_ONLY) { |
| 53 | op->error = -ESTALE; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 54 | return false; |
| 55 | } |
| 56 | |
| 57 | /* Note that the callback promise is effectively broken */ |
| 58 | write_seqlock(&vnode->cb_lock); |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 59 | ASSERTCMP(cb_server, ==, vnode->cb_server); |
| 60 | vnode->cb_server = NULL; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 61 | if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) |
| 62 | vnode->cb_break++; |
| 63 | write_sequnlock(&vnode->cb_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | found_interest: |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 67 | return true; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * Post volume busy note. |
| 72 | */ |
| 73 | static 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 Howells | 0fafdc9 | 2017-11-13 16:59:50 +0000 | [diff] [blame] | 83 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 84 | pr_notice("kAFS: Volume %llu '%s' is %s\n", volume->vid, volume->name, m); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Sleep and retry the operation to the same fileserver. |
| 89 | */ |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 90 | static bool afs_sleep_and_retry(struct afs_operation *op) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 91 | { |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 92 | if (!(op->flags & AFS_OPERATION_UNINTR)) { |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 93 | msleep_interruptible(1000); |
| 94 | if (signal_pending(current)) { |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 95 | op->error = -ERESTARTSYS; |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | } else { |
| 99 | msleep(1000); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 100 | } |
| 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 109 | bool afs_select_fileserver(struct afs_operation *op) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 110 | { |
| 111 | struct afs_addr_list *alist; |
| 112 | struct afs_server *server; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 113 | struct afs_vnode *vnode = op->file[0].vnode; |
David Howells | 4584ae9 | 2018-11-13 23:20:28 +0000 | [diff] [blame] | 114 | struct afs_error e; |
| 115 | u32 rtt; |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 116 | int error = op->ac.error, i; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 117 | |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 118 | _enter("%lx[%d],%lx[%d],%d,%d", |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 119 | op->untried, op->index, |
| 120 | op->ac.tried, op->ac.index, |
| 121 | error, op->ac.abort_code); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 122 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 123 | if (op->flags & AFS_OPERATION_STOP) { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 124 | _leave(" = f [stopped]"); |
| 125 | return false; |
| 126 | } |
| 127 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 128 | op->nr_iterations++; |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 129 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 130 | /* Evaluate the result of the previous operation, if there was one. */ |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 131 | switch (error) { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 132 | case SHRT_MAX: |
| 133 | goto start; |
| 134 | |
| 135 | case 0: |
| 136 | default: |
| 137 | /* Success or local failure. Stop. */ |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 138 | op->error = error; |
| 139 | op->flags |= AFS_OPERATION_STOP; |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 140 | _leave(" = f [okay/local %d]", error); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 141 | 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 147 | switch (op->ac.abort_code) { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 148 | 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 154 | if (op->flags & AFS_OPERATION_VNOVOL) { |
| 155 | op->error = -EREMOTEIO; |
David Howells | 3d9fa91 | 2018-05-11 22:55:59 +0100 | [diff] [blame] | 156 | goto next_server; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 157 | } |
| 158 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 159 | write_lock(&op->volume->servers_lock); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 160 | op->server_list->vnovol_mask |= 1 << op->index; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 161 | write_unlock(&op->volume->servers_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 162 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 163 | set_bit(AFS_VOLUME_NEEDS_UPDATE, &op->volume->flags); |
| 164 | error = afs_check_volume_status(op->volume, op); |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 165 | if (error < 0) |
| 166 | goto failed_set_error; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 167 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 168 | if (test_bit(AFS_VOLUME_DELETED, &op->volume->flags)) { |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 169 | op->error = -ENOMEDIUM; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 170 | goto failed; |
| 171 | } |
| 172 | |
| 173 | /* If the server list didn't change, then assume that |
| 174 | * it's the fileserver having trouble. |
| 175 | */ |
David Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 176 | if (rcu_access_pointer(op->volume->servers) == op->server_list) { |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 177 | op->error = -EREMOTEIO; |
David Howells | 3d9fa91 | 2018-05-11 22:55:59 +0100 | [diff] [blame] | 178 | goto next_server; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* Try again */ |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 182 | op->flags |= AFS_OPERATION_VNOVOL; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 183 | _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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 192 | op->error = afs_abort_to_error(op->ac.abort_code); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 193 | goto next_server; |
| 194 | |
| 195 | case VOFFLINE: |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 196 | 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 Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 199 | } |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 200 | if (op->flags & AFS_OPERATION_NO_VSLEEP) { |
| 201 | op->error = -EADV; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 202 | goto failed; |
| 203 | } |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 204 | if (op->flags & AFS_OPERATION_CUR_ONLY) { |
| 205 | op->error = -ESTALE; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 206 | 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 216 | if (op->flags & AFS_OPERATION_NO_VSLEEP) { |
| 217 | op->error = -EBUSY; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 218 | goto failed; |
| 219 | } |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 220 | 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 Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 223 | } |
| 224 | busy: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 225 | if (op->flags & AFS_OPERATION_CUR_ONLY) { |
| 226 | if (!afs_sleep_and_retry(op)) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 227 | goto failed; |
| 228 | |
| 229 | /* Retry with same server & address */ |
| 230 | _leave(" = t [vbusy]"); |
| 231 | return true; |
| 232 | } |
| 233 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 234 | op->flags |= AFS_OPERATION_VBUSY; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 235 | 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 245 | if (op->flags & AFS_OPERATION_VMOVED) { |
| 246 | op->error = -EREMOTEIO; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 247 | goto failed; |
| 248 | } |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 249 | op->flags |= AFS_OPERATION_VMOVED; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 250 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 251 | 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 Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 254 | if (error < 0) |
| 255 | goto failed_set_error; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 256 | |
| 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 Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 266 | if (rcu_access_pointer(op->volume->servers) == op->server_list) { |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 267 | op->error = -ENOMEDIUM; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 268 | goto failed; |
| 269 | } |
| 270 | |
| 271 | goto restart_from_beginning; |
| 272 | |
| 273 | default: |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 274 | clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags); |
| 275 | clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 276 | op->error = afs_abort_to_error(op->ac.abort_code); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 277 | goto failed; |
| 278 | } |
| 279 | |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 280 | case -ETIMEDOUT: |
| 281 | case -ETIME: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 282 | if (op->error != -EDESTADDRREQ) |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 283 | goto iterate_address; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 284 | fallthrough; |
David Howells | 4584ae9 | 2018-11-13 23:20:28 +0000 | [diff] [blame] | 285 | case -ERFKILL: |
| 286 | case -EADDRNOTAVAIL: |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 287 | case -ENETUNREACH: |
| 288 | case -EHOSTUNREACH: |
David Howells | 4584ae9 | 2018-11-13 23:20:28 +0000 | [diff] [blame] | 289 | case -EHOSTDOWN: |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 290 | case -ECONNREFUSED: |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 291 | _debug("no conn"); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 292 | op->error = error; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 293 | goto iterate_address; |
David Howells | 1a02502 | 2018-06-03 02:17:39 +0100 | [diff] [blame] | 294 | |
| 295 | case -ECONNRESET: |
| 296 | _debug("call reset"); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 297 | op->error = error; |
David Howells | 1a02502 | 2018-06-03 02:17:39 +0100 | [diff] [blame] | 298 | goto failed; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | restart_from_beginning: |
| 302 | _debug("restart"); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 303 | afs_end_cursor(&op->ac); |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 304 | op->server = NULL; |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 305 | afs_put_serverlist(op->net, op->server_list); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 306 | op->server_list = NULL; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 307 | start: |
| 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 Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 312 | error = afs_check_volume_status(op->volume, op); |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 313 | if (error < 0) |
| 314 | goto failed_set_error; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 315 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 316 | if (!afs_start_fs_iteration(op, vnode)) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 317 | goto failed; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 318 | |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 319 | _debug("__ VOL %llx __", op->volume->vid); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 320 | |
| 321 | pick_server: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 322 | _debug("pick [%lx]", op->untried); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 323 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 324 | error = afs_wait_for_fs_probes(op->server_list, op->untried); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 325 | 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 Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 331 | if (op->server) { |
| 332 | _debug("server %u", op->index); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 333 | if (test_bit(op->index, &op->untried)) |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 334 | goto selected_server; |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 335 | op->server = NULL; |
| 336 | _debug("no server"); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 337 | } |
| 338 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 339 | op->index = -1; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 340 | rtt = U32_MAX; |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 341 | for (i = 0; i < op->server_list->nr_servers; i++) { |
| 342 | struct afs_server *s = op->server_list->servers[i].server; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 343 | |
David Howells | f3c130e | 2020-05-02 13:39:57 +0100 | [diff] [blame] | 344 | if (!test_bit(i, &op->untried) || |
| 345 | !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags)) |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 346 | continue; |
| 347 | if (s->probe.rtt < rtt) { |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 348 | op->index = i; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 349 | rtt = s->probe.rtt; |
| 350 | } |
| 351 | } |
| 352 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 353 | if (op->index == -1) |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 354 | goto no_more_servers; |
| 355 | |
| 356 | selected_server: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 357 | _debug("use %d", op->index); |
| 358 | __clear_bit(op->index, &op->untried); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 359 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 360 | /* 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 Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 364 | ASSERTCMP(op->ac.alist, ==, NULL); |
| 365 | server = op->server_list->servers[op->index].server; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 366 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 367 | if (!afs_check_server_record(op, server)) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 368 | goto failed; |
| 369 | |
| 370 | _debug("USING SERVER: %pU", &server->uuid); |
| 371 | |
David Howells | 8409f67 | 2020-04-22 00:02:46 +0100 | [diff] [blame] | 372 | op->flags |= AFS_OPERATION_RETRY_SERVER; |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 373 | op->server = server; |
| 374 | if (vnode->cb_server != server) { |
| 375 | vnode->cb_server = server; |
| 376 | vnode->cb_s_break = server->cb_s_break; |
David Howells | 4fe6a94 | 2021-09-02 21:51:01 +0100 | [diff] [blame] | 377 | vnode->cb_fs_s_break = atomic_read(&server->cell->fs_s_break); |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 378 | vnode->cb_v_break = vnode->volume->cb_v_break; |
| 379 | clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); |
| 380 | } |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 381 | |
| 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 Howells | 8409f67 | 2020-04-22 00:02:46 +0100 | [diff] [blame] | 388 | retry_server: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 389 | memset(&op->ac, 0, sizeof(op->ac)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 390 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 391 | if (!op->ac.alist) |
| 392 | op->ac.alist = alist; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 393 | else |
| 394 | afs_put_addrlist(alist); |
| 395 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 396 | op->ac.index = -1; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 397 | |
| 398 | iterate_address: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 399 | ASSERT(op->ac.alist); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 400 | /* Iterate over the current server's address list to try and find an |
| 401 | * address on which it will respond to us. |
| 402 | */ |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 403 | if (!afs_iterate_addresses(&op->ac)) |
David Howells | 8409f67 | 2020-04-22 00:02:46 +0100 | [diff] [blame] | 404 | goto out_of_addresses; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 405 | |
David Howells | 8409f67 | 2020-04-22 00:02:46 +0100 | [diff] [blame] | 406 | _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 Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 409 | |
David Howells | fe4d774 | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 410 | _leave(" = t"); |
| 411 | return true; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 412 | |
David Howells | 8409f67 | 2020-04-22 00:02:46 +0100 | [diff] [blame] | 413 | out_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 Howells | 16280a1 | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 434 | next_server: |
| 435 | _debug("next"); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 436 | afs_end_cursor(&op->ac); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 437 | goto pick_server; |
David Howells | 16280a1 | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 438 | |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 439 | no_more_servers: |
David Howells | 16280a1 | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 440 | /* That's all the servers poked to no good effect. Try again if some |
| 441 | * of them were busy. |
| 442 | */ |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 443 | if (op->flags & AFS_OPERATION_VBUSY) |
David Howells | 16280a1 | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 444 | goto restart_from_beginning; |
| 445 | |
David Howells | 4584ae9 | 2018-11-13 23:20:28 +0000 | [diff] [blame] | 446 | e.error = -EDESTADDRREQ; |
| 447 | e.responded = false; |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 448 | for (i = 0; i < op->server_list->nr_servers; i++) { |
| 449 | struct afs_server *s = op->server_list->servers[i].server; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 450 | |
David Howells | 4584ae9 | 2018-11-13 23:20:28 +0000 | [diff] [blame] | 451 | afs_prioritise_error(&e, READ_ONCE(s->probe.error), |
| 452 | s->probe.abort_code); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 453 | } |
| 454 | |
David Howells | 51eba99 | 2019-05-15 23:06:24 +0100 | [diff] [blame] | 455 | error = e.error; |
| 456 | |
David Howells | e7f680f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 457 | failed_set_error: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 458 | op->error = error; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 459 | failed: |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 460 | op->flags |= AFS_OPERATION_STOP; |
| 461 | afs_end_cursor(&op->ac); |
| 462 | _leave(" = f [failed %d]", op->error); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 463 | return false; |
| 464 | } |
| 465 | |
| 466 | /* |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 467 | * Dump cursor state in the case of the error being EDESTADDRREQ. |
| 468 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 469 | void afs_dump_edestaddrreq(const struct afs_operation *op) |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 470 | { |
| 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 Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 481 | 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 Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 484 | pr_notice("FC: ut=%lx ix=%d ni=%u\n", |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 485 | op->untried, op->index, op->nr_iterations); |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 486 | |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 487 | if (op->server_list) { |
| 488 | const struct afs_server_list *sl = op->server_list; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 489 | pr_notice("FC: SL nr=%u pr=%u vnov=%hx\n", |
| 490 | sl->nr_servers, sl->preferred, sl->vnovol_mask); |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 491 | 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 Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 498 | pr_notice("FC: - av=%u nr=%u/%u/%u pr=%u\n", |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 499 | a->version, |
| 500 | a->nr_ipv4, a->nr_addrs, a->max_addrs, |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 501 | a->preferred); |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 502 | pr_notice("FC: - R=%lx F=%lx\n", |
| 503 | a->responded, a->failed); |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 504 | if (a == op->ac.alist) |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 505 | pr_notice("FC: - current\n"); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 510 | pr_notice("AC: t=%lx ax=%u ac=%d er=%d r=%u ni=%u\n", |
David Howells | a310082 | 2020-03-20 09:32:50 +0000 | [diff] [blame] | 511 | op->ac.tried, op->ac.index, op->ac.abort_code, op->ac.error, |
| 512 | op->ac.responded, op->ac.nr_iterations); |
David Howells | 744bcd7 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 513 | rcu_read_unlock(); |
| 514 | } |