Commit d2ddc776 authored by David Howells's avatar David Howells

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: default avatarDavid Howells <dhowells@redhat.com>
parent 9cc6fc50
...@@ -24,11 +24,10 @@ kafs-objs := \ ...@@ -24,11 +24,10 @@ kafs-objs := \
rxrpc.o \ rxrpc.o \
security.o \ security.o \
server.o \ server.o \
server_list.o \
super.o \ super.o \
netdevices.o \ netdevices.o \
vlclient.o \ vlclient.o \
vlocation.o \
vnode.o \
volume.o \ volume.o \
write.o \ write.o \
xattr.o xattr.o
......
...@@ -227,6 +227,37 @@ struct afs_addr_list *afs_dns_query(struct afs_cell *cell, time64_t *_expiry) ...@@ -227,6 +227,37 @@ struct afs_addr_list *afs_dns_query(struct afs_cell *cell, time64_t *_expiry)
return alist; return alist;
} }
/*
* Merge an IPv4 entry into a fileserver address list.
*/
void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr)
{
struct sockaddr_in6 *a;
int i;
for (i = 0; i < alist->nr_ipv4; i++) {
a = &alist->addrs[i].transport.sin6;
if (xdr == a->sin6_addr.s6_addr32[3])
return;
if (xdr < a->sin6_addr.s6_addr32[3])
break;
}
if (i < alist->nr_addrs)
memmove(alist->addrs + i + 1,
alist->addrs + i,
sizeof(alist->addrs[0]) * (alist->nr_addrs - i));
a = &alist->addrs[i].transport.sin6;
a->sin6_port = htons(AFS_FS_PORT);
a->sin6_addr.s6_addr32[0] = 0;
a->sin6_addr.s6_addr32[1] = 0;
a->sin6_addr.s6_addr32[2] = htonl(0xffff);
a->sin6_addr.s6_addr32[3] = xdr;
alist->nr_ipv4++;
alist->nr_addrs++;
}
/* /*
* Get an address to try. * Get an address to try.
*/ */
......
...@@ -38,6 +38,7 @@ enum AFS_FS_Operations { ...@@ -38,6 +38,7 @@ enum AFS_FS_Operations {
FSFETCHDATA64 = 65537, /* AFS Fetch file data */ FSFETCHDATA64 = 65537, /* AFS Fetch file data */
FSSTOREDATA64 = 65538, /* AFS Store file data */ FSSTOREDATA64 = 65538, /* AFS Store file data */
FSGIVEUPALLCALLBACKS = 65539, /* AFS Give up all outstanding callbacks on a server */ FSGIVEUPALLCALLBACKS = 65539, /* AFS Give up all outstanding callbacks on a server */
FSGETCAPABILITIES = 65540, /* Probe and get the capabilities of a fileserver */
}; };
enum AFS_FS_Errors { enum AFS_FS_Errors {
......
...@@ -88,4 +88,46 @@ struct afs_vldbentry { ...@@ -88,4 +88,46 @@ struct afs_vldbentry {
#define AFS_VLDB_MAXNAMELEN 65 #define AFS_VLDB_MAXNAMELEN 65
struct afs_ListAddrByAttributes__xdr {
__be32 Mask;
#define AFS_VLADDR_IPADDR 0x1 /* Match by ->ipaddr */
#define AFS_VLADDR_INDEX 0x2 /* Match by ->index */
#define AFS_VLADDR_UUID 0x4 /* Match by ->uuid */
__be32 ipaddr;
__be32 index;
__be32 spare;
struct afs_uuid__xdr uuid;
};
struct afs_uvldbentry__xdr {
__be32 name[AFS_VLDB_MAXNAMELEN];
__be32 nServers;
struct afs_uuid__xdr serverNumber[AFS_NMAXNSERVERS];
__be32 serverUnique[AFS_NMAXNSERVERS];
__be32 serverPartition[AFS_NMAXNSERVERS];
__be32 serverFlags[AFS_NMAXNSERVERS];
__be32 volumeId[AFS_MAXTYPES];
__be32 cloneId;
__be32 flags;
__be32 spares1;
__be32 spares2;
__be32 spares3;
__be32 spares4;
__be32 spares5;
__be32 spares6;
__be32 spares7;
__be32 spares8;
__be32 spares9;
};
struct afs_address_list {
refcount_t usage;
unsigned int version;
unsigned int nr_addrs;
struct sockaddr_rxrpc addrs[];
};
extern void afs_put_address_list(struct afs_address_list *alist);
#endif /* AFS_VL_H */ #endif /* AFS_VL_H */
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
* - Called with volume->server_sem held. * - Called with volume->server_sem held.
*/ */
int afs_register_server_cb_interest(struct afs_vnode *vnode, int afs_register_server_cb_interest(struct afs_vnode *vnode,
struct afs_cb_interest **ppcbi, struct afs_server_entry *entry)
struct afs_server *server)
{ {
struct afs_cb_interest *cbi = *ppcbi, *vcbi, *new, *x; struct afs_cb_interest *cbi = entry->cb_interest, *vcbi, *new, *x;
struct afs_server *server = entry->server;
again: again:
vcbi = vnode->cb_interest; vcbi = vnode->cb_interest;
...@@ -47,7 +47,7 @@ int afs_register_server_cb_interest(struct afs_vnode *vnode, ...@@ -47,7 +47,7 @@ int afs_register_server_cb_interest(struct afs_vnode *vnode,
if (!cbi && vcbi->server == server) { if (!cbi && vcbi->server == server) {
afs_get_cb_interest(vcbi); afs_get_cb_interest(vcbi);
x = cmpxchg(ppcbi, cbi, vcbi); x = cmpxchg(&entry->cb_interest, cbi, vcbi);
if (x != cbi) { if (x != cbi) {
cbi = x; cbi = x;
afs_put_cb_interest(afs_v2net(vnode), vcbi); afs_put_cb_interest(afs_v2net(vnode), vcbi);
...@@ -72,7 +72,7 @@ int afs_register_server_cb_interest(struct afs_vnode *vnode, ...@@ -72,7 +72,7 @@ int afs_register_server_cb_interest(struct afs_vnode *vnode,
list_add_tail(&new->cb_link, &server->cb_interests); list_add_tail(&new->cb_link, &server->cb_interests);
write_unlock(&server->cb_break_lock); write_unlock(&server->cb_break_lock);
x = cmpxchg(ppcbi, cbi, new); x = cmpxchg(&entry->cb_interest, cbi, new);
if (x == cbi) { if (x == cbi) {
cbi = new; cbi = new;
} else { } else {
...@@ -137,7 +137,7 @@ void afs_put_cb_interest(struct afs_net *net, struct afs_cb_interest *cbi) ...@@ -137,7 +137,7 @@ void afs_put_cb_interest(struct afs_net *net, struct afs_cb_interest *cbi)
*/ */
void afs_init_callback_state(struct afs_server *server) void afs_init_callback_state(struct afs_server *server)
{ {
if (!test_and_clear_bit(AFS_SERVER_NEW, &server->flags)) if (!test_and_clear_bit(AFS_SERVER_FL_NEW, &server->flags))
server->cb_s_break++; server->cb_s_break++;
} }
...@@ -233,12 +233,12 @@ void afs_break_callbacks(struct afs_server *server, size_t count, ...@@ -233,12 +233,12 @@ void afs_break_callbacks(struct afs_server *server, size_t count,
/* /*
* Clear the callback interests in a server list. * Clear the callback interests in a server list.
*/ */
void afs_clear_callback_interests(struct afs_net *net, struct afs_volume *volume) void afs_clear_callback_interests(struct afs_net *net, struct afs_server_list *slist)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(volume->cb_interests); i++) { for (i = 0; i < slist->nr_servers; i++) {
afs_put_cb_interest(net, volume->cb_interests[i]); afs_put_cb_interest(net, slist->servers[i].cb_interest);
volume->cb_interests[i] = NULL; slist->servers[i].cb_interest = NULL;
} }
} }
...@@ -146,13 +146,10 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, ...@@ -146,13 +146,10 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
atomic_set(&cell->usage, 2); atomic_set(&cell->usage, 2);
INIT_WORK(&cell->manager, afs_manage_cell); INIT_WORK(&cell->manager, afs_manage_cell);
rwlock_init(&cell->servers_lock);
INIT_LIST_HEAD(&cell->servers);
init_rwsem(&cell->vl_sem);
INIT_LIST_HEAD(&cell->vl_list);
spin_lock_init(&cell->vl_lock);
cell->flags = ((1 << AFS_CELL_FL_NOT_READY) | cell->flags = ((1 << AFS_CELL_FL_NOT_READY) |
(1 << AFS_CELL_FL_NO_LOOKUP_YET)); (1 << AFS_CELL_FL_NO_LOOKUP_YET));
INIT_LIST_HEAD(&cell->proc_volumes);
rwlock_init(&cell->proc_lock);
rwlock_init(&cell->vl_addrs_lock); rwlock_init(&cell->vl_addrs_lock);
/* Fill in the VL server list if we were given a list of addresses to /* Fill in the VL server list if we were given a list of addresses to
......
This diff is collapsed.
...@@ -137,6 +137,37 @@ static void afs_file_readpage_read_complete(struct page *page, ...@@ -137,6 +137,37 @@ static void afs_file_readpage_read_complete(struct page *page,
} }
#endif #endif
/*
* Fetch file data from the volume.
*/
int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *desc)
{
struct afs_fs_cursor fc;
int ret;
_enter("%s{%x:%u.%u},%x,,,",
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_fileserver(&fc)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
afs_fs_fetch_data(&fc, desc);
}
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;
}
/* /*
* read page from file, directory or symlink, given a key to use * read page from file, directory or symlink, given a key to use
*/ */
...@@ -199,7 +230,7 @@ int afs_page_filler(void *data, struct page *page) ...@@ -199,7 +230,7 @@ int afs_page_filler(void *data, struct page *page)
/* read the contents of the file from the server into the /* read the contents of the file from the server into the
* page */ * page */
ret = afs_vnode_fetch_data(vnode, key, req); ret = afs_fetch_data(vnode, key, req);
afs_put_read(req); afs_put_read(req);
if (ret < 0) { if (ret < 0) {
if (ret == -ENOENT) { if (ret == -ENOENT) {
...@@ -264,7 +295,7 @@ static int afs_readpage(struct file *file, struct page *page) ...@@ -264,7 +295,7 @@ static int afs_readpage(struct file *file, struct page *page)
ret = afs_page_filler(key, page); ret = afs_page_filler(key, page);
} else { } else {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell); key = afs_request_key(AFS_FS_S(inode->i_sb)->cell);
if (IS_ERR(key)) { if (IS_ERR(key)) {
ret = PTR_ERR(key); ret = PTR_ERR(key);
} else { } else {
...@@ -369,7 +400,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, ...@@ -369,7 +400,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
return 0; return 0;
} }
ret = afs_vnode_fetch_data(vnode, key, req); ret = afs_fetch_data(vnode, key, req);
if (ret < 0) if (ret < 0)
goto error; goto error;
......
...@@ -67,6 +67,100 @@ static void afs_grant_locks(struct afs_vnode *vnode, struct file_lock *fl) ...@@ -67,6 +67,100 @@ static void afs_grant_locks(struct afs_vnode *vnode, struct file_lock *fl)
} }
} }
/*
* 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;
_enter("%s{%x:%u.%u},%x,%u",
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)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
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;
_enter("%s{%x:%u.%u},%x",
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)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
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;
_enter("%s{%x:%u.%u},%x",
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)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
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;
}
/* /*
* do work for a lock, including: * do work for a lock, including:
* - probing for a lock we're waiting on but didn't get immediately * - probing for a lock we're waiting on but didn't get immediately
...@@ -91,7 +185,7 @@ void afs_lock_work(struct work_struct *work) ...@@ -91,7 +185,7 @@ void afs_lock_work(struct work_struct *work)
/* attempt to release the server lock; if it fails, we just /* attempt to release the server lock; if it fails, we just
* wait 5 minutes and it'll time out anyway */ * wait 5 minutes and it'll time out anyway */
ret = afs_vnode_release_lock(vnode, vnode->unlock_key); ret = afs_release_lock(vnode, vnode->unlock_key);
if (ret < 0) if (ret < 0)
printk(KERN_WARNING "AFS:" printk(KERN_WARNING "AFS:"
" Failed to release lock on {%x:%x} error %d\n", " Failed to release lock on {%x:%x} error %d\n",
...@@ -115,7 +209,7 @@ void afs_lock_work(struct work_struct *work) ...@@ -115,7 +209,7 @@ void afs_lock_work(struct work_struct *work)
key = key_get(fl->fl_file->private_data); key = key_get(fl->fl_file->private_data);
spin_unlock(&vnode->lock); spin_unlock(&vnode->lock);
ret = afs_vnode_extend_lock(vnode, key); ret = afs_extend_lock(vnode, key);
clear_bit(AFS_VNODE_LOCKING, &vnode->flags); clear_bit(AFS_VNODE_LOCKING, &vnode->flags);
key_put(key); key_put(key);
switch (ret) { switch (ret) {
...@@ -151,7 +245,7 @@ void afs_lock_work(struct work_struct *work) ...@@ -151,7 +245,7 @@ void afs_lock_work(struct work_struct *work)
AFS_LOCK_READ : AFS_LOCK_WRITE; AFS_LOCK_READ : AFS_LOCK_WRITE;
spin_unlock(&vnode->lock); spin_unlock(&vnode->lock);
ret = afs_vnode_set_lock(vnode, key, type); ret = afs_set_lock(vnode, key, type);
clear_bit(AFS_VNODE_LOCKING, &vnode->flags); clear_bit(AFS_VNODE_LOCKING, &vnode->flags);
switch (ret) { switch (ret) {
case -EWOULDBLOCK: case -EWOULDBLOCK:
...@@ -182,7 +276,7 @@ void afs_lock_work(struct work_struct *work) ...@@ -182,7 +276,7 @@ void afs_lock_work(struct work_struct *work)
clear_bit(AFS_VNODE_READLOCKED, &vnode->flags); clear_bit(AFS_VNODE_READLOCKED, &vnode->flags);
clear_bit(AFS_VNODE_WRITELOCKED, &vnode->flags); clear_bit(AFS_VNODE_WRITELOCKED, &vnode->flags);
spin_unlock(&vnode->lock); spin_unlock(&vnode->lock);
afs_vnode_release_lock(vnode, key); afs_release_lock(vnode, key);
if (!list_empty(&vnode->pending_locks)) if (!list_empty(&vnode->pending_locks))
afs_lock_may_be_available(vnode); afs_lock_may_be_available(vnode);
} }
...@@ -280,7 +374,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl) ...@@ -280,7 +374,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl)
set_bit(AFS_VNODE_LOCKING, &vnode->flags); set_bit(AFS_VNODE_LOCKING, &vnode->flags);
spin_unlock(&vnode->lock); spin_unlock(&vnode->lock);
ret = afs_vnode_set_lock(vnode, key, type); ret = afs_set_lock(vnode, key, type);
clear_bit(AFS_VNODE_LOCKING, &vnode->flags); clear_bit(AFS_VNODE_LOCKING, &vnode->flags);
switch (ret) { switch (ret) {
case 0: case 0:
...@@ -383,7 +477,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl) ...@@ -383,7 +477,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl)
/* again, make sure we've got a callback on this file and, again, make /* again, make sure we've got a callback on this file and, again, make
* sure that our view of the data version is up to date (we ignore * sure that our view of the data version is up to date (we ignore
* errors incurred here and deal with the consequences elsewhere) */ * errors incurred here and deal with the consequences elsewhere) */
afs_vnode_fetch_status(vnode, key, false); afs_validate(vnode, key);
error: error:
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
...@@ -455,7 +549,7 @@ static int afs_do_getlk(struct file *file, struct file_lock *fl) ...@@ -455,7 +549,7 @@ static int afs_do_getlk(struct file *file, struct file_lock *fl)
posix_test_lock(file, fl); posix_test_lock(file, fl);
if (fl->fl_type == F_UNLCK) { if (fl->fl_type == F_UNLCK) {
/* no local locks; consult the server */ /* no local locks; consult the server */
ret = afs_vnode_fetch_status(vnode, key, true); ret = afs_fetch_status(vnode, key);
if (ret < 0) if (ret < 0)
goto error; goto error;
lock_count = vnode->status.lock_count; lock_count = vnode->status.lock_count;
......
This diff is collapsed.
...@@ -101,6 +101,35 @@ static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key) ...@@ -101,6 +101,35 @@ static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)
return 0; return 0;
} }
/*
* Fetch file status from the volume.
*/
int afs_fetch_status(struct afs_vnode *vnode, struct key *key)
{
struct afs_fs_cursor fc;
int ret;
_enter("%s,{%x:%u.%u,S=%lx}",
vnode->volume->name,
vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique,
vnode->flags);
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, key)) {
while (afs_select_fileserver(&fc)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
afs_fs_fetch_file_status(&fc, NULL);
}
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;
}
/* /*
* iget5() comparator * iget5() comparator
*/ */
...@@ -205,7 +234,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name, ...@@ -205,7 +234,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
*/ */
struct inode *afs_iget(struct super_block *sb, struct key *key, struct inode *afs_iget(struct super_block *sb, struct key *key,
struct afs_fid *fid, struct afs_file_status *status, struct afs_fid *fid, struct afs_file_status *status,
struct afs_callback *cb) struct afs_callback *cb, struct afs_cb_interest *cbi)
{ {
struct afs_iget_data data = { .fid = *fid }; struct afs_iget_data data = { .fid = *fid };
struct afs_super_info *as; struct afs_super_info *as;
...@@ -238,7 +267,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, ...@@ -238,7 +267,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
if (!status) { if (!status) {
/* it's a remotely extant inode */ /* it's a remotely extant inode */
ret = afs_vnode_fetch_status(vnode, key, true); ret = afs_fetch_status(vnode, key);
if (ret < 0) if (ret < 0)
goto bad_inode; goto bad_inode;
} else { } else {
...@@ -255,6 +284,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, ...@@ -255,6 +284,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
vnode->cb_version = cb->version; vnode->cb_version = cb->version;
vnode->cb_type = cb->type; vnode->cb_type = cb->type;
vnode->cb_expires_at = cb->expiry; vnode->cb_expires_at = cb->expiry;
vnode->cb_interest = afs_get_cb_interest(cbi);
set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
} }
...@@ -358,7 +388,7 @@ int afs_validate(struct afs_vnode *vnode, struct key *key) ...@@ -358,7 +388,7 @@ int afs_validate(struct afs_vnode *vnode, struct key *key)
* access */ * access */
if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
_debug("not promised"); _debug("not promised");
ret = afs_vnode_fetch_status(vnode, key, false); ret = afs_fetch_status(vnode, key);
if (ret < 0) { if (ret < 0) {
if (ret == -ENOENT) { if (ret == -ENOENT) {
set_bit(AFS_VNODE_DELETED, &vnode->flags); set_bit(AFS_VNODE_DELETED, &vnode->flags);
...@@ -468,6 +498,7 @@ void afs_evict_inode(struct inode *inode) ...@@ -468,6 +498,7 @@ void afs_evict_inode(struct inode *inode)
*/ */
int afs_setattr(struct dentry *dentry, struct iattr *attr) int afs_setattr(struct dentry *dentry, struct iattr *attr)
{ {
struct afs_fs_cursor fc;
struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
struct key *key; struct key *key;
int ret; int ret;
...@@ -498,7 +529,18 @@ int afs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -498,7 +529,18 @@ int afs_setattr(struct dentry *dentry, struct iattr *attr)
} }
} }
ret = afs_vnode_setattr(vnode, key, attr); ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, key)) {
while (afs_select_fileserver(&fc)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
afs_fs_setattr(&fc, attr);
}
afs_check_for_remote_deletion(&fc, fc.vnode);
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
ret = afs_end_vnode_operation(&fc);
}
if (!(attr->ia_valid & ATTR_FILE)) if (!(attr->ia_valid & ATTR_FILE))
key_put(key); key_put(key);
......
This diff is collapsed.
...@@ -55,18 +55,17 @@ static int __net_init afs_net_init(struct afs_net *net) ...@@ -55,18 +55,17 @@ static int __net_init afs_net_init(struct afs_net *net)
spin_lock_init(&net->proc_cells_lock); spin_lock_init(&net->proc_cells_lock);
INIT_LIST_HEAD(&net->proc_cells); INIT_LIST_HEAD(&net->proc_cells);
INIT_LIST_HEAD(&net->vl_updates); seqlock_init(&net->fs_lock);
INIT_LIST_HEAD(&net->vl_graveyard); net->fs_servers = RB_ROOT;
INIT_DELAYED_WORK(&net->vl_reaper, afs_vlocation_reaper); INIT_LIST_HEAD(&net->fs_updates);
INIT_DELAYED_WORK(&net->vl_updater, afs_vlocation_updater); INIT_HLIST_HEAD(&net->fs_proc);
spin_lock_init(&net->vl_updates_lock);
spin_lock_init(&net->vl_graveyard_lock); INIT_HLIST_HEAD(&net->fs_addresses4);
net->servers = RB_ROOT; INIT_HLIST_HEAD(&net->fs_addresses6);
rwlock_init(&net->servers_lock); seqlock_init(&net->fs_addr_lock);
INIT_LIST_HEAD(&net->server_graveyard);
spin_lock_init(&net->server_graveyard_lock); INIT_WORK(&net->fs_manager, afs_manage_servers);
INIT_WORK(&net->server_reaper, afs_reap_server); timer_setup(&net->fs_timer, afs_servers_timer, 0);
timer_setup(&net->server_timer, afs_server_timer, 0);
/* Register the /proc stuff */ /* Register the /proc stuff */
ret = afs_proc_init(net); ret = afs_proc_init(net);
...@@ -87,8 +86,8 @@ static int __net_init afs_net_init(struct afs_net *net) ...@@ -87,8 +86,8 @@ static int __net_init afs_net_init(struct afs_net *net)
error_open_socket: error_open_socket:
net->live = false; net->live = false;
afs_vlocation_purge(net);
afs_cell_purge(net); afs_cell_purge(net);
afs_purge_servers(net);
error_cell_init: error_cell_init:
net->live = false; net->live = false;
afs_proc_cleanup(net); afs_proc_cleanup(net);
...@@ -103,9 +102,8 @@ static int __net_init afs_net_init(struct afs_net *net) ...@@ -103,9 +102,8 @@ static int __net_init afs_net_init(struct afs_net *net)
static void __net_exit afs_net_exit(struct afs_net *net) static void __net_exit afs_net_exit(struct afs_net *net)
{ {
net->live = false; net->live = false;
afs_purge_servers(net);
afs_vlocation_purge(net);
afs_cell_purge(net); afs_cell_purge(net);
afs_purge_servers(net);
afs_close_socket(net); afs_close_socket(net);
afs_proc_cleanup(net); afs_proc_cleanup(net);
} }
...@@ -125,10 +123,6 @@ static int __init afs_init(void) ...@@ -125,10 +123,6 @@ static int __init afs_init(void)
afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0); afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
if (!afs_async_calls) if (!afs_async_calls)
goto error_async; goto error_async;
afs_vlocation_update_worker =
alloc_workqueue("kafs_vlupdated", WQ_MEM_RECLAIM, 0);
if (!afs_vlocation_update_worker)
goto error_vl_up;
afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0); afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
if (!afs_lock_manager) if (!afs_lock_manager)
goto error_lockmgr; goto error_lockmgr;
...@@ -160,8 +154,6 @@ static int __init afs_init(void) ...@@ -160,8 +154,6 @@ static int __init afs_init(void)
#endif #endif
destroy_workqueue(afs_lock_manager); destroy_workqueue(afs_lock_manager);
error_lockmgr: error_lockmgr:
destroy_workqueue(afs_vlocation_update_worker);
error_vl_up:
destroy_workqueue(afs_async_calls); destroy_workqueue(afs_async_calls);
error_async: error_async:
destroy_workqueue(afs_wq); destroy_workqueue(afs_wq);
...@@ -189,7 +181,6 @@ static void __exit afs_exit(void) ...@@ -189,7 +181,6 @@ static void __exit afs_exit(void)
fscache_unregister_netfs(&afs_cache_netfs); fscache_unregister_netfs(&afs_cache_netfs);
#endif #endif
destroy_workqueue(afs_lock_manager); destroy_workqueue(afs_lock_manager);
destroy_workqueue(afs_vlocation_update_worker);
destroy_workqueue(afs_async_calls); destroy_workqueue(afs_async_calls);
destroy_workqueue(afs_wq); destroy_workqueue(afs_wq);
afs_clean_up_permit_cache(); afs_clean_up_permit_cache();
......
...@@ -105,22 +105,22 @@ static const struct file_operations afs_proc_cell_vlservers_fops = { ...@@ -105,22 +105,22 @@ static const struct file_operations afs_proc_cell_vlservers_fops = {
.release = seq_release, .release = seq_release,
}; };
static int afs_proc_cell_servers_open(struct inode *inode, struct file *file); static int afs_proc_servers_open(struct inode *inode, struct file *file);
static void *afs_proc_cell_servers_start(struct seq_file *p, loff_t *pos); static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos);
static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, static void *afs_proc_servers_next(struct seq_file *p, void *v,
loff_t *pos); loff_t *pos);
static void afs_proc_cell_servers_stop(struct seq_file *p, void *v); static void afs_proc_servers_stop(struct seq_file *p, void *v);
static int afs_proc_cell_servers_show(struct seq_file *m, void *v); static int afs_proc_servers_show(struct seq_file *m, void *v);
static const struct seq_operations afs_proc_cell_servers_ops = { static const struct seq_operations afs_proc_servers_ops = {
.start = afs_proc_cell_servers_start, .start = afs_proc_servers_start,
.next = afs_proc_cell_servers_next, .next = afs_proc_servers_next,
.stop = afs_proc_cell_servers_stop, .stop = afs_proc_servers_stop,
.show = afs_proc_cell_servers_show, .show = afs_proc_servers_show,
}; };
static const struct file_operations afs_proc_cell_servers_fops = { static const struct file_operations afs_proc_servers_fops = {
.open = afs_proc_cell_servers_open, .open = afs_proc_servers_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
.release = seq_release, .release = seq_release,
...@@ -138,7 +138,8 @@ int afs_proc_init(struct afs_net *net) ...@@ -138,7 +138,8 @@ int afs_proc_init(struct afs_net *net)
goto error_dir; goto error_dir;
if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) || if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) ||
!proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops)) !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) ||
!proc_create("servers", 0644, net->proc_afs, &afs_proc_servers_fops))
goto error_tree; goto error_tree;
_leave(" = 0"); _leave(" = 0");
...@@ -174,7 +175,6 @@ static int afs_proc_cells_open(struct inode *inode, struct file *file) ...@@ -174,7 +175,6 @@ static int afs_proc_cells_open(struct inode *inode, struct file *file)
m = file->private_data; m = file->private_data;
m->private = PDE_DATA(inode); m->private = PDE_DATA(inode);
return 0; return 0;
} }
...@@ -357,9 +357,7 @@ int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell) ...@@ -357,9 +357,7 @@ int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell)
if (!dir) if (!dir)
goto error_dir; goto error_dir;
if (!proc_create_data("servers", 0, dir, if (!proc_create_data("vlservers", 0, dir,
&afs_proc_cell_servers_fops, cell) ||
!proc_create_data("vlservers", 0, dir,
&afs_proc_cell_vlservers_fops, cell) || &afs_proc_cell_vlservers_fops, cell) ||
!proc_create_data("volumes", 0, dir, !proc_create_data("volumes", 0, dir,
&afs_proc_cell_volumes_fops, cell)) &afs_proc_cell_volumes_fops, cell))
...@@ -420,9 +418,8 @@ static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) ...@@ -420,9 +418,8 @@ static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
_enter("cell=%p pos=%Ld", cell, *_pos); _enter("cell=%p pos=%Ld", cell, *_pos);
/* lock the list against modification */ read_lock(&cell->proc_lock);
down_read(&cell->vl_sem); return seq_list_start_head(&cell->proc_volumes, *_pos);
return seq_list_start_head(&cell->vl_list, *_pos);
} }
/* /*
...@@ -434,7 +431,7 @@ static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, ...@@ -434,7 +431,7 @@ static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
struct afs_cell *cell = p->private; struct afs_cell *cell = p->private;
_enter("cell=%p pos=%Ld", cell, *_pos); _enter("cell=%p pos=%Ld", cell, *_pos);
return seq_list_next(v, &cell->vl_list, _pos); return seq_list_next(v, &cell->proc_volumes, _pos);
} }
/* /*
...@@ -444,17 +441,13 @@ static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) ...@@ -444,17 +441,13 @@ static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
{ {
struct afs_cell *cell = p->private; struct afs_cell *cell = p->private;
up_read(&cell->vl_sem); read_unlock(&cell->proc_lock);
} }
static const char afs_vlocation_states[][4] = { static const char afs_vol_types[3][3] = {
[AFS_VL_NEW] = "New", [AFSVL_RWVOL] = "RW",
[AFS_VL_CREATING] = "Crt", [AFSVL_ROVOL] = "RO",
[AFS_VL_VALID] = "Val", [AFSVL_BACKVOL] = "BK",
[AFS_VL_NO_VOLUME] = "NoV",
[AFS_VL_UPDATING] = "Upd",
[AFS_VL_VOLUME_DELETED] = "Del",
[AFS_VL_UNCERTAIN] = "Unc",
}; };
/* /*
...@@ -463,23 +456,17 @@ static const char afs_vlocation_states[][4] = { ...@@ -463,23 +456,17 @@ static const char afs_vlocation_states[][4] = {
static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
{ {
struct afs_cell *cell = m->private; struct afs_cell *cell = m->private;
struct afs_vlocation *vlocation = struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link);
list_entry(v, struct afs_vlocation, link);
/* display header on line 1 */ /* Display header on line 1 */
if (v == &cell->vl_list) { if (v == &cell->proc_volumes) {
seq_puts(m, "USE STT VLID[0] VLID[1] VLID[2] NAME\n"); seq_puts(m, "USE VID TY\n");
return 0; return 0;
} }
/* display one cell per line on subsequent lines */ seq_printf(m, "%3d %08x %s\n",
seq_printf(m, "%3d %s %08x %08x %08x %s\n", atomic_read(&vol->usage), vol->vid,
atomic_read(&vlocation->usage), afs_vol_types[vol->type]);
afs_vlocation_states[vlocation->state],
vlocation->vldb.vid[0],
vlocation->vldb.vid[1],
vlocation->vldb.vid[2],
vlocation->vldb.name);
return 0; return 0;
} }
...@@ -580,86 +567,62 @@ static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v) ...@@ -580,86 +567,62 @@ static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
} }
/* /*
* open "/proc/fs/afs/<cell>/servers" which provides a summary of active * open "/proc/fs/afs/servers" which provides a summary of active
* servers * servers
*/ */
static int afs_proc_cell_servers_open(struct inode *inode, struct file *file) static int afs_proc_servers_open(struct inode *inode, struct file *file)
{ {
struct afs_cell *cell; return seq_open(file, &afs_proc_servers_ops);
struct seq_file *m;
int ret;
cell = PDE_DATA(inode);
if (!cell)
return -ENOENT;
ret = seq_open(file, &afs_proc_cell_servers_ops);
if (ret < 0)
return ret;
m = file->private_data;
m->private = cell;
return 0;
} }
/* /*
* set up the iterator to start reading from the cells list and return the * Set up the iterator to start reading from the server list and return the
* first item * first item.
*/ */
static void *afs_proc_cell_servers_start(struct seq_file *m, loff_t *_pos) static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos)
__acquires(m->private->servers_lock)
{ {
struct afs_cell *cell = m->private; struct afs_net *net = afs_seq2net(m);
_enter("cell=%p pos=%Ld", cell, *_pos);
/* lock the list against modification */ rcu_read_lock();
read_lock(&cell->servers_lock); return seq_hlist_start_head_rcu(&net->fs_proc, *_pos);
return seq_list_start_head(&cell->servers, *_pos);
} }
/* /*
* move to next cell in cells list * move to next cell in cells list
*/ */
static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos)
loff_t *_pos)
{ {
struct afs_cell *cell = p->private; struct afs_net *net = afs_seq2net(m);
_enter("cell=%p pos=%Ld", cell, *_pos); return seq_hlist_next_rcu(v, &net->fs_proc, _pos);
return seq_list_next(v, &cell->servers, _pos);
} }
/* /*
* clean up after reading from the cells list * clean up after reading from the cells list
*/ */
static void afs_proc_cell_servers_stop(struct seq_file *p, void *v) static void afs_proc_servers_stop(struct seq_file *p, void *v)
__releases(p->private->servers_lock)
{ {
struct afs_cell *cell = p->private; rcu_read_unlock();
read_unlock(&cell->servers_lock);
} }
/* /*
* display a header line followed by a load of volume lines * display a header line followed by a load of volume lines
*/ */
static int afs_proc_cell_servers_show(struct seq_file *m, void *v) static int afs_proc_servers_show(struct seq_file *m, void *v)
{ {
struct afs_cell *cell = m->private; struct afs_server *server;
struct afs_server *server = list_entry(v, struct afs_server, link); struct afs_addr_list *alist;
char ipaddr[64];
/* display header on line 1 */ if (v == SEQ_START_TOKEN) {
if (v == &cell->servers) { seq_puts(m, "UUID USE ADDR\n");
seq_puts(m, "USE ADDR STATE\n");
return 0; return 0;
} }
/* display one cell per line on subsequent lines */ server = list_entry(v, struct afs_server, proc_link);
sprintf(ipaddr, "%pISp", &server->addrs->addrs[0].transport); alist = rcu_dereference(server->addresses);
seq_printf(m, "%3d %-15s %5d\n", seq_printf(m, "%pU %3d %pISp\n",
atomic_read(&server->usage), ipaddr, server->fs_state); &server->uuid,
atomic_read(&server->usage),
&alist->addrs[alist->index].transport);
return 0; return 0;
} }
This diff is collapsed.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
struct workqueue_struct *afs_async_calls; struct workqueue_struct *afs_async_calls;
static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long); static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long);
static long afs_wait_for_call_to_complete(struct afs_call *); static long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long); static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long);
static void afs_process_async_call(struct work_struct *); static void afs_process_async_call(struct work_struct *);
static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long); static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long);
...@@ -162,6 +162,7 @@ void afs_put_call(struct afs_call *call) ...@@ -162,6 +162,7 @@ void afs_put_call(struct afs_call *call)
call->type->destructor(call); call->type->destructor(call);
afs_put_server(call->net, call->cm_server); afs_put_server(call->net, call->cm_server);
afs_put_cb_interest(call->net, call->cbi);
kfree(call->request); kfree(call->request);
kfree(call); kfree(call);
...@@ -330,7 +331,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, ...@@ -330,7 +331,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
struct kvec iov[1]; struct kvec iov[1];
size_t offset; size_t offset;
s64 tx_total_len; s64 tx_total_len;
u32 abort_code;
int ret; int ret;
_enter(",{%pISp},", &srx->transport); _enter(",{%pISp},", &srx->transport);
...@@ -362,7 +362,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, ...@@ -362,7 +362,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
afs_wake_up_async_call : afs_wake_up_async_call :
afs_wake_up_call_waiter), afs_wake_up_call_waiter),
call->upgrade); call->upgrade);
call->key = NULL;
if (IS_ERR(rxcall)) { if (IS_ERR(rxcall)) {
ret = PTR_ERR(rxcall); ret = PTR_ERR(rxcall);
goto error_kill_call; goto error_kill_call;
...@@ -406,7 +405,7 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, ...@@ -406,7 +405,7 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
if (call->async) if (call->async)
return -EINPROGRESS; return -EINPROGRESS;
return afs_wait_for_call_to_complete(call); return afs_wait_for_call_to_complete(call, ac);
error_do_abort: error_do_abort:
call->state = AFS_CALL_COMPLETE; call->state = AFS_CALL_COMPLETE;
...@@ -414,15 +413,16 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, ...@@ -414,15 +413,16 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
rxrpc_kernel_abort_call(call->net->socket, rxcall, rxrpc_kernel_abort_call(call->net->socket, rxcall,
RX_USER_ABORT, ret, "KSD"); RX_USER_ABORT, ret, "KSD");
} else { } else {
abort_code = 0;
offset = 0; offset = 0;
rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL, rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL,
0, &offset, false, &call->abort_code, 0, &offset, false, &call->abort_code,
&call->service_id); &call->service_id);
ret = afs_abort_to_error(call->abort_code); ac->abort_code = call->abort_code;
ac->responded = true;
} }
error_kill_call: error_kill_call:
afs_put_call(call); afs_put_call(call);
ac->error = ret;
_leave(" = %d", ret); _leave(" = %d", ret);
return ret; return ret;
} }
...@@ -510,7 +510,8 @@ static void afs_deliver_to_call(struct afs_call *call) ...@@ -510,7 +510,8 @@ static void afs_deliver_to_call(struct afs_call *call)
/* /*
* wait synchronously for a call to complete * wait synchronously for a call to complete
*/ */
static long afs_wait_for_call_to_complete(struct afs_call *call) static long afs_wait_for_call_to_complete(struct afs_call *call,
struct afs_addr_cursor *ac)
{ {
signed long rtt2, timeout; signed long rtt2, timeout;
long ret; long ret;
...@@ -563,17 +564,26 @@ static long afs_wait_for_call_to_complete(struct afs_call *call) ...@@ -563,17 +564,26 @@ static long afs_wait_for_call_to_complete(struct afs_call *call)
/* Kill off the call if it's still live. */ /* Kill off the call if it's still live. */
if (call->state < AFS_CALL_COMPLETE) { if (call->state < AFS_CALL_COMPLETE) {
_debug("call interrupted"); _debug("call interrupted");
rxrpc_kernel_abort_call(call->net->socket, call->rxcall, if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
RX_USER_ABORT, -EINTR, "KWI"); RX_USER_ABORT, -EINTR, "KWI"))
call->error = -ERESTARTSYS;
} }
ret = call->error; ac->abort_code = call->abort_code;
if (ret < 0) { ac->error = call->error;
ret = afs_abort_to_error(call->abort_code);
} else if (ret == 0 && call->ret_reply0) { ret = ac->error;
switch (ret) {
case 0:
if (call->ret_reply0) {
ret = (long)call->reply[0]; ret = (long)call->reply[0];
call->reply[0] = NULL; call->reply[0] = NULL;
} }
/* Fall through */
case -ECONNABORTED:
ac->responded = true;
break;
}
_debug("call complete"); _debug("call complete");
afs_put_call(call); afs_put_call(call);
...@@ -882,9 +892,6 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count, ...@@ -882,9 +892,6 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count,
return 0; return 0;
} }
if (ret == -ECONNABORTED)
call->error = afs_abort_to_error(call->abort_code);
else
call->error = ret; call->error = ret;
call->state = AFS_CALL_COMPLETE; call->state = AFS_CALL_COMPLETE;
return ret; return ret;
......
...@@ -325,7 +325,7 @@ static int afs_check_permit(struct afs_vnode *vnode, struct key *key, ...@@ -325,7 +325,7 @@ static int afs_check_permit(struct afs_vnode *vnode, struct key *key,
*/ */
_debug("no valid permit"); _debug("no valid permit");
ret = afs_vnode_fetch_status(vnode, key, true); ret = afs_fetch_status(vnode, key);
if (ret < 0) { if (ret < 0) {
*_access = 0; *_access = 0;
_leave(" = %d", ret); _leave(" = %d", ret);
......
This diff is collapsed.
/* AFS fileserver list management.
*
* Copyright (C) 2017 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 <linux/kernel.h>
#include <linux/slab.h>
#include "internal.h"
void afs_put_serverlist(struct afs_net *net, struct afs_server_list *slist)
{
int i;
if (refcount_dec_and_test(&slist->usage)) {
for (i = 0; i < slist->nr_servers; i++) {
afs_put_cb_interest(net, slist->servers[i].cb_interest);
afs_put_server(net, slist->servers[i].server);
}
kfree(slist);
}
}
/*
* Build a server list from a VLDB record.
*/
struct afs_server_list *afs_alloc_server_list(struct afs_cell *cell,
struct key *key,
struct afs_vldb_entry *vldb,
u8 type_mask)
{
struct afs_server_list *slist;
struct afs_server *server;
int ret = -ENOMEM, nr_servers = 0, i, j;
for (i = 0; i < vldb->nr_servers; i++)
if (vldb->fs_mask[i] & type_mask)
nr_servers++;
slist = kzalloc(sizeof(struct afs_server_list) +
sizeof(struct afs_server_entry) * nr_servers,
GFP_KERNEL);
if (!slist)
goto error;
refcount_set(&slist->usage, 1);
/* Make sure a records exists for each server in the list. */
for (i = 0; i < vldb->nr_servers; i++) {
if (!(vldb->fs_mask[i] & type_mask))
continue;
server = afs_lookup_server(cell, key, &vldb->fs_server[i]);
if (IS_ERR(server)) {
ret = PTR_ERR(server);
if (ret == -ENOENT)
continue;
goto error_2;
}
/* Insertion-sort by server pointer */
for (j = 0; j < slist->nr_servers; j++)
if (slist->servers[j].server >= server)
break;
if (j < slist->nr_servers) {
if (slist->servers[j].server == server) {
afs_put_server(cell->net, server);
continue;
}
memmove(slist->servers + j + 1,
slist->servers + j,
(slist->nr_servers - j) * sizeof(struct afs_server_entry));
}
slist->servers[j].server = server;
slist->nr_servers++;
}
if (slist->nr_servers == 0) {
ret = -EDESTADDRREQ;
goto error_2;
}
return slist;
error_2:
afs_put_serverlist(cell->net, slist);
error:
return ERR_PTR(ret);
}
/*
* Copy the annotations from an old server list to its potential replacement.
*/
bool afs_annotate_server_list(struct afs_server_list *new,
struct afs_server_list *old)
{
struct afs_server *cur;
int i, j;
if (old->nr_servers != new->nr_servers)
goto changed;
for (i = 0; i < old->nr_servers; i++)
if (old->servers[i].server != new->servers[i].server)
goto changed;
return false;
changed:
/* Maintain the same current server as before if possible. */
cur = old->servers[old->index].server;
for (j = 0; j < new->nr_servers; j++) {
if (new->servers[j].server == cur) {
new->index = j;
break;
}
}
/* Keep the old callback interest records where possible so that we
* maintain callback interception.
*/
i = 0;
j = 0;
while (i < old->nr_servers && j < new->nr_servers) {
if (new->servers[j].server == old->servers[i].server) {
struct afs_cb_interest *cbi = old->servers[i].cb_interest;
if (cbi) {
new->servers[j].cb_interest = cbi;
refcount_inc(&cbi->usage);
}
i++;
j++;
continue;
}
if (new->servers[j].server < old->servers[i].server) {
j++;
continue;
}
i++;
continue;
}
return true;
}
...@@ -142,9 +142,9 @@ void __exit afs_fs_exit(void) ...@@ -142,9 +142,9 @@ void __exit afs_fs_exit(void)
*/ */
static int afs_show_devname(struct seq_file *m, struct dentry *root) static int afs_show_devname(struct seq_file *m, struct dentry *root)
{ {
struct afs_super_info *as = root->d_sb->s_fs_info; struct afs_super_info *as = AFS_FS_S(root->d_sb);
struct afs_volume *volume = as->volume; struct afs_volume *volume = as->volume;
struct afs_cell *cell = volume->cell; struct afs_cell *cell = as->cell;
const char *suf = ""; const char *suf = "";
char pref = '%'; char pref = '%';
...@@ -162,7 +162,7 @@ static int afs_show_devname(struct seq_file *m, struct dentry *root) ...@@ -162,7 +162,7 @@ static int afs_show_devname(struct seq_file *m, struct dentry *root)
break; break;
} }
seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->vlocation->vldb.name, suf); seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->name, suf);
return 0; return 0;
} }
...@@ -334,14 +334,16 @@ static int afs_parse_device_name(struct afs_mount_params *params, ...@@ -334,14 +334,16 @@ static int afs_parse_device_name(struct afs_mount_params *params,
static int afs_test_super(struct super_block *sb, void *data) static int afs_test_super(struct super_block *sb, void *data)
{ {
struct afs_super_info *as1 = data; struct afs_super_info *as1 = data;
struct afs_super_info *as = sb->s_fs_info; struct afs_super_info *as = AFS_FS_S(sb);
return as->net == as1->net && as->volume == as1->volume; return as->net == as1->net && as->volume->vid == as1->volume->vid;
} }
static int afs_set_super(struct super_block *sb, void *data) static int afs_set_super(struct super_block *sb, void *data)
{ {
sb->s_fs_info = data; struct afs_super_info *as = data;
sb->s_fs_info = as;
return set_anon_super(sb, NULL); return set_anon_super(sb, NULL);
} }
...@@ -351,7 +353,7 @@ static int afs_set_super(struct super_block *sb, void *data) ...@@ -351,7 +353,7 @@ static int afs_set_super(struct super_block *sb, void *data)
static int afs_fill_super(struct super_block *sb, static int afs_fill_super(struct super_block *sb,
struct afs_mount_params *params) struct afs_mount_params *params)
{ {
struct afs_super_info *as = sb->s_fs_info; struct afs_super_info *as = AFS_FS_S(sb);
struct afs_fid fid; struct afs_fid fid;
struct inode *inode = NULL; struct inode *inode = NULL;
int ret; int ret;
...@@ -368,13 +370,15 @@ static int afs_fill_super(struct super_block *sb, ...@@ -368,13 +370,15 @@ static int afs_fill_super(struct super_block *sb,
if (ret) if (ret)
return ret; return ret;
sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE; sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE;
strlcpy(sb->s_id, as->volume->vlocation->vldb.name, sizeof(sb->s_id)); sprintf(sb->s_id, "%u", as->volume->vid);
afs_activate_volume(as->volume);
/* allocate the root inode and dentry */ /* allocate the root inode and dentry */
fid.vid = as->volume->vid; fid.vid = as->volume->vid;
fid.vnode = 1; fid.vnode = 1;
fid.unique = 1; fid.unique = 1;
inode = afs_iget(sb, params->key, &fid, NULL, NULL); inode = afs_iget(sb, params->key, &fid, NULL, NULL, NULL);
if (IS_ERR(inode)) if (IS_ERR(inode))
return PTR_ERR(inode); return PTR_ERR(inode);
...@@ -426,7 +430,7 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -426,7 +430,7 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
{ {
struct afs_mount_params params; struct afs_mount_params params;
struct super_block *sb; struct super_block *sb;
struct afs_volume *vol; struct afs_volume *candidate;
struct key *key; struct key *key;
struct afs_super_info *as; struct afs_super_info *as;
int ret; int ret;
...@@ -464,15 +468,19 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -464,15 +468,19 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
ret = -ENOMEM; ret = -ENOMEM;
as = afs_alloc_sbi(&params); as = afs_alloc_sbi(&params);
if (!as) if (!as)
goto error; goto error_key;
/* parse the device name */ /* Assume we're going to need a volume record; at the very least we can
vol = afs_volume_lookup(&params); * use it to update the volume record if we have one already. This
if (IS_ERR(vol)) { * checks that the volume exists within the cell.
ret = PTR_ERR(vol); */
goto error; candidate = afs_create_volume(&params);
if (IS_ERR(candidate)) {
ret = PTR_ERR(candidate);
goto error_as;
} }
as->volume = vol;
as->volume = candidate;
/* allocate a deviceless superblock */ /* allocate a deviceless superblock */
sb = sget(fs_type, afs_test_super, afs_set_super, flags, as); sb = sget(fs_type, afs_test_super, afs_set_super, flags, as);
...@@ -503,11 +511,13 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -503,11 +511,13 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
error_sb: error_sb:
deactivate_locked_super(sb); deactivate_locked_super(sb);
goto error_key;
error_as: error_as:
afs_destroy_sbi(as); afs_destroy_sbi(as);
error_key:
key_put(params.key);
error: error:
afs_put_cell(params.net, params.cell); afs_put_cell(params.net, params.cell);
key_put(params.key);
_leave(" = %d", ret); _leave(" = %d", ret);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -519,8 +529,9 @@ static void afs_kill_super(struct super_block *sb) ...@@ -519,8 +529,9 @@ static void afs_kill_super(struct super_block *sb)
/* Clear the callback interests (which will do ilookup5) before /* Clear the callback interests (which will do ilookup5) before
* deactivating the superblock. * deactivating the superblock.
*/ */
afs_clear_callback_interests(as->net, as->volume); afs_clear_callback_interests(as->net, as->volume->servers);
kill_anon_super(sb); kill_anon_super(sb);
afs_deactivate_volume(as->volume);
afs_destroy_sbi(as); afs_destroy_sbi(as);
} }
...@@ -533,7 +544,7 @@ static void afs_i_init_once(void *_vnode) ...@@ -533,7 +544,7 @@ static void afs_i_init_once(void *_vnode)
memset(vnode, 0, sizeof(*vnode)); memset(vnode, 0, sizeof(*vnode));
inode_init_once(&vnode->vfs_inode); inode_init_once(&vnode->vfs_inode);
init_waitqueue_head(&vnode->update_waitq); mutex_init(&vnode->io_lock);
mutex_init(&vnode->validate_lock); mutex_init(&vnode->validate_lock);
spin_lock_init(&vnode->writeback_lock); spin_lock_init(&vnode->writeback_lock);
spin_lock_init(&vnode->lock); spin_lock_init(&vnode->lock);
...@@ -561,7 +572,6 @@ static struct inode *afs_alloc_inode(struct super_block *sb) ...@@ -561,7 +572,6 @@ static struct inode *afs_alloc_inode(struct super_block *sb)
memset(&vnode->status, 0, sizeof(vnode->status)); memset(&vnode->status, 0, sizeof(vnode->status));
vnode->volume = NULL; vnode->volume = NULL;
vnode->update_cnt = 0;
vnode->flags = 1 << AFS_VNODE_UNSET; vnode->flags = 1 << AFS_VNODE_UNSET;
_leave(" = %p", &vnode->vfs_inode); _leave(" = %p", &vnode->vfs_inode);
...@@ -597,6 +607,7 @@ static void afs_destroy_inode(struct inode *inode) ...@@ -597,6 +607,7 @@ static void afs_destroy_inode(struct inode *inode)
*/ */
static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
{ {
struct afs_fs_cursor fc;
struct afs_volume_status vs; struct afs_volume_status vs;
struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
struct key *key; struct key *key;
...@@ -606,13 +617,22 @@ static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -606,13 +617,22 @@ static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
if (IS_ERR(key)) if (IS_ERR(key))
return PTR_ERR(key); return PTR_ERR(key);
ret = afs_vnode_get_volume_status(vnode, key, &vs); ret = -ERESTARTSYS;
key_put(key); if (afs_begin_vnode_operation(&fc, vnode, key)) {
if (ret < 0) { fc.flags |= AFS_FS_CURSOR_NO_VSLEEP;
_leave(" = %d", ret); while (afs_select_fileserver(&fc)) {
return ret; fc.cb_break = vnode->cb_break + vnode->cb_s_break;
afs_fs_get_volume_status(&fc, &vs);
} }
afs_check_for_remote_deletion(&fc, fc.vnode);
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
ret = afs_end_vnode_operation(&fc);
}
key_put(key);
if (ret == 0) {
buf->f_type = dentry->d_sb->s_magic; buf->f_type = dentry->d_sb->s_magic;
buf->f_bsize = AFS_BLOCK_SIZE; buf->f_bsize = AFS_BLOCK_SIZE;
buf->f_namelen = AFSNAMEMAX - 1; buf->f_namelen = AFSNAMEMAX - 1;
...@@ -622,5 +642,7 @@ static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -622,5 +642,7 @@ static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
else else
buf->f_blocks = vs.max_quota; buf->f_blocks = vs.max_quota;
buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use; buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use;
return 0; }
return ret;
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -103,7 +103,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key, ...@@ -103,7 +103,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,
req->pages[0] = page; req->pages[0] = page;
get_page(page); get_page(page);
ret = afs_vnode_fetch_data(vnode, key, req); ret = afs_fetch_data(vnode, key, req);
afs_put_read(req); afs_put_read(req);
if (ret < 0) { if (ret < 0) {
if (ret == -ENOENT) { if (ret == -ENOENT) {
...@@ -337,6 +337,40 @@ static void afs_kill_pages(struct afs_vnode *vnode, bool error, ...@@ -337,6 +337,40 @@ static void afs_kill_pages(struct afs_vnode *vnode, bool error,
_leave(""); _leave("");
} }
/*
* write to a file
*/
static int afs_store_data(struct afs_writeback *wb, pgoff_t first, pgoff_t last,
unsigned offset, unsigned to)
{
struct afs_fs_cursor fc;
struct afs_vnode *vnode = wb->vnode;
int ret;
_enter("%s{%x:%u.%u},%x,%lx,%lx,%x,%x",
vnode->volume->name,
vnode->fid.vid,
vnode->fid.vnode,
vnode->fid.unique,
key_serial(wb->key),
first, last, offset, to);
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, wb->key)) {
while (afs_select_fileserver(&fc)) {
fc.cb_break = vnode->cb_break + vnode->cb_s_break;
afs_fs_store_data(&fc, wb, first, last, offset, to);
}
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;
}
/* /*
* synchronously write back the locked page and any subsequent non-locked dirty * synchronously write back the locked page and any subsequent non-locked dirty
* pages also covered by the same writeback record * pages also covered by the same writeback record
...@@ -420,7 +454,7 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb, ...@@ -420,7 +454,7 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb,
_debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to); _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to);
ret = afs_vnode_store_data(wb, first, last, offset, to); ret = afs_store_data(wb, first, last, offset, to);
if (ret < 0) { if (ret < 0) {
switch (ret) { switch (ret) {
case -EDQUOT: case -EDQUOT:
......
...@@ -96,7 +96,7 @@ static int afs_xattr_get_volume(const struct xattr_handler *handler, ...@@ -96,7 +96,7 @@ static int afs_xattr_get_volume(const struct xattr_handler *handler,
void *buffer, size_t size) void *buffer, size_t size)
{ {
struct afs_vnode *vnode = AFS_FS_I(inode); struct afs_vnode *vnode = AFS_FS_I(inode);
const char *volname = vnode->volume->vlocation->vldb.name; const char *volname = vnode->volume->name;
size_t namelen; size_t namelen;
namelen = strlen(volname); namelen = strlen(volname);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment