Lines Matching full:server

2 /* AFS server record management
14 static unsigned afs_server_gc_delay = 10; /* Server record timeout in seconds */
22 * Find a server by one of its addresses.
28 struct afs_server *server = NULL; in afs_find_server() local
35 if (server) in afs_find_server()
36 afs_unuse_server_notime(net, server, afs_server_trace_put_find_rsq); in afs_find_server()
37 server = NULL; in afs_find_server()
41 hlist_for_each_entry_rcu(server, &net->fs_addresses, addr_link) { in afs_find_server()
42 estate = rcu_dereference(server->endpoint_state); in afs_find_server()
49 server = NULL; in afs_find_server()
52 server = afs_maybe_use_server(server, afs_server_trace_get_by_addr); in afs_find_server()
59 return server; in afs_find_server()
63 * Look up a server by its UUID and mark it active.
67 struct afs_server *server = NULL; in afs_find_server_by_uuid() local
78 if (server) in afs_find_server_by_uuid()
79 afs_unuse_server(net, server, afs_server_trace_put_uuid_rsq); in afs_find_server_by_uuid()
80 server = NULL; in afs_find_server_by_uuid()
86 server = rb_entry(p, struct afs_server, uuid_rb); in afs_find_server_by_uuid()
88 diff = memcmp(uuid, &server->uuid, sizeof(*uuid)); in afs_find_server_by_uuid()
94 afs_use_server(server, afs_server_trace_get_by_uuid); in afs_find_server_by_uuid()
98 server = NULL; in afs_find_server_by_uuid()
104 _leave(" = %p", server); in afs_find_server_by_uuid()
105 return server; in afs_find_server_by_uuid()
109 * Install a server record in the namespace tree. If there's a clash, we stick
118 struct afs_server *server, *next; in afs_install_server() local
127 /* Firstly install the server in the UUID lookup tree */ in afs_install_server()
133 server = rb_entry(p, struct afs_server, uuid_rb); in afs_install_server()
134 diff = memcmp(&candidate->uuid, &server->uuid, sizeof(uuid_t)); in afs_install_server()
140 if (server->cell == cell) in afs_install_server()
144 * different cells. Append the new server to the list. in afs_install_server()
148 server->uuid_next, in afs_install_server()
152 server = next; in afs_install_server()
154 rcu_assign_pointer(server->uuid_next, candidate); in afs_install_server()
155 candidate->uuid_prev = server; in afs_install_server()
156 server = candidate; in afs_install_server()
161 server = candidate; in afs_install_server()
162 rb_link_node(&server->uuid_rb, p, pp); in afs_install_server()
163 rb_insert_color(&server->uuid_rb, &net->fs_servers); in afs_install_server()
164 hlist_add_head_rcu(&server->proc_link, &net->fs_proc); in afs_install_server()
168 estate = rcu_dereference_protected(server->endpoint_state, in afs_install_server()
172 /* Secondly, if the server has any IPv4 and/or IPv6 addresses, install in afs_install_server()
181 hlist_add_head_rcu(&server->addr_link, &net->fs_addresses); in afs_install_server()
186 afs_get_server(server, afs_server_trace_get_install); in afs_install_server()
188 return server; in afs_install_server()
192 * Allocate a new server record and mark it active.
199 struct afs_server *server; in afs_alloc_server() local
204 server = kzalloc(sizeof(struct afs_server), GFP_KERNEL); in afs_alloc_server()
205 if (!server) in afs_alloc_server()
212 refcount_set(&server->ref, 1); in afs_alloc_server()
213 atomic_set(&server->active, 1); in afs_alloc_server()
214 server->debug_id = atomic_inc_return(&afs_server_debug_id); in afs_alloc_server()
215 server->addr_version = alist->version; in afs_alloc_server()
216 server->uuid = *uuid; in afs_alloc_server()
217 rwlock_init(&server->fs_lock); in afs_alloc_server()
218 INIT_LIST_HEAD(&server->volumes); in afs_alloc_server()
219 init_waitqueue_head(&server->probe_wq); in afs_alloc_server()
220 INIT_LIST_HEAD(&server->probe_link); in afs_alloc_server()
221 spin_lock_init(&server->probe_lock); in afs_alloc_server()
222 server->cell = cell; in afs_alloc_server()
223 server->rtt = UINT_MAX; in afs_alloc_server()
224 server->service_id = FS_SERVICE; in afs_alloc_server()
226 server->probe_counter = 1; in afs_alloc_server()
227 server->probed_at = jiffies - LONG_MAX / 2; in afs_alloc_server()
230 estate->server_id = server->debug_id; in afs_alloc_server()
232 rcu_assign_pointer(server->endpoint_state, estate); in afs_alloc_server()
235 trace_afs_server(server->debug_id, 1, 1, afs_server_trace_alloc); in afs_alloc_server()
238 _leave(" = %p", server); in afs_alloc_server()
239 return server; in afs_alloc_server()
242 kfree(server); in afs_alloc_server()
249 * Look up an address record for a server
261 if (test_bit(AFS_VLSERVER_FL_IS_YFS, &vc.server->flags)) in afs_vl_lookup_addrs()
280 struct afs_server *server, *candidate; in afs_lookup_server() local
284 server = afs_find_server_by_uuid(cell->net, uuid); in afs_lookup_server()
285 if (server) { in afs_lookup_server()
286 if (server->addr_version != addr_version) in afs_lookup_server()
287 set_bit(AFS_SERVER_FL_NEEDS_UPDATE, &server->flags); in afs_lookup_server()
288 return server; in afs_lookup_server()
301 server = afs_install_server(cell, candidate); in afs_lookup_server()
302 if (server != candidate) { in afs_lookup_server()
310 afs_fs_probe_fileserver(cell->net, server, alist, key); in afs_lookup_server()
313 return server; in afs_lookup_server()
317 * Set the server timer to fire after a given delay, assuming it's not already
330 * Server management timer. We have an increment on fs_outstanding that we
343 * Get a reference on a server object.
345 struct afs_server *afs_get_server(struct afs_server *server, in afs_get_server() argument
351 __refcount_inc(&server->ref, &r); in afs_get_server()
352 a = atomic_read(&server->active); in afs_get_server()
353 trace_afs_server(server->debug_id, r + 1, a, reason); in afs_get_server()
354 return server; in afs_get_server()
358 * Try to get a reference on a server object.
360 static struct afs_server *afs_maybe_use_server(struct afs_server *server, in afs_maybe_use_server() argument
366 if (!__refcount_inc_not_zero(&server->ref, &r)) in afs_maybe_use_server()
369 a = atomic_inc_return(&server->active); in afs_maybe_use_server()
370 trace_afs_server(server->debug_id, r + 1, a, reason); in afs_maybe_use_server()
371 return server; in afs_maybe_use_server()
375 * Get an active count on a server object.
377 struct afs_server *afs_use_server(struct afs_server *server, enum afs_server_trace reason) in afs_use_server() argument
382 __refcount_inc(&server->ref, &r); in afs_use_server()
383 a = atomic_inc_return(&server->active); in afs_use_server()
385 trace_afs_server(server->debug_id, r + 1, a, reason); in afs_use_server()
386 return server; in afs_use_server()
390 * Release a reference on a server record.
392 void afs_put_server(struct afs_net *net, struct afs_server *server, in afs_put_server() argument
395 unsigned int a, debug_id = server->debug_id; in afs_put_server()
399 if (!server) in afs_put_server()
402 a = atomic_read(&server->active); in afs_put_server()
403 zero = __refcount_dec_and_test(&server->ref, &r); in afs_put_server()
406 __afs_put_server(net, server); in afs_put_server()
410 * Drop an active count on a server object without updating the last-unused
413 void afs_unuse_server_notime(struct afs_net *net, struct afs_server *server, in afs_unuse_server_notime() argument
416 if (server) { in afs_unuse_server_notime()
417 unsigned int active = atomic_dec_return(&server->active); in afs_unuse_server_notime()
421 afs_put_server(net, server, reason); in afs_unuse_server_notime()
426 * Drop an active count on a server object.
428 void afs_unuse_server(struct afs_net *net, struct afs_server *server, in afs_unuse_server() argument
431 if (server) { in afs_unuse_server()
432 server->unuse_time = ktime_get_real_seconds(); in afs_unuse_server()
433 afs_unuse_server_notime(net, server, reason); in afs_unuse_server()
439 struct afs_server *server = container_of(rcu, struct afs_server, rcu); in afs_server_rcu() local
441 trace_afs_server(server->debug_id, refcount_read(&server->ref), in afs_server_rcu()
442 atomic_read(&server->active), afs_server_trace_free); in afs_server_rcu()
443 afs_put_endpoint_state(rcu_access_pointer(server->endpoint_state), in afs_server_rcu()
445 kfree(server); in afs_server_rcu()
448 static void __afs_put_server(struct afs_net *net, struct afs_server *server) in __afs_put_server() argument
450 call_rcu(&server->rcu, afs_server_rcu); in __afs_put_server()
454 static void afs_give_up_callbacks(struct afs_net *net, struct afs_server *server) in afs_give_up_callbacks() argument
456 struct afs_endpoint_state *estate = rcu_access_pointer(server->endpoint_state); in afs_give_up_callbacks()
459 afs_fs_give_up_all_callbacks(net, server, &alist->addrs[alist->preferred], NULL); in afs_give_up_callbacks()
463 * destroy a dead server
465 static void afs_destroy_server(struct afs_net *net, struct afs_server *server) in afs_destroy_server() argument
467 if (test_bit(AFS_SERVER_FL_MAY_HAVE_CB, &server->flags)) in afs_destroy_server()
468 afs_give_up_callbacks(net, server); in afs_destroy_server()
470 afs_put_server(net, server, afs_server_trace_destroy); in afs_destroy_server()
478 struct afs_server *server, *next, *prev; in afs_gc_servers() local
481 while ((server = gc_list)) { in afs_gc_servers()
482 gc_list = server->gc_next; in afs_gc_servers()
486 active = atomic_read(&server->active); in afs_gc_servers()
488 trace_afs_server(server->debug_id, refcount_read(&server->ref), in afs_gc_servers()
491 server->uuid_next, lockdep_is_held(&net->fs_lock.lock)); in afs_gc_servers()
492 prev = server->uuid_prev; in afs_gc_servers()
496 rb_erase(&server->uuid_rb, &net->fs_servers); in afs_gc_servers()
498 rb_replace_node_rcu(&server->uuid_rb, in afs_gc_servers()
504 /* This server is not at the front */ in afs_gc_servers()
510 list_del(&server->probe_link); in afs_gc_servers()
511 hlist_del_rcu(&server->proc_link); in afs_gc_servers()
512 if (!hlist_unhashed(&server->addr_link)) in afs_gc_servers()
513 hlist_del_rcu(&server->addr_link); in afs_gc_servers()
518 afs_destroy_server(net, server); in afs_gc_servers()
539 /* Trawl the server list looking for servers that have expired from in afs_manage_servers()
545 struct afs_server *server = in afs_manage_servers() local
547 int active = atomic_read(&server->active); in afs_manage_servers()
549 _debug("manage %pU %u", &server->uuid, active); in afs_manage_servers()
552 trace_afs_server(server->debug_id, refcount_read(&server->ref), in afs_manage_servers()
555 pr_notice("Can't purge s=%08x\n", server->debug_id); in afs_manage_servers()
559 time64_t expire_at = server->unuse_time; in afs_manage_servers()
561 if (!test_bit(AFS_SERVER_FL_VL_FAIL, &server->flags) && in afs_manage_servers()
562 !test_bit(AFS_SERVER_FL_NOT_FOUND, &server->flags)) in afs_manage_servers()
565 server->gc_next = gc_list; in afs_manage_servers()
566 gc_list = server; in afs_manage_servers()
623 * Get an update for a server's address list.
626 struct afs_server *server, in afs_update_server_record() argument
635 trace_afs_server(server->debug_id, refcount_read(&server->ref), in afs_update_server_record()
636 atomic_read(&server->active), in afs_update_server_record()
639 alist = afs_vl_lookup_addrs(op->volume->cell, op->key, &server->uuid); in afs_update_server_record()
642 estate = rcu_dereference(server->endpoint_state); in afs_update_server_record()
658 if (server->addr_version != alist->version) in afs_update_server_record()
659 afs_fs_probe_fileserver(op->net, server, alist, key); in afs_update_server_record()
667 * See if a server's address list needs updating.
669 bool afs_check_server_record(struct afs_operation *op, struct afs_server *server, in afs_check_server_record() argument
677 ASSERT(server); in afs_check_server_record()
680 if (test_bit(AFS_SERVER_FL_UPDATING, &server->flags)) in afs_check_server_record()
682 if (test_bit(AFS_SERVER_FL_NEEDS_UPDATE, &server->flags)) in afs_check_server_record()
688 if (!test_and_set_bit_lock(AFS_SERVER_FL_UPDATING, &server->flags)) { in afs_check_server_record()
689 clear_bit(AFS_SERVER_FL_NEEDS_UPDATE, &server->flags); in afs_check_server_record()
690 success = afs_update_server_record(op, server, key); in afs_check_server_record()
691 clear_bit_unlock(AFS_SERVER_FL_UPDATING, &server->flags); in afs_check_server_record()
692 wake_up_bit(&server->flags, AFS_SERVER_FL_UPDATING); in afs_check_server_record()
698 ret = wait_on_bit(&server->flags, AFS_SERVER_FL_UPDATING, in afs_check_server_record()