2007-07-16 10:40:12 +04:00
/* AFS file locking support
*
* Copyright ( C ) 2007 Red Hat , Inc . All Rights Reserved .
* Written by David Howells ( dhowells @ redhat . com )
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version
* 2 of the License , or ( at your option ) any later version .
*/
# include "internal.h"
# define AFS_LOCK_GRANTED 0
# define AFS_LOCK_PENDING 1
2017-11-02 18:27:45 +03:00
struct workqueue_struct * afs_lock_manager ;
2007-07-16 10:40:12 +04:00
static void afs_fl_copy_lock ( struct file_lock * new , struct file_lock * fl ) ;
static void afs_fl_release_private ( struct file_lock * fl ) ;
2009-09-22 04:01:11 +04:00
static const struct file_lock_operations afs_lock_ops = {
2007-07-16 10:40:12 +04:00
. fl_copy_lock = afs_fl_copy_lock ,
. fl_release_private = afs_fl_release_private ,
} ;
/*
* if the callback is broken on this vnode , then the lock may now be available
*/
void afs_lock_may_be_available ( struct afs_vnode * vnode )
{
2018-10-20 02:57:57 +03:00
_enter ( " {%llx:%llu} " , vnode - > fid . vid , vnode - > fid . vnode ) ;
2007-07-16 10:40:12 +04:00
queue_delayed_work ( afs_lock_manager , & vnode - > lock_work , 0 ) ;
}
/*
* the lock will time out in 5 minutes unless we extend it , so schedule
* extension in a bit less than that time
*/
static void afs_schedule_lock_extension ( struct afs_vnode * vnode )
{
queue_delayed_work ( afs_lock_manager , & vnode - > lock_work ,
AFS_LOCKWAIT * HZ / 2 ) ;
}
2007-07-31 11:38:49 +04:00
/*
* grant one or more locks ( readlocks are allowed to jump the queue if the
* first lock in the queue is itself a readlock )
* - the caller must hold the vnode lock
*/
static void afs_grant_locks ( struct afs_vnode * vnode , struct file_lock * fl )
{
struct file_lock * p , * _p ;
list_move_tail ( & fl - > fl_u . afs . link , & vnode - > granted_locks ) ;
if ( fl - > fl_type = = F_RDLCK ) {
list_for_each_entry_safe ( p , _p , & vnode - > pending_locks ,
fl_u . afs . link ) {
if ( p - > fl_type = = F_RDLCK ) {
p - > fl_u . afs . state = AFS_LOCK_GRANTED ;
list_move_tail ( & p - > fl_u . afs . link ,
& vnode - > granted_locks ) ;
wake_up ( & p - > fl_wait ) ;
}
}
}
}
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 18:27:50 +03:00
/*
* Get a lock on a file
*/
static int afs_set_lock ( struct afs_vnode * vnode , struct key * key ,
afs_lock_type_t type )
{
struct afs_fs_cursor fc ;
int ret ;
2018-10-20 02:57:57 +03:00
_enter ( " %s{%llx:%llu.%u},%x,%u " ,
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 18:27:50 +03:00
vnode - > volume - > name ,
vnode - > fid . vid ,
vnode - > fid . vnode ,
vnode - > fid . unique ,
key_serial ( key ) , type ) ;
ret = - ERESTARTSYS ;
if ( afs_begin_vnode_operation ( & fc , vnode , key ) ) {
while ( afs_select_fileserver ( & fc ) ) {
2018-05-13 00:31:33 +03:00
fc . cb_break = afs_calc_vnode_cb_break ( vnode ) ;
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 18:27:50 +03:00
afs_fs_set_lock ( & fc , type ) ;
}
afs_check_for_remote_deletion ( & fc , fc . vnode ) ;
afs_vnode_commit_status ( & fc , vnode , fc . cb_break ) ;
ret = afs_end_vnode_operation ( & fc ) ;
}
_leave ( " = %d " , ret ) ;
return ret ;
}
/*
* Extend a lock on a file
*/
static int afs_extend_lock ( struct afs_vnode * vnode , struct key * key )
{
struct afs_fs_cursor fc ;
int ret ;
2018-10-20 02:57:57 +03:00
_enter ( " %s{%llx:%llu.%u},%x " ,
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 18:27:50 +03:00
vnode - > volume - > name ,
vnode - > fid . vid ,
vnode - > fid . vnode ,
vnode - > fid . unique ,
key_serial ( key ) ) ;
ret = - ERESTARTSYS ;
if ( afs_begin_vnode_operation ( & fc , vnode , key ) ) {
while ( afs_select_current_fileserver ( & fc ) ) {
2018-05-13 00:31:33 +03:00
fc . cb_break = afs_calc_vnode_cb_break ( vnode ) ;
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 18:27:50 +03:00
afs_fs_extend_lock ( & fc ) ;
}
afs_check_for_remote_deletion ( & fc , fc . vnode ) ;
afs_vnode_commit_status ( & fc , vnode , fc . cb_break ) ;
ret = afs_end_vnode_operation ( & fc ) ;
}
_leave ( " = %d " , ret ) ;
return ret ;
}
/*
* Release a lock on a file
*/
static int afs_release_lock ( struct afs_vnode * vnode , struct key * key )
{
struct afs_fs_cursor fc ;
int ret ;
2018-10-20 02:57:57 +03:00
_enter ( " %s{%llx:%llu.%u},%x " ,
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 18:27:50 +03:00
vnode - > volume - > name ,
vnode - > fid . vid ,
vnode - > fid . vnode ,
vnode - > fid . unique ,
key_serial ( key ) ) ;
ret = - ERESTARTSYS ;
if ( afs_begin_vnode_operation ( & fc , vnode , key ) ) {
while ( afs_select_current_fileserver ( & fc ) ) {
2018-05-13 00:31:33 +03:00
fc . cb_break = afs_calc_vnode_cb_break ( vnode ) ;
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 18:27:50 +03:00
afs_fs_release_lock ( & fc ) ;
}
afs_check_for_remote_deletion ( & fc , fc . vnode ) ;
afs_vnode_commit_status ( & fc , vnode , fc . cb_break ) ;
ret = afs_end_vnode_operation ( & fc ) ;
}
_leave ( " = %d " , ret ) ;
return ret ;
}
2007-07-16 10:40:12 +04:00
/*
* do work for a lock , including :
* - probing for a lock we ' re waiting on but didn ' t get immediately
* - extending a lock that ' s close to timing out
*/
void afs_lock_work ( struct work_struct * work )
{
struct afs_vnode * vnode =
container_of ( work , struct afs_vnode , lock_work . work ) ;
2017-11-13 19:59:50 +03:00
struct file_lock * fl , * next ;
2007-07-16 10:40:12 +04:00
afs_lock_type_t type ;
struct key * key ;
int ret ;
2018-10-20 02:57:57 +03:00
_enter ( " {%llx:%llu} " , vnode - > fid . vid , vnode - > fid . vnode ) ;
2007-07-16 10:40:12 +04:00
spin_lock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
again :
_debug ( " wstate %u for %p " , vnode - > lock_state , vnode ) ;
switch ( vnode - > lock_state ) {
case AFS_VNODE_LOCK_NEED_UNLOCK :
2007-07-16 10:40:12 +04:00
_debug ( " unlock " ) ;
2017-11-13 19:59:50 +03:00
vnode - > lock_state = AFS_VNODE_LOCK_UNLOCKING ;
2007-07-16 10:40:12 +04:00
spin_unlock ( & vnode - > lock ) ;
/* attempt to release the server lock; if it fails, we just
2017-11-13 19:59:50 +03:00
* wait 5 minutes and it ' ll expire anyway */
ret = afs_release_lock ( vnode , vnode - > lock_key ) ;
2007-07-16 10:40:12 +04:00
if ( ret < 0 )
printk ( KERN_WARNING " AFS: "
2018-10-20 02:57:57 +03:00
" Failed to release lock on {%llx:%llx} error %d \n " ,
2007-07-16 10:40:12 +04:00
vnode - > fid . vid , vnode - > fid . vnode , ret ) ;
spin_lock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
key_put ( vnode - > lock_key ) ;
vnode - > lock_key = NULL ;
vnode - > lock_state = AFS_VNODE_LOCK_NONE ;
if ( list_empty ( & vnode - > pending_locks ) ) {
spin_unlock ( & vnode - > lock ) ;
return ;
}
/* The new front of the queue now owns the state variables. */
next = list_entry ( vnode - > pending_locks . next ,
struct file_lock , fl_u . afs . link ) ;
vnode - > lock_key = afs_file_key ( next - > fl_file ) ;
vnode - > lock_type = ( next - > fl_type = = F_RDLCK ) ? AFS_LOCK_READ : AFS_LOCK_WRITE ;
vnode - > lock_state = AFS_VNODE_LOCK_WAITING_FOR_CB ;
goto again ;
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
/* If we've already got a lock, then it must be time to extend that
* lock as AFS locks time out after 5 minutes .
*/
case AFS_VNODE_LOCK_GRANTED :
2007-07-16 10:40:12 +04:00
_debug ( " extend " ) ;
2017-11-13 19:59:50 +03:00
ASSERT ( ! list_empty ( & vnode - > granted_locks ) ) ;
key = key_get ( vnode - > lock_key ) ;
vnode - > lock_state = AFS_VNODE_LOCK_EXTENDING ;
2007-07-16 10:40:12 +04:00
spin_unlock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
ret = afs_extend_lock ( vnode , key ) ; /* RPC */
2007-07-16 10:40:12 +04:00
key_put ( key ) ;
2017-11-13 19:59:50 +03:00
if ( ret < 0 )
2018-10-20 02:57:57 +03:00
pr_warning ( " AFS: Failed to extend lock on {%llx:%llx} error %d \n " ,
2017-11-13 19:59:50 +03:00
vnode - > fid . vid , vnode - > fid . vnode , ret ) ;
spin_lock ( & vnode - > lock ) ;
if ( vnode - > lock_state ! = AFS_VNODE_LOCK_EXTENDING )
goto again ;
vnode - > lock_state = AFS_VNODE_LOCK_GRANTED ;
if ( ret = = 0 )
2007-07-16 10:40:12 +04:00
afs_schedule_lock_extension ( vnode ) ;
2017-11-13 19:59:50 +03:00
else
2007-07-16 10:40:12 +04:00
queue_delayed_work ( afs_lock_manager , & vnode - > lock_work ,
HZ * 10 ) ;
2017-11-13 19:59:50 +03:00
spin_unlock ( & vnode - > lock ) ;
_leave ( " [ext] " ) ;
2007-07-16 10:40:12 +04:00
return ;
2017-11-13 19:59:50 +03:00
/* If we don't have a granted lock, then we must've been called
* back by the server , and so if might be possible to get a
* lock we ' re currently waiting for .
*/
case AFS_VNODE_LOCK_WAITING_FOR_CB :
2007-07-16 10:40:12 +04:00
_debug ( " get " ) ;
2017-11-13 19:59:50 +03:00
key = key_get ( vnode - > lock_key ) ;
type = vnode - > lock_type ;
vnode - > lock_state = AFS_VNODE_LOCK_SETTING ;
2007-07-16 10:40:12 +04:00
spin_unlock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
ret = afs_set_lock ( vnode , key , type ) ; /* RPC */
key_put ( key ) ;
spin_lock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
switch ( ret ) {
case - EWOULDBLOCK :
_debug ( " blocked " ) ;
break ;
case 0 :
_debug ( " acquired " ) ;
2017-11-13 19:59:50 +03:00
vnode - > lock_state = AFS_VNODE_LOCK_GRANTED ;
/* Fall through */
2007-07-16 10:40:12 +04:00
default :
2017-11-13 19:59:50 +03:00
/* Pass the lock or the error onto the first locker in
* the list - if they ' re looking for this type of lock .
* If they ' re not , we assume that whoever asked for it
* took a signal .
*/
if ( list_empty ( & vnode - > pending_locks ) ) {
2007-07-16 10:40:12 +04:00
_debug ( " withdrawn " ) ;
2017-11-13 19:59:50 +03:00
vnode - > lock_state = AFS_VNODE_LOCK_NEED_UNLOCK ;
goto again ;
2007-07-16 10:40:12 +04:00
}
2017-11-13 19:59:50 +03:00
fl = list_entry ( vnode - > pending_locks . next ,
struct file_lock , fl_u . afs . link ) ;
type = ( fl - > fl_type = = F_RDLCK ) ? AFS_LOCK_READ : AFS_LOCK_WRITE ;
if ( vnode - > lock_type ! = type ) {
_debug ( " changed " ) ;
vnode - > lock_state = AFS_VNODE_LOCK_NEED_UNLOCK ;
goto again ;
}
fl - > fl_u . afs . state = ret ;
if ( ret = = 0 )
afs_grant_locks ( vnode , fl ) ;
else
list_del_init ( & fl - > fl_u . afs . link ) ;
wake_up ( & fl - > fl_wait ) ;
spin_unlock ( & vnode - > lock ) ;
_leave ( " [granted] " ) ;
return ;
2007-07-16 10:40:12 +04:00
}
2017-11-13 19:59:50 +03:00
default :
/* Looks like a lock request was withdrawn. */
spin_unlock ( & vnode - > lock ) ;
_leave ( " [no] " ) ;
2007-07-16 10:40:12 +04:00
return ;
}
}
/*
* pass responsibility for the unlocking of a vnode on the server to the
* manager thread , lest a pending signal in the calling thread interrupt
* AF_RXRPC
* - the caller must hold the vnode lock
*/
2017-11-13 19:59:50 +03:00
static void afs_defer_unlock ( struct afs_vnode * vnode )
2007-07-16 10:40:12 +04:00
{
2017-11-13 19:59:50 +03:00
_enter ( " " ) ;
if ( vnode - > lock_state = = AFS_VNODE_LOCK_GRANTED | |
vnode - > lock_state = = AFS_VNODE_LOCK_EXTENDING ) {
cancel_delayed_work ( & vnode - > lock_work ) ;
vnode - > lock_state = AFS_VNODE_LOCK_NEED_UNLOCK ;
afs_lock_may_be_available ( vnode ) ;
}
}
/*
* Check that our view of the file metadata is up to date and check to see
* whether we think that we have a locking permit .
*/
static int afs_do_setlk_check ( struct afs_vnode * vnode , struct key * key ,
afs_lock_type_t type , bool can_sleep )
{
afs_access_t access ;
int ret ;
/* Make sure we've got a callback on this file and that our view of the
* data version is up to date .
*/
ret = afs_validate ( vnode , key ) ;
if ( ret < 0 )
return ret ;
/* Check the permission set to see if we're actually going to be
* allowed to get a lock on this file .
*/
ret = afs_check_permit ( vnode , key , & access ) ;
if ( ret < 0 )
return ret ;
/* At a rough estimation, you need LOCK, WRITE or INSERT perm to
* read - lock a file and WRITE or INSERT perm to write - lock a file .
*
* We can ' t rely on the server to do this for us since if we want to
* share a read lock that we already have , we won ' t go the server .
*/
if ( type = = AFS_LOCK_READ ) {
if ( ! ( access & ( AFS_ACE_INSERT | AFS_ACE_WRITE | AFS_ACE_LOCK ) ) )
return - EACCES ;
if ( vnode - > status . lock_count = = - 1 & & ! can_sleep )
return - EAGAIN ; /* Write locked */
} else {
if ( ! ( access & ( AFS_ACE_INSERT | AFS_ACE_WRITE ) ) )
return - EACCES ;
if ( vnode - > status . lock_count ! = 0 & & ! can_sleep )
return - EAGAIN ; /* Locked */
}
return 0 ;
}
/*
* Remove the front runner from the pending queue .
* - The caller must hold vnode - > lock .
*/
static void afs_dequeue_lock ( struct afs_vnode * vnode , struct file_lock * fl )
{
struct file_lock * next ;
_enter ( " " ) ;
/* ->lock_type, ->lock_key and ->lock_state only belong to this
* file_lock if we ' re at the front of the pending queue or if we have
* the lock granted or if the lock_state is NEED_UNLOCK or UNLOCKING .
*/
if ( vnode - > granted_locks . next = = & fl - > fl_u . afs . link & &
vnode - > granted_locks . prev = = & fl - > fl_u . afs . link ) {
list_del_init ( & fl - > fl_u . afs . link ) ;
afs_defer_unlock ( vnode ) ;
return ;
}
if ( ! list_empty ( & vnode - > granted_locks ) | |
vnode - > pending_locks . next ! = & fl - > fl_u . afs . link ) {
list_del_init ( & fl - > fl_u . afs . link ) ;
return ;
}
list_del_init ( & fl - > fl_u . afs . link ) ;
key_put ( vnode - > lock_key ) ;
vnode - > lock_key = NULL ;
vnode - > lock_state = AFS_VNODE_LOCK_NONE ;
if ( list_empty ( & vnode - > pending_locks ) )
return ;
/* The new front of the queue now owns the state variables. */
next = list_entry ( vnode - > pending_locks . next ,
struct file_lock , fl_u . afs . link ) ;
vnode - > lock_key = afs_file_key ( next - > fl_file ) ;
vnode - > lock_type = ( next - > fl_type = = F_RDLCK ) ? AFS_LOCK_READ : AFS_LOCK_WRITE ;
vnode - > lock_state = AFS_VNODE_LOCK_WAITING_FOR_CB ;
2007-07-16 10:40:12 +04:00
afs_lock_may_be_available ( vnode ) ;
}
/*
* request a lock on a file on the server
*/
static int afs_do_setlk ( struct file * file , struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct inode * inode = locks_inode ( file ) ;
2013-06-21 16:58:15 +04:00
struct afs_vnode * vnode = AFS_FS_I ( inode ) ;
2007-07-16 10:40:12 +04:00
afs_lock_type_t type ;
2017-11-02 18:27:52 +03:00
struct key * key = afs_file_key ( file ) ;
2007-07-16 10:40:12 +04:00
int ret ;
2018-10-20 02:57:57 +03:00
_enter ( " {%llx:%llu},%u " , vnode - > fid . vid , vnode - > fid . vnode , fl - > fl_type ) ;
2007-07-16 10:40:12 +04:00
/* only whole-file locks are supported */
if ( fl - > fl_start ! = 0 | | fl - > fl_end ! = OFFSET_MAX )
return - EINVAL ;
fl - > fl_ops = & afs_lock_ops ;
INIT_LIST_HEAD ( & fl - > fl_u . afs . link ) ;
fl - > fl_u . afs . state = AFS_LOCK_PENDING ;
type = ( fl - > fl_type = = F_RDLCK ) ? AFS_LOCK_READ : AFS_LOCK_WRITE ;
2017-11-13 19:59:50 +03:00
ret = afs_do_setlk_check ( vnode , key , type , fl - > fl_flags & FL_SLEEP ) ;
2007-07-16 10:40:12 +04:00
if ( ret < 0 )
2017-11-13 19:59:50 +03:00
return ret ;
2007-07-16 10:40:12 +04:00
spin_lock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
/* If we've already got a readlock on the server then we instantly
2007-07-31 11:38:49 +04:00
* grant another readlock , irrespective of whether there are any
2017-11-13 19:59:50 +03:00
* pending writelocks .
*/
2007-07-31 11:38:49 +04:00
if ( type = = AFS_LOCK_READ & &
2017-11-13 19:59:50 +03:00
vnode - > lock_state = = AFS_VNODE_LOCK_GRANTED & &
vnode - > lock_type = = AFS_LOCK_READ ) {
2007-07-31 11:38:49 +04:00
_debug ( " instant readlock " ) ;
ASSERT ( ! list_empty ( & vnode - > granted_locks ) ) ;
2017-11-13 19:59:50 +03:00
goto share_existing_lock ;
2007-07-31 11:38:49 +04:00
}
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
list_add_tail ( & fl - > fl_u . afs . link , & vnode - > pending_locks ) ;
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
if ( vnode - > lock_state ! = AFS_VNODE_LOCK_NONE )
goto need_to_wait ;
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
/* We don't have a lock on this vnode and we aren't currently waiting
* for one either , so ask the server for a lock .
*
* Note that we need to be careful if we get interrupted by a signal
* after dispatching the request as we may still get the lock , even
* though we don ' t wait for the reply ( it ' s not too bad a problem - the
* lock will expire in 10 mins anyway ) .
*/
_debug ( " not locked " ) ;
vnode - > lock_key = key_get ( key ) ;
vnode - > lock_type = type ;
vnode - > lock_state = AFS_VNODE_LOCK_SETTING ;
2007-07-16 10:40:12 +04:00
spin_unlock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
ret = afs_set_lock ( vnode , key , type ) ; /* RPC */
2007-07-16 10:40:12 +04:00
spin_lock ( & vnode - > lock ) ;
2017-11-13 19:59:50 +03:00
switch ( ret ) {
default :
goto abort_attempt ;
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
case - EWOULDBLOCK :
/* The server doesn't have a lock-waiting queue, so the client
* will have to retry . The server will break the outstanding
* callbacks on a file when a lock is released .
*/
_debug ( " would block " ) ;
ASSERT ( list_empty ( & vnode - > granted_locks ) ) ;
ASSERTCMP ( vnode - > pending_locks . next , = = , & fl - > fl_u . afs . link ) ;
vnode - > lock_state = AFS_VNODE_LOCK_WAITING_FOR_CB ;
goto need_to_wait ;
case 0 :
_debug ( " acquired " ) ;
break ;
2007-07-16 10:40:12 +04:00
}
/* we've acquired a server lock, but it needs to be renewed after 5
* mins */
2017-11-13 19:59:50 +03:00
vnode - > lock_state = AFS_VNODE_LOCK_GRANTED ;
2007-07-16 10:40:12 +04:00
afs_schedule_lock_extension ( vnode ) ;
2017-11-13 19:59:50 +03:00
share_existing_lock :
2007-07-16 10:40:12 +04:00
/* the lock has been granted as far as we're concerned... */
fl - > fl_u . afs . state = AFS_LOCK_GRANTED ;
list_move_tail ( & fl - > fl_u . afs . link , & vnode - > granted_locks ) ;
2017-11-13 19:59:50 +03:00
2007-07-16 10:40:12 +04:00
given_lock :
/* ... but we do still need to get the VFS's blessing */
2017-11-13 19:59:50 +03:00
spin_unlock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
ret = posix_lock_file ( file , fl , NULL ) ;
if ( ret < 0 )
goto vfs_rejected_lock ;
2017-11-13 19:59:50 +03:00
/* Again, make sure we've got a callback on this file and, again, make
2007-07-16 10:40:12 +04:00
* sure that our view of the data version is up to date ( we ignore
2017-11-13 19:59:50 +03:00
* errors incurred here and deal with the consequences elsewhere ) .
*/
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 18:27:50 +03:00
afs_validate ( vnode , key ) ;
2017-11-13 19:59:50 +03:00
_leave ( " = 0 " ) ;
return 0 ;
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
need_to_wait :
/* We're going to have to wait. Either this client doesn't have a lock
* on the server yet and we need to wait for a callback to occur , or
* the client does have a lock on the server , but it belongs to some
* other process ( es ) and is incompatible with the lock we want .
*/
ret = - EAGAIN ;
if ( fl - > fl_flags & FL_SLEEP ) {
spin_unlock ( & vnode - > lock ) ;
_debug ( " sleep " ) ;
ret = wait_event_interruptible ( fl - > fl_wait ,
fl - > fl_u . afs . state ! = AFS_LOCK_PENDING ) ;
spin_lock ( & vnode - > lock ) ;
}
if ( fl - > fl_u . afs . state = = AFS_LOCK_GRANTED )
goto given_lock ;
if ( fl - > fl_u . afs . state < 0 )
ret = fl - > fl_u . afs . state ;
abort_attempt :
/* we aren't going to get the lock, either because we're unwilling to
* wait , or because some signal happened */
_debug ( " abort " ) ;
afs_dequeue_lock ( vnode , fl ) ;
error_unlock :
spin_unlock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
_leave ( " = %d " , ret ) ;
return ret ;
vfs_rejected_lock :
2017-11-13 19:59:50 +03:00
/* The VFS rejected the lock we just obtained, so we have to discard
* what we just got . We defer this to the lock manager work item to
* deal with .
*/
2007-07-16 10:40:12 +04:00
_debug ( " vfs refused %d " , ret ) ;
2017-11-13 19:59:50 +03:00
spin_lock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
list_del_init ( & fl - > fl_u . afs . link ) ;
if ( list_empty ( & vnode - > granted_locks ) )
2017-11-13 19:59:50 +03:00
afs_defer_unlock ( vnode ) ;
goto error_unlock ;
2007-07-16 10:40:12 +04:00
}
/*
* unlock on a file on the server
*/
static int afs_do_unlk ( struct file * file , struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct afs_vnode * vnode = AFS_FS_I ( locks_inode ( file ) ) ;
2007-07-16 10:40:12 +04:00
int ret ;
2018-10-20 02:57:57 +03:00
_enter ( " {%llx:%llu},%u " , vnode - > fid . vid , vnode - > fid . vnode , fl - > fl_type ) ;
2007-07-16 10:40:12 +04:00
2017-11-13 19:59:50 +03:00
/* Flush all pending writes before doing anything with locks. */
vfs_fsync ( file , 0 ) ;
2007-07-16 10:40:12 +04:00
/* only whole-file unlocks are supported */
if ( fl - > fl_start ! = 0 | | fl - > fl_end ! = OFFSET_MAX )
return - EINVAL ;
ret = posix_lock_file ( file , fl , NULL ) ;
2017-11-13 19:59:50 +03:00
_leave ( " = %d [%u] " , ret , vnode - > lock_state ) ;
return ret ;
2007-07-16 10:40:12 +04:00
}
/*
* return information about a lock we currently hold , if indeed we hold one
*/
static int afs_do_getlk ( struct file * file , struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct afs_vnode * vnode = AFS_FS_I ( locks_inode ( file ) ) ;
2017-11-02 18:27:52 +03:00
struct key * key = afs_file_key ( file ) ;
2007-07-16 10:40:12 +04:00
int ret , lock_count ;
_enter ( " " ) ;
fl - > fl_type = F_UNLCK ;
/* check local lock records first */
2007-07-19 12:50:35 +04:00
posix_test_lock ( file , fl ) ;
if ( fl - > fl_type = = F_UNLCK ) {
2007-07-16 10:40:12 +04:00
/* no local locks; consult the server */
2018-04-06 16:17:24 +03:00
ret = afs_fetch_status ( vnode , key , false ) ;
2007-07-16 10:40:12 +04:00
if ( ret < 0 )
goto error ;
2017-11-13 19:59:50 +03:00
lock_count = READ_ONCE ( vnode - > status . lock_count ) ;
if ( lock_count > 0 )
fl - > fl_type = F_RDLCK ;
else
fl - > fl_type = F_WRLCK ;
fl - > fl_start = 0 ;
fl - > fl_end = OFFSET_MAX ;
2007-07-16 10:40:12 +04:00
}
2017-11-13 19:59:50 +03:00
ret = 0 ;
2007-07-16 10:40:12 +04:00
error :
_leave ( " = %d [%hd] " , ret , fl - > fl_type ) ;
return ret ;
}
/*
* manage POSIX locks on a file
*/
int afs_lock ( struct file * file , int cmd , struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct afs_vnode * vnode = AFS_FS_I ( locks_inode ( file ) ) ;
2007-07-16 10:40:12 +04:00
2018-10-20 02:57:57 +03:00
_enter ( " {%llx:%llu},%d,{t=%x,fl=%x,r=%Ld:%Ld} " ,
2007-07-16 10:40:12 +04:00
vnode - > fid . vid , vnode - > fid . vnode , cmd ,
fl - > fl_type , fl - > fl_flags ,
( long long ) fl - > fl_start , ( long long ) fl - > fl_end ) ;
/* AFS doesn't support mandatory locks */
2007-10-02 01:41:14 +04:00
if ( __mandatory_lock ( & vnode - > vfs_inode ) & & fl - > fl_type ! = F_UNLCK )
2007-07-16 10:40:12 +04:00
return - ENOLCK ;
if ( IS_GETLK ( cmd ) )
return afs_do_getlk ( file , fl ) ;
if ( fl - > fl_type = = F_UNLCK )
return afs_do_unlk ( file , fl ) ;
return afs_do_setlk ( file , fl ) ;
}
/*
* manage FLOCK locks on a file
*/
int afs_flock ( struct file * file , int cmd , struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct afs_vnode * vnode = AFS_FS_I ( locks_inode ( file ) ) ;
2007-07-16 10:40:12 +04:00
2018-10-20 02:57:57 +03:00
_enter ( " {%llx:%llu},%d,{t=%x,fl=%x} " ,
2007-07-16 10:40:12 +04:00
vnode - > fid . vid , vnode - > fid . vnode , cmd ,
fl - > fl_type , fl - > fl_flags ) ;
/*
* No BSD flocks over NFS allowed .
* Note : we could try to fake a POSIX lock request here by
* using ( ( u32 ) filp | 0x80000000 ) or some such as the pid .
* Not sure whether that would be unique , though , or whether
* that would break in other places .
*/
if ( ! ( fl - > fl_flags & FL_FLOCK ) )
return - ENOLCK ;
/* we're simulating flock() locks using posix locks on the server */
if ( fl - > fl_type = = F_UNLCK )
return afs_do_unlk ( file , fl ) ;
return afs_do_setlk ( file , fl ) ;
}
/*
* the POSIX lock management core VFS code copies the lock record and adds the
* copy into its own list , so we need to add that copy to the vnode ' s lock
* queue in the same place as the original ( which will be deleted shortly
* after )
*/
static void afs_fl_copy_lock ( struct file_lock * new , struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct afs_vnode * vnode = AFS_FS_I ( locks_inode ( fl - > fl_file ) ) ;
2007-07-16 10:40:12 +04:00
_enter ( " " ) ;
2017-11-13 19:59:50 +03:00
spin_lock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
list_add ( & new - > fl_u . afs . link , & fl - > fl_u . afs . link ) ;
2017-11-13 19:59:50 +03:00
spin_unlock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
}
/*
* need to remove this lock from the vnode queue when it ' s removed from the
* VFS ' s list
*/
static void afs_fl_release_private ( struct file_lock * fl )
{
2017-11-13 19:59:50 +03:00
struct afs_vnode * vnode = AFS_FS_I ( locks_inode ( fl - > fl_file ) ) ;
2007-07-16 10:40:12 +04:00
_enter ( " " ) ;
2017-11-13 19:59:50 +03:00
spin_lock ( & vnode - > lock ) ;
afs_dequeue_lock ( vnode , fl ) ;
_debug ( " state %u for %p " , vnode - > lock_state , vnode ) ;
spin_unlock ( & vnode - > lock ) ;
2007-07-16 10:40:12 +04:00
}