mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-18 08:56:48 +07:00
20325960f8
Reorganise afs_volume objects such that they're in a tree keyed on volume ID, rooted at on an afs_cell object rather than being in multiple trees, each of which is rooted on an afs_server object. afs_server structs become per-cell and acquire a pointer to the cell. The process of breaking a callback then starts with finding the server by its network address, following that to the cell and then looking up each volume ID in the volume tree. This is simpler than the afs_vol_interest/afs_cb_interest N:M mapping web and allows those structs and the code for maintaining them to be simplified or removed. It does make a couple of things a bit more tricky, though: (1) Operations now start with a volume, not a server, so there can be more than one answer as to whether or not the server we'll end up using supports the FS.InlineBulkStatus RPC. (2) CB RPC operations that specify the server UUID. There's still a tree of servers by UUID on the afs_net struct, but the UUIDs in it aren't guaranteed unique. Signed-off-by: David Howells <dhowells@redhat.com>
130 lines
2.9 KiB
C
130 lines
2.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/* AFS fileserver list management.
|
|
*
|
|
* Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include "internal.h"
|
|
|
|
void afs_put_serverlist(struct afs_net *net, struct afs_server_list *slist)
|
|
{
|
|
int i;
|
|
|
|
if (slist && refcount_dec_and_test(&slist->usage)) {
|
|
for (i = 0; i < slist->nr_servers; i++)
|
|
afs_unuse_server(net, slist->servers[i].server,
|
|
afs_server_trace_put_slist);
|
|
kfree(slist);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Build a server list from a VLDB record.
|
|
*/
|
|
struct afs_server_list *afs_alloc_server_list(struct afs_cell *cell,
|
|
struct key *key,
|
|
struct afs_vldb_entry *vldb,
|
|
u8 type_mask)
|
|
{
|
|
struct afs_server_list *slist;
|
|
struct afs_server *server;
|
|
int ret = -ENOMEM, nr_servers = 0, i, j;
|
|
|
|
for (i = 0; i < vldb->nr_servers; i++)
|
|
if (vldb->fs_mask[i] & type_mask)
|
|
nr_servers++;
|
|
|
|
slist = kzalloc(struct_size(slist, servers, nr_servers), GFP_KERNEL);
|
|
if (!slist)
|
|
goto error;
|
|
|
|
refcount_set(&slist->usage, 1);
|
|
rwlock_init(&slist->lock);
|
|
|
|
for (i = 0; i < AFS_MAXTYPES; i++)
|
|
slist->vids[i] = vldb->vid[i];
|
|
|
|
/* Make sure a records exists for each server in the list. */
|
|
for (i = 0; i < vldb->nr_servers; i++) {
|
|
if (!(vldb->fs_mask[i] & type_mask))
|
|
continue;
|
|
|
|
server = afs_lookup_server(cell, key, &vldb->fs_server[i],
|
|
vldb->addr_version[i]);
|
|
if (IS_ERR(server)) {
|
|
ret = PTR_ERR(server);
|
|
if (ret == -ENOENT ||
|
|
ret == -ENOMEDIUM)
|
|
continue;
|
|
goto error_2;
|
|
}
|
|
|
|
/* Insertion-sort by UUID */
|
|
for (j = 0; j < slist->nr_servers; j++)
|
|
if (memcmp(&slist->servers[j].server->uuid,
|
|
&server->uuid,
|
|
sizeof(server->uuid)) >= 0)
|
|
break;
|
|
if (j < slist->nr_servers) {
|
|
if (slist->servers[j].server == server) {
|
|
afs_put_server(cell->net, server,
|
|
afs_server_trace_put_slist_isort);
|
|
continue;
|
|
}
|
|
|
|
memmove(slist->servers + j + 1,
|
|
slist->servers + j,
|
|
(slist->nr_servers - j) * sizeof(struct afs_server_entry));
|
|
}
|
|
|
|
slist->servers[j].server = server;
|
|
slist->nr_servers++;
|
|
}
|
|
|
|
if (slist->nr_servers == 0) {
|
|
ret = -EDESTADDRREQ;
|
|
goto error_2;
|
|
}
|
|
|
|
return slist;
|
|
|
|
error_2:
|
|
afs_put_serverlist(cell->net, slist);
|
|
error:
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
/*
|
|
* Copy the annotations from an old server list to its potential replacement.
|
|
*/
|
|
bool afs_annotate_server_list(struct afs_server_list *new,
|
|
struct afs_server_list *old)
|
|
{
|
|
struct afs_server *cur;
|
|
int i, j;
|
|
|
|
if (old->nr_servers != new->nr_servers)
|
|
goto changed;
|
|
|
|
for (i = 0; i < old->nr_servers; i++)
|
|
if (old->servers[i].server != new->servers[i].server)
|
|
goto changed;
|
|
|
|
return false;
|
|
|
|
changed:
|
|
/* Maintain the same preferred server as before if possible. */
|
|
cur = old->servers[old->preferred].server;
|
|
for (j = 0; j < new->nr_servers; j++) {
|
|
if (new->servers[j].server == cur) {
|
|
new->preferred = j;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|