diff options
author | Paul Mackerras <paulus@samba.org> | 2007-05-10 07:08:37 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-05-10 07:08:37 -0400 |
commit | 2ecf042ef530dd0943e41d84b6344f507941af3e (patch) | |
tree | 73100361dd74e3f80f14c7c81ba4675948983f44 /fs/afs | |
parent | 32a56ebb24f23da1bbaf24292acf85b6c04526ab (diff) | |
parent | de5603748af8bf7deac403e6ba92887f8d18e812 (diff) |
Merge branch 'linux-2.6'
Diffstat (limited to 'fs/afs')
-rw-r--r-- | fs/afs/Makefile | 3 | ||||
-rw-r--r-- | fs/afs/afs_fs.h | 2 | ||||
-rw-r--r-- | fs/afs/callback.c | 9 | ||||
-rw-r--r-- | fs/afs/dir.c | 19 | ||||
-rw-r--r-- | fs/afs/file.c | 107 | ||||
-rw-r--r-- | fs/afs/fsclient.c | 369 | ||||
-rw-r--r-- | fs/afs/inode.c | 70 | ||||
-rw-r--r-- | fs/afs/internal.h | 95 | ||||
-rw-r--r-- | fs/afs/main.c | 2 | ||||
-rw-r--r-- | fs/afs/misc.c | 1 | ||||
-rw-r--r-- | fs/afs/mntpt.c | 5 | ||||
-rw-r--r-- | fs/afs/rxrpc.c | 80 | ||||
-rw-r--r-- | fs/afs/security.c | 12 | ||||
-rw-r--r-- | fs/afs/server.c | 3 | ||||
-rw-r--r-- | fs/afs/super.c | 5 | ||||
-rw-r--r-- | fs/afs/vnode.c | 121 | ||||
-rw-r--r-- | fs/afs/write.c | 835 |
17 files changed, 1603 insertions, 135 deletions
diff --git a/fs/afs/Makefile b/fs/afs/Makefile index cf83e5d63512..73ce561f3ea0 100644 --- a/fs/afs/Makefile +++ b/fs/afs/Makefile | |||
@@ -22,6 +22,7 @@ kafs-objs := \ | |||
22 | vlclient.o \ | 22 | vlclient.o \ |
23 | vlocation.o \ | 23 | vlocation.o \ |
24 | vnode.o \ | 24 | vnode.o \ |
25 | volume.o | 25 | volume.o \ |
26 | write.o | ||
26 | 27 | ||
27 | obj-$(CONFIG_AFS_FS) := kafs.o | 28 | obj-$(CONFIG_AFS_FS) := kafs.o |
diff --git a/fs/afs/afs_fs.h b/fs/afs/afs_fs.h index 89e0d1650a72..2198006d2d03 100644 --- a/fs/afs/afs_fs.h +++ b/fs/afs/afs_fs.h | |||
@@ -18,6 +18,8 @@ | |||
18 | enum AFS_FS_Operations { | 18 | enum AFS_FS_Operations { |
19 | FSFETCHDATA = 130, /* AFS Fetch file data */ | 19 | FSFETCHDATA = 130, /* AFS Fetch file data */ |
20 | FSFETCHSTATUS = 132, /* AFS Fetch file status */ | 20 | FSFETCHSTATUS = 132, /* AFS Fetch file status */ |
21 | FSSTOREDATA = 133, /* AFS Store file data */ | ||
22 | FSSTORESTATUS = 135, /* AFS Store file status */ | ||
21 | FSREMOVEFILE = 136, /* AFS Remove a file */ | 23 | FSREMOVEFILE = 136, /* AFS Remove a file */ |
22 | FSCREATEFILE = 137, /* AFS Create a file */ | 24 | FSCREATEFILE = 137, /* AFS Create a file */ |
23 | FSRENAME = 138, /* AFS Rename or move a file or directory */ | 25 | FSRENAME = 138, /* AFS Rename or move a file or directory */ |
diff --git a/fs/afs/callback.c b/fs/afs/callback.c index 9bdbf36a9aa9..f64e40fefc02 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c | |||
@@ -44,7 +44,7 @@ void afs_init_callback_state(struct afs_server *server) | |||
44 | while (!RB_EMPTY_ROOT(&server->cb_promises)) { | 44 | while (!RB_EMPTY_ROOT(&server->cb_promises)) { |
45 | vnode = rb_entry(server->cb_promises.rb_node, | 45 | vnode = rb_entry(server->cb_promises.rb_node, |
46 | struct afs_vnode, cb_promise); | 46 | struct afs_vnode, cb_promise); |
47 | _debug("UNPROMISE { vid=%x vn=%u uq=%u}", | 47 | _debug("UNPROMISE { vid=%x:%u uq=%u}", |
48 | vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); | 48 | vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); |
49 | rb_erase(&vnode->cb_promise, &server->cb_promises); | 49 | rb_erase(&vnode->cb_promise, &server->cb_promises); |
50 | vnode->cb_promised = false; | 50 | vnode->cb_promised = false; |
@@ -84,11 +84,8 @@ void afs_broken_callback_work(struct work_struct *work) | |||
84 | 84 | ||
85 | /* if the vnode's data version number changed then its contents | 85 | /* if the vnode's data version number changed then its contents |
86 | * are different */ | 86 | * are different */ |
87 | if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) { | 87 | if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) |
88 | _debug("zap data {%x:%u}", | 88 | afs_zap_data(vnode); |
89 | vnode->fid.vid, vnode->fid.vnode); | ||
90 | invalidate_remote_inode(&vnode->vfs_inode); | ||
91 | } | ||
92 | } | 89 | } |
93 | 90 | ||
94 | out: | 91 | out: |
diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 0c1e902f17a3..2fb31276196b 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c | |||
@@ -55,7 +55,8 @@ const struct inode_operations afs_dir_inode_operations = { | |||
55 | .rmdir = afs_rmdir, | 55 | .rmdir = afs_rmdir, |
56 | .rename = afs_rename, | 56 | .rename = afs_rename, |
57 | .permission = afs_permission, | 57 | .permission = afs_permission, |
58 | .getattr = afs_inode_getattr, | 58 | .getattr = afs_getattr, |
59 | .setattr = afs_setattr, | ||
59 | }; | 60 | }; |
60 | 61 | ||
61 | static struct dentry_operations afs_fs_dentry_operations = { | 62 | static struct dentry_operations afs_fs_dentry_operations = { |
@@ -491,7 +492,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry, | |||
491 | 492 | ||
492 | vnode = AFS_FS_I(dir); | 493 | vnode = AFS_FS_I(dir); |
493 | 494 | ||
494 | _enter("{%x:%d},%p{%s},", | 495 | _enter("{%x:%u},%p{%s},", |
495 | vnode->fid.vid, vnode->fid.vnode, dentry, dentry->d_name.name); | 496 | vnode->fid.vid, vnode->fid.vnode, dentry, dentry->d_name.name); |
496 | 497 | ||
497 | ASSERTCMP(dentry->d_inode, ==, NULL); | 498 | ASSERTCMP(dentry->d_inode, ==, NULL); |
@@ -731,7 +732,7 @@ static int afs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
731 | 732 | ||
732 | dvnode = AFS_FS_I(dir); | 733 | dvnode = AFS_FS_I(dir); |
733 | 734 | ||
734 | _enter("{%x:%d},{%s},%o", | 735 | _enter("{%x:%u},{%s},%o", |
735 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode); | 736 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode); |
736 | 737 | ||
737 | ret = -ENAMETOOLONG; | 738 | ret = -ENAMETOOLONG; |
@@ -796,7 +797,7 @@ static int afs_rmdir(struct inode *dir, struct dentry *dentry) | |||
796 | 797 | ||
797 | dvnode = AFS_FS_I(dir); | 798 | dvnode = AFS_FS_I(dir); |
798 | 799 | ||
799 | _enter("{%x:%d},{%s}", | 800 | _enter("{%x:%u},{%s}", |
800 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name); | 801 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name); |
801 | 802 | ||
802 | ret = -ENAMETOOLONG; | 803 | ret = -ENAMETOOLONG; |
@@ -842,7 +843,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry) | |||
842 | 843 | ||
843 | dvnode = AFS_FS_I(dir); | 844 | dvnode = AFS_FS_I(dir); |
844 | 845 | ||
845 | _enter("{%x:%d},{%s}", | 846 | _enter("{%x:%u},{%s}", |
846 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name); | 847 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name); |
847 | 848 | ||
848 | ret = -ENAMETOOLONG; | 849 | ret = -ENAMETOOLONG; |
@@ -916,7 +917,7 @@ static int afs_create(struct inode *dir, struct dentry *dentry, int mode, | |||
916 | 917 | ||
917 | dvnode = AFS_FS_I(dir); | 918 | dvnode = AFS_FS_I(dir); |
918 | 919 | ||
919 | _enter("{%x:%d},{%s},%o,", | 920 | _enter("{%x:%u},{%s},%o,", |
920 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode); | 921 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode); |
921 | 922 | ||
922 | ret = -ENAMETOOLONG; | 923 | ret = -ENAMETOOLONG; |
@@ -983,7 +984,7 @@ static int afs_link(struct dentry *from, struct inode *dir, | |||
983 | vnode = AFS_FS_I(from->d_inode); | 984 | vnode = AFS_FS_I(from->d_inode); |
984 | dvnode = AFS_FS_I(dir); | 985 | dvnode = AFS_FS_I(dir); |
985 | 986 | ||
986 | _enter("{%x:%d},{%x:%d},{%s}", | 987 | _enter("{%x:%u},{%x:%u},{%s}", |
987 | vnode->fid.vid, vnode->fid.vnode, | 988 | vnode->fid.vid, vnode->fid.vnode, |
988 | dvnode->fid.vid, dvnode->fid.vnode, | 989 | dvnode->fid.vid, dvnode->fid.vnode, |
989 | dentry->d_name.name); | 990 | dentry->d_name.name); |
@@ -1032,7 +1033,7 @@ static int afs_symlink(struct inode *dir, struct dentry *dentry, | |||
1032 | 1033 | ||
1033 | dvnode = AFS_FS_I(dir); | 1034 | dvnode = AFS_FS_I(dir); |
1034 | 1035 | ||
1035 | _enter("{%x:%d},{%s},%s", | 1036 | _enter("{%x:%u},{%s},%s", |
1036 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, | 1037 | dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, |
1037 | content); | 1038 | content); |
1038 | 1039 | ||
@@ -1104,7 +1105,7 @@ static int afs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1104 | orig_dvnode = AFS_FS_I(old_dir); | 1105 | orig_dvnode = AFS_FS_I(old_dir); |
1105 | new_dvnode = AFS_FS_I(new_dir); | 1106 | new_dvnode = AFS_FS_I(new_dir); |
1106 | 1107 | ||
1107 | _enter("{%x:%d},{%x:%d},{%x:%d},{%s}", | 1108 | _enter("{%x:%u},{%x:%u},{%x:%u},{%s}", |
1108 | orig_dvnode->fid.vid, orig_dvnode->fid.vnode, | 1109 | orig_dvnode->fid.vid, orig_dvnode->fid.vnode, |
1109 | vnode->fid.vid, vnode->fid.vnode, | 1110 | vnode->fid.vid, vnode->fid.vnode, |
1110 | new_dvnode->fid.vid, new_dvnode->fid.vnode, | 1111 | new_dvnode->fid.vid, new_dvnode->fid.vnode, |
diff --git a/fs/afs/file.c b/fs/afs/file.c index ae256498f4f7..3e25795e5a42 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c | |||
@@ -15,32 +15,43 @@ | |||
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/fs.h> | 16 | #include <linux/fs.h> |
17 | #include <linux/pagemap.h> | 17 | #include <linux/pagemap.h> |
18 | #include <linux/writeback.h> | ||
18 | #include "internal.h" | 19 | #include "internal.h" |
19 | 20 | ||
20 | static int afs_file_readpage(struct file *file, struct page *page); | 21 | static int afs_readpage(struct file *file, struct page *page); |
21 | static void afs_file_invalidatepage(struct page *page, unsigned long offset); | 22 | static void afs_invalidatepage(struct page *page, unsigned long offset); |
22 | static int afs_file_releasepage(struct page *page, gfp_t gfp_flags); | 23 | static int afs_releasepage(struct page *page, gfp_t gfp_flags); |
24 | static int afs_launder_page(struct page *page); | ||
23 | 25 | ||
24 | const struct file_operations afs_file_operations = { | 26 | const struct file_operations afs_file_operations = { |
25 | .open = afs_open, | 27 | .open = afs_open, |
26 | .release = afs_release, | 28 | .release = afs_release, |
27 | .llseek = generic_file_llseek, | 29 | .llseek = generic_file_llseek, |
28 | .read = do_sync_read, | 30 | .read = do_sync_read, |
31 | .write = do_sync_write, | ||
29 | .aio_read = generic_file_aio_read, | 32 | .aio_read = generic_file_aio_read, |
33 | .aio_write = afs_file_write, | ||
30 | .mmap = generic_file_readonly_mmap, | 34 | .mmap = generic_file_readonly_mmap, |
31 | .sendfile = generic_file_sendfile, | 35 | .sendfile = generic_file_sendfile, |
36 | .fsync = afs_fsync, | ||
32 | }; | 37 | }; |
33 | 38 | ||
34 | const struct inode_operations afs_file_inode_operations = { | 39 | const struct inode_operations afs_file_inode_operations = { |
35 | .getattr = afs_inode_getattr, | 40 | .getattr = afs_getattr, |
41 | .setattr = afs_setattr, | ||
36 | .permission = afs_permission, | 42 | .permission = afs_permission, |
37 | }; | 43 | }; |
38 | 44 | ||
39 | const struct address_space_operations afs_fs_aops = { | 45 | const struct address_space_operations afs_fs_aops = { |
40 | .readpage = afs_file_readpage, | 46 | .readpage = afs_readpage, |
41 | .set_page_dirty = __set_page_dirty_nobuffers, | 47 | .set_page_dirty = afs_set_page_dirty, |
42 | .releasepage = afs_file_releasepage, | 48 | .launder_page = afs_launder_page, |
43 | .invalidatepage = afs_file_invalidatepage, | 49 | .releasepage = afs_releasepage, |
50 | .invalidatepage = afs_invalidatepage, | ||
51 | .prepare_write = afs_prepare_write, | ||
52 | .commit_write = afs_commit_write, | ||
53 | .writepage = afs_writepage, | ||
54 | .writepages = afs_writepages, | ||
44 | }; | 55 | }; |
45 | 56 | ||
46 | /* | 57 | /* |
@@ -52,7 +63,7 @@ int afs_open(struct inode *inode, struct file *file) | |||
52 | struct key *key; | 63 | struct key *key; |
53 | int ret; | 64 | int ret; |
54 | 65 | ||
55 | _enter("{%x:%x},", vnode->fid.vid, vnode->fid.vnode); | 66 | _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode); |
56 | 67 | ||
57 | key = afs_request_key(vnode->volume->cell); | 68 | key = afs_request_key(vnode->volume->cell); |
58 | if (IS_ERR(key)) { | 69 | if (IS_ERR(key)) { |
@@ -78,7 +89,7 @@ int afs_release(struct inode *inode, struct file *file) | |||
78 | { | 89 | { |
79 | struct afs_vnode *vnode = AFS_FS_I(inode); | 90 | struct afs_vnode *vnode = AFS_FS_I(inode); |
80 | 91 | ||
81 | _enter("{%x:%x},", vnode->fid.vid, vnode->fid.vnode); | 92 | _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode); |
82 | 93 | ||
83 | key_put(file->private_data); | 94 | key_put(file->private_data); |
84 | _leave(" = 0"); | 95 | _leave(" = 0"); |
@@ -89,10 +100,10 @@ int afs_release(struct inode *inode, struct file *file) | |||
89 | * deal with notification that a page was read from the cache | 100 | * deal with notification that a page was read from the cache |
90 | */ | 101 | */ |
91 | #ifdef AFS_CACHING_SUPPORT | 102 | #ifdef AFS_CACHING_SUPPORT |
92 | static void afs_file_readpage_read_complete(void *cookie_data, | 103 | static void afs_readpage_read_complete(void *cookie_data, |
93 | struct page *page, | 104 | struct page *page, |
94 | void *data, | 105 | void *data, |
95 | int error) | 106 | int error) |
96 | { | 107 | { |
97 | _enter("%p,%p,%p,%d", cookie_data, page, data, error); | 108 | _enter("%p,%p,%p,%d", cookie_data, page, data, error); |
98 | 109 | ||
@@ -109,10 +120,10 @@ static void afs_file_readpage_read_complete(void *cookie_data, | |||
109 | * deal with notification that a page was written to the cache | 120 | * deal with notification that a page was written to the cache |
110 | */ | 121 | */ |
111 | #ifdef AFS_CACHING_SUPPORT | 122 | #ifdef AFS_CACHING_SUPPORT |
112 | static void afs_file_readpage_write_complete(void *cookie_data, | 123 | static void afs_readpage_write_complete(void *cookie_data, |
113 | struct page *page, | 124 | struct page *page, |
114 | void *data, | 125 | void *data, |
115 | int error) | 126 | int error) |
116 | { | 127 | { |
117 | _enter("%p,%p,%p,%d", cookie_data, page, data, error); | 128 | _enter("%p,%p,%p,%d", cookie_data, page, data, error); |
118 | 129 | ||
@@ -121,9 +132,9 @@ static void afs_file_readpage_write_complete(void *cookie_data, | |||
121 | #endif | 132 | #endif |
122 | 133 | ||
123 | /* | 134 | /* |
124 | * AFS read page from file (or symlink) | 135 | * AFS read page from file, directory or symlink |
125 | */ | 136 | */ |
126 | static int afs_file_readpage(struct file *file, struct page *page) | 137 | static int afs_readpage(struct file *file, struct page *page) |
127 | { | 138 | { |
128 | struct afs_vnode *vnode; | 139 | struct afs_vnode *vnode; |
129 | struct inode *inode; | 140 | struct inode *inode; |
@@ -219,39 +230,17 @@ error: | |||
219 | } | 230 | } |
220 | 231 | ||
221 | /* | 232 | /* |
222 | * get a page cookie for the specified page | ||
223 | */ | ||
224 | #ifdef AFS_CACHING_SUPPORT | ||
225 | int afs_cache_get_page_cookie(struct page *page, | ||
226 | struct cachefs_page **_page_cookie) | ||
227 | { | ||
228 | int ret; | ||
229 | |||
230 | _enter(""); | ||
231 | ret = cachefs_page_get_private(page,_page_cookie, GFP_NOIO); | ||
232 | |||
233 | _leave(" = %d", ret); | ||
234 | return ret; | ||
235 | } | ||
236 | #endif | ||
237 | |||
238 | /* | ||
239 | * invalidate part or all of a page | 233 | * invalidate part or all of a page |
240 | */ | 234 | */ |
241 | static void afs_file_invalidatepage(struct page *page, unsigned long offset) | 235 | static void afs_invalidatepage(struct page *page, unsigned long offset) |
242 | { | 236 | { |
243 | int ret = 1; | 237 | int ret = 1; |
244 | 238 | ||
245 | _enter("{%lu},%lu", page->index, offset); | 239 | kenter("{%lu},%lu", page->index, offset); |
246 | 240 | ||
247 | BUG_ON(!PageLocked(page)); | 241 | BUG_ON(!PageLocked(page)); |
248 | 242 | ||
249 | if (PagePrivate(page)) { | 243 | if (PagePrivate(page)) { |
250 | #ifdef AFS_CACHING_SUPPORT | ||
251 | struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); | ||
252 | cachefs_uncache_page(vnode->cache,page); | ||
253 | #endif | ||
254 | |||
255 | /* We release buffers only if the entire page is being | 244 | /* We release buffers only if the entire page is being |
256 | * invalidated. | 245 | * invalidated. |
257 | * The get_block cached value has been unconditionally | 246 | * The get_block cached value has been unconditionally |
@@ -272,25 +261,33 @@ static void afs_file_invalidatepage(struct page *page, unsigned long offset) | |||
272 | } | 261 | } |
273 | 262 | ||
274 | /* | 263 | /* |
264 | * write back a dirty page | ||
265 | */ | ||
266 | static int afs_launder_page(struct page *page) | ||
267 | { | ||
268 | _enter("{%lu}", page->index); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | /* | ||
275 | * release a page and cleanup its private data | 274 | * release a page and cleanup its private data |
276 | */ | 275 | */ |
277 | static int afs_file_releasepage(struct page *page, gfp_t gfp_flags) | 276 | static int afs_releasepage(struct page *page, gfp_t gfp_flags) |
278 | { | 277 | { |
279 | struct cachefs_page *pageio; | 278 | struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); |
279 | struct afs_writeback *wb; | ||
280 | 280 | ||
281 | _enter("{%lu},%x", page->index, gfp_flags); | 281 | _enter("{{%x:%u}[%lu],%lx},%x", |
282 | vnode->fid.vid, vnode->fid.vnode, page->index, page->flags, | ||
283 | gfp_flags); | ||
282 | 284 | ||
283 | if (PagePrivate(page)) { | 285 | if (PagePrivate(page)) { |
284 | #ifdef AFS_CACHING_SUPPORT | 286 | wb = (struct afs_writeback *) page_private(page); |
285 | struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); | 287 | ASSERT(wb != NULL); |
286 | cachefs_uncache_page(vnode->cache, page); | ||
287 | #endif | ||
288 | |||
289 | pageio = (struct cachefs_page *) page_private(page); | ||
290 | set_page_private(page, 0); | 288 | set_page_private(page, 0); |
291 | ClearPagePrivate(page); | 289 | ClearPagePrivate(page); |
292 | 290 | afs_put_writeback(wb); | |
293 | kfree(pageio); | ||
294 | } | 291 | } |
295 | 292 | ||
296 | _leave(" = 0"); | 293 | _leave(" = 0"); |
diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index e54e6c2ad343..025b1903d9e1 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c | |||
@@ -33,8 +33,10 @@ static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid) | |||
33 | */ | 33 | */ |
34 | static void xdr_decode_AFSFetchStatus(const __be32 **_bp, | 34 | static void xdr_decode_AFSFetchStatus(const __be32 **_bp, |
35 | struct afs_file_status *status, | 35 | struct afs_file_status *status, |
36 | struct afs_vnode *vnode) | 36 | struct afs_vnode *vnode, |
37 | afs_dataversion_t *store_version) | ||
37 | { | 38 | { |
39 | afs_dataversion_t expected_version; | ||
38 | const __be32 *bp = *_bp; | 40 | const __be32 *bp = *_bp; |
39 | umode_t mode; | 41 | umode_t mode; |
40 | u64 data_version, size; | 42 | u64 data_version, size; |
@@ -101,7 +103,11 @@ static void xdr_decode_AFSFetchStatus(const __be32 **_bp, | |||
101 | vnode->vfs_inode.i_atime = vnode->vfs_inode.i_ctime; | 103 | vnode->vfs_inode.i_atime = vnode->vfs_inode.i_ctime; |
102 | } | 104 | } |
103 | 105 | ||
104 | if (status->data_version != data_version) { | 106 | expected_version = status->data_version; |
107 | if (store_version) | ||
108 | expected_version = *store_version; | ||
109 | |||
110 | if (expected_version != data_version) { | ||
105 | status->data_version = data_version; | 111 | status->data_version = data_version; |
106 | if (vnode && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) { | 112 | if (vnode && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) { |
107 | _debug("vnode modified %llx on {%x:%u}", | 113 | _debug("vnode modified %llx on {%x:%u}", |
@@ -110,6 +116,8 @@ static void xdr_decode_AFSFetchStatus(const __be32 **_bp, | |||
110 | set_bit(AFS_VNODE_MODIFIED, &vnode->flags); | 116 | set_bit(AFS_VNODE_MODIFIED, &vnode->flags); |
111 | set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags); | 117 | set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags); |
112 | } | 118 | } |
119 | } else if (store_version) { | ||
120 | status->data_version = data_version; | ||
113 | } | 121 | } |
114 | } | 122 | } |
115 | 123 | ||
@@ -156,6 +164,44 @@ static void xdr_decode_AFSVolSync(const __be32 **_bp, | |||
156 | } | 164 | } |
157 | 165 | ||
158 | /* | 166 | /* |
167 | * encode the requested attributes into an AFSStoreStatus block | ||
168 | */ | ||
169 | static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr) | ||
170 | { | ||
171 | __be32 *bp = *_bp; | ||
172 | u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0; | ||
173 | |||
174 | mask = 0; | ||
175 | if (attr->ia_valid & ATTR_MTIME) { | ||
176 | mask |= AFS_SET_MTIME; | ||
177 | mtime = attr->ia_mtime.tv_sec; | ||
178 | } | ||
179 | |||
180 | if (attr->ia_valid & ATTR_UID) { | ||
181 | mask |= AFS_SET_OWNER; | ||
182 | owner = attr->ia_uid; | ||
183 | } | ||
184 | |||
185 | if (attr->ia_valid & ATTR_GID) { | ||
186 | mask |= AFS_SET_GROUP; | ||
187 | group = attr->ia_gid; | ||
188 | } | ||
189 | |||
190 | if (attr->ia_valid & ATTR_MODE) { | ||
191 | mask |= AFS_SET_MODE; | ||
192 | mode = attr->ia_mode & S_IALLUGO; | ||
193 | } | ||
194 | |||
195 | *bp++ = htonl(mask); | ||
196 | *bp++ = htonl(mtime); | ||
197 | *bp++ = htonl(owner); | ||
198 | *bp++ = htonl(group); | ||
199 | *bp++ = htonl(mode); | ||
200 | *bp++ = 0; /* segment size */ | ||
201 | *_bp = bp; | ||
202 | } | ||
203 | |||
204 | /* | ||
159 | * deliver reply data to an FS.FetchStatus | 205 | * deliver reply data to an FS.FetchStatus |
160 | */ | 206 | */ |
161 | static int afs_deliver_fs_fetch_status(struct afs_call *call, | 207 | static int afs_deliver_fs_fetch_status(struct afs_call *call, |
@@ -175,7 +221,7 @@ static int afs_deliver_fs_fetch_status(struct afs_call *call, | |||
175 | 221 | ||
176 | /* unmarshall the reply once we've received all of it */ | 222 | /* unmarshall the reply once we've received all of it */ |
177 | bp = call->buffer; | 223 | bp = call->buffer; |
178 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode); | 224 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
179 | xdr_decode_AFSCallBack(&bp, vnode); | 225 | xdr_decode_AFSCallBack(&bp, vnode); |
180 | if (call->reply2) | 226 | if (call->reply2) |
181 | xdr_decode_AFSVolSync(&bp, call->reply2); | 227 | xdr_decode_AFSVolSync(&bp, call->reply2); |
@@ -206,7 +252,7 @@ int afs_fs_fetch_file_status(struct afs_server *server, | |||
206 | struct afs_call *call; | 252 | struct afs_call *call; |
207 | __be32 *bp; | 253 | __be32 *bp; |
208 | 254 | ||
209 | _enter(",%x,{%x:%d},,", | 255 | _enter(",%x,{%x:%u},,", |
210 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); | 256 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); |
211 | 257 | ||
212 | call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4); | 258 | call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4); |
@@ -265,25 +311,20 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call, | |||
265 | call->offset = 0; | 311 | call->offset = 0; |
266 | call->unmarshall++; | 312 | call->unmarshall++; |
267 | 313 | ||
268 | if (call->count < PAGE_SIZE) { | ||
269 | page = call->reply3; | ||
270 | buffer = kmap_atomic(page, KM_USER0); | ||
271 | memset(buffer + PAGE_SIZE - call->count, 0, | ||
272 | call->count); | ||
273 | kunmap_atomic(buffer, KM_USER0); | ||
274 | } | ||
275 | |||
276 | /* extract the returned data */ | 314 | /* extract the returned data */ |
277 | case 2: | 315 | case 2: |
278 | _debug("extract data"); | 316 | _debug("extract data"); |
279 | page = call->reply3; | 317 | if (call->count > 0) { |
280 | buffer = kmap_atomic(page, KM_USER0); | 318 | page = call->reply3; |
281 | ret = afs_extract_data(call, skb, last, buffer, call->count); | 319 | buffer = kmap_atomic(page, KM_USER0); |
282 | kunmap_atomic(buffer, KM_USER0); | 320 | ret = afs_extract_data(call, skb, last, buffer, |
283 | switch (ret) { | 321 | call->count); |
284 | case 0: break; | 322 | kunmap_atomic(buffer, KM_USER0); |
285 | case -EAGAIN: return 0; | 323 | switch (ret) { |
286 | default: return ret; | 324 | case 0: break; |
325 | case -EAGAIN: return 0; | ||
326 | default: return ret; | ||
327 | } | ||
287 | } | 328 | } |
288 | 329 | ||
289 | call->offset = 0; | 330 | call->offset = 0; |
@@ -300,7 +341,7 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call, | |||
300 | } | 341 | } |
301 | 342 | ||
302 | bp = call->buffer; | 343 | bp = call->buffer; |
303 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode); | 344 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
304 | xdr_decode_AFSCallBack(&bp, vnode); | 345 | xdr_decode_AFSCallBack(&bp, vnode); |
305 | if (call->reply2) | 346 | if (call->reply2) |
306 | xdr_decode_AFSVolSync(&bp, call->reply2); | 347 | xdr_decode_AFSVolSync(&bp, call->reply2); |
@@ -318,6 +359,14 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call, | |||
318 | if (!last) | 359 | if (!last) |
319 | return 0; | 360 | return 0; |
320 | 361 | ||
362 | if (call->count < PAGE_SIZE) { | ||
363 | _debug("clear"); | ||
364 | page = call->reply3; | ||
365 | buffer = kmap_atomic(page, KM_USER0); | ||
366 | memset(buffer + call->count, 0, PAGE_SIZE - call->count); | ||
367 | kunmap_atomic(buffer, KM_USER0); | ||
368 | } | ||
369 | |||
321 | _leave(" = 0 [done]"); | 370 | _leave(" = 0 [done]"); |
322 | return 0; | 371 | return 0; |
323 | } | 372 | } |
@@ -476,8 +525,8 @@ static int afs_deliver_fs_create_vnode(struct afs_call *call, | |||
476 | /* unmarshall the reply once we've received all of it */ | 525 | /* unmarshall the reply once we've received all of it */ |
477 | bp = call->buffer; | 526 | bp = call->buffer; |
478 | xdr_decode_AFSFid(&bp, call->reply2); | 527 | xdr_decode_AFSFid(&bp, call->reply2); |
479 | xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL); | 528 | xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL); |
480 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode); | 529 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
481 | xdr_decode_AFSCallBack_raw(&bp, call->reply4); | 530 | xdr_decode_AFSCallBack_raw(&bp, call->reply4); |
482 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | 531 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
483 | 532 | ||
@@ -574,7 +623,7 @@ static int afs_deliver_fs_remove(struct afs_call *call, | |||
574 | 623 | ||
575 | /* unmarshall the reply once we've received all of it */ | 624 | /* unmarshall the reply once we've received all of it */ |
576 | bp = call->buffer; | 625 | bp = call->buffer; |
577 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode); | 626 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
578 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | 627 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
579 | 628 | ||
580 | _leave(" = 0 [done]"); | 629 | _leave(" = 0 [done]"); |
@@ -657,8 +706,8 @@ static int afs_deliver_fs_link(struct afs_call *call, | |||
657 | 706 | ||
658 | /* unmarshall the reply once we've received all of it */ | 707 | /* unmarshall the reply once we've received all of it */ |
659 | bp = call->buffer; | 708 | bp = call->buffer; |
660 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode); | 709 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
661 | xdr_decode_AFSFetchStatus(&bp, &dvnode->status, dvnode); | 710 | xdr_decode_AFSFetchStatus(&bp, &dvnode->status, dvnode, NULL); |
662 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | 711 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
663 | 712 | ||
664 | _leave(" = 0 [done]"); | 713 | _leave(" = 0 [done]"); |
@@ -746,8 +795,8 @@ static int afs_deliver_fs_symlink(struct afs_call *call, | |||
746 | /* unmarshall the reply once we've received all of it */ | 795 | /* unmarshall the reply once we've received all of it */ |
747 | bp = call->buffer; | 796 | bp = call->buffer; |
748 | xdr_decode_AFSFid(&bp, call->reply2); | 797 | xdr_decode_AFSFid(&bp, call->reply2); |
749 | xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL); | 798 | xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL); |
750 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode); | 799 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); |
751 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | 800 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
752 | 801 | ||
753 | _leave(" = 0 [done]"); | 802 | _leave(" = 0 [done]"); |
@@ -852,9 +901,10 @@ static int afs_deliver_fs_rename(struct afs_call *call, | |||
852 | 901 | ||
853 | /* unmarshall the reply once we've received all of it */ | 902 | /* unmarshall the reply once we've received all of it */ |
854 | bp = call->buffer; | 903 | bp = call->buffer; |
855 | xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->status, orig_dvnode); | 904 | xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->status, orig_dvnode, NULL); |
856 | if (new_dvnode != orig_dvnode) | 905 | if (new_dvnode != orig_dvnode) |
857 | xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode); | 906 | xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode, |
907 | NULL); | ||
858 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | 908 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ |
859 | 909 | ||
860 | _leave(" = 0 [done]"); | 910 | _leave(" = 0 [done]"); |
@@ -936,3 +986,262 @@ int afs_fs_rename(struct afs_server *server, | |||
936 | 986 | ||
937 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); | 987 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); |
938 | } | 988 | } |
989 | |||
990 | /* | ||
991 | * deliver reply data to an FS.StoreData | ||
992 | */ | ||
993 | static int afs_deliver_fs_store_data(struct afs_call *call, | ||
994 | struct sk_buff *skb, bool last) | ||
995 | { | ||
996 | struct afs_vnode *vnode = call->reply; | ||
997 | const __be32 *bp; | ||
998 | |||
999 | _enter(",,%u", last); | ||
1000 | |||
1001 | afs_transfer_reply(call, skb); | ||
1002 | if (!last) { | ||
1003 | _leave(" = 0 [more]"); | ||
1004 | return 0; | ||
1005 | } | ||
1006 | |||
1007 | if (call->reply_size != call->reply_max) { | ||
1008 | _leave(" = -EBADMSG [%u != %u]", | ||
1009 | call->reply_size, call->reply_max); | ||
1010 | return -EBADMSG; | ||
1011 | } | ||
1012 | |||
1013 | /* unmarshall the reply once we've received all of it */ | ||
1014 | bp = call->buffer; | ||
1015 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, | ||
1016 | &call->store_version); | ||
1017 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | ||
1018 | |||
1019 | afs_pages_written_back(vnode, call); | ||
1020 | |||
1021 | _leave(" = 0 [done]"); | ||
1022 | return 0; | ||
1023 | } | ||
1024 | |||
1025 | /* | ||
1026 | * FS.StoreData operation type | ||
1027 | */ | ||
1028 | static const struct afs_call_type afs_RXFSStoreData = { | ||
1029 | .name = "FS.StoreData", | ||
1030 | .deliver = afs_deliver_fs_store_data, | ||
1031 | .abort_to_error = afs_abort_to_error, | ||
1032 | .destructor = afs_flat_call_destructor, | ||
1033 | }; | ||
1034 | |||
1035 | /* | ||
1036 | * store a set of pages | ||
1037 | */ | ||
1038 | int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb, | ||
1039 | pgoff_t first, pgoff_t last, | ||
1040 | unsigned offset, unsigned to, | ||
1041 | const struct afs_wait_mode *wait_mode) | ||
1042 | { | ||
1043 | struct afs_vnode *vnode = wb->vnode; | ||
1044 | struct afs_call *call; | ||
1045 | loff_t size, pos, i_size; | ||
1046 | __be32 *bp; | ||
1047 | |||
1048 | _enter(",%x,{%x:%u},,", | ||
1049 | key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode); | ||
1050 | |||
1051 | size = to - offset; | ||
1052 | if (first != last) | ||
1053 | size += (loff_t)(last - first) << PAGE_SHIFT; | ||
1054 | pos = (loff_t)first << PAGE_SHIFT; | ||
1055 | pos += offset; | ||
1056 | |||
1057 | i_size = i_size_read(&vnode->vfs_inode); | ||
1058 | if (pos + size > i_size) | ||
1059 | i_size = size + pos; | ||
1060 | |||
1061 | _debug("size %llx, at %llx, i_size %llx", | ||
1062 | (unsigned long long) size, (unsigned long long) pos, | ||
1063 | (unsigned long long) i_size); | ||
1064 | |||
1065 | BUG_ON(i_size > 0xffffffff); // TODO: use 64-bit store | ||
1066 | |||
1067 | call = afs_alloc_flat_call(&afs_RXFSStoreData, | ||
1068 | (4 + 6 + 3) * 4, | ||
1069 | (21 + 6) * 4); | ||
1070 | if (!call) | ||
1071 | return -ENOMEM; | ||
1072 | |||
1073 | call->wb = wb; | ||
1074 | call->key = wb->key; | ||
1075 | call->reply = vnode; | ||
1076 | call->service_id = FS_SERVICE; | ||
1077 | call->port = htons(AFS_FS_PORT); | ||
1078 | call->mapping = vnode->vfs_inode.i_mapping; | ||
1079 | call->first = first; | ||
1080 | call->last = last; | ||
1081 | call->first_offset = offset; | ||
1082 | call->last_to = to; | ||
1083 | call->send_pages = true; | ||
1084 | call->store_version = vnode->status.data_version + 1; | ||
1085 | |||
1086 | /* marshall the parameters */ | ||
1087 | bp = call->request; | ||
1088 | *bp++ = htonl(FSSTOREDATA); | ||
1089 | *bp++ = htonl(vnode->fid.vid); | ||
1090 | *bp++ = htonl(vnode->fid.vnode); | ||
1091 | *bp++ = htonl(vnode->fid.unique); | ||
1092 | |||
1093 | *bp++ = 0; /* mask */ | ||
1094 | *bp++ = 0; /* mtime */ | ||
1095 | *bp++ = 0; /* owner */ | ||
1096 | *bp++ = 0; /* group */ | ||
1097 | *bp++ = 0; /* unix mode */ | ||
1098 | *bp++ = 0; /* segment size */ | ||
1099 | |||
1100 | *bp++ = htonl(pos); | ||
1101 | *bp++ = htonl(size); | ||
1102 | *bp++ = htonl(i_size); | ||
1103 | |||
1104 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); | ||
1105 | } | ||
1106 | |||
1107 | /* | ||
1108 | * deliver reply data to an FS.StoreStatus | ||
1109 | */ | ||
1110 | static int afs_deliver_fs_store_status(struct afs_call *call, | ||
1111 | struct sk_buff *skb, bool last) | ||
1112 | { | ||
1113 | afs_dataversion_t *store_version; | ||
1114 | struct afs_vnode *vnode = call->reply; | ||
1115 | const __be32 *bp; | ||
1116 | |||
1117 | _enter(",,%u", last); | ||
1118 | |||
1119 | afs_transfer_reply(call, skb); | ||
1120 | if (!last) { | ||
1121 | _leave(" = 0 [more]"); | ||
1122 | return 0; | ||
1123 | } | ||
1124 | |||
1125 | if (call->reply_size != call->reply_max) { | ||
1126 | _leave(" = -EBADMSG [%u != %u]", | ||
1127 | call->reply_size, call->reply_max); | ||
1128 | return -EBADMSG; | ||
1129 | } | ||
1130 | |||
1131 | /* unmarshall the reply once we've received all of it */ | ||
1132 | store_version = NULL; | ||
1133 | if (call->operation_ID == FSSTOREDATA) | ||
1134 | store_version = &call->store_version; | ||
1135 | |||
1136 | bp = call->buffer; | ||
1137 | xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, store_version); | ||
1138 | /* xdr_decode_AFSVolSync(&bp, call->replyX); */ | ||
1139 | |||
1140 | _leave(" = 0 [done]"); | ||
1141 | return 0; | ||
1142 | } | ||
1143 | |||
1144 | /* | ||
1145 | * FS.StoreStatus operation type | ||
1146 | */ | ||
1147 | static const struct afs_call_type afs_RXFSStoreStatus = { | ||
1148 | .name = "FS.StoreStatus", | ||
1149 | .deliver = afs_deliver_fs_store_status, | ||
1150 | .abort_to_error = afs_abort_to_error, | ||
1151 | .destructor = afs_flat_call_destructor, | ||
1152 | }; | ||
1153 | |||
1154 | static const struct afs_call_type afs_RXFSStoreData_as_Status = { | ||
1155 | .name = "FS.StoreData", | ||
1156 | .deliver = afs_deliver_fs_store_status, | ||
1157 | .abort_to_error = afs_abort_to_error, | ||
1158 | .destructor = afs_flat_call_destructor, | ||
1159 | }; | ||
1160 | |||
1161 | /* | ||
1162 | * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus | ||
1163 | * so as to alter the file size also | ||
1164 | */ | ||
1165 | static int afs_fs_setattr_size(struct afs_server *server, struct key *key, | ||
1166 | struct afs_vnode *vnode, struct iattr *attr, | ||
1167 | const struct afs_wait_mode *wait_mode) | ||
1168 | { | ||
1169 | struct afs_call *call; | ||
1170 | __be32 *bp; | ||
1171 | |||
1172 | _enter(",%x,{%x:%u},,", | ||
1173 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); | ||
1174 | |||
1175 | ASSERT(attr->ia_valid & ATTR_SIZE); | ||
1176 | ASSERTCMP(attr->ia_size, <=, 0xffffffff); // TODO: use 64-bit store | ||
1177 | |||
1178 | call = afs_alloc_flat_call(&afs_RXFSStoreData_as_Status, | ||
1179 | (4 + 6 + 3) * 4, | ||
1180 | (21 + 6) * 4); | ||
1181 | if (!call) | ||
1182 | return -ENOMEM; | ||
1183 | |||
1184 | call->key = key; | ||
1185 | call->reply = vnode; | ||
1186 | call->service_id = FS_SERVICE; | ||
1187 | call->port = htons(AFS_FS_PORT); | ||
1188 | call->store_version = vnode->status.data_version + 1; | ||
1189 | call->operation_ID = FSSTOREDATA; | ||
1190 | |||
1191 | /* marshall the parameters */ | ||
1192 | bp = call->request; | ||
1193 | *bp++ = htonl(FSSTOREDATA); | ||
1194 | *bp++ = htonl(vnode->fid.vid); | ||
1195 | *bp++ = htonl(vnode->fid.vnode); | ||
1196 | *bp++ = htonl(vnode->fid.unique); | ||
1197 | |||
1198 | xdr_encode_AFS_StoreStatus(&bp, attr); | ||
1199 | |||
1200 | *bp++ = 0; /* position of start of write */ | ||
1201 | *bp++ = 0; /* size of write */ | ||
1202 | *bp++ = htonl(attr->ia_size); /* new file length */ | ||
1203 | |||
1204 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); | ||
1205 | } | ||
1206 | |||
1207 | /* | ||
1208 | * set the attributes on a file, using FS.StoreData if there's a change in file | ||
1209 | * size, and FS.StoreStatus otherwise | ||
1210 | */ | ||
1211 | int afs_fs_setattr(struct afs_server *server, struct key *key, | ||
1212 | struct afs_vnode *vnode, struct iattr *attr, | ||
1213 | const struct afs_wait_mode *wait_mode) | ||
1214 | { | ||
1215 | struct afs_call *call; | ||
1216 | __be32 *bp; | ||
1217 | |||
1218 | if (attr->ia_valid & ATTR_SIZE) | ||
1219 | return afs_fs_setattr_size(server, key, vnode, attr, | ||
1220 | wait_mode); | ||
1221 | |||
1222 | _enter(",%x,{%x:%u},,", | ||
1223 | key_serial(key), vnode->fid.vid, vnode->fid.vnode); | ||
1224 | |||
1225 | call = afs_alloc_flat_call(&afs_RXFSStoreStatus, | ||
1226 | (4 + 6) * 4, | ||
1227 | (21 + 6) * 4); | ||
1228 | if (!call) | ||
1229 | return -ENOMEM; | ||
1230 | |||
1231 | call->key = key; | ||
1232 | call->reply = vnode; | ||
1233 | call->service_id = FS_SERVICE; | ||
1234 | call->port = htons(AFS_FS_PORT); | ||
1235 | call->operation_ID = FSSTORESTATUS; | ||
1236 | |||
1237 | /* marshall the parameters */ | ||
1238 | bp = call->request; | ||
1239 | *bp++ = htonl(FSSTORESTATUS); | ||
1240 | *bp++ = htonl(vnode->fid.vid); | ||
1241 | *bp++ = htonl(vnode->fid.vnode); | ||
1242 | *bp++ = htonl(vnode->fid.unique); | ||
1243 | |||
1244 | xdr_encode_AFS_StoreStatus(&bp, attr); | ||
1245 | |||
1246 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); | ||
1247 | } | ||
diff --git a/fs/afs/inode.c b/fs/afs/inode.c index c184a4ee5995..515a5d12d8fb 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c | |||
@@ -125,7 +125,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, | |||
125 | struct inode *inode; | 125 | struct inode *inode; |
126 | int ret; | 126 | int ret; |
127 | 127 | ||
128 | _enter(",{%u,%u,%u},,", fid->vid, fid->vnode, fid->unique); | 128 | _enter(",{%x:%u.%u},,", fid->vid, fid->vnode, fid->unique); |
129 | 129 | ||
130 | as = sb->s_fs_info; | 130 | as = sb->s_fs_info; |
131 | data.volume = as->volume; | 131 | data.volume = as->volume; |
@@ -204,6 +204,19 @@ bad_inode: | |||
204 | } | 204 | } |
205 | 205 | ||
206 | /* | 206 | /* |
207 | * mark the data attached to an inode as obsolete due to a write on the server | ||
208 | * - might also want to ditch all the outstanding writes and dirty pages | ||
209 | */ | ||
210 | void afs_zap_data(struct afs_vnode *vnode) | ||
211 | { | ||
212 | _enter("zap data {%x:%u}", vnode->fid.vid, vnode->fid.vnode); | ||
213 | |||
214 | /* nuke all the non-dirty pages that aren't locked, mapped or being | ||
215 | * written back */ | ||
216 | invalidate_remote_inode(&vnode->vfs_inode); | ||
217 | } | ||
218 | |||
219 | /* | ||
207 | * validate a vnode/inode | 220 | * validate a vnode/inode |
208 | * - there are several things we need to check | 221 | * - there are several things we need to check |
209 | * - parent dir data changes (rm, rmdir, rename, mkdir, create, link, | 222 | * - parent dir data changes (rm, rmdir, rename, mkdir, create, link, |
@@ -258,10 +271,8 @@ int afs_validate(struct afs_vnode *vnode, struct key *key) | |||
258 | 271 | ||
259 | /* if the vnode's data version number changed then its contents are | 272 | /* if the vnode's data version number changed then its contents are |
260 | * different */ | 273 | * different */ |
261 | if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) { | 274 | if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) |
262 | _debug("zap data {%x:%d}", vnode->fid.vid, vnode->fid.vnode); | 275 | afs_zap_data(vnode); |
263 | invalidate_remote_inode(&vnode->vfs_inode); | ||
264 | } | ||
265 | 276 | ||
266 | clear_bit(AFS_VNODE_MODIFIED, &vnode->flags); | 277 | clear_bit(AFS_VNODE_MODIFIED, &vnode->flags); |
267 | mutex_unlock(&vnode->validate_lock); | 278 | mutex_unlock(&vnode->validate_lock); |
@@ -278,7 +289,7 @@ error_unlock: | |||
278 | /* | 289 | /* |
279 | * read the attributes of an inode | 290 | * read the attributes of an inode |
280 | */ | 291 | */ |
281 | int afs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, | 292 | int afs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
282 | struct kstat *stat) | 293 | struct kstat *stat) |
283 | { | 294 | { |
284 | struct inode *inode; | 295 | struct inode *inode; |
@@ -301,7 +312,7 @@ void afs_clear_inode(struct inode *inode) | |||
301 | 312 | ||
302 | vnode = AFS_FS_I(inode); | 313 | vnode = AFS_FS_I(inode); |
303 | 314 | ||
304 | _enter("{%x:%d.%d} v=%u x=%u t=%u }", | 315 | _enter("{%x:%u.%d} v=%u x=%u t=%u }", |
305 | vnode->fid.vid, | 316 | vnode->fid.vid, |
306 | vnode->fid.vnode, | 317 | vnode->fid.vnode, |
307 | vnode->fid.unique, | 318 | vnode->fid.unique, |
@@ -323,6 +334,7 @@ void afs_clear_inode(struct inode *inode) | |||
323 | vnode->server = NULL; | 334 | vnode->server = NULL; |
324 | } | 335 | } |
325 | 336 | ||
337 | ASSERT(list_empty(&vnode->writebacks)); | ||
326 | ASSERT(!vnode->cb_promised); | 338 | ASSERT(!vnode->cb_promised); |
327 | 339 | ||
328 | #ifdef AFS_CACHING_SUPPORT | 340 | #ifdef AFS_CACHING_SUPPORT |
@@ -339,3 +351,47 @@ void afs_clear_inode(struct inode *inode) | |||
339 | 351 | ||
340 | _leave(""); | 352 | _leave(""); |
341 | } | 353 | } |
354 | |||
355 | /* | ||
356 | * set the attributes of an inode | ||
357 | */ | ||
358 | int afs_setattr(struct dentry *dentry, struct iattr *attr) | ||
359 | { | ||
360 | struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); | ||
361 | struct key *key; | ||
362 | int ret; | ||
363 | |||
364 | _enter("{%x:%u},{n=%s},%x", | ||
365 | vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name, | ||
366 | attr->ia_valid); | ||
367 | |||
368 | if (!(attr->ia_valid & (ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID | | ||
369 | ATTR_MTIME))) { | ||
370 | _leave(" = 0 [unsupported]"); | ||
371 | return 0; | ||
372 | } | ||
373 | |||
374 | /* flush any dirty data outstanding on a regular file */ | ||
375 | if (S_ISREG(vnode->vfs_inode.i_mode)) { | ||
376 | filemap_write_and_wait(vnode->vfs_inode.i_mapping); | ||
377 | afs_writeback_all(vnode); | ||
378 | } | ||
379 | |||
380 | if (attr->ia_valid & ATTR_FILE) { | ||
381 | key = attr->ia_file->private_data; | ||
382 | } else { | ||
383 | key = afs_request_key(vnode->volume->cell); | ||
384 | if (IS_ERR(key)) { | ||
385 | ret = PTR_ERR(key); | ||
386 | goto error; | ||
387 | } | ||
388 | } | ||
389 | |||
390 | ret = afs_vnode_setattr(vnode, key, attr); | ||
391 | if (!(attr->ia_valid & ATTR_FILE)) | ||
392 | key_put(key); | ||
393 | |||
394 | error: | ||
395 | _leave(" = %d", ret); | ||
396 | return ret; | ||
397 | } | ||
diff --git a/fs/afs/internal.h b/fs/afs/internal.h index d90c158cd934..a30d4fa768e3 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #define AFS_CELL_MAX_ADDRS 15 | 22 | #define AFS_CELL_MAX_ADDRS 15 |
23 | 23 | ||
24 | struct pagevec; | ||
24 | struct afs_call; | 25 | struct afs_call; |
25 | 26 | ||
26 | typedef enum { | 27 | typedef enum { |
@@ -75,12 +76,15 @@ struct afs_call { | |||
75 | struct key *key; /* security for this call */ | 76 | struct key *key; /* security for this call */ |
76 | struct afs_server *server; /* server affected by incoming CM call */ | 77 | struct afs_server *server; /* server affected by incoming CM call */ |
77 | void *request; /* request data (first part) */ | 78 | void *request; /* request data (first part) */ |
78 | void *request2; /* request data (second part) */ | 79 | struct address_space *mapping; /* page set */ |
80 | struct afs_writeback *wb; /* writeback being performed */ | ||
79 | void *buffer; /* reply receive buffer */ | 81 | void *buffer; /* reply receive buffer */ |
80 | void *reply; /* reply buffer (first part) */ | 82 | void *reply; /* reply buffer (first part) */ |
81 | void *reply2; /* reply buffer (second part) */ | 83 | void *reply2; /* reply buffer (second part) */ |
82 | void *reply3; /* reply buffer (third part) */ | 84 | void *reply3; /* reply buffer (third part) */ |
83 | void *reply4; /* reply buffer (fourth part) */ | 85 | void *reply4; /* reply buffer (fourth part) */ |
86 | pgoff_t first; /* first page in mapping to deal with */ | ||
87 | pgoff_t last; /* last page in mapping to deal with */ | ||
84 | enum { /* call state */ | 88 | enum { /* call state */ |
85 | AFS_CALL_REQUESTING, /* request is being sent for outgoing call */ | 89 | AFS_CALL_REQUESTING, /* request is being sent for outgoing call */ |
86 | AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */ | 90 | AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */ |
@@ -97,14 +101,18 @@ struct afs_call { | |||
97 | unsigned request_size; /* size of request data */ | 101 | unsigned request_size; /* size of request data */ |
98 | unsigned reply_max; /* maximum size of reply */ | 102 | unsigned reply_max; /* maximum size of reply */ |
99 | unsigned reply_size; /* current size of reply */ | 103 | unsigned reply_size; /* current size of reply */ |
104 | unsigned first_offset; /* offset into mapping[first] */ | ||
105 | unsigned last_to; /* amount of mapping[last] */ | ||
100 | unsigned short offset; /* offset into received data store */ | 106 | unsigned short offset; /* offset into received data store */ |
101 | unsigned char unmarshall; /* unmarshalling phase */ | 107 | unsigned char unmarshall; /* unmarshalling phase */ |
102 | bool incoming; /* T if incoming call */ | 108 | bool incoming; /* T if incoming call */ |
109 | bool send_pages; /* T if data from mapping should be sent */ | ||
103 | u16 service_id; /* RxRPC service ID to call */ | 110 | u16 service_id; /* RxRPC service ID to call */ |
104 | __be16 port; /* target UDP port */ | 111 | __be16 port; /* target UDP port */ |
105 | __be32 operation_ID; /* operation ID for an incoming call */ | 112 | __be32 operation_ID; /* operation ID for an incoming call */ |
106 | u32 count; /* count for use in unmarshalling */ | 113 | u32 count; /* count for use in unmarshalling */ |
107 | __be32 tmp; /* place to extract temporary data */ | 114 | __be32 tmp; /* place to extract temporary data */ |
115 | afs_dataversion_t store_version; /* updated version expected from store */ | ||
108 | }; | 116 | }; |
109 | 117 | ||
110 | struct afs_call_type { | 118 | struct afs_call_type { |
@@ -124,6 +132,32 @@ struct afs_call_type { | |||
124 | }; | 132 | }; |
125 | 133 | ||
126 | /* | 134 | /* |
135 | * record of an outstanding writeback on a vnode | ||
136 | */ | ||
137 | struct afs_writeback { | ||
138 | struct list_head link; /* link in vnode->writebacks */ | ||
139 | struct work_struct writer; /* work item to perform the writeback */ | ||
140 | struct afs_vnode *vnode; /* vnode to which this write applies */ | ||
141 | struct key *key; /* owner of this write */ | ||
142 | wait_queue_head_t waitq; /* completion and ready wait queue */ | ||
143 | pgoff_t first; /* first page in batch */ | ||
144 | pgoff_t point; /* last page in current store op */ | ||
145 | pgoff_t last; /* last page in batch (inclusive) */ | ||
146 | unsigned offset_first; /* offset into first page of start of write */ | ||
147 | unsigned to_last; /* offset into last page of end of write */ | ||
148 | int num_conflicts; /* count of conflicting writes in list */ | ||
149 | int usage; | ||
150 | bool conflicts; /* T if has dependent conflicts */ | ||
151 | enum { | ||
152 | AFS_WBACK_SYNCING, /* synchronisation being performed */ | ||
153 | AFS_WBACK_PENDING, /* write pending */ | ||
154 | AFS_WBACK_CONFLICTING, /* conflicting writes posted */ | ||
155 | AFS_WBACK_WRITING, /* writing back */ | ||
156 | AFS_WBACK_COMPLETE /* the writeback record has been unlinked */ | ||
157 | } state __attribute__((packed)); | ||
158 | }; | ||
159 | |||
160 | /* | ||
127 | * AFS superblock private data | 161 | * AFS superblock private data |
128 | * - there's one superblock per volume | 162 | * - there's one superblock per volume |
129 | */ | 163 | */ |
@@ -305,6 +339,7 @@ struct afs_vnode { | |||
305 | wait_queue_head_t update_waitq; /* status fetch waitqueue */ | 339 | wait_queue_head_t update_waitq; /* status fetch waitqueue */ |
306 | int update_cnt; /* number of outstanding ops that will update the | 340 | int update_cnt; /* number of outstanding ops that will update the |
307 | * status */ | 341 | * status */ |
342 | spinlock_t writeback_lock; /* lock for writebacks */ | ||
308 | spinlock_t lock; /* waitqueue/flags lock */ | 343 | spinlock_t lock; /* waitqueue/flags lock */ |
309 | unsigned long flags; | 344 | unsigned long flags; |
310 | #define AFS_VNODE_CB_BROKEN 0 /* set if vnode's callback was broken */ | 345 | #define AFS_VNODE_CB_BROKEN 0 /* set if vnode's callback was broken */ |
@@ -316,6 +351,8 @@ struct afs_vnode { | |||
316 | 351 | ||
317 | long acl_order; /* ACL check count (callback break count) */ | 352 | long acl_order; /* ACL check count (callback break count) */ |
318 | 353 | ||
354 | struct list_head writebacks; /* alterations in pagecache that need writing */ | ||
355 | |||
319 | /* outstanding callback notification on this file */ | 356 | /* outstanding callback notification on this file */ |
320 | struct rb_node server_rb; /* link in server->fs_vnodes */ | 357 | struct rb_node server_rb; /* link in server->fs_vnodes */ |
321 | struct rb_node cb_promise; /* link in server->cb_promises */ | 358 | struct rb_node cb_promise; /* link in server->cb_promises */ |
@@ -433,10 +470,6 @@ extern const struct file_operations afs_file_operations; | |||
433 | extern int afs_open(struct inode *, struct file *); | 470 | extern int afs_open(struct inode *, struct file *); |
434 | extern int afs_release(struct inode *, struct file *); | 471 | extern int afs_release(struct inode *, struct file *); |
435 | 472 | ||
436 | #ifdef AFS_CACHING_SUPPORT | ||
437 | extern int afs_cache_get_page_cookie(struct page *, struct cachefs_page **); | ||
438 | #endif | ||
439 | |||
440 | /* | 473 | /* |
441 | * fsclient.c | 474 | * fsclient.c |
442 | */ | 475 | */ |
@@ -467,6 +500,12 @@ extern int afs_fs_rename(struct afs_server *, struct key *, | |||
467 | struct afs_vnode *, const char *, | 500 | struct afs_vnode *, const char *, |
468 | struct afs_vnode *, const char *, | 501 | struct afs_vnode *, const char *, |
469 | const struct afs_wait_mode *); | 502 | const struct afs_wait_mode *); |
503 | extern int afs_fs_store_data(struct afs_server *, struct afs_writeback *, | ||
504 | pgoff_t, pgoff_t, unsigned, unsigned, | ||
505 | const struct afs_wait_mode *); | ||
506 | extern int afs_fs_setattr(struct afs_server *, struct key *, | ||
507 | struct afs_vnode *, struct iattr *, | ||
508 | const struct afs_wait_mode *); | ||
470 | 509 | ||
471 | /* | 510 | /* |
472 | * inode.c | 511 | * inode.c |
@@ -474,10 +513,10 @@ extern int afs_fs_rename(struct afs_server *, struct key *, | |||
474 | extern struct inode *afs_iget(struct super_block *, struct key *, | 513 | extern struct inode *afs_iget(struct super_block *, struct key *, |
475 | struct afs_fid *, struct afs_file_status *, | 514 | struct afs_fid *, struct afs_file_status *, |
476 | struct afs_callback *); | 515 | struct afs_callback *); |
516 | extern void afs_zap_data(struct afs_vnode *); | ||
477 | extern int afs_validate(struct afs_vnode *, struct key *); | 517 | extern int afs_validate(struct afs_vnode *, struct key *); |
478 | extern int afs_inode_getattr(struct vfsmount *, struct dentry *, | 518 | extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
479 | struct kstat *); | 519 | extern int afs_setattr(struct dentry *, struct iattr *); |
480 | extern void afs_zap_permits(struct rcu_head *); | ||
481 | extern void afs_clear_inode(struct inode *); | 520 | extern void afs_clear_inode(struct inode *); |
482 | 521 | ||
483 | /* | 522 | /* |
@@ -533,6 +572,7 @@ extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *, | |||
533 | */ | 572 | */ |
534 | extern void afs_clear_permits(struct afs_vnode *); | 573 | extern void afs_clear_permits(struct afs_vnode *); |
535 | extern void afs_cache_permit(struct afs_vnode *, struct key *, long); | 574 | extern void afs_cache_permit(struct afs_vnode *, struct key *, long); |
575 | extern void afs_zap_permits(struct rcu_head *); | ||
536 | extern struct key *afs_request_key(struct afs_cell *); | 576 | extern struct key *afs_request_key(struct afs_cell *); |
537 | extern int afs_permission(struct inode *, int, struct nameidata *); | 577 | extern int afs_permission(struct inode *, int, struct nameidata *); |
538 | 578 | ||
@@ -629,6 +669,9 @@ extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *, | |||
629 | struct afs_file_status *, struct afs_server **); | 669 | struct afs_file_status *, struct afs_server **); |
630 | extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *, | 670 | extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *, |
631 | struct key *, const char *, const char *); | 671 | struct key *, const char *, const char *); |
672 | extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t, | ||
673 | unsigned, unsigned); | ||
674 | extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *); | ||
632 | 675 | ||
633 | /* | 676 | /* |
634 | * volume.c | 677 | * volume.c |
@@ -645,6 +688,23 @@ extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *); | |||
645 | extern int afs_volume_release_fileserver(struct afs_vnode *, | 688 | extern int afs_volume_release_fileserver(struct afs_vnode *, |
646 | struct afs_server *, int); | 689 | struct afs_server *, int); |
647 | 690 | ||
691 | /* | ||
692 | * write.c | ||
693 | */ | ||
694 | extern int afs_set_page_dirty(struct page *); | ||
695 | extern void afs_put_writeback(struct afs_writeback *); | ||
696 | extern int afs_prepare_write(struct file *, struct page *, unsigned, unsigned); | ||
697 | extern int afs_commit_write(struct file *, struct page *, unsigned, unsigned); | ||
698 | extern int afs_writepage(struct page *, struct writeback_control *); | ||
699 | extern int afs_writepages(struct address_space *, struct writeback_control *); | ||
700 | extern int afs_write_inode(struct inode *, int); | ||
701 | extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); | ||
702 | extern ssize_t afs_file_write(struct kiocb *, const struct iovec *, | ||
703 | unsigned long, loff_t); | ||
704 | extern int afs_writeback_all(struct afs_vnode *); | ||
705 | extern int afs_fsync(struct file *, struct dentry *, int); | ||
706 | |||
707 | |||
648 | /*****************************************************************************/ | 708 | /*****************************************************************************/ |
649 | /* | 709 | /* |
650 | * debug tracing | 710 | * debug tracing |
@@ -726,6 +786,21 @@ do { \ | |||
726 | } \ | 786 | } \ |
727 | } while(0) | 787 | } while(0) |
728 | 788 | ||
789 | #define ASSERTRANGE(L, OP1, N, OP2, H) \ | ||
790 | do { \ | ||
791 | if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \ | ||
792 | printk(KERN_ERR "\n"); \ | ||
793 | printk(KERN_ERR "AFS: Assertion failed\n"); \ | ||
794 | printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \ | ||
795 | (unsigned long)(L), (unsigned long)(N), \ | ||
796 | (unsigned long)(H)); \ | ||
797 | printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \ | ||
798 | (unsigned long)(L), (unsigned long)(N), \ | ||
799 | (unsigned long)(H)); \ | ||
800 | BUG(); \ | ||
801 | } \ | ||
802 | } while(0) | ||
803 | |||
729 | #define ASSERTIF(C, X) \ | 804 | #define ASSERTIF(C, X) \ |
730 | do { \ | 805 | do { \ |
731 | if (unlikely((C) && !(X))) { \ | 806 | if (unlikely((C) && !(X))) { \ |
@@ -758,6 +833,10 @@ do { \ | |||
758 | do { \ | 833 | do { \ |
759 | } while(0) | 834 | } while(0) |
760 | 835 | ||
836 | #define ASSERTRANGE(L, OP1, N, OP2, H) \ | ||
837 | do { \ | ||
838 | } while(0) | ||
839 | |||
761 | #define ASSERTIF(C, X) \ | 840 | #define ASSERTIF(C, X) \ |
762 | do { \ | 841 | do { \ |
763 | } while(0) | 842 | } while(0) |
diff --git a/fs/afs/main.c b/fs/afs/main.c index 80ec6fd19a73..f1f71ff7d5c6 100644 --- a/fs/afs/main.c +++ b/fs/afs/main.c | |||
@@ -149,6 +149,7 @@ error_cache: | |||
149 | afs_vlocation_purge(); | 149 | afs_vlocation_purge(); |
150 | afs_cell_purge(); | 150 | afs_cell_purge(); |
151 | afs_proc_cleanup(); | 151 | afs_proc_cleanup(); |
152 | rcu_barrier(); | ||
152 | printk(KERN_ERR "kAFS: failed to register: %d\n", ret); | 153 | printk(KERN_ERR "kAFS: failed to register: %d\n", ret); |
153 | return ret; | 154 | return ret; |
154 | } | 155 | } |
@@ -176,6 +177,7 @@ static void __exit afs_exit(void) | |||
176 | cachefs_unregister_netfs(&afs_cache_netfs); | 177 | cachefs_unregister_netfs(&afs_cache_netfs); |
177 | #endif | 178 | #endif |
178 | afs_proc_cleanup(); | 179 | afs_proc_cleanup(); |
180 | rcu_barrier(); | ||
179 | } | 181 | } |
180 | 182 | ||
181 | module_exit(afs_exit); | 183 | module_exit(afs_exit); |
diff --git a/fs/afs/misc.c b/fs/afs/misc.c index cdb9792d8161..d1a889c40742 100644 --- a/fs/afs/misc.c +++ b/fs/afs/misc.c | |||
@@ -22,6 +22,7 @@ int afs_abort_to_error(u32 abort_code) | |||
22 | { | 22 | { |
23 | switch (abort_code) { | 23 | switch (abort_code) { |
24 | case 13: return -EACCES; | 24 | case 13: return -EACCES; |
25 | case 27: return -EFBIG; | ||
25 | case 30: return -EROFS; | 26 | case 30: return -EROFS; |
26 | case VSALVAGE: return -EIO; | 27 | case VSALVAGE: return -EIO; |
27 | case VNOVNODE: return -ENOENT; | 28 | case VNOVNODE: return -ENOENT; |
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c index 034fcfd4e330..a3684dcc76e7 100644 --- a/fs/afs/mntpt.c +++ b/fs/afs/mntpt.c | |||
@@ -36,7 +36,7 @@ const struct inode_operations afs_mntpt_inode_operations = { | |||
36 | .lookup = afs_mntpt_lookup, | 36 | .lookup = afs_mntpt_lookup, |
37 | .follow_link = afs_mntpt_follow_link, | 37 | .follow_link = afs_mntpt_follow_link, |
38 | .readlink = page_readlink, | 38 | .readlink = page_readlink, |
39 | .getattr = afs_inode_getattr, | 39 | .getattr = afs_getattr, |
40 | }; | 40 | }; |
41 | 41 | ||
42 | static LIST_HEAD(afs_vfsmounts); | 42 | static LIST_HEAD(afs_vfsmounts); |
@@ -58,7 +58,8 @@ int afs_mntpt_check_symlink(struct afs_vnode *vnode, struct key *key) | |||
58 | char *buf; | 58 | char *buf; |
59 | int ret; | 59 | int ret; |
60 | 60 | ||
61 | _enter("{%u,%u}", vnode->fid.vnode, vnode->fid.unique); | 61 | _enter("{%x:%u,%u}", |
62 | vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); | ||
62 | 63 | ||
63 | /* read the contents of the symlink into the pagecache */ | 64 | /* read the contents of the symlink into the pagecache */ |
64 | page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, &file); | 65 | page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, &file); |
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 222c1a3abbb8..04189c47d6a0 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c | |||
@@ -237,6 +237,70 @@ void afs_flat_call_destructor(struct afs_call *call) | |||
237 | } | 237 | } |
238 | 238 | ||
239 | /* | 239 | /* |
240 | * attach the data from a bunch of pages on an inode to a call | ||
241 | */ | ||
242 | int afs_send_pages(struct afs_call *call, struct msghdr *msg, struct kvec *iov) | ||
243 | { | ||
244 | struct page *pages[8]; | ||
245 | unsigned count, n, loop, offset, to; | ||
246 | pgoff_t first = call->first, last = call->last; | ||
247 | int ret; | ||
248 | |||
249 | _enter(""); | ||
250 | |||
251 | offset = call->first_offset; | ||
252 | call->first_offset = 0; | ||
253 | |||
254 | do { | ||
255 | _debug("attach %lx-%lx", first, last); | ||
256 | |||
257 | count = last - first + 1; | ||
258 | if (count > ARRAY_SIZE(pages)) | ||
259 | count = ARRAY_SIZE(pages); | ||
260 | n = find_get_pages_contig(call->mapping, first, count, pages); | ||
261 | ASSERTCMP(n, ==, count); | ||
262 | |||
263 | loop = 0; | ||
264 | do { | ||
265 | msg->msg_flags = 0; | ||
266 | to = PAGE_SIZE; | ||
267 | if (first + loop >= last) | ||
268 | to = call->last_to; | ||
269 | else | ||
270 | msg->msg_flags = MSG_MORE; | ||
271 | iov->iov_base = kmap(pages[loop]) + offset; | ||
272 | iov->iov_len = to - offset; | ||
273 | offset = 0; | ||
274 | |||
275 | _debug("- range %u-%u%s", | ||
276 | offset, to, msg->msg_flags ? " [more]" : ""); | ||
277 | msg->msg_iov = (struct iovec *) iov; | ||
278 | msg->msg_iovlen = 1; | ||
279 | |||
280 | /* have to change the state *before* sending the last | ||
281 | * packet as RxRPC might give us the reply before it | ||
282 | * returns from sending the request */ | ||
283 | if (first + loop >= last) | ||
284 | call->state = AFS_CALL_AWAIT_REPLY; | ||
285 | ret = rxrpc_kernel_send_data(call->rxcall, msg, | ||
286 | to - offset); | ||
287 | kunmap(pages[loop]); | ||
288 | if (ret < 0) | ||
289 | break; | ||
290 | } while (++loop < count); | ||
291 | first += count; | ||
292 | |||
293 | for (loop = 0; loop < count; loop++) | ||
294 | put_page(pages[loop]); | ||
295 | if (ret < 0) | ||
296 | break; | ||
297 | } while (first < last); | ||
298 | |||
299 | _leave(" = %d", ret); | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | /* | ||
240 | * initiate a call | 304 | * initiate a call |
241 | */ | 305 | */ |
242 | int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, | 306 | int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, |
@@ -253,8 +317,9 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, | |||
253 | ASSERT(call->type != NULL); | 317 | ASSERT(call->type != NULL); |
254 | ASSERT(call->type->name != NULL); | 318 | ASSERT(call->type->name != NULL); |
255 | 319 | ||
256 | _debug("MAKE %p{%s} [%d]", | 320 | _debug("____MAKE %p{%s,%x} [%d]____", |
257 | call, call->type->name, atomic_read(&afs_outstanding_calls)); | 321 | call, call->type->name, key_serial(call->key), |
322 | atomic_read(&afs_outstanding_calls)); | ||
258 | 323 | ||
259 | call->wait_mode = wait_mode; | 324 | call->wait_mode = wait_mode; |
260 | INIT_WORK(&call->async_work, afs_process_async_call); | 325 | INIT_WORK(&call->async_work, afs_process_async_call); |
@@ -289,16 +354,23 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, | |||
289 | msg.msg_iovlen = 1; | 354 | msg.msg_iovlen = 1; |
290 | msg.msg_control = NULL; | 355 | msg.msg_control = NULL; |
291 | msg.msg_controllen = 0; | 356 | msg.msg_controllen = 0; |
292 | msg.msg_flags = 0; | 357 | msg.msg_flags = (call->send_pages ? MSG_MORE : 0); |
293 | 358 | ||
294 | /* have to change the state *before* sending the last packet as RxRPC | 359 | /* have to change the state *before* sending the last packet as RxRPC |
295 | * might give us the reply before it returns from sending the | 360 | * might give us the reply before it returns from sending the |
296 | * request */ | 361 | * request */ |
297 | call->state = AFS_CALL_AWAIT_REPLY; | 362 | if (!call->send_pages) |
363 | call->state = AFS_CALL_AWAIT_REPLY; | ||
298 | ret = rxrpc_kernel_send_data(rxcall, &msg, call->request_size); | 364 | ret = rxrpc_kernel_send_data(rxcall, &msg, call->request_size); |
299 | if (ret < 0) | 365 | if (ret < 0) |
300 | goto error_do_abort; | 366 | goto error_do_abort; |
301 | 367 | ||
368 | if (call->send_pages) { | ||
369 | ret = afs_send_pages(call, &msg, iov); | ||
370 | if (ret < 0) | ||
371 | goto error_do_abort; | ||
372 | } | ||
373 | |||
302 | /* at this point, an async call may no longer exist as it may have | 374 | /* at this point, an async call may no longer exist as it may have |
303 | * already completed */ | 375 | * already completed */ |
304 | return wait_mode->wait(call); | 376 | return wait_mode->wait(call); |
diff --git a/fs/afs/security.c b/fs/afs/security.c index f9f424d80458..e0ea88b63ebf 100644 --- a/fs/afs/security.c +++ b/fs/afs/security.c | |||
@@ -109,7 +109,7 @@ void afs_clear_permits(struct afs_vnode *vnode) | |||
109 | { | 109 | { |
110 | struct afs_permits *permits; | 110 | struct afs_permits *permits; |
111 | 111 | ||
112 | _enter("{%x}", vnode->fid.vnode); | 112 | _enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode); |
113 | 113 | ||
114 | mutex_lock(&vnode->permits_lock); | 114 | mutex_lock(&vnode->permits_lock); |
115 | permits = vnode->permits; | 115 | permits = vnode->permits; |
@@ -132,7 +132,8 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key, long acl_order) | |||
132 | struct afs_vnode *auth_vnode; | 132 | struct afs_vnode *auth_vnode; |
133 | int count, loop; | 133 | int count, loop; |
134 | 134 | ||
135 | _enter("{%x},%x,%lx", vnode->fid.vnode, key_serial(key), acl_order); | 135 | _enter("{%x:%u},%x,%lx", |
136 | vnode->fid.vid, vnode->fid.vnode, key_serial(key), acl_order); | ||
136 | 137 | ||
137 | auth_vnode = afs_get_auth_inode(vnode, key); | 138 | auth_vnode = afs_get_auth_inode(vnode, key); |
138 | if (IS_ERR(auth_vnode)) { | 139 | if (IS_ERR(auth_vnode)) { |
@@ -220,7 +221,8 @@ static int afs_check_permit(struct afs_vnode *vnode, struct key *key, | |||
220 | bool valid; | 221 | bool valid; |
221 | int loop, ret; | 222 | int loop, ret; |
222 | 223 | ||
223 | _enter(""); | 224 | _enter("{%x:%u},%x", |
225 | vnode->fid.vid, vnode->fid.vnode, key_serial(key)); | ||
224 | 226 | ||
225 | auth_vnode = afs_get_auth_inode(vnode, key); | 227 | auth_vnode = afs_get_auth_inode(vnode, key); |
226 | if (IS_ERR(auth_vnode)) { | 228 | if (IS_ERR(auth_vnode)) { |
@@ -268,9 +270,9 @@ static int afs_check_permit(struct afs_vnode *vnode, struct key *key, | |||
268 | _leave(" = %d", ret); | 270 | _leave(" = %d", ret); |
269 | return ret; | 271 | return ret; |
270 | } | 272 | } |
273 | *_access = vnode->status.caller_access; | ||
271 | } | 274 | } |
272 | 275 | ||
273 | *_access = vnode->status.caller_access; | ||
274 | iput(&auth_vnode->vfs_inode); | 276 | iput(&auth_vnode->vfs_inode); |
275 | _leave(" = 0 [access %x]", *_access); | 277 | _leave(" = 0 [access %x]", *_access); |
276 | return 0; | 278 | return 0; |
@@ -288,7 +290,7 @@ int afs_permission(struct inode *inode, int mask, struct nameidata *nd) | |||
288 | struct key *key; | 290 | struct key *key; |
289 | int ret; | 291 | int ret; |
290 | 292 | ||
291 | _enter("{{%x:%x},%lx},%x,", | 293 | _enter("{{%x:%u},%lx},%x,", |
292 | vnode->fid.vid, vnode->fid.vnode, vnode->flags, mask); | 294 | vnode->fid.vid, vnode->fid.vnode, vnode->flags, mask); |
293 | 295 | ||
294 | key = afs_request_key(vnode->volume->cell); | 296 | key = afs_request_key(vnode->volume->cell); |
diff --git a/fs/afs/server.c b/fs/afs/server.c index 96bb23b476a2..231ae4150279 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c | |||
@@ -252,6 +252,9 @@ static void afs_destroy_server(struct afs_server *server) | |||
252 | { | 252 | { |
253 | _enter("%p", server); | 253 | _enter("%p", server); |
254 | 254 | ||
255 | ASSERTIF(server->cb_break_head != server->cb_break_tail, | ||
256 | delayed_work_pending(&server->cb_break_work)); | ||
257 | |||
255 | ASSERTCMP(server->fs_vnodes.rb_node, ==, NULL); | 258 | ASSERTCMP(server->fs_vnodes.rb_node, ==, NULL); |
256 | ASSERTCMP(server->cb_promises.rb_node, ==, NULL); | 259 | ASSERTCMP(server->cb_promises.rb_node, ==, NULL); |
257 | ASSERTCMP(server->cb_break_head, ==, server->cb_break_tail); | 260 | ASSERTCMP(server->cb_break_head, ==, server->cb_break_tail); |
diff --git a/fs/afs/super.c b/fs/afs/super.c index 7030d76155fc..d24be334b608 100644 --- a/fs/afs/super.c +++ b/fs/afs/super.c | |||
@@ -50,6 +50,7 @@ static const struct super_operations afs_super_ops = { | |||
50 | .statfs = simple_statfs, | 50 | .statfs = simple_statfs, |
51 | .alloc_inode = afs_alloc_inode, | 51 | .alloc_inode = afs_alloc_inode, |
52 | .drop_inode = generic_delete_inode, | 52 | .drop_inode = generic_delete_inode, |
53 | .write_inode = afs_write_inode, | ||
53 | .destroy_inode = afs_destroy_inode, | 54 | .destroy_inode = afs_destroy_inode, |
54 | .clear_inode = afs_clear_inode, | 55 | .clear_inode = afs_clear_inode, |
55 | .umount_begin = afs_umount_begin, | 56 | .umount_begin = afs_umount_begin, |
@@ -66,7 +67,7 @@ enum { | |||
66 | afs_opt_vol, | 67 | afs_opt_vol, |
67 | }; | 68 | }; |
68 | 69 | ||
69 | static const match_table_t afs_options_list = { | 70 | static match_table_t afs_options_list = { |
70 | { afs_opt_cell, "cell=%s" }, | 71 | { afs_opt_cell, "cell=%s" }, |
71 | { afs_opt_rwpath, "rwpath" }, | 72 | { afs_opt_rwpath, "rwpath" }, |
72 | { afs_opt_vol, "vol=%s" }, | 73 | { afs_opt_vol, "vol=%s" }, |
@@ -459,7 +460,9 @@ static void afs_i_init_once(void *_vnode, struct kmem_cache *cachep, | |||
459 | init_waitqueue_head(&vnode->update_waitq); | 460 | init_waitqueue_head(&vnode->update_waitq); |
460 | mutex_init(&vnode->permits_lock); | 461 | mutex_init(&vnode->permits_lock); |
461 | mutex_init(&vnode->validate_lock); | 462 | mutex_init(&vnode->validate_lock); |
463 | spin_lock_init(&vnode->writeback_lock); | ||
462 | spin_lock_init(&vnode->lock); | 464 | spin_lock_init(&vnode->lock); |
465 | INIT_LIST_HEAD(&vnode->writebacks); | ||
463 | INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work); | 466 | INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work); |
464 | } | 467 | } |
465 | } | 468 | } |
diff --git a/fs/afs/vnode.c b/fs/afs/vnode.c index a1904ab8426a..ec814660209f 100644 --- a/fs/afs/vnode.c +++ b/fs/afs/vnode.c | |||
@@ -261,7 +261,7 @@ int afs_vnode_fetch_status(struct afs_vnode *vnode, | |||
261 | 261 | ||
262 | DECLARE_WAITQUEUE(myself, current); | 262 | DECLARE_WAITQUEUE(myself, current); |
263 | 263 | ||
264 | _enter("%s,{%u,%u,%u}", | 264 | _enter("%s,{%x:%u.%u}", |
265 | vnode->volume->vlocation->vldb.name, | 265 | vnode->volume->vlocation->vldb.name, |
266 | vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); | 266 | vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); |
267 | 267 | ||
@@ -389,7 +389,7 @@ int afs_vnode_fetch_data(struct afs_vnode *vnode, struct key *key, | |||
389 | struct afs_server *server; | 389 | struct afs_server *server; |
390 | int ret; | 390 | int ret; |
391 | 391 | ||
392 | _enter("%s{%u,%u,%u},%x,,,", | 392 | _enter("%s{%x:%u.%u},%x,,,", |
393 | vnode->volume->vlocation->vldb.name, | 393 | vnode->volume->vlocation->vldb.name, |
394 | vnode->fid.vid, | 394 | vnode->fid.vid, |
395 | vnode->fid.vnode, | 395 | vnode->fid.vnode, |
@@ -446,7 +446,7 @@ int afs_vnode_create(struct afs_vnode *vnode, struct key *key, | |||
446 | struct afs_server *server; | 446 | struct afs_server *server; |
447 | int ret; | 447 | int ret; |
448 | 448 | ||
449 | _enter("%s{%u,%u,%u},%x,%s,,", | 449 | _enter("%s{%x:%u.%u},%x,%s,,", |
450 | vnode->volume->vlocation->vldb.name, | 450 | vnode->volume->vlocation->vldb.name, |
451 | vnode->fid.vid, | 451 | vnode->fid.vid, |
452 | vnode->fid.vnode, | 452 | vnode->fid.vnode, |
@@ -502,7 +502,7 @@ int afs_vnode_remove(struct afs_vnode *vnode, struct key *key, const char *name, | |||
502 | struct afs_server *server; | 502 | struct afs_server *server; |
503 | int ret; | 503 | int ret; |
504 | 504 | ||
505 | _enter("%s{%u,%u,%u},%x,%s", | 505 | _enter("%s{%x:%u.%u},%x,%s", |
506 | vnode->volume->vlocation->vldb.name, | 506 | vnode->volume->vlocation->vldb.name, |
507 | vnode->fid.vid, | 507 | vnode->fid.vid, |
508 | vnode->fid.vnode, | 508 | vnode->fid.vnode, |
@@ -557,7 +557,7 @@ extern int afs_vnode_link(struct afs_vnode *dvnode, struct afs_vnode *vnode, | |||
557 | struct afs_server *server; | 557 | struct afs_server *server; |
558 | int ret; | 558 | int ret; |
559 | 559 | ||
560 | _enter("%s{%u,%u,%u},%s{%u,%u,%u},%x,%s", | 560 | _enter("%s{%x:%u.%u},%s{%x:%u.%u},%x,%s", |
561 | dvnode->volume->vlocation->vldb.name, | 561 | dvnode->volume->vlocation->vldb.name, |
562 | dvnode->fid.vid, | 562 | dvnode->fid.vid, |
563 | dvnode->fid.vnode, | 563 | dvnode->fid.vnode, |
@@ -628,7 +628,7 @@ int afs_vnode_symlink(struct afs_vnode *vnode, struct key *key, | |||
628 | struct afs_server *server; | 628 | struct afs_server *server; |
629 | int ret; | 629 | int ret; |
630 | 630 | ||
631 | _enter("%s{%u,%u,%u},%x,%s,%s,,,", | 631 | _enter("%s{%x:%u.%u},%x,%s,%s,,,", |
632 | vnode->volume->vlocation->vldb.name, | 632 | vnode->volume->vlocation->vldb.name, |
633 | vnode->fid.vid, | 633 | vnode->fid.vid, |
634 | vnode->fid.vnode, | 634 | vnode->fid.vnode, |
@@ -687,7 +687,7 @@ int afs_vnode_rename(struct afs_vnode *orig_dvnode, | |||
687 | struct afs_server *server; | 687 | struct afs_server *server; |
688 | int ret; | 688 | int ret; |
689 | 689 | ||
690 | _enter("%s{%u,%u,%u},%s{%u,%u,%u},%x,%s,%s", | 690 | _enter("%s{%x:%u.%u},%s{%u,%u,%u},%x,%s,%s", |
691 | orig_dvnode->volume->vlocation->vldb.name, | 691 | orig_dvnode->volume->vlocation->vldb.name, |
692 | orig_dvnode->fid.vid, | 692 | orig_dvnode->fid.vid, |
693 | orig_dvnode->fid.vnode, | 693 | orig_dvnode->fid.vnode, |
@@ -753,3 +753,110 @@ no_server: | |||
753 | _leave(" = %ld [cnt %d]", PTR_ERR(server), orig_dvnode->update_cnt); | 753 | _leave(" = %ld [cnt %d]", PTR_ERR(server), orig_dvnode->update_cnt); |
754 | return PTR_ERR(server); | 754 | return PTR_ERR(server); |
755 | } | 755 | } |
756 | |||
757 | /* | ||
758 | * write to a file | ||
759 | */ | ||
760 | int afs_vnode_store_data(struct afs_writeback *wb, pgoff_t first, pgoff_t last, | ||
761 | unsigned offset, unsigned to) | ||
762 | { | ||
763 | struct afs_server *server; | ||
764 | struct afs_vnode *vnode = wb->vnode; | ||
765 | int ret; | ||
766 | |||
767 | _enter("%s{%x:%u.%u},%x,%lx,%lx,%x,%x", | ||
768 | vnode->volume->vlocation->vldb.name, | ||
769 | vnode->fid.vid, | ||
770 | vnode->fid.vnode, | ||
771 | vnode->fid.unique, | ||
772 | key_serial(wb->key), | ||
773 | first, last, offset, to); | ||
774 | |||
775 | /* this op will fetch the status */ | ||
776 | spin_lock(&vnode->lock); | ||
777 | vnode->update_cnt++; | ||
778 | spin_unlock(&vnode->lock); | ||
779 | |||
780 | do { | ||
781 | /* pick a server to query */ | ||
782 | server = afs_volume_pick_fileserver(vnode); | ||
783 | if (IS_ERR(server)) | ||
784 | goto no_server; | ||
785 | |||
786 | _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr)); | ||
787 | |||
788 | ret = afs_fs_store_data(server, wb, first, last, offset, to, | ||
789 | &afs_sync_call); | ||
790 | |||
791 | } while (!afs_volume_release_fileserver(vnode, server, ret)); | ||
792 | |||
793 | /* adjust the flags */ | ||
794 | if (ret == 0) { | ||
795 | afs_vnode_finalise_status_update(vnode, server); | ||
796 | afs_put_server(server); | ||
797 | } else { | ||
798 | afs_vnode_status_update_failed(vnode, ret); | ||
799 | } | ||
800 | |||
801 | _leave(" = %d", ret); | ||
802 | return ret; | ||
803 | |||
804 | no_server: | ||
805 | spin_lock(&vnode->lock); | ||
806 | vnode->update_cnt--; | ||
807 | ASSERTCMP(vnode->update_cnt, >=, 0); | ||
808 | spin_unlock(&vnode->lock); | ||
809 | return PTR_ERR(server); | ||
810 | } | ||
811 | |||
812 | /* | ||
813 | * set the attributes on a file | ||
814 | */ | ||
815 | int afs_vnode_setattr(struct afs_vnode *vnode, struct key *key, | ||
816 | struct iattr *attr) | ||
817 | { | ||
818 | struct afs_server *server; | ||
819 | int ret; | ||
820 | |||
821 | _enter("%s{%x:%u.%u},%x", | ||
822 | vnode->volume->vlocation->vldb.name, | ||
823 | vnode->fid.vid, | ||
824 | vnode->fid.vnode, | ||
825 | vnode->fid.unique, | ||
826 | key_serial(key)); | ||
827 | |||
828 | /* this op will fetch the status */ | ||
829 | spin_lock(&vnode->lock); | ||
830 | vnode->update_cnt++; | ||
831 | spin_unlock(&vnode->lock); | ||
832 | |||
833 | do { | ||
834 | /* pick a server to query */ | ||
835 | server = afs_volume_pick_fileserver(vnode); | ||
836 | if (IS_ERR(server)) | ||
837 | goto no_server; | ||
838 | |||
839 | _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr)); | ||
840 | |||
841 | ret = afs_fs_setattr(server, key, vnode, attr, &afs_sync_call); | ||
842 | |||
843 | } while (!afs_volume_release_fileserver(vnode, server, ret)); | ||
844 | |||
845 | /* adjust the flags */ | ||
846 | if (ret == 0) { | ||
847 | afs_vnode_finalise_status_update(vnode, server); | ||
848 | afs_put_server(server); | ||
849 | } else { | ||
850 | afs_vnode_status_update_failed(vnode, ret); | ||
851 | } | ||
852 | |||
853 | _leave(" = %d", ret); | ||
854 | return ret; | ||
855 | |||
856 | no_server: | ||
857 | spin_lock(&vnode->lock); | ||
858 | vnode->update_cnt--; | ||
859 | ASSERTCMP(vnode->update_cnt, >=, 0); | ||
860 | spin_unlock(&vnode->lock); | ||
861 | return PTR_ERR(server); | ||
862 | } | ||
diff --git a/fs/afs/write.c b/fs/afs/write.c new file mode 100644 index 000000000000..83ff29262816 --- /dev/null +++ b/fs/afs/write.c | |||
@@ -0,0 +1,835 @@ | |||
1 | /* handling of writes to regular files and writing back to the server | ||
2 | * | ||
3 | * Copyright (C) 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/slab.h> | ||
13 | #include <linux/fs.h> | ||
14 | #include <linux/pagemap.h> | ||
15 | #include <linux/writeback.h> | ||
16 | #include <linux/pagevec.h> | ||
17 | #include "internal.h" | ||
18 | |||
19 | static int afs_write_back_from_locked_page(struct afs_writeback *wb, | ||
20 | struct page *page); | ||
21 | |||
22 | /* | ||
23 | * mark a page as having been made dirty and thus needing writeback | ||
24 | */ | ||
25 | int afs_set_page_dirty(struct page *page) | ||
26 | { | ||
27 | _enter(""); | ||
28 | return __set_page_dirty_nobuffers(page); | ||
29 | } | ||
30 | |||
31 | /* | ||
32 | * unlink a writeback record because its usage has reached zero | ||
33 | * - must be called with the wb->vnode->writeback_lock held | ||
34 | */ | ||
35 | static void afs_unlink_writeback(struct afs_writeback *wb) | ||
36 | { | ||
37 | struct afs_writeback *front; | ||
38 | struct afs_vnode *vnode = wb->vnode; | ||
39 | |||
40 | list_del_init(&wb->link); | ||
41 | if (!list_empty(&vnode->writebacks)) { | ||
42 | /* if an fsync rises to the front of the queue then wake it | ||
43 | * up */ | ||
44 | front = list_entry(vnode->writebacks.next, | ||
45 | struct afs_writeback, link); | ||
46 | if (front->state == AFS_WBACK_SYNCING) { | ||
47 | _debug("wake up sync"); | ||
48 | front->state = AFS_WBACK_COMPLETE; | ||
49 | wake_up(&front->waitq); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | /* | ||
55 | * free a writeback record | ||
56 | */ | ||
57 | static void afs_free_writeback(struct afs_writeback *wb) | ||
58 | { | ||
59 | _enter(""); | ||
60 | key_put(wb->key); | ||
61 | kfree(wb); | ||
62 | } | ||
63 | |||
64 | /* | ||
65 | * dispose of a reference to a writeback record | ||
66 | */ | ||
67 | void afs_put_writeback(struct afs_writeback *wb) | ||
68 | { | ||
69 | struct afs_vnode *vnode = wb->vnode; | ||
70 | |||
71 | _enter("{%d}", wb->usage); | ||
72 | |||
73 | spin_lock(&vnode->writeback_lock); | ||
74 | if (--wb->usage == 0) | ||
75 | afs_unlink_writeback(wb); | ||
76 | else | ||
77 | wb = NULL; | ||
78 | spin_unlock(&vnode->writeback_lock); | ||
79 | if (wb) | ||
80 | afs_free_writeback(wb); | ||
81 | } | ||
82 | |||
83 | /* | ||
84 | * partly or wholly fill a page that's under preparation for writing | ||
85 | */ | ||
86 | static int afs_fill_page(struct afs_vnode *vnode, struct key *key, | ||
87 | unsigned start, unsigned len, struct page *page) | ||
88 | { | ||
89 | int ret; | ||
90 | |||
91 | _enter(",,%u,%u", start, len); | ||
92 | |||
93 | ASSERTCMP(start + len, <=, PAGE_SIZE); | ||
94 | |||
95 | ret = afs_vnode_fetch_data(vnode, key, start, len, page); | ||
96 | if (ret < 0) { | ||
97 | if (ret == -ENOENT) { | ||
98 | _debug("got NOENT from server" | ||
99 | " - marking file deleted and stale"); | ||
100 | set_bit(AFS_VNODE_DELETED, &vnode->flags); | ||
101 | ret = -ESTALE; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | _leave(" = %d", ret); | ||
106 | return ret; | ||
107 | } | ||
108 | |||
109 | /* | ||
110 | * prepare a page for being written to | ||
111 | */ | ||
112 | static int afs_prepare_page(struct afs_vnode *vnode, struct page *page, | ||
113 | struct key *key, unsigned offset, unsigned to) | ||
114 | { | ||
115 | unsigned eof, tail, start, stop, len; | ||
116 | loff_t i_size, pos; | ||
117 | void *p; | ||
118 | int ret; | ||
119 | |||
120 | _enter(""); | ||
121 | |||
122 | if (offset == 0 && to == PAGE_SIZE) | ||
123 | return 0; | ||
124 | |||
125 | p = kmap(page); | ||
126 | |||
127 | i_size = i_size_read(&vnode->vfs_inode); | ||
128 | pos = (loff_t) page->index << PAGE_SHIFT; | ||
129 | if (pos >= i_size) { | ||
130 | /* partial write, page beyond EOF */ | ||
131 | _debug("beyond"); | ||
132 | if (offset > 0) | ||
133 | memset(p, 0, offset); | ||
134 | if (to < PAGE_SIZE) | ||
135 | memset(p + to, 0, PAGE_SIZE - to); | ||
136 | kunmap(page); | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | if (i_size - pos >= PAGE_SIZE) { | ||
141 | /* partial write, page entirely before EOF */ | ||
142 | _debug("before"); | ||
143 | tail = eof = PAGE_SIZE; | ||
144 | } else { | ||
145 | /* partial write, page overlaps EOF */ | ||
146 | eof = i_size - pos; | ||
147 | _debug("overlap %u", eof); | ||
148 | tail = max(eof, to); | ||
149 | if (tail < PAGE_SIZE) | ||
150 | memset(p + tail, 0, PAGE_SIZE - tail); | ||
151 | if (offset > eof) | ||
152 | memset(p + eof, 0, PAGE_SIZE - eof); | ||
153 | } | ||
154 | |||
155 | kunmap(p); | ||
156 | |||
157 | ret = 0; | ||
158 | if (offset > 0 || eof > to) { | ||
159 | /* need to fill one or two bits that aren't going to be written | ||
160 | * (cover both fillers in one read if there are two) */ | ||
161 | start = (offset > 0) ? 0 : to; | ||
162 | stop = (eof > to) ? eof : offset; | ||
163 | len = stop - start; | ||
164 | _debug("wr=%u-%u av=0-%u rd=%u@%u", | ||
165 | offset, to, eof, start, len); | ||
166 | ret = afs_fill_page(vnode, key, start, len, page); | ||
167 | } | ||
168 | |||
169 | _leave(" = %d", ret); | ||
170 | return ret; | ||
171 | } | ||
172 | |||
173 | /* | ||
174 | * prepare to perform part of a write to a page | ||
175 | * - the caller holds the page locked, preventing it from being written out or | ||
176 | * modified by anyone else | ||
177 | */ | ||
178 | int afs_prepare_write(struct file *file, struct page *page, | ||
179 | unsigned offset, unsigned to) | ||
180 | { | ||
181 | struct afs_writeback *candidate, *wb; | ||
182 | struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode); | ||
183 | struct key *key = file->private_data; | ||
184 | pgoff_t index; | ||
185 | int ret; | ||
186 | |||
187 | _enter("{%x:%u},{%lx},%u,%u", | ||
188 | vnode->fid.vid, vnode->fid.vnode, page->index, offset, to); | ||
189 | |||
190 | candidate = kzalloc(sizeof(*candidate), GFP_KERNEL); | ||
191 | if (!candidate) | ||
192 | return -ENOMEM; | ||
193 | candidate->vnode = vnode; | ||
194 | candidate->first = candidate->last = page->index; | ||
195 | candidate->offset_first = offset; | ||
196 | candidate->to_last = to; | ||
197 | candidate->usage = 1; | ||
198 | candidate->state = AFS_WBACK_PENDING; | ||
199 | init_waitqueue_head(&candidate->waitq); | ||
200 | |||
201 | if (!PageUptodate(page)) { | ||
202 | _debug("not up to date"); | ||
203 | ret = afs_prepare_page(vnode, page, key, offset, to); | ||
204 | if (ret < 0) { | ||
205 | kfree(candidate); | ||
206 | _leave(" = %d [prep]", ret); | ||
207 | return ret; | ||
208 | } | ||
209 | SetPageUptodate(page); | ||
210 | } | ||
211 | |||
212 | try_again: | ||
213 | index = page->index; | ||
214 | spin_lock(&vnode->writeback_lock); | ||
215 | |||
216 | /* see if this page is already pending a writeback under a suitable key | ||
217 | * - if so we can just join onto that one */ | ||
218 | wb = (struct afs_writeback *) page_private(page); | ||
219 | if (wb) { | ||
220 | if (wb->key == key && wb->state == AFS_WBACK_PENDING) | ||
221 | goto subsume_in_current_wb; | ||
222 | goto flush_conflicting_wb; | ||
223 | } | ||
224 | |||
225 | if (index > 0) { | ||
226 | /* see if we can find an already pending writeback that we can | ||
227 | * append this page to */ | ||
228 | list_for_each_entry(wb, &vnode->writebacks, link) { | ||
229 | if (wb->last == index - 1 && wb->key == key && | ||
230 | wb->state == AFS_WBACK_PENDING) | ||
231 | goto append_to_previous_wb; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | list_add_tail(&candidate->link, &vnode->writebacks); | ||
236 | candidate->key = key_get(key); | ||
237 | spin_unlock(&vnode->writeback_lock); | ||
238 | SetPagePrivate(page); | ||
239 | set_page_private(page, (unsigned long) candidate); | ||
240 | _leave(" = 0 [new]"); | ||
241 | return 0; | ||
242 | |||
243 | subsume_in_current_wb: | ||
244 | _debug("subsume"); | ||
245 | ASSERTRANGE(wb->first, <=, index, <=, wb->last); | ||
246 | if (index == wb->first && offset < wb->offset_first) | ||
247 | wb->offset_first = offset; | ||
248 | if (index == wb->last && to > wb->to_last) | ||
249 | wb->to_last = to; | ||
250 | spin_unlock(&vnode->writeback_lock); | ||
251 | kfree(candidate); | ||
252 | _leave(" = 0 [sub]"); | ||
253 | return 0; | ||
254 | |||
255 | append_to_previous_wb: | ||
256 | _debug("append into %lx-%lx", wb->first, wb->last); | ||
257 | wb->usage++; | ||
258 | wb->last++; | ||
259 | wb->to_last = to; | ||
260 | spin_unlock(&vnode->writeback_lock); | ||
261 | SetPagePrivate(page); | ||
262 | set_page_private(page, (unsigned long) wb); | ||
263 | kfree(candidate); | ||
264 | _leave(" = 0 [app]"); | ||
265 | return 0; | ||
266 | |||
267 | /* the page is currently bound to another context, so if it's dirty we | ||
268 | * need to flush it before we can use the new context */ | ||
269 | flush_conflicting_wb: | ||
270 | _debug("flush conflict"); | ||
271 | if (wb->state == AFS_WBACK_PENDING) | ||
272 | wb->state = AFS_WBACK_CONFLICTING; | ||
273 | spin_unlock(&vnode->writeback_lock); | ||
274 | if (PageDirty(page)) { | ||
275 | ret = afs_write_back_from_locked_page(wb, page); | ||
276 | if (ret < 0) { | ||
277 | afs_put_writeback(candidate); | ||
278 | _leave(" = %d", ret); | ||
279 | return ret; | ||
280 | } | ||
281 | } | ||
282 | |||
283 | /* the page holds a ref on the writeback record */ | ||
284 | afs_put_writeback(wb); | ||
285 | set_page_private(page, 0); | ||
286 | ClearPagePrivate(page); | ||
287 | goto try_again; | ||
288 | } | ||
289 | |||
290 | /* | ||
291 | * finalise part of a write to a page | ||
292 | */ | ||
293 | int afs_commit_write(struct file *file, struct page *page, | ||
294 | unsigned offset, unsigned to) | ||
295 | { | ||
296 | struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode); | ||
297 | loff_t i_size, maybe_i_size; | ||
298 | |||
299 | _enter("{%x:%u},{%lx},%u,%u", | ||
300 | vnode->fid.vid, vnode->fid.vnode, page->index, offset, to); | ||
301 | |||
302 | maybe_i_size = (loff_t) page->index << PAGE_SHIFT; | ||
303 | maybe_i_size += to; | ||
304 | |||
305 | i_size = i_size_read(&vnode->vfs_inode); | ||
306 | if (maybe_i_size > i_size) { | ||
307 | spin_lock(&vnode->writeback_lock); | ||
308 | i_size = i_size_read(&vnode->vfs_inode); | ||
309 | if (maybe_i_size > i_size) | ||
310 | i_size_write(&vnode->vfs_inode, maybe_i_size); | ||
311 | spin_unlock(&vnode->writeback_lock); | ||
312 | } | ||
313 | |||
314 | set_page_dirty(page); | ||
315 | |||
316 | if (PageDirty(page)) | ||
317 | _debug("dirtied"); | ||
318 | |||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | /* | ||
323 | * kill all the pages in the given range | ||
324 | */ | ||
325 | static void afs_kill_pages(struct afs_vnode *vnode, bool error, | ||
326 | pgoff_t first, pgoff_t last) | ||
327 | { | ||
328 | struct pagevec pv; | ||
329 | unsigned count, loop; | ||
330 | |||
331 | _enter("{%x:%u},%lx-%lx", | ||
332 | vnode->fid.vid, vnode->fid.vnode, first, last); | ||
333 | |||
334 | pagevec_init(&pv, 0); | ||
335 | |||
336 | do { | ||
337 | _debug("kill %lx-%lx", first, last); | ||
338 | |||
339 | count = last - first + 1; | ||
340 | if (count > PAGEVEC_SIZE) | ||
341 | count = PAGEVEC_SIZE; | ||
342 | pv.nr = find_get_pages_contig(vnode->vfs_inode.i_mapping, | ||
343 | first, count, pv.pages); | ||
344 | ASSERTCMP(pv.nr, ==, count); | ||
345 | |||
346 | for (loop = 0; loop < count; loop++) { | ||
347 | ClearPageUptodate(pv.pages[loop]); | ||
348 | if (error) | ||
349 | SetPageError(pv.pages[loop]); | ||
350 | end_page_writeback(pv.pages[loop]); | ||
351 | } | ||
352 | |||
353 | __pagevec_release(&pv); | ||
354 | } while (first < last); | ||
355 | |||
356 | _leave(""); | ||
357 | } | ||
358 | |||
359 | /* | ||
360 | * synchronously write back the locked page and any subsequent non-locked dirty | ||
361 | * pages also covered by the same writeback record | ||
362 | */ | ||
363 | static int afs_write_back_from_locked_page(struct afs_writeback *wb, | ||
364 | struct page *primary_page) | ||
365 | { | ||
366 | struct page *pages[8], *page; | ||
367 | unsigned long count; | ||
368 | unsigned n, offset, to; | ||
369 | pgoff_t start, first, last; | ||
370 | int loop, ret; | ||
371 | |||
372 | _enter(",%lx", primary_page->index); | ||
373 | |||
374 | count = 1; | ||
375 | if (!clear_page_dirty_for_io(primary_page)) | ||
376 | BUG(); | ||
377 | if (test_set_page_writeback(primary_page)) | ||
378 | BUG(); | ||
379 | |||
380 | /* find all consecutive lockable dirty pages, stopping when we find a | ||
381 | * page that is not immediately lockable, is not dirty or is missing, | ||
382 | * or we reach the end of the range */ | ||
383 | start = primary_page->index; | ||
384 | if (start >= wb->last) | ||
385 | goto no_more; | ||
386 | start++; | ||
387 | do { | ||
388 | _debug("more %lx [%lx]", start, count); | ||
389 | n = wb->last - start + 1; | ||
390 | if (n > ARRAY_SIZE(pages)) | ||
391 | n = ARRAY_SIZE(pages); | ||
392 | n = find_get_pages_contig(wb->vnode->vfs_inode.i_mapping, | ||
393 | start, n, pages); | ||
394 | _debug("fgpc %u", n); | ||
395 | if (n == 0) | ||
396 | goto no_more; | ||
397 | if (pages[0]->index != start) { | ||
398 | for (n--; n >= 0; n--) | ||
399 | put_page(pages[n]); | ||
400 | goto no_more; | ||
401 | } | ||
402 | |||
403 | for (loop = 0; loop < n; loop++) { | ||
404 | page = pages[loop]; | ||
405 | if (page->index > wb->last) | ||
406 | break; | ||
407 | if (TestSetPageLocked(page)) | ||
408 | break; | ||
409 | if (!PageDirty(page) || | ||
410 | page_private(page) != (unsigned long) wb) { | ||
411 | unlock_page(page); | ||
412 | break; | ||
413 | } | ||
414 | if (!clear_page_dirty_for_io(page)) | ||
415 | BUG(); | ||
416 | if (test_set_page_writeback(page)) | ||
417 | BUG(); | ||
418 | unlock_page(page); | ||
419 | put_page(page); | ||
420 | } | ||
421 | count += loop; | ||
422 | if (loop < n) { | ||
423 | for (; loop < n; loop++) | ||
424 | put_page(pages[loop]); | ||
425 | goto no_more; | ||
426 | } | ||
427 | |||
428 | start += loop; | ||
429 | } while (start <= wb->last && count < 65536); | ||
430 | |||
431 | no_more: | ||
432 | /* we now have a contiguous set of dirty pages, each with writeback set | ||
433 | * and the dirty mark cleared; the first page is locked and must remain | ||
434 | * so, all the rest are unlocked */ | ||
435 | first = primary_page->index; | ||
436 | last = first + count - 1; | ||
437 | |||
438 | offset = (first == wb->first) ? wb->offset_first : 0; | ||
439 | to = (last == wb->last) ? wb->to_last : PAGE_SIZE; | ||
440 | |||
441 | _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to); | ||
442 | |||
443 | ret = afs_vnode_store_data(wb, first, last, offset, to); | ||
444 | if (ret < 0) { | ||
445 | switch (ret) { | ||
446 | case -EDQUOT: | ||
447 | case -ENOSPC: | ||
448 | set_bit(AS_ENOSPC, | ||
449 | &wb->vnode->vfs_inode.i_mapping->flags); | ||
450 | break; | ||
451 | case -EROFS: | ||
452 | case -EIO: | ||
453 | case -EREMOTEIO: | ||
454 | case -EFBIG: | ||
455 | case -ENOENT: | ||
456 | case -ENOMEDIUM: | ||
457 | case -ENXIO: | ||
458 | afs_kill_pages(wb->vnode, true, first, last); | ||
459 | set_bit(AS_EIO, &wb->vnode->vfs_inode.i_mapping->flags); | ||
460 | break; | ||
461 | case -EACCES: | ||
462 | case -EPERM: | ||
463 | case -ENOKEY: | ||
464 | case -EKEYEXPIRED: | ||
465 | case -EKEYREJECTED: | ||
466 | case -EKEYREVOKED: | ||
467 | afs_kill_pages(wb->vnode, false, first, last); | ||
468 | break; | ||
469 | default: | ||
470 | break; | ||
471 | } | ||
472 | } else { | ||
473 | ret = count; | ||
474 | } | ||
475 | |||
476 | _leave(" = %d", ret); | ||
477 | return ret; | ||
478 | } | ||
479 | |||
480 | /* | ||
481 | * write a page back to the server | ||
482 | * - the caller locked the page for us | ||
483 | */ | ||
484 | int afs_writepage(struct page *page, struct writeback_control *wbc) | ||
485 | { | ||
486 | struct backing_dev_info *bdi = page->mapping->backing_dev_info; | ||
487 | struct afs_writeback *wb; | ||
488 | int ret; | ||
489 | |||
490 | _enter("{%lx},", page->index); | ||
491 | |||
492 | if (wbc->sync_mode != WB_SYNC_NONE) | ||
493 | wait_on_page_writeback(page); | ||
494 | |||
495 | if (PageWriteback(page) || !PageDirty(page)) { | ||
496 | unlock_page(page); | ||
497 | return 0; | ||
498 | } | ||
499 | |||
500 | wb = (struct afs_writeback *) page_private(page); | ||
501 | ASSERT(wb != NULL); | ||
502 | |||
503 | ret = afs_write_back_from_locked_page(wb, page); | ||
504 | unlock_page(page); | ||
505 | if (ret < 0) { | ||
506 | _leave(" = %d", ret); | ||
507 | return 0; | ||
508 | } | ||
509 | |||
510 | wbc->nr_to_write -= ret; | ||
511 | if (wbc->nonblocking && bdi_write_congested(bdi)) | ||
512 | wbc->encountered_congestion = 1; | ||
513 | |||
514 | _leave(" = 0"); | ||
515 | return 0; | ||
516 | } | ||
517 | |||
518 | /* | ||
519 | * write a region of pages back to the server | ||
520 | */ | ||
521 | int afs_writepages_region(struct address_space *mapping, | ||
522 | struct writeback_control *wbc, | ||
523 | pgoff_t index, pgoff_t end, pgoff_t *_next) | ||
524 | { | ||
525 | struct backing_dev_info *bdi = mapping->backing_dev_info; | ||
526 | struct afs_writeback *wb; | ||
527 | struct page *page; | ||
528 | int ret, n; | ||
529 | |||
530 | _enter(",,%lx,%lx,", index, end); | ||
531 | |||
532 | do { | ||
533 | n = find_get_pages_tag(mapping, &index, PAGECACHE_TAG_DIRTY, | ||
534 | 1, &page); | ||
535 | if (!n) | ||
536 | break; | ||
537 | |||
538 | _debug("wback %lx", page->index); | ||
539 | |||
540 | if (page->index > end) { | ||
541 | *_next = index; | ||
542 | page_cache_release(page); | ||
543 | _leave(" = 0 [%lx]", *_next); | ||
544 | return 0; | ||
545 | } | ||
546 | |||
547 | /* at this point we hold neither mapping->tree_lock nor lock on | ||
548 | * the page itself: the page may be truncated or invalidated | ||
549 | * (changing page->mapping to NULL), or even swizzled back from | ||
550 | * swapper_space to tmpfs file mapping | ||
551 | */ | ||
552 | lock_page(page); | ||
553 | |||
554 | if (page->mapping != mapping) { | ||
555 | unlock_page(page); | ||
556 | page_cache_release(page); | ||
557 | continue; | ||
558 | } | ||
559 | |||
560 | if (wbc->sync_mode != WB_SYNC_NONE) | ||
561 | wait_on_page_writeback(page); | ||
562 | |||
563 | if (PageWriteback(page) || !PageDirty(page)) { | ||
564 | unlock_page(page); | ||
565 | continue; | ||
566 | } | ||
567 | |||
568 | wb = (struct afs_writeback *) page_private(page); | ||
569 | ASSERT(wb != NULL); | ||
570 | |||
571 | spin_lock(&wb->vnode->writeback_lock); | ||
572 | wb->state = AFS_WBACK_WRITING; | ||
573 | spin_unlock(&wb->vnode->writeback_lock); | ||
574 | |||
575 | ret = afs_write_back_from_locked_page(wb, page); | ||
576 | unlock_page(page); | ||
577 | page_cache_release(page); | ||
578 | if (ret < 0) { | ||
579 | _leave(" = %d", ret); | ||
580 | return ret; | ||
581 | } | ||
582 | |||
583 | wbc->nr_to_write -= ret; | ||
584 | |||
585 | if (wbc->nonblocking && bdi_write_congested(bdi)) { | ||
586 | wbc->encountered_congestion = 1; | ||
587 | break; | ||
588 | } | ||
589 | |||
590 | cond_resched(); | ||
591 | } while (index < end && wbc->nr_to_write > 0); | ||
592 | |||
593 | *_next = index; | ||
594 | _leave(" = 0 [%lx]", *_next); | ||
595 | return 0; | ||
596 | } | ||
597 | |||
598 | /* | ||
599 | * write some of the pending data back to the server | ||
600 | */ | ||
601 | int afs_writepages(struct address_space *mapping, | ||
602 | struct writeback_control *wbc) | ||
603 | { | ||
604 | struct backing_dev_info *bdi = mapping->backing_dev_info; | ||
605 | pgoff_t start, end, next; | ||
606 | int ret; | ||
607 | |||
608 | _enter(""); | ||
609 | |||
610 | if (wbc->nonblocking && bdi_write_congested(bdi)) { | ||
611 | wbc->encountered_congestion = 1; | ||
612 | _leave(" = 0 [congest]"); | ||
613 | return 0; | ||
614 | } | ||
615 | |||
616 | if (wbc->range_cyclic) { | ||
617 | start = mapping->writeback_index; | ||
618 | end = -1; | ||
619 | ret = afs_writepages_region(mapping, wbc, start, end, &next); | ||
620 | if (start > 0 && wbc->nr_to_write > 0 && ret == 0 && | ||
621 | !(wbc->nonblocking && wbc->encountered_congestion)) | ||
622 | ret = afs_writepages_region(mapping, wbc, 0, start, | ||
623 | &next); | ||
624 | mapping->writeback_index = next; | ||
625 | } else if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) { | ||
626 | end = (pgoff_t)(LLONG_MAX >> PAGE_CACHE_SHIFT); | ||
627 | ret = afs_writepages_region(mapping, wbc, 0, end, &next); | ||
628 | if (wbc->nr_to_write > 0) | ||
629 | mapping->writeback_index = next; | ||
630 | } else { | ||
631 | start = wbc->range_start >> PAGE_CACHE_SHIFT; | ||
632 | end = wbc->range_end >> PAGE_CACHE_SHIFT; | ||
633 | ret = afs_writepages_region(mapping, wbc, start, end, &next); | ||
634 | } | ||
635 | |||
636 | _leave(" = %d", ret); | ||
637 | return ret; | ||
638 | } | ||
639 | |||
640 | /* | ||
641 | * write an inode back | ||
642 | */ | ||
643 | int afs_write_inode(struct inode *inode, int sync) | ||
644 | { | ||
645 | struct afs_vnode *vnode = AFS_FS_I(inode); | ||
646 | int ret; | ||
647 | |||
648 | _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode); | ||
649 | |||
650 | ret = 0; | ||
651 | if (sync) { | ||
652 | ret = filemap_fdatawait(inode->i_mapping); | ||
653 | if (ret < 0) | ||
654 | __mark_inode_dirty(inode, I_DIRTY_DATASYNC); | ||
655 | } | ||
656 | |||
657 | _leave(" = %d", ret); | ||
658 | return ret; | ||
659 | } | ||
660 | |||
661 | /* | ||
662 | * completion of write to server | ||
663 | */ | ||
664 | void afs_pages_written_back(struct afs_vnode *vnode, struct afs_call *call) | ||
665 | { | ||
666 | struct afs_writeback *wb = call->wb; | ||
667 | struct pagevec pv; | ||
668 | unsigned count, loop; | ||
669 | pgoff_t first = call->first, last = call->last; | ||
670 | bool free_wb; | ||
671 | |||
672 | _enter("{%x:%u},{%lx-%lx}", | ||
673 | vnode->fid.vid, vnode->fid.vnode, first, last); | ||
674 | |||
675 | ASSERT(wb != NULL); | ||
676 | |||
677 | pagevec_init(&pv, 0); | ||
678 | |||
679 | do { | ||
680 | _debug("attach %lx-%lx", first, last); | ||
681 | |||
682 | count = last - first + 1; | ||
683 | if (count > PAGEVEC_SIZE) | ||
684 | count = PAGEVEC_SIZE; | ||
685 | pv.nr = find_get_pages_contig(call->mapping, first, count, | ||
686 | pv.pages); | ||
687 | ASSERTCMP(pv.nr, ==, count); | ||
688 | |||
689 | spin_lock(&vnode->writeback_lock); | ||
690 | for (loop = 0; loop < count; loop++) { | ||
691 | struct page *page = pv.pages[loop]; | ||
692 | end_page_writeback(page); | ||
693 | if (page_private(page) == (unsigned long) wb) { | ||
694 | set_page_private(page, 0); | ||
695 | ClearPagePrivate(page); | ||
696 | wb->usage--; | ||
697 | } | ||
698 | } | ||
699 | free_wb = false; | ||
700 | if (wb->usage == 0) { | ||
701 | afs_unlink_writeback(wb); | ||
702 | free_wb = true; | ||
703 | } | ||
704 | spin_unlock(&vnode->writeback_lock); | ||
705 | first += count; | ||
706 | if (free_wb) { | ||
707 | afs_free_writeback(wb); | ||
708 | wb = NULL; | ||
709 | } | ||
710 | |||
711 | __pagevec_release(&pv); | ||
712 | } while (first < last); | ||
713 | |||
714 | _leave(""); | ||
715 | } | ||
716 | |||
717 | /* | ||
718 | * write to an AFS file | ||
719 | */ | ||
720 | ssize_t afs_file_write(struct kiocb *iocb, const struct iovec *iov, | ||
721 | unsigned long nr_segs, loff_t pos) | ||
722 | { | ||
723 | struct dentry *dentry = iocb->ki_filp->f_path.dentry; | ||
724 | struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); | ||
725 | ssize_t result; | ||
726 | size_t count = iov_length(iov, nr_segs); | ||
727 | int ret; | ||
728 | |||
729 | _enter("{%x.%u},{%zu},%lu,", | ||
730 | vnode->fid.vid, vnode->fid.vnode, count, nr_segs); | ||
731 | |||
732 | if (IS_SWAPFILE(&vnode->vfs_inode)) { | ||
733 | printk(KERN_INFO | ||
734 | "AFS: Attempt to write to active swap file!\n"); | ||
735 | return -EBUSY; | ||
736 | } | ||
737 | |||
738 | if (!count) | ||
739 | return 0; | ||
740 | |||
741 | result = generic_file_aio_write(iocb, iov, nr_segs, pos); | ||
742 | if (IS_ERR_VALUE(result)) { | ||
743 | _leave(" = %zd", result); | ||
744 | return result; | ||
745 | } | ||
746 | |||
747 | /* return error values for O_SYNC and IS_SYNC() */ | ||
748 | if (IS_SYNC(&vnode->vfs_inode) || iocb->ki_filp->f_flags & O_SYNC) { | ||
749 | ret = afs_fsync(iocb->ki_filp, dentry, 1); | ||
750 | if (ret < 0) | ||
751 | result = ret; | ||
752 | } | ||
753 | |||
754 | _leave(" = %zd", result); | ||
755 | return result; | ||
756 | } | ||
757 | |||
758 | /* | ||
759 | * flush the vnode to the fileserver | ||
760 | */ | ||
761 | int afs_writeback_all(struct afs_vnode *vnode) | ||
762 | { | ||
763 | struct address_space *mapping = vnode->vfs_inode.i_mapping; | ||
764 | struct writeback_control wbc = { | ||
765 | .bdi = mapping->backing_dev_info, | ||
766 | .sync_mode = WB_SYNC_ALL, | ||
767 | .nr_to_write = LONG_MAX, | ||
768 | .for_writepages = 1, | ||
769 | .range_cyclic = 1, | ||
770 | }; | ||
771 | int ret; | ||
772 | |||
773 | _enter(""); | ||
774 | |||
775 | ret = mapping->a_ops->writepages(mapping, &wbc); | ||
776 | __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); | ||
777 | |||
778 | _leave(" = %d", ret); | ||
779 | return ret; | ||
780 | } | ||
781 | |||
782 | /* | ||
783 | * flush any dirty pages for this process, and check for write errors. | ||
784 | * - the return status from this call provides a reliable indication of | ||
785 | * whether any write errors occurred for this process. | ||
786 | */ | ||
787 | int afs_fsync(struct file *file, struct dentry *dentry, int datasync) | ||
788 | { | ||
789 | struct afs_writeback *wb, *xwb; | ||
790 | struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); | ||
791 | int ret; | ||
792 | |||
793 | _enter("{%x:%u},{n=%s},%d", | ||
794 | vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name, | ||
795 | datasync); | ||
796 | |||
797 | /* use a writeback record as a marker in the queue - when this reaches | ||
798 | * the front of the queue, all the outstanding writes are either | ||
799 | * completed or rejected */ | ||
800 | wb = kzalloc(sizeof(*wb), GFP_KERNEL); | ||
801 | if (!wb) | ||
802 | return -ENOMEM; | ||
803 | wb->vnode = vnode; | ||
804 | wb->first = 0; | ||
805 | wb->last = -1; | ||
806 | wb->offset_first = 0; | ||
807 | wb->to_last = PAGE_SIZE; | ||
808 | wb->usage = 1; | ||
809 | wb->state = AFS_WBACK_SYNCING; | ||
810 | init_waitqueue_head(&wb->waitq); | ||
811 | |||
812 | spin_lock(&vnode->writeback_lock); | ||
813 | list_for_each_entry(xwb, &vnode->writebacks, link) { | ||
814 | if (xwb->state == AFS_WBACK_PENDING) | ||
815 | xwb->state = AFS_WBACK_CONFLICTING; | ||
816 | } | ||
817 | list_add_tail(&wb->link, &vnode->writebacks); | ||
818 | spin_unlock(&vnode->writeback_lock); | ||
819 | |||
820 | /* push all the outstanding writebacks to the server */ | ||
821 | ret = afs_writeback_all(vnode); | ||
822 | if (ret < 0) { | ||
823 | afs_put_writeback(wb); | ||
824 | _leave(" = %d [wb]", ret); | ||
825 | return ret; | ||
826 | } | ||
827 | |||
828 | /* wait for the preceding writes to actually complete */ | ||
829 | ret = wait_event_interruptible(wb->waitq, | ||
830 | wb->state == AFS_WBACK_COMPLETE || | ||
831 | vnode->writebacks.next == &wb->link); | ||
832 | afs_put_writeback(wb); | ||
833 | _leave(" = %d", ret); | ||
834 | return ret; | ||
835 | } | ||