2019-05-19 15:08:55 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2005-04-17 02:20:36 +04:00
/*
* linux / fs / nfs / read . c
*
* Block I / O for NFS
*
* Partial copy of Linus ' read cache modifications to fs / nfs / file . c
* modified for async RPC by okir @ monad . swb . de
*/
# include <linux/time.h>
# include <linux/kernel.h>
# include <linux/errno.h>
# include <linux/fcntl.h>
# include <linux/stat.h>
# include <linux/mm.h>
# include <linux/slab.h>
# include <linux/pagemap.h>
# include <linux/sunrpc/clnt.h>
# include <linux/nfs_fs.h>
# include <linux/nfs_page.h>
2011-03-01 04:34:16 +03:00
# include <linux/module.h>
2005-04-17 02:20:36 +04:00
2009-04-01 17:22:25 +04:00
# include "nfs4_fs.h"
2006-12-05 08:35:38 +03:00
# include "internal.h"
2006-03-20 21:44:14 +03:00
# include "iostat.h"
2009-04-03 19:42:44 +04:00
# include "fscache.h"
2014-04-16 17:07:22 +04:00
# include "pnfs.h"
2017-08-21 22:00:49 +03:00
# include "nfstrace.h"
2006-03-20 21:44:14 +03:00
2005-04-17 02:20:36 +04:00
# define NFSDBG_FACILITY NFSDBG_PAGECACHE
2012-04-20 22:47:48 +04:00
static const struct nfs_pgio_completion_ops nfs_async_read_completion_ops ;
2014-05-06 17:12:30 +04:00
static const struct nfs_rw_ops nfs_rw_read_ops ;
2005-04-17 02:20:36 +04:00
2006-12-07 07:33:20 +03:00
static struct kmem_cache * nfs_rdata_cachep ;
2005-04-17 02:20:36 +04:00
2014-06-09 19:48:33 +04:00
static struct nfs_pgio_header * nfs_readhdr_alloc ( void )
2006-03-20 21:44:37 +03:00
{
2017-04-19 17:11:35 +03:00
struct nfs_pgio_header * p = kmem_cache_zalloc ( nfs_rdata_cachep , GFP_KERNEL ) ;
if ( p )
p - > rw_mode = FMODE_READ ;
return p ;
2012-04-20 22:47:46 +04:00
}
2014-06-09 19:48:33 +04:00
static void nfs_readhdr_free ( struct nfs_pgio_header * rhdr )
2006-03-20 21:44:37 +03:00
{
2012-04-20 22:47:44 +04:00
kmem_cache_free ( nfs_rdata_cachep , rhdr ) ;
2006-03-20 21:44:37 +03:00
}
2005-04-17 02:20:36 +04:00
static
int nfs_return_empty_page ( struct page * page )
{
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
zero_user ( page , 0 , PAGE_SIZE ) ;
2005-04-17 02:20:36 +04:00
SetPageUptodate ( page ) ;
unlock_page ( page ) ;
return 0 ;
}
2012-06-20 23:53:47 +04:00
void nfs_pageio_init_read ( struct nfs_pageio_descriptor * pgio ,
2014-04-16 17:07:22 +04:00
struct inode * inode , bool force_mds ,
2012-04-20 22:47:48 +04:00
const struct nfs_pgio_completion_ops * compl_ops )
2011-06-10 21:30:23 +04:00
{
2014-04-16 17:07:22 +04:00
struct nfs_server * server = NFS_SERVER ( inode ) ;
2014-05-06 17:12:40 +04:00
const struct nfs_pageio_ops * pg_ops = & nfs_pgio_rw_ops ;
2014-04-16 17:07:22 +04:00
# ifdef CONFIG_NFS_V4_1
if ( server - > pnfs_curr_ld & & ! force_mds )
pg_ops = server - > pnfs_curr_ld - > pg_read_ops ;
# endif
2014-05-06 17:12:30 +04:00
nfs_pageio_init ( pgio , inode , pg_ops , compl_ops , & nfs_rw_read_ops ,
2017-08-20 18:33:25 +03:00
server - > rsize , 0 ) ;
2011-06-10 21:30:23 +04:00
}
2012-07-31 00:05:23 +04:00
EXPORT_SYMBOL_GPL ( nfs_pageio_init_read ) ;
2011-06-10 21:30:23 +04:00
2021-01-28 17:55:03 +03:00
static void nfs_pageio_complete_read ( struct nfs_pageio_descriptor * pgio ,
struct inode * inode )
{
struct nfs_pgio_mirror * pgm ;
unsigned long npages ;
nfs_pageio_complete ( pgio ) ;
/* It doesn't make sense to do mirrored reads! */
WARN_ON_ONCE ( pgio - > pg_mirror_count ! = 1 ) ;
pgm = & pgio - > pg_mirrors [ 0 ] ;
NFS_I ( inode ) - > read_io + = pgm - > pg_bytes_written ;
npages = ( pgm - > pg_bytes_written + PAGE_SIZE - 1 ) > > PAGE_SHIFT ;
nfs_add_stats ( inode , NFSIOS_READPAGES , npages ) ;
}
2011-07-13 23:58:28 +04:00
void nfs_pageio_reset_read_mds ( struct nfs_pageio_descriptor * pgio )
{
2014-09-19 18:55:07 +04:00
struct nfs_pgio_mirror * mirror ;
2015-09-20 18:03:28 +03:00
if ( pgio - > pg_ops & & pgio - > pg_ops - > pg_cleanup )
pgio - > pg_ops - > pg_cleanup ( pgio ) ;
2014-05-06 17:12:40 +04:00
pgio - > pg_ops = & nfs_pgio_rw_ops ;
2014-09-19 18:55:07 +04:00
/* read path should never have more than one mirror */
WARN_ON_ONCE ( pgio - > pg_mirror_count ! = 1 ) ;
mirror = & pgio - > pg_mirrors [ 0 ] ;
mirror - > pg_bsize = NFS_SERVER ( pgio - > pg_inode ) - > rsize ;
2011-07-13 23:58:28 +04:00
}
2011-07-13 23:59:57 +04:00
EXPORT_SYMBOL_GPL ( nfs_pageio_reset_read_mds ) ;
2011-07-13 23:58:28 +04:00
2019-08-15 19:26:05 +03:00
static void nfs_readpage_release ( struct nfs_page * req , int error )
2015-12-05 10:57:31 +03:00
{
2019-04-07 20:59:11 +03:00
struct inode * inode = d_inode ( nfs_req_openctx ( req ) - > dentry ) ;
2019-08-15 19:26:05 +03:00
struct page * page = req - > wb_page ;
2015-12-05 10:57:31 +03:00
dprintk ( " NFS: read done (%s/%llu %d@%lld) \n " , inode - > i_sb - > s_id ,
( unsigned long long ) NFS_FILEID ( inode ) , req - > wb_bytes ,
( long long ) req_offset ( req ) ) ;
2019-08-15 19:26:05 +03:00
if ( nfs_error_is_fatal_on_server ( error ) & & error ! = - ETIMEDOUT )
SetPageError ( page ) ;
2015-12-05 10:57:31 +03:00
if ( nfs_page_group_sync_on_bit ( req , PG_UNLOCKPAGE ) ) {
2019-08-15 19:26:05 +03:00
struct address_space * mapping = page_file_mapping ( page ) ;
2015-12-05 10:57:31 +03:00
2019-08-15 19:26:05 +03:00
if ( PageUptodate ( page ) )
nfs_readpage_to_fscache ( inode , page , 0 ) ;
else if ( ! PageError ( page ) & & ! PagePrivate ( page ) )
generic_error_remove_page ( mapping , page ) ;
unlock_page ( page ) ;
2015-12-05 10:57:31 +03:00
}
nfs_release_request ( req ) ;
}
2021-01-28 17:55:01 +03:00
struct nfs_readdesc {
struct nfs_pageio_descriptor pgio ;
struct nfs_open_context * ctx ;
} ;
2014-05-15 19:56:46 +04:00
static void nfs_page_group_set_uptodate ( struct nfs_page * req )
{
if ( nfs_page_group_sync_on_bit ( req , PG_UPTODATE ) )
SetPageUptodate ( req - > wb_page ) ;
}
2012-04-20 22:47:48 +04:00
static void nfs_read_completion ( struct nfs_pgio_header * hdr )
2012-04-20 22:47:46 +04:00
{
unsigned long bytes = 0 ;
2019-08-15 19:26:05 +03:00
int error ;
2012-04-20 22:47:46 +04:00
if ( test_bit ( NFS_IOHDR_REDO , & hdr - > flags ) )
goto out ;
2012-05-01 20:49:58 +04:00
while ( ! list_empty ( & hdr - > pages ) ) {
struct nfs_page * req = nfs_list_entry ( hdr - > pages . next ) ;
struct page * page = req - > wb_page ;
2014-05-15 19:56:57 +04:00
unsigned long start = req - > wb_pgbase ;
unsigned long end = req - > wb_pgbase + req - > wb_bytes ;
2012-05-01 20:49:58 +04:00
if ( test_bit ( NFS_IOHDR_EOF , & hdr - > flags ) ) {
2014-05-15 19:56:57 +04:00
/* note: regions of the page not covered by a
2021-01-28 17:55:03 +03:00
* request are zeroed in readpage_async_filler */
2014-05-15 19:56:57 +04:00
if ( bytes > hdr - > good_bytes ) {
/* nothing in this request was good, so zero
* the full extent of the request */
zero_user_segment ( page , start , end ) ;
} else if ( hdr - > good_bytes - bytes < req - > wb_bytes ) {
/* part of this request has good bytes, but
* not all . zero the bad bytes */
start + = hdr - > good_bytes - bytes ;
WARN_ON ( start < req - > wb_pgbase ) ;
zero_user_segment ( page , start , end ) ;
}
2012-04-20 22:47:46 +04:00
}
2019-08-15 19:26:05 +03:00
error = 0 ;
2012-05-01 20:49:58 +04:00
bytes + = req - > wb_bytes ;
if ( test_bit ( NFS_IOHDR_ERROR , & hdr - > flags ) ) {
2012-04-20 22:47:46 +04:00
if ( bytes < = hdr - > good_bytes )
2014-05-15 19:56:46 +04:00
nfs_page_group_set_uptodate ( req ) ;
2019-08-15 19:26:05 +03:00
else {
error = hdr - > error ;
xchg ( & nfs_req_openctx ( req ) - > error , error ) ;
}
2012-05-01 20:49:58 +04:00
} else
2014-05-15 19:56:46 +04:00
nfs_page_group_set_uptodate ( req ) ;
2012-05-01 20:49:58 +04:00
nfs_list_remove_request ( req ) ;
2019-08-15 19:26:05 +03:00
nfs_readpage_release ( req , error ) ;
2012-04-20 22:47:46 +04:00
}
out :
hdr - > release ( hdr ) ;
}
2014-06-09 19:48:35 +04:00
static void nfs_initiate_read ( struct nfs_pgio_header * hdr ,
struct rpc_message * msg ,
2014-06-10 00:12:20 +04:00
const struct nfs_rpc_ops * rpc_ops ,
2014-05-06 17:12:37 +04:00
struct rpc_task_setup * task_setup_data , int how )
2005-04-17 02:20:36 +04:00
{
2014-06-09 19:48:35 +04:00
struct inode * inode = hdr - > inode ;
2007-07-14 23:39:59 +04:00
int swap_flags = IS_SWAPFILE ( inode ) ? NFS_RPC_SWAPFLAGS : 0 ;
2005-04-17 02:20:36 +04:00
2014-05-06 17:12:37 +04:00
task_setup_data - > flags | = swap_flags ;
2014-06-10 00:12:20 +04:00
rpc_ops - > read_setup ( hdr , msg ) ;
2020-01-06 23:25:08 +03:00
trace_nfs_initiate_read ( hdr ) ;
2011-03-01 04:34:16 +03:00
}
2012-04-20 22:47:48 +04:00
static void
2019-02-13 18:39:39 +03:00
nfs_async_read_error ( struct list_head * head , int error )
2005-04-17 02:20:36 +04:00
{
struct nfs_page * req ;
while ( ! list_empty ( head ) ) {
req = nfs_list_entry ( head - > next ) ;
nfs_list_remove_request ( req ) ;
2019-08-15 19:26:05 +03:00
nfs_readpage_release ( req , error ) ;
2005-04-17 02:20:36 +04:00
}
}
2012-04-20 22:47:48 +04:00
static const struct nfs_pgio_completion_ops nfs_async_read_completion_ops = {
. error_cleanup = nfs_async_read_error ,
. completion = nfs_read_completion ,
} ;
2006-11-15 00:12:23 +03:00
/*
* This is the callback from RPC telling us whether a reply was
* received or some error occurred ( timeout or socket shutdown ) .
*/
2014-06-09 19:48:35 +04:00
static int nfs_readpage_done ( struct rpc_task * task ,
struct nfs_pgio_header * hdr ,
2014-05-06 17:12:32 +04:00
struct inode * inode )
2006-11-15 00:12:23 +03:00
{
2014-06-09 19:48:35 +04:00
int status = NFS_PROTO ( inode ) - > read_done ( task , hdr ) ;
2006-11-15 00:12:23 +03:00
if ( status ! = 0 )
return status ;
2014-06-09 19:48:35 +04:00
nfs_add_stats ( inode , NFSIOS_SERVERREADBYTES , hdr - > res . count ) ;
2020-01-06 23:25:08 +03:00
trace_nfs_readpage_done ( task , hdr ) ;
2006-11-15 00:12:23 +03:00
if ( task - > tk_status = = - ESTALE ) {
2020-04-06 20:39:29 +03:00
nfs_set_inode_stale ( inode ) ;
2012-04-20 22:47:44 +04:00
nfs_mark_for_revalidate ( inode ) ;
2006-11-15 00:12:23 +03:00
}
return 0 ;
}
2014-06-09 19:48:35 +04:00
static void nfs_readpage_retry ( struct rpc_task * task ,
struct nfs_pgio_header * hdr )
2006-11-15 00:12:23 +03:00
{
2014-06-09 19:48:35 +04:00
struct nfs_pgio_args * argp = & hdr - > args ;
struct nfs_pgio_res * resp = & hdr - > res ;
2006-11-15 00:12:23 +03:00
/* This is a short read! */
2014-06-09 19:48:35 +04:00
nfs_inc_stats ( hdr - > inode , NFSIOS_SHORTREAD ) ;
2020-05-13 00:14:05 +03:00
trace_nfs_readpage_short ( task , hdr ) ;
2006-11-15 00:12:23 +03:00
/* Has the server at least made some progress? */
2012-04-20 22:47:46 +04:00
if ( resp - > count = = 0 ) {
2014-06-09 19:48:35 +04:00
nfs_set_pgio_error ( hdr , - EIO , argp - > offset ) ;
2009-12-06 03:32:19 +03:00
return ;
2012-04-20 22:47:46 +04:00
}
2015-10-16 12:23:29 +03:00
/* For non rpc-based layout drivers, retry-through-MDS */
if ( ! task - > tk_ops ) {
hdr - > pnfs_error = - EAGAIN ;
return ;
}
2014-06-09 19:48:35 +04:00
/* Yes, so retry the read at the end of the hdr */
hdr - > mds_offset + = resp - > count ;
2006-11-15 00:12:23 +03:00
argp - > offset + = resp - > count ;
argp - > pgbase + = resp - > count ;
argp - > count - = resp - > count ;
2020-01-06 23:25:13 +03:00
resp - > count = 0 ;
resp - > eof = 0 ;
2011-10-19 23:17:29 +04:00
rpc_restart_call_prepare ( task ) ;
2006-11-15 00:12:23 +03:00
}
2014-06-09 19:48:35 +04:00
static void nfs_readpage_result ( struct rpc_task * task ,
struct nfs_pgio_header * hdr )
2005-04-17 02:20:36 +04:00
{
2014-06-09 19:48:35 +04:00
if ( hdr - > res . eof ) {
2018-09-25 19:34:43 +03:00
loff_t pos = hdr - > args . offset + hdr - > res . count ;
unsigned int new = pos - hdr - > io_start ;
2012-04-20 22:47:46 +04:00
2018-09-25 19:34:43 +03:00
if ( hdr - > good_bytes > new ) {
hdr - > good_bytes = new ;
2012-04-20 22:47:46 +04:00
set_bit ( NFS_IOHDR_EOF , & hdr - > flags ) ;
clear_bit ( NFS_IOHDR_ERROR , & hdr - > flags ) ;
}
2015-10-16 12:23:29 +03:00
} else if ( hdr - > res . count < hdr - > args . count )
2014-06-09 19:48:35 +04:00
nfs_readpage_retry ( task , hdr ) ;
2008-04-16 00:33:58 +04:00
}
2021-01-28 17:55:03 +03:00
static int
readpage_async_filler ( void * data , struct page * page )
{
struct nfs_readdesc * desc = data ;
struct nfs_page * new ;
unsigned int len ;
int error ;
len = nfs_page_length ( page ) ;
if ( len = = 0 )
return nfs_return_empty_page ( page ) ;
new = nfs_create_request ( desc - > ctx , page , 0 , len ) ;
if ( IS_ERR ( new ) )
goto out_error ;
if ( len < PAGE_SIZE )
zero_user_segment ( page , len , PAGE_SIZE ) ;
if ( ! nfs_pageio_add_request ( & desc - > pgio , new ) ) {
nfs_list_remove_request ( new ) ;
error = desc - > pgio . pg_error ;
nfs_readpage_release ( new , error ) ;
goto out ;
}
return 0 ;
out_error :
error = PTR_ERR ( new ) ;
unlock_page ( page ) ;
out :
return error ;
}
2005-04-17 02:20:36 +04:00
/*
* Read a page over NFS .
* We read the page synchronously in the following case :
* - The error flag is set for this page . This happens only when a
* previous async read operation failed .
*/
int nfs_readpage ( struct file * file , struct page * page )
{
2021-01-28 17:55:01 +03:00
struct nfs_readdesc desc ;
2012-08-01 03:45:06 +04:00
struct inode * inode = page_file_mapping ( page ) - > host ;
2021-01-28 17:54:59 +03:00
int ret ;
2005-04-17 02:20:36 +04:00
dprintk ( " NFS: nfs_readpage (%p %ld@%lu) \n " ,
2016-10-08 03:00:24 +03:00
page , PAGE_SIZE , page_index ( page ) ) ;
2006-03-20 21:44:14 +03:00
nfs_inc_stats ( inode , NFSIOS_VFSREADPAGE ) ;
2005-04-17 02:20:36 +04:00
/*
* Try to flush any pending writes to the file . .
*
* NOTE ! Because we own the page lock , there cannot
* be any new pending writes generated at this point
* for this page ( other pages can be written to ) .
*/
2021-01-28 17:54:59 +03:00
ret = nfs_wb_page ( inode , page ) ;
if ( ret )
2007-05-20 21:05:05 +04:00
goto out_unlock ;
if ( PageUptodate ( page ) )
goto out_unlock ;
2005-04-17 02:20:36 +04:00
2021-01-28 17:54:59 +03:00
ret = - ESTALE ;
2006-09-14 22:03:14 +04:00
if ( NFS_STALE ( inode ) )
2007-05-20 21:05:05 +04:00
goto out_unlock ;
2006-09-14 22:03:14 +04:00
2005-04-17 02:20:36 +04:00
if ( file = = NULL ) {
2021-01-28 17:54:59 +03:00
ret = - EBADF ;
2021-01-28 17:55:01 +03:00
desc . ctx = nfs_find_open_context ( inode , NULL , FMODE_READ ) ;
if ( desc . ctx = = NULL )
2007-05-20 21:05:05 +04:00
goto out_unlock ;
2005-04-17 02:20:36 +04:00
} else
2021-01-28 17:55:01 +03:00
desc . ctx = get_nfs_open_context ( nfs_file_open_context ( file ) ) ;
2005-04-17 02:20:36 +04:00
2009-04-03 19:42:44 +04:00
if ( ! IS_SYNC ( inode ) ) {
2021-01-28 17:55:01 +03:00
ret = nfs_readpage_from_fscache ( desc . ctx , inode , page ) ;
2021-01-28 17:54:59 +03:00
if ( ret = = 0 )
2009-04-03 19:42:44 +04:00
goto out ;
}
2021-01-28 17:55:01 +03:00
xchg ( & desc . ctx - > error , 0 ) ;
2021-01-28 17:55:03 +03:00
nfs_pageio_init_read ( & desc . pgio , inode , false ,
& nfs_async_read_completion_ops ) ;
ret = readpage_async_filler ( & desc , page ) ;
if ( ! ret )
nfs_pageio_complete_read ( & desc . pgio , inode ) ;
ret = desc . pgio . pg_error < 0 ? desc . pgio . pg_error : 0 ;
2021-01-28 17:54:59 +03:00
if ( ! ret ) {
ret = wait_on_page_locked_killable ( page ) ;
if ( ! PageUptodate ( page ) & & ! ret )
2021-01-28 17:55:01 +03:00
ret = xchg ( & desc . ctx - > error , 0 ) ;
2019-08-15 19:26:05 +03:00
}
2009-04-03 19:42:44 +04:00
out :
2021-01-28 17:55:01 +03:00
put_nfs_open_context ( desc . ctx ) ;
2021-01-28 17:54:59 +03:00
return ret ;
2007-05-20 21:05:05 +04:00
out_unlock :
2005-04-17 02:20:36 +04:00
unlock_page ( page ) ;
2021-01-28 17:54:59 +03:00
return ret ;
2005-04-17 02:20:36 +04:00
}
2021-01-28 17:54:59 +03:00
int nfs_readpages ( struct file * file , struct address_space * mapping ,
2005-04-17 02:20:36 +04:00
struct list_head * pages , unsigned nr_pages )
{
2021-01-28 17:54:59 +03:00
struct nfs_readdesc desc ;
2005-04-17 02:20:36 +04:00
struct inode * inode = mapping - > host ;
2021-01-28 17:54:59 +03:00
int ret ;
2005-04-17 02:20:36 +04:00
2013-12-17 21:20:16 +04:00
dprintk ( " NFS: nfs_readpages (%s/%Lu %d) \n " ,
2005-04-17 02:20:36 +04:00
inode - > i_sb - > s_id ,
2013-12-17 21:20:16 +04:00
( unsigned long long ) NFS_FILEID ( inode ) ,
2005-04-17 02:20:36 +04:00
nr_pages ) ;
2006-03-20 21:44:14 +03:00
nfs_inc_stats ( inode , NFSIOS_VFSREADPAGES ) ;
2005-04-17 02:20:36 +04:00
2021-01-28 17:54:59 +03:00
ret = - ESTALE ;
2006-09-14 22:03:14 +04:00
if ( NFS_STALE ( inode ) )
goto out ;
2021-01-28 17:54:59 +03:00
if ( file = = NULL ) {
ret = - EBADF ;
2005-11-04 23:33:38 +03:00
desc . ctx = nfs_find_open_context ( inode , NULL , FMODE_READ ) ;
2005-04-17 02:20:36 +04:00
if ( desc . ctx = = NULL )
2021-01-28 17:54:59 +03:00
goto out ;
2005-04-17 02:20:36 +04:00
} else
2021-01-28 17:54:59 +03:00
desc . ctx = get_nfs_open_context ( nfs_file_open_context ( file ) ) ;
2009-04-03 19:42:44 +04:00
/* attempt to read as many of the pages as possible from the cache
* - this returns - ENOBUFS immediately if the cookie is negative
*/
ret = nfs_readpages_from_fscache ( desc . ctx , inode , mapping ,
pages , & nr_pages ) ;
if ( ret = = 0 )
goto read_complete ; /* all pages were read */
2021-01-28 17:55:01 +03:00
nfs_pageio_init_read ( & desc . pgio , inode , false ,
2014-04-16 17:07:22 +04:00
& nfs_async_read_completion_ops ) ;
2007-04-03 02:48:28 +04:00
2005-04-17 02:20:36 +04:00
ret = read_cache_pages ( mapping , pages , readpage_async_filler , & desc ) ;
2014-09-19 18:55:07 +04:00
2021-01-28 17:55:03 +03:00
nfs_pageio_complete_read ( & desc . pgio , inode ) ;
2014-09-19 18:55:07 +04:00
2009-04-03 19:42:44 +04:00
read_complete :
2005-04-17 02:20:36 +04:00
put_nfs_open_context ( desc . ctx ) ;
2006-09-14 22:03:14 +04:00
out :
2005-04-17 02:20:36 +04:00
return ret ;
}
NFS: Split fs/nfs/inode.c
As fs/nfs/inode.c is rather large, heterogenous and unwieldy, the attached
patch splits it up into a number of files:
(*) fs/nfs/inode.c
Strictly inode specific functions.
(*) fs/nfs/super.c
Superblock management functions for NFS and NFS4, normal access, clones
and referrals. The NFS4 superblock functions _could_ move out into a
separate conditionally compiled file, but it's probably not worth it as
there're so many common bits.
(*) fs/nfs/namespace.c
Some namespace-specific functions have been moved here.
(*) fs/nfs/nfs4namespace.c
NFS4-specific namespace functions (this could be merged into the previous
file). This file is conditionally compiled.
(*) fs/nfs/internal.h
Inter-file declarations, plus a few simple utility functions moved from
fs/nfs/inode.c.
Additionally, all the in-.c-file externs have been moved here, and those
files they were moved from now includes this file.
For the most part, the functions have not been changed, only some multiplexor
functions have changed significantly.
I've also:
(*) Added some extra banner comments above some functions.
(*) Rearranged the function order within the files to be more logical and
better grouped (IMO), though someone may prefer a different order.
(*) Reduced the number of #ifdefs in .c files.
(*) Added missing __init and __exit directives.
Signed-Off-By: David Howells <dhowells@redhat.com>
2006-06-09 17:34:33 +04:00
int __init nfs_init_readpagecache ( void )
2005-04-17 02:20:36 +04:00
{
nfs_rdata_cachep = kmem_cache_create ( " nfs_read_data " ,
2014-06-09 19:48:33 +04:00
sizeof ( struct nfs_pgio_header ) ,
2005-04-17 02:20:36 +04:00
0 , SLAB_HWCACHE_ALIGN ,
2007-07-20 05:11:58 +04:00
NULL ) ;
2005-04-17 02:20:36 +04:00
if ( nfs_rdata_cachep = = NULL )
return - ENOMEM ;
return 0 ;
}
2006-06-27 23:59:15 +04:00
void nfs_destroy_readpagecache ( void )
2005-04-17 02:20:36 +04:00
{
2006-09-27 12:49:40 +04:00
kmem_cache_destroy ( nfs_rdata_cachep ) ;
2005-04-17 02:20:36 +04:00
}
2014-05-06 17:12:30 +04:00
static const struct nfs_rw_ops nfs_rw_read_ops = {
. rw_alloc_header = nfs_readhdr_alloc ,
. rw_free_header = nfs_readhdr_free ,
2014-05-06 17:12:32 +04:00
. rw_done = nfs_readpage_done ,
. rw_result = nfs_readpage_result ,
2014-05-06 17:12:37 +04:00
. rw_initiate = nfs_initiate_read ,
2014-05-06 17:12:30 +04:00
} ;