vlocation.c 18 KB

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