/* * Destroy a cell record */ static void afs_cell_destroy(struct rcu_head *rcu) { struct afs_cell *cell = container_of(rcu, struct afs_cell, rcu); _enter("%p{%s}", cell, cell->name); ASSERTCMP(atomic_read(&cell->usage), ==, 0); afs_put_vlserverlist(cell->net, rcu_access_pointer(cell->vl_servers)); key_put(cell->anonymous_key); kfree(cell); _leave(" [destroyed]"); }
/* * Tidy up a volume location server cursor and unlock the vnode. */ int afs_end_vlserver_operation(struct afs_vl_cursor *vc) { struct afs_net *net = vc->cell->net; if (vc->error == -EDESTADDRREQ || vc->error == -EADDRNOTAVAIL || vc->error == -ENETUNREACH || vc->error == -EHOSTUNREACH) afs_vl_dump_edestaddrreq(vc); afs_end_cursor(&vc->ac); afs_put_vlserverlist(net, vc->server_list); if (vc->error == -ECONNABORTED) vc->error = afs_abort_to_error(vc->ac.abort_code); return vc->error; }
/* * Select the vlserver to use. May be called multiple times to rotate * through the vlservers. */ bool afs_select_vlserver(struct afs_vl_cursor *vc) { struct afs_addr_list *alist; struct afs_vlserver *vlserver; struct afs_error e; u32 rtt; int error = vc->ac.error, i; _enter("%lx[%d],%lx[%d],%d,%d", vc->untried, vc->index, vc->ac.tried, vc->ac.index, error, vc->ac.abort_code); if (vc->flags & AFS_VL_CURSOR_STOP) { _leave(" = f [stopped]"); return false; } vc->nr_iterations++; /* Evaluate the result of the previous operation, if there was one. */ switch (error) { case SHRT_MAX: goto start; default: case 0: /* Success or local failure. Stop. */ vc->error = error; vc->flags |= AFS_VL_CURSOR_STOP; _leave(" = f [okay/local %d]", vc->ac.error); return false; case -ECONNABORTED: /* The far side rejected the operation on some grounds. This * might involve the server being busy or the volume having been moved. */ switch (vc->ac.abort_code) { case AFSVL_IO: case AFSVL_BADVOLOPER: case AFSVL_NOMEM: /* The server went weird. */ vc->error = -EREMOTEIO; //write_lock(&vc->cell->vl_servers_lock); //vc->server_list->weird_mask |= 1 << vc->index; //write_unlock(&vc->cell->vl_servers_lock); goto next_server; default: vc->error = afs_abort_to_error(vc->ac.abort_code); goto failed; } case -ERFKILL: case -EADDRNOTAVAIL: case -ENETUNREACH: case -EHOSTUNREACH: case -EHOSTDOWN: case -ECONNREFUSED: case -ETIMEDOUT: case -ETIME: _debug("no conn %d", error); vc->error = error; goto iterate_address; case -ECONNRESET: _debug("call reset"); vc->error = error; vc->flags |= AFS_VL_CURSOR_RETRY; goto next_server; } restart_from_beginning: _debug("restart"); afs_end_cursor(&vc->ac); afs_put_vlserverlist(vc->cell->net, vc->server_list); vc->server_list = NULL; if (vc->flags & AFS_VL_CURSOR_RETRIED) goto failed; vc->flags |= AFS_VL_CURSOR_RETRIED; start: _debug("start"); if (!afs_start_vl_iteration(vc)) goto failed; error = afs_send_vl_probes(vc->cell->net, vc->key, vc->server_list); if (error < 0) goto failed_set_error; pick_server: _debug("pick [%lx]", vc->untried); error = afs_wait_for_vl_probes(vc->server_list, vc->untried); if (error < 0) goto failed_set_error; /* Pick the untried server with the lowest RTT. */ vc->index = vc->server_list->preferred; if (test_bit(vc->index, &vc->untried)) goto selected_server; vc->index = -1; rtt = U32_MAX; for (i = 0; i < vc->server_list->nr_servers; i++) { struct afs_vlserver *s = vc->server_list->servers[i].server; if (!test_bit(i, &vc->untried) || !s->probe.responded) continue; if (s->probe.rtt < rtt) { vc->index = i; rtt = s->probe.rtt; } } if (vc->index == -1) goto no_more_servers; selected_server: _debug("use %d", vc->index); __clear_bit(vc->index, &vc->untried); /* We're starting on a different vlserver from the list. We need to * check it, find its address list and probe its capabilities before we * use it. */ ASSERTCMP(vc->ac.alist, ==, NULL); vlserver = vc->server_list->servers[vc->index].server; vc->server = vlserver; _debug("USING VLSERVER: %s", vlserver->name); read_lock(&vlserver->lock); alist = rcu_dereference_protected(vlserver->addresses, lockdep_is_held(&vlserver->lock)); afs_get_addrlist(alist); read_unlock(&vlserver->lock); memset(&vc->ac, 0, sizeof(vc->ac)); if (!vc->ac.alist) vc->ac.alist = alist; else afs_put_addrlist(alist); vc->ac.index = -1; iterate_address: ASSERT(vc->ac.alist); /* Iterate over the current server's address list to try and find an * address on which it will respond to us. */ if (!afs_iterate_addresses(&vc->ac)) goto next_server; _debug("VL address %d/%d", vc->ac.index, vc->ac.alist->nr_addrs); _leave(" = t %pISpc", &vc->ac.alist->addrs[vc->ac.index].transport); return true; next_server: _debug("next"); afs_end_cursor(&vc->ac); goto pick_server; no_more_servers: /* That's all the servers poked to no good effect. Try again if some * of them were busy. */ if (vc->flags & AFS_VL_CURSOR_RETRY) goto restart_from_beginning; e.error = -EDESTADDRREQ; e.responded = false; for (i = 0; i < vc->server_list->nr_servers; i++) { struct afs_vlserver *s = vc->server_list->servers[i].server; afs_prioritise_error(&e, READ_ONCE(s->probe.error), s->probe.abort_code); } failed_set_error: vc->error = error; failed: vc->flags |= AFS_VL_CURSOR_STOP; afs_end_cursor(&vc->ac); _leave(" = f [failed %d]", vc->error); return false; }
/* * Update a cell's VL server address list from the DNS. */ static void afs_update_cell(struct afs_cell *cell) { struct afs_vlserver_list *vllist, *old; unsigned int min_ttl = READ_ONCE(afs_cell_min_ttl); unsigned int max_ttl = READ_ONCE(afs_cell_max_ttl); time64_t now, expiry = 0; _enter("%s", cell->name); vllist = afs_dns_query(cell, &expiry); now = ktime_get_real_seconds(); if (min_ttl > max_ttl) max_ttl = min_ttl; if (expiry < now + min_ttl) expiry = now + min_ttl; else if (expiry > now + max_ttl) expiry = now + max_ttl; if (IS_ERR(vllist)) { switch (PTR_ERR(vllist)) { case -ENODATA: case -EDESTADDRREQ: /* The DNS said that the cell does not exist or there * weren't any addresses to be had. */ set_bit(AFS_CELL_FL_NOT_FOUND, &cell->flags); clear_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags); cell->dns_expiry = expiry; break; case -EAGAIN: case -ECONNREFUSED: default: set_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags); cell->dns_expiry = now + 10; break; } cell->error = -EDESTADDRREQ; } else { clear_bit(AFS_CELL_FL_DNS_FAIL, &cell->flags); clear_bit(AFS_CELL_FL_NOT_FOUND, &cell->flags); /* Exclusion on changing vl_addrs is achieved by a * non-reentrant work item. */ old = rcu_dereference_protected(cell->vl_servers, true); rcu_assign_pointer(cell->vl_servers, vllist); cell->dns_expiry = expiry; if (old) afs_put_vlserverlist(cell->net, old); } if (test_and_clear_bit(AFS_CELL_FL_NO_LOOKUP_YET, &cell->flags)) wake_up_bit(&cell->flags, AFS_CELL_FL_NO_LOOKUP_YET); now = ktime_get_real_seconds(); afs_set_cell_timer(cell->net, cell->dns_expiry - now); _leave(""); }