Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 2 | /* AFS volume management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 4 | * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Written by David Howells (dhowells@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "internal.h" |
| 11 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 12 | unsigned __read_mostly afs_volume_gc_delay = 10; |
| 13 | unsigned __read_mostly afs_volume_record_life = 60 * 60; |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 16 | * Allocate a volume record and load it up from a vldb record. |
| 17 | */ |
David Howells | 13fcc68 | 2018-11-01 23:07:27 +0000 | [diff] [blame] | 18 | static struct afs_volume *afs_alloc_volume(struct afs_fs_context *params, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 19 | struct afs_vldb_entry *vldb, |
| 20 | unsigned long type_mask) |
| 21 | { |
| 22 | struct afs_server_list *slist; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 23 | struct afs_volume *volume; |
David Howells | 45df846 | 2018-02-06 14:12:32 +0000 | [diff] [blame] | 24 | int ret = -ENOMEM, nr_servers = 0, i; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 25 | |
| 26 | for (i = 0; i < vldb->nr_servers; i++) |
| 27 | if (vldb->fs_mask[i] & type_mask) |
| 28 | nr_servers++; |
| 29 | |
| 30 | volume = kzalloc(sizeof(struct afs_volume), GFP_KERNEL); |
| 31 | if (!volume) |
| 32 | goto error_0; |
| 33 | |
| 34 | volume->vid = vldb->vid[params->type]; |
| 35 | volume->update_at = ktime_get_real_seconds() + afs_volume_record_life; |
| 36 | volume->cell = afs_get_cell(params->cell); |
| 37 | volume->type = params->type; |
| 38 | volume->type_force = params->force; |
| 39 | volume->name_len = vldb->name_len; |
| 40 | |
| 41 | atomic_set(&volume->usage, 1); |
| 42 | INIT_LIST_HEAD(&volume->proc_link); |
| 43 | rwlock_init(&volume->servers_lock); |
David Howells | 90fa9b6 | 2019-06-20 16:49:35 +0100 | [diff] [blame] | 44 | rwlock_init(&volume->cb_v_break_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 45 | memcpy(volume->name, vldb->name, vldb->name_len + 1); |
| 46 | |
| 47 | slist = afs_alloc_server_list(params->cell, params->key, vldb, type_mask); |
| 48 | if (IS_ERR(slist)) { |
| 49 | ret = PTR_ERR(slist); |
| 50 | goto error_1; |
| 51 | } |
| 52 | |
| 53 | refcount_set(&slist->usage, 1); |
David Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 54 | rcu_assign_pointer(volume->servers, slist); |
David Howells | cca37d4 | 2020-04-29 17:02:04 +0100 | [diff] [blame^] | 55 | trace_afs_volume(volume->vid, 1, afs_volume_trace_alloc); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 56 | return volume; |
| 57 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 58 | error_1: |
David Howells | e441501 | 2018-02-06 09:26:27 +0000 | [diff] [blame] | 59 | afs_put_cell(params->net, volume->cell); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 60 | kfree(volume); |
| 61 | error_0: |
| 62 | return ERR_PTR(ret); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Look up a VLDB record for a volume. |
| 67 | */ |
| 68 | static struct afs_vldb_entry *afs_vl_lookup_vldb(struct afs_cell *cell, |
| 69 | struct key *key, |
| 70 | const char *volname, |
| 71 | size_t volnamesz) |
| 72 | { |
David Howells | 0a5143f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 73 | struct afs_vldb_entry *vldb = ERR_PTR(-EDESTADDRREQ); |
| 74 | struct afs_vl_cursor vc; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 75 | int ret; |
| 76 | |
David Howells | 0a5143f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 77 | if (!afs_begin_vlserver_operation(&vc, cell, key)) |
| 78 | return ERR_PTR(-ERESTARTSYS); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 79 | |
David Howells | 0a5143f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 80 | while (afs_select_vlserver(&vc)) { |
David Howells | 0a5143f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 81 | vldb = afs_vl_get_entry_by_name_u(&vc, volname, volnamesz); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 82 | } |
| 83 | |
David Howells | 0a5143f | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 84 | ret = afs_end_vlserver_operation(&vc); |
| 85 | return ret < 0 ? ERR_PTR(ret) : vldb; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Look up a volume in the VL server and create a candidate volume record for |
| 90 | * it. |
| 91 | * |
| 92 | * The volume name can be one of the following: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | * "%[cell:]volume[.]" R/W volume |
| 94 | * "#[cell:]volume[.]" R/O or R/W volume (rwparent=0), |
| 95 | * or R/W (rwparent=1) volume |
| 96 | * "%[cell:]volume.readonly" R/O volume |
| 97 | * "#[cell:]volume.readonly" R/O volume |
| 98 | * "%[cell:]volume.backup" Backup volume |
| 99 | * "#[cell:]volume.backup" Backup volume |
| 100 | * |
| 101 | * The cell name is optional, and defaults to the current cell. |
| 102 | * |
| 103 | * See "The Rules of Mount Point Traversal" in Chapter 5 of the AFS SysAdmin |
| 104 | * Guide |
| 105 | * - Rule 1: Explicit type suffix forces access of that type or nothing |
| 106 | * (no suffix, then use Rule 2 & 3) |
| 107 | * - Rule 2: If parent volume is R/O, then mount R/O volume by preference, R/W |
| 108 | * if not available |
| 109 | * - Rule 3: If parent volume is R/W, then only mount R/W volume unless |
| 110 | * explicitly told otherwise |
| 111 | */ |
David Howells | 13fcc68 | 2018-11-01 23:07:27 +0000 | [diff] [blame] | 112 | struct afs_volume *afs_create_volume(struct afs_fs_context *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 114 | struct afs_vldb_entry *vldb; |
| 115 | struct afs_volume *volume; |
| 116 | unsigned long type_mask = 1UL << params->type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 118 | vldb = afs_vl_lookup_vldb(params->cell, params->key, |
| 119 | params->volname, params->volnamesz); |
| 120 | if (IS_ERR(vldb)) |
| 121 | return ERR_CAST(vldb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 123 | if (test_bit(AFS_VLDB_QUERY_ERROR, &vldb->flags)) { |
| 124 | volume = ERR_PTR(vldb->error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 128 | /* Make the final decision on the type we want */ |
| 129 | volume = ERR_PTR(-ENOMEDIUM); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 130 | if (params->force) { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 131 | if (!(vldb->flags & type_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | goto error; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 133 | } else if (test_bit(AFS_VLDB_HAS_RO, &vldb->flags)) { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 134 | params->type = AFSVL_ROVOL; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 135 | } else if (test_bit(AFS_VLDB_HAS_RW, &vldb->flags)) { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 136 | params->type = AFSVL_RWVOL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 137 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | goto error; |
| 139 | } |
| 140 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 141 | type_mask = 1UL << params->type; |
| 142 | volume = afs_alloc_volume(params, vldb, type_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 144 | error: |
| 145 | kfree(vldb); |
| 146 | return volume; |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Destroy a volume record |
| 151 | */ |
| 152 | static void afs_destroy_volume(struct afs_net *net, struct afs_volume *volume) |
| 153 | { |
| 154 | _enter("%p", volume); |
| 155 | |
| 156 | #ifdef CONFIG_AFS_FSCACHE |
| 157 | ASSERTCMP(volume->cache, ==, NULL); |
| 158 | #endif |
| 159 | |
David Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 160 | afs_put_serverlist(net, rcu_access_pointer(volume->servers)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 161 | afs_put_cell(net, volume->cell); |
David Howells | cca37d4 | 2020-04-29 17:02:04 +0100 | [diff] [blame^] | 162 | trace_afs_volume(volume->vid, atomic_read(&volume->usage), |
| 163 | afs_volume_trace_free); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 164 | kfree(volume); |
| 165 | |
| 166 | _leave(" [destroyed]"); |
| 167 | } |
| 168 | |
| 169 | /* |
David Howells | cca37d4 | 2020-04-29 17:02:04 +0100 | [diff] [blame^] | 170 | * Get a reference on a volume record. |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 171 | */ |
David Howells | cca37d4 | 2020-04-29 17:02:04 +0100 | [diff] [blame^] | 172 | struct afs_volume *afs_get_volume(struct afs_volume *volume, |
| 173 | enum afs_volume_trace reason) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 174 | { |
| 175 | if (volume) { |
David Howells | cca37d4 | 2020-04-29 17:02:04 +0100 | [diff] [blame^] | 176 | int u = atomic_inc_return(&volume->usage); |
| 177 | trace_afs_volume(volume->vid, u, reason); |
| 178 | } |
| 179 | return volume; |
| 180 | } |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 181 | |
David Howells | cca37d4 | 2020-04-29 17:02:04 +0100 | [diff] [blame^] | 182 | |
| 183 | /* |
| 184 | * Drop a reference on a volume record. |
| 185 | */ |
| 186 | void afs_put_volume(struct afs_net *net, struct afs_volume *volume, |
| 187 | enum afs_volume_trace reason) |
| 188 | { |
| 189 | if (volume) { |
| 190 | afs_volid_t vid = volume->vid; |
| 191 | int u = atomic_dec_return(&volume->usage); |
| 192 | trace_afs_volume(vid, u, reason); |
| 193 | if (u == 0) |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 194 | afs_destroy_volume(net, volume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 198 | /* |
| 199 | * Activate a volume. |
| 200 | */ |
| 201 | void afs_activate_volume(struct afs_volume *volume) |
| 202 | { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 203 | #ifdef CONFIG_AFS_FSCACHE |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 204 | volume->cache = fscache_acquire_cookie(volume->cell->cache, |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 205 | &afs_volume_cache_index_def, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 206 | &volume->vid, sizeof(volume->vid), |
| 207 | NULL, 0, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 208 | volume, 0, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 211 | write_lock(&volume->cell->proc_lock); |
| 212 | list_add_tail(&volume->proc_link, &volume->cell->proc_volumes); |
| 213 | write_unlock(&volume->cell->proc_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 217 | * Deactivate a volume. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 219 | void afs_deactivate_volume(struct afs_volume *volume) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 221 | _enter("%s", volume->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 223 | write_lock(&volume->cell->proc_lock); |
| 224 | list_del_init(&volume->proc_link); |
| 225 | write_unlock(&volume->cell->proc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 227 | #ifdef CONFIG_AFS_FSCACHE |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 228 | fscache_relinquish_cookie(volume->cache, NULL, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 229 | test_bit(AFS_VOLUME_DELETED, &volume->flags)); |
| 230 | volume->cache = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 233 | _leave(""); |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Query the VL service to update the volume status. |
| 238 | */ |
| 239 | static int afs_update_volume_status(struct afs_volume *volume, struct key *key) |
| 240 | { |
| 241 | struct afs_server_list *new, *old, *discard; |
| 242 | struct afs_vldb_entry *vldb; |
| 243 | char idbuf[16]; |
| 244 | int ret, idsz; |
| 245 | |
| 246 | _enter(""); |
| 247 | |
| 248 | /* We look up an ID by passing it as a decimal string in the |
| 249 | * operation's name parameter. |
| 250 | */ |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 251 | idsz = sprintf(idbuf, "%llu", volume->vid); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 252 | |
| 253 | vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz); |
| 254 | if (IS_ERR(vldb)) { |
| 255 | ret = PTR_ERR(vldb); |
| 256 | goto error; |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 259 | /* See if the volume got renamed. */ |
| 260 | if (vldb->name_len != volume->name_len || |
| 261 | memcmp(vldb->name, volume->name, vldb->name_len) != 0) { |
| 262 | /* TODO: Use RCU'd string. */ |
| 263 | memcpy(volume->name, vldb->name, AFS_MAXVOLNAME); |
| 264 | volume->name_len = vldb->name_len; |
| 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 267 | /* See if the volume's server list got updated. */ |
| 268 | new = afs_alloc_server_list(volume->cell, key, |
David Howells | 45df846 | 2018-02-06 14:12:32 +0000 | [diff] [blame] | 269 | vldb, (1 << volume->type)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 270 | if (IS_ERR(new)) { |
| 271 | ret = PTR_ERR(new); |
| 272 | goto error_vldb; |
| 273 | } |
| 274 | |
| 275 | write_lock(&volume->servers_lock); |
| 276 | |
| 277 | discard = new; |
David Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 278 | old = rcu_dereference_protected(volume->servers, |
| 279 | lockdep_is_held(&volume->servers_lock)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 280 | if (afs_annotate_server_list(new, old)) { |
| 281 | new->seq = volume->servers_seq + 1; |
David Howells | 8a070a9 | 2020-04-25 10:26:02 +0100 | [diff] [blame] | 282 | rcu_assign_pointer(volume->servers, new); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 283 | smp_wmb(); |
| 284 | volume->servers_seq++; |
| 285 | discard = old; |
| 286 | } |
| 287 | |
| 288 | volume->update_at = ktime_get_real_seconds() + afs_volume_record_life; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 289 | write_unlock(&volume->servers_lock); |
| 290 | ret = 0; |
| 291 | |
| 292 | afs_put_serverlist(volume->cell->net, discard); |
| 293 | error_vldb: |
| 294 | kfree(vldb); |
| 295 | error: |
| 296 | _leave(" = %d", ret); |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * Make sure the volume record is up to date. |
| 302 | */ |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 303 | int afs_check_volume_status(struct afs_volume *volume, struct afs_operation *op) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 304 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 305 | int ret, retries = 0; |
| 306 | |
| 307 | _enter(""); |
| 308 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 309 | retry: |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 310 | if (test_bit(AFS_VOLUME_WAIT, &volume->flags)) |
| 311 | goto wait; |
| 312 | if (volume->update_at <= ktime_get_real_seconds() || |
| 313 | test_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags)) |
| 314 | goto update; |
| 315 | _leave(" = 0"); |
| 316 | return 0; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 317 | |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 318 | update: |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 319 | if (!test_and_set_bit_lock(AFS_VOLUME_UPDATING, &volume->flags)) { |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 320 | clear_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags); |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 321 | ret = afs_update_volume_status(volume, op->key); |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 322 | if (ret < 0) |
| 323 | set_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 324 | clear_bit_unlock(AFS_VOLUME_WAIT, &volume->flags); |
| 325 | clear_bit_unlock(AFS_VOLUME_UPDATING, &volume->flags); |
| 326 | wake_up_bit(&volume->flags, AFS_VOLUME_WAIT); |
| 327 | _leave(" = %d", ret); |
| 328 | return ret; |
| 329 | } |
| 330 | |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 331 | wait: |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 332 | if (!test_bit(AFS_VOLUME_WAIT, &volume->flags)) { |
| 333 | _leave(" = 0 [no wait]"); |
| 334 | return 0; |
| 335 | } |
| 336 | |
David Howells | c4bfda1 | 2020-04-16 18:17:13 +0100 | [diff] [blame] | 337 | ret = wait_on_bit(&volume->flags, AFS_VOLUME_WAIT, |
David Howells | e49c7b2 | 2020-04-10 20:51:51 +0100 | [diff] [blame] | 338 | (op->flags & AFS_OPERATION_UNINTR) ? |
| 339 | TASK_UNINTERRUPTIBLE : TASK_INTERRUPTIBLE); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 340 | if (ret == -ERESTARTSYS) { |
| 341 | _leave(" = %d", ret); |
| 342 | return ret; |
| 343 | } |
| 344 | |
| 345 | retries++; |
| 346 | if (retries == 4) { |
| 347 | _leave(" = -ESTALE"); |
| 348 | return -ESTALE; |
| 349 | } |
| 350 | goto retry; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 351 | } |