12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
16 #include <linux/sched.h>
19 static unsigned afs_vlocation_timeout = 10;
20 static unsigned afs_vlocation_update_timeout = 10 * 60;
22 static void afs_vlocation_reaper(
struct work_struct *);
23 static void afs_vlocation_updater(
struct work_struct *);
26 static LIST_HEAD(afs_vlocation_graveyard);
49 for (count = cell->
vl_naddrs; count > 0; count--) {
93 static int afs_vlocation_access_vl_by_id(
struct afs_vlocation *vl,
96 afs_voltype_t voltype,
103 _enter(
"%s,%x,%d,", cell->
name, volid, voltype);
107 for (count = cell->
vl_naddrs; count > 0; count--) {
154 if (ret < 0 && vl->upd_rej_cnt > 0) {
156 " Active volume no longer valid '%s'\n",
181 INIT_LIST_HEAD(&vl->
link);
182 INIT_LIST_HEAD(&vl->
grave);
183 INIT_LIST_HEAD(&vl->
update);
196 static int afs_vlocation_update_record(
struct afs_vlocation *vl,
200 afs_voltype_t voltype;
205 _debug(
"Locally Cached: %s %02x { %08x(%x) %08x(%x) %08x(%x) }",
209 vl->
vldb.srvtmask[0],
211 vl->
vldb.srvtmask[1],
213 vl->
vldb.srvtmask[2]);
215 _debug(
"Vids: %08x %08x %08x",
221 vid = vl->
vldb.vid[0];
224 vid = vl->
vldb.vid[1];
227 vid = vl->
vldb.vid[2];
238 ret = afs_vlocation_access_vl_by_id(vl, key, vid, voltype, vldb);
243 " failed to update volume '%s' (%x) up in '%s': %d\n",
244 vl->
vldb.name, vid, vl->
cell->name, ret);
256 " volume '%s' (%x) does not exist '%s'\n",
257 vl->
vldb.name, vid, vl->
cell->name);
268 static void afs_vlocation_apply_update(
struct afs_vlocation *vl,
271 _debug(
"Done VL Lookup: %s %02x { %08x(%x) %08x(%x) %08x(%x) }",
277 _debug(
"Vids: %08x %08x %08x",
278 vldb->
vid[0], vldb->
vid[1], vldb->
vid[2]);
282 " name of volume '%s' changed to '%s' on server\n",
287 #ifdef CONFIG_AFS_FSCACHE
288 fscache_update_cookie(vl->cache);
296 static int afs_vlocation_fill_in_record(
struct afs_vlocation *vl,
306 memset(&vldb, 0,
sizeof(vldb));
309 #ifdef CONFIG_AFS_FSCACHE
310 vl->cache = fscache_acquire_cookie(vl->
cell->cache,
318 ret = afs_vlocation_update_record(vl, key, &vldb);
322 ret = afs_vlocation_access_vl_by_name(vl, key, &vldb);
324 printk(
"kAFS: failed to locate '%s' in cell '%s'\n",
330 afs_vlocation_apply_update(vl, &vldb);
338 static void afs_vlocation_queue_for_updates(
struct afs_vlocation *vl)
345 spin_lock(&afs_vlocation_updates_lock);
347 if (!list_empty(&afs_vlocation_updates)) {
358 &afs_vlocation_update,
359 afs_vlocation_update_timeout *
HZ);
363 spin_unlock(&afs_vlocation_updates_lock);
381 _enter(
"{%s},{%x},%*.*s,%zu",
382 cell->
name, key_serial(key),
383 (
int) namesz, (
int) namesz, name, namesz);
385 if (namesz >=
sizeof(vl->
vldb.name)) {
386 _leave(
" = -ENAMETOOLONG");
394 if (vl->
vldb.name[namesz] !=
'\0')
397 goto found_in_memory;
402 vl = afs_vlocation_alloc(cell, name, namesz);
415 ret = afs_vlocation_fill_in_record(vl, key);
418 spin_lock(&vl->
lock);
420 spin_unlock(&vl->
lock);
424 #ifdef CONFIG_AFS_FSCACHE
425 fscache_update_cookie(vl->cache);
429 afs_vlocation_queue_for_updates(vl);
434 _debug(
"found in memory");
437 if (!list_empty(&vl->
grave)) {
438 spin_lock(&afs_vlocation_graveyard_lock);
439 list_del_init(&vl->
grave);
440 spin_unlock(&afs_vlocation_graveyard_lock);
445 spin_lock(&vl->
lock);
449 _debug(
"invalid [state %d]", state);
453 spin_unlock(&vl->
lock);
461 spin_unlock(&vl->
lock);
468 spin_lock(&vl->
lock);
470 spin_unlock(&vl->
lock);
477 spin_lock(&vl->
lock);
479 spin_unlock(&vl->
lock);
505 spin_lock(&afs_vlocation_graveyard_lock);
508 list_move_tail(&vl->
grave, &afs_vlocation_graveyard);
511 afs_vlocation_timeout *
HZ);
514 if (!list_empty(&vl->
update)) {
515 spin_lock(&afs_vlocation_updates_lock);
516 list_del_init(&vl->
update);
517 spin_unlock(&afs_vlocation_updates_lock);
520 spin_unlock(&afs_vlocation_graveyard_lock);
531 #ifdef CONFIG_AFS_FSCACHE
532 fscache_relinquish_cookie(vl->cache, 0);
545 unsigned long delay, expiry;
551 spin_lock(&afs_vlocation_graveyard_lock);
553 while (!list_empty(&afs_vlocation_graveyard)) {
562 delay = (expiry - now) *
HZ;
563 _debug(
"delay %lu", delay);
568 spin_lock(&vl->
cell->vl_lock);
571 list_del_init(&vl->
grave);
574 list_move_tail(&vl->
grave, &corpses);
575 list_del_init(&vl->
link);
577 spin_unlock(&vl->
cell->vl_lock);
580 spin_unlock(&afs_vlocation_graveyard_lock);
583 while (!list_empty(&corpses)) {
586 afs_vlocation_destroy(vl);
597 afs_vlocation_update_worker =
599 return afs_vlocation_update_worker ? 0 : -
ENOMEM;
607 afs_vlocation_timeout = 0;
609 spin_lock(&afs_vlocation_updates_lock);
610 list_del_init(&afs_vlocation_updates);
611 spin_unlock(&afs_vlocation_updates_lock);
621 static void afs_vlocation_updater(
struct work_struct *work)
634 spin_lock(&afs_vlocation_updates_lock);
636 if (list_empty(&afs_vlocation_updates)) {
637 spin_unlock(&afs_vlocation_updates_lock);
646 list_del_init(&vl->
update);
652 &afs_vlocation_update, timeout *
HZ);
653 spin_unlock(&afs_vlocation_updates_lock);
658 list_del_init(&vl->
update);
660 spin_unlock(&afs_vlocation_updates_lock);
668 ret = afs_vlocation_update_record(vl,
NULL, &vldb);
669 spin_lock(&vl->
lock);
672 afs_vlocation_apply_update(vl, &vldb);
682 spin_unlock(&vl->
lock);
689 spin_lock(&afs_vlocation_updates_lock);
691 if (!list_empty(&afs_vlocation_updates)) {
706 timeout = afs_vlocation_update_timeout;
713 _debug(
"timeout %ld", timeout);
715 &afs_vlocation_update, timeout *
HZ);
716 spin_unlock(&afs_vlocation_updates_lock);