11
11
#include <linux/pagemap.h>
12
12
#include <linux/writeback.h>
13
13
#include <linux/pagevec.h>
14
+ #include <linux/netfs.h>
15
+ #include <linux/fscache.h>
14
16
#include "internal.h"
15
17
16
18
/*
@@ -22,68 +24,6 @@ int afs_set_page_dirty(struct page *page)
22
24
return __set_page_dirty_nobuffers (page );
23
25
}
24
26
25
- /*
26
- * Handle completion of a read operation to fill a page.
27
- */
28
- static void afs_fill_hole (struct afs_read * req )
29
- {
30
- if (iov_iter_count (req -> iter ) > 0 )
31
- /* The read was short - clear the excess buffer. */
32
- iov_iter_zero (iov_iter_count (req -> iter ), req -> iter );
33
- }
34
-
35
- /*
36
- * partly or wholly fill a page that's under preparation for writing
37
- */
38
- static int afs_fill_page (struct file * file ,
39
- loff_t pos , unsigned int len , struct page * page )
40
- {
41
- struct afs_vnode * vnode = AFS_FS_I (file_inode (file ));
42
- struct afs_read * req ;
43
- size_t p ;
44
- void * data ;
45
- int ret ;
46
-
47
- _enter (",,%llu" , (unsigned long long )pos );
48
-
49
- if (pos >= vnode -> vfs_inode .i_size ) {
50
- p = pos & ~PAGE_MASK ;
51
- ASSERTCMP (p + len , <=, PAGE_SIZE );
52
- data = kmap (page );
53
- memset (data + p , 0 , len );
54
- kunmap (page );
55
- return 0 ;
56
- }
57
-
58
- req = kzalloc (sizeof (struct afs_read ), GFP_KERNEL );
59
- if (!req )
60
- return - ENOMEM ;
61
-
62
- refcount_set (& req -> usage , 1 );
63
- req -> vnode = vnode ;
64
- req -> done = afs_fill_hole ;
65
- req -> key = key_get (afs_file_key (file ));
66
- req -> pos = pos ;
67
- req -> len = len ;
68
- req -> nr_pages = 1 ;
69
- req -> iter = & req -> def_iter ;
70
- iov_iter_xarray (& req -> def_iter , READ , & file -> f_mapping -> i_pages , pos , len );
71
-
72
- ret = afs_fetch_data (vnode , req );
73
- afs_put_read (req );
74
- if (ret < 0 ) {
75
- if (ret == - ENOENT ) {
76
- _debug ("got NOENT from server"
77
- " - marking file deleted and stale" );
78
- set_bit (AFS_VNODE_DELETED , & vnode -> flags );
79
- ret = - ESTALE ;
80
- }
81
- }
82
-
83
- _leave (" = %d" , ret );
84
- return ret ;
85
- }
86
-
87
27
/*
88
28
* prepare to perform part of a write to a page
89
29
*/
@@ -102,24 +42,14 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
102
42
_enter ("{%llx:%llu},%llx,%x" ,
103
43
vnode -> fid .vid , vnode -> fid .vnode , pos , len );
104
44
105
- page = grab_cache_page_write_begin (mapping , pos / PAGE_SIZE , flags );
106
- if (!page )
107
- return - ENOMEM ;
108
-
109
- if (!PageUptodate (page ) && len != PAGE_SIZE ) {
110
- ret = afs_fill_page (file , pos & PAGE_MASK , PAGE_SIZE , page );
111
- if (ret < 0 ) {
112
- unlock_page (page );
113
- put_page (page );
114
- _leave (" = %d [prep]" , ret );
115
- return ret ;
116
- }
117
- SetPageUptodate (page );
118
- }
119
-
120
- #ifdef CONFIG_AFS_FSCACHE
121
- wait_on_page_fscache (page );
122
- #endif
45
+ /* Prefetch area to be written into the cache if we're caching this
46
+ * file. We need to do this before we get a lock on the page in case
47
+ * there's more than one writer competing for the same cache block.
48
+ */
49
+ ret = netfs_write_begin (file , mapping , pos , len , flags , & page , fsdata ,
50
+ & afs_req_ops , NULL );
51
+ if (ret < 0 )
52
+ return ret ;
123
53
124
54
index = page -> index ;
125
55
from = pos - index * PAGE_SIZE ;
@@ -184,7 +114,6 @@ int afs_write_end(struct file *file, struct address_space *mapping,
184
114
unsigned int f , from = pos & (thp_size (page ) - 1 );
185
115
unsigned int t , to = from + copied ;
186
116
loff_t i_size , maybe_i_size ;
187
- int ret = 0 ;
188
117
189
118
_enter ("{%llx:%llu},{%lx}" ,
190
119
vnode -> fid .vid , vnode -> fid .vnode , page -> index );
@@ -203,19 +132,7 @@ int afs_write_end(struct file *file, struct address_space *mapping,
203
132
write_sequnlock (& vnode -> cb_lock );
204
133
}
205
134
206
- if (!PageUptodate (page )) {
207
- if (copied < len ) {
208
- /* Try and load any missing data from the server. The
209
- * unmarshalling routine will take care of clearing any
210
- * bits that are beyond the EOF.
211
- */
212
- ret = afs_fill_page (file , pos + copied ,
213
- len - copied , page );
214
- if (ret < 0 )
215
- goto out ;
216
- }
217
- SetPageUptodate (page );
218
- }
135
+ ASSERT (PageUptodate (page ));
219
136
220
137
if (PagePrivate (page )) {
221
138
priv = page_private (page );
@@ -236,12 +153,11 @@ int afs_write_end(struct file *file, struct address_space *mapping,
236
153
237
154
if (set_page_dirty (page ))
238
155
_debug ("dirtied %lx" , page -> index );
239
- ret = copied ;
240
156
241
157
out :
242
158
unlock_page (page );
243
159
put_page (page );
244
- return ret ;
160
+ return copied ;
245
161
}
246
162
247
163
/*
0 commit comments