blob: ee07162d35c7a2b260dacbf6e6897e5230335dd9 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/* AFS cell and server record management
2 *
3 * Copyright (C) 2002, 2017 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
12#include <linux/slab.h>
13#include <linux/key.h>
14#include <linux/ctype.h>
15#include <linux/dns_resolver.h>
16#include <linux/sched.h>
17#include <linux/inet.h>
18#include <linux/namei.h>
19#include <keys/rxrpc-type.h>
20#include "internal.h"
21
22static unsigned __read_mostly afs_cell_gc_delay = 10;
23
24static void afs_manage_cell(struct work_struct *);
25
26static void afs_dec_cells_outstanding(struct afs_net *net)
27{
28 if (atomic_dec_and_test(&net->cells_outstanding))
29 wake_up_var(&net->cells_outstanding);
30}
31
32/*
33 * Set the cell timer to fire after a given delay, assuming it's not already
34 * set for an earlier time.
35 */
36static void afs_set_cell_timer(struct afs_net *net, time64_t delay)
37{
38 if (net->live) {
39 atomic_inc(&net->cells_outstanding);
40 if (timer_reduce(&net->cells_timer, jiffies + delay * HZ))
41 afs_dec_cells_outstanding(net);
42 }
43}
44
45/*
46 * Look up and get an activation reference on a cell record under RCU
47 * conditions. The caller must hold the RCU read lock.
48 */
49struct afs_cell *afs_lookup_cell_rcu(struct afs_net *net,
50 const char *name, unsigned int namesz)
51{
52 struct afs_cell *cell = NULL;
53 struct rb_node *p;
54 int n, seq = 0, ret = 0;
55
56 _enter("%*.*s", namesz, namesz, name);
57
58 if (name && namesz == 0)
59 return ERR_PTR(-EINVAL);
60 if (namesz > AFS_MAXCELLNAME)
61 return ERR_PTR(-ENAMETOOLONG);
62
63 do {
64 /* Unfortunately, rbtree walking doesn't give reliable results
65 * under just the RCU read lock, so we have to check for
66 * changes.
67 */
68 if (cell)
69 afs_put_cell(net, cell);
70 cell = NULL;
71 ret = -ENOENT;
72
73 read_seqbegin_or_lock(&net->cells_lock, &seq);
74
75 if (!name) {
76 cell = rcu_dereference_raw(net->ws_cell);
77 if (cell) {
78 afs_get_cell(cell);
79 ret = 0;
80 break;
81 }
82 ret = -EDESTADDRREQ;
83 continue;
84 }
85
86 p = rcu_dereference_raw(net->cells.rb_node);
87 while (p) {
88 cell = rb_entry(p, struct afs_cell, net_node);
89
90 n = strncasecmp(cell->name, name,
91 min_t(size_t, cell->name_len, namesz));
92 if (n == 0)
93 n = cell->name_len - namesz;
94 if (n < 0) {
95 p = rcu_dereference_raw(p->rb_left);
96 } else if (n > 0) {
97 p = rcu_dereference_raw(p->rb_right);
98 } else {
99 if (atomic_inc_not_zero(&cell->usage)) {
100 ret = 0;
101 break;
102 }
103 /* We want to repeat the search, this time with
104 * the lock properly locked.
105 */
106 }
107 cell = NULL;
108 }
109
110 } while (need_seqretry(&net->cells_lock, seq));
111
112 done_seqretry(&net->cells_lock, seq);
113
114 if (ret != 0 && cell)
115 afs_put_cell(net, cell);
116
117 return ret == 0 ? cell : ERR_PTR(ret);
118}
119
120/*
121 * Set up a cell record and fill in its name, VL server address list and
122 * allocate an anonymous key
123 */
124static struct afs_cell *afs_alloc_cell(struct afs_net *net,
125 const char *name, unsigned int namelen,
126 const char *vllist)
127{
128 struct afs_cell *cell;
129 int i, ret;
130
131 ASSERT(name);
132 if (namelen == 0)
133 return ERR_PTR(-EINVAL);
134 if (namelen > AFS_MAXCELLNAME) {
135 _leave(" = -ENAMETOOLONG");
136 return ERR_PTR(-ENAMETOOLONG);
137 }
138 if (namelen == 5 && memcmp(name, "@cell", 5) == 0)
139 return ERR_PTR(-EINVAL);
140
141 _enter("%*.*s,%s", namelen, namelen, name, vllist);
142
143 cell = kzalloc(sizeof(struct afs_cell), GFP_KERNEL);
144 if (!cell) {
145 _leave(" = -ENOMEM");
146 return ERR_PTR(-ENOMEM);
147 }
148
149 cell->net = net;
150 cell->name_len = namelen;
151 for (i = 0; i < namelen; i++)
152 cell->name[i] = tolower(name[i]);
153
154 atomic_set(&cell->usage, 2);
155 INIT_WORK(&cell->manager, afs_manage_cell);
156 cell->flags = ((1 << AFS_CELL_FL_NOT_READY) |
157 (1 << AFS_CELL_FL_NO_LOOKUP_YET));
158 INIT_LIST_HEAD(&cell->proc_volumes);
159 rwlock_init(&cell->proc_lock);
160 rwlock_init(&cell->vl_addrs_lock);
161
162 /* Fill in the VL server list if we were given a list of addresses to
163 * use.
164 */
165 if (vllist) {
166 struct afs_addr_list *alist;
167
168 alist = afs_parse_text_addrs(vllist, strlen(vllist), ':',
169 VL_SERVICE, AFS_VL_PORT);
170 if (IS_ERR(alist)) {
171 ret = PTR_ERR(alist);
172 goto parse_failed;
173 }
174
175 rcu_assign_pointer(cell->vl_addrs, alist);
176 cell->dns_expiry = TIME64_MAX;
177 }
178
179 _leave(" = %p", cell);
180 return cell;
181
182parse_failed:
183 if (ret == -EINVAL)
184 printk(KERN_ERR "kAFS: bad VL server IP address\n");
185 kfree(cell);
186 _leave(" = %d", ret);
187 return ERR_PTR(ret);
188}
189
190/*
191 * afs_lookup_cell - Look up or create a cell record.
192 * @net: The network namespace
193 * @name: The name of the cell.
194 * @namesz: The strlen of the cell name.
195 * @vllist: A colon/comma separated list of numeric IP addresses or NULL.
196 * @excl: T if an error should be given if the cell name already exists.
197 *
198 * Look up a cell record by name and query the DNS for VL server addresses if
199 * needed. Note that that actual DNS query is punted off to the manager thread
200 * so that this function can return immediately if interrupted whilst allowing
201 * cell records to be shared even if not yet fully constructed.
202 */
203struct afs_cell *afs_lookup_cell(struct afs_net *net,
204 const char *name, unsigned int namesz,
205 const char *vllist, bool excl)
206{
207 struct afs_cell *cell, *candidate, *cursor;
208 struct rb_node *parent, **pp;
209 int ret, n;
210
211 _enter("%s,%s", name, vllist);
212
213 if (!excl) {
214 rcu_read_lock();
215 cell = afs_lookup_cell_rcu(net, name, namesz);
216 rcu_read_unlock();
217 if (!IS_ERR(cell))
218 goto wait_for_cell;
219 }
220
221 /* Assume we're probably going to create a cell and preallocate and
222 * mostly set up a candidate record. We can then use this to stash the
223 * name, the net namespace and VL server addresses.
224 *
225 * We also want to do this before we hold any locks as it may involve
226 * upcalling to userspace to make DNS queries.
227 */
228 candidate = afs_alloc_cell(net, name, namesz, vllist);
229 if (IS_ERR(candidate)) {
230 _leave(" = %ld", PTR_ERR(candidate));
231 return candidate;
232 }
233
234 /* Find the insertion point and check to see if someone else added a
235 * cell whilst we were allocating.
236 */
237 write_seqlock(&net->cells_lock);
238
239 pp = &net->cells.rb_node;
240 parent = NULL;
241 while (*pp) {
242 parent = *pp;
243 cursor = rb_entry(parent, struct afs_cell, net_node);
244
245 n = strncasecmp(cursor->name, name,
246 min_t(size_t, cursor->name_len, namesz));
247 if (n == 0)
248 n = cursor->name_len - namesz;
249 if (n < 0)
250 pp = &(*pp)->rb_left;
251 else if (n > 0)
252 pp = &(*pp)->rb_right;
253 else
254 goto cell_already_exists;
255 }
256
257 cell = candidate;
258 candidate = NULL;
259 rb_link_node_rcu(&cell->net_node, parent, pp);
260 rb_insert_color(&cell->net_node, &net->cells);
261 atomic_inc(&net->cells_outstanding);
262 write_sequnlock(&net->cells_lock);
263
264 queue_work(afs_wq, &cell->manager);
265
266wait_for_cell:
267 _debug("wait_for_cell");
268 ret = wait_on_bit(&cell->flags, AFS_CELL_FL_NOT_READY, TASK_INTERRUPTIBLE);
269 smp_rmb();
270
271 switch (READ_ONCE(cell->state)) {
272 case AFS_CELL_FAILED:
273 ret = cell->error;
274 goto error;
275 default:
276 _debug("weird %u %d", cell->state, cell->error);
277 goto error;
278 case AFS_CELL_ACTIVE:
279 break;
280 }
281
282 _leave(" = %p [cell]", cell);
283 return cell;
284
285cell_already_exists:
286 _debug("cell exists");
287 cell = cursor;
288 if (excl) {
289 ret = -EEXIST;
290 } else {
291 afs_get_cell(cursor);
292 ret = 0;
293 }
294 write_sequnlock(&net->cells_lock);
295 kfree(candidate);
296 if (ret == 0)
297 goto wait_for_cell;
298 goto error_noput;
299error:
300 afs_put_cell(net, cell);
301error_noput:
302 _leave(" = %d [error]", ret);
303 return ERR_PTR(ret);
304}
305
306/*
307 * set the root cell information
308 * - can be called with a module parameter string
309 * - can be called from a write to /proc/fs/afs/rootcell
310 */
311int afs_cell_init(struct afs_net *net, const char *rootcell)
312{
313 struct afs_cell *old_root, *new_root;
314 const char *cp, *vllist;
315 size_t len;
316
317 _enter("");
318
319 if (!rootcell) {
320 /* module is loaded with no parameters, or built statically.
321 * - in the future we might initialize cell DB here.
322 */
323 _leave(" = 0 [no root]");
324 return 0;
325 }
326
327 cp = strchr(rootcell, ':');
328 if (!cp) {
329 _debug("kAFS: no VL server IP addresses specified");
330 vllist = NULL;
331 len = strlen(rootcell);
332 } else {
333 vllist = cp + 1;
334 len = cp - rootcell;
335 }
336
337 /* allocate a cell record for the root cell */
338 new_root = afs_lookup_cell(net, rootcell, len, vllist, false);
339 if (IS_ERR(new_root)) {
340 _leave(" = %ld", PTR_ERR(new_root));
341 return PTR_ERR(new_root);
342 }
343
344 if (!test_and_set_bit(AFS_CELL_FL_NO_GC, &new_root->flags))
345 afs_get_cell(new_root);
346
347 /* install the new cell */
348 write_seqlock(&net->cells_lock);
349 old_root = rcu_access_pointer(net->ws_cell);
350 rcu_assign_pointer(net->ws_cell, new_root);
351 write_sequnlock(&net->cells_lock);
352
353 afs_put_cell(net, old_root);
354 _leave(" = 0");
355 return 0;
356}
357
358/*
359 * Update a cell's VL server address list from the DNS.
360 */
361static void afs_update_cell(struct afs_cell *cell)
362{
363 struct afs_addr_list *alist, *old;
364 time64_t now, expiry;
365
366 _enter("%s", cell->name);
367
368 alist = afs_dns_query(cell, &expiry);
369 if (IS_ERR(alist)) {
370 switch (PTR_ERR(alist)) {
371 case -ENODATA:
372 /* The DNS said that the cell does not exist */
373 set_bit(AFS_CELL_FL_NOT_FOUND, &cell->flags);
374 clear_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags);
375 cell->dns_expiry = ktime_get_real_seconds() + 61;
376 break;
377
378 case -EAGAIN:
379 case -ECONNREFUSED:
380 default:
381 set_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags);
382 cell->dns_expiry = ktime_get_real_seconds() + 10;
383 break;
384 }
385
386 cell->error = -EDESTADDRREQ;
387 } else {
388 clear_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags);
389 clear_bit(AFS_CELL_FL_NOT_FOUND, &cell->flags);
390
391 /* Exclusion on changing vl_addrs is achieved by a
392 * non-reentrant work item.
393 */
394 old = rcu_dereference_protected(cell->vl_addrs, true);
395 rcu_assign_pointer(cell->vl_addrs, alist);
396 cell->dns_expiry = expiry;
397
398 if (old)
399 afs_put_addrlist(old);
400 }
401
402 if (test_and_clear_bit(AFS_CELL_FL_NO_LOOKUP_YET, &cell->flags))
403 wake_up_bit(&cell->flags, AFS_CELL_FL_NO_LOOKUP_YET);
404
405 now = ktime_get_real_seconds();
406 afs_set_cell_timer(cell->net, cell->dns_expiry - now);
407 _leave("");
408}
409
410/*
411 * Destroy a cell record
412 */
413static void afs_cell_destroy(struct rcu_head *rcu)
414{
415 struct afs_cell *cell = container_of(rcu, struct afs_cell, rcu);
416
417 _enter("%p{%s}", cell, cell->name);
418
419 ASSERTCMP(atomic_read(&cell->usage), ==, 0);
420
421 afs_put_addrlist(rcu_access_pointer(cell->vl_addrs));
422 key_put(cell->anonymous_key);
423 kfree(cell);
424
425 _leave(" [destroyed]");
426}
427
428/*
429 * Queue the cell manager.
430 */
431static void afs_queue_cell_manager(struct afs_net *net)
432{
433 int outstanding = atomic_inc_return(&net->cells_outstanding);
434
435 _enter("%d", outstanding);
436
437 if (!queue_work(afs_wq, &net->cells_manager))
438 afs_dec_cells_outstanding(net);
439}
440
441/*
442 * Cell management timer. We have an increment on cells_outstanding that we
443 * need to pass along to the work item.
444 */
445void afs_cells_timer(struct timer_list *timer)
446{
447 struct afs_net *net = container_of(timer, struct afs_net, cells_timer);
448
449 _enter("");
450 if (!queue_work(afs_wq, &net->cells_manager))
451 afs_dec_cells_outstanding(net);
452}
453
454/*
455 * Get a reference on a cell record.
456 */
457struct afs_cell *afs_get_cell(struct afs_cell *cell)
458{
459 atomic_inc(&cell->usage);
460 return cell;
461}
462
463/*
464 * Drop a reference on a cell record.
465 */
466void afs_put_cell(struct afs_net *net, struct afs_cell *cell)
467{
468 time64_t now, expire_delay;
469
470 if (!cell)
471 return;
472
473 _enter("%s", cell->name);
474
475 now = ktime_get_real_seconds();
476 cell->last_inactive = now;
477 expire_delay = 0;
478 if (!test_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags) &&
479 !test_bit(AFS_CELL_FL_NOT_FOUND, &cell->flags))
480 expire_delay = afs_cell_gc_delay;
481
482 if (atomic_dec_return(&cell->usage) > 1)
483 return;
484
485 /* 'cell' may now be garbage collected. */
486 afs_set_cell_timer(net, expire_delay);
487}
488
489/*
490 * Allocate a key to use as a placeholder for anonymous user security.
491 */
492static int afs_alloc_anon_key(struct afs_cell *cell)
493{
494 struct key *key;
495 char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp;
496
497 /* Create a key to represent an anonymous user. */
498 memcpy(keyname, "afs@", 4);
499 dp = keyname + 4;
500 cp = cell->name;
501 do {
502 *dp++ = tolower(*cp);
503 } while (*cp++);
504
505 key = rxrpc_get_null_key(keyname);
506 if (IS_ERR(key))
507 return PTR_ERR(key);
508
509 cell->anonymous_key = key;
510
511 _debug("anon key %p{%x}",
512 cell->anonymous_key, key_serial(cell->anonymous_key));
513 return 0;
514}
515
516/*
517 * Activate a cell.
518 */
519static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)
520{
521 struct hlist_node **p;
522 struct afs_cell *pcell;
523 int ret;
524
525 if (!cell->anonymous_key) {
526 ret = afs_alloc_anon_key(cell);
527 if (ret < 0)
528 return ret;
529 }
530
531#ifdef CONFIG_AFS_FSCACHE
532 cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index,
533 &afs_cell_cache_index_def,
534 cell->name, strlen(cell->name),
535 NULL, 0,
536 cell, 0, true);
537#endif
538 ret = afs_proc_cell_setup(cell);
539 if (ret < 0)
540 return ret;
541
542 mutex_lock(&net->proc_cells_lock);
543 for (p = &net->proc_cells.first; *p; p = &(*p)->next) {
544 pcell = hlist_entry(*p, struct afs_cell, proc_link);
545 if (strcmp(cell->name, pcell->name) < 0)
546 break;
547 }
548
549 cell->proc_link.pprev = p;
550 cell->proc_link.next = *p;
551 rcu_assign_pointer(*p, &cell->proc_link.next);
552 if (cell->proc_link.next)
553 cell->proc_link.next->pprev = &cell->proc_link.next;
554
555 afs_dynroot_mkdir(net, cell);
556 mutex_unlock(&net->proc_cells_lock);
557 return 0;
558}
559
560/*
561 * Deactivate a cell.
562 */
563static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell)
564{
565 _enter("%s", cell->name);
566
567 afs_proc_cell_remove(cell);
568
569 mutex_lock(&net->proc_cells_lock);
570 hlist_del_rcu(&cell->proc_link);
571 afs_dynroot_rmdir(net, cell);
572 mutex_unlock(&net->proc_cells_lock);
573
574#ifdef CONFIG_AFS_FSCACHE
575 fscache_relinquish_cookie(cell->cache, NULL, false);
576 cell->cache = NULL;
577#endif
578
579 _leave("");
580}
581
582/*
583 * Manage a cell record, initialising and destroying it, maintaining its DNS
584 * records.
585 */
586static void afs_manage_cell(struct work_struct *work)
587{
588 struct afs_cell *cell = container_of(work, struct afs_cell, manager);
589 struct afs_net *net = cell->net;
590 bool deleted;
591 int ret, usage;
592
593 _enter("%s", cell->name);
594
595again:
596 _debug("state %u", cell->state);
597 switch (cell->state) {
598 case AFS_CELL_INACTIVE:
599 case AFS_CELL_FAILED:
600 write_seqlock(&net->cells_lock);
601 usage = 1;
602 deleted = atomic_try_cmpxchg_relaxed(&cell->usage, &usage, 0);
603 if (deleted)
604 rb_erase(&cell->net_node, &net->cells);
605 write_sequnlock(&net->cells_lock);
606 if (deleted)
607 goto final_destruction;
608 if (cell->state == AFS_CELL_FAILED)
609 goto done;
610 cell->state = AFS_CELL_UNSET;
611 goto again;
612
613 case AFS_CELL_UNSET:
614 cell->state = AFS_CELL_ACTIVATING;
615 goto again;
616
617 case AFS_CELL_ACTIVATING:
618 ret = afs_activate_cell(net, cell);
619 if (ret < 0)
620 goto activation_failed;
621
622 cell->state = AFS_CELL_ACTIVE;
623 smp_wmb();
624 clear_bit(AFS_CELL_FL_NOT_READY, &cell->flags);
625 wake_up_bit(&cell->flags, AFS_CELL_FL_NOT_READY);
626 goto again;
627
628 case AFS_CELL_ACTIVE:
629 if (atomic_read(&cell->usage) > 1) {
630 time64_t now = ktime_get_real_seconds();
631 if (cell->dns_expiry <= now && net->live)
632 afs_update_cell(cell);
633 goto done;
634 }
635 cell->state = AFS_CELL_DEACTIVATING;
636 goto again;
637
638 case AFS_CELL_DEACTIVATING:
639 set_bit(AFS_CELL_FL_NOT_READY, &cell->flags);
640 if (atomic_read(&cell->usage) > 1)
641 goto reverse_deactivation;
642 afs_deactivate_cell(net, cell);
643 cell->state = AFS_CELL_INACTIVE;
644 goto again;
645
646 default:
647 break;
648 }
649 _debug("bad state %u", cell->state);
650 BUG(); /* Unhandled state */
651
652activation_failed:
653 cell->error = ret;
654 afs_deactivate_cell(net, cell);
655
656 cell->state = AFS_CELL_FAILED;
657 smp_wmb();
658 if (test_and_clear_bit(AFS_CELL_FL_NOT_READY, &cell->flags))
659 wake_up_bit(&cell->flags, AFS_CELL_FL_NOT_READY);
660 goto again;
661
662reverse_deactivation:
663 cell->state = AFS_CELL_ACTIVE;
664 smp_wmb();
665 clear_bit(AFS_CELL_FL_NOT_READY, &cell->flags);
666 wake_up_bit(&cell->flags, AFS_CELL_FL_NOT_READY);
667 _leave(" [deact->act]");
668 return;
669
670done:
671 _leave(" [done %u]", cell->state);
672 return;
673
674final_destruction:
675 call_rcu(&cell->rcu, afs_cell_destroy);
676 afs_dec_cells_outstanding(net);
677 _leave(" [destruct %d]", atomic_read(&net->cells_outstanding));
678}
679
680/*
681 * Manage the records of cells known to a network namespace. This includes
682 * updating the DNS records and garbage collecting unused cells that were
683 * automatically added.
684 *
685 * Note that constructed cell records may only be removed from net->cells by
686 * this work item, so it is safe for this work item to stash a cursor pointing
687 * into the tree and then return to caller (provided it skips cells that are
688 * still under construction).
689 *
690 * Note also that we were given an increment on net->cells_outstanding by
691 * whoever queued us that we need to deal with before returning.
692 */
693void afs_manage_cells(struct work_struct *work)
694{
695 struct afs_net *net = container_of(work, struct afs_net, cells_manager);
696 struct rb_node *cursor;
697 time64_t now = ktime_get_real_seconds(), next_manage = TIME64_MAX;
698 bool purging = !net->live;
699
700 _enter("");
701
702 /* Trawl the cell database looking for cells that have expired from
703 * lack of use and cells whose DNS results have expired and dispatch
704 * their managers.
705 */
706 read_seqlock_excl(&net->cells_lock);
707
708 for (cursor = rb_first(&net->cells); cursor; cursor = rb_next(cursor)) {
709 struct afs_cell *cell =
710 rb_entry(cursor, struct afs_cell, net_node);
711 unsigned usage;
712 bool sched_cell = false;
713
714 usage = atomic_read(&cell->usage);
715 _debug("manage %s %u", cell->name, usage);
716
717 ASSERTCMP(usage, >=, 1);
718
719 if (purging) {
720 if (test_and_clear_bit(AFS_CELL_FL_NO_GC, &cell->flags))
721 usage = atomic_dec_return(&cell->usage);
722 ASSERTCMP(usage, ==, 1);
723 }
724
725 if (usage == 1) {
726 time64_t expire_at = cell->last_inactive;
727
728 if (!test_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags) &&
729 !test_bit(AFS_CELL_FL_NOT_FOUND, &cell->flags))
730 expire_at += afs_cell_gc_delay;
731 if (purging || expire_at <= now)
732 sched_cell = true;
733 else if (expire_at < next_manage)
734 next_manage = expire_at;
735 }
736
737 if (!purging) {
738 if (cell->dns_expiry <= now)
739 sched_cell = true;
740 else if (cell->dns_expiry <= next_manage)
741 next_manage = cell->dns_expiry;
742 }
743
744 if (sched_cell)
745 queue_work(afs_wq, &cell->manager);
746 }
747
748 read_sequnlock_excl(&net->cells_lock);
749
750 /* Update the timer on the way out. We have to pass an increment on
751 * cells_outstanding in the namespace that we are in to the timer or
752 * the work scheduler.
753 */
754 if (!purging && next_manage < TIME64_MAX) {
755 now = ktime_get_real_seconds();
756
757 if (next_manage - now <= 0) {
758 if (queue_work(afs_wq, &net->cells_manager))
759 atomic_inc(&net->cells_outstanding);
760 } else {
761 afs_set_cell_timer(net, next_manage - now);
762 }
763 }
764
765 afs_dec_cells_outstanding(net);
766 _leave(" [%d]", atomic_read(&net->cells_outstanding));
767}
768
769/*
770 * Purge in-memory cell database.
771 */
772void afs_cell_purge(struct afs_net *net)
773{
774 struct afs_cell *ws;
775
776 _enter("");
777
778 write_seqlock(&net->cells_lock);
779 ws = rcu_access_pointer(net->ws_cell);
780 RCU_INIT_POINTER(net->ws_cell, NULL);
781 write_sequnlock(&net->cells_lock);
782 afs_put_cell(net, ws);
783
784 _debug("del timer");
785 if (del_timer_sync(&net->cells_timer))
786 atomic_dec(&net->cells_outstanding);
787
788 _debug("kick mgr");
789 afs_queue_cell_manager(net);
790
791 _debug("wait");
792 wait_var_event(&net->cells_outstanding,
793 !atomic_read(&net->cells_outstanding));
794 _leave("");
795}