David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 1 | /* AFS volume location management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 3 | * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "internal.h" |
| 16 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 17 | unsigned afs_vlocation_timeout = 10; /* volume location timeout in seconds */ |
| 18 | unsigned afs_vlocation_update_timeout = 10 * 60; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 20 | static void afs_vlocation_reaper(struct work_struct *); |
| 21 | static void afs_vlocation_updater(struct work_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 23 | static LIST_HEAD(afs_vlocation_updates); |
| 24 | static LIST_HEAD(afs_vlocation_graveyard); |
| 25 | static DEFINE_SPINLOCK(afs_vlocation_updates_lock); |
| 26 | static DEFINE_SPINLOCK(afs_vlocation_graveyard_lock); |
| 27 | static DECLARE_DELAYED_WORK(afs_vlocation_reap, afs_vlocation_reaper); |
| 28 | static DECLARE_DELAYED_WORK(afs_vlocation_update, afs_vlocation_updater); |
| 29 | static struct workqueue_struct *afs_vlocation_update_worker; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* |
| 32 | * iterate through the VL servers in a cell until one of them admits knowing |
| 33 | * about the volume in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 35 | static int afs_vlocation_access_vl_by_name(struct afs_vlocation *vl, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 36 | struct key *key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | struct afs_cache_vlocation *vldb) |
| 38 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 39 | struct afs_cell *cell = vl->cell; |
| 40 | struct in_addr addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | int count, ret; |
| 42 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 43 | _enter("%s,%s", cell->name, vl->vldb.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 45 | down_write(&vl->cell->vl_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | ret = -ENOMEDIUM; |
| 47 | for (count = cell->vl_naddrs; count > 0; count--) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 48 | addr = cell->vl_addrs[cell->vl_curr_svix]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 50 | _debug("CellServ[%hu]: %08x", cell->vl_curr_svix, addr.s_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* attempt to access the VL server */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 53 | ret = afs_vl_get_entry_by_name(&addr, key, vl->vldb.name, vldb, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 54 | &afs_sync_call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | switch (ret) { |
| 56 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | goto out; |
| 58 | case -ENOMEM: |
| 59 | case -ENONET: |
| 60 | case -ENETUNREACH: |
| 61 | case -EHOSTUNREACH: |
| 62 | case -ECONNREFUSED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (ret == -ENOMEM || ret == -ENONET) |
| 64 | goto out; |
| 65 | goto rotate; |
| 66 | case -ENOMEDIUM: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | goto out; |
| 68 | default: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 69 | ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | goto rotate; |
| 71 | } |
| 72 | |
| 73 | /* rotate the server records upon lookup failure */ |
| 74 | rotate: |
| 75 | cell->vl_curr_svix++; |
| 76 | cell->vl_curr_svix %= cell->vl_naddrs; |
| 77 | } |
| 78 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 79 | out: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 80 | up_write(&vl->cell->vl_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | _leave(" = %d", ret); |
| 82 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 83 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* |
| 86 | * iterate through the VL servers in a cell until one of them admits knowing |
| 87 | * about the volume in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 89 | static int afs_vlocation_access_vl_by_id(struct afs_vlocation *vl, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 90 | struct key *key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | afs_volid_t volid, |
| 92 | afs_voltype_t voltype, |
| 93 | struct afs_cache_vlocation *vldb) |
| 94 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 95 | struct afs_cell *cell = vl->cell; |
| 96 | struct in_addr addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | int count, ret; |
| 98 | |
| 99 | _enter("%s,%x,%d,", cell->name, volid, voltype); |
| 100 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 101 | down_write(&vl->cell->vl_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | ret = -ENOMEDIUM; |
| 103 | for (count = cell->vl_naddrs; count > 0; count--) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 104 | addr = cell->vl_addrs[cell->vl_curr_svix]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 106 | _debug("CellServ[%hu]: %08x", cell->vl_curr_svix, addr.s_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | /* attempt to access the VL server */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 109 | ret = afs_vl_get_entry_by_id(&addr, key, volid, voltype, vldb, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 110 | &afs_sync_call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | switch (ret) { |
| 112 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | goto out; |
| 114 | case -ENOMEM: |
| 115 | case -ENONET: |
| 116 | case -ENETUNREACH: |
| 117 | case -EHOSTUNREACH: |
| 118 | case -ECONNREFUSED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | if (ret == -ENOMEM || ret == -ENONET) |
| 120 | goto out; |
| 121 | goto rotate; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 122 | case -EBUSY: |
| 123 | vl->upd_busy_cnt++; |
| 124 | if (vl->upd_busy_cnt <= 3) { |
| 125 | if (vl->upd_busy_cnt > 1) { |
| 126 | /* second+ BUSY - sleep a little bit */ |
| 127 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 128 | schedule_timeout(1); |
| 129 | __set_current_state(TASK_RUNNING); |
| 130 | } |
| 131 | continue; |
| 132 | } |
| 133 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | case -ENOMEDIUM: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 135 | vl->upd_rej_cnt++; |
| 136 | goto rotate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | default: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 138 | ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | goto rotate; |
| 140 | } |
| 141 | |
| 142 | /* rotate the server records upon lookup failure */ |
| 143 | rotate: |
| 144 | cell->vl_curr_svix++; |
| 145 | cell->vl_curr_svix %= cell->vl_naddrs; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 146 | vl->upd_busy_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 149 | out: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 150 | if (ret < 0 && vl->upd_rej_cnt > 0) { |
| 151 | printk(KERN_NOTICE "kAFS:" |
| 152 | " Active volume no longer valid '%s'\n", |
| 153 | vl->vldb.name); |
| 154 | vl->valid = 0; |
| 155 | ret = -ENOMEDIUM; |
| 156 | } |
| 157 | |
| 158 | up_write(&vl->cell->vl_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | _leave(" = %d", ret); |
| 160 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 164 | * allocate a volume location record |
| 165 | */ |
| 166 | static struct afs_vlocation *afs_vlocation_alloc(struct afs_cell *cell, |
| 167 | const char *name, |
| 168 | size_t namesz) |
| 169 | { |
| 170 | struct afs_vlocation *vl; |
| 171 | |
| 172 | vl = kzalloc(sizeof(struct afs_vlocation), GFP_KERNEL); |
| 173 | if (vl) { |
| 174 | vl->cell = cell; |
| 175 | vl->state = AFS_VL_NEW; |
| 176 | atomic_set(&vl->usage, 1); |
| 177 | INIT_LIST_HEAD(&vl->link); |
| 178 | INIT_LIST_HEAD(&vl->grave); |
| 179 | INIT_LIST_HEAD(&vl->update); |
| 180 | init_waitqueue_head(&vl->waitq); |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 181 | spin_lock_init(&vl->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 182 | memcpy(vl->vldb.name, name, namesz); |
| 183 | } |
| 184 | |
| 185 | _leave(" = %p", vl); |
| 186 | return vl; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * update record if we found it in the cache |
| 191 | */ |
| 192 | static int afs_vlocation_update_record(struct afs_vlocation *vl, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 193 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 194 | struct afs_cache_vlocation *vldb) |
| 195 | { |
| 196 | afs_voltype_t voltype; |
| 197 | afs_volid_t vid; |
| 198 | int ret; |
| 199 | |
| 200 | /* try to look up a cached volume in the cell VL databases by ID */ |
| 201 | _debug("Locally Cached: %s %02x { %08x(%x) %08x(%x) %08x(%x) }", |
| 202 | vl->vldb.name, |
| 203 | vl->vldb.vidmask, |
| 204 | ntohl(vl->vldb.servers[0].s_addr), |
| 205 | vl->vldb.srvtmask[0], |
| 206 | ntohl(vl->vldb.servers[1].s_addr), |
| 207 | vl->vldb.srvtmask[1], |
| 208 | ntohl(vl->vldb.servers[2].s_addr), |
| 209 | vl->vldb.srvtmask[2]); |
| 210 | |
| 211 | _debug("Vids: %08x %08x %08x", |
| 212 | vl->vldb.vid[0], |
| 213 | vl->vldb.vid[1], |
| 214 | vl->vldb.vid[2]); |
| 215 | |
| 216 | if (vl->vldb.vidmask & AFS_VOL_VTM_RW) { |
| 217 | vid = vl->vldb.vid[0]; |
| 218 | voltype = AFSVL_RWVOL; |
| 219 | } else if (vl->vldb.vidmask & AFS_VOL_VTM_RO) { |
| 220 | vid = vl->vldb.vid[1]; |
| 221 | voltype = AFSVL_ROVOL; |
| 222 | } else if (vl->vldb.vidmask & AFS_VOL_VTM_BAK) { |
| 223 | vid = vl->vldb.vid[2]; |
| 224 | voltype = AFSVL_BACKVOL; |
| 225 | } else { |
| 226 | BUG(); |
| 227 | vid = 0; |
| 228 | voltype = 0; |
| 229 | } |
| 230 | |
| 231 | /* contact the server to make sure the volume is still available |
| 232 | * - TODO: need to handle disconnected operation here |
| 233 | */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 234 | ret = afs_vlocation_access_vl_by_id(vl, key, vid, voltype, vldb); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 235 | switch (ret) { |
| 236 | /* net error */ |
| 237 | default: |
| 238 | printk(KERN_WARNING "kAFS:" |
| 239 | " failed to update volume '%s' (%x) up in '%s': %d\n", |
| 240 | vl->vldb.name, vid, vl->cell->name, ret); |
| 241 | _leave(" = %d", ret); |
| 242 | return ret; |
| 243 | |
| 244 | /* pulled from local cache into memory */ |
| 245 | case 0: |
| 246 | _leave(" = 0"); |
| 247 | return 0; |
| 248 | |
| 249 | /* uh oh... looks like the volume got deleted */ |
| 250 | case -ENOMEDIUM: |
| 251 | printk(KERN_ERR "kAFS:" |
| 252 | " volume '%s' (%x) does not exist '%s'\n", |
| 253 | vl->vldb.name, vid, vl->cell->name); |
| 254 | |
| 255 | /* TODO: make existing record unavailable */ |
| 256 | _leave(" = %d", ret); |
| 257 | return ret; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * apply the update to a VL record |
| 263 | */ |
| 264 | static void afs_vlocation_apply_update(struct afs_vlocation *vl, |
| 265 | struct afs_cache_vlocation *vldb) |
| 266 | { |
| 267 | _debug("Done VL Lookup: %s %02x { %08x(%x) %08x(%x) %08x(%x) }", |
| 268 | vldb->name, vldb->vidmask, |
| 269 | ntohl(vldb->servers[0].s_addr), vldb->srvtmask[0], |
| 270 | ntohl(vldb->servers[1].s_addr), vldb->srvtmask[1], |
| 271 | ntohl(vldb->servers[2].s_addr), vldb->srvtmask[2]); |
| 272 | |
| 273 | _debug("Vids: %08x %08x %08x", |
| 274 | vldb->vid[0], vldb->vid[1], vldb->vid[2]); |
| 275 | |
| 276 | if (strcmp(vldb->name, vl->vldb.name) != 0) |
| 277 | printk(KERN_NOTICE "kAFS:" |
| 278 | " name of volume '%s' changed to '%s' on server\n", |
| 279 | vl->vldb.name, vldb->name); |
| 280 | |
| 281 | vl->vldb = *vldb; |
| 282 | |
| 283 | #ifdef AFS_CACHING_SUPPORT |
| 284 | /* update volume entry in local cache */ |
| 285 | cachefs_update_cookie(vl->cache); |
| 286 | #endif |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * fill in a volume location record, consulting the cache and the VL server |
| 291 | * both |
| 292 | */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 293 | static int afs_vlocation_fill_in_record(struct afs_vlocation *vl, |
| 294 | struct key *key) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 295 | { |
| 296 | struct afs_cache_vlocation vldb; |
| 297 | int ret; |
| 298 | |
| 299 | _enter(""); |
| 300 | |
| 301 | ASSERTCMP(vl->valid, ==, 0); |
| 302 | |
| 303 | memset(&vldb, 0, sizeof(vldb)); |
| 304 | |
| 305 | /* see if we have an in-cache copy (will set vl->valid if there is) */ |
| 306 | #ifdef AFS_CACHING_SUPPORT |
| 307 | cachefs_acquire_cookie(cell->cache, |
| 308 | &afs_volume_cache_index_def, |
| 309 | vlocation, |
| 310 | &vl->cache); |
| 311 | #endif |
| 312 | |
| 313 | if (vl->valid) { |
| 314 | /* try to update a known volume in the cell VL databases by |
| 315 | * ID as the name may have changed */ |
| 316 | _debug("found in cache"); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 317 | ret = afs_vlocation_update_record(vl, key, &vldb); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 318 | } else { |
| 319 | /* try to look up an unknown volume in the cell VL databases by |
| 320 | * name */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 321 | ret = afs_vlocation_access_vl_by_name(vl, key, &vldb); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 322 | if (ret < 0) { |
| 323 | printk("kAFS: failed to locate '%s' in cell '%s'\n", |
| 324 | vl->vldb.name, vl->cell->name); |
| 325 | return ret; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | afs_vlocation_apply_update(vl, &vldb); |
| 330 | _leave(" = 0"); |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * queue a vlocation record for updates |
| 336 | */ |
| 337 | void afs_vlocation_queue_for_updates(struct afs_vlocation *vl) |
| 338 | { |
| 339 | struct afs_vlocation *xvl; |
| 340 | |
| 341 | /* wait at least 10 minutes before updating... */ |
| 342 | vl->update_at = get_seconds() + afs_vlocation_update_timeout; |
| 343 | |
| 344 | spin_lock(&afs_vlocation_updates_lock); |
| 345 | |
| 346 | if (!list_empty(&afs_vlocation_updates)) { |
| 347 | /* ... but wait at least 1 second more than the newest record |
| 348 | * already queued so that we don't spam the VL server suddenly |
| 349 | * with lots of requests |
| 350 | */ |
| 351 | xvl = list_entry(afs_vlocation_updates.prev, |
| 352 | struct afs_vlocation, update); |
| 353 | if (vl->update_at <= xvl->update_at) |
| 354 | vl->update_at = xvl->update_at + 1; |
| 355 | } else { |
| 356 | queue_delayed_work(afs_vlocation_update_worker, |
| 357 | &afs_vlocation_update, |
| 358 | afs_vlocation_update_timeout * HZ); |
| 359 | } |
| 360 | |
| 361 | list_add_tail(&vl->update, &afs_vlocation_updates); |
| 362 | spin_unlock(&afs_vlocation_updates_lock); |
| 363 | } |
| 364 | |
| 365 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | * lookup volume location |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * - iterate through the VL servers in a cell until one of them admits knowing |
| 368 | * about the volume in question |
| 369 | * - lookup in the local cache if not able to find on the VL server |
| 370 | * - insert/update in the local cache if did get a VL response |
| 371 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 372 | struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *cell, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 373 | struct key *key, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 374 | const char *name, |
| 375 | size_t namesz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 377 | struct afs_vlocation *vl; |
| 378 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 380 | _enter("{%s},{%x},%*.*s,%zu", |
| 381 | cell->name, key_serial(key), |
| 382 | (int) namesz, (int) namesz, name, namesz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 384 | if (namesz > sizeof(vl->vldb.name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | _leave(" = -ENAMETOOLONG"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 386 | return ERR_PTR(-ENAMETOOLONG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 389 | /* see if we have an in-memory copy first */ |
| 390 | down_write(&cell->vl_sem); |
| 391 | spin_lock(&cell->vl_lock); |
| 392 | list_for_each_entry(vl, &cell->vl_list, link) { |
| 393 | if (vl->vldb.name[namesz] != '\0') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | continue; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 395 | if (memcmp(vl->vldb.name, name, namesz) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | goto found_in_memory; |
| 397 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 398 | spin_unlock(&cell->vl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | /* not in the cell's in-memory lists - create a new record */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 401 | vl = afs_vlocation_alloc(cell, name, namesz); |
| 402 | if (!vl) { |
| 403 | up_write(&cell->vl_sem); |
| 404 | return ERR_PTR(-ENOMEM); |
| 405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | afs_get_cell(cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 409 | list_add_tail(&vl->link, &cell->vl_list); |
| 410 | vl->state = AFS_VL_CREATING; |
| 411 | up_write(&cell->vl_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 413 | fill_in_record: |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 414 | ret = afs_vlocation_fill_in_record(vl, key); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 415 | if (ret < 0) |
| 416 | goto error_abandon; |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 417 | spin_lock(&vl->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 418 | vl->state = AFS_VL_VALID; |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 419 | spin_unlock(&vl->lock); |
David Howells | 47051a2 | 2007-04-27 15:26:30 -0700 | [diff] [blame] | 420 | wake_up(&vl->waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 422 | /* schedule for regular updates */ |
| 423 | afs_vlocation_queue_for_updates(vl); |
| 424 | goto success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 426 | found_in_memory: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 427 | /* found in memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | _debug("found in memory"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 429 | atomic_inc(&vl->usage); |
| 430 | spin_unlock(&cell->vl_lock); |
| 431 | if (!list_empty(&vl->grave)) { |
| 432 | spin_lock(&afs_vlocation_graveyard_lock); |
| 433 | list_del_init(&vl->grave); |
| 434 | spin_unlock(&afs_vlocation_graveyard_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 436 | up_write(&cell->vl_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 438 | /* see if it was an abandoned record that we might try filling in */ |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 439 | spin_lock(&vl->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 440 | while (vl->state != AFS_VL_VALID) { |
| 441 | afs_vlocation_state_t state = vl->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 443 | _debug("invalid [state %d]", state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
David Howells | 47051a2 | 2007-04-27 15:26:30 -0700 | [diff] [blame] | 445 | if (state == AFS_VL_NEW || state == AFS_VL_NO_VOLUME) { |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 446 | vl->state = AFS_VL_CREATING; |
| 447 | spin_unlock(&vl->lock); |
| 448 | goto fill_in_record; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 451 | /* must now wait for creation or update by someone else to |
| 452 | * complete */ |
| 453 | _debug("wait"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 455 | spin_unlock(&vl->lock); |
David Howells | 47051a2 | 2007-04-27 15:26:30 -0700 | [diff] [blame] | 456 | ret = wait_event_interruptible(vl->waitq, |
| 457 | vl->state == AFS_VL_NEW || |
| 458 | vl->state == AFS_VL_VALID || |
| 459 | vl->state == AFS_VL_NO_VOLUME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 461 | goto error; |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 462 | spin_lock(&vl->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 464 | spin_unlock(&vl->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 466 | success: |
| 467 | _leave(" = %p",vl); |
| 468 | return vl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 470 | error_abandon: |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 471 | spin_lock(&vl->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 472 | vl->state = AFS_VL_NEW; |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 473 | spin_unlock(&vl->lock); |
David Howells | 47051a2 | 2007-04-27 15:26:30 -0700 | [diff] [blame] | 474 | wake_up(&vl->waitq); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 475 | error: |
| 476 | ASSERT(vl != NULL); |
| 477 | afs_put_vlocation(vl); |
| 478 | _leave(" = %d", ret); |
| 479 | return ERR_PTR(ret); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 483 | * finish using a volume location record |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 485 | void afs_put_vlocation(struct afs_vlocation *vl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 487 | if (!vl) |
| 488 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 490 | _enter("%s", vl->vldb.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 492 | ASSERTCMP(atomic_read(&vl->usage), >, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 494 | if (likely(!atomic_dec_and_test(&vl->usage))) { |
| 495 | _leave(""); |
| 496 | return; |
| 497 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 499 | spin_lock(&afs_vlocation_graveyard_lock); |
| 500 | if (atomic_read(&vl->usage) == 0) { |
| 501 | _debug("buried"); |
| 502 | list_move_tail(&vl->grave, &afs_vlocation_graveyard); |
| 503 | vl->time_of_death = get_seconds(); |
| 504 | schedule_delayed_work(&afs_vlocation_reap, |
| 505 | afs_vlocation_timeout * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 507 | /* suspend updates on this record */ |
| 508 | if (!list_empty(&vl->update)) { |
| 509 | spin_lock(&afs_vlocation_updates_lock); |
| 510 | list_del_init(&vl->update); |
| 511 | spin_unlock(&afs_vlocation_updates_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 514 | spin_unlock(&afs_vlocation_graveyard_lock); |
| 515 | _leave(" [killed?]"); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 519 | * destroy a dead volume location record |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 521 | static void afs_vlocation_destroy(struct afs_vlocation *vl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 523 | _enter("%p", vl); |
| 524 | |
| 525 | #ifdef AFS_CACHING_SUPPORT |
| 526 | cachefs_relinquish_cookie(vl->cache, 0); |
| 527 | #endif |
| 528 | |
| 529 | afs_put_cell(vl->cell); |
| 530 | kfree(vl); |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | * reap dead volume location records |
| 535 | */ |
| 536 | static void afs_vlocation_reaper(struct work_struct *work) |
| 537 | { |
| 538 | LIST_HEAD(corpses); |
| 539 | struct afs_vlocation *vl; |
| 540 | unsigned long delay, expiry; |
| 541 | time_t now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | _enter(""); |
| 544 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 545 | now = get_seconds(); |
| 546 | spin_lock(&afs_vlocation_graveyard_lock); |
| 547 | |
| 548 | while (!list_empty(&afs_vlocation_graveyard)) { |
| 549 | vl = list_entry(afs_vlocation_graveyard.next, |
| 550 | struct afs_vlocation, grave); |
| 551 | |
| 552 | _debug("check %p", vl); |
| 553 | |
| 554 | /* the queue is ordered most dead first */ |
| 555 | expiry = vl->time_of_death + afs_vlocation_timeout; |
| 556 | if (expiry > now) { |
| 557 | delay = (expiry - now) * HZ; |
| 558 | _debug("delay %lu", delay); |
| 559 | if (!schedule_delayed_work(&afs_vlocation_reap, |
| 560 | delay)) { |
| 561 | cancel_delayed_work(&afs_vlocation_reap); |
| 562 | schedule_delayed_work(&afs_vlocation_reap, |
| 563 | delay); |
| 564 | } |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | spin_lock(&vl->cell->vl_lock); |
| 569 | if (atomic_read(&vl->usage) > 0) { |
| 570 | _debug("no reap"); |
| 571 | list_del_init(&vl->grave); |
| 572 | } else { |
| 573 | _debug("reap"); |
| 574 | list_move_tail(&vl->grave, &corpses); |
| 575 | list_del_init(&vl->link); |
| 576 | } |
| 577 | spin_unlock(&vl->cell->vl_lock); |
| 578 | } |
| 579 | |
| 580 | spin_unlock(&afs_vlocation_graveyard_lock); |
| 581 | |
| 582 | /* now reap the corpses we've extracted */ |
| 583 | while (!list_empty(&corpses)) { |
| 584 | vl = list_entry(corpses.next, struct afs_vlocation, grave); |
| 585 | list_del(&vl->grave); |
| 586 | afs_vlocation_destroy(vl); |
| 587 | } |
| 588 | |
| 589 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 590 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 591 | |
| 592 | /* |
| 593 | * initialise the VL update process |
| 594 | */ |
| 595 | int __init afs_vlocation_update_init(void) |
| 596 | { |
| 597 | afs_vlocation_update_worker = |
| 598 | create_singlethread_workqueue("kafs_vlupdated"); |
| 599 | return afs_vlocation_update_worker ? 0 : -ENOMEM; |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | * discard all the volume location records for rmmod |
| 604 | */ |
David Howells | fbb3fcb | 2007-05-03 03:12:46 -0700 | [diff] [blame^] | 605 | void afs_vlocation_purge(void) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 606 | { |
| 607 | afs_vlocation_timeout = 0; |
| 608 | |
| 609 | spin_lock(&afs_vlocation_updates_lock); |
| 610 | list_del_init(&afs_vlocation_updates); |
| 611 | spin_unlock(&afs_vlocation_updates_lock); |
| 612 | cancel_delayed_work(&afs_vlocation_update); |
| 613 | queue_delayed_work(afs_vlocation_update_worker, |
| 614 | &afs_vlocation_update, 0); |
| 615 | destroy_workqueue(afs_vlocation_update_worker); |
| 616 | |
| 617 | cancel_delayed_work(&afs_vlocation_reap); |
| 618 | schedule_delayed_work(&afs_vlocation_reap, 0); |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * update a volume location |
| 623 | */ |
| 624 | static void afs_vlocation_updater(struct work_struct *work) |
| 625 | { |
| 626 | struct afs_cache_vlocation vldb; |
| 627 | struct afs_vlocation *vl, *xvl; |
| 628 | time_t now; |
| 629 | long timeout; |
| 630 | int ret; |
| 631 | |
| 632 | _enter(""); |
| 633 | |
| 634 | now = get_seconds(); |
| 635 | |
| 636 | /* find a record to update */ |
| 637 | spin_lock(&afs_vlocation_updates_lock); |
| 638 | for (;;) { |
| 639 | if (list_empty(&afs_vlocation_updates)) { |
| 640 | spin_unlock(&afs_vlocation_updates_lock); |
| 641 | _leave(" [nothing]"); |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | vl = list_entry(afs_vlocation_updates.next, |
| 646 | struct afs_vlocation, update); |
| 647 | if (atomic_read(&vl->usage) > 0) |
| 648 | break; |
| 649 | list_del_init(&vl->update); |
| 650 | } |
| 651 | |
| 652 | timeout = vl->update_at - now; |
| 653 | if (timeout > 0) { |
| 654 | queue_delayed_work(afs_vlocation_update_worker, |
| 655 | &afs_vlocation_update, timeout * HZ); |
| 656 | spin_unlock(&afs_vlocation_updates_lock); |
| 657 | _leave(" [nothing]"); |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | list_del_init(&vl->update); |
| 662 | atomic_inc(&vl->usage); |
| 663 | spin_unlock(&afs_vlocation_updates_lock); |
| 664 | |
| 665 | /* we can now perform the update */ |
| 666 | _debug("update %s", vl->vldb.name); |
| 667 | vl->state = AFS_VL_UPDATING; |
| 668 | vl->upd_rej_cnt = 0; |
| 669 | vl->upd_busy_cnt = 0; |
| 670 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 671 | ret = afs_vlocation_update_record(vl, NULL, &vldb); |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 672 | spin_lock(&vl->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 673 | switch (ret) { |
| 674 | case 0: |
| 675 | afs_vlocation_apply_update(vl, &vldb); |
| 676 | vl->state = AFS_VL_VALID; |
| 677 | break; |
| 678 | case -ENOMEDIUM: |
| 679 | vl->state = AFS_VL_VOLUME_DELETED; |
| 680 | break; |
| 681 | default: |
| 682 | vl->state = AFS_VL_UNCERTAIN; |
| 683 | break; |
| 684 | } |
David S. Miller | 39bf094 | 2007-04-26 20:39:14 -0700 | [diff] [blame] | 685 | spin_unlock(&vl->lock); |
David Howells | 47051a2 | 2007-04-27 15:26:30 -0700 | [diff] [blame] | 686 | wake_up(&vl->waitq); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 687 | |
| 688 | /* and then reschedule */ |
| 689 | _debug("reschedule"); |
| 690 | vl->update_at = get_seconds() + afs_vlocation_update_timeout; |
| 691 | |
| 692 | spin_lock(&afs_vlocation_updates_lock); |
| 693 | |
| 694 | if (!list_empty(&afs_vlocation_updates)) { |
| 695 | /* next update in 10 minutes, but wait at least 1 second more |
| 696 | * than the newest record already queued so that we don't spam |
| 697 | * the VL server suddenly with lots of requests |
| 698 | */ |
| 699 | xvl = list_entry(afs_vlocation_updates.prev, |
| 700 | struct afs_vlocation, update); |
| 701 | if (vl->update_at <= xvl->update_at) |
| 702 | vl->update_at = xvl->update_at + 1; |
| 703 | xvl = list_entry(afs_vlocation_updates.next, |
| 704 | struct afs_vlocation, update); |
| 705 | timeout = xvl->update_at - now; |
| 706 | if (timeout < 0) |
| 707 | timeout = 0; |
| 708 | } else { |
| 709 | timeout = afs_vlocation_update_timeout; |
| 710 | } |
| 711 | |
| 712 | ASSERT(list_empty(&vl->update)); |
| 713 | |
| 714 | list_add_tail(&vl->update, &afs_vlocation_updates); |
| 715 | |
| 716 | _debug("timeout %ld", timeout); |
| 717 | queue_delayed_work(afs_vlocation_update_worker, |
| 718 | &afs_vlocation_update, timeout * HZ); |
| 719 | spin_unlock(&afs_vlocation_updates_lock); |
| 720 | afs_put_vlocation(vl); |
| 721 | } |