Commit f94f70d3 authored by David Howells's avatar David Howells

afs: Provide a way to configure address priorities

AFS servers may have multiple addresses, but the client can't easily judge
between them as to which one is best.  For instance, an address that has a
larger RTT might actually have a better bandwidth because it goes through a
switch rather than being directly connected - but we can't work this out
dynamically unless we push through sufficient data that we can measure it.

To allow the administrator to configure this, add a list of preference
weightings for server addresses by IPv4/IPv6 address or subnet and allow
this to be viewed through a procfile and altered by writing text commands
to that same file.  Preference rules can be added/updated by:

	echo "add <proto> <addr>[/<subnet>] <prior>" >/proc/fs/afs/addr_prefs
	echo "add udp 1.2.3.4 1000" >/proc/fs/afs/addr_prefs
	echo "add udp 192.168.0.0/16 3000" >/proc/fs/afs/addr_prefs
	echo "add udp 1001:2002:0:6::/64 4000" >/proc/fs/afs/addr_prefs

and removed by:

	echo "del <proto> <addr>[/<subnet>]" >/proc/fs/afs/addr_prefs
	echo "del udp 1.2.3.4" >/proc/fs/afs/addr_prefs

where the priority is a number between 0 and 65535.

The list is split between IPv4 and IPv6 addresses and each sublist is kept
in numerical order, with rules that would otherwise match but have
different subnet masking being ordered with the most specific submatch
first.

A subsequent patch will apply these rules.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
parent b605ee42
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
kafs-y := \ kafs-y := \
addr_list.o \ addr_list.o \
addr_prefs.o \
callback.o \ callback.o \
cell.o \ cell.o \
cmservice.o \ cmservice.o \
......
This diff is collapsed.
...@@ -72,6 +72,28 @@ enum afs_call_state { ...@@ -72,6 +72,28 @@ enum afs_call_state {
AFS_CALL_COMPLETE, /* Completed or failed */ AFS_CALL_COMPLETE, /* Completed or failed */
}; };
/*
* Address preferences.
*/
struct afs_addr_preference {
union {
struct in_addr ipv4_addr; /* AF_INET address to compare against */
struct in6_addr ipv6_addr; /* AF_INET6 address to compare against */
};
sa_family_t family; /* Which address to use */
u16 prio; /* Priority */
u8 subnet_mask; /* How many bits to compare */
};
struct afs_addr_preference_list {
struct rcu_head rcu;
u16 version; /* Incremented when prefs list changes */
u8 ipv6_off; /* Offset of IPv6 addresses */
u8 nr; /* Number of addresses in total */
u8 max_prefs; /* Number of prefs allocated */
struct afs_addr_preference prefs[] __counted_by(max_prefs);
};
struct afs_address { struct afs_address {
struct rxrpc_peer *peer; struct rxrpc_peer *peer;
short last_error; /* Last error from this address */ short last_error; /* Last error from this address */
...@@ -315,6 +337,8 @@ struct afs_net { ...@@ -315,6 +337,8 @@ struct afs_net {
struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */ struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
struct afs_sysnames *sysnames; struct afs_sysnames *sysnames;
rwlock_t sysnames_lock; rwlock_t sysnames_lock;
struct afs_addr_preference_list __rcu *address_prefs;
u16 address_pref_version;
/* Statistics counters */ /* Statistics counters */
atomic_t n_lookup; /* Number of lookups done */ atomic_t n_lookup; /* Number of lookups done */
...@@ -982,6 +1006,11 @@ extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *addr, ...@@ -982,6 +1006,11 @@ extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *addr,
extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *addr, extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *addr,
__be32 *xdr, u16 port); __be32 *xdr, u16 port);
/*
* addr_prefs.c
*/
int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size);
/* /*
* callback.c * callback.c
*/ */
......
...@@ -156,6 +156,7 @@ static void __net_exit afs_net_exit(struct net *net_ns) ...@@ -156,6 +156,7 @@ static void __net_exit afs_net_exit(struct net *net_ns)
afs_close_socket(net); afs_close_socket(net);
afs_proc_cleanup(net); afs_proc_cleanup(net);
afs_put_sysnames(net->sysnames); afs_put_sysnames(net->sysnames);
kfree_rcu(rcu_access_pointer(net->address_prefs), rcu);
} }
static struct pernet_operations afs_net_ops = { static struct pernet_operations afs_net_ops = {
......
...@@ -146,6 +146,55 @@ static int afs_proc_cells_write(struct file *file, char *buf, size_t size) ...@@ -146,6 +146,55 @@ static int afs_proc_cells_write(struct file *file, char *buf, size_t size)
goto done; goto done;
} }
/*
* Display the list of addr_prefs known to the namespace.
*/
static int afs_proc_addr_prefs_show(struct seq_file *m, void *v)
{
struct afs_addr_preference_list *preflist;
struct afs_addr_preference *pref;
struct afs_net *net = afs_seq2net_single(m);
union {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} addr;
unsigned int i;
char buf[44]; /* Maximum ipv6 + max subnet is 43 */
rcu_read_lock();
preflist = rcu_dereference(net->address_prefs);
if (!preflist) {
seq_puts(m, "NO PREFS\n");
return 0;
}
seq_printf(m, "PROT SUBNET PRIOR (v=%u n=%u/%u/%u)\n",
preflist->version, preflist->ipv6_off, preflist->nr, preflist->max_prefs);
memset(&addr, 0, sizeof(addr));
for (i = 0; i < preflist->nr; i++) {
pref = &preflist->prefs[i];
addr.sin.sin_family = pref->family;
if (pref->family == AF_INET) {
memcpy(&addr.sin.sin_addr, &pref->ipv4_addr,
sizeof(addr.sin.sin_addr));
snprintf(buf, sizeof(buf), "%pISc/%u", &addr.sin, pref->subnet_mask);
seq_printf(m, "UDP %-43.43s %5u\n", buf, pref->prio);
} else {
memcpy(&addr.sin6.sin6_addr, &pref->ipv6_addr,
sizeof(addr.sin6.sin6_addr));
snprintf(buf, sizeof(buf), "%pISc/%u", &addr.sin6, pref->subnet_mask);
seq_printf(m, "UDP %-43.43s %5u\n", buf, pref->prio);
}
}
rcu_read_lock();
return 0;
}
/* /*
* Display the name of the current workstation cell. * Display the name of the current workstation cell.
*/ */
...@@ -690,6 +739,10 @@ int afs_proc_init(struct afs_net *net) ...@@ -690,6 +739,10 @@ int afs_proc_init(struct afs_net *net)
&afs_proc_sysname_ops, &afs_proc_sysname_ops,
afs_proc_sysname_write, afs_proc_sysname_write,
sizeof(struct seq_net_private), sizeof(struct seq_net_private),
NULL) ||
!proc_create_net_single_write("addr_prefs", 0644, p,
afs_proc_addr_prefs_show,
afs_proc_addr_prefs_write,
NULL)) NULL))
goto error_tree; goto error_tree;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment