2019-05-19 20:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 06:20:36 +08: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>
|
2023-03-10 02:58:52 +08:00
|
|
|
#include <linux/task_io_accounting_ops.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/sunrpc/clnt.h>
|
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include <linux/nfs_page.h>
|
2011-03-01 09:34:16 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-01 21:22:25 +08:00
|
|
|
#include "nfs4_fs.h"
|
2006-12-05 13:35:38 +08:00
|
|
|
#include "internal.h"
|
2006-03-21 02:44:14 +08:00
|
|
|
#include "iostat.h"
|
2009-04-03 23:42:44 +08:00
|
|
|
#include "fscache.h"
|
2014-04-16 21:07:22 +08:00
|
|
|
#include "pnfs.h"
|
2017-08-22 03:00:49 +08:00
|
|
|
#include "nfstrace.h"
|
2024-06-17 09:21:25 +08:00
|
|
|
#include "delegation.h"
|
2006-03-21 02:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define NFSDBG_FACILITY NFSDBG_PAGECACHE
|
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
const struct nfs_pgio_completion_ops nfs_async_read_completion_ops;
|
2014-05-06 21:12:30 +08:00
|
|
|
static const struct nfs_rw_ops nfs_rw_read_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-07 12:33:20 +08:00
|
|
|
static struct kmem_cache *nfs_rdata_cachep;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-09 23:48:33 +08:00
|
|
|
static struct nfs_pgio_header *nfs_readhdr_alloc(void)
|
2006-03-21 02:44:37 +08:00
|
|
|
{
|
2017-04-19 22:11:35 +08: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-21 02:47:46 +08:00
|
|
|
}
|
|
|
|
|
2014-06-09 23:48:33 +08:00
|
|
|
static void nfs_readhdr_free(struct nfs_pgio_header *rhdr)
|
2006-03-21 02:44:37 +08:00
|
|
|
{
|
2023-06-10 03:26:25 +08:00
|
|
|
if (rhdr->res.scratch != NULL)
|
|
|
|
kfree(rhdr->res.scratch);
|
2012-04-21 02:47:44 +08:00
|
|
|
kmem_cache_free(nfs_rdata_cachep, rhdr);
|
2006-03-21 02:44:37 +08:00
|
|
|
}
|
|
|
|
|
2023-01-20 05:33:41 +08:00
|
|
|
static int nfs_return_empty_folio(struct folio *folio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-01-20 05:33:41 +08:00
|
|
|
folio_zero_segment(folio, 0, folio_size(folio));
|
|
|
|
folio_mark_uptodate(folio);
|
|
|
|
folio_unlock(folio);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-21 03:53:47 +08:00
|
|
|
void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
|
2014-04-16 21:07:22 +08:00
|
|
|
struct inode *inode, bool force_mds,
|
2012-04-21 02:47:48 +08:00
|
|
|
const struct nfs_pgio_completion_ops *compl_ops)
|
2011-06-11 01:30:23 +08:00
|
|
|
{
|
2014-04-16 21:07:22 +08:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
2014-05-06 21:12:40 +08:00
|
|
|
const struct nfs_pageio_ops *pg_ops = &nfs_pgio_rw_ops;
|
2014-04-16 21:07:22 +08: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 21:12:30 +08:00
|
|
|
nfs_pageio_init(pgio, inode, pg_ops, compl_ops, &nfs_rw_read_ops,
|
2017-08-20 23:33:25 +08:00
|
|
|
server->rsize, 0);
|
2011-06-11 01:30:23 +08:00
|
|
|
}
|
2012-07-31 04:05:23 +08:00
|
|
|
EXPORT_SYMBOL_GPL(nfs_pageio_init_read);
|
2011-06-11 01:30:23 +08:00
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio)
|
2021-01-28 22:55:03 +08:00
|
|
|
{
|
|
|
|
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];
|
2021-06-24 23:34:18 +08:00
|
|
|
NFS_I(pgio->pg_inode)->read_io += pgm->pg_bytes_written;
|
2021-01-28 22:55:03 +08:00
|
|
|
npages = (pgm->pg_bytes_written + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
2021-06-24 23:34:18 +08:00
|
|
|
nfs_add_stats(pgio->pg_inode, NFSIOS_READPAGES, npages);
|
2021-01-28 22:55:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 03:58:28 +08:00
|
|
|
void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio)
|
|
|
|
{
|
2014-09-19 22:55:07 +08:00
|
|
|
struct nfs_pgio_mirror *mirror;
|
|
|
|
|
2015-09-20 23:03:28 +08:00
|
|
|
if (pgio->pg_ops && pgio->pg_ops->pg_cleanup)
|
|
|
|
pgio->pg_ops->pg_cleanup(pgio);
|
|
|
|
|
2014-05-06 21:12:40 +08:00
|
|
|
pgio->pg_ops = &nfs_pgio_rw_ops;
|
2014-09-19 22:55:07 +08: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-14 03:58:28 +08:00
|
|
|
}
|
2011-07-14 03:59:57 +08:00
|
|
|
EXPORT_SYMBOL_GPL(nfs_pageio_reset_read_mds);
|
2011-07-14 03:58:28 +08:00
|
|
|
|
2023-06-10 03:26:25 +08:00
|
|
|
bool nfs_read_alloc_scratch(struct nfs_pgio_header *hdr, size_t size)
|
|
|
|
{
|
|
|
|
WARN_ON(hdr->res.scratch != NULL);
|
|
|
|
hdr->res.scratch = kmalloc(size, GFP_KERNEL);
|
|
|
|
return hdr->res.scratch != NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs_read_alloc_scratch);
|
|
|
|
|
2019-08-16 00:26:05 +08:00
|
|
|
static void nfs_readpage_release(struct nfs_page *req, int error)
|
2015-12-05 15:57:31 +08:00
|
|
|
{
|
2023-01-20 05:33:41 +08:00
|
|
|
struct folio *folio = nfs_page_to_folio(req);
|
2015-12-05 15:57:31 +08:00
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
if (nfs_page_group_sync_on_bit(req, PG_UNLOCKPAGE))
|
|
|
|
if (nfs_netfs_folio_unlock(folio))
|
|
|
|
folio_unlock(folio);
|
|
|
|
|
2015-12-05 15:57:31 +08:00
|
|
|
nfs_release_request(req);
|
|
|
|
}
|
|
|
|
|
2014-05-15 23:56:46 +08:00
|
|
|
static void nfs_page_group_set_uptodate(struct nfs_page *req)
|
|
|
|
{
|
|
|
|
if (nfs_page_group_sync_on_bit(req, PG_UPTODATE))
|
2023-01-20 05:33:41 +08:00
|
|
|
folio_mark_uptodate(nfs_page_to_folio(req));
|
2014-05-15 23:56:46 +08:00
|
|
|
}
|
|
|
|
|
2012-04-21 02:47:48 +08:00
|
|
|
static void nfs_read_completion(struct nfs_pgio_header *hdr)
|
2012-04-21 02:47:46 +08:00
|
|
|
{
|
|
|
|
unsigned long bytes = 0;
|
2019-08-16 00:26:05 +08:00
|
|
|
int error;
|
2012-04-21 02:47:46 +08:00
|
|
|
|
|
|
|
if (test_bit(NFS_IOHDR_REDO, &hdr->flags))
|
|
|
|
goto out;
|
2012-05-02 00:49:58 +08:00
|
|
|
while (!list_empty(&hdr->pages)) {
|
|
|
|
struct nfs_page *req = nfs_list_entry(hdr->pages.next);
|
2023-01-20 05:33:41 +08:00
|
|
|
struct folio *folio = nfs_page_to_folio(req);
|
2014-05-15 23:56:57 +08:00
|
|
|
unsigned long start = req->wb_pgbase;
|
|
|
|
unsigned long end = req->wb_pgbase + req->wb_bytes;
|
2012-05-02 00:49:58 +08:00
|
|
|
|
|
|
|
if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) {
|
2014-05-15 23:56:57 +08:00
|
|
|
/* note: regions of the page not covered by a
|
2023-02-20 21:43:04 +08:00
|
|
|
* request are zeroed in nfs_read_add_folio
|
|
|
|
*/
|
2014-05-15 23:56:57 +08:00
|
|
|
if (bytes > hdr->good_bytes) {
|
|
|
|
/* nothing in this request was good, so zero
|
|
|
|
* the full extent of the request */
|
2023-01-20 05:33:41 +08:00
|
|
|
folio_zero_segment(folio, start, end);
|
2014-05-15 23:56:57 +08:00
|
|
|
|
|
|
|
} 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);
|
2023-01-20 05:33:41 +08:00
|
|
|
folio_zero_segment(folio, start, end);
|
2014-05-15 23:56:57 +08:00
|
|
|
}
|
2012-04-21 02:47:46 +08:00
|
|
|
}
|
2019-08-16 00:26:05 +08:00
|
|
|
error = 0;
|
2012-05-02 00:49:58 +08:00
|
|
|
bytes += req->wb_bytes;
|
|
|
|
if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) {
|
2012-04-21 02:47:46 +08:00
|
|
|
if (bytes <= hdr->good_bytes)
|
2014-05-15 23:56:46 +08:00
|
|
|
nfs_page_group_set_uptodate(req);
|
2019-08-16 00:26:05 +08:00
|
|
|
else {
|
|
|
|
error = hdr->error;
|
|
|
|
xchg(&nfs_req_openctx(req)->error, error);
|
|
|
|
}
|
2012-05-02 00:49:58 +08:00
|
|
|
} else
|
2014-05-15 23:56:46 +08:00
|
|
|
nfs_page_group_set_uptodate(req);
|
2012-05-02 00:49:58 +08:00
|
|
|
nfs_list_remove_request(req);
|
2019-08-16 00:26:05 +08:00
|
|
|
nfs_readpage_release(req, error);
|
2012-04-21 02:47:46 +08:00
|
|
|
}
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
nfs_netfs_read_completion(hdr);
|
|
|
|
|
2012-04-21 02:47:46 +08:00
|
|
|
out:
|
|
|
|
hdr->release(hdr);
|
|
|
|
}
|
|
|
|
|
2014-06-09 23:48:35 +08:00
|
|
|
static void nfs_initiate_read(struct nfs_pgio_header *hdr,
|
|
|
|
struct rpc_message *msg,
|
2014-06-10 04:12:20 +08:00
|
|
|
const struct nfs_rpc_ops *rpc_ops,
|
2014-05-06 21:12:37 +08:00
|
|
|
struct rpc_task_setup *task_setup_data, int how)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-06-10 04:12:20 +08:00
|
|
|
rpc_ops->read_setup(hdr, msg);
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
nfs_netfs_initiate_read(hdr);
|
2020-01-07 04:25:08 +08:00
|
|
|
trace_nfs_initiate_read(hdr);
|
2011-03-01 09:34:16 +08:00
|
|
|
}
|
|
|
|
|
2012-04-21 02:47:48 +08:00
|
|
|
static void
|
2019-02-13 23:39:39 +08:00
|
|
|
nfs_async_read_error(struct list_head *head, int error)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct nfs_page *req;
|
|
|
|
|
|
|
|
while (!list_empty(head)) {
|
|
|
|
req = nfs_list_entry(head->next);
|
|
|
|
nfs_list_remove_request(req);
|
2019-08-16 00:26:05 +08:00
|
|
|
nfs_readpage_release(req, error);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
const struct nfs_pgio_completion_ops nfs_async_read_completion_ops = {
|
2012-04-21 02:47:48 +08:00
|
|
|
.error_cleanup = nfs_async_read_error,
|
|
|
|
.completion = nfs_read_completion,
|
|
|
|
};
|
|
|
|
|
2006-11-15 05:12:23 +08: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 23:48:35 +08:00
|
|
|
static int nfs_readpage_done(struct rpc_task *task,
|
|
|
|
struct nfs_pgio_header *hdr,
|
2014-05-06 21:12:32 +08:00
|
|
|
struct inode *inode)
|
2006-11-15 05:12:23 +08:00
|
|
|
{
|
2014-06-09 23:48:35 +08:00
|
|
|
int status = NFS_PROTO(inode)->read_done(task, hdr);
|
2006-11-15 05:12:23 +08:00
|
|
|
if (status != 0)
|
|
|
|
return status;
|
|
|
|
|
2014-06-09 23:48:35 +08:00
|
|
|
nfs_add_stats(inode, NFSIOS_SERVERREADBYTES, hdr->res.count);
|
2020-01-07 04:25:08 +08:00
|
|
|
trace_nfs_readpage_done(task, hdr);
|
2006-11-15 05:12:23 +08:00
|
|
|
|
|
|
|
if (task->tk_status == -ESTALE) {
|
2020-04-07 01:39:29 +08:00
|
|
|
nfs_set_inode_stale(inode);
|
2012-04-21 02:47:44 +08:00
|
|
|
nfs_mark_for_revalidate(inode);
|
2006-11-15 05:12:23 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-09 23:48:35 +08:00
|
|
|
static void nfs_readpage_retry(struct rpc_task *task,
|
|
|
|
struct nfs_pgio_header *hdr)
|
2006-11-15 05:12:23 +08:00
|
|
|
{
|
2014-06-09 23:48:35 +08:00
|
|
|
struct nfs_pgio_args *argp = &hdr->args;
|
|
|
|
struct nfs_pgio_res *resp = &hdr->res;
|
2006-11-15 05:12:23 +08:00
|
|
|
|
|
|
|
/* This is a short read! */
|
2014-06-09 23:48:35 +08:00
|
|
|
nfs_inc_stats(hdr->inode, NFSIOS_SHORTREAD);
|
2020-05-13 05:14:05 +08:00
|
|
|
trace_nfs_readpage_short(task, hdr);
|
|
|
|
|
2006-11-15 05:12:23 +08:00
|
|
|
/* Has the server at least made some progress? */
|
2012-04-21 02:47:46 +08:00
|
|
|
if (resp->count == 0) {
|
2014-06-09 23:48:35 +08:00
|
|
|
nfs_set_pgio_error(hdr, -EIO, argp->offset);
|
2009-12-06 08:32:19 +08:00
|
|
|
return;
|
2012-04-21 02:47:46 +08:00
|
|
|
}
|
2015-10-16 17:23:29 +08:00
|
|
|
|
|
|
|
/* For non rpc-based layout drivers, retry-through-MDS */
|
|
|
|
if (!task->tk_ops) {
|
|
|
|
hdr->pnfs_error = -EAGAIN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-09 23:48:35 +08:00
|
|
|
/* Yes, so retry the read at the end of the hdr */
|
|
|
|
hdr->mds_offset += resp->count;
|
2006-11-15 05:12:23 +08:00
|
|
|
argp->offset += resp->count;
|
|
|
|
argp->pgbase += resp->count;
|
|
|
|
argp->count -= resp->count;
|
2020-01-07 04:25:13 +08:00
|
|
|
resp->count = 0;
|
|
|
|
resp->eof = 0;
|
2011-10-20 03:17:29 +08:00
|
|
|
rpc_restart_call_prepare(task);
|
2006-11-15 05:12:23 +08:00
|
|
|
}
|
|
|
|
|
2014-06-09 23:48:35 +08:00
|
|
|
static void nfs_readpage_result(struct rpc_task *task,
|
|
|
|
struct nfs_pgio_header *hdr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-06-09 23:48:35 +08:00
|
|
|
if (hdr->res.eof) {
|
2018-09-26 00:34:43 +08:00
|
|
|
loff_t pos = hdr->args.offset + hdr->res.count;
|
|
|
|
unsigned int new = pos - hdr->io_start;
|
2012-04-21 02:47:46 +08:00
|
|
|
|
2018-09-26 00:34:43 +08:00
|
|
|
if (hdr->good_bytes > new) {
|
|
|
|
hdr->good_bytes = new;
|
2012-04-21 02:47:46 +08:00
|
|
|
set_bit(NFS_IOHDR_EOF, &hdr->flags);
|
|
|
|
clear_bit(NFS_IOHDR_ERROR, &hdr->flags);
|
|
|
|
}
|
2015-10-16 17:23:29 +08:00
|
|
|
} else if (hdr->res.count < hdr->args.count)
|
2014-06-09 23:48:35 +08:00
|
|
|
nfs_readpage_retry(task, hdr);
|
2008-04-16 04:33:58 +08:00
|
|
|
}
|
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
|
|
|
|
struct nfs_open_context *ctx,
|
|
|
|
struct folio *folio)
|
2021-01-28 22:55:03 +08:00
|
|
|
{
|
2024-07-01 13:26:48 +08:00
|
|
|
struct inode *inode = folio->mapping->host;
|
2023-01-20 05:33:41 +08:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
size_t fsize = folio_size(folio);
|
|
|
|
unsigned int rsize = server->rsize;
|
2021-01-28 22:55:03 +08:00
|
|
|
struct nfs_page *new;
|
2021-08-28 02:00:56 +08:00
|
|
|
unsigned int len, aligned_len;
|
2021-01-28 22:55:03 +08:00
|
|
|
int error;
|
|
|
|
|
2023-01-20 05:33:41 +08:00
|
|
|
len = nfs_folio_length(folio);
|
2021-01-28 22:55:03 +08:00
|
|
|
if (len == 0)
|
2023-01-20 05:33:41 +08:00
|
|
|
return nfs_return_empty_folio(folio);
|
2021-01-28 22:55:03 +08:00
|
|
|
|
2023-01-20 05:33:41 +08:00
|
|
|
aligned_len = min_t(unsigned int, ALIGN(len, rsize), fsize);
|
2021-08-28 02:00:56 +08:00
|
|
|
|
2023-02-20 21:43:04 +08:00
|
|
|
new = nfs_page_create_from_folio(ctx, folio, 0, aligned_len);
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
if (IS_ERR(new)) {
|
|
|
|
error = PTR_ERR(new);
|
2024-03-07 22:41:18 +08:00
|
|
|
if (nfs_netfs_folio_unlock(folio))
|
|
|
|
folio_unlock(folio);
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2021-01-28 22:55:03 +08:00
|
|
|
|
2023-01-20 05:33:41 +08:00
|
|
|
if (len < fsize)
|
|
|
|
folio_zero_segment(folio, len, fsize);
|
2023-02-20 21:43:04 +08:00
|
|
|
if (!nfs_pageio_add_request(pgio, new)) {
|
2021-01-28 22:55:03 +08:00
|
|
|
nfs_list_remove_request(new);
|
2023-02-20 21:43:04 +08:00
|
|
|
error = pgio->pg_error;
|
2021-01-28 22:55:03 +08:00
|
|
|
nfs_readpage_release(new, error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2024-07-11 15:17:03 +08:00
|
|
|
* Actually read a folio over the wire.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2024-07-11 15:17:03 +08:00
|
|
|
static int nfs_do_read_folio(struct file *file, struct folio *folio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-01-20 05:33:41 +08:00
|
|
|
struct inode *inode = file_inode(file);
|
2023-02-20 21:43:04 +08:00
|
|
|
struct nfs_pageio_descriptor pgio;
|
|
|
|
struct nfs_open_context *ctx;
|
2021-01-28 22:54:59 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2024-07-11 15:17:03 +08:00
|
|
|
ctx = get_nfs_open_context(nfs_file_open_context(file));
|
|
|
|
|
|
|
|
xchg(&ctx->error, 0);
|
|
|
|
nfs_pageio_init_read(&pgio, inode, false,
|
|
|
|
&nfs_async_read_completion_ops);
|
|
|
|
|
|
|
|
ret = nfs_read_add_folio(&pgio, ctx, folio);
|
|
|
|
if (ret)
|
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
nfs_pageio_complete_read(&pgio);
|
|
|
|
nfs_update_delegated_atime(inode);
|
|
|
|
if (pgio.pg_error < 0) {
|
|
|
|
ret = pgio.pg_error;
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = folio_wait_locked_killable(folio);
|
|
|
|
if (!folio_test_uptodate(folio) && !ret)
|
|
|
|
ret = xchg(&ctx->error, 0);
|
|
|
|
|
|
|
|
out_put:
|
|
|
|
put_nfs_open_context(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronously read a folio.
|
|
|
|
*
|
|
|
|
* This is not heavily used as most users to try an asynchronous
|
|
|
|
* large read through ->readahead first.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2022-04-29 23:12:16 +08:00
|
|
|
int nfs_read_folio(struct file *file, struct folio *folio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-01-20 05:33:41 +08:00
|
|
|
struct inode *inode = file_inode(file);
|
2024-07-11 15:17:02 +08:00
|
|
|
loff_t pos = folio_pos(folio);
|
|
|
|
size_t len = folio_size(folio);
|
2021-01-28 22:54:59 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2024-07-11 15:17:02 +08:00
|
|
|
trace_nfs_aop_readpage(inode, pos, len);
|
2006-03-21 02:44:14 +08:00
|
|
|
nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
|
2024-07-11 15:17:02 +08:00
|
|
|
task_io_account_read(len);
|
2006-03-21 02:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Try to flush any pending writes to the file..
|
|
|
|
*
|
2023-01-20 05:33:41 +08:00
|
|
|
* NOTE! Because we own the folio lock, there cannot
|
2005-04-17 06:20:36 +08:00
|
|
|
* be any new pending writes generated at this point
|
2023-01-20 05:33:41 +08:00
|
|
|
* for this folio (other folios can be written to).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2023-01-20 05:33:41 +08:00
|
|
|
ret = nfs_wb_folio(inode, folio);
|
2021-01-28 22:54:59 +08:00
|
|
|
if (ret)
|
2007-05-21 01:05:05 +08:00
|
|
|
goto out_unlock;
|
2023-01-20 05:33:41 +08:00
|
|
|
if (folio_test_uptodate(folio))
|
2007-05-21 01:05:05 +08:00
|
|
|
goto out_unlock;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-01-28 22:54:59 +08:00
|
|
|
ret = -ESTALE;
|
2006-09-15 02:03:14 +08:00
|
|
|
if (NFS_STALE(inode))
|
2007-05-21 01:05:05 +08:00
|
|
|
goto out_unlock;
|
2006-09-15 02:03:14 +08:00
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
ret = nfs_netfs_read_folio(file, folio);
|
2021-06-29 17:11:28 +08:00
|
|
|
if (ret)
|
2024-07-11 15:17:03 +08:00
|
|
|
ret = nfs_do_read_folio(file, folio);
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
out:
|
2024-07-11 15:17:02 +08:00
|
|
|
trace_nfs_aop_readpage_done(inode, pos, len, ret);
|
2021-01-28 22:54:59 +08:00
|
|
|
return ret;
|
2007-05-21 01:05:05 +08:00
|
|
|
out_unlock:
|
2023-01-20 05:33:41 +08:00
|
|
|
folio_unlock(folio);
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2022-01-23 04:54:52 +08:00
|
|
|
void nfs_readahead(struct readahead_control *ractl)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-02-20 21:43:04 +08:00
|
|
|
struct nfs_pageio_descriptor pgio;
|
|
|
|
struct nfs_open_context *ctx;
|
2022-01-23 04:54:52 +08:00
|
|
|
unsigned int nr_pages = readahead_count(ractl);
|
|
|
|
struct file *file = ractl->file;
|
|
|
|
struct inode *inode = ractl->mapping->host;
|
2023-01-20 05:33:41 +08:00
|
|
|
struct folio *folio;
|
2021-01-28 22:54:59 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2022-01-23 04:54:52 +08:00
|
|
|
trace_nfs_aop_readahead(inode, readahead_pos(ractl), nr_pages);
|
2006-03-21 02:44:14 +08:00
|
|
|
nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
|
2023-03-10 02:58:52 +08:00
|
|
|
task_io_account_read(readahead_length(ractl));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-01-28 22:54:59 +08:00
|
|
|
ret = -ESTALE;
|
2006-09-15 02:03:14 +08:00
|
|
|
if (NFS_STALE(inode))
|
|
|
|
goto out;
|
|
|
|
|
NFS: Convert buffered read paths to use netfs when fscache is enabled
Convert the NFS buffered read code paths to corresponding netfs APIs,
but only when fscache is configured and enabled.
The netfs API defines struct netfs_request_ops which must be filled
in by the network filesystem. For NFS, we only need to define 5 of
the functions, the main one being the issue_read() function.
The issue_read() function is called by the netfs layer when a read
cannot be fulfilled locally, and must be sent to the server (either
the cache is not active, or it is active but the data is not available).
Once the read from the server is complete, netfs requires a call to
netfs_subreq_terminated() which conveys either how many bytes were read
successfully, or an error. Note that issue_read() is called with a
structure, netfs_io_subrequest, which defines the IO requested, and
contains a start and a length (both in bytes), and assumes the underlying
netfs will return a either an error on the whole region, or the number
of bytes successfully read.
The NFS IO path is page based and the main APIs are the pgio APIs defined
in pagelist.c. For the pgio APIs, there is no way for the caller to
know how many RPCs will be sent and how the pages will be broken up
into underlying RPCs, each of which will have their own completion and
return code. In contrast, netfs is subrequest based, a single
subrequest may contain multiple pages, and a single subrequest is
initiated with issue_read() and terminated with netfs_subreq_terminated().
Thus, to utilze the netfs APIs, NFS needs some way to accommodate
the netfs API requirement on the single response to the whole
subrequest, while also minimizing disruptive changes to the NFS
pgio layer.
The approach taken with this patch is to allocate a small structure
for each nfs_netfs_issue_read() call, store the final error and number
of bytes successfully transferred in the structure, and update these values
as each RPC completes. The refcount on the structure is used as a marker
for the last RPC completion, is incremented in nfs_netfs_read_initiate(),
and decremented inside nfs_netfs_read_completion(), when a nfs_pgio_header
contains a valid pointer to the data. On the final put (which signals
the final outstanding RPC is complete) in nfs_netfs_read_completion(),
call netfs_subreq_terminated() with either the final error value (if
one or more READs complete with an error) or the number of bytes
successfully transferred (if all RPCs complete successfully). Note
that when all RPCs complete successfully, the number of bytes transferred
is capped to the length of the subrequest. Capping the transferred length
to the subrequest length prevents "Subreq overread" warnings from netfs.
This is due to the "aligned_len" in nfs_pageio_add_page(), and the
corner case where NFS requests a full page at the end of the file,
even when i_size reflects only a partial page (NFS overread).
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Tested-by: Daire Byrne <daire@dneg.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
2023-02-20 21:43:06 +08:00
|
|
|
ret = nfs_netfs_readahead(ractl);
|
|
|
|
if (!ret)
|
|
|
|
goto out;
|
|
|
|
|
2021-01-28 22:54:59 +08:00
|
|
|
if (file == NULL) {
|
|
|
|
ret = -EBADF;
|
2023-02-20 21:43:04 +08:00
|
|
|
ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
|
|
|
|
if (ctx == NULL)
|
2021-01-28 22:54:59 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
2023-02-20 21:43:04 +08:00
|
|
|
ctx = get_nfs_open_context(nfs_file_open_context(file));
|
2009-04-03 23:42:44 +08:00
|
|
|
|
2023-02-20 21:43:04 +08:00
|
|
|
nfs_pageio_init_read(&pgio, inode, false,
|
2014-04-16 21:07:22 +08:00
|
|
|
&nfs_async_read_completion_ops);
|
2007-04-03 06:48:28 +08:00
|
|
|
|
2023-01-20 05:33:41 +08:00
|
|
|
while ((folio = readahead_folio(ractl)) != NULL) {
|
2023-02-20 21:43:04 +08:00
|
|
|
ret = nfs_read_add_folio(&pgio, ctx, folio);
|
2022-01-23 04:54:52 +08:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2014-09-19 22:55:07 +08:00
|
|
|
|
2023-02-20 21:43:04 +08:00
|
|
|
nfs_pageio_complete_read(&pgio);
|
2024-06-17 09:21:25 +08:00
|
|
|
nfs_update_delegated_atime(inode);
|
2014-09-19 22:55:07 +08:00
|
|
|
|
2023-02-20 21:43:04 +08:00
|
|
|
put_nfs_open_context(ctx);
|
2006-09-15 02:03:14 +08:00
|
|
|
out:
|
2021-10-17 06:02:51 +08:00
|
|
|
trace_nfs_aop_readahead_done(inode, nr_pages, ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 21:34:33 +08:00
|
|
|
int __init nfs_init_readpagecache(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
|
2014-06-09 23:48:33 +08:00
|
|
|
sizeof(struct nfs_pgio_header),
|
2005-04-17 06:20:36 +08:00
|
|
|
0, SLAB_HWCACHE_ALIGN,
|
2007-07-20 09:11:58 +08:00
|
|
|
NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (nfs_rdata_cachep == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-28 03:59:15 +08:00
|
|
|
void nfs_destroy_readpagecache(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-09-27 16:49:40 +08:00
|
|
|
kmem_cache_destroy(nfs_rdata_cachep);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2014-05-06 21:12:30 +08: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 21:12:32 +08:00
|
|
|
.rw_done = nfs_readpage_done,
|
|
|
|
.rw_result = nfs_readpage_result,
|
2014-05-06 21:12:37 +08:00
|
|
|
.rw_initiate = nfs_initiate_read,
|
2014-05-06 21:12:30 +08:00
|
|
|
};
|