2019-05-27 13:55:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-04-27 05:49:28 +07:00
|
|
|
/* AFS client file system
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2009-04-03 22:42:41 +07:00
|
|
|
* Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
|
2005-04-17 05:20:36 +07:00
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/completion.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-21 04:22:52 +07:00
|
|
|
#include <linux/sched.h>
|
2016-08-30 22:05:14 +07:00
|
|
|
#include <linux/random.h>
|
2018-05-18 17:46:15 +07:00
|
|
|
#include <linux/proc_fs.h>
|
2017-01-05 17:38:34 +07:00
|
|
|
#define CREATE_TRACE_POINTS
|
2005-04-17 05:20:36 +07:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("AFS Client File System");
|
|
|
|
MODULE_AUTHOR("Red Hat, Inc.");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2007-04-27 05:55:03 +07:00
|
|
|
unsigned afs_debug;
|
|
|
|
module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
|
2008-04-16 17:08:22 +07:00
|
|
|
MODULE_PARM_DESC(debug, "AFS debugging mask");
|
2007-04-27 05:55:03 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static char *rootcell;
|
|
|
|
|
|
|
|
module_param(rootcell, charp, 0);
|
|
|
|
MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
|
|
|
|
|
2011-01-14 22:56:37 +07:00
|
|
|
struct workqueue_struct *afs_wq;
|
2018-05-18 17:46:15 +07:00
|
|
|
static struct proc_dir_entry *afs_proc_symlink;
|
2017-11-02 22:27:45 +07:00
|
|
|
|
2018-04-10 03:12:31 +07:00
|
|
|
#if defined(CONFIG_ALPHA)
|
|
|
|
const char afs_init_sysname[] = "alpha_linux26";
|
|
|
|
#elif defined(CONFIG_X86_64)
|
|
|
|
const char afs_init_sysname[] = "amd64_linux26";
|
|
|
|
#elif defined(CONFIG_ARM)
|
|
|
|
const char afs_init_sysname[] = "arm_linux26";
|
|
|
|
#elif defined(CONFIG_ARM64)
|
|
|
|
const char afs_init_sysname[] = "aarch64_linux26";
|
|
|
|
#elif defined(CONFIG_X86_32)
|
|
|
|
const char afs_init_sysname[] = "i386_linux26";
|
|
|
|
#elif defined(CONFIG_IA64)
|
|
|
|
const char afs_init_sysname[] = "ia64_linux26";
|
|
|
|
#elif defined(CONFIG_PPC64)
|
|
|
|
const char afs_init_sysname[] = "ppc64_linux26";
|
|
|
|
#elif defined(CONFIG_PPC32)
|
|
|
|
const char afs_init_sysname[] = "ppc_linux26";
|
|
|
|
#elif defined(CONFIG_S390)
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
const char afs_init_sysname[] = "s390x_linux26";
|
|
|
|
#else
|
|
|
|
const char afs_init_sysname[] = "s390_linux26";
|
|
|
|
#endif
|
|
|
|
#elif defined(CONFIG_SPARC64)
|
|
|
|
const char afs_init_sysname[] = "sparc64_linux26";
|
|
|
|
#elif defined(CONFIG_SPARC32)
|
|
|
|
const char afs_init_sysname[] = "sparc_linux26";
|
|
|
|
#else
|
|
|
|
const char afs_init_sysname[] = "unknown_linux26";
|
|
|
|
#endif
|
|
|
|
|
2017-11-02 22:27:45 +07:00
|
|
|
/*
|
|
|
|
* Initialise an AFS network namespace record.
|
|
|
|
*/
|
2018-05-18 17:46:15 +07:00
|
|
|
static int __net_init afs_net_init(struct net *net_ns)
|
2017-11-02 22:27:45 +07:00
|
|
|
{
|
2018-04-10 03:12:31 +07:00
|
|
|
struct afs_sysnames *sysnames;
|
2018-05-18 17:46:15 +07:00
|
|
|
struct afs_net *net = afs_net(net_ns);
|
2017-11-02 22:27:45 +07:00
|
|
|
int ret;
|
|
|
|
|
2018-05-18 17:46:15 +07:00
|
|
|
net->net = net_ns;
|
2017-11-02 22:27:45 +07:00
|
|
|
net->live = true;
|
|
|
|
generate_random_uuid((unsigned char *)&net->uuid);
|
|
|
|
|
|
|
|
INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
|
|
|
|
mutex_init(&net->socket_mutex);
|
2017-11-02 22:27:50 +07:00
|
|
|
|
|
|
|
net->cells = RB_ROOT;
|
afs: Fix rapid cell addition/removal by not using RCU on cells tree
There are a number of problems that are being seen by the rapidly mounting
and unmounting an afs dynamic root with an explicit cell and volume
specified (which should probably be rejected, but that's a separate issue):
What the tests are doing is to look up/create a cell record for the name
given and then tear it down again without actually using it to try to talk
to a server. This is repeated endlessly, very fast, and the new cell
collides with the old one if it's not quick enough to reuse it.
It appears (as suggested by Hillf Danton) that the search through the RB
tree under a read_seqbegin_or_lock() under RCU conditions isn't safe and
that it's not blocking the write_seqlock(), despite taking two passes at
it. He suggested that the code should take a ref on the cell it's
attempting to look at - but this shouldn't be necessary until we've
compared the cell names. It's possible that I'm missing a barrier
somewhere.
However, using an RCU search for this is overkill, really - we only need to
access the cell name in a few places, and they're places where we're may
end up sleeping anyway.
Fix this by switching to an R/W semaphore instead.
Additionally, draw the down_read() call inside the function (renamed to
afs_find_cell()) since all the callers were taking the RCU read lock (or
should've been[*]).
[*] afs_probe_cell_name() should have been, but that doesn't appear to be
involved in the bug reports.
The symptoms of this look like:
general protection fault, probably for non-canonical address 0xf27d208691691fdb: 0000 [#1] PREEMPT SMP KASAN
KASAN: maybe wild-memory-access in range [0x93e924348b48fed8-0x93e924348b48fedf]
...
RIP: 0010:strncasecmp lib/string.c:52 [inline]
RIP: 0010:strncasecmp+0x5f/0x240 lib/string.c:43
afs_lookup_cell_rcu+0x313/0x720 fs/afs/cell.c:88
afs_lookup_cell+0x2ee/0x1440 fs/afs/cell.c:249
afs_parse_source fs/afs/super.c:290 [inline]
...
Fixes: 989782dcdc91 ("afs: Overhaul cell database management")
Reported-by: syzbot+459a5dce0b4cb70fd076@syzkaller.appspotmail.com
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Hillf Danton <hdanton@sina.com>
cc: syzkaller-bugs@googlegroups.com
2020-10-09 20:11:58 +07:00
|
|
|
init_rwsem(&net->cells_lock);
|
2017-11-02 22:27:50 +07:00
|
|
|
INIT_WORK(&net->cells_manager, afs_manage_cells);
|
|
|
|
timer_setup(&net->cells_timer, afs_cells_timer, 0);
|
|
|
|
|
afs: Detect cell aliases 1 - Cells with root volumes
Put in the first phase of cell alias detection. This part handles alias
detection for cells that have root.cell volumes (which is expected to be
likely).
When a cell becomes newly active, it is probed for its root.cell volume,
and if it has one, this volume is compared against other root.cell volumes
to find out if the list of fileserver UUIDs have any in common - and if
that's the case, do the address lists of those fileservers have any
addresses in common. If they do, the new cell is adjudged to be an alias
of the old cell and the old cell is used instead.
Comparing is aided by the server list in struct afs_server_list being
sorted in UUID order and the addresses in the fileserver address lists
being sorted in address order.
The cell then retains the afs_volume object for the root.cell volume, even
if it's not mounted for future alias checking.
This necessary because:
(1) Whilst fileservers have UUIDs that are meant to be globally unique, in
practice they are not because cells get cloned without changing the
UUIDs - so afs_server records need to be per cell.
(2) Sometimes the DNS is used to make cell aliases - but if we don't know
they're the same, we may end up with multiple superblocks and multiple
afs_server records for the same thing, impairing our ability to
deliver callback notifications of third party changes
(3) The fileserver RPC API doesn't contain the cell name, so it can't tell
us which cell it's notifying and can't see that a change made to to
one cell should notify the same client that's also accessed as the
other cell.
Reported-by: Jeffrey Altman <jaltman@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
2020-04-25 16:26:02 +07:00
|
|
|
mutex_init(&net->cells_alias_lock);
|
2018-06-15 21:19:22 +07:00
|
|
|
mutex_init(&net->proc_cells_lock);
|
2018-10-12 04:45:49 +07:00
|
|
|
INIT_HLIST_HEAD(&net->proc_cells);
|
2017-11-02 22:27:50 +07:00
|
|
|
|
afs: Overhaul volume and server record caching and fileserver rotation
The current code assumes that volumes and servers are per-cell and are
never shared, but this is not enforced, and, indeed, public cells do exist
that are aliases of each other. Further, an organisation can, say, set up
a public cell and a private cell with overlapping, but not identical, sets
of servers. The difference is purely in the database attached to the VL
servers.
The current code will malfunction if it sees a server in two cells as it
assumes global address -> server record mappings and that each server is in
just one cell.
Further, each server may have multiple addresses - and may have addresses
of different families (IPv4 and IPv6, say).
To this end, the following structural changes are made:
(1) Server record management is overhauled:
(a) Server records are made independent of cell. The namespace keeps
track of them, volume records have lists of them and each vnode
has a server on which its callback interest currently resides.
(b) The cell record no longer keeps a list of servers known to be in
that cell.
(c) The server records are now kept in a flat list because there's no
single address to sort on.
(d) Server records are now keyed by their UUID within the namespace.
(e) The addresses for a server are obtained with the VL.GetAddrsU
rather than with VL.GetEntryByName, using the server's UUID as a
parameter.
(f) Cached server records are garbage collected after a period of
non-use and are counted out of existence before purging is allowed
to complete. This protects the work functions against rmmod.
(g) The servers list is now in /proc/fs/afs/servers.
(2) Volume record management is overhauled:
(a) An RCU-replaceable server list is introduced. This tracks both
servers and their coresponding callback interests.
(b) The superblock is now keyed on cell record and numeric volume ID.
(c) The volume record is now tied to the superblock which mounts it,
and is activated when mounted and deactivated when unmounted.
This makes it easier to handle the cache cookie without causing a
double-use in fscache.
(d) The volume record is loaded from the VLDB using VL.GetEntryByNameU
to get the server UUID list.
(e) The volume name is updated if it is seen to have changed when the
volume is updated (the update is keyed on the volume ID).
(3) The vlocation record is got rid of and VLDB records are no longer
cached. Sufficient information is stored in the volume record, though
an update to a volume record is now no longer shared between related
volumes (volumes come in bundles of three: R/W, R/O and backup).
and the following procedural changes are made:
(1) The fileserver cursor introduced previously is now fleshed out and
used to iterate over fileservers and their addresses.
(2) Volume status is checked during iteration, and the server list is
replaced if a change is detected.
(3) Server status is checked during iteration, and the address list is
replaced if a change is detected.
(4) The abort code is saved into the address list cursor and -ECONNABORTED
returned in afs_make_call() if a remote abort happened rather than
translating the abort into an error message. This allows actions to
be taken depending on the abort code more easily.
(a) If a VMOVED abort is seen then this is handled by rechecking the
volume and restarting the iteration.
(b) If a VBUSY, VRESTARTING or VSALVAGING abort is seen then this is
handled by sleeping for a short period and retrying and/or trying
other servers that might serve that volume. A message is also
displayed once until the condition has cleared.
(c) If a VOFFLINE abort is seen, then this is handled as VBUSY for the
moment.
(d) If a VNOVOL abort is seen, the volume is rechecked in the VLDB to
see if it has been deleted; if not, the fileserver is probably
indicating that the volume couldn't be attached and needs
salvaging.
(e) If statfs() sees one of these aborts, it does not sleep, but
rather returns an error, so as not to block the umount program.
(5) The fileserver iteration functions in vnode.c are now merged into
their callers and more heavily macroised around the cursor. vnode.c
is removed.
(6) Operations on a particular vnode are serialised on that vnode because
the server will lock that vnode whilst it operates on it, so a second
op sent will just have to wait.
(7) Fileservers are probed with FS.GetCapabilities before being used.
This is where service upgrade will be done.
(8) A callback interest on a fileserver is set up before an FS operation
is performed and passed through to afs_make_call() so that it can be
set on the vnode if the operation returns a callback. The callback
interest is passed through to afs_iget() also so that it can be set
there too.
In general, record updating is done on an as-needed basis when we try to
access servers, volumes or vnodes rather than offloading it to work items
and special threads.
Notes:
(1) Pre AFS-3.4 servers are no longer supported, though this can be added
back if necessary (AFS-3.4 was released in 1998).
(2) VBUSY is retried forever for the moment at intervals of 1s.
(3) /proc/fs/afs/<cell>/servers no longer exists.
Signed-off-by: David Howells <dhowells@redhat.com>
2017-11-02 22:27:50 +07:00
|
|
|
seqlock_init(&net->fs_lock);
|
|
|
|
net->fs_servers = RB_ROOT;
|
afs: Actively poll fileservers to maintain NAT or firewall openings
When an AFS client accesses a file, it receives a limited-duration callback
promise that the server will notify it if another client changes a file.
This callback duration can be a few hours in length.
If a client mounts a volume and then an application prevents it from being
unmounted, say by chdir'ing into it, but then does nothing for some time,
the rxrpc_peer record will expire and rxrpc-level keepalive will cease.
If there is NAT or a firewall between the client and the server, the route
back for the server may close after a comparatively short duration, meaning
that attempts by the server to notify the client may then bounce.
The client, however, may (so far as it knows) still have a valid unexpired
promise and will then rely on its cached data and will not see changes made
on the server by a third party until it incidentally rechecks the status or
the promise needs renewal.
To deal with this, the client needs to regularly probe the server. This
has two effects: firstly, it keeps a route open back for the server, and
secondly, it causes the server to disgorge any notifications that got
queued up because they couldn't be sent.
Fix this by adding a mechanism to emit regular probes.
Two levels of probing are made available: Under normal circumstances the
'slow' queue will be used for a fileserver - this just probes the preferred
address once every 5 mins or so; however, if server fails to respond to any
probes, the server will shift to the 'fast' queue from which all its
interfaces will be probed every 30s. When it finally responds, the record
will switch back to the slow queue.
Further notes:
(1) Probing is now no longer driven from the fileserver rotation
algorithm.
(2) Probes are dispatched to all interfaces on a fileserver when that an
afs_server object is set up to record it.
(3) The afs_server object is removed from the probe queues when we start
to probe it. afs_is_probing_server() returns true if it's not listed
- ie. it's undergoing probing.
(4) The afs_server object is added back on to the probe queue when the
final outstanding probe completes, but the probed_at time is set when
we're about to launch a probe so that it's not dependent on the probe
duration.
(5) The timer and the work item added for this must be handed a count on
net->servers_outstanding, which they hand on or release. This makes
sure that network namespace cleanup waits for them.
Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation")
Reported-by: Dave Botsch <botsch@cnf.cornell.edu>
Signed-off-by: David Howells <dhowells@redhat.com>
2020-04-24 21:10:00 +07:00
|
|
|
INIT_LIST_HEAD(&net->fs_probe_fast);
|
|
|
|
INIT_LIST_HEAD(&net->fs_probe_slow);
|
afs: Overhaul volume and server record caching and fileserver rotation
The current code assumes that volumes and servers are per-cell and are
never shared, but this is not enforced, and, indeed, public cells do exist
that are aliases of each other. Further, an organisation can, say, set up
a public cell and a private cell with overlapping, but not identical, sets
of servers. The difference is purely in the database attached to the VL
servers.
The current code will malfunction if it sees a server in two cells as it
assumes global address -> server record mappings and that each server is in
just one cell.
Further, each server may have multiple addresses - and may have addresses
of different families (IPv4 and IPv6, say).
To this end, the following structural changes are made:
(1) Server record management is overhauled:
(a) Server records are made independent of cell. The namespace keeps
track of them, volume records have lists of them and each vnode
has a server on which its callback interest currently resides.
(b) The cell record no longer keeps a list of servers known to be in
that cell.
(c) The server records are now kept in a flat list because there's no
single address to sort on.
(d) Server records are now keyed by their UUID within the namespace.
(e) The addresses for a server are obtained with the VL.GetAddrsU
rather than with VL.GetEntryByName, using the server's UUID as a
parameter.
(f) Cached server records are garbage collected after a period of
non-use and are counted out of existence before purging is allowed
to complete. This protects the work functions against rmmod.
(g) The servers list is now in /proc/fs/afs/servers.
(2) Volume record management is overhauled:
(a) An RCU-replaceable server list is introduced. This tracks both
servers and their coresponding callback interests.
(b) The superblock is now keyed on cell record and numeric volume ID.
(c) The volume record is now tied to the superblock which mounts it,
and is activated when mounted and deactivated when unmounted.
This makes it easier to handle the cache cookie without causing a
double-use in fscache.
(d) The volume record is loaded from the VLDB using VL.GetEntryByNameU
to get the server UUID list.
(e) The volume name is updated if it is seen to have changed when the
volume is updated (the update is keyed on the volume ID).
(3) The vlocation record is got rid of and VLDB records are no longer
cached. Sufficient information is stored in the volume record, though
an update to a volume record is now no longer shared between related
volumes (volumes come in bundles of three: R/W, R/O and backup).
and the following procedural changes are made:
(1) The fileserver cursor introduced previously is now fleshed out and
used to iterate over fileservers and their addresses.
(2) Volume status is checked during iteration, and the server list is
replaced if a change is detected.
(3) Server status is checked during iteration, and the address list is
replaced if a change is detected.
(4) The abort code is saved into the address list cursor and -ECONNABORTED
returned in afs_make_call() if a remote abort happened rather than
translating the abort into an error message. This allows actions to
be taken depending on the abort code more easily.
(a) If a VMOVED abort is seen then this is handled by rechecking the
volume and restarting the iteration.
(b) If a VBUSY, VRESTARTING or VSALVAGING abort is seen then this is
handled by sleeping for a short period and retrying and/or trying
other servers that might serve that volume. A message is also
displayed once until the condition has cleared.
(c) If a VOFFLINE abort is seen, then this is handled as VBUSY for the
moment.
(d) If a VNOVOL abort is seen, the volume is rechecked in the VLDB to
see if it has been deleted; if not, the fileserver is probably
indicating that the volume couldn't be attached and needs
salvaging.
(e) If statfs() sees one of these aborts, it does not sleep, but
rather returns an error, so as not to block the umount program.
(5) The fileserver iteration functions in vnode.c are now merged into
their callers and more heavily macroised around the cursor. vnode.c
is removed.
(6) Operations on a particular vnode are serialised on that vnode because
the server will lock that vnode whilst it operates on it, so a second
op sent will just have to wait.
(7) Fileservers are probed with FS.GetCapabilities before being used.
This is where service upgrade will be done.
(8) A callback interest on a fileserver is set up before an FS operation
is performed and passed through to afs_make_call() so that it can be
set on the vnode if the operation returns a callback. The callback
interest is passed through to afs_iget() also so that it can be set
there too.
In general, record updating is done on an as-needed basis when we try to
access servers, volumes or vnodes rather than offloading it to work items
and special threads.
Notes:
(1) Pre AFS-3.4 servers are no longer supported, though this can be added
back if necessary (AFS-3.4 was released in 1998).
(2) VBUSY is retried forever for the moment at intervals of 1s.
(3) /proc/fs/afs/<cell>/servers no longer exists.
Signed-off-by: David Howells <dhowells@redhat.com>
2017-11-02 22:27:50 +07:00
|
|
|
INIT_HLIST_HEAD(&net->fs_proc);
|
|
|
|
|
|
|
|
INIT_HLIST_HEAD(&net->fs_addresses4);
|
|
|
|
INIT_HLIST_HEAD(&net->fs_addresses6);
|
|
|
|
seqlock_init(&net->fs_addr_lock);
|
|
|
|
|
|
|
|
INIT_WORK(&net->fs_manager, afs_manage_servers);
|
|
|
|
timer_setup(&net->fs_timer, afs_servers_timer, 0);
|
afs: Actively poll fileservers to maintain NAT or firewall openings
When an AFS client accesses a file, it receives a limited-duration callback
promise that the server will notify it if another client changes a file.
This callback duration can be a few hours in length.
If a client mounts a volume and then an application prevents it from being
unmounted, say by chdir'ing into it, but then does nothing for some time,
the rxrpc_peer record will expire and rxrpc-level keepalive will cease.
If there is NAT or a firewall between the client and the server, the route
back for the server may close after a comparatively short duration, meaning
that attempts by the server to notify the client may then bounce.
The client, however, may (so far as it knows) still have a valid unexpired
promise and will then rely on its cached data and will not see changes made
on the server by a third party until it incidentally rechecks the status or
the promise needs renewal.
To deal with this, the client needs to regularly probe the server. This
has two effects: firstly, it keeps a route open back for the server, and
secondly, it causes the server to disgorge any notifications that got
queued up because they couldn't be sent.
Fix this by adding a mechanism to emit regular probes.
Two levels of probing are made available: Under normal circumstances the
'slow' queue will be used for a fileserver - this just probes the preferred
address once every 5 mins or so; however, if server fails to respond to any
probes, the server will shift to the 'fast' queue from which all its
interfaces will be probed every 30s. When it finally responds, the record
will switch back to the slow queue.
Further notes:
(1) Probing is now no longer driven from the fileserver rotation
algorithm.
(2) Probes are dispatched to all interfaces on a fileserver when that an
afs_server object is set up to record it.
(3) The afs_server object is removed from the probe queues when we start
to probe it. afs_is_probing_server() returns true if it's not listed
- ie. it's undergoing probing.
(4) The afs_server object is added back on to the probe queue when the
final outstanding probe completes, but the probed_at time is set when
we're about to launch a probe so that it's not dependent on the probe
duration.
(5) The timer and the work item added for this must be handed a count on
net->servers_outstanding, which they hand on or release. This makes
sure that network namespace cleanup waits for them.
Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation")
Reported-by: Dave Botsch <botsch@cnf.cornell.edu>
Signed-off-by: David Howells <dhowells@redhat.com>
2020-04-24 21:10:00 +07:00
|
|
|
INIT_WORK(&net->fs_prober, afs_fs_probe_dispatcher);
|
|
|
|
timer_setup(&net->fs_probe_timer, afs_fs_probe_timer, 0);
|
2020-06-20 05:39:36 +07:00
|
|
|
atomic_set(&net->servers_outstanding, 1);
|
2017-11-02 22:27:45 +07:00
|
|
|
|
2018-04-10 03:12:31 +07:00
|
|
|
ret = -ENOMEM;
|
|
|
|
sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
|
|
|
|
if (!sysnames)
|
|
|
|
goto error_sysnames;
|
|
|
|
sysnames->subs[0] = (char *)&afs_init_sysname;
|
|
|
|
sysnames->nr = 1;
|
|
|
|
refcount_set(&sysnames->usage, 1);
|
|
|
|
net->sysnames = sysnames;
|
|
|
|
rwlock_init(&net->sysnames_lock);
|
|
|
|
|
2017-11-02 22:27:45 +07:00
|
|
|
/* Register the /proc stuff */
|
|
|
|
ret = afs_proc_init(net);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error_proc;
|
|
|
|
|
|
|
|
/* Initialise the cell DB */
|
|
|
|
ret = afs_cell_init(net, rootcell);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error_cell_init;
|
|
|
|
|
|
|
|
/* Create the RxRPC transport */
|
|
|
|
ret = afs_open_socket(net);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error_open_socket;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_open_socket:
|
2017-11-02 22:27:50 +07:00
|
|
|
net->live = false;
|
2020-06-20 05:39:36 +07:00
|
|
|
afs_fs_probe_cleanup(net);
|
2017-11-02 22:27:45 +07:00
|
|
|
afs_cell_purge(net);
|
afs: Overhaul volume and server record caching and fileserver rotation
The current code assumes that volumes and servers are per-cell and are
never shared, but this is not enforced, and, indeed, public cells do exist
that are aliases of each other. Further, an organisation can, say, set up
a public cell and a private cell with overlapping, but not identical, sets
of servers. The difference is purely in the database attached to the VL
servers.
The current code will malfunction if it sees a server in two cells as it
assumes global address -> server record mappings and that each server is in
just one cell.
Further, each server may have multiple addresses - and may have addresses
of different families (IPv4 and IPv6, say).
To this end, the following structural changes are made:
(1) Server record management is overhauled:
(a) Server records are made independent of cell. The namespace keeps
track of them, volume records have lists of them and each vnode
has a server on which its callback interest currently resides.
(b) The cell record no longer keeps a list of servers known to be in
that cell.
(c) The server records are now kept in a flat list because there's no
single address to sort on.
(d) Server records are now keyed by their UUID within the namespace.
(e) The addresses for a server are obtained with the VL.GetAddrsU
rather than with VL.GetEntryByName, using the server's UUID as a
parameter.
(f) Cached server records are garbage collected after a period of
non-use and are counted out of existence before purging is allowed
to complete. This protects the work functions against rmmod.
(g) The servers list is now in /proc/fs/afs/servers.
(2) Volume record management is overhauled:
(a) An RCU-replaceable server list is introduced. This tracks both
servers and their coresponding callback interests.
(b) The superblock is now keyed on cell record and numeric volume ID.
(c) The volume record is now tied to the superblock which mounts it,
and is activated when mounted and deactivated when unmounted.
This makes it easier to handle the cache cookie without causing a
double-use in fscache.
(d) The volume record is loaded from the VLDB using VL.GetEntryByNameU
to get the server UUID list.
(e) The volume name is updated if it is seen to have changed when the
volume is updated (the update is keyed on the volume ID).
(3) The vlocation record is got rid of and VLDB records are no longer
cached. Sufficient information is stored in the volume record, though
an update to a volume record is now no longer shared between related
volumes (volumes come in bundles of three: R/W, R/O and backup).
and the following procedural changes are made:
(1) The fileserver cursor introduced previously is now fleshed out and
used to iterate over fileservers and their addresses.
(2) Volume status is checked during iteration, and the server list is
replaced if a change is detected.
(3) Server status is checked during iteration, and the address list is
replaced if a change is detected.
(4) The abort code is saved into the address list cursor and -ECONNABORTED
returned in afs_make_call() if a remote abort happened rather than
translating the abort into an error message. This allows actions to
be taken depending on the abort code more easily.
(a) If a VMOVED abort is seen then this is handled by rechecking the
volume and restarting the iteration.
(b) If a VBUSY, VRESTARTING or VSALVAGING abort is seen then this is
handled by sleeping for a short period and retrying and/or trying
other servers that might serve that volume. A message is also
displayed once until the condition has cleared.
(c) If a VOFFLINE abort is seen, then this is handled as VBUSY for the
moment.
(d) If a VNOVOL abort is seen, the volume is rechecked in the VLDB to
see if it has been deleted; if not, the fileserver is probably
indicating that the volume couldn't be attached and needs
salvaging.
(e) If statfs() sees one of these aborts, it does not sleep, but
rather returns an error, so as not to block the umount program.
(5) The fileserver iteration functions in vnode.c are now merged into
their callers and more heavily macroised around the cursor. vnode.c
is removed.
(6) Operations on a particular vnode are serialised on that vnode because
the server will lock that vnode whilst it operates on it, so a second
op sent will just have to wait.
(7) Fileservers are probed with FS.GetCapabilities before being used.
This is where service upgrade will be done.
(8) A callback interest on a fileserver is set up before an FS operation
is performed and passed through to afs_make_call() so that it can be
set on the vnode if the operation returns a callback. The callback
interest is passed through to afs_iget() also so that it can be set
there too.
In general, record updating is done on an as-needed basis when we try to
access servers, volumes or vnodes rather than offloading it to work items
and special threads.
Notes:
(1) Pre AFS-3.4 servers are no longer supported, though this can be added
back if necessary (AFS-3.4 was released in 1998).
(2) VBUSY is retried forever for the moment at intervals of 1s.
(3) /proc/fs/afs/<cell>/servers no longer exists.
Signed-off-by: David Howells <dhowells@redhat.com>
2017-11-02 22:27:50 +07:00
|
|
|
afs_purge_servers(net);
|
2017-11-02 22:27:45 +07:00
|
|
|
error_cell_init:
|
2017-11-02 22:27:50 +07:00
|
|
|
net->live = false;
|
2017-11-02 22:27:45 +07:00
|
|
|
afs_proc_cleanup(net);
|
|
|
|
error_proc:
|
2018-04-10 03:12:31 +07:00
|
|
|
afs_put_sysnames(net->sysnames);
|
|
|
|
error_sysnames:
|
2017-11-02 22:27:50 +07:00
|
|
|
net->live = false;
|
2017-11-02 22:27:45 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up and destroy an AFS network namespace record.
|
|
|
|
*/
|
2018-05-18 17:46:15 +07:00
|
|
|
static void __net_exit afs_net_exit(struct net *net_ns)
|
2017-11-02 22:27:45 +07:00
|
|
|
{
|
2018-05-18 17:46:15 +07:00
|
|
|
struct afs_net *net = afs_net(net_ns);
|
|
|
|
|
2017-11-02 22:27:45 +07:00
|
|
|
net->live = false;
|
2020-06-20 05:39:36 +07:00
|
|
|
afs_fs_probe_cleanup(net);
|
2017-11-02 22:27:45 +07:00
|
|
|
afs_cell_purge(net);
|
afs: Overhaul volume and server record caching and fileserver rotation
The current code assumes that volumes and servers are per-cell and are
never shared, but this is not enforced, and, indeed, public cells do exist
that are aliases of each other. Further, an organisation can, say, set up
a public cell and a private cell with overlapping, but not identical, sets
of servers. The difference is purely in the database attached to the VL
servers.
The current code will malfunction if it sees a server in two cells as it
assumes global address -> server record mappings and that each server is in
just one cell.
Further, each server may have multiple addresses - and may have addresses
of different families (IPv4 and IPv6, say).
To this end, the following structural changes are made:
(1) Server record management is overhauled:
(a) Server records are made independent of cell. The namespace keeps
track of them, volume records have lists of them and each vnode
has a server on which its callback interest currently resides.
(b) The cell record no longer keeps a list of servers known to be in
that cell.
(c) The server records are now kept in a flat list because there's no
single address to sort on.
(d) Server records are now keyed by their UUID within the namespace.
(e) The addresses for a server are obtained with the VL.GetAddrsU
rather than with VL.GetEntryByName, using the server's UUID as a
parameter.
(f) Cached server records are garbage collected after a period of
non-use and are counted out of existence before purging is allowed
to complete. This protects the work functions against rmmod.
(g) The servers list is now in /proc/fs/afs/servers.
(2) Volume record management is overhauled:
(a) An RCU-replaceable server list is introduced. This tracks both
servers and their coresponding callback interests.
(b) The superblock is now keyed on cell record and numeric volume ID.
(c) The volume record is now tied to the superblock which mounts it,
and is activated when mounted and deactivated when unmounted.
This makes it easier to handle the cache cookie without causing a
double-use in fscache.
(d) The volume record is loaded from the VLDB using VL.GetEntryByNameU
to get the server UUID list.
(e) The volume name is updated if it is seen to have changed when the
volume is updated (the update is keyed on the volume ID).
(3) The vlocation record is got rid of and VLDB records are no longer
cached. Sufficient information is stored in the volume record, though
an update to a volume record is now no longer shared between related
volumes (volumes come in bundles of three: R/W, R/O and backup).
and the following procedural changes are made:
(1) The fileserver cursor introduced previously is now fleshed out and
used to iterate over fileservers and their addresses.
(2) Volume status is checked during iteration, and the server list is
replaced if a change is detected.
(3) Server status is checked during iteration, and the address list is
replaced if a change is detected.
(4) The abort code is saved into the address list cursor and -ECONNABORTED
returned in afs_make_call() if a remote abort happened rather than
translating the abort into an error message. This allows actions to
be taken depending on the abort code more easily.
(a) If a VMOVED abort is seen then this is handled by rechecking the
volume and restarting the iteration.
(b) If a VBUSY, VRESTARTING or VSALVAGING abort is seen then this is
handled by sleeping for a short period and retrying and/or trying
other servers that might serve that volume. A message is also
displayed once until the condition has cleared.
(c) If a VOFFLINE abort is seen, then this is handled as VBUSY for the
moment.
(d) If a VNOVOL abort is seen, the volume is rechecked in the VLDB to
see if it has been deleted; if not, the fileserver is probably
indicating that the volume couldn't be attached and needs
salvaging.
(e) If statfs() sees one of these aborts, it does not sleep, but
rather returns an error, so as not to block the umount program.
(5) The fileserver iteration functions in vnode.c are now merged into
their callers and more heavily macroised around the cursor. vnode.c
is removed.
(6) Operations on a particular vnode are serialised on that vnode because
the server will lock that vnode whilst it operates on it, so a second
op sent will just have to wait.
(7) Fileservers are probed with FS.GetCapabilities before being used.
This is where service upgrade will be done.
(8) A callback interest on a fileserver is set up before an FS operation
is performed and passed through to afs_make_call() so that it can be
set on the vnode if the operation returns a callback. The callback
interest is passed through to afs_iget() also so that it can be set
there too.
In general, record updating is done on an as-needed basis when we try to
access servers, volumes or vnodes rather than offloading it to work items
and special threads.
Notes:
(1) Pre AFS-3.4 servers are no longer supported, though this can be added
back if necessary (AFS-3.4 was released in 1998).
(2) VBUSY is retried forever for the moment at intervals of 1s.
(3) /proc/fs/afs/<cell>/servers no longer exists.
Signed-off-by: David Howells <dhowells@redhat.com>
2017-11-02 22:27:50 +07:00
|
|
|
afs_purge_servers(net);
|
2017-11-02 22:27:45 +07:00
|
|
|
afs_close_socket(net);
|
2017-11-02 22:27:45 +07:00
|
|
|
afs_proc_cleanup(net);
|
2018-04-10 03:12:31 +07:00
|
|
|
afs_put_sysnames(net->sysnames);
|
2017-11-02 22:27:45 +07:00
|
|
|
}
|
2007-04-27 05:58:17 +07:00
|
|
|
|
2018-05-18 17:46:15 +07:00
|
|
|
static struct pernet_operations afs_net_ops = {
|
|
|
|
.init = afs_net_init,
|
|
|
|
.exit = afs_net_exit,
|
|
|
|
.id = &afs_net_id,
|
|
|
|
.size = sizeof(struct afs_net),
|
|
|
|
};
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* initialise the AFS client FS module
|
|
|
|
*/
|
|
|
|
static int __init afs_init(void)
|
|
|
|
{
|
2017-11-02 22:27:45 +07:00
|
|
|
int ret = -ENOMEM;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
|
|
|
|
|
2011-01-14 22:56:37 +07:00
|
|
|
afs_wq = alloc_workqueue("afs", 0, 0);
|
|
|
|
if (!afs_wq)
|
2017-11-02 22:27:45 +07:00
|
|
|
goto error_afs_wq;
|
|
|
|
afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
|
|
|
|
if (!afs_async_calls)
|
|
|
|
goto error_async;
|
|
|
|
afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
|
|
|
|
if (!afs_lock_manager)
|
|
|
|
goto error_lockmgr;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-04-03 22:42:41 +07:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
2005-04-17 05:20:36 +07:00
|
|
|
/* we want to be able to cache */
|
2009-04-03 22:42:41 +07:00
|
|
|
ret = fscache_register_netfs(&afs_cache_netfs);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (ret < 0)
|
|
|
|
goto error_cache;
|
|
|
|
#endif
|
|
|
|
|
2021-01-30 06:53:50 +07:00
|
|
|
ret = register_pernet_device(&afs_net_ops);
|
2010-08-06 23:26:48 +07:00
|
|
|
if (ret < 0)
|
2017-11-02 22:27:45 +07:00
|
|
|
goto error_net;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* register the filesystems */
|
|
|
|
ret = afs_fs_init();
|
|
|
|
if (ret < 0)
|
2007-04-27 05:49:28 +07:00
|
|
|
goto error_fs;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-05-18 17:46:15 +07:00
|
|
|
afs_proc_symlink = proc_symlink("fs/afs", NULL, "../self/net/afs");
|
|
|
|
if (IS_ERR(afs_proc_symlink)) {
|
|
|
|
ret = PTR_ERR(afs_proc_symlink);
|
|
|
|
goto error_proc;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return ret;
|
|
|
|
|
2018-05-18 17:46:15 +07:00
|
|
|
error_proc:
|
|
|
|
afs_fs_exit();
|
2007-04-27 05:49:28 +07:00
|
|
|
error_fs:
|
2021-01-30 06:53:50 +07:00
|
|
|
unregister_pernet_device(&afs_net_ops);
|
2017-11-02 22:27:45 +07:00
|
|
|
error_net:
|
2009-04-03 22:42:41 +07:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
fscache_unregister_netfs(&afs_cache_netfs);
|
2007-04-27 05:49:28 +07:00
|
|
|
error_cache:
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
2017-11-02 22:27:45 +07:00
|
|
|
destroy_workqueue(afs_lock_manager);
|
|
|
|
error_lockmgr:
|
|
|
|
destroy_workqueue(afs_async_calls);
|
|
|
|
error_async:
|
2011-01-14 22:56:37 +07:00
|
|
|
destroy_workqueue(afs_wq);
|
2017-11-02 22:27:45 +07:00
|
|
|
error_afs_wq:
|
2007-05-09 16:33:45 +07:00
|
|
|
rcu_barrier();
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
|
|
|
|
return ret;
|
2007-04-27 05:49:28 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* XXX late_initcall is kludgy, but the only alternative seems to create
|
|
|
|
* a transport upon the first mount, which is worse. Or is it?
|
|
|
|
*/
|
|
|
|
late_initcall(afs_init); /* must be called after net/ to create socket */
|
2007-04-27 05:49:28 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* clean up on module removal
|
|
|
|
*/
|
|
|
|
static void __exit afs_exit(void)
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
|
|
|
|
|
2018-05-18 17:46:15 +07:00
|
|
|
proc_remove(afs_proc_symlink);
|
2005-04-17 05:20:36 +07:00
|
|
|
afs_fs_exit();
|
2021-01-30 06:53:50 +07:00
|
|
|
unregister_pernet_device(&afs_net_ops);
|
2009-04-03 22:42:41 +07:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
fscache_unregister_netfs(&afs_cache_netfs);
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
2017-11-02 22:27:45 +07:00
|
|
|
destroy_workqueue(afs_lock_manager);
|
|
|
|
destroy_workqueue(afs_async_calls);
|
|
|
|
destroy_workqueue(afs_wq);
|
afs: Overhaul permit caching
Overhaul permit caching in AFS by making it per-vnode and sharing permit
lists where possible.
When most of the fileserver operations are called, they return a status
structure indicating the (revised) details of the vnode or vnodes involved
in the operation. This includes the access mark derived from the ACL
(named CallerAccess in the protocol definition file). This is cacheable
and if the ACL changes, the server will tell us that it is breaking the
callback promise, at which point we can discard the currently cached
permits.
With this patch, the afs_permits structure has, at the end, an array of
{ key, CallerAccess } elements, sorted by key pointer. This is then cached
in a hash table so that it can be shared between vnodes with the same
access permits.
Permit lists can only be shared if they contain the exact same set of
key->CallerAccess mappings.
Note that that table is global rather than being per-net_ns. If the keys
in a permit list cross net_ns boundaries, there is no problem sharing the
cached permits, since the permits are just integer masks.
Since permit lists pin keys, the permit cache also makes it easier for a
future patch to find all occurrences of a key and remove them by means of
setting the afs_permits::invalidated flag and then clearing the appropriate
key pointer. In such an event, memory barriers will need adding.
Lastly, the permit caching is skipped if the server has sent either a
vnode-specific or an entire-server callback since the start of the
operation.
Signed-off-by: David Howells <dhowells@redhat.com>
2017-11-02 22:27:49 +07:00
|
|
|
afs_clean_up_permit_cache();
|
2007-05-09 16:33:45 +07:00
|
|
|
rcu_barrier();
|
2007-04-27 05:49:28 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
module_exit(afs_exit);
|