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 atomic_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 rwlock_init(&cell->vl_servers_lock);
170 cell->flags = (1 << AFS_CELL_FL_CHECK_ALIAS);
186 cell->dns_expiry = TIME64_MAX;
194 cell->dns_expiry = ktime_get_real_seconds();
197 rcu_assign_pointer(cell->vl_servers, vllist);
199 cell->dns_source = vllist->source;
200 cell->dns_status = vllist->status;
201 smp_store_release(&cell->dns_lookup_count, 1); /* vs source/status */
203 cell->debug_id = atomic_inc_return(&cell_debug_id);
204 trace_afs_cell(cell->debug_id, 1, 0, afs_cell_trace_alloc);
206 _leave(" = %p", cell);
207 return cell;
213 kfree(cell->name);
214 kfree(cell);
220 * afs_lookup_cell - Look up or create a cell record.
222 * @name: The name of the cell.
223 * @namesz: The strlen of the cell name.
225 * @excl: T if an error should be given if the cell name already exists.
227 * Look up a cell record by name and query the DNS for VL server addresses if
230 * cell records to be shared even if not yet fully constructed.
236 struct afs_cell *cell, *candidate, *cursor;
244 cell = afs_find_cell(net, name, namesz, afs_cell_trace_use_lookup);
245 if (!IS_ERR(cell))
249 /* Assume we're probably going to create a cell and preallocate and
263 * cell whilst we were allocating.
285 cell = candidate;
287 atomic_set(&cell->active, 2);
288 trace_afs_cell(cell->debug_id, atomic_read(&cell->ref), 2, afs_cell_trace_insert);
289 rb_link_node_rcu(&cell->net_node, parent, pp);
290 rb_insert_color(&cell->net_node, &net->cells);
293 afs_queue_cell(cell, afs_cell_trace_get_queue_new);
296 trace_afs_cell(cell->debug_id, atomic_read(&cell->ref), atomic_read(&cell->active),
299 wait_var_event(&cell->state,
301 state = smp_load_acquire(&cell->state); /* vs error */
307 ret = cell->error;
311 _leave(" = %p [cell]", cell);
312 return cell;
315 _debug("cell exists");
316 cell = cursor;
330 afs_unuse_cell(net, cell, afs_cell_trace_unuse_lookup);
337 * set the root cell information
351 * - in the future we might initialize cell DB here.
367 /* allocate a cell record for the root cell */
377 /* install the new cell */
390 * Update a cell's VL server address list from the DNS.
392 static int afs_update_cell(struct afs_cell *cell)
400 _enter("%s", cell->name);
402 vllist = afs_dns_query(cell, &expiry);
406 _debug("%s: fail %d", cell->name, ret);
432 _debug("%s: got list %d %d", cell->name, vllist->source, vllist->status);
433 cell->dns_status = vllist->status;
443 _debug("%s: status %d", cell->name, vllist->status);
447 /* The DNS said that the cell does not exist or there
450 cell->dns_expiry = expiry;
458 cell->dns_expiry = now + 10;
462 cell->dns_expiry = expiry;
468 write_lock(&cell->vl_servers_lock);
469 p = rcu_dereference_protected(cell->vl_servers, true);
471 rcu_assign_pointer(cell->vl_servers, vllist);
472 cell->dns_source = vllist->source;
475 write_unlock(&cell->vl_servers_lock);
476 afs_put_vlserverlist(cell->net, old);
479 smp_store_release(&cell->dns_lookup_count,
480 cell->dns_lookup_count + 1); /* vs source/status */
481 wake_up_var(&cell->dns_lookup_count);
487 * Destroy a cell record
491 struct afs_cell *cell = container_of(rcu, struct afs_cell, rcu);
492 struct afs_net *net = cell->net;
495 _enter("%p{%s}", cell, cell->name);
497 u = atomic_read(&cell->ref);
499 trace_afs_cell(cell->debug_id, u, atomic_read(&cell->active), afs_cell_trace_free);
501 afs_put_vlserverlist(net, rcu_access_pointer(cell->vl_servers));
502 afs_unuse_cell(net, cell->alias_of, afs_cell_trace_unuse_alias);
503 key_put(cell->anonymous_key);
504 kfree(cell->name);
505 kfree(cell);
512 * Queue the cell manager.
538 * Get a reference on a cell record.
540 struct afs_cell *afs_get_cell(struct afs_cell *cell, enum afs_cell_trace reason)
544 if (atomic_read(&cell->ref) <= 0)
547 u = atomic_inc_return(&cell->ref);
548 trace_afs_cell(cell->debug_id, u, atomic_read(&cell->active), reason);
549 return cell;
553 * Drop a reference on a cell record.
555 void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)
557 if (cell) {
558 unsigned int debug_id = cell->debug_id;
561 a = atomic_read(&cell->active);
562 u = atomic_dec_return(&cell->ref);
565 a = atomic_read(&cell->active);
567 call_rcu(&cell->rcu, afs_cell_destroy);
573 * Note a cell becoming more active.
575 struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason)
579 if (atomic_read(&cell->ref) <= 0)
582 u = atomic_read(&cell->ref);
583 a = atomic_inc_return(&cell->active);
584 trace_afs_cell(cell->debug_id, u, a, reason);
585 return cell;
589 * Record a cell becoming less active. When the active counter reaches 1, it
592 void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_trace reason)
598 if (!cell)
601 _enter("%s", cell->name);
604 cell->last_inactive = now;
606 if (cell->vl_servers->nr_servers)
609 debug_id = cell->debug_id;
610 u = atomic_read(&cell->ref);
611 a = atomic_dec_return(&cell->active);
615 /* 'cell' may now be garbage collected. */
620 * Note that a cell has been seen.
622 void afs_see_cell(struct afs_cell *cell, enum afs_cell_trace reason)
626 u = atomic_read(&cell->ref);
627 a = atomic_read(&cell->active);
628 trace_afs_cell(cell->debug_id, u, a, reason);
632 * Queue a cell for management, giving the workqueue a ref to hold.
634 void afs_queue_cell(struct afs_cell *cell, enum afs_cell_trace reason)
636 afs_get_cell(cell, reason);
637 if (!queue_work(afs_wq, &cell->manager))
638 afs_put_cell(cell, afs_cell_trace_put_queue_fail);
644 static int afs_alloc_anon_key(struct afs_cell *cell)
652 cp = cell->name;
661 cell->anonymous_key = key;
664 cell->anonymous_key, key_serial(cell->anonymous_key));
669 * Activate a cell.
671 static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)
677 if (!cell->anonymous_key) {
678 ret = afs_alloc_anon_key(cell);
684 cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index,
686 cell->name, strlen(cell->name),
688 cell, 0, true);
690 ret = afs_proc_cell_setup(cell);
697 if (strcmp(cell->name, pcell->name) < 0)
701 cell->proc_link.pprev = p;
702 cell->proc_link.next = *p;
703 rcu_assign_pointer(*p, &cell->proc_link.next);
704 if (cell->proc_link.next)
705 cell->proc_link.next->pprev = &cell->proc_link.next;
707 afs_dynroot_mkdir(net, cell);
713 * Deactivate a cell.
715 static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell)
717 _enter("%s", cell->name);
719 afs_proc_cell_remove(cell);
722 hlist_del_rcu(&cell->proc_link);
723 afs_dynroot_rmdir(net, cell);
727 fscache_relinquish_cookie(cell->cache, NULL, false);
728 cell->cache = NULL;
735 * Manage a cell record, initialising and destroying it, maintaining its DNS
738 static void afs_manage_cell(struct afs_cell *cell)
740 struct afs_net *net = cell->net;
743 _enter("%s", cell->name);
746 _debug("state %u", cell->state);
747 switch (cell->state) {
752 if (atomic_try_cmpxchg_relaxed(&cell->active, &active, 0)) {
753 rb_erase(&cell->net_node, &net->cells);
754 trace_afs_cell(cell->debug_id, atomic_read(&cell->ref), 0,
756 smp_store_release(&cell->state, AFS_CELL_REMOVED);
759 if (cell->state == AFS_CELL_REMOVED) {
760 wake_up_var(&cell->state);
763 if (cell->state == AFS_CELL_FAILED)
765 smp_store_release(&cell->state, AFS_CELL_UNSET);
766 wake_up_var(&cell->state);
770 smp_store_release(&cell->state, AFS_CELL_ACTIVATING);
771 wake_up_var(&cell->state);
775 ret = afs_activate_cell(net, cell);
779 smp_store_release(&cell->state, AFS_CELL_ACTIVE);
780 wake_up_var(&cell->state);
784 if (atomic_read(&cell->active) > 1) {
785 if (test_and_clear_bit(AFS_CELL_FL_DO_LOOKUP, &cell->flags)) {
786 ret = afs_update_cell(cell);
788 cell->error = ret;
792 smp_store_release(&cell->state, AFS_CELL_DEACTIVATING);
793 wake_up_var(&cell->state);
797 if (atomic_read(&cell->active) > 1)
799 afs_deactivate_cell(net, cell);
800 smp_store_release(&cell->state, AFS_CELL_INACTIVE);
801 wake_up_var(&cell->state);
810 _debug("bad state %u", cell->state);
814 cell->error = ret;
815 afs_deactivate_cell(net, cell);
817 smp_store_release(&cell->state, AFS_CELL_FAILED); /* vs error */
818 wake_up_var(&cell->state);
822 smp_store_release(&cell->state, AFS_CELL_ACTIVE);
823 wake_up_var(&cell->state);
828 _leave(" [done %u]", cell->state);
832 /* The root volume is pinning the cell */
833 afs_put_volume(cell->net, cell->root_volume, afs_volume_trace_put_cell_root);
834 cell->root_volume = NULL;
835 afs_put_cell(cell, afs_cell_trace_put_destroy);
840 struct afs_cell *cell = container_of(work, struct afs_cell, manager);
842 afs_manage_cell(cell);
843 afs_put_cell(cell, afs_cell_trace_put_queue_work);
851 * Note that constructed cell records may only be removed from net->cells by
868 /* Trawl the cell database looking for cells that have expired from
875 struct afs_cell *cell =
880 active = atomic_read(&cell->active);
881 trace_afs_cell(cell->debug_id, atomic_read(&cell->ref),
887 if (test_and_clear_bit(AFS_CELL_FL_NO_GC, &cell->flags)) {
888 active = atomic_dec_return(&cell->active);
889 trace_afs_cell(cell->debug_id, atomic_read(&cell->ref),
896 time64_t expire_at = cell->last_inactive;
898 read_lock(&cell->vl_servers_lock);
900 cell->vl_servers,
901 lockdep_is_held(&cell->vl_servers_lock));
904 read_unlock(&cell->vl_servers_lock);
912 if (test_bit(AFS_CELL_FL_DO_LOOKUP, &cell->flags))
917 afs_queue_cell(cell, afs_cell_trace_get_queue_manage);
942 * Purge in-memory cell database.