Lines Matching refs: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;
67 cell = net->ws_cell;
68 if (!cell)
75 cell = rb_entry(p, struct afs_cell, net_node);
77 n = strncasecmp(cell->name, name,
78 min_t(size_t, cell->name_len, namesz));
80 n = cell->name_len - namesz;
92 return afs_use_cell(cell, reason);
96 * Look up and get an activation reference on a cell record.
102 struct afs_cell *cell;
105 cell = afs_find_cell_locked(net, name, namesz, reason);
107 return cell;
111 * Set up a cell record and fill in its name, VL server address list and
119 struct afs_cell *cell;
130 /* Prohibit cell names that contain unprintable chars, '/' and '@' or
131 * that begin with a dot. This also precludes "@cell".
143 cell = kzalloc(sizeof(struct afs_cell), GFP_KERNEL);
144 if (!cell) {
149 cell->name = kmalloc(namelen + 1, GFP_KERNEL);
150 if (!cell->name) {
151 kfree(cell);
155 cell->net = net;
156 cell->name_len = namelen;
158 cell->name[i] = tolower(name[i]);
159 cell->name[i] = 0;
161 refcount_set(&cell->ref, 1);
162 atomic_set(&cell->active, 0);
163 INIT_WORK(&cell->manager, afs_manage_cell_work);
164 cell->volumes = RB_ROOT;
165 INIT_HLIST_HEAD(&cell->proc_volumes);
166 seqlock_init(&cell->volume_lock);
167 cell->fs_servers = RB_ROOT;
168 seqlock_init(&cell->fs_lock);
169 INIT_LIST_HEAD(&cell->fs_open_mmaps);
170 init_rwsem(&cell->fs_open_mmaps_lock);
171 rwlock_init(&cell->vl_servers_lock);
172 cell->flags = (1 << AFS_CELL_FL_CHECK_ALIAS);
188 cell->dns_expiry = TIME64_MAX;
196 cell->dns_expiry = ktime_get_real_seconds();
199 rcu_assign_pointer(cell->vl_servers, vllist);
201 cell->dns_source = vllist->source;
202 cell->dns_status = vllist->status;
203 smp_store_release(&cell->dns_lookup_count, 1); /* vs source/status */
205 cell->debug_id = atomic_inc_return(&cell_debug_id);
206 trace_afs_cell(cell->debug_id, 1, 0, afs_cell_trace_alloc);
208 _leave(" = %p", cell);
209 return cell;
215 kfree(cell->name);
216 kfree(cell);
222 * afs_lookup_cell - Look up or create a cell record.
224 * @name: The name of the cell.
225 * @namesz: The strlen of the cell name.
227 * @excl: T if an error should be given if the cell name already exists.
229 * Look up a cell record by name and query the DNS for VL server addresses if
232 * cell records to be shared even if not yet fully constructed.
238 struct afs_cell *cell, *candidate, *cursor;
246 cell = afs_find_cell(net, name, namesz, afs_cell_trace_use_lookup);
247 if (!IS_ERR(cell))
251 /* Assume we're probably going to create a cell and preallocate and
265 * cell whilst we were allocating.
287 cell = candidate;
289 atomic_set(&cell->active, 2);
290 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), 2, afs_cell_trace_insert);
291 rb_link_node_rcu(&cell->net_node, parent, pp);
292 rb_insert_color(&cell->net_node, &net->cells);
295 afs_queue_cell(cell, afs_cell_trace_get_queue_new);
298 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), atomic_read(&cell->active),
301 wait_var_event(&cell->state,
303 state = smp_load_acquire(&cell->state); /* vs error */
309 ret = cell->error;
313 _leave(" = %p [cell]", cell);
314 return cell;
317 _debug("cell exists");
318 cell = cursor;
332 afs_unuse_cell(net, cell, afs_cell_trace_unuse_lookup);
339 * set the root cell information
353 * - in the future we might initialize cell DB here.
369 /* allocate a cell record for the root cell */
379 /* install the new cell */
392 * Update a cell's VL server address list from the DNS.
394 static int afs_update_cell(struct afs_cell *cell)
402 _enter("%s", cell->name);
404 vllist = afs_dns_query(cell, &expiry);
408 _debug("%s: fail %d", cell->name, ret);
434 _debug("%s: got list %d %d", cell->name, vllist->source, vllist->status);
435 cell->dns_status = vllist->status;
445 _debug("%s: status %d", cell->name, vllist->status);
449 /* The DNS said that the cell does not exist or there
452 cell->dns_expiry = expiry;
460 cell->dns_expiry = now + 10;
464 cell->dns_expiry = expiry;
470 write_lock(&cell->vl_servers_lock);
471 p = rcu_dereference_protected(cell->vl_servers, true);
473 rcu_assign_pointer(cell->vl_servers, vllist);
474 cell->dns_source = vllist->source;
477 write_unlock(&cell->vl_servers_lock);
478 afs_put_vlserverlist(cell->net, old);
481 smp_store_release(&cell->dns_lookup_count,
482 cell->dns_lookup_count + 1); /* vs source/status */
483 wake_up_var(&cell->dns_lookup_count);
489 * Destroy a cell record
493 struct afs_cell *cell = container_of(rcu, struct afs_cell, rcu);
494 struct afs_net *net = cell->net;
497 _enter("%p{%s}", cell, cell->name);
499 r = refcount_read(&cell->ref);
501 trace_afs_cell(cell->debug_id, r, atomic_read(&cell->active), afs_cell_trace_free);
503 afs_put_vlserverlist(net, rcu_access_pointer(cell->vl_servers));
504 afs_unuse_cell(net, cell->alias_of, afs_cell_trace_unuse_alias);
505 key_put(cell->anonymous_key);
506 kfree(cell->name);
507 kfree(cell);
514 * Queue the cell manager.
540 * Get a reference on a cell record.
542 struct afs_cell *afs_get_cell(struct afs_cell *cell, enum afs_cell_trace reason)
546 __refcount_inc(&cell->ref, &r);
547 trace_afs_cell(cell->debug_id, r + 1, atomic_read(&cell->active), reason);
548 return cell;
552 * Drop a reference on a cell record.
554 void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)
556 if (cell) {
557 unsigned int debug_id = cell->debug_id;
562 a = atomic_read(&cell->active);
563 zero = __refcount_dec_and_test(&cell->ref, &r);
566 a = atomic_read(&cell->active);
568 call_rcu(&cell->rcu, afs_cell_destroy);
574 * Note a cell becoming more active.
576 struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason)
580 r = refcount_read(&cell->ref);
582 a = atomic_inc_return(&cell->active);
583 trace_afs_cell(cell->debug_id, r, a, reason);
584 return cell;
588 * Record a cell becoming less active. When the active counter reaches 1, it
591 void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_trace reason)
597 if (!cell)
600 _enter("%s", cell->name);
603 cell->last_inactive = now;
605 if (cell->vl_servers->nr_servers)
608 debug_id = cell->debug_id;
609 r = refcount_read(&cell->ref);
610 a = atomic_dec_return(&cell->active);
614 /* 'cell' may now be garbage collected. */
619 * Note that a cell has been seen.
621 void afs_see_cell(struct afs_cell *cell, enum afs_cell_trace reason)
625 r = refcount_read(&cell->ref);
626 a = atomic_read(&cell->active);
627 trace_afs_cell(cell->debug_id, r, a, reason);
631 * Queue a cell for management, giving the workqueue a ref to hold.
633 void afs_queue_cell(struct afs_cell *cell, enum afs_cell_trace reason)
635 afs_get_cell(cell, reason);
636 if (!queue_work(afs_wq, &cell->manager))
637 afs_put_cell(cell, afs_cell_trace_put_queue_fail);
643 static int afs_alloc_anon_key(struct afs_cell *cell)
651 cp = cell->name;
660 cell->anonymous_key = key;
663 cell->anonymous_key, key_serial(cell->anonymous_key));
668 * Activate a cell.
670 static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)
676 if (!cell->anonymous_key) {
677 ret = afs_alloc_anon_key(cell);
682 ret = afs_proc_cell_setup(cell);
689 if (strcmp(cell->name, pcell->name) < 0)
693 cell->proc_link.pprev = p;
694 cell->proc_link.next = *p;
695 rcu_assign_pointer(*p, &cell->proc_link.next);
696 if (cell->proc_link.next)
697 cell->proc_link.next->pprev = &cell->proc_link.next;
699 afs_dynroot_mkdir(net, cell);
705 * Deactivate a cell.
707 static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell)
709 _enter("%s", cell->name);
711 afs_proc_cell_remove(cell);
714 hlist_del_rcu(&cell->proc_link);
715 afs_dynroot_rmdir(net, cell);
722 * Manage a cell record, initialising and destroying it, maintaining its DNS
725 static void afs_manage_cell(struct afs_cell *cell)
727 struct afs_net *net = cell->net;
730 _enter("%s", cell->name);
733 _debug("state %u", cell->state);
734 switch (cell->state) {
739 if (atomic_try_cmpxchg_relaxed(&cell->active, &active, 0)) {
740 rb_erase(&cell->net_node, &net->cells);
741 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref), 0,
743 smp_store_release(&cell->state, AFS_CELL_REMOVED);
746 if (cell->state == AFS_CELL_REMOVED) {
747 wake_up_var(&cell->state);
750 if (cell->state == AFS_CELL_FAILED)
752 smp_store_release(&cell->state, AFS_CELL_UNSET);
753 wake_up_var(&cell->state);
757 smp_store_release(&cell->state, AFS_CELL_ACTIVATING);
758 wake_up_var(&cell->state);
762 ret = afs_activate_cell(net, cell);
766 smp_store_release(&cell->state, AFS_CELL_ACTIVE);
767 wake_up_var(&cell->state);
771 if (atomic_read(&cell->active) > 1) {
772 if (test_and_clear_bit(AFS_CELL_FL_DO_LOOKUP, &cell->flags)) {
773 ret = afs_update_cell(cell);
775 cell->error = ret;
779 smp_store_release(&cell->state, AFS_CELL_DEACTIVATING);
780 wake_up_var(&cell->state);
784 if (atomic_read(&cell->active) > 1)
786 afs_deactivate_cell(net, cell);
787 smp_store_release(&cell->state, AFS_CELL_INACTIVE);
788 wake_up_var(&cell->state);
797 _debug("bad state %u", cell->state);
801 cell->error = ret;
802 afs_deactivate_cell(net, cell);
804 smp_store_release(&cell->state, AFS_CELL_FAILED); /* vs error */
805 wake_up_var(&cell->state);
809 smp_store_release(&cell->state, AFS_CELL_ACTIVE);
810 wake_up_var(&cell->state);
815 _leave(" [done %u]", cell->state);
819 /* The root volume is pinning the cell */
820 afs_put_volume(cell->net, cell->root_volume, afs_volume_trace_put_cell_root);
821 cell->root_volume = NULL;
822 afs_put_cell(cell, afs_cell_trace_put_destroy);
827 struct afs_cell *cell = container_of(work, struct afs_cell, manager);
829 afs_manage_cell(cell);
830 afs_put_cell(cell, afs_cell_trace_put_queue_work);
838 * Note that constructed cell records may only be removed from net->cells by
855 /* Trawl the cell database looking for cells that have expired from
862 struct afs_cell *cell =
867 active = atomic_read(&cell->active);
868 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref),
874 if (test_and_clear_bit(AFS_CELL_FL_NO_GC, &cell->flags)) {
875 active = atomic_dec_return(&cell->active);
876 trace_afs_cell(cell->debug_id, refcount_read(&cell->ref),
883 time64_t expire_at = cell->last_inactive;
885 read_lock(&cell->vl_servers_lock);
887 cell->vl_servers,
888 lockdep_is_held(&cell->vl_servers_lock));
891 read_unlock(&cell->vl_servers_lock);
899 if (test_bit(AFS_CELL_FL_DO_LOOKUP, &cell->flags))
904 afs_queue_cell(cell, afs_cell_trace_get_queue_manage);
929 * Purge in-memory cell database.