@@ -249,48 +249,128 @@ void nfs_fscache_release_file(struct inode *inode, struct file *filp)
249249 }
250250}
251251
252+ static inline void fscache_end_operation (struct netfs_cache_resources * cres )
253+ {
254+ const struct netfs_cache_ops * ops = fscache_operation_valid (cres );
255+
256+ if (ops )
257+ ops -> end_operation (cres );
258+ }
259+
260+ /*
261+ * Fallback page reading interface.
262+ */
263+ static int fscache_fallback_read_page (struct inode * inode , struct page * page )
264+ {
265+ struct netfs_cache_resources cres ;
266+ struct fscache_cookie * cookie = nfs_i_fscache (inode );
267+ struct iov_iter iter ;
268+ struct bio_vec bvec [1 ];
269+ int ret ;
270+
271+ memset (& cres , 0 , sizeof (cres ));
272+ bvec [0 ].bv_page = page ;
273+ bvec [0 ].bv_offset = 0 ;
274+ bvec [0 ].bv_len = PAGE_SIZE ;
275+ iov_iter_bvec (& iter , READ , bvec , ARRAY_SIZE (bvec ), PAGE_SIZE );
276+
277+ ret = fscache_begin_read_operation (& cres , cookie );
278+ if (ret < 0 )
279+ return ret ;
280+
281+ ret = fscache_read (& cres , page_offset (page ), & iter , NETFS_READ_HOLE_FAIL ,
282+ NULL , NULL );
283+ fscache_end_operation (& cres );
284+ return ret ;
285+ }
286+
287+ /*
288+ * Fallback page writing interface.
289+ */
290+ static int fscache_fallback_write_page (struct inode * inode , struct page * page ,
291+ bool no_space_allocated_yet )
292+ {
293+ struct netfs_cache_resources cres ;
294+ struct fscache_cookie * cookie = nfs_i_fscache (inode );
295+ struct iov_iter iter ;
296+ struct bio_vec bvec [1 ];
297+ loff_t start = page_offset (page );
298+ size_t len = PAGE_SIZE ;
299+ int ret ;
300+
301+ memset (& cres , 0 , sizeof (cres ));
302+ bvec [0 ].bv_page = page ;
303+ bvec [0 ].bv_offset = 0 ;
304+ bvec [0 ].bv_len = PAGE_SIZE ;
305+ iov_iter_bvec (& iter , WRITE , bvec , ARRAY_SIZE (bvec ), PAGE_SIZE );
306+
307+ ret = fscache_begin_write_operation (& cres , cookie );
308+ if (ret < 0 )
309+ return ret ;
310+
311+ ret = cres .ops -> prepare_write (& cres , & start , & len , i_size_read (inode ),
312+ no_space_allocated_yet );
313+ if (ret == 0 )
314+ ret = fscache_write (& cres , page_offset (page ), & iter , NULL , NULL );
315+ fscache_end_operation (& cres );
316+ return ret ;
317+ }
318+
252319/*
253320 * Retrieve a page from fscache
254321 */
255- int __nfs_readpage_from_fscache (struct nfs_open_context * ctx ,
256- struct inode * inode , struct page * page )
322+ int __nfs_readpage_from_fscache (struct inode * inode , struct page * page )
257323{
324+ int ret ;
325+
258326 dfprintk (FSCACHE ,
259327 "NFS: readpage_from_fscache(fsc:%p/p:%p(i:%lx f:%lx)/0x%p)\n" ,
260328 nfs_i_fscache (inode ), page , page -> index , page -> flags , inode );
261329
262330 if (PageChecked (page )) {
331+ dfprintk (FSCACHE , "NFS: readpage_from_fscache: PageChecked\n" );
263332 ClearPageChecked (page );
264333 return 1 ;
265334 }
266335
267- return - ENOBUFS ; // TODO: Use netfslib
268- }
269-
270- /*
271- * Retrieve a set of pages from fscache
272- */
273- int __nfs_readpages_from_fscache (struct nfs_open_context * ctx ,
274- struct inode * inode ,
275- struct address_space * mapping ,
276- struct list_head * pages ,
277- unsigned * nr_pages )
278- {
279- dfprintk (FSCACHE , "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n" ,
280- nfs_i_fscache (inode ), * nr_pages , inode );
336+ ret = fscache_fallback_read_page (inode , page );
337+ if (ret < 0 ) {
338+ nfs_inc_fscache_stats (inode , NFSIOS_FSCACHE_PAGES_READ_FAIL );
339+ dfprintk (FSCACHE ,
340+ "NFS: readpage_from_fscache failed %d\n" , ret );
341+ SetPageChecked (page );
342+ return ret ;
343+ }
281344
282- return - ENOBUFS ; // TODO: Use netfslib
345+ /* Read completed synchronously */
346+ dfprintk (FSCACHE , "NFS: readpage_from_fscache: read successful\n" );
347+ nfs_inc_fscache_stats (inode , NFSIOS_FSCACHE_PAGES_READ_OK );
348+ SetPageUptodate (page );
349+ return 0 ;
283350}
284351
285352/*
286- * Store a newly fetched page in fscache
287- * - PG_fscache must be set on the page
353+ * Store a newly fetched page in fscache. We can be certain there's no page
354+ * stored in the cache as yet otherwise we would've read it from there.
288355 */
289- void __nfs_readpage_to_fscache (struct inode * inode , struct page * page , int sync )
356+ void __nfs_readpage_to_fscache (struct inode * inode , struct page * page )
290357{
358+ int ret ;
359+
291360 dfprintk (FSCACHE ,
292- "NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d )\n" ,
293- nfs_i_fscache (inode ), page , page -> index , page -> flags , sync );
361+ "NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx))\n" ,
362+ nfs_i_fscache (inode ), page , page -> index , page -> flags );
294363
295- return ; // TODO: Use netfslib
364+ ret = fscache_fallback_write_page (inode , page , true);
365+
366+ dfprintk (FSCACHE ,
367+ "NFS: readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n" ,
368+ page , page -> index , page -> flags , ret );
369+
370+ if (ret != 0 ) {
371+ nfs_inc_fscache_stats (inode , NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL );
372+ nfs_inc_fscache_stats (inode , NFSIOS_FSCACHE_PAGES_UNCACHED );
373+ } else {
374+ nfs_inc_fscache_stats (inode , NFSIOS_FSCACHE_PAGES_WRITTEN_OK );
375+ }
296376}
0 commit comments