Lines Matching full:cell
2 /* AFS cell and server record management
33 * Set the cell timer to fire after a given delay, assuming it's not already
48 * Look up and get an activation reference on a cell record. The caller must
55 struct afs_cell *cell = NULL; in afs_find_cell_locked() local
67 cell = rcu_dereference_protected(net->ws_cell, in afs_find_cell_locked()
69 if (!cell) in afs_find_cell_locked()
76 cell = rb_entry(p, struct afs_cell, net_node); in afs_find_cell_locked()
78 n = strncasecmp(cell->name, name, in afs_find_cell_locked()
79 min_t(size_t, cell->name_len, namesz)); in afs_find_cell_locked()
81 n = cell->name_len - namesz; in afs_find_cell_locked()
93 return afs_use_cell(cell, reason); in afs_find_cell_locked()
97 * Look up and get an activation reference on a cell record.
103 struct afs_cell *cell; in afs_find_cell() local
106 cell = afs_find_cell_locked(net, name, namesz, reason); in afs_find_cell()
108 return cell; in afs_find_cell()
112 * Set up a cell record and fill in its name, VL server address list and
120 struct afs_cell *cell; in afs_alloc_cell() local
131 /* Prohibit cell names that contain unprintable chars, '/' and '@' or in afs_alloc_cell()
132 * that begin with a dot. This also precludes "@cell". in afs_alloc_cell()
144 cell = kzalloc(sizeof(struct afs_cell), GFP_KERNEL); in afs_alloc_cell()
145 if (!cell) { in afs_alloc_cell()
150 cell->name = kmalloc(1 + namelen + 1, GFP_KERNEL); in afs_alloc_cell()
151 if (!cell->name) { in afs_alloc_cell()
152 kfree(cell); in afs_alloc_cell()
156 cell->name[0] = '.'; in afs_alloc_cell()
157 cell->name++; in afs_alloc_cell()
158 cell->name_len = namelen; in afs_alloc_cell()
160 cell->name[i] = tolower(name[i]); in afs_alloc_cell()
161 cell->name[i] = 0; in afs_alloc_cell()
163 cell->net = net; in afs_alloc_cell()
164 refcount_set(&cell->ref, 1); in afs_alloc_cell()
165 atomic_set(&cell->active, 0); in afs_alloc_cell()
166 INIT_WORK(&cell->manager, afs_manage_cell_work); in afs_alloc_cell()
167 init_rwsem(&cell->vs_lock); in afs_alloc_cell()
168 cell->volumes = RB_ROOT; in afs_alloc_cell()
169 INIT_HLIST_HEAD(&cell->proc_volumes); in afs_alloc_cell()
170 seqlock_init(&cell->volume_lock); in afs_alloc_cell()
171 cell->fs_servers = RB_ROOT; in afs_alloc_cell()
172 seqlock_init(&cell->fs_lock); in afs_alloc_cell()
173 rwlock_init(&cell->vl_servers_lock); in afs_alloc_cell()
174 cell->flags = (1 << AFS_CELL_FL_CHECK_ALIAS); in afs_alloc_cell()
190 cell->dns_expiry = TIME64_MAX; in afs_alloc_cell()
198 cell->dns_expiry = ktime_get_real_seconds(); in afs_alloc_cell()
201 rcu_assign_pointer(cell->vl_servers, vllist); in afs_alloc_cell()
203 cell->dns_source = vllist->source; in afs_alloc_cell()
204 cell->dns_status = vllist->status; in afs_alloc_cell()
205 smp_store_release(&cell->dns_lookup_count, 1); /* vs source/status */ in afs_alloc_cell()
207 cell->debug_id = atomic_inc_return(&cell_debug_id); in afs_alloc_cell()
208 trace_afs_cell(cell->debug_id, 1, 0, afs_cell_trace_alloc); in afs_alloc_cell()
210 _leave(" = %p", cell); in afs_alloc_cell()
211 return cell; in afs_alloc_cell()
217 kfree(cell->name - 1); in afs_alloc_cell()
218 kfree(cell); in afs_alloc_cell()
224 * afs_lookup_cell - Look up or create a cell record.
226 * @name: The name of the cell.
227 * @namesz: The strlen of the cell name.
229 * @excl: T if an error should be given if the cell name already exists.
231 * Look up a cell record by name and query the DNS for VL server addresses if
234 * cell records to be shared even if not yet fully constructed.
240 struct afs_cell *cell, *candidate, *cursor; in afs_lookup_cell() local
248 cell = afs_find_cell(net, name, namesz, afs_cell_trace_use_lookup); in afs_lookup_cell()
249 if (!IS_ERR(cell)) in afs_lookup_cell()
253 /* Assume we're probably going to create a cell and preallocate and in afs_lookup_cell()
267 * cell whilst we were allocating. in afs_lookup_cell()
289 cell = candidate; in afs_lookup_cell()
291 atomic_set(&cell->active, 2); in afs_lookup_cell()
292 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), 2, afs_cell_trace_insert); in afs_lookup_cell()
293 rb_link_node_rcu(&cell->net_node, parent, pp); in afs_lookup_cell()
294 rb_insert_color(&cell->net_node, &net->cells); in afs_lookup_cell()
297 afs_queue_cell(cell, afs_cell_trace_get_queue_new); in afs_lookup_cell()
300 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), atomic_read(&cell->active), in afs_lookup_cell()
303 wait_var_event(&cell->state, in afs_lookup_cell()
305 state = smp_load_acquire(&cell->state); /* vs error */ in afs_lookup_cell()
311 ret = cell->error; in afs_lookup_cell()
315 _leave(" = %p [cell]", cell); in afs_lookup_cell()
316 return cell; in afs_lookup_cell()
319 _debug("cell exists"); in afs_lookup_cell()
320 cell = cursor; in afs_lookup_cell()
334 afs_unuse_cell(net, cell, afs_cell_trace_unuse_lookup); in afs_lookup_cell()
341 * set the root cell information
355 * - in the future we might initialize cell DB here. in afs_cell_init()
379 /* allocate a cell record for the root cell */ in afs_cell_init()
389 /* install the new cell */ in afs_cell_init()
402 * Update a cell's VL server address list from the DNS.
404 static int afs_update_cell(struct afs_cell *cell) in afs_update_cell() argument
412 _enter("%s", cell->name); in afs_update_cell()
414 vllist = afs_dns_query(cell, &expiry); in afs_update_cell()
418 _debug("%s: fail %d", cell->name, ret); in afs_update_cell()
444 _debug("%s: got list %d %d", cell->name, vllist->source, vllist->status); in afs_update_cell()
445 cell->dns_status = vllist->status; in afs_update_cell()
455 _debug("%s: status %d", cell->name, vllist->status); in afs_update_cell()
459 /* The DNS said that the cell does not exist or there in afs_update_cell()
462 cell->dns_expiry = expiry; in afs_update_cell()
470 cell->dns_expiry = now + 10; in afs_update_cell()
474 cell->dns_expiry = expiry; in afs_update_cell()
480 write_lock(&cell->vl_servers_lock); in afs_update_cell()
481 p = rcu_dereference_protected(cell->vl_servers, true); in afs_update_cell()
483 rcu_assign_pointer(cell->vl_servers, vllist); in afs_update_cell()
484 cell->dns_source = vllist->source; in afs_update_cell()
487 write_unlock(&cell->vl_servers_lock); in afs_update_cell()
488 afs_put_vlserverlist(cell->net, old); in afs_update_cell()
491 smp_store_release(&cell->dns_lookup_count, in afs_update_cell()
492 cell->dns_lookup_count + 1); /* vs source/status */ in afs_update_cell()
493 wake_up_var(&cell->dns_lookup_count); in afs_update_cell()
499 * Destroy a cell record
503 struct afs_cell *cell = container_of(rcu, struct afs_cell, rcu); in afs_cell_destroy() local
504 struct afs_net *net = cell->net; in afs_cell_destroy()
507 _enter("%p{%s}", cell, cell->name); in afs_cell_destroy()
509 r = refcount_read(&cell->ref); in afs_cell_destroy()
511 trace_afs_cell(cell->debug_id, r, atomic_read(&cell->active), afs_cell_trace_free); in afs_cell_destroy()
513 afs_put_vlserverlist(net, rcu_access_pointer(cell->vl_servers)); in afs_cell_destroy()
514 afs_unuse_cell(net, cell->alias_of, afs_cell_trace_unuse_alias); in afs_cell_destroy()
515 key_put(cell->anonymous_key); in afs_cell_destroy()
516 kfree(cell->name - 1); in afs_cell_destroy()
517 kfree(cell); in afs_cell_destroy()
524 * Queue the cell manager.
537 * Cell management timer. We have an increment on cells_outstanding that we
550 * Get a reference on a cell record.
552 struct afs_cell *afs_get_cell(struct afs_cell *cell, enum afs_cell_trace reason) in afs_get_cell() argument
556 __refcount_inc(&cell->ref, &r); in afs_get_cell()
557 trace_afs_cell(cell->debug_id, r + 1, atomic_read(&cell->active), reason); in afs_get_cell()
558 return cell; in afs_get_cell()
562 * Drop a reference on a cell record.
564 void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason) in afs_put_cell() argument
566 if (cell) { in afs_put_cell()
567 unsigned int debug_id = cell->debug_id; in afs_put_cell()
572 a = atomic_read(&cell->active); in afs_put_cell()
573 zero = __refcount_dec_and_test(&cell->ref, &r); in afs_put_cell()
576 a = atomic_read(&cell->active); in afs_put_cell()
577 WARN(a != 0, "Cell active count %u > 0\n", a); in afs_put_cell()
578 call_rcu(&cell->rcu, afs_cell_destroy); in afs_put_cell()
584 * Note a cell becoming more active.
586 struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason) in afs_use_cell() argument
590 r = refcount_read(&cell->ref); in afs_use_cell()
592 a = atomic_inc_return(&cell->active); in afs_use_cell()
593 trace_afs_cell(cell->debug_id, r, a, reason); in afs_use_cell()
594 return cell; in afs_use_cell()
598 * Record a cell becoming less active. When the active counter reaches 1, it
601 void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_trace reason) in afs_unuse_cell() argument
607 if (!cell) in afs_unuse_cell()
610 _enter("%s", cell->name); in afs_unuse_cell()
613 cell->last_inactive = now; in afs_unuse_cell()
615 if (cell->vl_servers->nr_servers) in afs_unuse_cell()
618 debug_id = cell->debug_id; in afs_unuse_cell()
619 r = refcount_read(&cell->ref); in afs_unuse_cell()
620 a = atomic_dec_return(&cell->active); in afs_unuse_cell()
624 /* 'cell' may now be garbage collected. */ in afs_unuse_cell()
629 * Note that a cell has been seen.
631 void afs_see_cell(struct afs_cell *cell, enum afs_cell_trace reason) in afs_see_cell() argument
635 r = refcount_read(&cell->ref); in afs_see_cell()
636 a = atomic_read(&cell->active); in afs_see_cell()
637 trace_afs_cell(cell->debug_id, r, a, reason); in afs_see_cell()
641 * Queue a cell for management, giving the workqueue a ref to hold.
643 void afs_queue_cell(struct afs_cell *cell, enum afs_cell_trace reason) in afs_queue_cell() argument
645 afs_get_cell(cell, reason); in afs_queue_cell()
646 if (!queue_work(afs_wq, &cell->manager)) in afs_queue_cell()
647 afs_put_cell(cell, afs_cell_trace_put_queue_fail); in afs_queue_cell()
653 static int afs_alloc_anon_key(struct afs_cell *cell) in afs_alloc_anon_key() argument
661 cp = cell->name; in afs_alloc_anon_key()
670 cell->anonymous_key = key; in afs_alloc_anon_key()
673 cell->anonymous_key, key_serial(cell->anonymous_key)); in afs_alloc_anon_key()
678 * Activate a cell.
680 static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell) in afs_activate_cell() argument
686 if (!cell->anonymous_key) { in afs_activate_cell()
687 ret = afs_alloc_anon_key(cell); in afs_activate_cell()
692 ret = afs_proc_cell_setup(cell); in afs_activate_cell()
699 if (strcmp(cell->name, pcell->name) < 0) in afs_activate_cell()
703 cell->proc_link.pprev = p; in afs_activate_cell()
704 cell->proc_link.next = *p; in afs_activate_cell()
705 rcu_assign_pointer(*p, &cell->proc_link.next); in afs_activate_cell()
706 if (cell->proc_link.next) in afs_activate_cell()
707 cell->proc_link.next->pprev = &cell->proc_link.next; in afs_activate_cell()
709 afs_dynroot_mkdir(net, cell); in afs_activate_cell()
715 * Deactivate a cell.
717 static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell) in afs_deactivate_cell() argument
719 _enter("%s", cell->name); in afs_deactivate_cell()
721 afs_proc_cell_remove(cell); in afs_deactivate_cell()
724 if (!hlist_unhashed(&cell->proc_link)) in afs_deactivate_cell()
725 hlist_del_rcu(&cell->proc_link); in afs_deactivate_cell()
726 afs_dynroot_rmdir(net, cell); in afs_deactivate_cell()
733 * Manage a cell record, initialising and destroying it, maintaining its DNS
736 static void afs_manage_cell(struct afs_cell *cell) in afs_manage_cell() argument
738 struct afs_net *net = cell->net; in afs_manage_cell()
741 _enter("%s", cell->name); in afs_manage_cell()
744 _debug("state %u", cell->state); in afs_manage_cell()
745 switch (cell->state) { in afs_manage_cell()
750 if (atomic_try_cmpxchg_relaxed(&cell->active, &active, 0)) { in afs_manage_cell()
751 rb_erase(&cell->net_node, &net->cells); in afs_manage_cell()
752 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), 0, in afs_manage_cell()
754 smp_store_release(&cell->state, AFS_CELL_REMOVED); in afs_manage_cell()
757 if (cell->state == AFS_CELL_REMOVED) { in afs_manage_cell()
758 wake_up_var(&cell->state); in afs_manage_cell()
761 if (cell->state == AFS_CELL_FAILED) in afs_manage_cell()
763 smp_store_release(&cell->state, AFS_CELL_UNSET); in afs_manage_cell()
764 wake_up_var(&cell->state); in afs_manage_cell()
768 smp_store_release(&cell->state, AFS_CELL_ACTIVATING); in afs_manage_cell()
769 wake_up_var(&cell->state); in afs_manage_cell()
773 ret = afs_activate_cell(net, cell); in afs_manage_cell()
777 smp_store_release(&cell->state, AFS_CELL_ACTIVE); in afs_manage_cell()
778 wake_up_var(&cell->state); in afs_manage_cell()
782 if (atomic_read(&cell->active) > 1) { in afs_manage_cell()
783 if (test_and_clear_bit(AFS_CELL_FL_DO_LOOKUP, &cell->flags)) { in afs_manage_cell()
784 ret = afs_update_cell(cell); in afs_manage_cell()
786 cell->error = ret; in afs_manage_cell()
790 smp_store_release(&cell->state, AFS_CELL_DEACTIVATING); in afs_manage_cell()
791 wake_up_var(&cell->state); in afs_manage_cell()
795 if (atomic_read(&cell->active) > 1) in afs_manage_cell()
797 afs_deactivate_cell(net, cell); in afs_manage_cell()
798 smp_store_release(&cell->state, AFS_CELL_INACTIVE); in afs_manage_cell()
799 wake_up_var(&cell->state); in afs_manage_cell()
808 _debug("bad state %u", cell->state); in afs_manage_cell()
812 cell->error = ret; in afs_manage_cell()
813 afs_deactivate_cell(net, cell); in afs_manage_cell()
815 smp_store_release(&cell->state, AFS_CELL_FAILED); /* vs error */ in afs_manage_cell()
816 wake_up_var(&cell->state); in afs_manage_cell()
820 smp_store_release(&cell->state, AFS_CELL_ACTIVE); in afs_manage_cell()
821 wake_up_var(&cell->state); in afs_manage_cell()
826 _leave(" [done %u]", cell->state); in afs_manage_cell()
830 /* The root volume is pinning the cell */ in afs_manage_cell()
831 afs_put_volume(cell->root_volume, afs_volume_trace_put_cell_root); in afs_manage_cell()
832 cell->root_volume = NULL; in afs_manage_cell()
833 afs_put_cell(cell, afs_cell_trace_put_destroy); in afs_manage_cell()
838 struct afs_cell *cell = container_of(work, struct afs_cell, manager); in afs_manage_cell_work() local
840 afs_manage_cell(cell); in afs_manage_cell_work()
841 afs_put_cell(cell, afs_cell_trace_put_queue_work); in afs_manage_cell_work()
849 * Note that constructed cell records may only be removed from net->cells by
866 /* Trawl the cell database looking for cells that have expired from in afs_manage_cells()
873 struct afs_cell *cell = in afs_manage_cells() local
878 active = atomic_read(&cell->active); in afs_manage_cells()
879 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), in afs_manage_cells()
885 if (test_and_clear_bit(AFS_CELL_FL_NO_GC, &cell->flags)) { in afs_manage_cells()
886 active = atomic_dec_return(&cell->active); in afs_manage_cells()
887 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), in afs_manage_cells()
894 time64_t expire_at = cell->last_inactive; in afs_manage_cells()
896 read_lock(&cell->vl_servers_lock); in afs_manage_cells()
898 cell->vl_servers, in afs_manage_cells()
899 lockdep_is_held(&cell->vl_servers_lock)); in afs_manage_cells()
902 read_unlock(&cell->vl_servers_lock); in afs_manage_cells()
910 if (test_bit(AFS_CELL_FL_DO_LOOKUP, &cell->flags)) in afs_manage_cells()
915 afs_queue_cell(cell, afs_cell_trace_get_queue_manage); in afs_manage_cells()
940 * Purge in-memory cell database.