summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2017-11-02 11:27:50 -0400
committerDavid Howells <dhowells@redhat.com>2017-11-13 10:38:19 -0500
commitd2ddc776a4581d900fc3bdc7803b403daae64d88 (patch)
tree6c5f6bac9e9e9a326ed0a9248914b53c421558e5
parent9cc6fc50f7bc69ac28bee45eed13cbc65a86210f (diff)
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>
-rw-r--r--fs/afs/Makefile3
-rw-r--r--fs/afs/addr_list.c31
-rw-r--r--fs/afs/afs_fs.h1
-rw-r--r--fs/afs/afs_vl.h42
-rw-r--r--fs/afs/callback.c20
-rw-r--r--fs/afs/cell.c7
-rw-r--r--fs/afs/dir.c388
-rw-r--r--fs/afs/file.c37
-rw-r--r--fs/afs/flock.c108
-rw-r--r--fs/afs/fsclient.c347
-rw-r--r--fs/afs/inode.c50
-rw-r--r--fs/afs/internal.h453
-rw-r--r--fs/afs/main.c35
-rw-r--r--fs/afs/proc.c153
-rw-r--r--fs/afs/rotate.c461
-rw-r--r--fs/afs/rxrpc.c45
-rw-r--r--fs/afs/security.c2
-rw-r--r--fs/afs/server.c750
-rw-r--r--fs/afs/server_list.c153
-rw-r--r--fs/afs/super.c92
-rw-r--r--fs/afs/vlclient.c307
-rw-r--r--fs/afs/vlocation.c669
-rw-r--r--fs/afs/vnode.c750
-rw-r--r--fs/afs/volume.c426
-rw-r--r--fs/afs/write.c38
-rw-r--r--fs/afs/xattr.c2
26 files changed, 2795 insertions, 2575 deletions
diff --git a/fs/afs/Makefile b/fs/afs/Makefile
index 192d476d7c76..45b7fc405fa6 100644
--- a/fs/afs/Makefile
+++ b/fs/afs/Makefile
@@ -24,11 +24,10 @@ kafs-objs := \
24 rxrpc.o \ 24 rxrpc.o \
25 security.o \ 25 security.o \
26 server.o \ 26 server.o \
27 server_list.o \
27 super.o \ 28 super.o \
28 netdevices.o \ 29 netdevices.o \
29 vlclient.o \ 30 vlclient.o \
30 vlocation.o \
31 vnode.o \
32 volume.o \ 31 volume.o \
33 write.o \ 32 write.o \
34 xattr.o 33 xattr.o
diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c
index ecb9c72aebd2..b91e59a77f0e 100644
--- a/fs/afs/addr_list.c
+++ b/fs/afs/addr_list.c
@@ -228,6 +228,37 @@ struct afs_addr_list *afs_dns_query(struct afs_cell *cell, time64_t *_expiry)
228} 228}
229 229
230/* 230/*
231 * Merge an IPv4 entry into a fileserver address list.
232 */
233void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr)
234{
235 struct sockaddr_in6 *a;
236 int i;
237
238 for (i = 0; i < alist->nr_ipv4; i++) {
239 a = &alist->addrs[i].transport.sin6;
240 if (xdr == a->sin6_addr.s6_addr32[3])
241 return;
242 if (xdr < a->sin6_addr.s6_addr32[3])
243 break;
244 }
245
246 if (i < alist->nr_addrs)
247 memmove(alist->addrs + i + 1,
248 alist->addrs + i,
249 sizeof(alist->addrs[0]) * (alist->nr_addrs - i));
250
251 a = &alist->addrs[i].transport.sin6;
252 a->sin6_port = htons(AFS_FS_PORT);
253 a->sin6_addr.s6_addr32[0] = 0;
254 a->sin6_addr.s6_addr32[1] = 0;
255 a->sin6_addr.s6_addr32[2] = htonl(0xffff);
256 a->sin6_addr.s6_addr32[3] = xdr;
257 alist->nr_ipv4++;
258 alist->nr_addrs++;
259}
260
261/*
231 * Get an address to try. 262 * Get an address to try.
232 */ 263 */
233bool afs_iterate_addresses(struct afs_addr_cursor *ac) 264bool afs_iterate_addresses(struct afs_addr_cursor *ac)
diff --git a/fs/afs/afs_fs.h b/fs/afs/afs_fs.h
index 05395d0f1941..d47b6d01e4c0 100644
--- a/fs/afs/afs_fs.h
+++ b/fs/afs/afs_fs.h
@@ -38,6 +38,7 @@ enum AFS_FS_Operations {
38 FSFETCHDATA64 = 65537, /* AFS Fetch file data */ 38 FSFETCHDATA64 = 65537, /* AFS Fetch file data */
39 FSSTOREDATA64 = 65538, /* AFS Store file data */ 39 FSSTOREDATA64 = 65538, /* AFS Store file data */
40 FSGIVEUPALLCALLBACKS = 65539, /* AFS Give up all outstanding callbacks on a server */ 40 FSGIVEUPALLCALLBACKS = 65539, /* AFS Give up all outstanding callbacks on a server */
41 FSGETCAPABILITIES = 65540, /* Probe and get the capabilities of a fileserver */
41}; 42};
42 43
43enum AFS_FS_Errors { 44enum AFS_FS_Errors {
diff --git a/fs/afs/afs_vl.h b/fs/afs/afs_vl.h
index 4eaa620992c8..6350b417aee9 100644
--- a/fs/afs/afs_vl.h
+++ b/fs/afs/afs_vl.h
@@ -88,4 +88,46 @@ struct afs_vldbentry {
88 88
89#define AFS_VLDB_MAXNAMELEN 65 89#define AFS_VLDB_MAXNAMELEN 65
90 90
91
92struct afs_ListAddrByAttributes__xdr {
93 __be32 Mask;
94#define AFS_VLADDR_IPADDR 0x1 /* Match by ->ipaddr */
95#define AFS_VLADDR_INDEX 0x2 /* Match by ->index */
96#define AFS_VLADDR_UUID 0x4 /* Match by ->uuid */
97 __be32 ipaddr;
98 __be32 index;
99 __be32 spare;
100 struct afs_uuid__xdr uuid;
101};
102
103struct afs_uvldbentry__xdr {
104 __be32 name[AFS_VLDB_MAXNAMELEN];
105 __be32 nServers;
106 struct afs_uuid__xdr serverNumber[AFS_NMAXNSERVERS];
107 __be32 serverUnique[AFS_NMAXNSERVERS];
108 __be32 serverPartition[AFS_NMAXNSERVERS];
109 __be32 serverFlags[AFS_NMAXNSERVERS];
110 __be32 volumeId[AFS_MAXTYPES];
111 __be32 cloneId;
112 __be32 flags;
113 __be32 spares1;
114 __be32 spares2;
115 __be32 spares3;
116 __be32 spares4;
117 __be32 spares5;
118 __be32 spares6;
119 __be32 spares7;
120 __be32 spares8;
121 __be32 spares9;
122};
123
124struct afs_address_list {
125 refcount_t usage;
126 unsigned int version;
127 unsigned int nr_addrs;
128 struct sockaddr_rxrpc addrs[];
129};
130
131extern void afs_put_address_list(struct afs_address_list *alist);
132
91#endif /* AFS_VL_H */ 133#endif /* AFS_VL_H */
diff --git a/fs/afs/callback.c b/fs/afs/callback.c
index 82f4c7a3b7b6..f4291b576054 100644
--- a/fs/afs/callback.c
+++ b/fs/afs/callback.c
@@ -26,10 +26,10 @@
26 * - Called with volume->server_sem held. 26 * - Called with volume->server_sem held.
27 */ 27 */
28int afs_register_server_cb_interest(struct afs_vnode *vnode, 28int afs_register_server_cb_interest(struct afs_vnode *vnode,
29 struct afs_cb_interest **ppcbi, 29 struct afs_server_entry *entry)
30 struct afs_server *server)
31{ 30{
32 struct afs_cb_interest *cbi = *ppcbi, *vcbi, *new, *x; 31 struct afs_cb_interest *cbi = entry->cb_interest, *vcbi, *new, *x;
32 struct afs_server *server = entry->server;
33 33
34again: 34again:
35 vcbi = vnode->cb_interest; 35 vcbi = vnode->cb_interest;
@@ -47,7 +47,7 @@ again:
47 47
48 if (!cbi && vcbi->server == server) { 48 if (!cbi && vcbi->server == server) {
49 afs_get_cb_interest(vcbi); 49 afs_get_cb_interest(vcbi);
50 x = cmpxchg(ppcbi, cbi, vcbi); 50 x = cmpxchg(&entry->cb_interest, cbi, vcbi);
51 if (x != cbi) { 51 if (x != cbi) {
52 cbi = x; 52 cbi = x;
53 afs_put_cb_interest(afs_v2net(vnode), vcbi); 53 afs_put_cb_interest(afs_v2net(vnode), vcbi);
@@ -72,7 +72,7 @@ again:
72 list_add_tail(&new->cb_link, &server->cb_interests); 72 list_add_tail(&new->cb_link, &server->cb_interests);
73 write_unlock(&server->cb_break_lock); 73 write_unlock(&server->cb_break_lock);
74 74
75 x = cmpxchg(ppcbi, cbi, new); 75 x = cmpxchg(&entry->cb_interest, cbi, new);
76 if (x == cbi) { 76 if (x == cbi) {
77 cbi = new; 77 cbi = new;
78 } else { 78 } else {
@@ -137,7 +137,7 @@ void afs_put_cb_interest(struct afs_net *net, struct afs_cb_interest *cbi)
137 */ 137 */
138void afs_init_callback_state(struct afs_server *server) 138void afs_init_callback_state(struct afs_server *server)
139{ 139{
140 if (!test_and_clear_bit(AFS_SERVER_NEW, &server->flags)) 140 if (!test_and_clear_bit(AFS_SERVER_FL_NEW, &server->flags))
141 server->cb_s_break++; 141 server->cb_s_break++;
142} 142}
143 143
@@ -233,12 +233,12 @@ void afs_break_callbacks(struct afs_server *server, size_t count,
233/* 233/*
234 * Clear the callback interests in a server list. 234 * Clear the callback interests in a server list.
235 */ 235 */
236void afs_clear_callback_interests(struct afs_net *net, struct afs_volume *volume) 236void afs_clear_callback_interests(struct afs_net *net, struct afs_server_list *slist)
237{ 237{
238 int i; 238 int i;
239 239
240 for (i = 0; i < ARRAY_SIZE(volume->cb_interests); i++) { 240 for (i = 0; i < slist->nr_servers; i++) {
241 afs_put_cb_interest(net, volume->cb_interests[i]); 241 afs_put_cb_interest(net, slist->servers[i].cb_interest);
242 volume->cb_interests[i] = NULL; 242 slist->servers[i].cb_interest = NULL;
243 } 243 }
244} 244}
diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index a0e08d3a108c..1858c91169e4 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -146,13 +146,10 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
146 146
147 atomic_set(&cell->usage, 2); 147 atomic_set(&cell->usage, 2);
148 INIT_WORK(&cell->manager, afs_manage_cell); 148 INIT_WORK(&cell->manager, afs_manage_cell);
149 rwlock_init(&cell->servers_lock);
150 INIT_LIST_HEAD(&cell->servers);
151 init_rwsem(&cell->vl_sem);
152 INIT_LIST_HEAD(&cell->vl_list);
153 spin_lock_init(&cell->vl_lock);
154 cell->flags = ((1 << AFS_CELL_FL_NOT_READY) | 149 cell->flags = ((1 << AFS_CELL_FL_NOT_READY) |
155 (1 << AFS_CELL_FL_NO_LOOKUP_YET)); 150 (1 << AFS_CELL_FL_NO_LOOKUP_YET));
151 INIT_LIST_HEAD(&cell->proc_volumes);
152 rwlock_init(&cell->proc_lock);
156 rwlock_init(&cell->vl_addrs_lock); 153 rwlock_init(&cell->vl_addrs_lock);
157 154
158 /* Fill in the VL server list if we were given a list of addresses to 155 /* Fill in the VL server list if we were given a list of addresses to
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 37083699a0df..53f3917440e7 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -553,7 +553,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
553 dentry->d_fsdata = (void *)(unsigned long) vnode->status.data_version; 553 dentry->d_fsdata = (void *)(unsigned long) vnode->status.data_version;
554 554
555 /* instantiate the dentry */ 555 /* instantiate the dentry */
556 inode = afs_iget(dir->i_sb, key, &fid, NULL, NULL); 556 inode = afs_iget(dir->i_sb, key, &fid, NULL, NULL, NULL);
557 key_put(key); 557 key_put(key);
558 if (IS_ERR(inode)) { 558 if (IS_ERR(inode)) {
559 _leave(" = %ld", PTR_ERR(inode)); 559 _leave(" = %ld", PTR_ERR(inode));
@@ -741,20 +741,48 @@ static void afs_d_release(struct dentry *dentry)
741} 741}
742 742
743/* 743/*
744 * Create a new inode for create/mkdir/symlink
745 */
746static void afs_vnode_new_inode(struct afs_fs_cursor *fc,
747 struct dentry *new_dentry,
748 struct afs_fid *newfid,
749 struct afs_file_status *newstatus,
750 struct afs_callback *newcb)
751{
752 struct inode *inode;
753
754 if (fc->ac.error < 0)
755 return;
756
757 inode = afs_iget(fc->vnode->vfs_inode.i_sb, fc->key,
758 newfid, newstatus, newcb, fc->cbi);
759 if (IS_ERR(inode)) {
760 /* ENOMEM or EINTR at a really inconvenient time - just abandon
761 * the new directory on the server.
762 */
763 fc->ac.error = PTR_ERR(inode);
764 return;
765 }
766
767 d_instantiate(new_dentry, inode);
768 if (d_unhashed(new_dentry))
769 d_rehash(new_dentry);
770}
771
772/*
744 * create a directory on an AFS filesystem 773 * create a directory on an AFS filesystem
745 */ 774 */
746static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 775static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
747{ 776{
748 struct afs_file_status status; 777 struct afs_file_status newstatus;
749 struct afs_callback cb; 778 struct afs_fs_cursor fc;
750 struct afs_server *server; 779 struct afs_callback newcb;
751 struct afs_vnode *dvnode, *vnode; 780 struct afs_vnode *dvnode = AFS_FS_I(dir);
752 struct afs_fid fid; 781 struct afs_fid newfid;
753 struct inode *inode;
754 struct key *key; 782 struct key *key;
755 int ret; 783 int ret;
756 784
757 dvnode = AFS_FS_I(dir); 785 mode |= S_IFDIR;
758 786
759 _enter("{%x:%u},{%pd},%ho", 787 _enter("{%x:%u},{%pd},%ho",
760 dvnode->fid.vid, dvnode->fid.vnode, dentry, mode); 788 dvnode->fid.vid, dvnode->fid.vnode, dentry, mode);
@@ -765,40 +793,27 @@ static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
765 goto error; 793 goto error;
766 } 794 }
767 795
768 mode |= S_IFDIR; 796 ret = -ERESTARTSYS;
769 ret = afs_vnode_create(dvnode, key, dentry->d_name.name, 797 if (afs_begin_vnode_operation(&fc, dvnode, key)) {
770 mode, &fid, &status, &cb, &server); 798 while (afs_select_fileserver(&fc)) {
771 if (ret < 0) 799 fc.cb_break = dvnode->cb_break + dvnode->cb_s_break;
772 goto mkdir_error; 800 afs_fs_create(&fc, dentry->d_name.name, mode,
801 &newfid, &newstatus, &newcb);
802 }
773 803
774 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb); 804 afs_check_for_remote_deletion(&fc, fc.vnode);
775 if (IS_ERR(inode)) { 805 afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
776 /* ENOMEM at a really inconvenient time - just abandon the new 806 afs_vnode_new_inode(&fc, dentry, &newfid, &newstatus, &newcb);
777 * directory on the server */ 807 ret = afs_end_vnode_operation(&fc);
778 ret = PTR_ERR(inode); 808 if (ret < 0)
779 goto iget_error; 809 goto error_key;
780 } 810 }
781 811
782 /* apply the status report we've got for the new vnode */
783 vnode = AFS_FS_I(inode);
784 spin_lock(&vnode->lock);
785 vnode->update_cnt++;
786 spin_unlock(&vnode->lock);
787 afs_vnode_finalise_status_update(vnode, server);
788 afs_put_server(afs_i2net(dir), server);
789
790 d_instantiate(dentry, inode);
791 if (d_unhashed(dentry)) {
792 _debug("not hashed");
793 d_rehash(dentry);
794 }
795 key_put(key); 812 key_put(key);
796 _leave(" = 0"); 813 _leave(" = 0");
797 return 0; 814 return 0;
798 815
799iget_error: 816error_key:
800 afs_put_server(afs_i2net(dir), server);
801mkdir_error:
802 key_put(key); 817 key_put(key);
803error: 818error:
804 d_drop(dentry); 819 d_drop(dentry);
@@ -807,16 +822,29 @@ error:
807} 822}
808 823
809/* 824/*
825 * Remove a subdir from a directory.
826 */
827static void afs_dir_remove_subdir(struct dentry *dentry)
828{
829 if (d_really_is_positive(dentry)) {
830 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
831
832 clear_nlink(&vnode->vfs_inode);
833 set_bit(AFS_VNODE_DELETED, &vnode->flags);
834 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
835 }
836}
837
838/*
810 * remove a directory from an AFS filesystem 839 * remove a directory from an AFS filesystem
811 */ 840 */
812static int afs_rmdir(struct inode *dir, struct dentry *dentry) 841static int afs_rmdir(struct inode *dir, struct dentry *dentry)
813{ 842{
814 struct afs_vnode *dvnode, *vnode; 843 struct afs_fs_cursor fc;
844 struct afs_vnode *dvnode = AFS_FS_I(dir);
815 struct key *key; 845 struct key *key;
816 int ret; 846 int ret;
817 847
818 dvnode = AFS_FS_I(dir);
819
820 _enter("{%x:%u},{%pd}", 848 _enter("{%x:%u},{%pd}",
821 dvnode->fid.vid, dvnode->fid.vnode, dentry); 849 dvnode->fid.vid, dvnode->fid.vnode, dentry);
822 850
@@ -826,45 +854,69 @@ static int afs_rmdir(struct inode *dir, struct dentry *dentry)
826 goto error; 854 goto error;
827 } 855 }
828 856
829 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, true); 857 ret = -ERESTARTSYS;
830 if (ret < 0) 858 if (afs_begin_vnode_operation(&fc, dvnode, key)) {
831 goto rmdir_error; 859 while (afs_select_fileserver(&fc)) {
860 fc.cb_break = dvnode->cb_break + dvnode->cb_s_break;
861 afs_fs_remove(&fc, dentry->d_name.name, true);
862 }
832 863
833 if (d_really_is_positive(dentry)) { 864 afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
834 vnode = AFS_FS_I(d_inode(dentry)); 865 ret = afs_end_vnode_operation(&fc);
835 clear_nlink(&vnode->vfs_inode); 866 if (ret == 0)
836 set_bit(AFS_VNODE_DELETED, &vnode->flags); 867 afs_dir_remove_subdir(dentry);
837 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
838 } 868 }
839 869
840 key_put(key); 870 key_put(key);
841 _leave(" = 0");
842 return 0;
843
844rmdir_error:
845 key_put(key);
846error: 871error:
847 _leave(" = %d", ret);
848 return ret; 872 return ret;
849} 873}
850 874
851/* 875/*
852 * remove a file from an AFS filesystem 876 * Remove a link to a file or symlink from a directory.
877 *
878 * If the file was not deleted due to excess hard links, the fileserver will
879 * break the callback promise on the file - if it had one - before it returns
880 * to us, and if it was deleted, it won't
881 *
882 * However, if we didn't have a callback promise outstanding, or it was
883 * outstanding on a different server, then it won't break it either...
884 */
885static int afs_dir_remove_link(struct dentry *dentry, struct key *key)
886{
887 int ret = 0;
888
889 if (d_really_is_positive(dentry)) {
890 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
891
892 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
893 kdebug("AFS_VNODE_DELETED");
894 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
895
896 ret = afs_validate(vnode, key);
897 if (ret == -ESTALE)
898 ret = 0;
899 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
900 }
901
902 return ret;
903}
904
905/*
906 * Remove a file or symlink from an AFS filesystem.
853 */ 907 */
854static int afs_unlink(struct inode *dir, struct dentry *dentry) 908static int afs_unlink(struct inode *dir, struct dentry *dentry)
855{ 909{
856 struct afs_vnode *dvnode, *vnode; 910 struct afs_fs_cursor fc;
911 struct afs_vnode *dvnode = AFS_FS_I(dir), *vnode;
857 struct key *key; 912 struct key *key;
858 int ret; 913 int ret;
859 914
860 dvnode = AFS_FS_I(dir);
861
862 _enter("{%x:%u},{%pd}", 915 _enter("{%x:%u},{%pd}",
863 dvnode->fid.vid, dvnode->fid.vnode, dentry); 916 dvnode->fid.vid, dvnode->fid.vnode, dentry);
864 917
865 ret = -ENAMETOOLONG;
866 if (dentry->d_name.len >= AFSNAMEMAX) 918 if (dentry->d_name.len >= AFSNAMEMAX)
867 goto error; 919 return -ENAMETOOLONG;
868 920
869 key = afs_request_key(dvnode->volume->cell); 921 key = afs_request_key(dvnode->volume->cell);
870 if (IS_ERR(key)) { 922 if (IS_ERR(key)) {
@@ -872,42 +924,28 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
872 goto error; 924 goto error;
873 } 925 }
874 926
927 /* Try to make sure we have a callback promise on the victim. */
875 if (d_really_is_positive(dentry)) { 928 if (d_really_is_positive(dentry)) {
876 vnode = AFS_FS_I(d_inode(dentry)); 929 vnode = AFS_FS_I(d_inode(dentry));
877
878 /* make sure we have a callback promise on the victim */
879 ret = afs_validate(vnode, key); 930 ret = afs_validate(vnode, key);
880 if (ret < 0) 931 if (ret < 0)
881 goto error; 932 goto error_key;
882 } 933 }
883 934
884 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, false); 935 ret = -ERESTARTSYS;
885 if (ret < 0) 936 if (afs_begin_vnode_operation(&fc, dvnode, key)) {
886 goto remove_error; 937 while (afs_select_fileserver(&fc)) {
938 fc.cb_break = dvnode->cb_break + dvnode->cb_s_break;
939 afs_fs_remove(&fc, dentry->d_name.name, false);
940 }
887 941
888 if (d_really_is_positive(dentry)) { 942 afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
889 /* if the file wasn't deleted due to excess hard links, the 943 ret = afs_end_vnode_operation(&fc);
890 * fileserver will break the callback promise on the file - if 944 if (ret == 0)
891 * it had one - before it returns to us, and if it was deleted, 945 ret = afs_dir_remove_link(dentry, key);
892 * it won't
893 *
894 * however, if we didn't have a callback promise outstanding,
895 * or it was outstanding on a different server, then it won't
896 * break it either...
897 */
898 vnode = AFS_FS_I(d_inode(dentry));
899 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
900 _debug("AFS_VNODE_DELETED");
901 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
902 ret = afs_validate(vnode, key);
903 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
904 } 946 }
905 947
906 key_put(key); 948error_key:
907 _leave(" = 0");
908 return 0;
909
910remove_error:
911 key_put(key); 949 key_put(key);
912error: 950error:
913 _leave(" = %d", ret); 951 _leave(" = %d", ret);
@@ -920,60 +958,50 @@ error:
920static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode, 958static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
921 bool excl) 959 bool excl)
922{ 960{
923 struct afs_file_status status; 961 struct afs_fs_cursor fc;
924 struct afs_callback cb; 962 struct afs_file_status newstatus;
925 struct afs_server *server; 963 struct afs_callback newcb;
926 struct afs_vnode *dvnode, *vnode; 964 struct afs_vnode *dvnode = dvnode = AFS_FS_I(dir);
927 struct afs_fid fid; 965 struct afs_fid newfid;
928 struct inode *inode;
929 struct key *key; 966 struct key *key;
930 int ret; 967 int ret;
931 968
932 dvnode = AFS_FS_I(dir); 969 mode |= S_IFREG;
933 970
934 _enter("{%x:%u},{%pd},%ho,", 971 _enter("{%x:%u},{%pd},%ho,",
935 dvnode->fid.vid, dvnode->fid.vnode, dentry, mode); 972 dvnode->fid.vid, dvnode->fid.vnode, dentry, mode);
936 973
974 ret = -ENAMETOOLONG;
975 if (dentry->d_name.len >= AFSNAMEMAX)
976 goto error;
977
937 key = afs_request_key(dvnode->volume->cell); 978 key = afs_request_key(dvnode->volume->cell);
938 if (IS_ERR(key)) { 979 if (IS_ERR(key)) {
939 ret = PTR_ERR(key); 980 ret = PTR_ERR(key);
940 goto error; 981 goto error;
941 } 982 }
942 983
943 mode |= S_IFREG; 984 ret = -ERESTARTSYS;
944 ret = afs_vnode_create(dvnode, key, dentry->d_name.name, 985 if (afs_begin_vnode_operation(&fc, dvnode, key)) {
945 mode, &fid, &status, &cb, &server); 986 while (afs_select_fileserver(&fc)) {
946 if (ret < 0) 987 fc.cb_break = dvnode->cb_break + dvnode->cb_s_break;
947 goto create_error; 988 afs_fs_create(&fc, dentry->d_name.name, mode,
989 &newfid, &newstatus, &newcb);
990 }
948 991
949 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb); 992 afs_check_for_remote_deletion(&fc, fc.vnode);
950 if (IS_ERR(inode)) { 993 afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
951 /* ENOMEM at a really inconvenient time - just abandon the new 994 afs_vnode_new_inode(&fc, dentry, &newfid, &newstatus, &newcb);
952 * directory on the server */ 995 ret = afs_end_vnode_operation(&fc);
953 ret = PTR_ERR(inode); 996 if (ret < 0)
954 goto iget_error; 997 goto error_key;
955 } 998 }
956 999
957 /* apply the status report we've got for the new vnode */
958 vnode = AFS_FS_I(inode);
959 spin_lock(&vnode->lock);
960 vnode->update_cnt++;
961 spin_unlock(&vnode->lock);
962 afs_vnode_finalise_status_update(vnode, server);
963 afs_put_server(afs_i2net(dir), server);
964
965 d_instantiate(dentry, inode);
966 if (d_unhashed(dentry)) {
967 _debug("not hashed");
968 d_rehash(dentry);
969 }
970 key_put(key); 1000 key_put(key);
971 _leave(" = 0"); 1001 _leave(" = 0");
972 return 0; 1002 return 0;
973 1003
974iget_error: 1004error_key:
975 afs_put_server(afs_i2net(dir), server);
976create_error:
977 key_put(key); 1005 key_put(key);
978error: 1006error:
979 d_drop(dentry); 1007 d_drop(dentry);
@@ -987,6 +1015,7 @@ error:
987static int afs_link(struct dentry *from, struct inode *dir, 1015static int afs_link(struct dentry *from, struct inode *dir,
988 struct dentry *dentry) 1016 struct dentry *dentry)
989{ 1017{
1018 struct afs_fs_cursor fc;
990 struct afs_vnode *dvnode, *vnode; 1019 struct afs_vnode *dvnode, *vnode;
991 struct key *key; 1020 struct key *key;
992 int ret; 1021 int ret;
@@ -999,23 +1028,45 @@ static int afs_link(struct dentry *from, struct inode *dir,
999 dvnode->fid.vid, dvnode->fid.vnode, 1028 dvnode->fid.vid, dvnode->fid.vnode,
1000 dentry); 1029 dentry);
1001 1030
1031 ret = -ENAMETOOLONG;
1032 if (dentry->d_name.len >= AFSNAMEMAX)
1033 goto error;
1034
1002 key = afs_request_key(dvnode->volume->cell); 1035 key = afs_request_key(dvnode->volume->cell);
1003 if (IS_ERR(key)) { 1036 if (IS_ERR(key)) {
1004 ret = PTR_ERR(key); 1037 ret = PTR_ERR(key);
1005 goto error; 1038 goto error;
1006 } 1039 }
1007 1040
1008 ret = afs_vnode_link(dvnode, vnode, key, dentry->d_name.name); 1041 ret = -ERESTARTSYS;
1009 if (ret < 0) 1042 if (afs_begin_vnode_operation(&fc, dvnode, key)) {
1010 goto link_error; 1043 if (mutex_lock_interruptible_nested(&vnode->io_lock, 1) < 0) {
1044 afs_end_vnode_operation(&fc);
1045 return -ERESTARTSYS;
1046 }
1047
1048 while (afs_select_fileserver(&fc)) {
1049 fc.cb_break = dvnode->cb_break + dvnode->cb_s_break;
1050 fc.cb_break_2 = vnode->cb_break + vnode->cb_s_break;
1051 afs_fs_link(&fc, vnode, dentry->d_name.name);
1052 }
1053
1054 afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
1055 afs_vnode_commit_status(&fc, vnode, fc.cb_break_2);
1056 ihold(&vnode->vfs_inode);
1057 d_instantiate(dentry, &vnode->vfs_inode);
1058
1059 mutex_unlock(&vnode->io_lock);
1060 ret = afs_end_vnode_operation(&fc);
1061 if (ret < 0)
1062 goto error_key;
1063 }
1011 1064
1012 ihold(&vnode->vfs_inode);
1013 d_instantiate(dentry, &vnode->vfs_inode);
1014 key_put(key); 1065 key_put(key);
1015 _leave(" = 0"); 1066 _leave(" = 0");
1016 return 0; 1067 return 0;
1017 1068
1018link_error: 1069error_key:
1019 key_put(key); 1070 key_put(key);
1020error: 1071error:
1021 d_drop(dentry); 1072 d_drop(dentry);
@@ -1029,20 +1080,21 @@ error:
1029static int afs_symlink(struct inode *dir, struct dentry *dentry, 1080static int afs_symlink(struct inode *dir, struct dentry *dentry,
1030 const char *content) 1081 const char *content)
1031{ 1082{
1032 struct afs_file_status status; 1083 struct afs_fs_cursor fc;
1033 struct afs_server *server; 1084 struct afs_file_status newstatus;
1034 struct afs_vnode *dvnode, *vnode; 1085 struct afs_vnode *dvnode = AFS_FS_I(dir);
1035 struct afs_fid fid; 1086 struct afs_fid newfid;
1036 struct inode *inode;
1037 struct key *key; 1087 struct key *key;
1038 int ret; 1088 int ret;
1039 1089
1040 dvnode = AFS_FS_I(dir);
1041
1042 _enter("{%x:%u},{%pd},%s", 1090 _enter("{%x:%u},{%pd},%s",
1043 dvnode->fid.vid, dvnode->fid.vnode, dentry, 1091 dvnode->fid.vid, dvnode->fid.vnode, dentry,
1044 content); 1092 content);
1045 1093
1094 ret = -ENAMETOOLONG;
1095 if (dentry->d_name.len >= AFSNAMEMAX)
1096 goto error;
1097
1046 ret = -EINVAL; 1098 ret = -EINVAL;
1047 if (strlen(content) >= AFSPATHMAX) 1099 if (strlen(content) >= AFSPATHMAX)
1048 goto error; 1100 goto error;
@@ -1053,39 +1105,27 @@ static int afs_symlink(struct inode *dir, struct dentry *dentry,
1053 goto error; 1105 goto error;
1054 } 1106 }
1055 1107
1056 ret = afs_vnode_symlink(dvnode, key, dentry->d_name.name, content, 1108 ret = -ERESTARTSYS;
1057 &fid, &status, &server); 1109 if (afs_begin_vnode_operation(&fc, dvnode, key)) {
1058 if (ret < 0) 1110 while (afs_select_fileserver(&fc)) {
1059 goto create_error; 1111 fc.cb_break = dvnode->cb_break + dvnode->cb_s_break;
1112 afs_fs_symlink(&fc, dentry->d_name.name, content,
1113 &newfid, &newstatus);
1114 }
1060 1115
1061 inode = afs_iget(dir->i_sb, key, &fid, &status, NULL); 1116 afs_check_for_remote_deletion(&fc, fc.vnode);
1062 if (IS_ERR(inode)) { 1117 afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
1063 /* ENOMEM at a really inconvenient time - just abandon the new 1118 afs_vnode_new_inode(&fc, dentry, &newfid, &newstatus, NULL);
1064 * directory on the server */ 1119 ret = afs_end_vnode_operation(&fc);
1065 ret = PTR_ERR(inode); 1120 if (ret < 0)
1066 goto iget_error; 1121 goto error_key;
1067 } 1122 }
1068 1123
1069 /* apply the status report we've got for the new vnode */
1070 vnode = AFS_FS_I(inode);
1071 spin_lock(&vnode->lock);
1072 vnode->update_cnt++;
1073 spin_unlock(&vnode->lock);
1074 afs_vnode_finalise_status_update(vnode, server);
1075 afs_put_server(afs_i2net(dir), server);
1076
1077 d_instantiate(dentry, inode);
1078 if (d_unhashed(dentry)) {
1079 _debug("not hashed");
1080 d_rehash(dentry);
1081 }
1082 key_put(key); 1124 key_put(key);
1083 _leave(" = 0"); 1125 _leave(" = 0");
1084 return 0; 1126 return 0;
1085 1127
1086iget_error: 1128error_key:
1087 afs_put_server(afs_i2net(dir), server);
1088create_error:
1089 key_put(key); 1129 key_put(key);
1090error: 1130error:
1091 d_drop(dentry); 1131 d_drop(dentry);
@@ -1100,6 +1140,7 @@ static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1100 struct inode *new_dir, struct dentry *new_dentry, 1140 struct inode *new_dir, struct dentry *new_dentry,
1101 unsigned int flags) 1141 unsigned int flags)
1102{ 1142{
1143 struct afs_fs_cursor fc;
1103 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode; 1144 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
1104 struct key *key; 1145 struct key *key;
1105 int ret; 1146 int ret;
@@ -1123,16 +1164,35 @@ static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1123 goto error; 1164 goto error;
1124 } 1165 }
1125 1166
1126 ret = afs_vnode_rename(orig_dvnode, new_dvnode, key, 1167 ret = -ERESTARTSYS;
1127 old_dentry->d_name.name, 1168 if (afs_begin_vnode_operation(&fc, orig_dvnode, key)) {
1128 new_dentry->d_name.name); 1169 if (orig_dvnode != new_dvnode) {
1129 if (ret < 0) 1170 if (mutex_lock_interruptible_nested(&new_dvnode->io_lock, 1) < 0) {
1130 goto rename_error; 1171 afs_end_vnode_operation(&fc);
1172 return -ERESTARTSYS;
1173 }
1174 }
1175 while (afs_select_fileserver(&fc)) {
1176 fc.cb_break = orig_dvnode->cb_break + orig_dvnode->cb_s_break;
1177 fc.cb_break_2 = new_dvnode->cb_break + new_dvnode->cb_s_break;
1178 afs_fs_rename(&fc, old_dentry->d_name.name,
1179 new_dvnode, new_dentry->d_name.name);
1180 }
1181
1182 afs_vnode_commit_status(&fc, orig_dvnode, fc.cb_break);
1183 afs_vnode_commit_status(&fc, new_dvnode, fc.cb_break_2);
1184 if (orig_dvnode != new_dvnode)
1185 mutex_unlock(&new_dvnode->io_lock);
1186 ret = afs_end_vnode_operation(&fc);
1187 if (ret < 0)
1188 goto error_key;
1189 }
1190
1131 key_put(key); 1191 key_put(key);
1132 _leave(" = 0"); 1192 _leave(" = 0");
1133 return 0; 1193 return 0;
1134 1194
1135rename_error: 1195error_key:
1136 key_put(key); 1196 key_put(key);
1137error: 1197error:
1138 d_drop(new_dentry); 1198 d_drop(new_dentry);
diff --git a/fs/afs/file.c b/fs/afs/file.c
index 08f9f0c5dfac..1f26ac9f816d 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -138,6 +138,37 @@ static void afs_file_readpage_read_complete(struct page *page,
138#endif 138#endif
139 139
140/* 140/*
141 * Fetch file data from the volume.
142 */
143int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *desc)
144{
145 struct afs_fs_cursor fc;
146 int ret;
147
148 _enter("%s{%x:%u.%u},%x,,,",
149 vnode->volume->name,
150 vnode->fid.vid,
151 vnode->fid.vnode,
152 vnode->fid.unique,
153 key_serial(key));
154
155 ret = -ERESTARTSYS;
156 if (afs_begin_vnode_operation(&fc, vnode, key)) {
157 while (afs_select_fileserver(&fc)) {
158 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
159 afs_fs_fetch_data(&fc, desc);
160 }
161
162 afs_check_for_remote_deletion(&fc, fc.vnode);
163 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
164 ret = afs_end_vnode_operation(&fc);
165 }
166
167 _leave(" = %d", ret);
168 return ret;
169}
170
171/*
141 * read page from file, directory or symlink, given a key to use 172 * read page from file, directory or symlink, given a key to use
142 */ 173 */
143int afs_page_filler(void *data, struct page *page) 174int afs_page_filler(void *data, struct page *page)
@@ -199,7 +230,7 @@ int afs_page_filler(void *data, struct page *page)
199 230
200 /* read the contents of the file from the server into the 231 /* read the contents of the file from the server into the
201 * page */ 232 * page */
202 ret = afs_vnode_fetch_data(vnode, key, req); 233 ret = afs_fetch_data(vnode, key, req);
203 afs_put_read(req); 234 afs_put_read(req);
204 if (ret < 0) { 235 if (ret < 0) {
205 if (ret == -ENOENT) { 236 if (ret == -ENOENT) {
@@ -264,7 +295,7 @@ static int afs_readpage(struct file *file, struct page *page)
264 ret = afs_page_filler(key, page); 295 ret = afs_page_filler(key, page);
265 } else { 296 } else {
266 struct inode *inode = page->mapping->host; 297 struct inode *inode = page->mapping->host;
267 key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell); 298 key = afs_request_key(AFS_FS_S(inode->i_sb)->cell);
268 if (IS_ERR(key)) { 299 if (IS_ERR(key)) {
269 ret = PTR_ERR(key); 300 ret = PTR_ERR(key);
270 } else { 301 } else {
@@ -369,7 +400,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
369 return 0; 400 return 0;
370 } 401 }
371 402
372 ret = afs_vnode_fetch_data(vnode, key, req); 403 ret = afs_fetch_data(vnode, key, req);
373 if (ret < 0) 404 if (ret < 0)
374 goto error; 405 goto error;
375 406
diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index 2b31ea58c50c..77b0a4606efd 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -68,6 +68,100 @@ static void afs_grant_locks(struct afs_vnode *vnode, struct file_lock *fl)
68} 68}
69 69
70/* 70/*
71 * Get a lock on a file
72 */
73static int afs_set_lock(struct afs_vnode *vnode, struct key *key,
74 afs_lock_type_t type)
75{
76 struct afs_fs_cursor fc;
77 int ret;
78
79 _enter("%s{%x:%u.%u},%x,%u",
80 vnode->volume->name,
81 vnode->fid.vid,
82 vnode->fid.vnode,
83 vnode->fid.unique,
84 key_serial(key), type);
85
86 ret = -ERESTARTSYS;
87 if (afs_begin_vnode_operation(&fc, vnode, key)) {
88 while (afs_select_fileserver(&fc)) {
89 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
90 afs_fs_set_lock(&fc, type);
91 }
92
93 afs_check_for_remote_deletion(&fc, fc.vnode);
94 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
95 ret = afs_end_vnode_operation(&fc);
96 }
97
98 _leave(" = %d", ret);
99 return ret;
100}
101
102/*
103 * Extend a lock on a file
104 */
105static int afs_extend_lock(struct afs_vnode *vnode, struct key *key)
106{
107 struct afs_fs_cursor fc;
108 int ret;
109
110 _enter("%s{%x:%u.%u},%x",
111 vnode->volume->name,
112 vnode->fid.vid,
113 vnode->fid.vnode,
114 vnode->fid.unique,
115 key_serial(key));
116
117 ret = -ERESTARTSYS;
118 if (afs_begin_vnode_operation(&fc, vnode, key)) {
119 while (afs_select_current_fileserver(&fc)) {
120 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
121 afs_fs_extend_lock(&fc);
122 }
123
124 afs_check_for_remote_deletion(&fc, fc.vnode);
125 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
126 ret = afs_end_vnode_operation(&fc);
127 }
128
129 _leave(" = %d", ret);
130 return ret;
131}
132
133/*
134 * Release a lock on a file
135 */
136static int afs_release_lock(struct afs_vnode *vnode, struct key *key)
137{
138 struct afs_fs_cursor fc;
139 int ret;
140
141 _enter("%s{%x:%u.%u},%x",
142 vnode->volume->name,
143 vnode->fid.vid,
144 vnode->fid.vnode,
145 vnode->fid.unique,
146 key_serial(key));
147
148 ret = -ERESTARTSYS;
149 if (afs_begin_vnode_operation(&fc, vnode, key)) {
150 while (afs_select_current_fileserver(&fc)) {
151 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
152 afs_fs_release_lock(&fc);
153 }
154
155 afs_check_for_remote_deletion(&fc, fc.vnode);
156 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
157 ret = afs_end_vnode_operation(&fc);
158 }
159
160 _leave(" = %d", ret);
161 return ret;
162}
163
164/*
71 * do work for a lock, including: 165 * do work for a lock, including:
72 * - probing for a lock we're waiting on but didn't get immediately 166 * - probing for a lock we're waiting on but didn't get immediately
73 * - extending a lock that's close to timing out 167 * - extending a lock that's close to timing out
@@ -91,7 +185,7 @@ void afs_lock_work(struct work_struct *work)
91 185
92 /* attempt to release the server lock; if it fails, we just 186 /* attempt to release the server lock; if it fails, we just
93 * wait 5 minutes and it'll time out anyway */ 187 * wait 5 minutes and it'll time out anyway */
94 ret = afs_vnode_release_lock(vnode, vnode->unlock_key); 188 ret = afs_release_lock(vnode, vnode->unlock_key);
95 if (ret < 0) 189 if (ret < 0)
96 printk(KERN_WARNING "AFS:" 190 printk(KERN_WARNING "AFS:"
97 " Failed to release lock on {%x:%x} error %d\n", 191 " Failed to release lock on {%x:%x} error %d\n",
@@ -115,7 +209,7 @@ void afs_lock_work(struct work_struct *work)
115 key = key_get(fl->fl_file->private_data); 209 key = key_get(fl->fl_file->private_data);
116 spin_unlock(&vnode->lock); 210 spin_unlock(&vnode->lock);
117 211
118 ret = afs_vnode_extend_lock(vnode, key); 212 ret = afs_extend_lock(vnode, key);
119 clear_bit(AFS_VNODE_LOCKING, &vnode->flags); 213 clear_bit(AFS_VNODE_LOCKING, &vnode->flags);
120 key_put(key); 214 key_put(key);
121 switch (ret) { 215 switch (ret) {
@@ -151,7 +245,7 @@ void afs_lock_work(struct work_struct *work)
151 AFS_LOCK_READ : AFS_LOCK_WRITE; 245 AFS_LOCK_READ : AFS_LOCK_WRITE;
152 spin_unlock(&vnode->lock); 246 spin_unlock(&vnode->lock);
153 247
154 ret = afs_vnode_set_lock(vnode, key, type); 248 ret = afs_set_lock(vnode, key, type);
155 clear_bit(AFS_VNODE_LOCKING, &vnode->flags); 249 clear_bit(AFS_VNODE_LOCKING, &vnode->flags);
156 switch (ret) { 250 switch (ret) {
157 case -EWOULDBLOCK: 251 case -EWOULDBLOCK:
@@ -182,7 +276,7 @@ void afs_lock_work(struct work_struct *work)
182 clear_bit(AFS_VNODE_READLOCKED, &vnode->flags); 276 clear_bit(AFS_VNODE_READLOCKED, &vnode->flags);
183 clear_bit(AFS_VNODE_WRITELOCKED, &vnode->flags); 277 clear_bit(AFS_VNODE_WRITELOCKED, &vnode->flags);
184 spin_unlock(&vnode->lock); 278 spin_unlock(&vnode->lock);
185 afs_vnode_release_lock(vnode, key); 279 afs_release_lock(vnode, key);
186 if (!list_empty(&vnode->pending_locks)) 280 if (!list_empty(&vnode->pending_locks))
187 afs_lock_may_be_available(vnode); 281 afs_lock_may_be_available(vnode);
188 } 282 }
@@ -280,7 +374,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl)
280 set_bit(AFS_VNODE_LOCKING, &vnode->flags); 374 set_bit(AFS_VNODE_LOCKING, &vnode->flags);
281 spin_unlock(&vnode->lock); 375 spin_unlock(&vnode->lock);
282 376
283 ret = afs_vnode_set_lock(vnode, key, type); 377 ret = afs_set_lock(vnode, key, type);
284 clear_bit(AFS_VNODE_LOCKING, &vnode->flags); 378 clear_bit(AFS_VNODE_LOCKING, &vnode->flags);
285 switch (ret) { 379 switch (ret) {
286 case 0: 380 case 0:
@@ -383,7 +477,7 @@ given_lock:
383 /* again, make sure we've got a callback on this file and, again, make 477 /* again, make sure we've got a callback on this file and, again, make
384 * sure that our view of the data version is up to date (we ignore 478 * sure that our view of the data version is up to date (we ignore
385 * errors incurred here and deal with the consequences elsewhere) */ 479 * errors incurred here and deal with the consequences elsewhere) */
386 afs_vnode_fetch_status(vnode, key, false); 480 afs_validate(vnode, key);
387 481
388error: 482error:
389 spin_unlock(&inode->i_lock); 483 spin_unlock(&inode->i_lock);
@@ -455,7 +549,7 @@ static int afs_do_getlk(struct file *file, struct file_lock *fl)
455 posix_test_lock(file, fl); 549 posix_test_lock(file, fl);
456 if (fl->fl_type == F_UNLCK) { 550 if (fl->fl_type == F_UNLCK) {
457 /* no local locks; consult the server */ 551 /* no local locks; consult the server */
458 ret = afs_vnode_fetch_status(vnode, key, true); 552 ret = afs_fetch_status(vnode, key);
459 if (ret < 0) 553 if (ret < 0)
460 goto error; 554 goto error;
461 lock_count = vnode->status.lock_count; 555 lock_count = vnode->status.lock_count;
diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index 6614d0a78daa..72ff3679fa2a 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -22,9 +22,9 @@
22 */ 22 */
23static u8 afs_discard_buffer[64]; 23static u8 afs_discard_buffer[64];
24 24
25static inline void afs_use_fs_server(struct afs_call *call, struct afs_server *server) 25static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
26{ 26{
27 call->server = afs_get_server(server); 27 call->cbi = afs_get_cb_interest(cbi);
28} 28}
29 29
30/* 30/*
@@ -56,7 +56,8 @@ static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
56 kuid_t owner; 56 kuid_t owner;
57 kgid_t group; 57 kgid_t group;
58 58
59 write_seqlock(&vnode->cb_lock); 59 if (vnode)
60 write_seqlock(&vnode->cb_lock);
60 61
61#define EXTRACT(DST) \ 62#define EXTRACT(DST) \
62 do { \ 63 do { \
@@ -141,7 +142,8 @@ static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
141 status->data_version = data_version; 142 status->data_version = data_version;
142 } 143 }
143 144
144 write_sequnlock(&vnode->cb_lock); 145 if (vnode)
146 write_sequnlock(&vnode->cb_lock);
145} 147}
146 148
147/* 149/*
@@ -151,22 +153,29 @@ static void xdr_decode_AFSCallBack(struct afs_call *call,
151 struct afs_vnode *vnode, 153 struct afs_vnode *vnode,
152 const __be32 **_bp) 154 const __be32 **_bp)
153{ 155{
156 struct afs_cb_interest *old, *cbi = call->cbi;
154 const __be32 *bp = *_bp; 157 const __be32 *bp = *_bp;
155 u32 cb_expiry; 158 u32 cb_expiry;
156 159
157 write_seqlock(&vnode->cb_lock); 160 write_seqlock(&vnode->cb_lock);
158 161
159 if (call->cb_break == (vnode->cb_break + call->server->cb_s_break)) { 162 if (call->cb_break == (vnode->cb_break + cbi->server->cb_s_break)) {
160 vnode->cb_version = ntohl(*bp++); 163 vnode->cb_version = ntohl(*bp++);
161 cb_expiry = ntohl(*bp++); 164 cb_expiry = ntohl(*bp++);
162 vnode->cb_type = ntohl(*bp++); 165 vnode->cb_type = ntohl(*bp++);
163 vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds(); 166 vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds();
167 old = vnode->cb_interest;
168 if (old != call->cbi) {
169 vnode->cb_interest = cbi;
170 cbi = old;
171 }
164 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); 172 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
165 } else { 173 } else {
166 bp += 3; 174 bp += 3;
167 } 175 }
168 176
169 write_sequnlock(&vnode->cb_lock); 177 write_sequnlock(&vnode->cb_lock);
178 call->cbi = cbi;
170 *_bp = bp; 179 *_bp = bp;
171} 180}
172 181
@@ -297,24 +306,23 @@ static const struct afs_call_type afs_RXFSFetchStatus = {
297/* 306/*
298 * fetch the status information for a file 307 * fetch the status information for a file
299 */ 308 */
300int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, 309int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync)
301 struct key *key,
302 struct afs_vnode *vnode,
303 struct afs_volsync *volsync,
304 bool async)
305{ 310{
311 struct afs_vnode *vnode = fc->vnode;
306 struct afs_call *call; 312 struct afs_call *call;
307 struct afs_net *net = afs_v2net(vnode); 313 struct afs_net *net = afs_v2net(vnode);
308 __be32 *bp; 314 __be32 *bp;
309 315
310 _enter(",%x,{%x:%u},,", 316 _enter(",%x,{%x:%u},,",
311 key_serial(key), vnode->fid.vid, vnode->fid.vnode); 317 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
312 318
313 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4); 319 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
314 if (!call) 320 if (!call) {
321 fc->ac.error = -ENOMEM;
315 return -ENOMEM; 322 return -ENOMEM;
323 }
316 324
317 call->key = key; 325 call->key = fc->key;
318 call->reply[0] = vnode; 326 call->reply[0] = vnode;
319 call->reply[1] = volsync; 327 call->reply[1] = volsync;
320 328
@@ -325,9 +333,9 @@ int afs_fs_fetch_file_status(struct afs_fs_cursor *fc,
325 bp[2] = htonl(vnode->fid.vnode); 333 bp[2] = htonl(vnode->fid.vnode);
326 bp[3] = htonl(vnode->fid.unique); 334 bp[3] = htonl(vnode->fid.unique);
327 335
328 call->cb_break = vnode->cb_break + fc->server->cb_s_break; 336 call->cb_break = fc->cb_break;
329 afs_use_fs_server(call, fc->server); 337 afs_use_fs_server(call, fc->cbi);
330 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 338 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
331} 339}
332 340
333/* 341/*
@@ -502,12 +510,9 @@ static const struct afs_call_type afs_RXFSFetchData64 = {
502/* 510/*
503 * fetch data from a very large file 511 * fetch data from a very large file
504 */ 512 */
505static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, 513static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
506 struct key *key,
507 struct afs_vnode *vnode,
508 struct afs_read *req,
509 bool async)
510{ 514{
515 struct afs_vnode *vnode = fc->vnode;
511 struct afs_call *call; 516 struct afs_call *call;
512 struct afs_net *net = afs_v2net(vnode); 517 struct afs_net *net = afs_v2net(vnode);
513 __be32 *bp; 518 __be32 *bp;
@@ -518,7 +523,7 @@ static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
518 if (!call) 523 if (!call)
519 return -ENOMEM; 524 return -ENOMEM;
520 525
521 call->key = key; 526 call->key = fc->key;
522 call->reply[0] = vnode; 527 call->reply[0] = vnode;
523 call->reply[1] = NULL; /* volsync */ 528 call->reply[1] = NULL; /* volsync */
524 call->reply[2] = req; 529 call->reply[2] = req;
@@ -536,20 +541,17 @@ static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
536 bp[7] = htonl(lower_32_bits(req->len)); 541 bp[7] = htonl(lower_32_bits(req->len));
537 542
538 atomic_inc(&req->usage); 543 atomic_inc(&req->usage);
539 call->cb_break = vnode->cb_break + fc->server->cb_s_break; 544 call->cb_break = fc->cb_break;
540 afs_use_fs_server(call, fc->server); 545 afs_use_fs_server(call, fc->cbi);
541 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 546 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
542} 547}
543 548
544/* 549/*
545 * fetch data from a file 550 * fetch data from a file
546 */ 551 */
547int afs_fs_fetch_data(struct afs_fs_cursor *fc, 552int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
548 struct key *key,
549 struct afs_vnode *vnode,
550 struct afs_read *req,
551 bool async)
552{ 553{
554 struct afs_vnode *vnode = fc->vnode;
553 struct afs_call *call; 555 struct afs_call *call;
554 struct afs_net *net = afs_v2net(vnode); 556 struct afs_net *net = afs_v2net(vnode);
555 __be32 *bp; 557 __be32 *bp;
@@ -557,7 +559,7 @@ int afs_fs_fetch_data(struct afs_fs_cursor *fc,
557 if (upper_32_bits(req->pos) || 559 if (upper_32_bits(req->pos) ||
558 upper_32_bits(req->len) || 560 upper_32_bits(req->len) ||
559 upper_32_bits(req->pos + req->len)) 561 upper_32_bits(req->pos + req->len))
560 return afs_fs_fetch_data64(fc, key, vnode, req, async); 562 return afs_fs_fetch_data64(fc, req);
561 563
562 _enter(""); 564 _enter("");
563 565
@@ -565,7 +567,7 @@ int afs_fs_fetch_data(struct afs_fs_cursor *fc,
565 if (!call) 567 if (!call)
566 return -ENOMEM; 568 return -ENOMEM;
567 569
568 call->key = key; 570 call->key = fc->key;
569 call->reply[0] = vnode; 571 call->reply[0] = vnode;
570 call->reply[1] = NULL; /* volsync */ 572 call->reply[1] = NULL; /* volsync */
571 call->reply[2] = req; 573 call->reply[2] = req;
@@ -581,9 +583,9 @@ int afs_fs_fetch_data(struct afs_fs_cursor *fc,
581 bp[5] = htonl(lower_32_bits(req->len)); 583 bp[5] = htonl(lower_32_bits(req->len));
582 584
583 atomic_inc(&req->usage); 585 atomic_inc(&req->usage);
584 call->cb_break = vnode->cb_break + fc->server->cb_s_break; 586 call->cb_break = fc->cb_break;
585 afs_use_fs_server(call, fc->server); 587 afs_use_fs_server(call, fc->cbi);
586 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 588 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
587} 589}
588 590
589/* 591/*
@@ -626,15 +628,13 @@ static const struct afs_call_type afs_RXFSCreateXXXX = {
626 * create a file or make a directory 628 * create a file or make a directory
627 */ 629 */
628int afs_fs_create(struct afs_fs_cursor *fc, 630int afs_fs_create(struct afs_fs_cursor *fc,
629 struct key *key,
630 struct afs_vnode *vnode,
631 const char *name, 631 const char *name,
632 umode_t mode, 632 umode_t mode,
633 struct afs_fid *newfid, 633 struct afs_fid *newfid,
634 struct afs_file_status *newstatus, 634 struct afs_file_status *newstatus,
635 struct afs_callback *newcb, 635 struct afs_callback *newcb)
636 bool async)
637{ 636{
637 struct afs_vnode *vnode = fc->vnode;
638 struct afs_call *call; 638 struct afs_call *call;
639 struct afs_net *net = afs_v2net(vnode); 639 struct afs_net *net = afs_v2net(vnode);
640 size_t namesz, reqsz, padsz; 640 size_t namesz, reqsz, padsz;
@@ -651,7 +651,7 @@ int afs_fs_create(struct afs_fs_cursor *fc,
651 if (!call) 651 if (!call)
652 return -ENOMEM; 652 return -ENOMEM;
653 653
654 call->key = key; 654 call->key = fc->key;
655 call->reply[0] = vnode; 655 call->reply[0] = vnode;
656 call->reply[1] = newfid; 656 call->reply[1] = newfid;
657 call->reply[2] = newstatus; 657 call->reply[2] = newstatus;
@@ -677,8 +677,8 @@ int afs_fs_create(struct afs_fs_cursor *fc,
677 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */ 677 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
678 *bp++ = 0; /* segment size */ 678 *bp++ = 0; /* segment size */
679 679
680 afs_use_fs_server(call, fc->server); 680 afs_use_fs_server(call, fc->cbi);
681 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 681 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
682} 682}
683 683
684/* 684/*
@@ -717,13 +717,9 @@ static const struct afs_call_type afs_RXFSRemoveXXXX = {
717/* 717/*
718 * remove a file or directory 718 * remove a file or directory
719 */ 719 */
720int afs_fs_remove(struct afs_fs_cursor *fc, 720int afs_fs_remove(struct afs_fs_cursor *fc, const char *name, bool isdir)
721 struct key *key,
722 struct afs_vnode *vnode,
723 const char *name,
724 bool isdir,
725 bool async)
726{ 721{
722 struct afs_vnode *vnode = fc->vnode;
727 struct afs_call *call; 723 struct afs_call *call;
728 struct afs_net *net = afs_v2net(vnode); 724 struct afs_net *net = afs_v2net(vnode);
729 size_t namesz, reqsz, padsz; 725 size_t namesz, reqsz, padsz;
@@ -739,7 +735,7 @@ int afs_fs_remove(struct afs_fs_cursor *fc,
739 if (!call) 735 if (!call)
740 return -ENOMEM; 736 return -ENOMEM;
741 737
742 call->key = key; 738 call->key = fc->key;
743 call->reply[0] = vnode; 739 call->reply[0] = vnode;
744 740
745 /* marshall the parameters */ 741 /* marshall the parameters */
@@ -756,8 +752,8 @@ int afs_fs_remove(struct afs_fs_cursor *fc,
756 bp = (void *) bp + padsz; 752 bp = (void *) bp + padsz;
757 } 753 }
758 754
759 afs_use_fs_server(call, fc->server); 755 afs_use_fs_server(call, fc->cbi);
760 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 756 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
761} 757}
762 758
763/* 759/*
@@ -797,13 +793,10 @@ static const struct afs_call_type afs_RXFSLink = {
797/* 793/*
798 * make a hard link 794 * make a hard link
799 */ 795 */
800int afs_fs_link(struct afs_fs_cursor *fc, 796int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
801 struct key *key, 797 const char *name)
802 struct afs_vnode *dvnode,
803 struct afs_vnode *vnode,
804 const char *name,
805 bool async)
806{ 798{
799 struct afs_vnode *dvnode = fc->vnode;
807 struct afs_call *call; 800 struct afs_call *call;
808 struct afs_net *net = afs_v2net(vnode); 801 struct afs_net *net = afs_v2net(vnode);
809 size_t namesz, reqsz, padsz; 802 size_t namesz, reqsz, padsz;
@@ -819,7 +812,7 @@ int afs_fs_link(struct afs_fs_cursor *fc,
819 if (!call) 812 if (!call)
820 return -ENOMEM; 813 return -ENOMEM;
821 814
822 call->key = key; 815 call->key = fc->key;
823 call->reply[0] = dvnode; 816 call->reply[0] = dvnode;
824 call->reply[1] = vnode; 817 call->reply[1] = vnode;
825 818
@@ -840,8 +833,8 @@ int afs_fs_link(struct afs_fs_cursor *fc,
840 *bp++ = htonl(vnode->fid.vnode); 833 *bp++ = htonl(vnode->fid.vnode);
841 *bp++ = htonl(vnode->fid.unique); 834 *bp++ = htonl(vnode->fid.unique);
842 835
843 afs_use_fs_server(call, fc->server); 836 afs_use_fs_server(call, fc->cbi);
844 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 837 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
845} 838}
846 839
847/* 840/*
@@ -883,14 +876,12 @@ static const struct afs_call_type afs_RXFSSymlink = {
883 * create a symbolic link 876 * create a symbolic link
884 */ 877 */
885int afs_fs_symlink(struct afs_fs_cursor *fc, 878int afs_fs_symlink(struct afs_fs_cursor *fc,
886 struct key *key,
887 struct afs_vnode *vnode,
888 const char *name, 879 const char *name,
889 const char *contents, 880 const char *contents,
890 struct afs_fid *newfid, 881 struct afs_fid *newfid,
891 struct afs_file_status *newstatus, 882 struct afs_file_status *newstatus)
892 bool async)
893{ 883{
884 struct afs_vnode *vnode = fc->vnode;
894 struct afs_call *call; 885 struct afs_call *call;
895 struct afs_net *net = afs_v2net(vnode); 886 struct afs_net *net = afs_v2net(vnode);
896 size_t namesz, reqsz, padsz, c_namesz, c_padsz; 887 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
@@ -911,7 +902,7 @@ int afs_fs_symlink(struct afs_fs_cursor *fc,
911 if (!call) 902 if (!call)
912 return -ENOMEM; 903 return -ENOMEM;
913 904
914 call->key = key; 905 call->key = fc->key;
915 call->reply[0] = vnode; 906 call->reply[0] = vnode;
916 call->reply[1] = newfid; 907 call->reply[1] = newfid;
917 call->reply[2] = newstatus; 908 call->reply[2] = newstatus;
@@ -943,8 +934,8 @@ int afs_fs_symlink(struct afs_fs_cursor *fc,
943 *bp++ = htonl(S_IRWXUGO); /* unix mode */ 934 *bp++ = htonl(S_IRWXUGO); /* unix mode */
944 *bp++ = 0; /* segment size */ 935 *bp++ = 0; /* segment size */
945 936
946 afs_use_fs_server(call, fc->server); 937 afs_use_fs_server(call, fc->cbi);
947 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 938 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
948} 939}
949 940
950/* 941/*
@@ -987,13 +978,11 @@ static const struct afs_call_type afs_RXFSRename = {
987 * create a symbolic link 978 * create a symbolic link
988 */ 979 */
989int afs_fs_rename(struct afs_fs_cursor *fc, 980int afs_fs_rename(struct afs_fs_cursor *fc,
990 struct key *key,
991 struct afs_vnode *orig_dvnode,
992 const char *orig_name, 981 const char *orig_name,
993 struct afs_vnode *new_dvnode, 982 struct afs_vnode *new_dvnode,
994 const char *new_name, 983 const char *new_name)
995 bool async)
996{ 984{
985 struct afs_vnode *orig_dvnode = fc->vnode;
997 struct afs_call *call; 986 struct afs_call *call;
998 struct afs_net *net = afs_v2net(orig_dvnode); 987 struct afs_net *net = afs_v2net(orig_dvnode);
999 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz; 988 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
@@ -1016,7 +1005,7 @@ int afs_fs_rename(struct afs_fs_cursor *fc,
1016 if (!call) 1005 if (!call)
1017 return -ENOMEM; 1006 return -ENOMEM;
1018 1007
1019 call->key = key; 1008 call->key = fc->key;
1020 call->reply[0] = orig_dvnode; 1009 call->reply[0] = orig_dvnode;
1021 call->reply[1] = new_dvnode; 1010 call->reply[1] = new_dvnode;
1022 1011
@@ -1045,8 +1034,8 @@ int afs_fs_rename(struct afs_fs_cursor *fc,
1045 bp = (void *) bp + n_padsz; 1034 bp = (void *) bp + n_padsz;
1046 } 1035 }
1047 1036
1048 afs_use_fs_server(call, fc->server); 1037 afs_use_fs_server(call, fc->cbi);
1049 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1038 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1050} 1039}
1051 1040
1052/* 1041/*
@@ -1098,8 +1087,7 @@ static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1098 struct afs_writeback *wb, 1087 struct afs_writeback *wb,
1099 pgoff_t first, pgoff_t last, 1088 pgoff_t first, pgoff_t last,
1100 unsigned offset, unsigned to, 1089 unsigned offset, unsigned to,
1101 loff_t size, loff_t pos, loff_t i_size, 1090 loff_t size, loff_t pos, loff_t i_size)
1102 bool async)
1103{ 1091{
1104 struct afs_vnode *vnode = wb->vnode; 1092 struct afs_vnode *vnode = wb->vnode;
1105 struct afs_call *call; 1093 struct afs_call *call;
@@ -1147,8 +1135,7 @@ static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1147 *bp++ = htonl(i_size >> 32); 1135 *bp++ = htonl(i_size >> 32);
1148 *bp++ = htonl((u32) i_size); 1136 *bp++ = htonl((u32) i_size);
1149 1137
1150 afs_use_fs_server(call, fc->server); 1138 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1151 return afs_make_call(&fc->ac, call, GFP_NOFS, async);
1152} 1139}
1153 1140
1154/* 1141/*
@@ -1156,8 +1143,7 @@ static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1156 */ 1143 */
1157int afs_fs_store_data(struct afs_fs_cursor *fc, struct afs_writeback *wb, 1144int afs_fs_store_data(struct afs_fs_cursor *fc, struct afs_writeback *wb,
1158 pgoff_t first, pgoff_t last, 1145 pgoff_t first, pgoff_t last,
1159 unsigned offset, unsigned to, 1146 unsigned offset, unsigned to)
1160 bool async)
1161{ 1147{
1162 struct afs_vnode *vnode = wb->vnode; 1148 struct afs_vnode *vnode = wb->vnode;
1163 struct afs_call *call; 1149 struct afs_call *call;
@@ -1184,7 +1170,7 @@ int afs_fs_store_data(struct afs_fs_cursor *fc, struct afs_writeback *wb,
1184 1170
1185 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32) 1171 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1186 return afs_fs_store_data64(fc, wb, first, last, offset, to, 1172 return afs_fs_store_data64(fc, wb, first, last, offset, to,
1187 size, pos, i_size, async); 1173 size, pos, i_size);
1188 1174
1189 call = afs_alloc_flat_call(net, &afs_RXFSStoreData, 1175 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1190 (4 + 6 + 3) * 4, 1176 (4 + 6 + 3) * 4,
@@ -1221,8 +1207,8 @@ int afs_fs_store_data(struct afs_fs_cursor *fc, struct afs_writeback *wb,
1221 *bp++ = htonl(size); 1207 *bp++ = htonl(size);
1222 *bp++ = htonl(i_size); 1208 *bp++ = htonl(i_size);
1223 1209
1224 afs_use_fs_server(call, fc->server); 1210 afs_use_fs_server(call, fc->cbi);
1225 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1211 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1226} 1212}
1227 1213
1228/* 1214/*
@@ -1279,16 +1265,15 @@ static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1279 * set the attributes on a very large file, using FS.StoreData rather than 1265 * set the attributes on a very large file, using FS.StoreData rather than
1280 * FS.StoreStatus so as to alter the file size also 1266 * FS.StoreStatus so as to alter the file size also
1281 */ 1267 */
1282static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct key *key, 1268static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
1283 struct afs_vnode *vnode, struct iattr *attr,
1284 bool async)
1285{ 1269{
1270 struct afs_vnode *vnode = fc->vnode;
1286 struct afs_call *call; 1271 struct afs_call *call;
1287 struct afs_net *net = afs_v2net(vnode); 1272 struct afs_net *net = afs_v2net(vnode);
1288 __be32 *bp; 1273 __be32 *bp;
1289 1274
1290 _enter(",%x,{%x:%u},,", 1275 _enter(",%x,{%x:%u},,",
1291 key_serial(key), vnode->fid.vid, vnode->fid.vnode); 1276 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1292 1277
1293 ASSERT(attr->ia_valid & ATTR_SIZE); 1278 ASSERT(attr->ia_valid & ATTR_SIZE);
1294 1279
@@ -1298,7 +1283,7 @@ static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct key *key,
1298 if (!call) 1283 if (!call)
1299 return -ENOMEM; 1284 return -ENOMEM;
1300 1285
1301 call->key = key; 1286 call->key = fc->key;
1302 call->reply[0] = vnode; 1287 call->reply[0] = vnode;
1303 call->store_version = vnode->status.data_version + 1; 1288 call->store_version = vnode->status.data_version + 1;
1304 call->operation_ID = FSSTOREDATA; 1289 call->operation_ID = FSSTOREDATA;
@@ -1319,28 +1304,27 @@ static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct key *key,
1319 *bp++ = htonl(attr->ia_size >> 32); /* new file length */ 1304 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1320 *bp++ = htonl((u32) attr->ia_size); 1305 *bp++ = htonl((u32) attr->ia_size);
1321 1306
1322 afs_use_fs_server(call, fc->server); 1307 afs_use_fs_server(call, fc->cbi);
1323 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1308 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1324} 1309}
1325 1310
1326/* 1311/*
1327 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus 1312 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1328 * so as to alter the file size also 1313 * so as to alter the file size also
1329 */ 1314 */
1330static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct key *key, 1315static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1331 struct afs_vnode *vnode, struct iattr *attr,
1332 bool async)
1333{ 1316{
1317 struct afs_vnode *vnode = fc->vnode;
1334 struct afs_call *call; 1318 struct afs_call *call;
1335 struct afs_net *net = afs_v2net(vnode); 1319 struct afs_net *net = afs_v2net(vnode);
1336 __be32 *bp; 1320 __be32 *bp;
1337 1321
1338 _enter(",%x,{%x:%u},,", 1322 _enter(",%x,{%x:%u},,",
1339 key_serial(key), vnode->fid.vid, vnode->fid.vnode); 1323 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1340 1324
1341 ASSERT(attr->ia_valid & ATTR_SIZE); 1325 ASSERT(attr->ia_valid & ATTR_SIZE);
1342 if (attr->ia_size >> 32) 1326 if (attr->ia_size >> 32)
1343 return afs_fs_setattr_size64(fc, key, vnode, attr, async); 1327 return afs_fs_setattr_size64(fc, attr);
1344 1328
1345 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status, 1329 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1346 (4 + 6 + 3) * 4, 1330 (4 + 6 + 3) * 4,
@@ -1348,7 +1332,7 @@ static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct key *key,
1348 if (!call) 1332 if (!call)
1349 return -ENOMEM; 1333 return -ENOMEM;
1350 1334
1351 call->key = key; 1335 call->key = fc->key;
1352 call->reply[0] = vnode; 1336 call->reply[0] = vnode;
1353 call->store_version = vnode->status.data_version + 1; 1337 call->store_version = vnode->status.data_version + 1;
1354 call->operation_ID = FSSTOREDATA; 1338 call->operation_ID = FSSTOREDATA;
@@ -1366,27 +1350,26 @@ static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct key *key,
1366 *bp++ = 0; /* size of write */ 1350 *bp++ = 0; /* size of write */
1367 *bp++ = htonl(attr->ia_size); /* new file length */ 1351 *bp++ = htonl(attr->ia_size); /* new file length */
1368 1352
1369 afs_use_fs_server(call, fc->server); 1353 afs_use_fs_server(call, fc->cbi);
1370 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1354 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1371} 1355}
1372 1356
1373/* 1357/*
1374 * set the attributes on a file, using FS.StoreData if there's a change in file 1358 * set the attributes on a file, using FS.StoreData if there's a change in file
1375 * size, and FS.StoreStatus otherwise 1359 * size, and FS.StoreStatus otherwise
1376 */ 1360 */
1377int afs_fs_setattr(struct afs_fs_cursor *fc, struct key *key, 1361int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1378 struct afs_vnode *vnode, struct iattr *attr,
1379 bool async)
1380{ 1362{
1363 struct afs_vnode *vnode = fc->vnode;
1381 struct afs_call *call; 1364 struct afs_call *call;
1382 struct afs_net *net = afs_v2net(vnode); 1365 struct afs_net *net = afs_v2net(vnode);
1383 __be32 *bp; 1366 __be32 *bp;
1384 1367
1385 if (attr->ia_valid & ATTR_SIZE) 1368 if (attr->ia_valid & ATTR_SIZE)
1386 return afs_fs_setattr_size(fc, key, vnode, attr, async); 1369 return afs_fs_setattr_size(fc, attr);
1387 1370
1388 _enter(",%x,{%x:%u},,", 1371 _enter(",%x,{%x:%u},,",
1389 key_serial(key), vnode->fid.vid, vnode->fid.vnode); 1372 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1390 1373
1391 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus, 1374 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1392 (4 + 6) * 4, 1375 (4 + 6) * 4,
@@ -1394,7 +1377,7 @@ int afs_fs_setattr(struct afs_fs_cursor *fc, struct key *key,
1394 if (!call) 1377 if (!call)
1395 return -ENOMEM; 1378 return -ENOMEM;
1396 1379
1397 call->key = key; 1380 call->key = fc->key;
1398 call->reply[0] = vnode; 1381 call->reply[0] = vnode;
1399 call->operation_ID = FSSTORESTATUS; 1382 call->operation_ID = FSSTORESTATUS;
1400 1383
@@ -1407,8 +1390,8 @@ int afs_fs_setattr(struct afs_fs_cursor *fc, struct key *key,
1407 1390
1408 xdr_encode_AFS_StoreStatus(&bp, attr); 1391 xdr_encode_AFS_StoreStatus(&bp, attr);
1409 1392
1410 afs_use_fs_server(call, fc->server); 1393 afs_use_fs_server(call, fc->cbi);
1411 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1394 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1412} 1395}
1413 1396
1414/* 1397/*
@@ -1606,11 +1589,9 @@ static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1606 * fetch the status of a volume 1589 * fetch the status of a volume
1607 */ 1590 */
1608int afs_fs_get_volume_status(struct afs_fs_cursor *fc, 1591int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1609 struct key *key, 1592 struct afs_volume_status *vs)
1610 struct afs_vnode *vnode,
1611 struct afs_volume_status *vs,
1612 bool async)
1613{ 1593{
1594 struct afs_vnode *vnode = fc->vnode;
1614 struct afs_call *call; 1595 struct afs_call *call;
1615 struct afs_net *net = afs_v2net(vnode); 1596 struct afs_net *net = afs_v2net(vnode);
1616 __be32 *bp; 1597 __be32 *bp;
@@ -1628,7 +1609,7 @@ int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1628 return -ENOMEM; 1609 return -ENOMEM;
1629 } 1610 }
1630 1611
1631 call->key = key; 1612 call->key = fc->key;
1632 call->reply[0] = vnode; 1613 call->reply[0] = vnode;
1633 call->reply[1] = vs; 1614 call->reply[1] = vs;
1634 call->reply[2] = tmpbuf; 1615 call->reply[2] = tmpbuf;
@@ -1638,8 +1619,8 @@ int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1638 bp[0] = htonl(FSGETVOLUMESTATUS); 1619 bp[0] = htonl(FSGETVOLUMESTATUS);
1639 bp[1] = htonl(vnode->fid.vid); 1620 bp[1] = htonl(vnode->fid.vid);
1640 1621
1641 afs_use_fs_server(call, fc->server); 1622 afs_use_fs_server(call, fc->cbi);
1642 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1623 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1643} 1624}
1644 1625
1645/* 1626/*
@@ -1692,14 +1673,11 @@ static const struct afs_call_type afs_RXFSReleaseLock = {
1692}; 1673};
1693 1674
1694/* 1675/*
1695 * get a lock on a file 1676 * Set a lock on a file
1696 */ 1677 */
1697int afs_fs_set_lock(struct afs_fs_cursor *fc, 1678int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1698 struct key *key,
1699 struct afs_vnode *vnode,
1700 afs_lock_type_t type,
1701 bool async)
1702{ 1679{
1680 struct afs_vnode *vnode = fc->vnode;
1703 struct afs_call *call; 1681 struct afs_call *call;
1704 struct afs_net *net = afs_v2net(vnode); 1682 struct afs_net *net = afs_v2net(vnode);
1705 __be32 *bp; 1683 __be32 *bp;
@@ -1710,7 +1688,7 @@ int afs_fs_set_lock(struct afs_fs_cursor *fc,
1710 if (!call) 1688 if (!call)
1711 return -ENOMEM; 1689 return -ENOMEM;
1712 1690
1713 call->key = key; 1691 call->key = fc->key;
1714 call->reply[0] = vnode; 1692 call->reply[0] = vnode;
1715 1693
1716 /* marshall the parameters */ 1694 /* marshall the parameters */
@@ -1721,18 +1699,16 @@ int afs_fs_set_lock(struct afs_fs_cursor *fc,
1721 *bp++ = htonl(vnode->fid.unique); 1699 *bp++ = htonl(vnode->fid.unique);
1722 *bp++ = htonl(type); 1700 *bp++ = htonl(type);
1723 1701
1724 afs_use_fs_server(call, fc->server); 1702 afs_use_fs_server(call, fc->cbi);
1725 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1703 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1726} 1704}
1727 1705
1728/* 1706/*
1729 * extend a lock on a file 1707 * extend a lock on a file
1730 */ 1708 */
1731int afs_fs_extend_lock(struct afs_fs_cursor *fc, 1709int afs_fs_extend_lock(struct afs_fs_cursor *fc)
1732 struct key *key,
1733 struct afs_vnode *vnode,
1734 bool async)
1735{ 1710{
1711 struct afs_vnode *vnode = fc->vnode;
1736 struct afs_call *call; 1712 struct afs_call *call;
1737 struct afs_net *net = afs_v2net(vnode); 1713 struct afs_net *net = afs_v2net(vnode);
1738 __be32 *bp; 1714 __be32 *bp;
@@ -1743,7 +1719,7 @@ int afs_fs_extend_lock(struct afs_fs_cursor *fc,
1743 if (!call) 1719 if (!call)
1744 return -ENOMEM; 1720 return -ENOMEM;
1745 1721
1746 call->key = key; 1722 call->key = fc->key;
1747 call->reply[0] = vnode; 1723 call->reply[0] = vnode;
1748 1724
1749 /* marshall the parameters */ 1725 /* marshall the parameters */
@@ -1753,18 +1729,16 @@ int afs_fs_extend_lock(struct afs_fs_cursor *fc,
1753 *bp++ = htonl(vnode->fid.vnode); 1729 *bp++ = htonl(vnode->fid.vnode);
1754 *bp++ = htonl(vnode->fid.unique); 1730 *bp++ = htonl(vnode->fid.unique);
1755 1731
1756 afs_use_fs_server(call, fc->server); 1732 afs_use_fs_server(call, fc->cbi);
1757 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1733 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1758} 1734}
1759 1735
1760/* 1736/*
1761 * release a lock on a file 1737 * release a lock on a file
1762 */ 1738 */
1763int afs_fs_release_lock(struct afs_fs_cursor *fc, 1739int afs_fs_release_lock(struct afs_fs_cursor *fc)
1764 struct key *key,
1765 struct afs_vnode *vnode,
1766 bool async)
1767{ 1740{
1741 struct afs_vnode *vnode = fc->vnode;
1768 struct afs_call *call; 1742 struct afs_call *call;
1769 struct afs_net *net = afs_v2net(vnode); 1743 struct afs_net *net = afs_v2net(vnode);
1770 __be32 *bp; 1744 __be32 *bp;
@@ -1775,7 +1749,7 @@ int afs_fs_release_lock(struct afs_fs_cursor *fc,
1775 if (!call) 1749 if (!call)
1776 return -ENOMEM; 1750 return -ENOMEM;
1777 1751
1778 call->key = key; 1752 call->key = fc->key;
1779 call->reply[0] = vnode; 1753 call->reply[0] = vnode;
1780 1754
1781 /* marshall the parameters */ 1755 /* marshall the parameters */
@@ -1785,8 +1759,8 @@ int afs_fs_release_lock(struct afs_fs_cursor *fc,
1785 *bp++ = htonl(vnode->fid.vnode); 1759 *bp++ = htonl(vnode->fid.vnode);
1786 *bp++ = htonl(vnode->fid.unique); 1760 *bp++ = htonl(vnode->fid.unique);
1787 1761
1788 afs_use_fs_server(call, fc->server); 1762 afs_use_fs_server(call, fc->cbi);
1789 return afs_make_call(&fc->ac, call, GFP_NOFS, async); 1763 return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1790} 1764}
1791 1765
1792/* 1766/*
@@ -1809,17 +1783,17 @@ static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1809/* 1783/*
1810 * Flush all the callbacks we have on a server. 1784 * Flush all the callbacks we have on a server.
1811 */ 1785 */
1812int afs_fs_give_up_all_callbacks(struct afs_server *server, 1786int afs_fs_give_up_all_callbacks(struct afs_net *net,
1787 struct afs_server *server,
1813 struct afs_addr_cursor *ac, 1788 struct afs_addr_cursor *ac,
1814 struct key *key, 1789 struct key *key)
1815 bool async)
1816{ 1790{
1817 struct afs_call *call; 1791 struct afs_call *call;
1818 __be32 *bp; 1792 __be32 *bp;
1819 1793
1820 _enter(""); 1794 _enter("");
1821 1795
1822 call = afs_alloc_flat_call(server->net, &afs_RXFSGiveUpAllCallBacks, 2 * 4, 0); 1796 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1823 if (!call) 1797 if (!call)
1824 return -ENOMEM; 1798 return -ENOMEM;
1825 1799
@@ -1830,5 +1804,96 @@ int afs_fs_give_up_all_callbacks(struct afs_server *server,
1830 *bp++ = htonl(FSGIVEUPALLCALLBACKS); 1804 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1831 1805
1832 /* Can't take a ref on server */ 1806 /* Can't take a ref on server */
1833 return afs_make_call(ac, call, GFP_NOFS, async); 1807 return afs_make_call(ac, call, GFP_NOFS, false);
1808}
1809
1810/*
1811 * Deliver reply data to an FS.GetCapabilities operation.
1812 */
1813static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1814{
1815 u32 count;
1816 int ret;
1817
1818 _enter("{%u,%zu/%u}", call->unmarshall, call->offset, call->count);
1819
1820again:
1821 switch (call->unmarshall) {
1822 case 0:
1823 call->offset = 0;
1824 call->unmarshall++;
1825
1826 /* Extract the capabilities word count */
1827 case 1:
1828 ret = afs_extract_data(call, &call->tmp,
1829 1 * sizeof(__be32),
1830 true);
1831 if (ret < 0)
1832 return ret;
1833
1834 count = ntohl(call->tmp);
1835
1836 call->count = count;
1837 call->count2 = count;
1838 call->offset = 0;
1839 call->unmarshall++;
1840
1841 /* Extract capabilities words */
1842 case 2:
1843 count = min(call->count, 16U);
1844 ret = afs_extract_data(call, call->buffer,
1845 count * sizeof(__be32),
1846 call->count > 16);
1847 if (ret < 0)
1848 return ret;
1849
1850 /* TODO: Examine capabilities */
1851
1852 call->count -= count;
1853 if (call->count > 0)
1854 goto again;
1855 call->offset = 0;
1856 call->unmarshall++;
1857 break;
1858 }
1859
1860 _leave(" = 0 [done]");
1861 return 0;
1862}
1863
1864/*
1865 * FS.GetCapabilities operation type
1866 */
1867static const struct afs_call_type afs_RXFSGetCapabilities = {
1868 .name = "FS.GetCapabilities",
1869 .deliver = afs_deliver_fs_get_capabilities,
1870 .destructor = afs_flat_call_destructor,
1871};
1872
1873/*
1874 * Probe a fileserver for the capabilities that it supports. This can
1875 * return up to 196 words.
1876 */
1877int afs_fs_get_capabilities(struct afs_net *net,
1878 struct afs_server *server,
1879 struct afs_addr_cursor *ac,
1880 struct key *key)
1881{
1882 struct afs_call *call;
1883 __be32 *bp;
1884
1885 _enter("");
1886
1887 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1888 if (!call)
1889 return -ENOMEM;
1890
1891 call->key = key;
1892
1893 /* marshall the parameters */
1894 bp = call->request;
1895 *bp++ = htonl(FSGETCAPABILITIES);
1896
1897 /* Can't take a ref on server */
1898 return afs_make_call(ac, call, GFP_NOFS, false);
1834} 1899}
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index ee86d5ad22d1..5a2f5854f349 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -102,6 +102,35 @@ static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)
102} 102}
103 103
104/* 104/*
105 * Fetch file status from the volume.
106 */
107int afs_fetch_status(struct afs_vnode *vnode, struct key *key)
108{
109 struct afs_fs_cursor fc;
110 int ret;
111
112 _enter("%s,{%x:%u.%u,S=%lx}",
113 vnode->volume->name,
114 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique,
115 vnode->flags);
116
117 ret = -ERESTARTSYS;
118 if (afs_begin_vnode_operation(&fc, vnode, key)) {
119 while (afs_select_fileserver(&fc)) {
120 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
121 afs_fs_fetch_file_status(&fc, NULL);
122 }
123
124 afs_check_for_remote_deletion(&fc, fc.vnode);
125 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
126 ret = afs_end_vnode_operation(&fc);
127 }
128
129 _leave(" = %d", ret);
130 return ret;
131}
132
133/*
105 * iget5() comparator 134 * iget5() comparator
106 */ 135 */
107int afs_iget5_test(struct inode *inode, void *opaque) 136int afs_iget5_test(struct inode *inode, void *opaque)
@@ -205,7 +234,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
205 */ 234 */
206struct inode *afs_iget(struct super_block *sb, struct key *key, 235struct inode *afs_iget(struct super_block *sb, struct key *key,
207 struct afs_fid *fid, struct afs_file_status *status, 236 struct afs_fid *fid, struct afs_file_status *status,
208 struct afs_callback *cb) 237 struct afs_callback *cb, struct afs_cb_interest *cbi)
209{ 238{
210 struct afs_iget_data data = { .fid = *fid }; 239 struct afs_iget_data data = { .fid = *fid };
211 struct afs_super_info *as; 240 struct afs_super_info *as;
@@ -238,7 +267,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
238 267
239 if (!status) { 268 if (!status) {
240 /* it's a remotely extant inode */ 269 /* it's a remotely extant inode */
241 ret = afs_vnode_fetch_status(vnode, key, true); 270 ret = afs_fetch_status(vnode, key);
242 if (ret < 0) 271 if (ret < 0)
243 goto bad_inode; 272 goto bad_inode;
244 } else { 273 } else {
@@ -255,6 +284,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
255 vnode->cb_version = cb->version; 284 vnode->cb_version = cb->version;
256 vnode->cb_type = cb->type; 285 vnode->cb_type = cb->type;
257 vnode->cb_expires_at = cb->expiry; 286 vnode->cb_expires_at = cb->expiry;
287 vnode->cb_interest = afs_get_cb_interest(cbi);
258 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); 288 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
259 } 289 }
260 290
@@ -358,7 +388,7 @@ int afs_validate(struct afs_vnode *vnode, struct key *key)
358 * access */ 388 * access */
359 if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { 389 if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
360 _debug("not promised"); 390 _debug("not promised");
361 ret = afs_vnode_fetch_status(vnode, key, false); 391 ret = afs_fetch_status(vnode, key);
362 if (ret < 0) { 392 if (ret < 0) {
363 if (ret == -ENOENT) { 393 if (ret == -ENOENT) {
364 set_bit(AFS_VNODE_DELETED, &vnode->flags); 394 set_bit(AFS_VNODE_DELETED, &vnode->flags);
@@ -468,6 +498,7 @@ void afs_evict_inode(struct inode *inode)
468 */ 498 */
469int afs_setattr(struct dentry *dentry, struct iattr *attr) 499int afs_setattr(struct dentry *dentry, struct iattr *attr)
470{ 500{
501 struct afs_fs_cursor fc;
471 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); 502 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
472 struct key *key; 503 struct key *key;
473 int ret; 504 int ret;
@@ -498,7 +529,18 @@ int afs_setattr(struct dentry *dentry, struct iattr *attr)
498 } 529 }
499 } 530 }
500 531
501 ret = afs_vnode_setattr(vnode, key, attr); 532 ret = -ERESTARTSYS;
533 if (afs_begin_vnode_operation(&fc, vnode, key)) {
534 while (afs_select_fileserver(&fc)) {
535 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
536 afs_fs_setattr(&fc, attr);
537 }
538
539 afs_check_for_remote_deletion(&fc, fc.vnode);
540 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
541 ret = afs_end_vnode_operation(&fc);
542 }
543
502 if (!(attr->ia_valid & ATTR_FILE)) 544 if (!(attr->ia_valid & ATTR_FILE))
503 key_put(key); 545 key_put(key);
504 546
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index df52bf18a263..1fadf40551fd 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -32,16 +32,6 @@
32struct pagevec; 32struct pagevec;
33struct afs_call; 33struct afs_call;
34 34
35typedef enum {
36 AFS_VL_NEW, /* new, uninitialised record */
37 AFS_VL_CREATING, /* creating record */
38 AFS_VL_VALID, /* record is pending */
39 AFS_VL_NO_VOLUME, /* no such volume available */
40 AFS_VL_UPDATING, /* update in progress */
41 AFS_VL_VOLUME_DELETED, /* volume was deleted */
42 AFS_VL_UNCERTAIN, /* uncertain state (update failed) */
43} __attribute__((packed)) afs_vlocation_state_t;
44
45struct afs_mount_params { 35struct afs_mount_params {
46 bool rwpath; /* T if the parent should be considered R/W */ 36 bool rwpath; /* T if the parent should be considered R/W */
47 bool force; /* T to force cell type */ 37 bool force; /* T to force cell type */
@@ -76,8 +66,10 @@ enum afs_call_state {
76struct afs_addr_list { 66struct afs_addr_list {
77 struct rcu_head rcu; /* Must be first */ 67 struct rcu_head rcu; /* Must be first */
78 refcount_t usage; 68 refcount_t usage;
69 u32 version; /* Version */
79 unsigned short nr_addrs; 70 unsigned short nr_addrs;
80 unsigned short index; /* Address currently in use */ 71 unsigned short index; /* Address currently in use */
72 unsigned short nr_ipv4; /* Number of IPv4 addresses */
81 struct sockaddr_rxrpc addrs[]; 73 struct sockaddr_rxrpc addrs[];
82}; 74};
83 75
@@ -93,7 +85,7 @@ struct afs_call {
93 struct key *key; /* security for this call */ 85 struct key *key; /* security for this call */
94 struct afs_net *net; /* The network namespace */ 86 struct afs_net *net; /* The network namespace */
95 struct afs_server *cm_server; /* Server affected by incoming CM call */ 87 struct afs_server *cm_server; /* Server affected by incoming CM call */
96 struct afs_server *server; /* Server used by client call */ 88 struct afs_cb_interest *cbi; /* Callback interest for server used */
97 void *request; /* request data (first part) */ 89 void *request; /* request data (first part) */
98 struct address_space *mapping; /* page set */ 90 struct address_space *mapping; /* page set */
99 struct afs_writeback *wb; /* writeback being performed */ 91 struct afs_writeback *wb; /* writeback being performed */
@@ -192,7 +184,6 @@ struct afs_super_info {
192 struct afs_net *net; /* Network namespace */ 184 struct afs_net *net; /* Network namespace */
193 struct afs_cell *cell; /* The cell in which the volume resides */ 185 struct afs_cell *cell; /* The cell in which the volume resides */
194 struct afs_volume *volume; /* volume record */ 186 struct afs_volume *volume; /* volume record */
195 char rwparent; /* T if parent is R/W AFS volume */
196}; 187};
197 188
198static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) 189static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
@@ -228,26 +219,26 @@ struct afs_net {
228 spinlock_t proc_cells_lock; 219 spinlock_t proc_cells_lock;
229 struct list_head proc_cells; 220 struct list_head proc_cells;
230 221
231 /* Volume location database */ 222 /* Known servers. Theoretically each fileserver can only be in one
232 struct list_head vl_updates; /* VL records in need-update order */ 223 * cell, but in practice, people create aliases and subsets and there's
233 struct list_head vl_graveyard; /* Inactive VL records */ 224 * no easy way to distinguish them.
234 struct delayed_work vl_reaper; 225 */
235 struct delayed_work vl_updater; 226 seqlock_t fs_lock; /* For fs_servers */
236 spinlock_t vl_updates_lock; 227 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
237 spinlock_t vl_graveyard_lock; 228 struct list_head fs_updates; /* afs_server (by update_at) */
229 struct hlist_head fs_proc; /* procfs servers list */
238 230
239 /* File locking renewal management */ 231 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
240 struct mutex lock_manager_mutex; 232 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
233 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
241 234
242 /* Server database */ 235 struct work_struct fs_manager;
243 struct rb_root servers; /* Active servers */ 236 struct timer_list fs_timer;
244 rwlock_t servers_lock;
245 struct list_head server_graveyard; /* Inactive server LRU list */
246 spinlock_t server_graveyard_lock;
247 struct timer_list server_timer;
248 struct work_struct server_reaper;
249 atomic_t servers_outstanding; 237 atomic_t servers_outstanding;
250 238
239 /* File locking renewal management */
240 struct mutex lock_manager_mutex;
241
251 /* Misc */ 242 /* Misc */
252 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */ 243 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
253}; 244};
@@ -264,7 +255,21 @@ enum afs_cell_state {
264}; 255};
265 256
266/* 257/*
267 * AFS cell record 258 * AFS cell record.
259 *
260 * This is a tricky concept to get right as it is possible to create aliases
261 * simply by pointing AFSDB/SRV records for two names at the same set of VL
262 * servers; it is also possible to do things like setting up two sets of VL
263 * servers, one of which provides a superset of the volumes provided by the
264 * other (for internal/external division, for example).
265 *
266 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
267 * servers and (b) a cell's name is used by the client to select the key to use
268 * for authentication and encryption. The cell name is not typically used in
269 * the protocol.
270 *
271 * There is no easy way to determine if two cells are aliases or one is a
272 * subset of another.
268 */ 273 */
269struct afs_cell { 274struct afs_cell {
270 union { 275 union {
@@ -278,14 +283,6 @@ struct afs_cell {
278#ifdef CONFIG_AFS_FSCACHE 283#ifdef CONFIG_AFS_FSCACHE
279 struct fscache_cookie *cache; /* caching cookie */ 284 struct fscache_cookie *cache; /* caching cookie */
280#endif 285#endif
281
282 /* server record management */
283 rwlock_t servers_lock; /* active server list lock */
284 struct list_head servers; /* active server list */
285
286 /* volume location record management */
287 struct rw_semaphore vl_sem; /* volume management serialisation semaphore */
288 struct list_head vl_list; /* cell's active VL record list */
289 time64_t dns_expiry; /* Time AFSDB/SRV record expires */ 286 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
290 time64_t last_inactive; /* Time of last drop of usage count */ 287 time64_t last_inactive; /* Time of last drop of usage count */
291 atomic_t usage; 288 atomic_t usage;
@@ -298,9 +295,11 @@ struct afs_cell {
298 enum afs_cell_state state; 295 enum afs_cell_state state;
299 short error; 296 short error;
300 297
301 spinlock_t vl_lock; /* vl_list lock */ 298 /* Active fileserver interaction state. */
299 struct list_head proc_volumes; /* procfs volume list */
300 rwlock_t proc_lock;
302 301
303 /* VLDB server list. */ 302 /* VL server list. */
304 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */ 303 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
305 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */ 304 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
306 u8 name_len; /* Length of name */ 305 u8 name_len; /* Length of name */
@@ -308,65 +307,62 @@ struct afs_cell {
308}; 307};
309 308
310/* 309/*
311 * entry in the cached volume location catalogue 310 * Cached VLDB entry.
311 *
312 * This is pointed to by cell->vldb_entries, indexed by name.
312 */ 313 */
313struct afs_cache_vlocation { 314struct afs_vldb_entry {
314 /* volume name (lowercase, padded with NULs) */ 315 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
315 uint8_t name[AFS_MAXVOLNAME + 1];
316 316
317 uint8_t nservers; /* number of entries used in servers[] */ 317 unsigned long flags;
318 uint8_t vidmask; /* voltype mask for vid[] */ 318#define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
319 uint8_t srvtmask[8]; /* voltype masks for servers[] */ 319#define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
320#define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
321#define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
322#define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
323
324 uuid_t fs_server[AFS_NMAXNSERVERS];
325 u8 fs_mask[AFS_NMAXNSERVERS];
320#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */ 326#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
321#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */ 327#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
322#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */ 328#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
323 329 short error;
324 afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */ 330 u8 nr_servers; /* Number of server records */
325 struct sockaddr_rxrpc servers[8]; /* fileserver addresses */ 331 u8 name_len;
326 time_t rtime; /* last retrieval time */ 332 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
327};
328
329/*
330 * AFS volume location record
331 */
332struct afs_vlocation {
333 atomic_t usage;
334 time64_t time_of_death; /* time at which put reduced usage to 0 */
335 struct list_head link; /* link in cell volume location list */
336 struct list_head grave; /* link in master graveyard list */
337 struct list_head update; /* link in master update list */
338 struct afs_cell *cell; /* cell to which volume belongs */
339 struct afs_cache_vlocation vldb; /* volume information DB record */
340 struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
341 wait_queue_head_t waitq; /* status change waitqueue */
342 time64_t update_at; /* time at which record should be updated */
343 spinlock_t lock; /* access lock */
344 afs_vlocation_state_t state; /* volume location state */
345 unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */
346 unsigned short upd_busy_cnt; /* EBUSY count during update */
347 bool valid; /* T if valid */
348}; 333};
349 334
350/* 335/*
351 * AFS fileserver record 336 * Record of fileserver with which we're actively communicating.
352 */ 337 */
353struct afs_server { 338struct afs_server {
354 atomic_t usage; 339 struct rcu_head rcu;
355 time64_t time_of_death; /* time at which put reduced usage to 0 */ 340 union {
356 struct afs_addr_list __rcu *addrs; /* List of addresses for this server */ 341 uuid_t uuid; /* Server ID */
357 struct afs_net *net; /* Network namespace in which the server resides */ 342 struct afs_uuid _uuid;
358 struct afs_cell *cell; /* cell in which server resides */ 343 };
359 struct list_head link; /* link in cell's server list */ 344
360 struct list_head grave; /* link in master graveyard list */ 345 struct afs_addr_list __rcu *addresses;
361 346 struct rb_node uuid_rb; /* Link in net->servers */
362 struct rb_node master_rb; /* link in master by-addr tree */ 347 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
363 struct rw_semaphore sem; /* access lock */ 348 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
349 struct hlist_node proc_link; /* Link in net->fs_proc */
350 struct afs_server *gc_next; /* Next server in manager's list */
351 time64_t put_time; /* Time at which last put */
352 time64_t update_at; /* Time at which to next update the record */
364 unsigned long flags; 353 unsigned long flags;
365#define AFS_SERVER_NEW 0 /* New server, don't inc cb_s_break */ 354#define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
355#define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
356#define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
357#define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
358#define AFS_SERVER_FL_UPDATING 4
359#define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
360#define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
361 atomic_t usage;
362 u32 addr_version; /* Address list version */
366 363
367 /* file service access */ 364 /* file service access */
368 int fs_state; /* 0 or reason FS currently marked dead (-errno) */ 365 rwlock_t fs_lock; /* access lock */
369 spinlock_t fs_lock; /* access lock */
370 366
371 /* callback promise management */ 367 /* callback promise management */
372 struct list_head cb_interests; /* List of superblocks using this server */ 368 struct list_head cb_interests; /* List of superblocks using this server */
@@ -386,32 +382,50 @@ struct afs_cb_interest {
386}; 382};
387 383
388/* 384/*
389 * AFS volume access record 385 * Replaceable server list.
386 */
387struct afs_server_entry {
388 struct afs_server *server;
389 struct afs_cb_interest *cb_interest;
390};
391
392struct afs_server_list {
393 refcount_t usage;
394 unsigned short nr_servers;
395 unsigned short index; /* Server currently in use */
396 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
397 unsigned int seq; /* Set to ->servers_seq when installed */
398 struct afs_server_entry servers[];
399};
400
401/*
402 * Live AFS volume management.
390 */ 403 */
391struct afs_volume { 404struct afs_volume {
405 afs_volid_t vid; /* volume ID */
392 atomic_t usage; 406 atomic_t usage;
393 struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */ 407 time64_t update_at; /* Time at which to next update */
394 struct afs_vlocation *vlocation; /* volume location */ 408 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
409 struct list_head proc_link; /* Link in cell->vl_proc */
410 unsigned long flags;
411#define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
412#define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
413#define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
414#define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
415#define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
416#define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
395#ifdef CONFIG_AFS_FSCACHE 417#ifdef CONFIG_AFS_FSCACHE
396 struct fscache_cookie *cache; /* caching cookie */ 418 struct fscache_cookie *cache; /* caching cookie */
397#endif 419#endif
398 afs_volid_t vid; /* volume ID */ 420 struct afs_server_list *servers; /* List of servers on which volume resides */
421 rwlock_t servers_lock; /* Lock for ->servers */
422 unsigned int servers_seq; /* Incremented each time ->servers changes */
423
399 afs_voltype_t type; /* type of volume */ 424 afs_voltype_t type; /* type of volume */
425 short error;
400 char type_force; /* force volume type (suppress R/O -> R/W) */ 426 char type_force; /* force volume type (suppress R/O -> R/W) */
401 unsigned short nservers; /* number of server slots filled */ 427 u8 name_len;
402 unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */ 428 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
403 struct afs_server *servers[8]; /* servers on which volume resides (ordered) */
404 struct afs_cb_interest *cb_interests[8]; /* Interests on servers for callbacks */
405 struct rw_semaphore server_sem; /* lock for accessing current server */
406};
407
408/*
409 * vnode catalogue entry
410 */
411struct afs_cache_vnode {
412 afs_vnodeid_t vnode_id; /* vnode ID */
413 unsigned vnode_unique; /* vnode ID uniquifier */
414 afs_dataversion_t data_version; /* data version */
415}; 429};
416 430
417/* 431/*
@@ -427,10 +441,8 @@ struct afs_vnode {
427 struct fscache_cookie *cache; /* caching cookie */ 441 struct fscache_cookie *cache; /* caching cookie */
428#endif 442#endif
429 struct afs_permits *permit_cache; /* cache of permits so far obtained */ 443 struct afs_permits *permit_cache; /* cache of permits so far obtained */
444 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
430 struct mutex validate_lock; /* lock for validating this vnode */ 445 struct mutex validate_lock; /* lock for validating this vnode */
431 wait_queue_head_t update_waitq; /* status fetch waitqueue */
432 int update_cnt; /* number of outstanding ops that will update the
433 * status */
434 spinlock_t writeback_lock; /* lock for writebacks */ 446 spinlock_t writeback_lock; /* lock for writebacks */
435 spinlock_t lock; /* waitqueue/flags lock */ 447 spinlock_t lock; /* waitqueue/flags lock */
436 unsigned long flags; 448 unsigned long flags;
@@ -501,6 +513,7 @@ struct afs_interface {
501struct afs_addr_cursor { 513struct afs_addr_cursor {
502 struct afs_addr_list *alist; /* Current address list (pins ref) */ 514 struct afs_addr_list *alist; /* Current address list (pins ref) */
503 struct sockaddr_rxrpc *addr; 515 struct sockaddr_rxrpc *addr;
516 u32 abort_code;
504 unsigned short start; /* Starting point in alist->addrs[] */ 517 unsigned short start; /* Starting point in alist->addrs[] */
505 unsigned short index; /* Wrapping offset from start to current addr */ 518 unsigned short index; /* Wrapping offset from start to current addr */
506 short error; 519 short error;
@@ -513,7 +526,21 @@ struct afs_addr_cursor {
513 */ 526 */
514struct afs_fs_cursor { 527struct afs_fs_cursor {
515 struct afs_addr_cursor ac; 528 struct afs_addr_cursor ac;
516 struct afs_server *server; /* Current server (pins ref) */ 529 struct afs_vnode *vnode;
530 struct afs_server_list *server_list; /* Current server list (pins ref) */
531 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
532 struct key *key; /* Key for the server */
533 unsigned int cb_break; /* cb_break + cb_s_break before the call */
534 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
535 unsigned char start; /* Initial index in server list */
536 unsigned char index; /* Number of servers tried beyond start */
537 unsigned short flags;
538#define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
539#define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
540#define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
541#define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
542#define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
543#define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
517}; 544};
518 545
519/*****************************************************************************/ 546/*****************************************************************************/
@@ -537,6 +564,8 @@ extern bool afs_iterate_addresses(struct afs_addr_cursor *);
537extern int afs_end_cursor(struct afs_addr_cursor *); 564extern int afs_end_cursor(struct afs_addr_cursor *);
538extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *); 565extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
539 566
567extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32);
568
540/* 569/*
541 * cache.c 570 * cache.c
542 */ 571 */
@@ -558,10 +587,9 @@ extern void afs_init_callback_state(struct afs_server *);
558extern void afs_break_callback(struct afs_vnode *); 587extern void afs_break_callback(struct afs_vnode *);
559extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]); 588extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]);
560 589
561extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_cb_interest **, 590extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
562 struct afs_server *);
563extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *); 591extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
564extern void afs_clear_callback_interests(struct afs_net *, struct afs_volume *); 592extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
565 593
566static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi) 594static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
567{ 595{
@@ -603,6 +631,7 @@ extern const struct file_operations afs_file_operations;
603 631
604extern int afs_open(struct inode *, struct file *); 632extern int afs_open(struct inode *, struct file *);
605extern int afs_release(struct inode *, struct file *); 633extern int afs_release(struct inode *, struct file *);
634extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
606extern int afs_page_filler(void *, struct page *); 635extern int afs_page_filler(void *, struct page *);
607extern void afs_put_read(struct afs_read *); 636extern void afs_put_read(struct afs_read *);
608 637
@@ -619,51 +648,40 @@ extern int afs_flock(struct file *, int, struct file_lock *);
619/* 648/*
620 * fsclient.c 649 * fsclient.c
621 */ 650 */
622extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct key *, 651extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
623 struct afs_vnode *, struct afs_volsync *, 652extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
624 bool); 653extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
625extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *, bool); 654extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
626extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct key *, 655 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
627 struct afs_vnode *, struct afs_read *, bool); 656extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
628extern int afs_fs_create(struct afs_fs_cursor *, struct key *, 657extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
629 struct afs_vnode *, const char *, umode_t, 658extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
630 struct afs_fid *, struct afs_file_status *, 659 struct afs_fid *, struct afs_file_status *);
631 struct afs_callback *, bool); 660extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
632extern int afs_fs_remove(struct afs_fs_cursor *, struct key *, 661 struct afs_vnode *, const char *);
633 struct afs_vnode *, const char *, bool, bool);
634extern int afs_fs_link(struct afs_fs_cursor *, struct key *, struct afs_vnode *,
635 struct afs_vnode *, const char *, bool);
636extern int afs_fs_symlink(struct afs_fs_cursor *, struct key *,
637 struct afs_vnode *, const char *, const char *,
638 struct afs_fid *, struct afs_file_status *, bool);
639extern int afs_fs_rename(struct afs_fs_cursor *, struct key *,
640 struct afs_vnode *, const char *,
641 struct afs_vnode *, const char *, bool);
642extern int afs_fs_store_data(struct afs_fs_cursor *, struct afs_writeback *, 662extern int afs_fs_store_data(struct afs_fs_cursor *, struct afs_writeback *,
643 pgoff_t, pgoff_t, unsigned, unsigned, bool); 663 pgoff_t, pgoff_t, unsigned, unsigned);
644extern int afs_fs_setattr(struct afs_fs_cursor *, struct key *, 664extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
645 struct afs_vnode *, struct iattr *, bool); 665extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
646extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct key *, 666extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
647 struct afs_vnode *, 667extern int afs_fs_extend_lock(struct afs_fs_cursor *);
648 struct afs_volume_status *, bool); 668extern int afs_fs_release_lock(struct afs_fs_cursor *);
649extern int afs_fs_set_lock(struct afs_fs_cursor *, struct key *, 669extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
650 struct afs_vnode *, afs_lock_type_t, bool); 670 struct afs_addr_cursor *, struct key *);
651extern int afs_fs_extend_lock(struct afs_fs_cursor *, struct key *, 671extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
652 struct afs_vnode *, bool); 672 struct afs_addr_cursor *, struct key *);
653extern int afs_fs_release_lock(struct afs_fs_cursor *, struct key *,
654 struct afs_vnode *, bool);
655extern int afs_fs_give_up_all_callbacks(struct afs_server *, struct afs_addr_cursor *,
656 struct key *, bool);
657 673
658/* 674/*
659 * inode.c 675 * inode.c
660 */ 676 */
677extern int afs_fetch_status(struct afs_vnode *, struct key *);
661extern int afs_iget5_test(struct inode *, void *); 678extern int afs_iget5_test(struct inode *, void *);
662extern struct inode *afs_iget_autocell(struct inode *, const char *, int, 679extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
663 struct key *); 680 struct key *);
664extern struct inode *afs_iget(struct super_block *, struct key *, 681extern struct inode *afs_iget(struct super_block *, struct key *,
665 struct afs_fid *, struct afs_file_status *, 682 struct afs_fid *, struct afs_file_status *,
666 struct afs_callback *); 683 struct afs_callback *,
684 struct afs_cb_interest *);
667extern void afs_zap_data(struct afs_vnode *); 685extern void afs_zap_data(struct afs_vnode *);
668extern int afs_validate(struct afs_vnode *, struct key *); 686extern int afs_validate(struct afs_vnode *, struct key *);
669extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int); 687extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
@@ -734,6 +752,15 @@ extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
734extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *); 752extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
735 753
736/* 754/*
755 * rotate.c
756 */
757extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
758 struct key *);
759extern bool afs_select_fileserver(struct afs_fs_cursor *);
760extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
761extern int afs_end_vnode_operation(struct afs_fs_cursor *);
762
763/*
737 * rxrpc.c 764 * rxrpc.c
738 */ 765 */
739extern struct workqueue_struct *afs_async_calls; 766extern struct workqueue_struct *afs_async_calls;
@@ -779,104 +806,62 @@ static inline struct afs_server *afs_get_server(struct afs_server *server)
779 return server; 806 return server;
780} 807}
781 808
782extern void afs_server_timer(struct timer_list *);
783extern struct afs_server *afs_lookup_server(struct afs_cell *,
784 struct sockaddr_rxrpc *);
785extern struct afs_server *afs_find_server(struct afs_net *, 809extern struct afs_server *afs_find_server(struct afs_net *,
786 const struct sockaddr_rxrpc *); 810 const struct sockaddr_rxrpc *);
811extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
812extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
787extern void afs_put_server(struct afs_net *, struct afs_server *); 813extern void afs_put_server(struct afs_net *, struct afs_server *);
788extern void afs_reap_server(struct work_struct *); 814extern void afs_manage_servers(struct work_struct *);
815extern void afs_servers_timer(struct timer_list *);
789extern void __net_exit afs_purge_servers(struct afs_net *); 816extern void __net_exit afs_purge_servers(struct afs_net *);
817extern bool afs_probe_fileserver(struct afs_fs_cursor *);
818extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
790 819
791/* 820/*
792 * super.c 821 * server_list.c
793 */ 822 */
794extern int __init afs_fs_init(void); 823static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
795extern void __exit afs_fs_exit(void); 824{
825 refcount_inc(&slist->usage);
826 return slist;
827}
796 828
797/* 829extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
798 * vlclient.c 830extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
799 */ 831 struct afs_vldb_entry *,
800extern int afs_vl_get_entry_by_name(struct afs_net *, struct afs_addr_cursor *, 832 u8);
801 struct key *, const char *, 833extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
802 struct afs_cache_vlocation *, bool);
803extern int afs_vl_get_entry_by_id(struct afs_net *, struct afs_addr_cursor *,
804 struct key *, afs_volid_t, afs_voltype_t,
805 struct afs_cache_vlocation *, bool);
806 834
807/* 835/*
808 * vlocation.c 836 * super.c
809 */ 837 */
810extern struct workqueue_struct *afs_vlocation_update_worker; 838extern int __init afs_fs_init(void);
811 839extern void __exit afs_fs_exit(void);
812#define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
813
814extern struct afs_vlocation *afs_vlocation_lookup(struct afs_net *,
815 struct afs_cell *,
816 struct key *,
817 const char *, size_t);
818extern void afs_put_vlocation(struct afs_net *, struct afs_vlocation *);
819extern void afs_vlocation_updater(struct work_struct *);
820extern void afs_vlocation_reaper(struct work_struct *);
821extern void __net_exit afs_vlocation_purge(struct afs_net *);
822 840
823/* 841/*
824 * vnode.c 842 * vlclient.c
825 */ 843 */
826static inline struct afs_vnode *AFS_FS_I(struct inode *inode) 844extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
827{ 845 struct afs_addr_cursor *,
828 return container_of(inode, struct afs_vnode, vfs_inode); 846 struct key *, const char *, int);
829} 847extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
830 848 struct key *, const uuid_t *);
831static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
832{
833 return &vnode->vfs_inode;
834}
835
836extern void afs_vnode_finalise_status_update(struct afs_vnode *,
837 struct afs_server *);
838extern int afs_vnode_fetch_status(struct afs_vnode *, struct key *, bool);
839extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *,
840 struct afs_read *);
841extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *,
842 umode_t, struct afs_fid *, struct afs_file_status *,
843 struct afs_callback *, struct afs_server **);
844extern int afs_vnode_remove(struct afs_vnode *, struct key *, const char *,
845 bool);
846extern int afs_vnode_link(struct afs_vnode *, struct afs_vnode *, struct key *,
847 const char *);
848extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *,
849 const char *, struct afs_fid *,
850 struct afs_file_status *, struct afs_server **);
851extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *,
852 struct key *, const char *, const char *);
853extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t,
854 unsigned, unsigned);
855extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *);
856extern int afs_vnode_get_volume_status(struct afs_vnode *, struct key *,
857 struct afs_volume_status *);
858extern int afs_vnode_set_lock(struct afs_vnode *, struct key *,
859 afs_lock_type_t);
860extern int afs_vnode_extend_lock(struct afs_vnode *, struct key *);
861extern int afs_vnode_release_lock(struct afs_vnode *, struct key *);
862 849
863/* 850/*
864 * volume.c 851 * volume.c
865 */ 852 */
866static inline struct afs_volume *afs_get_volume(struct afs_volume *volume) 853static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
867{ 854{
868 if (volume) 855 if (volume)
869 atomic_inc(&volume->usage); 856 atomic_inc(&volume->usage);
870 return volume; 857 return volume;
871} 858}
872 859
860extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
861extern void afs_activate_volume(struct afs_volume *);
862extern void afs_deactivate_volume(struct afs_volume *);
873extern void afs_put_volume(struct afs_cell *, struct afs_volume *); 863extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
874extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *); 864extern int afs_check_volume_status(struct afs_volume *, struct key *);
875extern void afs_init_fs_cursor(struct afs_fs_cursor *, struct afs_vnode *);
876extern int afs_set_fs_cursor(struct afs_fs_cursor *, struct afs_vnode *);
877extern bool afs_volume_pick_fileserver(struct afs_fs_cursor *, struct afs_vnode *);
878extern bool afs_iterate_fs_cursor(struct afs_fs_cursor *, struct afs_vnode *);
879extern int afs_end_fs_cursor(struct afs_fs_cursor *, struct afs_net *);
880 865
881/* 866/*
882 * write.c 867 * write.c
@@ -903,6 +888,38 @@ extern int afs_fsync(struct file *, loff_t, loff_t, int);
903extern const struct xattr_handler *afs_xattr_handlers[]; 888extern const struct xattr_handler *afs_xattr_handlers[];
904extern ssize_t afs_listxattr(struct dentry *, char *, size_t); 889extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
905 890
891
892/*
893 * Miscellaneous inline functions.
894 */
895static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
896{
897 return container_of(inode, struct afs_vnode, vfs_inode);
898}
899
900static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
901{
902 return &vnode->vfs_inode;
903}
904
905static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
906 struct afs_vnode *vnode,
907 unsigned int cb_break)
908{
909 if (fc->ac.error == 0)
910 afs_cache_permit(vnode, fc->key, cb_break);
911}
912
913static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
914 struct afs_vnode *vnode)
915{
916 if (fc->ac.error == -ENOENT) {
917 set_bit(AFS_VNODE_DELETED, &vnode->flags);
918 afs_break_callback(vnode);
919 }
920}
921
922
906/*****************************************************************************/ 923/*****************************************************************************/
907/* 924/*
908 * debug tracing 925 * debug tracing
diff --git a/fs/afs/main.c b/fs/afs/main.c
index e7f87d723761..15a02a05ff40 100644
--- a/fs/afs/main.c
+++ b/fs/afs/main.c
@@ -55,18 +55,17 @@ static int __net_init afs_net_init(struct afs_net *net)
55 spin_lock_init(&net->proc_cells_lock); 55 spin_lock_init(&net->proc_cells_lock);
56 INIT_LIST_HEAD(&net->proc_cells); 56 INIT_LIST_HEAD(&net->proc_cells);
57 57
58 INIT_LIST_HEAD(&net->vl_updates); 58 seqlock_init(&net->fs_lock);
59 INIT_LIST_HEAD(&net->vl_graveyard); 59 net->fs_servers = RB_ROOT;
60 INIT_DELAYED_WORK(&net->vl_reaper, afs_vlocation_reaper); 60 INIT_LIST_HEAD(&net->fs_updates);
61 INIT_DELAYED_WORK(&net->vl_updater, afs_vlocation_updater); 61 INIT_HLIST_HEAD(&net->fs_proc);
62 spin_lock_init(&net->vl_updates_lock); 62
63 spin_lock_init(&net->vl_graveyard_lock); 63 INIT_HLIST_HEAD(&net->fs_addresses4);
64 net->servers = RB_ROOT; 64 INIT_HLIST_HEAD(&net->fs_addresses6);
65 rwlock_init(&net->servers_lock); 65 seqlock_init(&net->fs_addr_lock);
66 INIT_LIST_HEAD(&net->server_graveyard); 66
67 spin_lock_init(&net->server_graveyard_lock); 67 INIT_WORK(&net->fs_manager, afs_manage_servers);
68 INIT_WORK(&net->server_reaper, afs_reap_server); 68 timer_setup(&net->fs_timer, afs_servers_timer, 0);
69 timer_setup(&net->server_timer, afs_server_timer, 0);
70 69
71 /* Register the /proc stuff */ 70 /* Register the /proc stuff */
72 ret = afs_proc_init(net); 71 ret = afs_proc_init(net);
@@ -87,8 +86,8 @@ static int __net_init afs_net_init(struct afs_net *net)
87 86
88error_open_socket: 87error_open_socket:
89 net->live = false; 88 net->live = false;
90 afs_vlocation_purge(net);
91 afs_cell_purge(net); 89 afs_cell_purge(net);
90 afs_purge_servers(net);
92error_cell_init: 91error_cell_init:
93 net->live = false; 92 net->live = false;
94 afs_proc_cleanup(net); 93 afs_proc_cleanup(net);
@@ -103,9 +102,8 @@ error_proc:
103static void __net_exit afs_net_exit(struct afs_net *net) 102static void __net_exit afs_net_exit(struct afs_net *net)
104{ 103{
105 net->live = false; 104 net->live = false;
106 afs_purge_servers(net);
107 afs_vlocation_purge(net);
108 afs_cell_purge(net); 105 afs_cell_purge(net);
106 afs_purge_servers(net);
109 afs_close_socket(net); 107 afs_close_socket(net);
110 afs_proc_cleanup(net); 108 afs_proc_cleanup(net);
111} 109}
@@ -125,10 +123,6 @@ static int __init afs_init(void)
125 afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0); 123 afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
126 if (!afs_async_calls) 124 if (!afs_async_calls)
127 goto error_async; 125 goto error_async;
128 afs_vlocation_update_worker =
129 alloc_workqueue("kafs_vlupdated", WQ_MEM_RECLAIM, 0);
130 if (!afs_vlocation_update_worker)
131 goto error_vl_up;
132 afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0); 126 afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
133 if (!afs_lock_manager) 127 if (!afs_lock_manager)
134 goto error_lockmgr; 128 goto error_lockmgr;
@@ -160,8 +154,6 @@ error_cache:
160#endif 154#endif
161 destroy_workqueue(afs_lock_manager); 155 destroy_workqueue(afs_lock_manager);
162error_lockmgr: 156error_lockmgr:
163 destroy_workqueue(afs_vlocation_update_worker);
164error_vl_up:
165 destroy_workqueue(afs_async_calls); 157 destroy_workqueue(afs_async_calls);
166error_async: 158error_async:
167 destroy_workqueue(afs_wq); 159 destroy_workqueue(afs_wq);
@@ -189,7 +181,6 @@ static void __exit afs_exit(void)
189 fscache_unregister_netfs(&afs_cache_netfs); 181 fscache_unregister_netfs(&afs_cache_netfs);
190#endif 182#endif
191 destroy_workqueue(afs_lock_manager); 183 destroy_workqueue(afs_lock_manager);
192 destroy_workqueue(afs_vlocation_update_worker);
193 destroy_workqueue(afs_async_calls); 184 destroy_workqueue(afs_async_calls);
194 destroy_workqueue(afs_wq); 185 destroy_workqueue(afs_wq);
195 afs_clean_up_permit_cache(); 186 afs_clean_up_permit_cache();
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 9cf9ce88a8dd..4508dd54f789 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -105,22 +105,22 @@ static const struct file_operations afs_proc_cell_vlservers_fops = {
105 .release = seq_release, 105 .release = seq_release,
106}; 106};
107 107
108static int afs_proc_cell_servers_open(struct inode *inode, struct file *file); 108static int afs_proc_servers_open(struct inode *inode, struct file *file);
109static void *afs_proc_cell_servers_start(struct seq_file *p, loff_t *pos); 109static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos);
110static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, 110static void *afs_proc_servers_next(struct seq_file *p, void *v,
111 loff_t *pos); 111 loff_t *pos);
112static void afs_proc_cell_servers_stop(struct seq_file *p, void *v); 112static void afs_proc_servers_stop(struct seq_file *p, void *v);
113static int afs_proc_cell_servers_show(struct seq_file *m, void *v); 113static int afs_proc_servers_show(struct seq_file *m, void *v);
114 114
115static const struct seq_operations afs_proc_cell_servers_ops = { 115static const struct seq_operations afs_proc_servers_ops = {
116 .start = afs_proc_cell_servers_start, 116 .start = afs_proc_servers_start,
117 .next = afs_proc_cell_servers_next, 117 .next = afs_proc_servers_next,
118 .stop = afs_proc_cell_servers_stop, 118 .stop = afs_proc_servers_stop,
119 .show = afs_proc_cell_servers_show, 119 .show = afs_proc_servers_show,
120}; 120};
121 121
122static const struct file_operations afs_proc_cell_servers_fops = { 122static const struct file_operations afs_proc_servers_fops = {
123 .open = afs_proc_cell_servers_open, 123 .open = afs_proc_servers_open,
124 .read = seq_read, 124 .read = seq_read,
125 .llseek = seq_lseek, 125 .llseek = seq_lseek,
126 .release = seq_release, 126 .release = seq_release,
@@ -138,7 +138,8 @@ int afs_proc_init(struct afs_net *net)
138 goto error_dir; 138 goto error_dir;
139 139
140 if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) || 140 if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) ||
141 !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops)) 141 !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) ||
142 !proc_create("servers", 0644, net->proc_afs, &afs_proc_servers_fops))
142 goto error_tree; 143 goto error_tree;
143 144
144 _leave(" = 0"); 145 _leave(" = 0");
@@ -174,7 +175,6 @@ static int afs_proc_cells_open(struct inode *inode, struct file *file)
174 175
175 m = file->private_data; 176 m = file->private_data;
176 m->private = PDE_DATA(inode); 177 m->private = PDE_DATA(inode);
177
178 return 0; 178 return 0;
179} 179}
180 180
@@ -357,12 +357,10 @@ int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell)
357 if (!dir) 357 if (!dir)
358 goto error_dir; 358 goto error_dir;
359 359
360 if (!proc_create_data("servers", 0, dir, 360 if (!proc_create_data("vlservers", 0, dir,
361 &afs_proc_cell_servers_fops, cell) || 361 &afs_proc_cell_vlservers_fops, cell) ||
362 !proc_create_data("vlservers", 0, dir,
363 &afs_proc_cell_vlservers_fops, cell) ||
364 !proc_create_data("volumes", 0, dir, 362 !proc_create_data("volumes", 0, dir,
365 &afs_proc_cell_volumes_fops, cell)) 363 &afs_proc_cell_volumes_fops, cell))
366 goto error_tree; 364 goto error_tree;
367 365
368 _leave(" = 0"); 366 _leave(" = 0");
@@ -420,9 +418,8 @@ static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
420 418
421 _enter("cell=%p pos=%Ld", cell, *_pos); 419 _enter("cell=%p pos=%Ld", cell, *_pos);
422 420
423 /* lock the list against modification */ 421 read_lock(&cell->proc_lock);
424 down_read(&cell->vl_sem); 422 return seq_list_start_head(&cell->proc_volumes, *_pos);
425 return seq_list_start_head(&cell->vl_list, *_pos);
426} 423}
427 424
428/* 425/*
@@ -434,7 +431,7 @@ static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
434 struct afs_cell *cell = p->private; 431 struct afs_cell *cell = p->private;
435 432
436 _enter("cell=%p pos=%Ld", cell, *_pos); 433 _enter("cell=%p pos=%Ld", cell, *_pos);
437 return seq_list_next(v, &cell->vl_list, _pos); 434 return seq_list_next(v, &cell->proc_volumes, _pos);
438} 435}
439 436
440/* 437/*
@@ -444,17 +441,13 @@ static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
444{ 441{
445 struct afs_cell *cell = p->private; 442 struct afs_cell *cell = p->private;
446 443
447 up_read(&cell->vl_sem); 444 read_unlock(&cell->proc_lock);
448} 445}
449 446
450static const char afs_vlocation_states[][4] = { 447static const char afs_vol_types[3][3] = {
451 [AFS_VL_NEW] = "New", 448 [AFSVL_RWVOL] = "RW",
452 [AFS_VL_CREATING] = "Crt", 449 [AFSVL_ROVOL] = "RO",
453 [AFS_VL_VALID] = "Val", 450 [AFSVL_BACKVOL] = "BK",
454 [AFS_VL_NO_VOLUME] = "NoV",
455 [AFS_VL_UPDATING] = "Upd",
456 [AFS_VL_VOLUME_DELETED] = "Del",
457 [AFS_VL_UNCERTAIN] = "Unc",
458}; 451};
459 452
460/* 453/*
@@ -463,23 +456,17 @@ static const char afs_vlocation_states[][4] = {
463static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) 456static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
464{ 457{
465 struct afs_cell *cell = m->private; 458 struct afs_cell *cell = m->private;
466 struct afs_vlocation *vlocation = 459 struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link);
467 list_entry(v, struct afs_vlocation, link);
468 460
469 /* display header on line 1 */ 461 /* Display header on line 1 */
470 if (v == &cell->vl_list) { 462 if (v == &cell->proc_volumes) {
471 seq_puts(m, "USE STT VLID[0] VLID[1] VLID[2] NAME\n"); 463 seq_puts(m, "USE VID TY\n");
472 return 0; 464 return 0;
473 } 465 }
474 466
475 /* display one cell per line on subsequent lines */ 467 seq_printf(m, "%3d %08x %s\n",
476 seq_printf(m, "%3d %s %08x %08x %08x %s\n", 468 atomic_read(&vol->usage), vol->vid,
477 atomic_read(&vlocation->usage), 469 afs_vol_types[vol->type]);
478 afs_vlocation_states[vlocation->state],
479 vlocation->vldb.vid[0],
480 vlocation->vldb.vid[1],
481 vlocation->vldb.vid[2],
482 vlocation->vldb.name);
483 470
484 return 0; 471 return 0;
485} 472}
@@ -580,86 +567,62 @@ static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
580} 567}
581 568
582/* 569/*
583 * open "/proc/fs/afs/<cell>/servers" which provides a summary of active 570 * open "/proc/fs/afs/servers" which provides a summary of active
584 * servers 571 * servers
585 */ 572 */
586static int afs_proc_cell_servers_open(struct inode *inode, struct file *file) 573static int afs_proc_servers_open(struct inode *inode, struct file *file)
587{ 574{
588 struct afs_cell *cell; 575 return seq_open(file, &afs_proc_servers_ops);
589 struct seq_file *m;
590 int ret;
591
592 cell = PDE_DATA(inode);
593 if (!cell)
594 return -ENOENT;
595
596 ret = seq_open(file, &afs_proc_cell_servers_ops);
597 if (ret < 0)
598 return ret;
599
600 m = file->private_data;
601 m->private = cell;
602 return 0;
603} 576}
604 577
605/* 578/*
606 * set up the iterator to start reading from the cells list and return the 579 * Set up the iterator to start reading from the server list and return the
607 * first item 580 * first item.
608 */ 581 */
609static void *afs_proc_cell_servers_start(struct seq_file *m, loff_t *_pos) 582static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos)
610 __acquires(m->private->servers_lock)
611{ 583{
612 struct afs_cell *cell = m->private; 584 struct afs_net *net = afs_seq2net(m);
613
614 _enter("cell=%p pos=%Ld", cell, *_pos);
615 585
616 /* lock the list against modification */ 586 rcu_read_lock();
617 read_lock(&cell->servers_lock); 587 return seq_hlist_start_head_rcu(&net->fs_proc, *_pos);
618 return seq_list_start_head(&cell->servers, *_pos);
619} 588}
620 589
621/* 590/*
622 * move to next cell in cells list 591 * move to next cell in cells list
623 */ 592 */
624static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, 593static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos)
625 loff_t *_pos)
626{ 594{
627 struct afs_cell *cell = p->private; 595 struct afs_net *net = afs_seq2net(m);
628 596
629 _enter("cell=%p pos=%Ld", cell, *_pos); 597 return seq_hlist_next_rcu(v, &net->fs_proc, _pos);
630 return seq_list_next(v, &cell->servers, _pos);
631} 598}
632 599
633/* 600/*
634 * clean up after reading from the cells list 601 * clean up after reading from the cells list
635 */ 602 */
636static void afs_proc_cell_servers_stop(struct seq_file *p, void *v) 603static void afs_proc_servers_stop(struct seq_file *p, void *v)
637 __releases(p->private->servers_lock)
638{ 604{
639 struct afs_cell *cell = p->private; 605 rcu_read_unlock();
640
641 read_unlock(&cell->servers_lock);
642} 606}
643 607
644/* 608/*
645 * display a header line followed by a load of volume lines 609 * display a header line followed by a load of volume lines
646 */ 610 */
647static int afs_proc_cell_servers_show(struct seq_file *m, void *v) 611static int afs_proc_servers_show(struct seq_file *m, void *v)
648{ 612{
649 struct afs_cell *cell = m->private; 613 struct afs_server *server;
650 struct afs_server *server = list_entry(v, struct afs_server, link); 614 struct afs_addr_list *alist;
651 char ipaddr[64];
652 615
653 /* display header on line 1 */ 616 if (v == SEQ_START_TOKEN) {
654 if (v == &cell->servers) { 617 seq_puts(m, "UUID USE ADDR\n");
655 seq_puts(m, "USE ADDR STATE\n");
656 return 0; 618 return 0;
657 } 619 }
658 620
659 /* display one cell per line on subsequent lines */ 621 server = list_entry(v, struct afs_server, proc_link);
660 sprintf(ipaddr, "%pISp", &server->addrs->addrs[0].transport); 622 alist = rcu_dereference(server->addresses);
661 seq_printf(m, "%3d %-15s %5d\n", 623 seq_printf(m, "%pU %3d %pISp\n",
662 atomic_read(&server->usage), ipaddr, server->fs_state); 624 &server->uuid,
663 625 atomic_read(&server->usage),
626 &alist->addrs[alist->index].transport);
664 return 0; 627 return 0;
665} 628}
diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c
index c7975b3ba59a..e728ca1776c9 100644
--- a/fs/afs/rotate.c
+++ b/fs/afs/rotate.c
@@ -11,7 +11,12 @@
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/fs.h>
15#include <linux/sched.h>
16#include <linux/delay.h>
17#include <linux/sched/signal.h>
14#include "internal.h" 18#include "internal.h"
19#include "afs_fs.h"
15 20
16/* 21/*
17 * Initialise a filesystem server cursor for iterating over FS servers. 22 * Initialise a filesystem server cursor for iterating over FS servers.
@@ -22,6 +27,460 @@ void afs_init_fs_cursor(struct afs_fs_cursor *fc, struct afs_vnode *vnode)
22} 27}
23 28
24/* 29/*
30 * Begin an operation on the fileserver.
31 *
32 * Fileserver operations are serialised on the server by vnode, so we serialise
33 * them here also using the io_lock.
34 */
35bool afs_begin_vnode_operation(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
36 struct key *key)
37{
38 afs_init_fs_cursor(fc, vnode);
39 fc->vnode = vnode;
40 fc->key = key;
41 fc->ac.error = SHRT_MAX;
42
43 if (mutex_lock_interruptible(&vnode->io_lock) < 0) {
44 fc->ac.error = -EINTR;
45 fc->flags |= AFS_FS_CURSOR_STOP;
46 return false;
47 }
48
49 if (test_bit(AFS_VNODE_READLOCKED, &vnode->flags) ||
50 test_bit(AFS_VNODE_WRITELOCKED, &vnode->flags))
51 fc->flags |= AFS_FS_CURSOR_CUR_ONLY;
52 return true;
53}
54
55/*
56 * Begin iteration through a server list, starting with the vnode's last used
57 * server if possible, or the last recorded good server if not.
58 */
59static bool afs_start_fs_iteration(struct afs_fs_cursor *fc,
60 struct afs_vnode *vnode)
61{
62 struct afs_cb_interest *cbi;
63 int i;
64
65 read_lock(&vnode->volume->servers_lock);
66 fc->server_list = afs_get_serverlist(vnode->volume->servers);
67 read_unlock(&vnode->volume->servers_lock);
68
69 cbi = vnode->cb_interest;
70 if (cbi) {
71 /* See if the vnode's preferred record is still available */
72 for (i = 0; i < fc->server_list->nr_servers; i++) {
73 if (fc->server_list->servers[i].cb_interest == cbi) {
74 fc->start = i;
75 goto found_interest;
76 }
77 }
78
79 /* If we have a lock outstanding on a server that's no longer
80 * serving this vnode, then we can't switch to another server
81 * and have to return an error.
82 */
83 if (fc->flags & AFS_FS_CURSOR_CUR_ONLY) {
84 fc->ac.error = -ESTALE;
85 return false;
86 }
87
88 /* Note that the callback promise is effectively broken */
89 write_seqlock(&vnode->cb_lock);
90 ASSERTCMP(cbi, ==, vnode->cb_interest);
91 vnode->cb_interest = NULL;
92 if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags))
93 vnode->cb_break++;
94 write_sequnlock(&vnode->cb_lock);
95
96 afs_put_cb_interest(afs_v2net(vnode), cbi);
97 cbi = NULL;
98 } else {
99 fc->start = READ_ONCE(fc->server_list->index);
100 }
101
102found_interest:
103 fc->index = fc->start;
104 return true;
105}
106
107/*
108 * Post volume busy note.
109 */
110static void afs_busy(struct afs_volume *volume, u32 abort_code)
111{
112 const char *m;
113
114 switch (abort_code) {
115 case VOFFLINE: m = "offline"; break;
116 case VRESTARTING: m = "restarting"; break;
117 case VSALVAGING: m = "being salvaged"; break;
118 default: m = "busy"; break;
119 }
120
121 pr_notice("kAFS: Volume %u '%s' is %s\n", volume->vid, volume->name, m);
122}
123
124/*
125 * Sleep and retry the operation to the same fileserver.
126 */
127static bool afs_sleep_and_retry(struct afs_fs_cursor *fc)
128{
129 msleep_interruptible(1000);
130 if (signal_pending(current)) {
131 fc->ac.error = -ERESTARTSYS;
132 return false;
133 }
134
135 return true;
136}
137
138/*
139 * Select the fileserver to use. May be called multiple times to rotate
140 * through the fileservers.
141 */
142bool afs_select_fileserver(struct afs_fs_cursor *fc)
143{
144 struct afs_addr_list *alist;
145 struct afs_server *server;
146 struct afs_vnode *vnode = fc->vnode;
147
148 _enter("%u/%u,%u/%u,%d,%d",
149 fc->index, fc->start,
150 fc->ac.index, fc->ac.start,
151 fc->ac.error, fc->ac.abort_code);
152
153 if (fc->flags & AFS_FS_CURSOR_STOP) {
154 _leave(" = f [stopped]");
155 return false;
156 }
157
158 /* Evaluate the result of the previous operation, if there was one. */
159 switch (fc->ac.error) {
160 case SHRT_MAX:
161 goto start;
162
163 case 0:
164 default:
165 /* Success or local failure. Stop. */
166 fc->flags |= AFS_FS_CURSOR_STOP;
167 _leave(" = f [okay/local %d]", fc->ac.error);
168 return false;
169
170 case -ECONNABORTED:
171 /* The far side rejected the operation on some grounds. This
172 * might involve the server being busy or the volume having been moved.
173 */
174 switch (fc->ac.abort_code) {
175 case VNOVOL:
176 /* This fileserver doesn't know about the volume.
177 * - May indicate that the VL is wrong - retry once and compare
178 * the results.
179 * - May indicate that the fileserver couldn't attach to the vol.
180 */
181 if (fc->flags & AFS_FS_CURSOR_VNOVOL) {
182 fc->ac.error = -EREMOTEIO;
183 goto failed;
184 }
185
186 write_lock(&vnode->volume->servers_lock);
187 fc->server_list->vnovol_mask |= 1 << fc->index;
188 write_unlock(&vnode->volume->servers_lock);
189
190 set_bit(AFS_VOLUME_NEEDS_UPDATE, &vnode->volume->flags);
191 fc->ac.error = afs_check_volume_status(vnode->volume, fc->key);
192 if (fc->ac.error < 0)
193 goto failed;
194
195 if (test_bit(AFS_VOLUME_DELETED, &vnode->volume->flags)) {
196 fc->ac.error = -ENOMEDIUM;
197 goto failed;
198 }
199
200 /* If the server list didn't change, then assume that
201 * it's the fileserver having trouble.
202 */
203 if (vnode->volume->servers == fc->server_list) {
204 fc->ac.error = -EREMOTEIO;
205 goto failed;
206 }
207
208 /* Try again */
209 fc->flags |= AFS_FS_CURSOR_VNOVOL;
210 _leave(" = t [vnovol]");
211 return true;
212
213 case VSALVAGE: /* TODO: Should this return an error or iterate? */
214 case VVOLEXISTS:
215 case VNOSERVICE:
216 case VONLINE:
217 case VDISKFULL:
218 case VOVERQUOTA:
219 fc->ac.error = afs_abort_to_error(fc->ac.abort_code);
220 goto next_server;
221
222 case VOFFLINE:
223 if (!test_and_set_bit(AFS_VOLUME_OFFLINE, &vnode->volume->flags)) {
224 afs_busy(vnode->volume, fc->ac.abort_code);
225 clear_bit(AFS_VOLUME_BUSY, &vnode->volume->flags);
226 }
227 if (fc->flags & AFS_FS_CURSOR_NO_VSLEEP) {
228 fc->ac.error = -EADV;
229 goto failed;
230 }
231 if (fc->flags & AFS_FS_CURSOR_CUR_ONLY) {
232 fc->ac.error = -ESTALE;
233 goto failed;
234 }
235 goto busy;
236
237 case VSALVAGING:
238 case VRESTARTING:
239 case VBUSY:
240 /* Retry after going round all the servers unless we
241 * have a file lock we need to maintain.
242 */
243 if (fc->flags & AFS_FS_CURSOR_NO_VSLEEP) {
244 fc->ac.error = -EBUSY;
245 goto failed;
246 }
247 if (!test_and_set_bit(AFS_VOLUME_BUSY, &vnode->volume->flags)) {
248 afs_busy(vnode->volume, fc->ac.abort_code);
249 clear_bit(AFS_VOLUME_OFFLINE, &vnode->volume->flags);
250 }
251 busy:
252 if (fc->flags & AFS_FS_CURSOR_CUR_ONLY) {
253 if (!afs_sleep_and_retry(fc))
254 goto failed;
255
256 /* Retry with same server & address */
257 _leave(" = t [vbusy]");
258 return true;
259 }
260
261 fc->flags |= AFS_FS_CURSOR_VBUSY;
262 goto next_server;
263
264 case VMOVED:
265 /* The volume migrated to another server. We consider
266 * consider all locks and callbacks broken and request
267 * an update from the VLDB.
268 *
269 * We also limit the number of VMOVED hops we will
270 * honour, just in case someone sets up a loop.
271 */
272 if (fc->flags & AFS_FS_CURSOR_VMOVED) {
273 fc->ac.error = -EREMOTEIO;
274 goto failed;
275 }
276 fc->flags |= AFS_FS_CURSOR_VMOVED;
277
278 set_bit(AFS_VOLUME_WAIT, &vnode->volume->flags);
279 set_bit(AFS_VOLUME_NEEDS_UPDATE, &vnode->volume->flags);
280 fc->ac.error = afs_check_volume_status(vnode->volume, fc->key);
281 if (fc->ac.error < 0)
282 goto failed;
283
284 /* If the server list didn't change, then the VLDB is
285 * out of sync with the fileservers. This is hopefully
286 * a temporary condition, however, so we don't want to
287 * permanently block access to the file.
288 *
289 * TODO: Try other fileservers if we can.
290 *
291 * TODO: Retry a few times with sleeps.
292 */
293 if (vnode->volume->servers == fc->server_list) {
294 fc->ac.error = -ENOMEDIUM;
295 goto failed;
296 }
297
298 goto restart_from_beginning;
299
300 default:
301 clear_bit(AFS_VOLUME_OFFLINE, &vnode->volume->flags);
302 clear_bit(AFS_VOLUME_BUSY, &vnode->volume->flags);
303 fc->ac.error = afs_abort_to_error(fc->ac.abort_code);
304 goto failed;
305 }
306
307 case -ENETUNREACH:
308 case -EHOSTUNREACH:
309 case -ECONNREFUSED:
310 case -ETIMEDOUT:
311 case -ETIME:
312 _debug("no conn");
313 goto iterate_address;
314 }
315
316restart_from_beginning:
317 _debug("restart");
318 afs_end_cursor(&fc->ac);
319 afs_put_cb_interest(afs_v2net(vnode), fc->cbi);
320 fc->cbi = NULL;
321 afs_put_serverlist(afs_v2net(vnode), fc->server_list);
322 fc->server_list = NULL;
323start:
324 _debug("start");
325 /* See if we need to do an update of the volume record. Note that the
326 * volume may have moved or even have been deleted.
327 */
328 fc->ac.error = afs_check_volume_status(vnode->volume, fc->key);
329 if (fc->ac.error < 0)
330 goto failed;
331
332 if (!afs_start_fs_iteration(fc, vnode))
333 goto failed;
334 goto use_server;
335
336next_server:
337 _debug("next");
338 afs_put_cb_interest(afs_v2net(vnode), fc->cbi);
339 fc->cbi = NULL;
340 fc->index++;
341 if (fc->index >= fc->server_list->nr_servers)
342 fc->index = 0;
343 if (fc->index != fc->start)
344 goto use_server;
345
346 /* That's all the servers poked to no good effect. Try again if some
347 * of them were busy.
348 */
349 if (fc->flags & AFS_FS_CURSOR_VBUSY)
350 goto restart_from_beginning;
351
352 fc->ac.error = -EDESTADDRREQ;
353 goto failed;
354
355use_server:
356 _debug("use");
357 /* We're starting on a different fileserver from the list. We need to
358 * check it, create a callback intercept, find its address list and
359 * probe its capabilities before we use it.
360 */
361 ASSERTCMP(fc->ac.alist, ==, NULL);
362 server = fc->server_list->servers[fc->index].server;
363
364 if (!afs_check_server_record(fc, server))
365 goto failed;
366
367 _debug("USING SERVER: %pU", &server->uuid);
368
369 /* Make sure we've got a callback interest record for this server. We
370 * have to link it in before we send the request as we can be sent a
371 * break request before we've finished decoding the reply and
372 * installing the vnode.
373 */
374 fc->ac.error = afs_register_server_cb_interest(
375 vnode, &fc->server_list->servers[fc->index]);
376 if (fc->ac.error < 0)
377 goto failed;
378
379 fc->cbi = afs_get_cb_interest(vnode->cb_interest);
380
381 read_lock(&server->fs_lock);
382 alist = rcu_dereference_protected(server->addresses,
383 lockdep_is_held(&server->fs_lock));
384 afs_get_addrlist(alist);
385 read_unlock(&server->fs_lock);
386
387
388 /* Probe the current fileserver if we haven't done so yet. */
389 if (!test_bit(AFS_SERVER_FL_PROBED, &server->flags)) {
390 fc->ac.alist = afs_get_addrlist(alist);
391
392 if (!afs_probe_fileserver(fc))
393 goto failed;
394 }
395
396 if (!fc->ac.alist)
397 fc->ac.alist = alist;
398 else
399 afs_put_addrlist(alist);
400
401 fc->ac.addr = NULL;
402 fc->ac.start = READ_ONCE(alist->index);
403 fc->ac.index = fc->ac.start;
404 fc->ac.error = 0;
405 fc->ac.begun = false;
406 goto iterate_address;
407
408iterate_address:
409 ASSERT(fc->ac.alist);
410 _debug("iterate %d/%d", fc->ac.index, fc->ac.alist->nr_addrs);
411 /* Iterate over the current server's address list to try and find an
412 * address on which it will respond to us.
413 */
414 if (afs_iterate_addresses(&fc->ac)) {
415 _leave(" = t");
416 return true;
417 }
418
419 afs_end_cursor(&fc->ac);
420 goto next_server;
421
422failed:
423 fc->flags |= AFS_FS_CURSOR_STOP;
424 _leave(" = f [failed %d]", fc->ac.error);
425 return false;
426}
427
428/*
429 * Select the same fileserver we used for a vnode before and only that
430 * fileserver. We use this when we have a lock on that file, which is backed
431 * only by the fileserver we obtained it from.
432 */
433bool afs_select_current_fileserver(struct afs_fs_cursor *fc)
434{
435 struct afs_vnode *vnode = fc->vnode;
436 struct afs_cb_interest *cbi = vnode->cb_interest;
437 struct afs_addr_list *alist;
438
439 _enter("");
440
441 if (!cbi) {
442 fc->ac.error = -ESTALE;
443 fc->flags |= AFS_FS_CURSOR_STOP;
444 return false;
445 }
446
447 read_lock(&cbi->server->fs_lock);
448 alist = afs_get_addrlist(cbi->server->addresses);
449 read_unlock(&cbi->server->fs_lock);
450 if (!alist) {
451 fc->ac.error = -ESTALE;
452 fc->flags |= AFS_FS_CURSOR_STOP;
453 return false;
454 }
455
456 fc->ac.alist = alist;
457 fc->ac.error = 0;
458 return true;
459}
460
461/*
462 * Tidy up a filesystem cursor and unlock the vnode.
463 */
464int afs_end_vnode_operation(struct afs_fs_cursor *fc)
465{
466 struct afs_net *net = afs_v2net(fc->vnode);
467 int ret;
468
469 mutex_unlock(&fc->vnode->io_lock);
470
471 afs_end_cursor(&fc->ac);
472 afs_put_cb_interest(net, fc->cbi);
473 afs_put_serverlist(net, fc->server_list);
474
475 ret = fc->ac.error;
476 if (ret == -ECONNABORTED)
477 afs_abort_to_error(fc->ac.abort_code);
478
479 return fc->ac.error;
480}
481
482#if 0
483/*
25 * Set a filesystem server cursor for using a specific FS server. 484 * Set a filesystem server cursor for using a specific FS server.
26 */ 485 */
27int afs_set_fs_cursor(struct afs_fs_cursor *fc, struct afs_vnode *vnode) 486int afs_set_fs_cursor(struct afs_fs_cursor *fc, struct afs_vnode *vnode)
@@ -252,3 +711,5 @@ int afs_end_fs_cursor(struct afs_fs_cursor *fc, struct afs_net *net)
252 afs_put_server(net, fc->server); 711 afs_put_server(net, fc->server);
253 return fc->ac.error; 712 return fc->ac.error;
254} 713}
714
715#endif
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index 5ddfb7c4cf78..1bbd5854507d 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -20,7 +20,7 @@
20struct workqueue_struct *afs_async_calls; 20struct workqueue_struct *afs_async_calls;
21 21
22static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long); 22static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long);
23static long afs_wait_for_call_to_complete(struct afs_call *); 23static long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
24static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long); 24static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long);
25static void afs_process_async_call(struct work_struct *); 25static void afs_process_async_call(struct work_struct *);
26static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long); 26static 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 call->type->destructor(call); 162 call->type->destructor(call);
163 163
164 afs_put_server(call->net, call->cm_server); 164 afs_put_server(call->net, call->cm_server);
165 afs_put_cb_interest(call->net, call->cbi);
165 kfree(call->request); 166 kfree(call->request);
166 kfree(call); 167 kfree(call);
167 168
@@ -330,7 +331,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
330 struct kvec iov[1]; 331 struct kvec iov[1];
331 size_t offset; 332 size_t offset;
332 s64 tx_total_len; 333 s64 tx_total_len;
333 u32 abort_code;
334 int ret; 334 int ret;
335 335
336 _enter(",{%pISp},", &srx->transport); 336 _enter(",{%pISp},", &srx->transport);
@@ -362,7 +362,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
362 afs_wake_up_async_call : 362 afs_wake_up_async_call :
363 afs_wake_up_call_waiter), 363 afs_wake_up_call_waiter),
364 call->upgrade); 364 call->upgrade);
365 call->key = NULL;
366 if (IS_ERR(rxcall)) { 365 if (IS_ERR(rxcall)) {
367 ret = PTR_ERR(rxcall); 366 ret = PTR_ERR(rxcall);
368 goto error_kill_call; 367 goto error_kill_call;
@@ -406,7 +405,7 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
406 if (call->async) 405 if (call->async)
407 return -EINPROGRESS; 406 return -EINPROGRESS;
408 407
409 return afs_wait_for_call_to_complete(call); 408 return afs_wait_for_call_to_complete(call, ac);
410 409
411error_do_abort: 410error_do_abort:
412 call->state = AFS_CALL_COMPLETE; 411 call->state = AFS_CALL_COMPLETE;
@@ -414,15 +413,16 @@ error_do_abort:
414 rxrpc_kernel_abort_call(call->net->socket, rxcall, 413 rxrpc_kernel_abort_call(call->net->socket, rxcall,
415 RX_USER_ABORT, ret, "KSD"); 414 RX_USER_ABORT, ret, "KSD");
416 } else { 415 } else {
417 abort_code = 0;
418 offset = 0; 416 offset = 0;
419 rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL, 417 rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL,
420 0, &offset, false, &call->abort_code, 418 0, &offset, false, &call->abort_code,
421 &call->service_id); 419 &call->service_id);
422 ret = afs_abort_to_error(call->abort_code); 420 ac->abort_code = call->abort_code;
421 ac->responded = true;
423 } 422 }
424error_kill_call: 423error_kill_call:
425 afs_put_call(call); 424 afs_put_call(call);
425 ac->error = ret;
426 _leave(" = %d", ret); 426 _leave(" = %d", ret);
427 return ret; 427 return ret;
428} 428}
@@ -510,7 +510,8 @@ save_error:
510/* 510/*
511 * wait synchronously for a call to complete 511 * wait synchronously for a call to complete
512 */ 512 */
513static long afs_wait_for_call_to_complete(struct afs_call *call) 513static long afs_wait_for_call_to_complete(struct afs_call *call,
514 struct afs_addr_cursor *ac)
514{ 515{
515 signed long rtt2, timeout; 516 signed long rtt2, timeout;
516 long ret; 517 long ret;
@@ -563,16 +564,25 @@ static long afs_wait_for_call_to_complete(struct afs_call *call)
563 /* Kill off the call if it's still live. */ 564 /* Kill off the call if it's still live. */
564 if (call->state < AFS_CALL_COMPLETE) { 565 if (call->state < AFS_CALL_COMPLETE) {
565 _debug("call interrupted"); 566 _debug("call interrupted");
566 rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 567 if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
567 RX_USER_ABORT, -EINTR, "KWI"); 568 RX_USER_ABORT, -EINTR, "KWI"))
569 call->error = -ERESTARTSYS;
568 } 570 }
569 571
570 ret = call->error; 572 ac->abort_code = call->abort_code;
571 if (ret < 0) { 573 ac->error = call->error;
572 ret = afs_abort_to_error(call->abort_code); 574
573 } else if (ret == 0 && call->ret_reply0) { 575 ret = ac->error;
574 ret = (long)call->reply[0]; 576 switch (ret) {
575 call->reply[0] = NULL; 577 case 0:
578 if (call->ret_reply0) {
579 ret = (long)call->reply[0];
580 call->reply[0] = NULL;
581 }
582 /* Fall through */
583 case -ECONNABORTED:
584 ac->responded = true;
585 break;
576 } 586 }
577 587
578 _debug("call complete"); 588 _debug("call complete");
@@ -882,10 +892,7 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count,
882 return 0; 892 return 0;
883 } 893 }
884 894
885 if (ret == -ECONNABORTED) 895 call->error = ret;
886 call->error = afs_abort_to_error(call->abort_code);
887 else
888 call->error = ret;
889 call->state = AFS_CALL_COMPLETE; 896 call->state = AFS_CALL_COMPLETE;
890 return ret; 897 return ret;
891} 898}
diff --git a/fs/afs/security.c b/fs/afs/security.c
index 1b5198fc1657..46a881a4d08f 100644
--- a/fs/afs/security.c
+++ b/fs/afs/security.c
@@ -325,7 +325,7 @@ static int afs_check_permit(struct afs_vnode *vnode, struct key *key,
325 */ 325 */
326 _debug("no valid permit"); 326 _debug("no valid permit");
327 327
328 ret = afs_vnode_fetch_status(vnode, key, true); 328 ret = afs_fetch_status(vnode, key);
329 if (ret < 0) { 329 if (ret < 0) {
330 *_access = 0; 330 *_access = 0;
331 _leave(" = %d", ret); 331 _leave(" = %d", ret);
diff --git a/fs/afs/server.c b/fs/afs/server.c
index 9ca174b24f5b..a6c860bcf391 100644
--- a/fs/afs/server.c
+++ b/fs/afs/server.c
@@ -14,7 +14,8 @@
14#include "afs_fs.h" 14#include "afs_fs.h"
15#include "internal.h" 15#include "internal.h"
16 16
17static unsigned afs_server_timeout = 10; /* server timeout in seconds */ 17static unsigned afs_server_gc_delay = 10; /* Server record timeout in seconds */
18static unsigned afs_server_update_delay = 30; /* Time till VLDB recheck in secs */
18 19
19static void afs_inc_servers_outstanding(struct afs_net *net) 20static void afs_inc_servers_outstanding(struct afs_net *net)
20{ 21{
@@ -27,60 +28,201 @@ static void afs_dec_servers_outstanding(struct afs_net *net)
27 wake_up_atomic_t(&net->servers_outstanding); 28 wake_up_atomic_t(&net->servers_outstanding);
28} 29}
29 30
30void afs_server_timer(struct timer_list *timer) 31/*
32 * Find a server by one of its addresses.
33 */
34struct afs_server *afs_find_server(struct afs_net *net,
35 const struct sockaddr_rxrpc *srx)
31{ 36{
32 struct afs_net *net = container_of(timer, struct afs_net, server_timer); 37 const struct sockaddr_in6 *a = &srx->transport.sin6, *b;
38 const struct afs_addr_list *alist;
39 struct afs_server *server = NULL;
40 unsigned int i;
41 bool ipv6 = true;
42 int seq = 0, diff;
43
44 if (srx->transport.sin6.sin6_addr.s6_addr32[0] == 0 ||
45 srx->transport.sin6.sin6_addr.s6_addr32[1] == 0 ||
46 srx->transport.sin6.sin6_addr.s6_addr32[2] == htonl(0xffff))
47 ipv6 = false;
48
49 rcu_read_lock();
50
51 do {
52 if (server)
53 afs_put_server(net, server);
54 server = NULL;
55 read_seqbegin_or_lock(&net->fs_addr_lock, &seq);
56
57 if (ipv6) {
58 hlist_for_each_entry_rcu(server, &net->fs_addresses6, addr6_link) {
59 alist = rcu_dereference(server->addresses);
60 for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) {
61 b = &alist->addrs[i].transport.sin6;
62 diff = (u16)a->sin6_port - (u16)b->sin6_port;
63 if (diff == 0)
64 diff = memcmp(&a->sin6_addr,
65 &b->sin6_addr,
66 sizeof(struct in6_addr));
67 if (diff == 0)
68 goto found;
69 if (diff < 0) {
70 // TODO: Sort the list
71 //if (i == alist->nr_ipv4)
72 // goto not_found;
73 break;
74 }
75 }
76 }
77 } else {
78 hlist_for_each_entry_rcu(server, &net->fs_addresses4, addr4_link) {
79 alist = rcu_dereference(server->addresses);
80 for (i = 0; i < alist->nr_ipv4; i++) {
81 b = &alist->addrs[i].transport.sin6;
82 diff = (u16)a->sin6_port - (u16)b->sin6_port;
83 if (diff == 0)
84 diff = ((u32)a->sin6_addr.s6_addr32[3] -
85 (u32)b->sin6_addr.s6_addr32[3]);
86 if (diff == 0)
87 goto found;
88 if (diff < 0) {
89 // TODO: Sort the list
90 //if (i == 0)
91 // goto not_found;
92 break;
93 }
94 }
95 }
96 }
33 97
34 if (!queue_work(afs_wq, &net->server_reaper)) 98 //not_found:
35 afs_dec_servers_outstanding(net); 99 server = NULL;
100 found:
101 if (server && !atomic_inc_not_zero(&server->usage))
102 server = NULL;
103
104 } while (need_seqretry(&net->fs_addr_lock, seq));
105
106 done_seqretry(&net->fs_addr_lock, seq);
107
108 rcu_read_unlock();
109 return server;
36} 110}
37 111
38/* 112/*
39 * install a server record in the master tree 113 * Look up a server by its UUID
40 */ 114 */
41static int afs_install_server(struct afs_server *server) 115struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uuid)
42{ 116{
43 struct afs_server *xserver; 117 struct afs_server *server = NULL;
44 struct afs_net *net = server->cell->net; 118 struct rb_node *p;
119 int diff, seq = 0;
120
121 _enter("%pU", uuid);
122
123 do {
124 /* Unfortunately, rbtree walking doesn't give reliable results
125 * under just the RCU read lock, so we have to check for
126 * changes.
127 */
128 if (server)
129 afs_put_server(net, server);
130 server = NULL;
131
132 read_seqbegin_or_lock(&net->fs_lock, &seq);
133
134 p = net->fs_servers.rb_node;
135 while (p) {
136 server = rb_entry(p, struct afs_server, uuid_rb);
137
138 diff = memcmp(uuid, &server->uuid, sizeof(*uuid));
139 if (diff < 0) {
140 p = p->rb_left;
141 } else if (diff > 0) {
142 p = p->rb_right;
143 } else {
144 afs_get_server(server);
145 break;
146 }
147
148 server = NULL;
149 }
150 } while (need_seqretry(&net->fs_lock, seq));
151
152 done_seqretry(&net->fs_lock, seq);
153
154 _leave(" = %p", server);
155 return server;
156}
157
158/*
159 * Install a server record in the namespace tree
160 */
161static struct afs_server *afs_install_server(struct afs_net *net,
162 struct afs_server *candidate)
163{
164 const struct afs_addr_list *alist;
165 struct afs_server *server;
45 struct rb_node **pp, *p; 166 struct rb_node **pp, *p;
46 int ret, diff; 167 int ret = -EEXIST, diff;
47 168
48 _enter("%p", server); 169 _enter("%p", candidate);
49 170
50 write_lock(&net->servers_lock); 171 write_seqlock(&net->fs_lock);
51 172
52 ret = -EEXIST; 173 /* Firstly install the server in the UUID lookup tree */
53 pp = &net->servers.rb_node; 174 pp = &net->fs_servers.rb_node;
54 p = NULL; 175 p = NULL;
55 while (*pp) { 176 while (*pp) {
56 p = *pp; 177 p = *pp;
57 _debug("- consider %p", p); 178 _debug("- consider %p", p);
58 xserver = rb_entry(p, struct afs_server, master_rb); 179 server = rb_entry(p, struct afs_server, uuid_rb);
59 diff = memcmp(&server->addrs->addrs[0], 180 diff = memcmp(&candidate->uuid, &server->uuid, sizeof(uuid_t));
60 &xserver->addrs->addrs[0],
61 sizeof(sizeof(server->addrs->addrs[0])));
62 if (diff < 0) 181 if (diff < 0)
63 pp = &(*pp)->rb_left; 182 pp = &(*pp)->rb_left;
64 else if (diff > 0) 183 else if (diff > 0)
65 pp = &(*pp)->rb_right; 184 pp = &(*pp)->rb_right;
66 else 185 else
67 goto error; 186 goto exists;
68 } 187 }
69 188
70 rb_link_node(&server->master_rb, p, pp); 189 server = candidate;
71 rb_insert_color(&server->master_rb, &net->servers); 190 rb_link_node(&server->uuid_rb, p, pp);
191 rb_insert_color(&server->uuid_rb, &net->fs_servers);
192 hlist_add_head_rcu(&server->proc_link, &net->fs_proc);
193
194 write_seqlock(&net->fs_addr_lock);
195 alist = rcu_dereference_protected(server->addresses,
196 lockdep_is_held(&net->fs_addr_lock.lock));
197
198 /* Secondly, if the server has any IPv4 and/or IPv6 addresses, install
199 * it in the IPv4 and/or IPv6 reverse-map lists.
200 *
201 * TODO: For speed we want to use something other than a flat list
202 * here; even sorting the list in terms of lowest address would help a
203 * bit, but anything we might want to do gets messy and memory
204 * intensive.
205 */
206 if (alist->nr_ipv4 > 0)
207 hlist_add_head_rcu(&server->addr4_link, &net->fs_addresses4);
208 if (alist->nr_addrs > alist->nr_ipv4)
209 hlist_add_head_rcu(&server->addr6_link, &net->fs_addresses6);
210
211 write_sequnlock(&net->fs_addr_lock);
72 ret = 0; 212 ret = 0;
73 213
74error: 214exists:
75 write_unlock(&net->servers_lock); 215 afs_get_server(server);
76 return ret; 216 write_sequnlock(&net->fs_lock);
217 return server;
77} 218}
78 219
79/* 220/*
80 * allocate a new server record 221 * allocate a new server record
81 */ 222 */
82static struct afs_server *afs_alloc_server(struct afs_cell *cell, 223static struct afs_server *afs_alloc_server(struct afs_net *net,
83 const struct sockaddr_rxrpc *addr) 224 const uuid_t *uuid,
225 struct afs_addr_list *alist)
84{ 226{
85 struct afs_server *server; 227 struct afs_server *server;
86 228
@@ -89,194 +231,155 @@ static struct afs_server *afs_alloc_server(struct afs_cell *cell,
89 server = kzalloc(sizeof(struct afs_server), GFP_KERNEL); 231 server = kzalloc(sizeof(struct afs_server), GFP_KERNEL);
90 if (!server) 232 if (!server)
91 goto enomem; 233 goto enomem;
92 server->addrs = kzalloc(sizeof(struct afs_addr_list) +
93 sizeof(struct sockaddr_rxrpc),
94 GFP_KERNEL);
95 if (!server->addrs)
96 goto enomem_server;
97 234
98 atomic_set(&server->usage, 1); 235 atomic_set(&server->usage, 1);
99 server->net = cell->net; 236 RCU_INIT_POINTER(server->addresses, alist);
100 server->cell = cell; 237 server->addr_version = alist->version;
101 238 server->uuid = *uuid;
102 INIT_LIST_HEAD(&server->link); 239 server->flags = (1UL << AFS_SERVER_FL_NEW);
103 INIT_LIST_HEAD(&server->grave); 240 server->update_at = ktime_get_real_seconds() + afs_server_update_delay;
104 init_rwsem(&server->sem); 241 rwlock_init(&server->fs_lock);
105 spin_lock_init(&server->fs_lock);
106 INIT_LIST_HEAD(&server->cb_interests); 242 INIT_LIST_HEAD(&server->cb_interests);
107 rwlock_init(&server->cb_break_lock); 243 rwlock_init(&server->cb_break_lock);
108 244
109 refcount_set(&server->addrs->usage, 1); 245 afs_inc_servers_outstanding(net);
110 server->addrs->nr_addrs = 1; 246 _leave(" = %p", server);
111 server->addrs->addrs[0] = *addr;
112 afs_inc_servers_outstanding(cell->net);
113
114 _leave(" = %p{%d}", server, atomic_read(&server->usage));
115 return server; 247 return server;
116 248
117enomem_server:
118 kfree(server);
119enomem: 249enomem:
120 _leave(" = NULL [nomem]"); 250 _leave(" = NULL [nomem]");
121 return NULL; 251 return NULL;
122} 252}
123 253
124/* 254/*
125 * get an FS-server record for a cell 255 * Look up an address record for a server
126 */ 256 */
127struct afs_server *afs_lookup_server(struct afs_cell *cell, 257static struct afs_addr_list *afs_vl_lookup_addrs(struct afs_cell *cell,
128 struct sockaddr_rxrpc *addr) 258 struct key *key, const uuid_t *uuid)
129{ 259{
130 struct afs_server *server, *candidate; 260 struct afs_addr_cursor ac;
131 261 struct afs_addr_list *alist;
132 _enter("%p,%pIS", cell, &addr->transport); 262 int ret;
133 263
134 /* quick scan of the list to see if we already have the server */ 264 ret = afs_set_vl_cursor(&ac, cell);
135 read_lock(&cell->servers_lock); 265 if (ret < 0)
136 266 return ERR_PTR(ret);
137 list_for_each_entry(server, &cell->servers, link) { 267
138 if (memcmp(&server->addrs->addrs[0], addr, sizeof(*addr)) == 0) 268 while (afs_iterate_addresses(&ac)) {
139 goto found_server_quickly; 269 alist = afs_vl_get_addrs_u(cell->net, &ac, key, uuid);
140 } 270 switch (ac.error) {
141 read_unlock(&cell->servers_lock); 271 case 0:
142 272 afs_end_cursor(&ac);
143 candidate = afs_alloc_server(cell, addr); 273 return alist;
144 if (!candidate) { 274 case -ECONNABORTED:
145 _leave(" = -ENOMEM"); 275 ac.error = afs_abort_to_error(ac.abort_code);
146 return ERR_PTR(-ENOMEM); 276 goto error;
147 } 277 case -ENOMEM:
148 278 case -ENONET:
149 write_lock(&cell->servers_lock); 279 goto error;
150 280 case -ENETUNREACH:
151 /* check the cell's server list again */ 281 case -EHOSTUNREACH:
152 list_for_each_entry(server, &cell->servers, link) { 282 case -ECONNREFUSED:
153 if (memcmp(&server->addrs->addrs[0], addr, sizeof(*addr)) == 0) 283 break;
154 goto found_server; 284 default:
155 } 285 ac.error = -EIO;
156 286 goto error;
157 _debug("new"); 287 }
158 server = candidate;
159 if (afs_install_server(server) < 0)
160 goto server_in_two_cells;
161
162 afs_get_cell(cell);
163 list_add_tail(&server->link, &cell->servers);
164
165 write_unlock(&cell->servers_lock);
166 _leave(" = %p{%d}", server, atomic_read(&server->usage));
167 return server;
168
169 /* found a matching server quickly */
170found_server_quickly:
171 _debug("found quickly");
172 afs_get_server(server);
173 read_unlock(&cell->servers_lock);
174no_longer_unused:
175 if (!list_empty(&server->grave)) {
176 spin_lock(&cell->net->server_graveyard_lock);
177 list_del_init(&server->grave);
178 spin_unlock(&cell->net->server_graveyard_lock);
179 } 288 }
180 _leave(" = %p{%d}", server, atomic_read(&server->usage));
181 return server;
182 289
183 /* found a matching server on the second pass */ 290error:
184found_server: 291 return ERR_PTR(afs_end_cursor(&ac));
185 _debug("found");
186 afs_get_server(server);
187 write_unlock(&cell->servers_lock);
188 kfree(candidate);
189 goto no_longer_unused;
190
191 /* found a server that seems to be in two cells */
192server_in_two_cells:
193 write_unlock(&cell->servers_lock);
194 kfree(candidate);
195 afs_dec_servers_outstanding(cell->net);
196 printk(KERN_NOTICE "kAFS: Server %pI4 appears to be in two cells\n",
197 addr);
198 _leave(" = -EEXIST");
199 return ERR_PTR(-EEXIST);
200} 292}
201 293
202/* 294/*
203 * look up a server by its IP address 295 * Get or create a fileserver record.
204 */ 296 */
205struct afs_server *afs_find_server(struct afs_net *net, 297struct afs_server *afs_lookup_server(struct afs_cell *cell, struct key *key,
206 const struct sockaddr_rxrpc *srx) 298 const uuid_t *uuid)
207{ 299{
208 struct afs_server *server = NULL; 300 struct afs_addr_list *alist;
209 struct rb_node *p; 301 struct afs_server *server, *candidate;
210 int diff;
211 302
212 _enter("{%d,%pIS}", srx->transport.family, &srx->transport); 303 _enter("%p,%pU", cell->net, uuid);
213 304
214 read_lock(&net->servers_lock); 305 server = afs_find_server_by_uuid(cell->net, uuid);
306 if (server)
307 return server;
215 308
216 p = net->servers.rb_node; 309 alist = afs_vl_lookup_addrs(cell, key, uuid);
217 while (p) { 310 if (IS_ERR(alist))
218 server = rb_entry(p, struct afs_server, master_rb); 311 return ERR_CAST(alist);
219 312
220 _debug("- consider %p", p); 313 candidate = afs_alloc_server(cell->net, uuid, alist);
314 if (!candidate) {
315 afs_put_addrlist(alist);
316 return ERR_PTR(-ENOMEM);
317 }
221 318
222 diff = memcmp(srx, &server->addrs->addrs[0], sizeof(*srx)); 319 server = afs_install_server(cell->net, candidate);
223 if (diff < 0) { 320 if (server != candidate) {
224 p = p->rb_left; 321 afs_put_addrlist(alist);
225 } else if (diff > 0) { 322 kfree(candidate);
226 p = p->rb_right;
227 } else {
228 afs_get_server(server);
229 goto found;
230 }
231 } 323 }
232 324
233 server = NULL; 325 _leave(" = %p{%d}", server, atomic_read(&server->usage));
234found:
235 read_unlock(&net->servers_lock);
236 _leave(" = %p", server);
237 return server; 326 return server;
238} 327}
239 328
329/*
330 * Set the server timer to fire after a given delay, assuming it's not already
331 * set for an earlier time.
332 */
240static void afs_set_server_timer(struct afs_net *net, time64_t delay) 333static void afs_set_server_timer(struct afs_net *net, time64_t delay)
241{ 334{
242 afs_inc_servers_outstanding(net);
243 if (net->live) { 335 if (net->live) {
244 if (timer_reduce(&net->server_timer, jiffies + delay * HZ)) 336 afs_inc_servers_outstanding(net);
245 afs_dec_servers_outstanding(net); 337 if (timer_reduce(&net->fs_timer, jiffies + delay * HZ))
246 } else {
247 if (!queue_work(afs_wq, &net->server_reaper))
248 afs_dec_servers_outstanding(net); 338 afs_dec_servers_outstanding(net);
249 } 339 }
250} 340}
251 341
252/* 342/*
253 * destroy a server record 343 * Server management timer. We have an increment on fs_outstanding that we
254 * - removes from the cell list 344 * need to pass along to the work item.
345 */
346void afs_servers_timer(struct timer_list *timer)
347{
348 struct afs_net *net = container_of(timer, struct afs_net, fs_timer);
349
350 _enter("");
351 if (!queue_work(afs_wq, &net->fs_manager))
352 afs_dec_servers_outstanding(net);
353}
354
355/*
356 * Release a reference on a server record.
255 */ 357 */
256void afs_put_server(struct afs_net *net, struct afs_server *server) 358void afs_put_server(struct afs_net *net, struct afs_server *server)
257{ 359{
360 unsigned int usage;
361
258 if (!server) 362 if (!server)
259 return; 363 return;
260 364
261 _enter("%p{%d}", server, atomic_read(&server->usage)); 365 server->put_time = ktime_get_real_seconds();
262 366
263 _debug("PUT SERVER %d", atomic_read(&server->usage)); 367 usage = atomic_dec_return(&server->usage);
264 368
265 ASSERTCMP(atomic_read(&server->usage), >, 0); 369 _enter("{%u}", usage);
266 370
267 if (likely(!atomic_dec_and_test(&server->usage))) { 371 if (likely(usage > 0))
268 _leave("");
269 return; 372 return;
270 }
271 373
272 spin_lock(&net->server_graveyard_lock); 374 afs_set_server_timer(net, afs_server_gc_delay);
273 if (atomic_read(&server->usage) == 0) { 375}
274 list_move_tail(&server->grave, &net->server_graveyard); 376
275 server->time_of_death = ktime_get_real_seconds(); 377static void afs_server_rcu(struct rcu_head *rcu)
276 afs_set_server_timer(net, afs_server_timeout); 378{
277 } 379 struct afs_server *server = container_of(rcu, struct afs_server, rcu);
278 spin_unlock(&net->server_graveyard_lock); 380
279 _leave(" [dead]"); 381 afs_put_addrlist(server->addresses);
382 kfree(server);
280} 383}
281 384
282/* 385/*
@@ -284,7 +387,7 @@ void afs_put_server(struct afs_net *net, struct afs_server *server)
284 */ 387 */
285static void afs_destroy_server(struct afs_net *net, struct afs_server *server) 388static void afs_destroy_server(struct afs_net *net, struct afs_server *server)
286{ 389{
287 struct afs_addr_list *alist = server->addrs; 390 struct afs_addr_list *alist = server->addresses;
288 struct afs_addr_cursor ac = { 391 struct afs_addr_cursor ac = {
289 .alist = alist, 392 .alist = alist,
290 .addr = &alist->addrs[0], 393 .addr = &alist->addrs[0],
@@ -294,79 +397,300 @@ static void afs_destroy_server(struct afs_net *net, struct afs_server *server)
294 }; 397 };
295 _enter("%p", server); 398 _enter("%p", server);
296 399
297 afs_fs_give_up_all_callbacks(server, &ac, NULL, false); 400 afs_fs_give_up_all_callbacks(net, server, &ac, NULL);
298 afs_put_cell(net, server->cell); 401 call_rcu(&server->rcu, afs_server_rcu);
299 afs_put_addrlist(server->addrs);
300 kfree(server);
301 afs_dec_servers_outstanding(net); 402 afs_dec_servers_outstanding(net);
302} 403}
303 404
304/* 405/*
305 * reap dead server records 406 * Garbage collect any expired servers.
306 */ 407 */
307void afs_reap_server(struct work_struct *work) 408static void afs_gc_servers(struct afs_net *net, struct afs_server *gc_list)
308{ 409{
309 LIST_HEAD(corpses);
310 struct afs_server *server; 410 struct afs_server *server;
311 struct afs_net *net = container_of(work, struct afs_net, server_reaper); 411 bool deleted;
312 unsigned long delay, expiry; 412 int usage;
313 time64_t now; 413
314 414 while ((server = gc_list)) {
315 now = ktime_get_real_seconds(); 415 gc_list = server->gc_next;
316 spin_lock(&net->server_graveyard_lock); 416
317 417 write_seqlock(&net->fs_lock);
318 while (!list_empty(&net->server_graveyard)) { 418 usage = 1;
319 server = list_entry(net->server_graveyard.next, 419 deleted = atomic_try_cmpxchg(&server->usage, &usage, 0);
320 struct afs_server, grave); 420 if (deleted) {
321 421 rb_erase(&server->uuid_rb, &net->fs_servers);
322 /* the queue is ordered most dead first */ 422 hlist_del_rcu(&server->proc_link);
323 if (net->live) {
324 expiry = server->time_of_death + afs_server_timeout;
325 if (expiry > now) {
326 delay = (expiry - now);
327 afs_set_server_timer(net, delay);
328 break;
329 }
330 } 423 }
424 write_sequnlock(&net->fs_lock);
331 425
332 write_lock(&server->cell->servers_lock); 426 if (deleted)
333 write_lock(&net->servers_lock); 427 afs_destroy_server(net, server);
334 if (atomic_read(&server->usage) > 0) { 428 }
335 list_del_init(&server->grave); 429}
336 } else { 430
337 list_move_tail(&server->grave, &corpses); 431/*
338 list_del_init(&server->link); 432 * Manage the records of servers known to be within a network namespace. This
339 rb_erase(&server->master_rb, &net->servers); 433 * includes garbage collecting unused servers.
434 *
435 * Note also that we were given an increment on net->servers_outstanding by
436 * whoever queued us that we need to deal with before returning.
437 */
438void afs_manage_servers(struct work_struct *work)
439{
440 struct afs_net *net = container_of(work, struct afs_net, fs_manager);
441 struct afs_server *gc_list = NULL;
442 struct rb_node *cursor;
443 time64_t now = ktime_get_real_seconds(), next_manage = TIME64_MAX;
444 bool purging = !net->live;
445
446 _enter("");
447
448 /* Trawl the server list looking for servers that have expired from
449 * lack of use.
450 */
451 read_seqlock_excl(&net->fs_lock);
452
453 for (cursor = rb_first(&net->fs_servers); cursor; cursor = rb_next(cursor)) {
454 struct afs_server *server =
455 rb_entry(cursor, struct afs_server, uuid_rb);
456 int usage = atomic_read(&server->usage);
457
458 _debug("manage %pU %u", &server->uuid, usage);
459
460 ASSERTCMP(usage, >=, 1);
461 ASSERTIFCMP(purging, usage, ==, 1);
462
463 if (usage == 1) {
464 time64_t expire_at = server->put_time;
465
466 if (!test_bit(AFS_SERVER_FL_VL_FAIL, &server->flags) &&
467 !test_bit(AFS_SERVER_FL_NOT_FOUND, &server->flags))
468 expire_at += afs_server_gc_delay;
469 if (purging || expire_at <= now) {
470 server->gc_next = gc_list;
471 gc_list = server;
472 } else if (expire_at < next_manage) {
473 next_manage = expire_at;
474 }
340 } 475 }
341 write_unlock(&net->servers_lock);
342 write_unlock(&server->cell->servers_lock);
343 } 476 }
344 477
345 spin_unlock(&net->server_graveyard_lock); 478 read_sequnlock_excl(&net->fs_lock);
346 479
347 /* now reap the corpses we've extracted */ 480 /* Update the timer on the way out. We have to pass an increment on
348 while (!list_empty(&corpses)) { 481 * servers_outstanding in the namespace that we are in to the timer or
349 server = list_entry(corpses.next, struct afs_server, grave); 482 * the work scheduler.
350 list_del(&server->grave); 483 */
351 afs_destroy_server(net, server); 484 if (!purging && next_manage < TIME64_MAX) {
485 now = ktime_get_real_seconds();
486
487 if (next_manage - now <= 0) {
488 if (queue_work(afs_wq, &net->fs_manager))
489 afs_inc_servers_outstanding(net);
490 } else {
491 afs_set_server_timer(net, next_manage - now);
492 }
352 } 493 }
353 494
495 afs_gc_servers(net, gc_list);
496
354 afs_dec_servers_outstanding(net); 497 afs_dec_servers_outstanding(net);
498 _leave(" [%d]", atomic_read(&net->servers_outstanding));
499}
500
501static void afs_queue_server_manager(struct afs_net *net)
502{
503 afs_inc_servers_outstanding(net);
504 if (!queue_work(afs_wq, &net->fs_manager))
505 afs_dec_servers_outstanding(net);
355} 506}
356 507
357/* 508/*
358 * Discard all the server records from a net namespace when it is destroyed or 509 * Purge list of servers.
359 * the afs module is removed.
360 */ 510 */
361void __net_exit afs_purge_servers(struct afs_net *net) 511void afs_purge_servers(struct afs_net *net)
362{ 512{
363 if (del_timer_sync(&net->server_timer)) 513 _enter("");
514
515 if (del_timer_sync(&net->fs_timer))
364 atomic_dec(&net->servers_outstanding); 516 atomic_dec(&net->servers_outstanding);
365 517
366 afs_inc_servers_outstanding(net); 518 afs_queue_server_manager(net);
367 if (!queue_work(afs_wq, &net->server_reaper))
368 afs_dec_servers_outstanding(net);
369 519
520 _debug("wait");
370 wait_on_atomic_t(&net->servers_outstanding, atomic_t_wait, 521 wait_on_atomic_t(&net->servers_outstanding, atomic_t_wait,
371 TASK_UNINTERRUPTIBLE); 522 TASK_UNINTERRUPTIBLE);
523 _leave("");
524}
525
526/*
527 * Probe a fileserver to find its capabilities.
528 *
529 * TODO: Try service upgrade.
530 */
531static bool afs_do_probe_fileserver(struct afs_fs_cursor *fc)
532{
533 _enter("");
534
535 fc->ac.addr = NULL;
536 fc->ac.start = READ_ONCE(fc->ac.alist->index);
537 fc->ac.index = fc->ac.start;
538 fc->ac.error = 0;
539 fc->ac.begun = false;
540
541 while (afs_iterate_addresses(&fc->ac)) {
542 afs_fs_get_capabilities(afs_v2net(fc->vnode), fc->cbi->server,
543 &fc->ac, fc->key);
544 switch (fc->ac.error) {
545 case 0:
546 afs_end_cursor(&fc->ac);
547 set_bit(AFS_SERVER_FL_PROBED, &fc->cbi->server->flags);
548 return true;
549 case -ECONNABORTED:
550 fc->ac.error = afs_abort_to_error(fc->ac.abort_code);
551 goto error;
552 case -ENOMEM:
553 case -ENONET:
554 goto error;
555 case -ENETUNREACH:
556 case -EHOSTUNREACH:
557 case -ECONNREFUSED:
558 case -ETIMEDOUT:
559 case -ETIME:
560 break;
561 default:
562 fc->ac.error = -EIO;
563 goto error;
564 }
565 }
566
567error:
568 afs_end_cursor(&fc->ac);
569 return false;
570}
571
572/*
573 * If we haven't already, try probing the fileserver to get its capabilities.
574 * We try not to instigate parallel probes, but it's possible that the parallel
575 * probes will fail due to authentication failure when ours would succeed.
576 *
577 * TODO: Try sending an anonymous probe if an authenticated probe fails.
578 */
579bool afs_probe_fileserver(struct afs_fs_cursor *fc)
580{
581 bool success;
582 int ret, retries = 0;
583
584 _enter("");
585
586retry:
587 if (test_bit(AFS_SERVER_FL_PROBED, &fc->cbi->server->flags)) {
588 _leave(" = t");
589 return true;
590 }
591
592 if (!test_and_set_bit_lock(AFS_SERVER_FL_PROBING, &fc->cbi->server->flags)) {
593 success = afs_do_probe_fileserver(fc);
594 clear_bit_unlock(AFS_SERVER_FL_PROBING, &fc->cbi->server->flags);
595 wake_up_bit(&fc->cbi->server->flags, AFS_SERVER_FL_PROBING);
596 _leave(" = t");
597 return success;
598 }
599
600 _debug("wait");
601 ret = wait_on_bit(&fc->cbi->server->flags, AFS_SERVER_FL_PROBING,
602 TASK_INTERRUPTIBLE);
603 if (ret == -ERESTARTSYS) {
604 fc->ac.error = ret;
605 _leave(" = f [%d]", ret);
606 return false;
607 }
608
609 retries++;
610 if (retries == 4) {
611 fc->ac.error = -ESTALE;
612 _leave(" = f [stale]");
613 return false;
614 }
615 _debug("retry");
616 goto retry;
617}
618
619/*
620 * Get an update for a server's address list.
621 */
622static noinline bool afs_update_server_record(struct afs_fs_cursor *fc, struct afs_server *server)
623{
624 struct afs_addr_list *alist, *discard;
625
626 _enter("");
627
628 alist = afs_vl_lookup_addrs(fc->vnode->volume->cell, fc->key,
629 &server->uuid);
630 if (IS_ERR(alist)) {
631 fc->ac.error = PTR_ERR(alist);
632 _leave(" = f [%d]", fc->ac.error);
633 return false;
634 }
635
636 discard = alist;
637 if (server->addr_version != alist->version) {
638 write_lock(&server->fs_lock);
639 discard = rcu_dereference_protected(server->addresses,
640 lockdep_is_held(&server->fs_lock));
641 rcu_assign_pointer(server->addresses, alist);
642 server->addr_version = alist->version;
643 write_unlock(&server->fs_lock);
644 }
645
646 server->update_at = ktime_get_real_seconds() + afs_server_update_delay;
647 afs_put_addrlist(discard);
648 _leave(" = t");
649 return true;
650}
651
652/*
653 * See if a server's address list needs updating.
654 */
655bool afs_check_server_record(struct afs_fs_cursor *fc, struct afs_server *server)
656{
657 time64_t now = ktime_get_real_seconds();
658 long diff;
659 bool success;
660 int ret, retries = 0;
661
662 _enter("");
663
664 ASSERT(server);
665
666retry:
667 diff = READ_ONCE(server->update_at) - now;
668 if (diff > 0) {
669 _leave(" = t [not now %ld]", diff);
670 return true;
671 }
672
673 if (!test_and_set_bit_lock(AFS_SERVER_FL_UPDATING, &server->flags)) {
674 success = afs_update_server_record(fc, server);
675 clear_bit_unlock(AFS_SERVER_FL_UPDATING, &server->flags);
676 wake_up_bit(&server->flags, AFS_SERVER_FL_UPDATING);
677 _leave(" = %d", success);
678 return success;
679 }
680
681 ret = wait_on_bit(&server->flags, AFS_SERVER_FL_UPDATING,
682 TASK_INTERRUPTIBLE);
683 if (ret == -ERESTARTSYS) {
684 fc->ac.error = ret;
685 _leave(" = f [intr]");
686 return false;
687 }
688
689 retries++;
690 if (retries == 4) {
691 _leave(" = f [stale]");
692 ret = -ESTALE;
693 return false;
694 }
695 goto retry;
372} 696}
diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c
new file mode 100644
index 000000000000..26bad7032bba
--- /dev/null
+++ b/fs/afs/server_list.c
@@ -0,0 +1,153 @@
1/* AFS fileserver list management.
2 *
3 * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include "internal.h"
15
16void afs_put_serverlist(struct afs_net *net, struct afs_server_list *slist)
17{
18 int i;
19
20 if (refcount_dec_and_test(&slist->usage)) {
21 for (i = 0; i < slist->nr_servers; i++) {
22 afs_put_cb_interest(net, slist->servers[i].cb_interest);
23 afs_put_server(net, slist->servers[i].server);
24 }
25 kfree(slist);
26 }
27}
28
29/*
30 * Build a server list from a VLDB record.
31 */
32struct afs_server_list *afs_alloc_server_list(struct afs_cell *cell,
33 struct key *key,
34 struct afs_vldb_entry *vldb,
35 u8 type_mask)
36{
37 struct afs_server_list *slist;
38 struct afs_server *server;
39 int ret = -ENOMEM, nr_servers = 0, i, j;
40
41 for (i = 0; i < vldb->nr_servers; i++)
42 if (vldb->fs_mask[i] & type_mask)
43 nr_servers++;
44
45 slist = kzalloc(sizeof(struct afs_server_list) +
46 sizeof(struct afs_server_entry) * nr_servers,
47 GFP_KERNEL);
48 if (!slist)
49 goto error;
50
51 refcount_set(&slist->usage, 1);
52
53 /* Make sure a records exists for each server in the list. */
54 for (i = 0; i < vldb->nr_servers; i++) {
55 if (!(vldb->fs_mask[i] & type_mask))
56 continue;
57
58 server = afs_lookup_server(cell, key, &vldb->fs_server[i]);
59 if (IS_ERR(server)) {
60 ret = PTR_ERR(server);
61 if (ret == -ENOENT)
62 continue;
63 goto error_2;
64 }
65
66 /* Insertion-sort by server pointer */
67 for (j = 0; j < slist->nr_servers; j++)
68 if (slist->servers[j].server >= server)
69 break;
70 if (j < slist->nr_servers) {
71 if (slist->servers[j].server == server) {
72 afs_put_server(cell->net, server);
73 continue;
74 }
75
76 memmove(slist->servers + j + 1,
77 slist->servers + j,
78 (slist->nr_servers - j) * sizeof(struct afs_server_entry));
79 }
80
81 slist->servers[j].server = server;
82 slist->nr_servers++;
83 }
84
85 if (slist->nr_servers == 0) {
86 ret = -EDESTADDRREQ;
87 goto error_2;
88 }
89
90 return slist;
91
92error_2:
93 afs_put_serverlist(cell->net, slist);
94error:
95 return ERR_PTR(ret);
96}
97
98/*
99 * Copy the annotations from an old server list to its potential replacement.
100 */
101bool afs_annotate_server_list(struct afs_server_list *new,
102 struct afs_server_list *old)
103{
104 struct afs_server *cur;
105 int i, j;
106
107 if (old->nr_servers != new->nr_servers)
108 goto changed;
109
110 for (i = 0; i < old->nr_servers; i++)
111 if (old->servers[i].server != new->servers[i].server)
112 goto changed;
113
114 return false;
115
116changed:
117 /* Maintain the same current server as before if possible. */
118 cur = old->servers[old->index].server;
119 for (j = 0; j < new->nr_servers; j++) {
120 if (new->servers[j].server == cur) {
121 new->index = j;
122 break;
123 }
124 }
125
126 /* Keep the old callback interest records where possible so that we
127 * maintain callback interception.
128 */
129 i = 0;
130 j = 0;
131 while (i < old->nr_servers && j < new->nr_servers) {
132 if (new->servers[j].server == old->servers[i].server) {
133 struct afs_cb_interest *cbi = old->servers[i].cb_interest;
134 if (cbi) {
135 new->servers[j].cb_interest = cbi;
136 refcount_inc(&cbi->usage);
137 }
138 i++;
139 j++;
140 continue;
141 }
142
143 if (new->servers[j].server < old->servers[i].server) {
144 j++;
145 continue;
146 }
147
148 i++;
149 continue;
150 }
151
152 return true;
153}
diff --git a/fs/afs/super.c b/fs/afs/super.c
index 3d53b78b350d..af1e769aaebf 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -142,9 +142,9 @@ void __exit afs_fs_exit(void)
142 */ 142 */
143static int afs_show_devname(struct seq_file *m, struct dentry *root) 143static int afs_show_devname(struct seq_file *m, struct dentry *root)
144{ 144{
145 struct afs_super_info *as = root->d_sb->s_fs_info; 145 struct afs_super_info *as = AFS_FS_S(root->d_sb);
146 struct afs_volume *volume = as->volume; 146 struct afs_volume *volume = as->volume;
147 struct afs_cell *cell = volume->cell; 147 struct afs_cell *cell = as->cell;
148 const char *suf = ""; 148 const char *suf = "";
149 char pref = '%'; 149 char pref = '%';
150 150
@@ -162,7 +162,7 @@ static int afs_show_devname(struct seq_file *m, struct dentry *root)
162 break; 162 break;
163 } 163 }
164 164
165 seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->vlocation->vldb.name, suf); 165 seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->name, suf);
166 return 0; 166 return 0;
167} 167}
168 168
@@ -334,14 +334,16 @@ static int afs_parse_device_name(struct afs_mount_params *params,
334static int afs_test_super(struct super_block *sb, void *data) 334static int afs_test_super(struct super_block *sb, void *data)
335{ 335{
336 struct afs_super_info *as1 = data; 336 struct afs_super_info *as1 = data;
337 struct afs_super_info *as = sb->s_fs_info; 337 struct afs_super_info *as = AFS_FS_S(sb);
338 338
339 return as->net == as1->net && as->volume == as1->volume; 339 return as->net == as1->net && as->volume->vid == as1->volume->vid;
340} 340}
341 341
342static int afs_set_super(struct super_block *sb, void *data) 342static int afs_set_super(struct super_block *sb, void *data)
343{ 343{
344 sb->s_fs_info = data; 344 struct afs_super_info *as = data;
345
346 sb->s_fs_info = as;
345 return set_anon_super(sb, NULL); 347 return set_anon_super(sb, NULL);
346} 348}
347 349
@@ -351,7 +353,7 @@ static int afs_set_super(struct super_block *sb, void *data)
351static int afs_fill_super(struct super_block *sb, 353static int afs_fill_super(struct super_block *sb,
352 struct afs_mount_params *params) 354 struct afs_mount_params *params)
353{ 355{
354 struct afs_super_info *as = sb->s_fs_info; 356 struct afs_super_info *as = AFS_FS_S(sb);
355 struct afs_fid fid; 357 struct afs_fid fid;
356 struct inode *inode = NULL; 358 struct inode *inode = NULL;
357 int ret; 359 int ret;
@@ -368,13 +370,15 @@ static int afs_fill_super(struct super_block *sb,
368 if (ret) 370 if (ret)
369 return ret; 371 return ret;
370 sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE; 372 sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE;
371 strlcpy(sb->s_id, as->volume->vlocation->vldb.name, sizeof(sb->s_id)); 373 sprintf(sb->s_id, "%u", as->volume->vid);
374
375 afs_activate_volume(as->volume);
372 376
373 /* allocate the root inode and dentry */ 377 /* allocate the root inode and dentry */
374 fid.vid = as->volume->vid; 378 fid.vid = as->volume->vid;
375 fid.vnode = 1; 379 fid.vnode = 1;
376 fid.unique = 1; 380 fid.unique = 1;
377 inode = afs_iget(sb, params->key, &fid, NULL, NULL); 381 inode = afs_iget(sb, params->key, &fid, NULL, NULL, NULL);
378 if (IS_ERR(inode)) 382 if (IS_ERR(inode))
379 return PTR_ERR(inode); 383 return PTR_ERR(inode);
380 384
@@ -426,7 +430,7 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
426{ 430{
427 struct afs_mount_params params; 431 struct afs_mount_params params;
428 struct super_block *sb; 432 struct super_block *sb;
429 struct afs_volume *vol; 433 struct afs_volume *candidate;
430 struct key *key; 434 struct key *key;
431 struct afs_super_info *as; 435 struct afs_super_info *as;
432 int ret; 436 int ret;
@@ -464,15 +468,19 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
464 ret = -ENOMEM; 468 ret = -ENOMEM;
465 as = afs_alloc_sbi(&params); 469 as = afs_alloc_sbi(&params);
466 if (!as) 470 if (!as)
467 goto error; 471 goto error_key;
468 472
469 /* parse the device name */ 473 /* Assume we're going to need a volume record; at the very least we can
470 vol = afs_volume_lookup(&params); 474 * use it to update the volume record if we have one already. This
471 if (IS_ERR(vol)) { 475 * checks that the volume exists within the cell.
472 ret = PTR_ERR(vol); 476 */
473 goto error; 477 candidate = afs_create_volume(&params);
478 if (IS_ERR(candidate)) {
479 ret = PTR_ERR(candidate);
480 goto error_as;
474 } 481 }
475 as->volume = vol; 482
483 as->volume = candidate;
476 484
477 /* allocate a deviceless superblock */ 485 /* allocate a deviceless superblock */
478 sb = sget(fs_type, afs_test_super, afs_set_super, flags, as); 486 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 511
504error_sb: 512error_sb:
505 deactivate_locked_super(sb); 513 deactivate_locked_super(sb);
514 goto error_key;
506error_as: 515error_as:
507 afs_destroy_sbi(as); 516 afs_destroy_sbi(as);
517error_key:
518 key_put(params.key);
508error: 519error:
509 afs_put_cell(params.net, params.cell); 520 afs_put_cell(params.net, params.cell);
510 key_put(params.key);
511 _leave(" = %d", ret); 521 _leave(" = %d", ret);
512 return ERR_PTR(ret); 522 return ERR_PTR(ret);
513} 523}
@@ -519,8 +529,9 @@ static void afs_kill_super(struct super_block *sb)
519 /* Clear the callback interests (which will do ilookup5) before 529 /* Clear the callback interests (which will do ilookup5) before
520 * deactivating the superblock. 530 * deactivating the superblock.
521 */ 531 */
522 afs_clear_callback_interests(as->net, as->volume); 532 afs_clear_callback_interests(as->net, as->volume->servers);
523 kill_anon_super(sb); 533 kill_anon_super(sb);
534 afs_deactivate_volume(as->volume);
524 afs_destroy_sbi(as); 535 afs_destroy_sbi(as);
525} 536}
526 537
@@ -533,7 +544,7 @@ static void afs_i_init_once(void *_vnode)
533 544
534 memset(vnode, 0, sizeof(*vnode)); 545 memset(vnode, 0, sizeof(*vnode));
535 inode_init_once(&vnode->vfs_inode); 546 inode_init_once(&vnode->vfs_inode);
536 init_waitqueue_head(&vnode->update_waitq); 547 mutex_init(&vnode->io_lock);
537 mutex_init(&vnode->validate_lock); 548 mutex_init(&vnode->validate_lock);
538 spin_lock_init(&vnode->writeback_lock); 549 spin_lock_init(&vnode->writeback_lock);
539 spin_lock_init(&vnode->lock); 550 spin_lock_init(&vnode->lock);
@@ -561,7 +572,6 @@ static struct inode *afs_alloc_inode(struct super_block *sb)
561 memset(&vnode->status, 0, sizeof(vnode->status)); 572 memset(&vnode->status, 0, sizeof(vnode->status));
562 573
563 vnode->volume = NULL; 574 vnode->volume = NULL;
564 vnode->update_cnt = 0;
565 vnode->flags = 1 << AFS_VNODE_UNSET; 575 vnode->flags = 1 << AFS_VNODE_UNSET;
566 576
567 _leave(" = %p", &vnode->vfs_inode); 577 _leave(" = %p", &vnode->vfs_inode);
@@ -597,6 +607,7 @@ static void afs_destroy_inode(struct inode *inode)
597 */ 607 */
598static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) 608static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
599{ 609{
610 struct afs_fs_cursor fc;
600 struct afs_volume_status vs; 611 struct afs_volume_status vs;
601 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); 612 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
602 struct key *key; 613 struct key *key;
@@ -606,21 +617,32 @@ static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
606 if (IS_ERR(key)) 617 if (IS_ERR(key))
607 return PTR_ERR(key); 618 return PTR_ERR(key);
608 619
609 ret = afs_vnode_get_volume_status(vnode, key, &vs); 620 ret = -ERESTARTSYS;
610 key_put(key); 621 if (afs_begin_vnode_operation(&fc, vnode, key)) {
611 if (ret < 0) { 622 fc.flags |= AFS_FS_CURSOR_NO_VSLEEP;
612 _leave(" = %d", ret); 623 while (afs_select_fileserver(&fc)) {
613 return ret; 624 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
625 afs_fs_get_volume_status(&fc, &vs);
626 }
627
628 afs_check_for_remote_deletion(&fc, fc.vnode);
629 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
630 ret = afs_end_vnode_operation(&fc);
614 } 631 }
615 632
616 buf->f_type = dentry->d_sb->s_magic; 633 key_put(key);
617 buf->f_bsize = AFS_BLOCK_SIZE;
618 buf->f_namelen = AFSNAMEMAX - 1;
619 634
620 if (vs.max_quota == 0) 635 if (ret == 0) {
621 buf->f_blocks = vs.part_max_blocks; 636 buf->f_type = dentry->d_sb->s_magic;
622 else 637 buf->f_bsize = AFS_BLOCK_SIZE;
623 buf->f_blocks = vs.max_quota; 638 buf->f_namelen = AFSNAMEMAX - 1;
624 buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use; 639
625 return 0; 640 if (vs.max_quota == 0)
641 buf->f_blocks = vs.part_max_blocks;
642 else
643 buf->f_blocks = vs.max_quota;
644 buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use;
645 }
646
647 return ret;
626} 648}
diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c
index 1d1e7df77dd5..173c652fe875 100644
--- a/fs/afs/vlclient.c
+++ b/fs/afs/vlclient.c
@@ -16,14 +16,15 @@
16#include "internal.h" 16#include "internal.h"
17 17
18/* 18/*
19 * deliver reply data to a VL.GetEntryByXXX call 19 * Deliver reply data to a VL.GetEntryByNameU call.
20 */ 20 */
21static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call) 21static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
22{ 22{
23 struct afs_cache_vlocation *entry; 23 struct afs_uvldbentry__xdr *uvldb;
24 __be32 *bp; 24 struct afs_vldb_entry *entry;
25 bool new_only = false;
25 u32 tmp; 26 u32 tmp;
26 int loop, ret; 27 int i, ret;
27 28
28 _enter(""); 29 _enter("");
29 30
@@ -32,152 +33,270 @@ static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call)
32 return ret; 33 return ret;
33 34
34 /* unmarshall the reply once we've received all of it */ 35 /* unmarshall the reply once we've received all of it */
36 uvldb = call->buffer;
35 entry = call->reply[0]; 37 entry = call->reply[0];
36 bp = call->buffer; 38
37 39 for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
38 for (loop = 0; loop < 64; loop++) 40 entry->name[i] = (u8)ntohl(uvldb->name[i]);
39 entry->name[loop] = ntohl(*bp++); 41 entry->name[i] = 0;
40 entry->name[loop] = 0; 42 entry->name_len = strlen(entry->name);
41 bp++; /* final NUL */ 43
42 44 /* If there is a new replication site that we can use, ignore all the
43 bp++; /* type */ 45 * sites that aren't marked as new.
44 entry->nservers = ntohl(*bp++); 46 */
45 47 for (i = 0; i < AFS_NMAXNSERVERS; i++) {
46 for (loop = 0; loop < 8; loop++) { 48 tmp = ntohl(uvldb->serverFlags[i]);
47 entry->servers[loop].srx_family = AF_RXRPC; 49 if (!(tmp & AFS_VLSF_DONTUSE) &&
48 entry->servers[loop].srx_service = FS_SERVICE; 50 (tmp & AFS_VLSF_NEWREPSITE))
49 entry->servers[loop].transport_type = SOCK_DGRAM; 51 new_only = true;
50 entry->servers[loop].transport_len = sizeof(entry->servers[loop].transport.sin6);
51 entry->servers[loop].transport.sin6.sin6_family = AF_INET6;
52 entry->servers[loop].transport.sin6.sin6_port = htons(AFS_FS_PORT);
53 entry->servers[loop].transport.sin6.sin6_flowinfo = 0;
54 entry->servers[loop].transport.sin6.sin6_scope_id = 0;
55 entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[0] = 0;
56 entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[1] = 0;
57 entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[2] = htonl(0xffff);
58 entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[3] = *bp++;
59 } 52 }
60 53
61 bp += 8; /* partition IDs */ 54 for (i = 0; i < AFS_NMAXNSERVERS; i++) {
55 struct afs_uuid__xdr *xdr;
56 struct afs_uuid *uuid;
57 int j;
62 58
63 for (loop = 0; loop < 8; loop++) { 59 tmp = ntohl(uvldb->serverFlags[i]);
64 tmp = ntohl(*bp++); 60 if (tmp & AFS_VLSF_DONTUSE ||
65 entry->srvtmask[loop] = 0; 61 (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
62 continue;
66 if (tmp & AFS_VLSF_RWVOL) 63 if (tmp & AFS_VLSF_RWVOL)
67 entry->srvtmask[loop] |= AFS_VOL_VTM_RW; 64 entry->fs_mask[i] |= AFS_VOL_VTM_RW;
68 if (tmp & AFS_VLSF_ROVOL) 65 if (tmp & AFS_VLSF_ROVOL)
69 entry->srvtmask[loop] |= AFS_VOL_VTM_RO; 66 entry->fs_mask[i] |= AFS_VOL_VTM_RO;
70 if (tmp & AFS_VLSF_BACKVOL) 67 if (tmp & AFS_VLSF_BACKVOL)
71 entry->srvtmask[loop] |= AFS_VOL_VTM_BAK; 68 entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
72 } 69 if (!entry->fs_mask[i])
70 continue;
71
72 xdr = &uvldb->serverNumber[i];
73 uuid = (struct afs_uuid *)&entry->fs_server[i];
74 uuid->time_low = xdr->time_low;
75 uuid->time_mid = htons(ntohl(xdr->time_mid));
76 uuid->time_hi_and_version = htons(ntohl(xdr->time_hi_and_version));
77 uuid->clock_seq_hi_and_reserved = (u8)ntohl(xdr->clock_seq_hi_and_reserved);
78 uuid->clock_seq_low = (u8)ntohl(xdr->clock_seq_low);
79 for (j = 0; j < 6; j++)
80 uuid->node[j] = (u8)ntohl(xdr->node[j]);
73 81
74 entry->vid[0] = ntohl(*bp++); 82 entry->nr_servers++;
75 entry->vid[1] = ntohl(*bp++); 83 }
76 entry->vid[2] = ntohl(*bp++);
77 84
78 bp++; /* clone ID */ 85 for (i = 0; i < AFS_MAXTYPES; i++)
86 entry->vid[i] = ntohl(uvldb->volumeId[i]);
79 87
80 tmp = ntohl(*bp++); /* flags */ 88 tmp = ntohl(uvldb->flags);
81 entry->vidmask = 0;
82 if (tmp & AFS_VLF_RWEXISTS) 89 if (tmp & AFS_VLF_RWEXISTS)
83 entry->vidmask |= AFS_VOL_VTM_RW; 90 __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
84 if (tmp & AFS_VLF_ROEXISTS) 91 if (tmp & AFS_VLF_ROEXISTS)
85 entry->vidmask |= AFS_VOL_VTM_RO; 92 __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
86 if (tmp & AFS_VLF_BACKEXISTS) 93 if (tmp & AFS_VLF_BACKEXISTS)
87 entry->vidmask |= AFS_VOL_VTM_BAK; 94 __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
88 if (!entry->vidmask)
89 return -EBADMSG;
90 95
96 if (!(tmp & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
97 entry->error = -ENOMEDIUM;
98 __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
99 }
100
101 __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
91 _leave(" = 0 [done]"); 102 _leave(" = 0 [done]");
92 return 0; 103 return 0;
93} 104}
94 105
95/* 106static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
96 * VL.GetEntryByName operation type 107{
97 */ 108 kfree(call->reply[0]);
98static const struct afs_call_type afs_RXVLGetEntryByName = { 109 afs_flat_call_destructor(call);
99 .name = "VL.GetEntryByName", 110}
100 .deliver = afs_deliver_vl_get_entry_by_xxx,
101 .destructor = afs_flat_call_destructor,
102};
103 111
104/* 112/*
105 * VL.GetEntryById operation type 113 * VL.GetEntryByNameU operation type.
106 */ 114 */
107static const struct afs_call_type afs_RXVLGetEntryById = { 115static const struct afs_call_type afs_RXVLGetEntryByNameU = {
108 .name = "VL.GetEntryById", 116 .name = "VL.GetEntryByNameU",
109 .deliver = afs_deliver_vl_get_entry_by_xxx, 117 .deliver = afs_deliver_vl_get_entry_by_name_u,
110 .destructor = afs_flat_call_destructor, 118 .destructor = afs_destroy_vl_get_entry_by_name_u,
111}; 119};
112 120
113/* 121/*
114 * dispatch a get volume entry by name operation 122 * Dispatch a get volume entry by name or ID operation (uuid variant). If the
123 * volname is a decimal number then it's a volume ID not a volume name.
115 */ 124 */
116int afs_vl_get_entry_by_name(struct afs_net *net, 125struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *net,
117 struct afs_addr_cursor *ac, 126 struct afs_addr_cursor *ac,
118 struct key *key, 127 struct key *key,
119 const char *volname, 128 const char *volname,
120 struct afs_cache_vlocation *entry, 129 int volnamesz)
121 bool async)
122{ 130{
131 struct afs_vldb_entry *entry;
123 struct afs_call *call; 132 struct afs_call *call;
124 size_t volnamesz, reqsz, padsz; 133 size_t reqsz, padsz;
125 __be32 *bp; 134 __be32 *bp;
126 135
127 _enter(""); 136 _enter("");
128 137
129 volnamesz = strlen(volname);
130 padsz = (4 - (volnamesz & 3)) & 3; 138 padsz = (4 - (volnamesz & 3)) & 3;
131 reqsz = 8 + volnamesz + padsz; 139 reqsz = 8 + volnamesz + padsz;
132 140
133 call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByName, reqsz, 384); 141 entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
134 if (!call) 142 if (!entry)
135 return -ENOMEM; 143 return ERR_PTR(-ENOMEM);
144
145 call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
146 sizeof(struct afs_uvldbentry__xdr));
147 if (!call) {
148 kfree(entry);
149 return ERR_PTR(-ENOMEM);
150 }
136 151
137 call->key = key; 152 call->key = key;
138 call->reply[0] = entry; 153 call->reply[0] = entry;
154 call->ret_reply0 = true;
139 155
140 /* marshall the parameters */ 156 /* Marshall the parameters */
141 bp = call->request; 157 bp = call->request;
142 *bp++ = htonl(VLGETENTRYBYNAME); 158 *bp++ = htonl(VLGETENTRYBYNAMEU);
143 *bp++ = htonl(volnamesz); 159 *bp++ = htonl(volnamesz);
144 memcpy(bp, volname, volnamesz); 160 memcpy(bp, volname, volnamesz);
145 if (padsz > 0) 161 if (padsz > 0)
146 memset((void *) bp + volnamesz, 0, padsz); 162 memset((void *)bp + volnamesz, 0, padsz);
147 163
148 /* initiate the call */ 164 return (struct afs_vldb_entry *)afs_make_call(ac, call, GFP_KERNEL, false);
149 return afs_make_call(ac, call, GFP_KERNEL, async);
150} 165}
151 166
152/* 167/*
153 * dispatch a get volume entry by ID operation 168 * Deliver reply data to a VL.GetAddrsU call.
169 *
170 * GetAddrsU(IN ListAddrByAttributes *inaddr,
171 * OUT afsUUID *uuidp1,
172 * OUT uint32_t *uniquifier,
173 * OUT uint32_t *nentries,
174 * OUT bulkaddrs *blkaddrs);
154 */ 175 */
155int afs_vl_get_entry_by_id(struct afs_net *net, 176static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
156 struct afs_addr_cursor *ac,
157 struct key *key,
158 afs_volid_t volid,
159 afs_voltype_t voltype,
160 struct afs_cache_vlocation *entry,
161 bool async)
162{ 177{
178 struct afs_addr_list *alist;
179 __be32 *bp;
180 u32 uniquifier, nentries, count;
181 int i, ret;
182
183 _enter("{%u,%zu/%u}", call->unmarshall, call->offset, call->count);
184
185again:
186 switch (call->unmarshall) {
187 case 0:
188 call->offset = 0;
189 call->unmarshall++;
190
191 /* Extract the returned uuid, uniquifier, nentries and blkaddrs size */
192 case 1:
193 ret = afs_extract_data(call, call->buffer,
194 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32),
195 true);
196 if (ret < 0)
197 return ret;
198
199 bp = call->buffer + sizeof(struct afs_uuid__xdr);
200 uniquifier = ntohl(*bp++);
201 nentries = ntohl(*bp++);
202 count = ntohl(*bp);
203
204 nentries = min(nentries, count);
205 alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
206 if (!alist)
207 return -ENOMEM;
208 alist->version = uniquifier;
209 call->reply[0] = alist;
210 call->count = count;
211 call->count2 = nentries;
212 call->offset = 0;
213 call->unmarshall++;
214
215 /* Extract entries */
216 case 2:
217 count = min(call->count, 4U);
218 ret = afs_extract_data(call, call->buffer,
219 count * sizeof(__be32),
220 call->count > 4);
221 if (ret < 0)
222 return ret;
223
224 alist = call->reply[0];
225 bp = call->buffer;
226 for (i = 0; i < count; i++)
227 if (alist->nr_addrs < call->count2)
228 afs_merge_fs_addr4(alist, *bp++);
229
230 call->count -= count;
231 if (call->count > 0)
232 goto again;
233 call->offset = 0;
234 call->unmarshall++;
235 break;
236 }
237
238 _leave(" = 0 [done]");
239 return 0;
240}
241
242static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
243{
244 afs_put_server(call->net, (struct afs_server *)call->reply[0]);
245 kfree(call->reply[1]);
246 return afs_flat_call_destructor(call);
247}
248
249/*
250 * VL.GetAddrsU operation type.
251 */
252static const struct afs_call_type afs_RXVLGetAddrsU = {
253 .name = "VL.GetAddrsU",
254 .deliver = afs_deliver_vl_get_addrs_u,
255 .destructor = afs_vl_get_addrs_u_destructor,
256};
257
258/*
259 * Dispatch an operation to get the addresses for a server, where the server is
260 * nominated by UUID.
261 */
262struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *net,
263 struct afs_addr_cursor *ac,
264 struct key *key,
265 const uuid_t *uuid)
266{
267 struct afs_ListAddrByAttributes__xdr *r;
268 const struct afs_uuid *u = (const struct afs_uuid *)uuid;
163 struct afs_call *call; 269 struct afs_call *call;
164 __be32 *bp; 270 __be32 *bp;
271 int i;
165 272
166 _enter(""); 273 _enter("");
167 274
168 call = afs_alloc_flat_call(net, &afs_RXVLGetEntryById, 12, 384); 275 call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
276 sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
277 sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
169 if (!call) 278 if (!call)
170 return -ENOMEM; 279 return ERR_PTR(-ENOMEM);
171 280
172 call->key = key; 281 call->key = key;
173 call->reply[0] = entry; 282 call->reply[0] = NULL;
283 call->ret_reply0 = true;
174 284
175 /* marshall the parameters */ 285 /* Marshall the parameters */
176 bp = call->request; 286 bp = call->request;
177 *bp++ = htonl(VLGETENTRYBYID); 287 *bp++ = htonl(VLGETADDRSU);
178 *bp++ = htonl(volid); 288 r = (struct afs_ListAddrByAttributes__xdr *)bp;
179 *bp = htonl(voltype); 289 r->Mask = htonl(AFS_VLADDR_UUID);
290 r->ipaddr = 0;
291 r->index = 0;
292 r->spare = 0;
293 r->uuid.time_low = u->time_low;
294 r->uuid.time_mid = htonl(ntohs(u->time_mid));
295 r->uuid.time_hi_and_version = htonl(ntohs(u->time_hi_and_version));
296 r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved);
297 r->uuid.clock_seq_low = htonl(u->clock_seq_low);
298 for (i = 0; i < 6; i++)
299 r->uuid.node[i] = ntohl(u->node[i]);
180 300
181 /* initiate the call */ 301 return (struct afs_addr_list *)afs_make_call(ac, call, GFP_KERNEL, false);
182 return afs_make_call(ac, call, GFP_KERNEL, async);
183} 302}
diff --git a/fs/afs/vlocation.c b/fs/afs/vlocation.c
deleted file mode 100644
index 52c31ad0ef60..000000000000
--- a/fs/afs/vlocation.c
+++ /dev/null
@@ -1,669 +0,0 @@
1/* AFS volume location management
2 *
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/init.h>
16#include <linux/sched.h>
17#include "internal.h"
18
19struct workqueue_struct *afs_vlocation_update_worker;
20
21static unsigned afs_vlocation_timeout = 10; /* volume location timeout in seconds */
22static unsigned afs_vlocation_update_timeout = 10 * 60;
23
24/*
25 * iterate through the VL servers in a cell until one of them admits knowing
26 * about the volume in question
27 */
28static int afs_vlocation_access_vl_by_name(struct afs_vlocation *vl,
29 struct key *key,
30 struct afs_cache_vlocation *vldb)
31{
32 struct afs_addr_cursor ac;
33 int ret;
34
35 _enter("%s,%s", vl->cell->name, vl->vldb.name);
36
37 ret = afs_set_vl_cursor(&ac, vl->cell);
38 if (ret < 0)
39 return ret;
40
41 down_write(&vl->cell->vl_sem);
42
43 ret = -ENOMEDIUM;
44 while (afs_iterate_addresses(&ac)) {
45 _debug("CellServ[%hu]: %pIS", ac.index, &ac.addr->transport);
46
47 /* attempt to access the VL server */
48 ac.error = afs_vl_get_entry_by_name(vl->cell->net, &ac, key,
49 vl->vldb.name, vldb, false);
50 switch (ac.error) {
51 case 0:
52 goto out;
53 case -ENOMEM:
54 case -ENONET:
55 case -ENETUNREACH:
56 case -EHOSTUNREACH:
57 case -ECONNREFUSED:
58 if (ac.error == -ENOMEM || ac.error == -ENONET)
59 goto out;
60 break;
61 case -ENOMEDIUM:
62 case -EKEYREJECTED:
63 case -EKEYEXPIRED:
64 ac.responded = true;
65 goto out;
66 default:
67 ac.responded = true;
68 ac.error = -EIO;
69 break;
70 }
71 }
72
73out:
74 up_write(&vl->cell->vl_sem);
75 ret = afs_end_cursor(&ac);
76 _leave(" = %d", ret);
77 return ret;
78}
79
80/*
81 * iterate through the VL servers in a cell until one of them admits knowing
82 * about the volume in question
83 */
84static int afs_vlocation_access_vl_by_id(struct afs_vlocation *vl,
85 struct key *key,
86 afs_volid_t volid,
87 afs_voltype_t voltype,
88 struct afs_cache_vlocation *vldb)
89{
90 struct afs_addr_cursor ac;
91 int ret;
92
93 _enter("%s,%x,%d,", vl->cell->name, volid, voltype);
94
95 ret = afs_set_vl_cursor(&ac, vl->cell);
96 if (ret < 0)
97 return ret;
98
99 down_write(&vl->cell->vl_sem);
100 ret = -ENOMEDIUM;
101 while (afs_iterate_addresses(&ac)) {
102 _debug("CellServ[%hu]: %pIS", ac.index, &ac.addr->transport);
103
104 /* attempt to access the VL server */
105 ac.error = afs_vl_get_entry_by_id(vl->cell->net, &ac, key, volid,
106 voltype, vldb, false);
107 switch (ac.error) {
108 case 0:
109 goto out;
110 case -ENOMEM:
111 case -ENONET:
112 case -ENETUNREACH:
113 case -EHOSTUNREACH:
114 case -ECONNREFUSED:
115 if (ac.error == -ENOMEM || ac.error == -ENONET)
116 goto out;
117 goto rotate;
118 case -EBUSY:
119 ac.responded = true;
120 vl->upd_busy_cnt++;
121 if (vl->upd_busy_cnt <= 3) {
122 if (vl->upd_busy_cnt > 1) {
123 /* second+ BUSY - sleep a little bit */
124 set_current_state(TASK_UNINTERRUPTIBLE);
125 schedule_timeout(1);
126 }
127 continue;
128 }
129 break;
130 case -ENOMEDIUM:
131 ac.responded = true;
132 vl->upd_rej_cnt++;
133 goto rotate;
134 default:
135 ac.responded = true;
136 ac.error = -EIO;
137 goto rotate;
138 }
139
140 /* rotate the server records upon lookup failure */
141 rotate:
142 vl->upd_busy_cnt = 0;
143 }
144
145out:
146 if (ac.error < 0 && vl->upd_rej_cnt > 0) {
147 printk(KERN_NOTICE "kAFS:"
148 " Active volume no longer valid '%s'\n",
149 vl->vldb.name);
150 vl->valid = 0;
151 ac.error = -ENOMEDIUM;
152 }
153
154 up_write(&vl->cell->vl_sem);
155 ret = afs_end_cursor(&ac);
156 _leave(" = %d", ret);
157 return ret;
158}
159
160/*
161 * allocate a volume location record
162 */
163static struct afs_vlocation *afs_vlocation_alloc(struct afs_cell *cell,
164 const char *name,
165 size_t namesz)
166{
167 struct afs_vlocation *vl;
168
169 vl = kzalloc(sizeof(struct afs_vlocation), GFP_KERNEL);
170 if (vl) {
171 vl->cell = cell;
172 vl->state = AFS_VL_NEW;
173 atomic_set(&vl->usage, 1);
174 INIT_LIST_HEAD(&vl->link);
175 INIT_LIST_HEAD(&vl->grave);
176 INIT_LIST_HEAD(&vl->update);
177 init_waitqueue_head(&vl->waitq);
178 spin_lock_init(&vl->lock);
179 memcpy(vl->vldb.name, name, namesz);
180 }
181
182 _leave(" = %p", vl);
183 return vl;
184}
185
186/*
187 * update record if we found it in the cache
188 */
189static int afs_vlocation_update_record(struct afs_vlocation *vl,
190 struct key *key,
191 struct afs_cache_vlocation *vldb)
192{
193 afs_voltype_t voltype;
194 afs_volid_t vid;
195 int ret;
196
197 /* try to look up a cached volume in the cell VL databases by ID */
198 _debug("Locally Cached: %s %02x", vl->vldb.name, vl->vldb.vidmask);
199
200 _debug("Vids: %08x %08x %08x",
201 vl->vldb.vid[0],
202 vl->vldb.vid[1],
203 vl->vldb.vid[2]);
204
205 if (vl->vldb.vidmask & AFS_VOL_VTM_RW) {
206 vid = vl->vldb.vid[0];
207 voltype = AFSVL_RWVOL;
208 } else if (vl->vldb.vidmask & AFS_VOL_VTM_RO) {
209 vid = vl->vldb.vid[1];
210 voltype = AFSVL_ROVOL;
211 } else if (vl->vldb.vidmask & AFS_VOL_VTM_BAK) {
212 vid = vl->vldb.vid[2];
213 voltype = AFSVL_BACKVOL;
214 } else {
215 BUG();
216 vid = 0;
217 voltype = 0;
218 }
219
220 /* contact the server to make sure the volume is still available
221 * - TODO: need to handle disconnected operation here
222 */
223 ret = afs_vlocation_access_vl_by_id(vl, key, vid, voltype, vldb);
224 switch (ret) {
225 /* net error */
226 default:
227 printk(KERN_WARNING "kAFS:"
228 " failed to update volume '%s' (%x) up in '%s': %d\n",
229 vl->vldb.name, vid, vl->cell->name, ret);
230 _leave(" = %d", ret);
231 return ret;
232
233 /* pulled from local cache into memory */
234 case 0:
235 _leave(" = 0");
236 return 0;
237
238 /* uh oh... looks like the volume got deleted */
239 case -ENOMEDIUM:
240 printk(KERN_ERR "kAFS:"
241 " volume '%s' (%x) does not exist '%s'\n",
242 vl->vldb.name, vid, vl->cell->name);
243
244 /* TODO: make existing record unavailable */
245 _leave(" = %d", ret);
246 return ret;
247 }
248}
249
250/*
251 * apply the update to a VL record
252 */
253static void afs_vlocation_apply_update(struct afs_vlocation *vl,
254 struct afs_cache_vlocation *vldb)
255{
256 _debug("Done VL Lookup: %s %02x", vldb->name, vldb->vidmask);
257
258 _debug("Vids: %08x %08x %08x",
259 vldb->vid[0], vldb->vid[1], vldb->vid[2]);
260
261 if (strcmp(vldb->name, vl->vldb.name) != 0)
262 printk(KERN_NOTICE "kAFS:"
263 " name of volume '%s' changed to '%s' on server\n",
264 vl->vldb.name, vldb->name);
265
266 vl->vldb = *vldb;
267}
268
269/*
270 * fill in a volume location record, consulting the cache and the VL server
271 * both
272 */
273static int afs_vlocation_fill_in_record(struct afs_vlocation *vl,
274 struct key *key)
275{
276 struct afs_cache_vlocation vldb;
277 int ret;
278
279 _enter("");
280
281 ASSERTCMP(vl->valid, ==, 0);
282
283 memset(&vldb, 0, sizeof(vldb));
284
285 /* Try to look up an unknown volume in the cell VL databases by name */
286 ret = afs_vlocation_access_vl_by_name(vl, key, &vldb);
287 if (ret < 0) {
288 printk("kAFS: failed to locate '%s' in cell '%s'\n",
289 vl->vldb.name, vl->cell->name);
290 return ret;
291 }
292
293 afs_vlocation_apply_update(vl, &vldb);
294 _leave(" = 0");
295 return 0;
296}
297
298/*
299 * queue a vlocation record for updates
300 */
301static void afs_vlocation_queue_for_updates(struct afs_net *net,
302 struct afs_vlocation *vl)
303{
304 struct afs_vlocation *xvl;
305
306 /* wait at least 10 minutes before updating... */
307 vl->update_at = ktime_get_real_seconds() +
308 afs_vlocation_update_timeout;
309
310 spin_lock(&net->vl_updates_lock);
311
312 if (!list_empty(&net->vl_updates)) {
313 /* ... but wait at least 1 second more than the newest record
314 * already queued so that we don't spam the VL server suddenly
315 * with lots of requests
316 */
317 xvl = list_entry(net->vl_updates.prev,
318 struct afs_vlocation, update);
319 if (vl->update_at <= xvl->update_at)
320 vl->update_at = xvl->update_at + 1;
321 } else if (net->live) {
322 queue_delayed_work(afs_vlocation_update_worker,
323 &net->vl_updater,
324 afs_vlocation_update_timeout * HZ);
325 }
326
327 list_add_tail(&vl->update, &net->vl_updates);
328 spin_unlock(&net->vl_updates_lock);
329}
330
331/*
332 * lookup volume location
333 * - iterate through the VL servers in a cell until one of them admits knowing
334 * about the volume in question
335 * - lookup in the local cache if not able to find on the VL server
336 * - insert/update in the local cache if did get a VL response
337 */
338struct afs_vlocation *afs_vlocation_lookup(struct afs_net *net,
339 struct afs_cell *cell,
340 struct key *key,
341 const char *name,
342 size_t namesz)
343{
344 struct afs_vlocation *vl;
345 int ret;
346
347 _enter("{%s},{%x},%*.*s,%zu",
348 cell->name, key_serial(key),
349 (int) namesz, (int) namesz, name, namesz);
350
351 if (namesz >= sizeof(vl->vldb.name)) {
352 _leave(" = -ENAMETOOLONG");
353 return ERR_PTR(-ENAMETOOLONG);
354 }
355
356 /* see if we have an in-memory copy first */
357 down_write(&cell->vl_sem);
358 spin_lock(&cell->vl_lock);
359 list_for_each_entry(vl, &cell->vl_list, link) {
360 if (vl->vldb.name[namesz] != '\0')
361 continue;
362 if (memcmp(vl->vldb.name, name, namesz) == 0)
363 goto found_in_memory;
364 }
365 spin_unlock(&cell->vl_lock);
366
367 /* not in the cell's in-memory lists - create a new record */
368 vl = afs_vlocation_alloc(cell, name, namesz);
369 if (!vl) {
370 up_write(&cell->vl_sem);
371 return ERR_PTR(-ENOMEM);
372 }
373
374 afs_get_cell(cell);
375
376 list_add_tail(&vl->link, &cell->vl_list);
377 vl->state = AFS_VL_CREATING;
378 up_write(&cell->vl_sem);
379
380fill_in_record:
381 ret = afs_vlocation_fill_in_record(vl, key);
382 if (ret < 0)
383 goto error_abandon;
384 spin_lock(&vl->lock);
385 vl->state = AFS_VL_VALID;
386 spin_unlock(&vl->lock);
387 wake_up(&vl->waitq);
388
389 /* schedule for regular updates */
390 afs_vlocation_queue_for_updates(net, vl);
391 goto success;
392
393found_in_memory:
394 /* found in memory */
395 _debug("found in memory");
396 atomic_inc(&vl->usage);
397 spin_unlock(&cell->vl_lock);
398 if (!list_empty(&vl->grave)) {
399 spin_lock(&net->vl_graveyard_lock);
400 list_del_init(&vl->grave);
401 spin_unlock(&net->vl_graveyard_lock);
402 }
403 up_write(&cell->vl_sem);
404
405 /* see if it was an abandoned record that we might try filling in */
406 spin_lock(&vl->lock);
407 while (vl->state != AFS_VL_VALID) {
408 afs_vlocation_state_t state = vl->state;
409
410 _debug("invalid [state %d]", state);
411
412 if (state == AFS_VL_NEW || state == AFS_VL_NO_VOLUME) {
413 vl->state = AFS_VL_CREATING;
414 spin_unlock(&vl->lock);
415 goto fill_in_record;
416 }
417
418 /* must now wait for creation or update by someone else to
419 * complete */
420 _debug("wait");
421
422 spin_unlock(&vl->lock);
423 ret = wait_event_interruptible(vl->waitq,
424 vl->state == AFS_VL_NEW ||
425 vl->state == AFS_VL_VALID ||
426 vl->state == AFS_VL_NO_VOLUME);
427 if (ret < 0)
428 goto error;
429 spin_lock(&vl->lock);
430 }
431 spin_unlock(&vl->lock);
432
433success:
434 _leave(" = %p", vl);
435 return vl;
436
437error_abandon:
438 spin_lock(&vl->lock);
439 vl->state = AFS_VL_NEW;
440 spin_unlock(&vl->lock);
441 wake_up(&vl->waitq);
442error:
443 ASSERT(vl != NULL);
444 afs_put_vlocation(net, vl);
445 _leave(" = %d", ret);
446 return ERR_PTR(ret);
447}
448
449/*
450 * finish using a volume location record
451 */
452void afs_put_vlocation(struct afs_net *net, struct afs_vlocation *vl)
453{
454 if (!vl)
455 return;
456
457 _enter("%s", vl->vldb.name);
458
459 ASSERTCMP(atomic_read(&vl->usage), >, 0);
460
461 if (likely(!atomic_dec_and_test(&vl->usage))) {
462 _leave("");
463 return;
464 }
465
466 spin_lock(&net->vl_graveyard_lock);
467 if (atomic_read(&vl->usage) == 0) {
468 _debug("buried");
469 list_move_tail(&vl->grave, &net->vl_graveyard);
470 vl->time_of_death = ktime_get_real_seconds();
471 queue_delayed_work(afs_wq, &net->vl_reaper,
472 afs_vlocation_timeout * HZ);
473
474 /* suspend updates on this record */
475 if (!list_empty(&vl->update)) {
476 spin_lock(&net->vl_updates_lock);
477 list_del_init(&vl->update);
478 spin_unlock(&net->vl_updates_lock);
479 }
480 }
481 spin_unlock(&net->vl_graveyard_lock);
482 _leave(" [killed?]");
483}
484
485/*
486 * destroy a dead volume location record
487 */
488static void afs_vlocation_destroy(struct afs_net *net, struct afs_vlocation *vl)
489{
490 _enter("%p", vl);
491
492 afs_put_cell(net, vl->cell);
493 kfree(vl);
494}
495
496/*
497 * reap dead volume location records
498 */
499void afs_vlocation_reaper(struct work_struct *work)
500{
501 LIST_HEAD(corpses);
502 struct afs_vlocation *vl;
503 struct afs_net *net = container_of(work, struct afs_net, vl_reaper.work);
504 unsigned long delay, expiry;
505 time64_t now;
506
507 _enter("");
508
509 now = ktime_get_real_seconds();
510 spin_lock(&net->vl_graveyard_lock);
511
512 while (!list_empty(&net->vl_graveyard)) {
513 vl = list_entry(net->vl_graveyard.next,
514 struct afs_vlocation, grave);
515
516 _debug("check %p", vl);
517
518 /* the queue is ordered most dead first */
519 if (net->live) {
520 expiry = vl->time_of_death + afs_vlocation_timeout;
521 if (expiry > now) {
522 delay = (expiry - now) * HZ;
523 _debug("delay %lu", delay);
524 mod_delayed_work(afs_wq, &net->vl_reaper, delay);
525 break;
526 }
527 }
528
529 spin_lock(&vl->cell->vl_lock);
530 if (atomic_read(&vl->usage) > 0) {
531 _debug("no reap");
532 list_del_init(&vl->grave);
533 } else {
534 _debug("reap");
535 list_move_tail(&vl->grave, &corpses);
536 list_del_init(&vl->link);
537 }
538 spin_unlock(&vl->cell->vl_lock);
539 }
540
541 spin_unlock(&net->vl_graveyard_lock);
542
543 /* now reap the corpses we've extracted */
544 while (!list_empty(&corpses)) {
545 vl = list_entry(corpses.next, struct afs_vlocation, grave);
546 list_del(&vl->grave);
547 afs_vlocation_destroy(net, vl);
548 }
549
550 _leave("");
551}
552
553/*
554 * discard all the volume location records for rmmod
555 */
556void __net_exit afs_vlocation_purge(struct afs_net *net)
557{
558 spin_lock(&net->vl_updates_lock);
559 list_del_init(&net->vl_updates);
560 spin_unlock(&net->vl_updates_lock);
561 mod_delayed_work(afs_vlocation_update_worker, &net->vl_updater, 0);
562 mod_delayed_work(afs_wq, &net->vl_reaper, 0);
563}
564
565/*
566 * update a volume location
567 */
568void afs_vlocation_updater(struct work_struct *work)
569{
570 struct afs_cache_vlocation vldb;
571 struct afs_vlocation *vl, *xvl;
572 struct afs_net *net = container_of(work, struct afs_net, vl_updater.work);
573 time64_t now;
574 long timeout;
575 int ret;
576
577 if (!net->live)
578 return;
579
580 _enter("");
581
582 now = ktime_get_real_seconds();
583
584 /* find a record to update */
585 spin_lock(&net->vl_updates_lock);
586 for (;;) {
587 if (list_empty(&net->vl_updates) || !net->live) {
588 spin_unlock(&net->vl_updates_lock);
589 _leave(" [nothing]");
590 return;
591 }
592
593 vl = list_entry(net->vl_updates.next,
594 struct afs_vlocation, update);
595 if (atomic_read(&vl->usage) > 0)
596 break;
597 list_del_init(&vl->update);
598 }
599
600 timeout = vl->update_at - now;
601 if (timeout > 0) {
602 queue_delayed_work(afs_vlocation_update_worker,
603 &net->vl_updater, timeout * HZ);
604 spin_unlock(&net->vl_updates_lock);
605 _leave(" [nothing]");
606 return;
607 }
608
609 list_del_init(&vl->update);
610 atomic_inc(&vl->usage);
611 spin_unlock(&net->vl_updates_lock);
612
613 /* we can now perform the update */
614 _debug("update %s", vl->vldb.name);
615 vl->state = AFS_VL_UPDATING;
616 vl->upd_rej_cnt = 0;
617 vl->upd_busy_cnt = 0;
618
619 ret = afs_vlocation_update_record(vl, NULL, &vldb);
620 spin_lock(&vl->lock);
621 switch (ret) {
622 case 0:
623 afs_vlocation_apply_update(vl, &vldb);
624 vl->state = AFS_VL_VALID;
625 break;
626 case -ENOMEDIUM:
627 vl->state = AFS_VL_VOLUME_DELETED;
628 break;
629 default:
630 vl->state = AFS_VL_UNCERTAIN;
631 break;
632 }
633 spin_unlock(&vl->lock);
634 wake_up(&vl->waitq);
635
636 /* and then reschedule */
637 _debug("reschedule");
638 vl->update_at = ktime_get_real_seconds() +
639 afs_vlocation_update_timeout;
640
641 spin_lock(&net->vl_updates_lock);
642
643 if (!list_empty(&net->vl_updates)) {
644 /* next update in 10 minutes, but wait at least 1 second more
645 * than the newest record already queued so that we don't spam
646 * the VL server suddenly with lots of requests
647 */
648 xvl = list_entry(net->vl_updates.prev,
649 struct afs_vlocation, update);
650 if (vl->update_at <= xvl->update_at)
651 vl->update_at = xvl->update_at + 1;
652 xvl = list_entry(net->vl_updates.next,
653 struct afs_vlocation, update);
654 timeout = xvl->update_at - now;
655 if (timeout < 0)
656 timeout = 0;
657 } else {
658 timeout = afs_vlocation_update_timeout;
659 }
660
661 ASSERT(list_empty(&vl->update));
662
663 list_add_tail(&vl->update, &net->vl_updates);
664
665 _debug("timeout %ld", timeout);
666 queue_delayed_work(afs_vlocation_update_worker, &net->vl_updater, timeout * HZ);
667 spin_unlock(&net->vl_updates_lock);
668 afs_put_vlocation(net, vl);
669}
diff --git a/fs/afs/vnode.c b/fs/afs/vnode.c
deleted file mode 100644
index 9c7333eb01c2..000000000000
--- a/fs/afs/vnode.c
+++ /dev/null
@@ -1,750 +0,0 @@
1/* AFS vnode management
2 *
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/fs.h>
16#include <linux/sched.h>
17#include "internal.h"
18
19/*
20 * Handle remote file deletion.
21 */
22static void afs_vnode_deleted_remotely(struct afs_vnode *vnode)
23{
24 struct afs_cb_interest *cbi = vnode->cb_interest;
25
26 _enter("{%p}", cbi);
27
28 set_bit(AFS_VNODE_DELETED, &vnode->flags);
29
30 if (cbi) {
31 vnode->cb_interest = NULL;
32 afs_put_cb_interest(afs_v2net(vnode), cbi);
33 }
34
35 _leave("");
36}
37
38/*
39 * finish off updating the recorded status of a file after a successful
40 * operation completion
41 * - starts callback expiry timer
42 * - adds to server's callback list
43 */
44void afs_vnode_finalise_status_update(struct afs_vnode *vnode,
45 struct afs_server *server)
46{
47 spin_lock(&vnode->lock);
48 vnode->update_cnt--;
49 ASSERTCMP(vnode->update_cnt, >=, 0);
50 spin_unlock(&vnode->lock);
51
52 wake_up_all(&vnode->update_waitq);
53 _leave("");
54}
55
56/*
57 * finish off updating the recorded status of a file after an operation failed
58 */
59static void afs_vnode_status_update_failed(struct afs_fs_cursor *fc,
60 struct afs_vnode *vnode)
61{
62 _enter("{%x:%u},%d", vnode->fid.vid, vnode->fid.vnode, fc->ac.error);
63
64 spin_lock(&vnode->lock);
65
66 if (fc->ac.error == -ENOENT) {
67 /* the file was deleted on the server */
68 _debug("got NOENT from server - marking file deleted");
69 afs_vnode_deleted_remotely(vnode);
70 }
71
72 vnode->update_cnt--;
73 ASSERTCMP(vnode->update_cnt, >=, 0);
74 spin_unlock(&vnode->lock);
75
76 wake_up_all(&vnode->update_waitq);
77 _leave("");
78}
79
80/*
81 * fetch file status from the volume
82 * - don't issue a fetch if:
83 * - the changed bit is not set and there's a valid callback
84 * - there are any outstanding ops that will fetch the status
85 * - TODO implement local caching
86 */
87int afs_vnode_fetch_status(struct afs_vnode *vnode, struct key *key, bool force)
88{
89 struct afs_fs_cursor fc;
90 unsigned int cb_break = 0;
91
92 DECLARE_WAITQUEUE(myself, current);
93
94 _enter("%s,{%x:%u.%u,S=%lx},%u",
95 vnode->volume->vlocation->vldb.name,
96 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique,
97 vnode->flags,
98 force);
99
100 if (!force && test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
101 _leave(" [unchanged]");
102 return 0;
103 }
104
105 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
106 _leave(" [deleted]");
107 return -ENOENT;
108 }
109
110 cb_break = vnode->cb_break + vnode->cb_s_break;
111
112 spin_lock(&vnode->lock);
113
114 if (!force && test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
115 spin_unlock(&vnode->lock);
116 _leave(" [unchanged]");
117 return 0;
118 }
119
120 ASSERTCMP(vnode->update_cnt, >=, 0);
121
122 if (vnode->update_cnt > 0) {
123 /* someone else started a fetch */
124 _debug("wait on fetch %d", vnode->update_cnt);
125
126 set_current_state(TASK_UNINTERRUPTIBLE);
127 ASSERT(myself.func != NULL);
128 add_wait_queue(&vnode->update_waitq, &myself);
129
130 /* wait for the status to be updated */
131 for (;;) {
132 if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags))
133 break;
134 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
135 break;
136
137 /* check to see if it got updated and invalidated all
138 * before we saw it */
139 if (vnode->update_cnt == 0) {
140 remove_wait_queue(&vnode->update_waitq,
141 &myself);
142 set_current_state(TASK_RUNNING);
143 goto get_anyway;
144 }
145
146 spin_unlock(&vnode->lock);
147
148 schedule();
149 set_current_state(TASK_UNINTERRUPTIBLE);
150
151 spin_lock(&vnode->lock);
152 }
153
154 remove_wait_queue(&vnode->update_waitq, &myself);
155 spin_unlock(&vnode->lock);
156 set_current_state(TASK_RUNNING);
157
158 return test_bit(AFS_VNODE_DELETED, &vnode->flags) ?
159 -ENOENT : 0;
160 }
161
162get_anyway:
163 /* okay... we're going to have to initiate the op */
164 vnode->update_cnt++;
165
166 spin_unlock(&vnode->lock);
167
168 /* merge AFS status fetches and clear outstanding callback on this
169 * vnode */
170 afs_init_fs_cursor(&fc, vnode);
171 do {
172 /* pick a server to query */
173 if (!afs_volume_pick_fileserver(&fc, vnode))
174 goto no_server;
175
176 fc.ac.error = afs_fs_fetch_file_status(&fc, key, vnode, NULL, false);
177
178 } while (afs_iterate_fs_cursor(&fc, vnode));
179
180 /* adjust the flags */
181 if (fc.ac.error == 0) {
182 _debug("adjust");
183 afs_cache_permit(vnode, key, cb_break);
184 afs_vnode_finalise_status_update(vnode, fc.server);
185 } else {
186 _debug("failed [%d]", fc.ac.error);
187 afs_vnode_status_update_failed(&fc, vnode);
188 }
189
190out:
191 afs_end_fs_cursor(&fc, afs_v2net(vnode));
192 ASSERTCMP(vnode->update_cnt, >=, 0);
193 _leave(" = %d [cnt %d]", fc.ac.error, vnode->update_cnt);
194 return fc.ac.error;
195
196no_server:
197 spin_lock(&vnode->lock);
198 vnode->update_cnt--;
199 spin_unlock(&vnode->lock);
200 goto out;
201}
202
203/*
204 * fetch file data from the volume
205 * - TODO implement caching
206 */
207int afs_vnode_fetch_data(struct afs_vnode *vnode, struct key *key,
208 struct afs_read *desc)
209{
210 struct afs_fs_cursor fc;
211
212 _enter("%s{%x:%u.%u},%x,,,",
213 vnode->volume->vlocation->vldb.name,
214 vnode->fid.vid,
215 vnode->fid.vnode,
216 vnode->fid.unique,
217 key_serial(key));
218
219 /* this op will fetch the status */
220 spin_lock(&vnode->lock);
221 vnode->update_cnt++;
222 spin_unlock(&vnode->lock);
223
224 /* merge in AFS status fetches and clear outstanding callback on this
225 * vnode */
226 afs_init_fs_cursor(&fc, vnode);
227 do {
228 /* pick a server to query */
229 if (!afs_volume_pick_fileserver(&fc, vnode))
230 goto no_server;
231
232 fc.ac.error = afs_fs_fetch_data(&fc, key, vnode, desc, false);
233
234 } while (afs_iterate_fs_cursor(&fc, vnode));
235
236 /* adjust the flags */
237 if (fc.ac.error == 0)
238 afs_vnode_finalise_status_update(vnode, fc.server);
239 else
240 afs_vnode_status_update_failed(&fc, vnode);
241
242out:
243 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
244
245no_server:
246 spin_lock(&vnode->lock);
247 vnode->update_cnt--;
248 ASSERTCMP(vnode->update_cnt, >=, 0);
249 spin_unlock(&vnode->lock);
250 goto out;
251}
252
253/*
254 * make a file or a directory
255 */
256int afs_vnode_create(struct afs_vnode *vnode, struct key *key,
257 const char *name, umode_t mode, struct afs_fid *newfid,
258 struct afs_file_status *newstatus,
259 struct afs_callback *newcb, struct afs_server **_server)
260{
261 struct afs_fs_cursor fc;
262
263 _enter("%s{%x:%u.%u},%x,%s,,",
264 vnode->volume->vlocation->vldb.name,
265 vnode->fid.vid,
266 vnode->fid.vnode,
267 vnode->fid.unique,
268 key_serial(key),
269 name);
270
271 /* this op will fetch the status on the directory we're creating in */
272 spin_lock(&vnode->lock);
273 vnode->update_cnt++;
274 spin_unlock(&vnode->lock);
275
276 afs_init_fs_cursor(&fc, vnode);
277 do {
278 /* pick a server to query */
279 if (!afs_volume_pick_fileserver(&fc, vnode))
280 goto no_server;
281
282 fc.ac.error = afs_fs_create(&fc, key, vnode, name, mode, newfid,
283 newstatus, newcb, false);
284
285 } while (afs_iterate_fs_cursor(&fc, vnode));
286
287 /* adjust the flags */
288 if (fc.ac.error == 0) {
289 afs_vnode_finalise_status_update(vnode, fc.server);
290 *_server = fc.server;
291 fc.server = NULL;
292 } else {
293 afs_vnode_status_update_failed(&fc, vnode);
294 *_server = NULL;
295 }
296
297out:
298 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
299
300no_server:
301 spin_lock(&vnode->lock);
302 vnode->update_cnt--;
303 ASSERTCMP(vnode->update_cnt, >=, 0);
304 spin_unlock(&vnode->lock);
305 goto out;
306}
307
308/*
309 * remove a file or directory
310 */
311int afs_vnode_remove(struct afs_vnode *vnode, struct key *key, const char *name,
312 bool isdir)
313{
314 struct afs_fs_cursor fc;
315
316 _enter("%s{%x:%u.%u},%x,%s",
317 vnode->volume->vlocation->vldb.name,
318 vnode->fid.vid,
319 vnode->fid.vnode,
320 vnode->fid.unique,
321 key_serial(key),
322 name);
323
324 /* this op will fetch the status on the directory we're removing from */
325 spin_lock(&vnode->lock);
326 vnode->update_cnt++;
327 spin_unlock(&vnode->lock);
328
329 afs_init_fs_cursor(&fc, vnode);
330 do {
331 /* pick a server to query */
332 if (!afs_volume_pick_fileserver(&fc, vnode))
333 goto no_server;
334
335 fc.ac.error = afs_fs_remove(&fc, key, vnode, name, isdir, false);
336
337 } while (afs_iterate_fs_cursor(&fc, vnode));
338
339 /* adjust the flags */
340 if (fc.ac.error == 0)
341 afs_vnode_finalise_status_update(vnode, fc.server);
342 else
343 afs_vnode_status_update_failed(&fc, vnode);
344
345out:
346 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
347
348no_server:
349 spin_lock(&vnode->lock);
350 vnode->update_cnt--;
351 ASSERTCMP(vnode->update_cnt, >=, 0);
352 spin_unlock(&vnode->lock);
353 goto out;
354}
355
356/*
357 * create a hard link
358 */
359int afs_vnode_link(struct afs_vnode *dvnode, struct afs_vnode *vnode,
360 struct key *key, const char *name)
361{
362 struct afs_fs_cursor fc;
363
364 _enter("%s{%x:%u.%u},%s{%x:%u.%u},%x,%s",
365 dvnode->volume->vlocation->vldb.name,
366 dvnode->fid.vid,
367 dvnode->fid.vnode,
368 dvnode->fid.unique,
369 vnode->volume->vlocation->vldb.name,
370 vnode->fid.vid,
371 vnode->fid.vnode,
372 vnode->fid.unique,
373 key_serial(key),
374 name);
375
376 /* this op will fetch the status on the directory we're removing from */
377 spin_lock(&vnode->lock);
378 vnode->update_cnt++;
379 spin_unlock(&vnode->lock);
380 spin_lock(&dvnode->lock);
381 dvnode->update_cnt++;
382 spin_unlock(&dvnode->lock);
383
384 afs_init_fs_cursor(&fc, vnode);
385 do {
386 /* pick a server to query */
387 if (!afs_volume_pick_fileserver(&fc, dvnode))
388 goto no_server;
389
390 fc.ac.error = afs_fs_link(&fc, key, dvnode, vnode, name, false);
391
392 } while (afs_iterate_fs_cursor(&fc, dvnode));
393
394 /* adjust the flags */
395 if (fc.ac.error == 0) {
396 afs_vnode_finalise_status_update(vnode, fc.server);
397 afs_vnode_finalise_status_update(dvnode, fc.server);
398 } else {
399 afs_vnode_status_update_failed(&fc, vnode);
400 afs_vnode_status_update_failed(&fc, dvnode);
401 }
402
403out:
404 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
405
406no_server:
407 spin_lock(&vnode->lock);
408 vnode->update_cnt--;
409 ASSERTCMP(vnode->update_cnt, >=, 0);
410 spin_unlock(&vnode->lock);
411 spin_lock(&dvnode->lock);
412 dvnode->update_cnt--;
413 ASSERTCMP(dvnode->update_cnt, >=, 0);
414 spin_unlock(&dvnode->lock);
415 goto out;
416}
417
418/*
419 * create a symbolic link
420 */
421int afs_vnode_symlink(struct afs_vnode *vnode, struct key *key,
422 const char *name, const char *content,
423 struct afs_fid *newfid,
424 struct afs_file_status *newstatus,
425 struct afs_server **_server)
426{
427 struct afs_fs_cursor fc;
428
429 _enter("%s{%x:%u.%u},%x,%s,%s,,,",
430 vnode->volume->vlocation->vldb.name,
431 vnode->fid.vid,
432 vnode->fid.vnode,
433 vnode->fid.unique,
434 key_serial(key),
435 name, content);
436
437 /* this op will fetch the status on the directory we're creating in */
438 spin_lock(&vnode->lock);
439 vnode->update_cnt++;
440 spin_unlock(&vnode->lock);
441
442 afs_init_fs_cursor(&fc, vnode);
443 do {
444 /* pick a server to query */
445 if (!afs_volume_pick_fileserver(&fc, vnode))
446 goto no_server;
447
448 fc.ac.error = afs_fs_symlink(&fc, key, vnode, name, content,
449 newfid, newstatus, false);
450
451 } while (afs_iterate_fs_cursor(&fc, vnode));
452
453 /* adjust the flags */
454 if (fc.ac.error == 0) {
455 afs_vnode_finalise_status_update(vnode, fc.server);
456 *_server = fc.server;
457 fc.server = NULL;
458 } else {
459 afs_vnode_status_update_failed(&fc, vnode);
460 *_server = NULL;
461 }
462
463out:
464 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
465
466no_server:
467 spin_lock(&vnode->lock);
468 vnode->update_cnt--;
469 ASSERTCMP(vnode->update_cnt, >=, 0);
470 spin_unlock(&vnode->lock);
471 *_server = NULL;
472 goto out;
473}
474
475/*
476 * rename a file
477 */
478int afs_vnode_rename(struct afs_vnode *orig_dvnode,
479 struct afs_vnode *new_dvnode,
480 struct key *key,
481 const char *orig_name,
482 const char *new_name)
483{
484 struct afs_fs_cursor fc;
485
486 _enter("%s{%x:%u.%u},%s{%u,%u,%u},%x,%s,%s",
487 orig_dvnode->volume->vlocation->vldb.name,
488 orig_dvnode->fid.vid,
489 orig_dvnode->fid.vnode,
490 orig_dvnode->fid.unique,
491 new_dvnode->volume->vlocation->vldb.name,
492 new_dvnode->fid.vid,
493 new_dvnode->fid.vnode,
494 new_dvnode->fid.unique,
495 key_serial(key),
496 orig_name,
497 new_name);
498
499 /* this op will fetch the status on both the directories we're dealing
500 * with */
501 spin_lock(&orig_dvnode->lock);
502 orig_dvnode->update_cnt++;
503 spin_unlock(&orig_dvnode->lock);
504 if (new_dvnode != orig_dvnode) {
505 spin_lock(&new_dvnode->lock);
506 new_dvnode->update_cnt++;
507 spin_unlock(&new_dvnode->lock);
508 }
509
510 afs_init_fs_cursor(&fc, orig_dvnode);
511 do {
512 /* pick a server to query */
513 if (!afs_volume_pick_fileserver(&fc, orig_dvnode))
514 goto no_server;
515
516 fc.ac.error = afs_fs_rename(&fc, key, orig_dvnode, orig_name,
517 new_dvnode, new_name, false);
518
519 } while (afs_iterate_fs_cursor(&fc, orig_dvnode));
520
521 /* adjust the flags */
522 if (fc.ac.error == 0) {
523 afs_vnode_finalise_status_update(orig_dvnode, fc.server);
524 if (new_dvnode != orig_dvnode)
525 afs_vnode_finalise_status_update(new_dvnode, fc.server);
526 } else {
527 afs_vnode_status_update_failed(&fc, orig_dvnode);
528 if (new_dvnode != orig_dvnode)
529 afs_vnode_status_update_failed(&fc, new_dvnode);
530 }
531
532out:
533 return afs_end_fs_cursor(&fc, afs_v2net(orig_dvnode));
534
535no_server:
536 spin_lock(&orig_dvnode->lock);
537 orig_dvnode->update_cnt--;
538 ASSERTCMP(orig_dvnode->update_cnt, >=, 0);
539 spin_unlock(&orig_dvnode->lock);
540 if (new_dvnode != orig_dvnode) {
541 spin_lock(&new_dvnode->lock);
542 new_dvnode->update_cnt--;
543 ASSERTCMP(new_dvnode->update_cnt, >=, 0);
544 spin_unlock(&new_dvnode->lock);
545 }
546 goto out;
547}
548
549/*
550 * write to a file
551 */
552int afs_vnode_store_data(struct afs_writeback *wb, pgoff_t first, pgoff_t last,
553 unsigned offset, unsigned to)
554{
555 struct afs_fs_cursor fc;
556 struct afs_vnode *vnode = wb->vnode;
557
558 _enter("%s{%x:%u.%u},%x,%lx,%lx,%x,%x",
559 vnode->volume->vlocation->vldb.name,
560 vnode->fid.vid,
561 vnode->fid.vnode,
562 vnode->fid.unique,
563 key_serial(wb->key),
564 first, last, offset, to);
565
566 /* this op will fetch the status */
567 spin_lock(&vnode->lock);
568 vnode->update_cnt++;
569 spin_unlock(&vnode->lock);
570
571 afs_init_fs_cursor(&fc, vnode);
572 do {
573 /* pick a server to query */
574 if (!afs_volume_pick_fileserver(&fc, vnode))
575 goto no_server;
576
577 fc.ac.error = afs_fs_store_data(&fc, wb, first, last, offset, to,
578 false);
579
580 } while (afs_iterate_fs_cursor(&fc, vnode));
581
582 /* adjust the flags */
583 if (fc.ac.error == 0) {
584 afs_vnode_finalise_status_update(vnode, fc.server);
585 } else {
586 afs_vnode_status_update_failed(&fc, vnode);
587 }
588
589out:
590 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
591
592no_server:
593 spin_lock(&vnode->lock);
594 vnode->update_cnt--;
595 ASSERTCMP(vnode->update_cnt, >=, 0);
596 spin_unlock(&vnode->lock);
597 goto out;
598}
599
600/*
601 * set the attributes on a file
602 */
603int afs_vnode_setattr(struct afs_vnode *vnode, struct key *key,
604 struct iattr *attr)
605{
606 struct afs_fs_cursor fc;
607
608 _enter("%s{%x:%u.%u},%x",
609 vnode->volume->vlocation->vldb.name,
610 vnode->fid.vid,
611 vnode->fid.vnode,
612 vnode->fid.unique,
613 key_serial(key));
614
615 /* this op will fetch the status */
616 spin_lock(&vnode->lock);
617 vnode->update_cnt++;
618 spin_unlock(&vnode->lock);
619
620 afs_init_fs_cursor(&fc, vnode);
621 do {
622 /* pick a server to query */
623 if (!afs_volume_pick_fileserver(&fc, vnode))
624 goto no_server;
625
626 fc.ac.error = afs_fs_setattr(&fc, key, vnode, attr, false);
627
628 } while (afs_iterate_fs_cursor(&fc, vnode));
629
630 /* adjust the flags */
631 if (fc.ac.error == 0) {
632 afs_vnode_finalise_status_update(vnode, fc.server);
633 } else {
634 afs_vnode_status_update_failed(&fc, vnode);
635 }
636
637out:
638 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
639
640no_server:
641 spin_lock(&vnode->lock);
642 vnode->update_cnt--;
643 ASSERTCMP(vnode->update_cnt, >=, 0);
644 spin_unlock(&vnode->lock);
645 goto out;
646}
647
648/*
649 * get the status of a volume
650 */
651int afs_vnode_get_volume_status(struct afs_vnode *vnode, struct key *key,
652 struct afs_volume_status *vs)
653{
654 struct afs_fs_cursor fc;
655
656 _enter("%s{%x:%u.%u},%x,",
657 vnode->volume->vlocation->vldb.name,
658 vnode->fid.vid,
659 vnode->fid.vnode,
660 vnode->fid.unique,
661 key_serial(key));
662
663 afs_init_fs_cursor(&fc, vnode);
664 do {
665 /* pick a server to query */
666 if (!afs_volume_pick_fileserver(&fc, vnode))
667 break;
668
669 fc.ac.error = afs_fs_get_volume_status(&fc, key, vnode, vs, false);
670
671 } while (afs_iterate_fs_cursor(&fc, vnode));
672
673 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
674}
675
676/*
677 * get a lock on a file
678 */
679int afs_vnode_set_lock(struct afs_vnode *vnode, struct key *key,
680 afs_lock_type_t type)
681{
682 struct afs_fs_cursor fc;
683
684 _enter("%s{%x:%u.%u},%x,%u",
685 vnode->volume->vlocation->vldb.name,
686 vnode->fid.vid,
687 vnode->fid.vnode,
688 vnode->fid.unique,
689 key_serial(key), type);
690
691 afs_init_fs_cursor(&fc, vnode);
692 do {
693 /* pick a server to query */
694 if (!afs_volume_pick_fileserver(&fc, vnode))
695 break;
696
697 fc.ac.error = afs_fs_set_lock(&fc, key, vnode, type, false);
698
699 } while (afs_iterate_fs_cursor(&fc, vnode));
700
701 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
702}
703
704/*
705 * extend a lock on a file
706 */
707int afs_vnode_extend_lock(struct afs_vnode *vnode, struct key *key)
708{
709 struct afs_fs_cursor fc;
710 int ret;
711
712 _enter("%s{%x:%u.%u},%x",
713 vnode->volume->vlocation->vldb.name,
714 vnode->fid.vid,
715 vnode->fid.vnode,
716 vnode->fid.unique,
717 key_serial(key));
718
719 ret = afs_set_fs_cursor(&fc, vnode);
720 if (ret < 0)
721 return ret;
722
723 fc.ac.error = afs_fs_extend_lock(&fc, key, vnode, false);
724
725 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
726}
727
728/*
729 * release a lock on a file
730 */
731int afs_vnode_release_lock(struct afs_vnode *vnode, struct key *key)
732{
733 struct afs_fs_cursor fc;
734 int ret;
735
736 _enter("%s{%x:%u.%u},%x",
737 vnode->volume->vlocation->vldb.name,
738 vnode->fid.vid,
739 vnode->fid.vnode,
740 vnode->fid.unique,
741 key_serial(key));
742
743 ret = afs_set_fs_cursor(&fc, vnode);
744 if (ret < 0)
745 return ret;
746
747 fc.ac.error = afs_fs_release_lock(&fc, key, vnode, false);
748
749 return afs_end_fs_cursor(&fc, afs_v2net(vnode));
750}
diff --git a/fs/afs/volume.c b/fs/afs/volume.c
index 3c5ad1cc50f3..2295dd4f9b15 100644
--- a/fs/afs/volume.c
+++ b/fs/afs/volume.c
@@ -13,11 +13,148 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include "internal.h" 14#include "internal.h"
15 15
16static const char *afs_voltypes[] = { "R/W", "R/O", "BAK" }; 16unsigned __read_mostly afs_volume_gc_delay = 10;
17unsigned __read_mostly afs_volume_record_life = 60 * 60;
18
19static const char *const afs_voltypes[] = { "R/W", "R/O", "BAK" };
17 20
18/* 21/*
19 * lookup a volume by name 22 * Allocate a volume record and load it up from a vldb record.
20 * - this can be one of the following: 23 */
24static struct afs_volume *afs_alloc_volume(struct afs_mount_params *params,
25 struct afs_vldb_entry *vldb,
26 unsigned long type_mask)
27{
28 struct afs_server_list *slist;
29 struct afs_server *server;
30 struct afs_volume *volume;
31 int ret = -ENOMEM, nr_servers = 0, i, j;
32
33 for (i = 0; i < vldb->nr_servers; i++)
34 if (vldb->fs_mask[i] & type_mask)
35 nr_servers++;
36
37 volume = kzalloc(sizeof(struct afs_volume), GFP_KERNEL);
38 if (!volume)
39 goto error_0;
40
41 volume->vid = vldb->vid[params->type];
42 volume->update_at = ktime_get_real_seconds() + afs_volume_record_life;
43 volume->cell = afs_get_cell(params->cell);
44 volume->type = params->type;
45 volume->type_force = params->force;
46 volume->name_len = vldb->name_len;
47
48 atomic_set(&volume->usage, 1);
49 INIT_LIST_HEAD(&volume->proc_link);
50 rwlock_init(&volume->servers_lock);
51 memcpy(volume->name, vldb->name, vldb->name_len + 1);
52
53 slist = afs_alloc_server_list(params->cell, params->key, vldb, type_mask);
54 if (IS_ERR(slist)) {
55 ret = PTR_ERR(slist);
56 goto error_1;
57 }
58
59 refcount_set(&slist->usage, 1);
60 volume->servers = slist;
61
62 /* Make sure a records exists for each server this volume occupies. */
63 for (i = 0; i < nr_servers; i++) {
64 if (!(vldb->fs_mask[i] & type_mask))
65 continue;
66
67 server = afs_lookup_server(params->cell, params->key,
68 &vldb->fs_server[i]);
69 if (IS_ERR(server)) {
70 ret = PTR_ERR(server);
71 if (ret == -ENOENT)
72 continue;
73 goto error_2;
74 }
75
76 /* Insertion-sort by server pointer */
77 for (j = 0; j < slist->nr_servers; j++)
78 if (slist->servers[j].server >= server)
79 break;
80 if (j < slist->nr_servers) {
81 if (slist->servers[j].server == server) {
82 afs_put_server(params->net, server);
83 continue;
84 }
85
86 memmove(slist->servers + j + 1,
87 slist->servers + j,
88 (slist->nr_servers - j) * sizeof(struct afs_server_entry));
89 }
90
91 slist->servers[j].server = server;
92 slist->nr_servers++;
93 }
94
95 if (slist->nr_servers == 0) {
96 ret = -EDESTADDRREQ;
97 goto error_2;
98 }
99
100 return volume;
101
102error_2:
103 afs_put_serverlist(params->net, slist);
104error_1:
105 kfree(volume);
106error_0:
107 return ERR_PTR(ret);
108}
109
110/*
111 * Look up a VLDB record for a volume.
112 */
113static struct afs_vldb_entry *afs_vl_lookup_vldb(struct afs_cell *cell,
114 struct key *key,
115 const char *volname,
116 size_t volnamesz)
117{
118 struct afs_addr_cursor ac;
119 struct afs_vldb_entry *vldb;
120 int ret;
121
122 ret = afs_set_vl_cursor(&ac, cell);
123 if (ret < 0)
124 return ERR_PTR(ret);
125
126 while (afs_iterate_addresses(&ac)) {
127 vldb = afs_vl_get_entry_by_name_u(cell->net, &ac, key,
128 volname, volnamesz);
129 switch (ac.error) {
130 case 0:
131 afs_end_cursor(&ac);
132 return vldb;
133 case -ECONNABORTED:
134 ac.error = afs_abort_to_error(ac.abort_code);
135 goto error;
136 case -ENOMEM:
137 case -ENONET:
138 goto error;
139 case -ENETUNREACH:
140 case -EHOSTUNREACH:
141 case -ECONNREFUSED:
142 break;
143 default:
144 ac.error = -EIO;
145 goto error;
146 }
147 }
148
149error:
150 return ERR_PTR(afs_end_cursor(&ac));
151}
152
153/*
154 * Look up a volume in the VL server and create a candidate volume record for
155 * it.
156 *
157 * The volume name can be one of the following:
21 * "%[cell:]volume[.]" R/W volume 158 * "%[cell:]volume[.]" R/W volume
22 * "#[cell:]volume[.]" R/O or R/W volume (rwparent=0), 159 * "#[cell:]volume[.]" R/O or R/W volume (rwparent=0),
23 * or R/W (rwparent=1) volume 160 * or R/W (rwparent=1) volume
@@ -37,169 +174,218 @@ static const char *afs_voltypes[] = { "R/W", "R/O", "BAK" };
37 * - Rule 3: If parent volume is R/W, then only mount R/W volume unless 174 * - Rule 3: If parent volume is R/W, then only mount R/W volume unless
38 * explicitly told otherwise 175 * explicitly told otherwise
39 */ 176 */
40struct afs_volume *afs_volume_lookup(struct afs_mount_params *params) 177struct afs_volume *afs_create_volume(struct afs_mount_params *params)
41{ 178{
42 struct afs_vlocation *vlocation = NULL; 179 struct afs_vldb_entry *vldb;
43 struct afs_volume *volume = NULL; 180 struct afs_volume *volume;
44 struct afs_server *server = NULL; 181 unsigned long type_mask = 1UL << params->type;
45 char srvtmask;
46 int ret, loop;
47
48 _enter("{%*.*s,%d}",
49 params->volnamesz, params->volnamesz, params->volname, params->rwpath);
50
51 /* lookup the volume location record */
52 vlocation = afs_vlocation_lookup(params->net, params->cell, params->key,
53 params->volname, params->volnamesz);
54 if (IS_ERR(vlocation)) {
55 ret = PTR_ERR(vlocation);
56 vlocation = NULL;
57 goto error;
58 }
59 182
60 /* make the final decision on the type we want */ 183 vldb = afs_vl_lookup_vldb(params->cell, params->key,
61 ret = -ENOMEDIUM; 184 params->volname, params->volnamesz);
62 if (params->force && !(vlocation->vldb.vidmask & (1 << params->type))) 185 if (IS_ERR(vldb))
63 goto error; 186 return ERR_CAST(vldb);
64 187
65 srvtmask = 0; 188 if (test_bit(AFS_VLDB_QUERY_ERROR, &vldb->flags)) {
66 for (loop = 0; loop < vlocation->vldb.nservers; loop++) 189 volume = ERR_PTR(vldb->error);
67 srvtmask |= vlocation->vldb.srvtmask[loop]; 190 goto error;
191 }
68 192
193 /* Make the final decision on the type we want */
194 volume = ERR_PTR(-ENOMEDIUM);
69 if (params->force) { 195 if (params->force) {
70 if (!(srvtmask & (1 << params->type))) 196 if (!(vldb->flags & type_mask))
71 goto error; 197 goto error;
72 } else if (srvtmask & AFS_VOL_VTM_RO) { 198 } else if (test_bit(AFS_VLDB_HAS_RO, &vldb->flags)) {
73 params->type = AFSVL_ROVOL; 199 params->type = AFSVL_ROVOL;
74 } else if (srvtmask & AFS_VOL_VTM_RW) { 200 } else if (test_bit(AFS_VLDB_HAS_RW, &vldb->flags)) {
75 params->type = AFSVL_RWVOL; 201 params->type = AFSVL_RWVOL;
76 } else { 202 } else {
77 goto error; 203 goto error;
78 } 204 }
79 205
80 down_write(&params->cell->vl_sem); 206 type_mask = 1UL << params->type;
207 volume = afs_alloc_volume(params, vldb, type_mask);
81 208
82 /* is the volume already active? */ 209error:
83 if (vlocation->vols[params->type]) { 210 kfree(vldb);
84 /* yes - re-use it */ 211 return volume;
85 volume = vlocation->vols[params->type]; 212}
86 afs_get_volume(volume);
87 goto success;
88 }
89 213
90 /* create a new volume record */ 214/*
91 _debug("creating new volume record"); 215 * Destroy a volume record
216 */
217static void afs_destroy_volume(struct afs_net *net, struct afs_volume *volume)
218{
219 _enter("%p", volume);
92 220
93 ret = -ENOMEM; 221#ifdef CONFIG_AFS_FSCACHE
94 volume = kzalloc(sizeof(struct afs_volume), GFP_KERNEL); 222 ASSERTCMP(volume->cache, ==, NULL);
95 if (!volume) 223#endif
96 goto error_up;
97 224
98 atomic_set(&volume->usage, 1); 225 afs_put_serverlist(net, volume->servers);
99 volume->type = params->type; 226 afs_put_cell(net, volume->cell);
100 volume->type_force = params->force; 227 kfree(volume);
101 volume->cell = params->cell;
102 volume->vid = vlocation->vldb.vid[params->type];
103
104 init_rwsem(&volume->server_sem);
105
106 /* look up all the applicable server records */
107 for (loop = 0; loop < 8; loop++) {
108 if (vlocation->vldb.srvtmask[loop] & (1 << volume->type)) {
109 server = afs_lookup_server(
110 volume->cell, &vlocation->vldb.servers[loop]);
111 if (IS_ERR(server)) {
112 ret = PTR_ERR(server);
113 goto error_discard;
114 }
115 228
116 volume->servers[volume->nservers] = server; 229 _leave(" [destroyed]");
117 volume->nservers++; 230}
118 } 231
232/*
233 * Drop a reference on a volume record.
234 */
235void afs_put_volume(struct afs_cell *cell, struct afs_volume *volume)
236{
237 if (volume) {
238 _enter("%s", volume->name);
239
240 if (atomic_dec_and_test(&volume->usage))
241 afs_destroy_volume(cell->net, volume);
119 } 242 }
243}
120 244
121 /* attach the cache and volume location */ 245/*
246 * Activate a volume.
247 */
248void afs_activate_volume(struct afs_volume *volume)
249{
122#ifdef CONFIG_AFS_FSCACHE 250#ifdef CONFIG_AFS_FSCACHE
123 volume->cache = fscache_acquire_cookie(volume->cell->cache, 251 volume->cache = fscache_acquire_cookie(volume->cell->cache,
124 &afs_volume_cache_index_def, 252 &afs_volume_cache_index_def,
125 volume, true); 253 volume, true);
126#endif 254#endif
127 afs_get_vlocation(vlocation);
128 volume->vlocation = vlocation;
129
130 vlocation->vols[volume->type] = volume;
131 255
132success: 256 write_lock(&volume->cell->proc_lock);
133 _debug("kAFS selected %s volume %08x", 257 list_add_tail(&volume->proc_link, &volume->cell->proc_volumes);
134 afs_voltypes[volume->type], volume->vid); 258 write_unlock(&volume->cell->proc_lock);
135 up_write(&params->cell->vl_sem); 259}
136 afs_put_vlocation(params->net, vlocation);
137 _leave(" = %p", volume);
138 return volume;
139 260
140 /* clean up */ 261/*
141error_up: 262 * Deactivate a volume.
142 up_write(&params->cell->vl_sem); 263 */
143error: 264void afs_deactivate_volume(struct afs_volume *volume)
144 afs_put_vlocation(params->net, vlocation); 265{
145 _leave(" = %d", ret); 266 _enter("%s", volume->name);
146 return ERR_PTR(ret);
147 267
148error_discard: 268 write_lock(&volume->cell->proc_lock);
149 up_write(&params->cell->vl_sem); 269 list_del_init(&volume->proc_link);
270 write_unlock(&volume->cell->proc_lock);
150 271
151 for (loop = volume->nservers - 1; loop >= 0; loop--) { 272#ifdef CONFIG_AFS_FSCACHE
152 afs_put_cb_interest(params->net, volume->cb_interests[loop]); 273 fscache_relinquish_cookie(volume->cache,
153 afs_put_server(params->net, volume->servers[loop]); 274 test_bit(AFS_VOLUME_DELETED, &volume->flags));
154 } 275 volume->cache = NULL;
276#endif
155 277
156 kfree(volume); 278 _leave("");
157 goto error;
158} 279}
159 280
160/* 281/*
161 * destroy a volume record 282 * Query the VL service to update the volume status.
162 */ 283 */
163void afs_put_volume(struct afs_cell *cell, struct afs_volume *volume) 284static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
164{ 285{
165 struct afs_vlocation *vlocation; 286 struct afs_server_list *new, *old, *discard;
166 int loop; 287 struct afs_vldb_entry *vldb;
288 char idbuf[16];
289 int ret, idsz;
167 290
168 if (!volume) 291 _enter("");
169 return;
170 292
171 _enter("%p", volume); 293 /* We look up an ID by passing it as a decimal string in the
294 * operation's name parameter.
295 */
296 idsz = sprintf(idbuf, "%u", volume->vid);
172 297
173 ASSERTCMP(atomic_read(&volume->usage), >, 0); 298 vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz);
299 if (IS_ERR(vldb)) {
300 ret = PTR_ERR(vldb);
301 goto error;
302 }
174 303
175 vlocation = volume->vlocation; 304 /* See if the volume got renamed. */
305 if (vldb->name_len != volume->name_len ||
306 memcmp(vldb->name, volume->name, vldb->name_len) != 0) {
307 /* TODO: Use RCU'd string. */
308 memcpy(volume->name, vldb->name, AFS_MAXVOLNAME);
309 volume->name_len = vldb->name_len;
310 }
311
312 /* See if the volume's server list got updated. */
313 new = afs_alloc_server_list(volume->cell, key,
314 vldb, (1 << volume->type));
315 if (IS_ERR(new)) {
316 ret = PTR_ERR(new);
317 goto error_vldb;
318 }
176 319
177 /* to prevent a race, the decrement and the dequeue must be effectively 320 write_lock(&volume->servers_lock);
178 * atomic */
179 down_write(&cell->vl_sem);
180 321
181 if (likely(!atomic_dec_and_test(&volume->usage))) { 322 discard = new;
182 up_write(&vlocation->cell->vl_sem); 323 old = volume->servers;
183 _leave(""); 324 if (afs_annotate_server_list(new, old)) {
184 return; 325 new->seq = volume->servers_seq + 1;
326 volume->servers = new;
327 smp_wmb();
328 volume->servers_seq++;
329 discard = old;
185 } 330 }
186 331
187 vlocation->vols[volume->type] = NULL; 332 volume->update_at = ktime_get_real_seconds() + afs_volume_record_life;
333 clear_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags);
334 write_unlock(&volume->servers_lock);
335 ret = 0;
188 336
189 up_write(&cell->vl_sem); 337 afs_put_serverlist(volume->cell->net, discard);
338error_vldb:
339 kfree(vldb);
340error:
341 _leave(" = %d", ret);
342 return ret;
343}
190 344
191 /* finish cleaning up the volume */ 345/*
192#ifdef CONFIG_AFS_FSCACHE 346 * Make sure the volume record is up to date.
193 fscache_relinquish_cookie(volume->cache, 0); 347 */
194#endif 348int afs_check_volume_status(struct afs_volume *volume, struct key *key)
195 afs_put_vlocation(cell->net, vlocation); 349{
350 time64_t now = ktime_get_real_seconds();
351 int ret, retries = 0;
196 352
197 for (loop = volume->nservers - 1; loop >= 0; loop--) { 353 _enter("");
198 afs_put_cb_interest(cell->net, volume->cb_interests[loop]); 354
199 afs_put_server(cell->net, volume->servers[loop]); 355 if (volume->update_at <= now)
356 set_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags);
357
358retry:
359 if (!test_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags) &&
360 !test_bit(AFS_VOLUME_WAIT, &volume->flags)) {
361 _leave(" = 0");
362 return 0;
200 } 363 }
201 364
202 kfree(volume); 365 if (!test_and_set_bit_lock(AFS_VOLUME_UPDATING, &volume->flags)) {
366 ret = afs_update_volume_status(volume, key);
367 clear_bit_unlock(AFS_VOLUME_WAIT, &volume->flags);
368 clear_bit_unlock(AFS_VOLUME_UPDATING, &volume->flags);
369 wake_up_bit(&volume->flags, AFS_VOLUME_WAIT);
370 _leave(" = %d", ret);
371 return ret;
372 }
203 373
204 _leave(" [destroyed]"); 374 if (!test_bit(AFS_VOLUME_WAIT, &volume->flags)) {
375 _leave(" = 0 [no wait]");
376 return 0;
377 }
378
379 ret = wait_on_bit(&volume->flags, AFS_VOLUME_WAIT, TASK_INTERRUPTIBLE);
380 if (ret == -ERESTARTSYS) {
381 _leave(" = %d", ret);
382 return ret;
383 }
384
385 retries++;
386 if (retries == 4) {
387 _leave(" = -ESTALE");
388 return -ESTALE;
389 }
390 goto retry;
205} 391}
diff --git a/fs/afs/write.c b/fs/afs/write.c
index 106e43db1115..1377a40ecdbb 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -103,7 +103,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,
103 req->pages[0] = page; 103 req->pages[0] = page;
104 get_page(page); 104 get_page(page);
105 105
106 ret = afs_vnode_fetch_data(vnode, key, req); 106 ret = afs_fetch_data(vnode, key, req);
107 afs_put_read(req); 107 afs_put_read(req);
108 if (ret < 0) { 108 if (ret < 0) {
109 if (ret == -ENOENT) { 109 if (ret == -ENOENT) {
@@ -338,6 +338,40 @@ static void afs_kill_pages(struct afs_vnode *vnode, bool error,
338} 338}
339 339
340/* 340/*
341 * write to a file
342 */
343static int afs_store_data(struct afs_writeback *wb, pgoff_t first, pgoff_t last,
344 unsigned offset, unsigned to)
345{
346 struct afs_fs_cursor fc;
347 struct afs_vnode *vnode = wb->vnode;
348 int ret;
349
350 _enter("%s{%x:%u.%u},%x,%lx,%lx,%x,%x",
351 vnode->volume->name,
352 vnode->fid.vid,
353 vnode->fid.vnode,
354 vnode->fid.unique,
355 key_serial(wb->key),
356 first, last, offset, to);
357
358 ret = -ERESTARTSYS;
359 if (afs_begin_vnode_operation(&fc, vnode, wb->key)) {
360 while (afs_select_fileserver(&fc)) {
361 fc.cb_break = vnode->cb_break + vnode->cb_s_break;
362 afs_fs_store_data(&fc, wb, first, last, offset, to);
363 }
364
365 afs_check_for_remote_deletion(&fc, fc.vnode);
366 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
367 ret = afs_end_vnode_operation(&fc);
368 }
369
370 _leave(" = %d", ret);
371 return ret;
372}
373
374/*
341 * synchronously write back the locked page and any subsequent non-locked dirty 375 * synchronously write back the locked page and any subsequent non-locked dirty
342 * pages also covered by the same writeback record 376 * pages also covered by the same writeback record
343 */ 377 */
@@ -420,7 +454,7 @@ no_more:
420 454
421 _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to); 455 _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to);
422 456
423 ret = afs_vnode_store_data(wb, first, last, offset, to); 457 ret = afs_store_data(wb, first, last, offset, to);
424 if (ret < 0) { 458 if (ret < 0) {
425 switch (ret) { 459 switch (ret) {
426 case -EDQUOT: 460 case -EDQUOT:
diff --git a/fs/afs/xattr.c b/fs/afs/xattr.c
index e58e00ee9747..cfcc674e64a5 100644
--- a/fs/afs/xattr.c
+++ b/fs/afs/xattr.c
@@ -96,7 +96,7 @@ static int afs_xattr_get_volume(const struct xattr_handler *handler,
96 void *buffer, size_t size) 96 void *buffer, size_t size)
97{ 97{
98 struct afs_vnode *vnode = AFS_FS_I(inode); 98 struct afs_vnode *vnode = AFS_FS_I(inode);
99 const char *volname = vnode->volume->vlocation->vldb.name; 99 const char *volname = vnode->volume->name;
100 size_t namelen; 100 size_t namelen;
101 101
102 namelen = strlen(volname); 102 namelen = strlen(volname);