nfs/nfsd: add support for localio
Subsystems (5)
v6 cover nfs/nfsd: add support for localio
Hi,
This v6 changes include:
- Quite a bit of rebasing to eliminate intermediate steps that include throwaway code (thanks to Jeff Layton for calling those out).
- Moved the Kconfig changes to the end of the series to ensure that localio cannot be enabled until the code is feature complete.
- Removed needless nfsd_serv_sync() call from nfsd_create_serv().
- Removed inline from fs/nfsd/localio.c:nfs_stat_to_errno
- Wrapped localio struct nfs_client members and related fs/nfs/client.c init code with #if IS_ENABLED(CONFIG_NFS_LOCALIO)
- Requested a unique RPC program number from IANA but switched to using 0x20000002 until one is assigned.
- Improved the Documentation and some code comments.
Otherwise, not a lot of actual code changes.
My git tree is here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/
This v6 is both branch nfs-localio-for-6.11 (always tracks latest) and nfs-localio-for-6.11.v6
Branches nfs-localio-for-6.11.v[12345] are also available.
To see the changes from v5 to v6 please do:
git remote add snitzer git://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git
git remote update snitzer
git diff snitzer/nfs-localio-for-6.11.v5 snitzer/nfs-localio-for-6.11.v6
All review and comments are welcome!
Thanks,
Mike
Mike Snitzer (10):
nfs_common: add NFS LOCALIO auxiliary protocol enablement nfsd/localio: manage netns reference in nfsd_open_local_fh
nfs: implement v3 and v4 client support for NFS_LOCALIO_PROGRAM
nfsd: implement v3 and v4 server support for NFS_LOCALIO_PROGRAM nfs/nfsd: consolidate {encode,decode}_opaque_fixed in nfs_xdr.h
nfsd: prepare to use SRCU to dereference nn->nfsd_serv
nfsd: use SRCU to dereference nn->nfsd_serv
nfsd/localio: use SRCU to dereference nn->nfsd_serv in nfsd_open_local_fh
nfs: add Documentation/filesystems/nfs/localio.rst
nfs/nfsd: add Kconfig options to allow localio to be enabled
Trond Myklebust (3):
NFS: Enable localio for non-pNFS I/O
pnfs/flexfiles: Enable localio for flexfiles I/O nfs/localio: use dedicated workqueues for filesystem read and write
Weston Andros Adamson (5):
nfs: pass nfs_client to nfs_initiate_pgio
nfs: pass descriptor thru nfs_initiate_pgio path
nfs: pass struct file to nfs_init_pgio and nfs_init_commit
sunrpc: add rpcauth_map_to_svc_cred_local nfs/nfsd: add "localio" support
Documentation/filesystems/nfs/localio.rst | 148 ++++ fs/Kconfig | 3 + fs/nfs/Kconfig | 30 + fs/nfs/Makefile | 1 + fs/nfs/blocklayout/blocklayout.c | 6 +- fs/nfs/client.c | 15 +- fs/nfs/filelayout/filelayout.c | 16 +- fs/nfs/flexfilelayout/flexfilelayout.c | 131 +++- fs/nfs/flexfilelayout/flexfilelayout.h | 2 + fs/nfs/flexfilelayout/flexfilelayoutdev.c | 6 + fs/nfs/inode.c | 61 +- fs/nfs/internal.h | 88 ++- fs/nfs/localio.c | 850 ++++++++++++++++++++++ fs/nfs/nfs3_fs.h | 1 + fs/nfs/nfs3client.c | 25 + fs/nfs/nfs3proc.c | 3 + fs/nfs/nfs3xdr.c | 58 ++ fs/nfs/nfs4_fs.h | 2 + fs/nfs/nfs4client.c | 23 + fs/nfs/nfs4proc.c | 3 + fs/nfs/nfs4xdr.c | 65 +- fs/nfs/nfstrace.h | 61 ++ fs/nfs/pagelist.c | 32 +- fs/nfs/pnfs.c | 24 +- fs/nfs/pnfs.h | 6 +- fs/nfs/pnfs_nfs.c | 2 +- fs/nfs/write.c | 13 +- fs/nfs_common/Makefile | 3 + fs/nfs_common/nfslocalio.c | 71 ++ fs/nfsd/Kconfig | 30 + fs/nfsd/Makefile | 1 + fs/nfsd/filecache.c | 15 +- fs/nfsd/localio.c | 398 ++++++++++ fs/nfsd/netns.h | 18 +- fs/nfsd/nfs4state.c | 25 +- fs/nfsd/nfsctl.c | 28 +- fs/nfsd/nfsd.h | 11 + fs/nfsd/nfssvc.c | 181 ++++- fs/nfsd/trace.h | 3 +- fs/nfsd/vfs.h | 9 + fs/nfsd/xdr.h | 6 + include/linux/nfs.h | 2 + include/linux/nfs_fs.h | 2 + include/linux/nfs_fs_sb.h | 10 + include/linux/nfs_xdr.h | 31 +- include/linux/nfslocalio.h | 41 ++ include/linux/sunrpc/auth.h | 4 + include/uapi/linux/nfs.h | 4 + net/sunrpc/auth.c | 15 + 49 files changed, 2438 insertions(+), 145 deletions(-) create mode 100644 Documentation/filesystems/nfs/localio.rst create mode 100644 fs/nfs/localio.c create mode 100644 fs/nfs_common/nfslocalio.c create mode 100644 fs/nfsd/localio.c create mode 100644 include/linux/nfslocalio.h
Signature · 1 line
2.44.0
PATCH v6 1/18 nfs: pass nfs_client to nfs_initiate_pgio
From: Weston Andros Adamson <[email protected]>
The nfs_client is needed for localio support. Otherwise it won't be possible to disable localio if it is attempted but fails.
--- fs/nfs/filelayout/filelayout.c | 4 ++-- fs/nfs/flexfilelayout/flexfilelayout.c | 6 ++++-- fs/nfs/internal.h | 5 +++-- fs/nfs/pagelist.c | 10 ++++++---- 4 files changed, 15 insertions(+), 10 deletions(-)
fs/nfs/filelayout/filelayout.c +2 -2
@@ -486,7 +486,7 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr) hdr->mds_offset = offset;/* Perform an asynchronous read to ds */ -nfs_initiate_pgio (ds_clnt, hdr, hdr->cred, +nfs_initiate_pgio (ds->ds_clp, ds_clnt, hdr, hdr->cred,NFS_PROTO (hdr->inode), &filelayout_read_call_ops,0 ,RPC_TASK_SOFTCONN );return PNFS_ATTEMPTED ;
@@ -528,7 +528,7 @@ filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync) hdr->args.offset =filelayout_get_dserver_offset (lseg, offset);/* Perform an asynchronous write */ -nfs_initiate_pgio (ds_clnt, hdr, hdr->cred, +nfs_initiate_pgio (ds->ds_clp, ds_clnt, hdr, hdr->cred,NFS_PROTO (hdr->inode), &filelayout_write_call_ops, sync,RPC_TASK_SOFTCONN );return PNFS_ATTEMPTED ;
fs/nfs/flexfilelayout/flexfilelayout.c +4 -2
@@ -1803,7 +1803,8 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr) hdr->mds_offset = offset;/* Perform an asynchronous read to ds */ -nfs_initiate_pgio (ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, +nfs_initiate_pgio (ds->ds_clp, ds_clnt, hdr, ds_cred, + ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_read_call_ops_v3 : &ff_layout_read_call_ops_v4,0 ,RPC_TASK_SOFTCONN );
@@ -1871,7 +1872,8 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) hdr->args.offset = offset;/* Perform an asynchronous write */ -nfs_initiate_pgio (ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, +nfs_initiate_pgio (ds->ds_clp, ds_clnt, hdr, ds_cred, + ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_write_call_ops_v3 : &ff_layout_write_call_ops_v4, sync,RPC_TASK_SOFTCONN );
fs/nfs/internal.h +3 -2
@@ -306,8 +306,9 @@ extern const struct nfs_pageio_ops nfs_pgio_rw_ops;struct nfs_pgio_header *nfs_pgio_header_alloc (const struct nfs_rw_ops *);void nfs_pgio_header_free (struct nfs_pgio_header *);int nfs_generic_pgio (struct nfs_pageio_descriptor *,struct nfs_pgio_header *); -int nfs_initiate_pgio (struct rpc_clnt *clnt,struct nfs_pgio_header *hdr, -const struct cred *cred,const struct nfs_rpc_ops *rpc_ops, +int nfs_initiate_pgio (struct nfs_client *clp,struct rpc_clnt *rpc_clnt, +struct nfs_pgio_header *hdr,const struct cred *cred, +const struct nfs_rpc_ops *rpc_ops,const struct rpc_call_ops *call_ops,int how,int flags);void nfs_free_request (struct nfs_page *req); struct nfs_pgio_mirror *
fs/nfs/pagelist.c +6 -4
@@ -844,8 +844,9 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)rpc_exit (task, err); } -int nfs_initiate_pgio (struct rpc_clnt *clnt,struct nfs_pgio_header *hdr, -const struct cred *cred,const struct nfs_rpc_ops *rpc_ops, +int nfs_initiate_pgio (struct nfs_client *clp,struct rpc_clnt *rpc_clnt, +struct nfs_pgio_header *hdr,const struct cred *cred, +const struct nfs_rpc_ops *rpc_ops,const struct rpc_call_ops *call_ops,int how,int flags) {struct rpc_task *task;
@@ -855,7 +856,7 @@ int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, .rpc_cred = cred, };struct rpc_task_setup task_setup_data = { - .rpc_client = clnt, + .rpc_client = rpc_clnt, .task = &hdr->task, .rpc_message = &msg, .callback_ops = call_ops,
@@ -1070,7 +1071,8 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)if (ret ==0 ) {if (NFS_SERVER (hdr->inode)->nfs_client->cl_minorversion) task_flags =RPC_TASK_MOVEABLE ; - ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode), + ret = nfs_initiate_pgio(NFS_SERVER(hdr->inode)->nfs_client, + NFS_CLIENT(hdr->inode), hdr, hdr->cred, NFS_PROTO(hdr->inode),
Signature · 1 line
2.44.0
PATCH v6 2/18 nfs: pass descriptor thru nfs_initiate_pgio path
In reply to Mike SnitzerFrom: Weston Andros Adamson <[email protected]>
This is needed for localio support.
--- fs/nfs/blocklayout/blocklayout.c | 6 ++++-- fs/nfs/filelayout/filelayout.c | 10 ++++++---- fs/nfs/flexfilelayout/flexfilelayout.c | 10 ++++++---- fs/nfs/internal.h | 6 +++--- fs/nfs/pagelist.c | 6 ++++-- fs/nfs/pnfs.c | 24 +++++++++++++----------- fs/nfs/pnfs.h | 6 ++++-- 7 files changed, 40 insertions(+), 28 deletions(-)
fs/nfs/blocklayout/blocklayout.c +4 -2
@@ -227,7 +227,8 @@ bl_end_par_io_read(void *data) }static enum pnfs_try_status -bl_read_pagelist (struct nfs_pgio_header *header) +bl_read_pagelist (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *header) {struct pnfs_block_layout *bl =BLK_LSEG2EXT (header->lseg);struct pnfs_block_dev_map map = { .start =NFS4_MAX_UINT64 };
@@ -372,7 +373,8 @@ static void bl_end_par_io_write(void *data) }static enum pnfs_try_status -bl_write_pagelist (struct nfs_pgio_header *header,int sync) +bl_write_pagelist (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *header,int sync) {struct pnfs_block_layout *bl =BLK_LSEG2EXT (header->lseg);struct pnfs_block_dev_map map = { .start =NFS4_MAX_UINT64 };
fs/nfs/filelayout/filelayout.c +6 -4
@@ -447,7 +447,8 @@ static const struct rpc_call_ops filelayout_commit_call_ops = { };static enum pnfs_try_status -filelayout_read_pagelist (struct nfs_pgio_header *hdr) +filelayout_read_pagelist (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *hdr) {struct pnfs_layout_segment *lseg = hdr->lseg;struct nfs4_pnfs_ds *ds;
@@ -486,7 +487,7 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr) hdr->mds_offset = offset;/* Perform an asynchronous read to ds */ -nfs_initiate_pgio (ds->ds_clp, ds_clnt, hdr, hdr->cred, +nfs_initiate_pgio (desc, ds->ds_clp, ds_clnt, hdr, hdr->cred,NFS_PROTO (hdr->inode), &filelayout_read_call_ops,0 ,RPC_TASK_SOFTCONN );return PNFS_ATTEMPTED ;
@@ -494,7 +495,8 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr)/* Perform async writes. */ static enum pnfs_try_status -filelayout_write_pagelist (struct nfs_pgio_header *hdr,int sync) +filelayout_write_pagelist (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *hdr,int sync) {struct pnfs_layout_segment *lseg = hdr->lseg;struct nfs4_pnfs_ds *ds;
@@ -528,7 +530,7 @@ filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync) hdr->args.offset =filelayout_get_dserver_offset (lseg, offset);/* Perform an asynchronous write */ -nfs_initiate_pgio (ds->ds_clp, ds_clnt, hdr, hdr->cred, +nfs_initiate_pgio (desc, ds->ds_clp, ds_clnt, hdr, hdr->cred,NFS_PROTO (hdr->inode), &filelayout_write_call_ops, sync,RPC_TASK_SOFTCONN );return PNFS_ATTEMPTED ;
fs/nfs/flexfilelayout/flexfilelayout.c +6 -4
@@ -1751,7 +1751,8 @@ static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = { };static enum pnfs_try_status -ff_layout_read_pagelist (struct nfs_pgio_header *hdr) +ff_layout_read_pagelist (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *hdr) {struct pnfs_layout_segment *lseg = hdr->lseg;struct nfs4_pnfs_ds *ds;
@@ -1803,7 +1804,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr) hdr->mds_offset = offset;/* Perform an asynchronous read to ds */ - nfs_initiate_pgio(ds->ds_clp, ds_clnt, hdr, ds_cred, + nfs_initiate_pgio(desc, ds->ds_clp, ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, vers == 3 ? &ff_layout_read_call_ops_v3 : &ff_layout_read_call_ops_v4,
@@ -1822,7 +1823,8 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)/* Perform async writes. */ static enum pnfs_try_status -ff_layout_write_pagelist (struct nfs_pgio_header *hdr,int sync) +ff_layout_write_pagelist (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *hdr,int sync) {struct pnfs_layout_segment *lseg = hdr->lseg;struct nfs4_pnfs_ds *ds;
@@ -1872,7 +1874,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) hdr->args.offset = offset;/* Perform an asynchronous write */ - nfs_initiate_pgio(ds->ds_clp, ds_clnt, hdr, ds_cred, + nfs_initiate_pgio(desc, ds->ds_clp, ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, vers == 3 ? &ff_layout_write_call_ops_v3 : &ff_layout_write_call_ops_v4,
fs/nfs/internal.h +3 -3
@@ -306,9 +306,9 @@ extern const struct nfs_pageio_ops nfs_pgio_rw_ops;struct nfs_pgio_header *nfs_pgio_header_alloc (const struct nfs_rw_ops *);void nfs_pgio_header_free (struct nfs_pgio_header *);int nfs_generic_pgio (struct nfs_pageio_descriptor *,struct nfs_pgio_header *); -int nfs_initiate_pgio (struct nfs_client *clp,struct rpc_clnt *rpc_clnt, -struct nfs_pgio_header *hdr,const struct cred *cred, -const struct nfs_rpc_ops *rpc_ops, +int nfs_initiate_pgio (struct nfs_pageio_descriptor *,struct nfs_client *clp, +struct rpc_clnt *rpc_clnt,struct nfs_pgio_header *hdr, +const struct cred *cred,const struct nfs_rpc_ops *rpc_ops,const struct rpc_call_ops *call_ops,int how,int flags);void nfs_free_request (struct nfs_page *req); struct nfs_pgio_mirror *
fs/nfs/pagelist.c +4 -2
@@ -844,7 +844,8 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)rpc_exit (task, err); } -int nfs_initiate_pgio (struct nfs_client *clp,struct rpc_clnt *rpc_clnt, +int nfs_initiate_pgio (struct nfs_pageio_descriptor *desc, +struct nfs_client *clp,struct rpc_clnt *rpc_clnt,struct nfs_pgio_header *hdr,const struct cred *cred,const struct nfs_rpc_ops *rpc_ops,const struct rpc_call_ops *call_ops,int how,int flags)
@@ -1071,7 +1072,8 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)if (ret ==0 ) {if (NFS_SERVER (hdr->inode)->nfs_client->cl_minorversion) task_flags =RPC_TASK_MOVEABLE ; - ret = nfs_initiate_pgio(NFS_SERVER(hdr->inode)->nfs_client, + ret = nfs_initiate_pgio(desc, + NFS_SERVER(hdr->inode)->nfs_client, NFS_CLIENT(hdr->inode), hdr, hdr->cred,
fs/nfs/pnfs.c +13 -11
@@ -2885,10 +2885,11 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, }static enum pnfs_try_status -pnfs_try_to_write_data (struct nfs_pgio_header *hdr, -const struct rpc_call_ops *call_ops, -struct pnfs_layout_segment *lseg, -int how) +pnfs_try_to_write_data (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *hdr, +const struct rpc_call_ops *call_ops, +struct pnfs_layout_segment *lseg, +int how) {struct inode *inode = hdr->inode;enum pnfs_try_status trypnfs;
@@ -2898,7 +2899,7 @@ pnfs_try_to_write_data(struct nfs_pgio_header *hdr,dprintk ("%s: Writing ino:%lu %u@%llu (how %d)\n" , __func__, inode->i_ino, hdr->args.count, hdr->args.offset, how); - trypnfs = nfss->pnfs_curr_ld->write_pagelist (hdr, how); + trypnfs = nfss->pnfs_curr_ld->write_pagelist (desc, hdr, how);if (trypnfs !=PNFS_NOT_ATTEMPTED )nfs_inc_stats (inode,NFSIOS_PNFS_WRITE );dprintk ("%s End (trypnfs:%d)\n" , __func__, trypnfs);
@@ -2913,7 +2914,7 @@ pnfs_do_write(struct nfs_pageio_descriptor *desc,struct pnfs_layout_segment *lseg = desc->pg_lseg;enum pnfs_try_status trypnfs; - trypnfs =pnfs_try_to_write_data (hdr, call_ops, lseg, how); + trypnfs =pnfs_try_to_write_data (desc, hdr, call_ops, lseg, how);switch (trypnfs) {case PNFS_NOT_ATTEMPTED :pnfs_write_through_mds (desc, hdr);
@@ -3012,9 +3013,10 @@ pnfs_read_through_mds(struct nfs_pageio_descriptor *desc,* Call the appropriate parallel I/O subsystem read function. */ static enum pnfs_try_status -pnfs_try_to_read_data (struct nfs_pgio_header *hdr, -const struct rpc_call_ops *call_ops, -struct pnfs_layout_segment *lseg) +pnfs_try_to_read_data (struct nfs_pageio_descriptor *desc, +struct nfs_pgio_header *hdr, +const struct rpc_call_ops *call_ops, +struct pnfs_layout_segment *lseg) {struct inode *inode = hdr->inode;struct nfs_server *nfss =NFS_SERVER (inode);
@@ -3025,7 +3027,7 @@ pnfs_try_to_read_data(struct nfs_pgio_header *hdr,dprintk ("%s: Reading ino:%lu %u@%llu\n" , __func__, inode->i_ino, hdr->args.count, hdr->args.offset); - trypnfs = nfss->pnfs_curr_ld->read_pagelist (hdr); + trypnfs = nfss->pnfs_curr_ld->read_pagelist (desc, hdr);if (trypnfs !=PNFS_NOT_ATTEMPTED )nfs_inc_stats (inode,NFSIOS_PNFS_READ );dprintk ("%s End (trypnfs:%d)\n" , __func__, trypnfs);
@@ -3058,7 +3060,7 @@ pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr)struct pnfs_layout_segment *lseg = desc->pg_lseg;enum pnfs_try_status trypnfs; - trypnfs =pnfs_try_to_read_data (hdr, call_ops, lseg); + trypnfs =pnfs_try_to_read_data (desc, hdr, call_ops, lseg);switch (trypnfs) {case PNFS_NOT_ATTEMPTED :pnfs_read_through_mds (desc, hdr);
fs/nfs/pnfs.h +4 -2
@@ -157,8 +157,10 @@ struct pnfs_layoutdriver_type {* Return PNFS_ATTEMPTED to indicate the layout code has attempted * I/O, else return PNFS_NOT_ATTEMPTED to fall back to normal NFS */ -enum pnfs_try_status (*read_pagelist)(struct nfs_pgio_header *); -enum pnfs_try_status (*write_pagelist)(struct nfs_pgio_header *,int ); +enum pnfs_try_status (*read_pagelist)(struct nfs_pageio_descriptor *, +struct nfs_pgio_header *); +enum pnfs_try_status (*write_pagelist)(struct nfs_pageio_descriptor *, +struct nfs_pgio_header *,int );void (*free_deviceid_node) (struct nfs4_deviceid_node *);struct nfs4_deviceid_node * (*alloc_deviceid_node)
Signature · 1 line
2.44.0
PATCH v6 3/18 nfs: pass struct file to nfs_init_pgio and nfs_init_commit
In reply to Mike SnitzerFrom: Weston Andros Adamson <[email protected]>
This is needed for localio support.
--- fs/nfs/filelayout/filelayout.c | 6 +++--- fs/nfs/flexfilelayout/flexfilelayout.c | 6 +++--- fs/nfs/internal.h | 6 ++++-- fs/nfs/pagelist.c | 6 ++++-- fs/nfs/pnfs_nfs.c | 2 +- fs/nfs/write.c | 5 +++-- 6 files changed, 18 insertions(+), 13 deletions(-)
fs/nfs/filelayout/filelayout.c +3 -3
@@ -489,7 +489,7 @@ filelayout_read_pagelist(struct nfs_pageio_descriptor *desc,/* Perform an asynchronous read to ds */ nfs_initiate_pgio (desc, ds->ds_clp, ds_clnt, hdr, hdr->cred,NFS_PROTO (hdr->inode), &filelayout_read_call_ops, -0 ,RPC_TASK_SOFTCONN ); +0 ,RPC_TASK_SOFTCONN ,NULL );return PNFS_ATTEMPTED ; }
@@ -532,7 +532,7 @@ filelayout_write_pagelist(struct nfs_pageio_descriptor *desc,/* Perform an asynchronous write */ nfs_initiate_pgio (desc, ds->ds_clp, ds_clnt, hdr, hdr->cred,NFS_PROTO (hdr->inode), &filelayout_write_call_ops, - sync,RPC_TASK_SOFTCONN ); + sync,RPC_TASK_SOFTCONN ,NULL );return PNFS_ATTEMPTED ; }
@@ -1013,7 +1013,7 @@ static int filelayout_initiate_commit(struct nfs_commit_data *data, int how) data->args.fh = fh;return nfs_initiate_commit (ds_clnt, data,NFS_PROTO (data->inode), &filelayout_commit_call_ops, how, -RPC_TASK_SOFTCONN ); +RPC_TASK_SOFTCONN ,NULL ); out_err:pnfs_generic_prepare_to_resend_writes (data);pnfs_generic_commit_release (data);
fs/nfs/flexfilelayout/flexfilelayout.c +3 -3
@@ -1808,7 +1808,7 @@ ff_layout_read_pagelist(struct nfs_pageio_descriptor *desc, ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_read_call_ops_v3 : &ff_layout_read_call_ops_v4, - 0, RPC_TASK_SOFTCONN); + 0, RPC_TASK_SOFTCONN, NULL);put_cred (ds_cred);return PNFS_ATTEMPTED ;
@@ -1878,7 +1878,7 @@ ff_layout_write_pagelist(struct nfs_pageio_descriptor *desc, ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_write_call_ops_v3 : &ff_layout_write_call_ops_v4, - sync, RPC_TASK_SOFTCONN); + sync, RPC_TASK_SOFTCONN, NULL);put_cred (ds_cred);return PNFS_ATTEMPTED ;
@@ -1953,7 +1953,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how) ret =nfs_initiate_commit (ds_clnt, data, ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_commit_call_ops_v3 : &ff_layout_commit_call_ops_v4, - how,RPC_TASK_SOFTCONN ); + how,RPC_TASK_SOFTCONN ,NULL );put_cred (ds_cred);return ret; out_err:
fs/nfs/internal.h +4 -2
@@ -309,7 +309,8 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);int nfs_initiate_pgio (struct nfs_pageio_descriptor *,struct nfs_client *clp,struct rpc_clnt *rpc_clnt,struct nfs_pgio_header *hdr,const struct cred *cred,const struct nfs_rpc_ops *rpc_ops, -const struct rpc_call_ops *call_ops,int how,int flags); +const struct rpc_call_ops *call_ops,int how,int flags, +struct file *localio);void nfs_free_request (struct nfs_page *req);struct nfs_pgio_mirror *nfs_pgio_current_mirror (struct nfs_pageio_descriptor *desc);
@@ -529,7 +530,8 @@ extern int nfs_initiate_commit(struct rpc_clnt *clnt,struct nfs_commit_data *data, const struct nfs_rpc_ops *nfs_ops, const struct rpc_call_ops *call_ops, - int how, int flags); + int how, int flags, + struct file *localio); extern void nfs_init_commit(struct nfs_commit_data *data, struct list_head *head, struct pnfs_layout_segment *lseg,
fs/nfs/pagelist.c +4 -2
@@ -848,7 +848,8 @@ int nfs_initiate_pgio(struct nfs_pageio_descriptor *desc, struct nfs_client *clp, struct rpc_clnt *rpc_clnt, struct nfs_pgio_header *hdr, const struct cred *cred, const struct nfs_rpc_ops *rpc_ops, - const struct rpc_call_ops *call_ops, int how, int flags) + const struct rpc_call_ops *call_ops, int how, int flags, + struct file *localio) { struct rpc_task *task; struct rpc_message msg = {
@@ -1080,7 +1081,8 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)NFS_PROTO (hdr->inode), desc->pg_rpc_callops, desc->pg_ioflags, - RPC_TASK_CRED_NOREF | task_flags); +RPC_TASK_CRED_NOREF | task_flags, + NULL); }return ret; }
fs/nfs/pnfs_nfs.c +1 -1
@@ -537,7 +537,7 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,nfs_initiate_commit (NFS_CLIENT (inode), data,NFS_PROTO (data->inode), data->mds_ops, how, -RPC_TASK_CRED_NOREF ); +RPC_TASK_CRED_NOREF ,NULL ); }else {nfs_init_commit (data,NULL , data->lseg, cinfo);initiate_commit (data, how);
fs/nfs/write.c +3 -2
@@ -1670,7 +1670,8 @@ EXPORT_SYMBOL_GPL(nfs_commitdata_release);int nfs_initiate_commit (struct rpc_clnt *clnt,struct nfs_commit_data *data,const struct nfs_rpc_ops *nfs_ops,const struct rpc_call_ops *call_ops, -int how,int flags) +int how,int flags, +struct file *localio) {struct rpc_task *task;int priority =flush_task_priority (how);
@@ -1816,7 +1817,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, task_flags =RPC_TASK_MOVEABLE ;return nfs_initiate_commit (NFS_CLIENT (inode), data,NFS_PROTO (inode), data->mds_ops, how, -RPC_TASK_CRED_NOREF | task_flags); +RPC_TASK_CRED_NOREF | task_flags,NULL ); }/*
Signature · 1 line
2.44.0
PATCH v6 4/18 sunrpc: add rpcauth_map_to_svc_cred_local
In reply to Mike SnitzerFrom: Weston Andros Adamson <[email protected]>
Add new funtion rpcauth_map_to_svc_cred_local which maps a generic cred to a svc_cred suitable for use in nfsd.
This is needed by the localio code to map nfs client creds to nfs server credentials.
--- include/linux/sunrpc/auth.h | 4 ++++ net/sunrpc/auth.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+)
include/linux/sunrpc/auth.h +4 -0
@@ -11,6 +11,7 @@#define _LINUX_SUNRPC_AUTH_H#include <linux/sunrpc/sched.h> +#include <linux/sunrpc/svcauth.h> #include <linux/sunrpc/msg_prot.h> #include <linux/sunrpc/xdr.h>
@@ -184,6 +185,9 @@ int rpcauth_uptodatecred(struct rpc_task *);int rpcauth_init_credcache (struct rpc_auth *);void rpcauth_destroy_credcache (struct rpc_auth *);void rpcauth_clear_credcache (struct rpc_cred_cache *); +void rpcauth_map_to_svc_cred_local (struct rpc_auth *, +const struct cred *, +struct svc_cred *);char *rpcauth_stringify_acceptor (struct rpc_cred *); static inline
net/sunrpc/auth.c +15 -0
@@ -308,6 +308,21 @@ rpcauth_init_credcache(struct rpc_auth *auth) }EXPORT_SYMBOL_GPL (rpcauth_init_credcache); +void +rpcauth_map_to_svc_cred_local (struct rpc_auth *auth,const struct cred *cred, +struct svc_cred *svc) +{ + svc->cr_uid = cred->uid; + svc->cr_gid = cred->gid; + svc->cr_flavor = auth->au_flavor; +if (cred->group_info) + svc->cr_group_info =get_group_info (cred->group_info); +/* These aren't relevant for local (network is bypassed) */ + svc->cr_principal =NULL ; + svc->cr_gss_mech =NULL ; +} +EXPORT_SYMBOL_GPL (rpcauth_map_to_svc_cred_local); +char *rpcauth_stringify_acceptor (struct rpc_cred *cred) {
Signature · 1 line
2.44.0
PATCH v6 5/18 nfs_common: add NFS LOCALIO auxiliary protocol enablement
In reply to Mike SnitzerFirst use is in nfsd, to add access to a global nfsd_uuids list that will be used to identify local nfsd instances.
nfsd_uuids is protected by nfsd_mutex or RCU read lock. List is composed of nfsd_uuid_t instances that are managed as nfsd creates them (per network namespace).
nfsd_uuid_is_local() will be used to search all local nfsd for the client specified nfsd uuid.
This commit also adds all the nfs_client members required to implement the entire localio feature (which depends on the LOCALIO protocol).
--- fs/nfs/client.c | 8 +++++ fs/nfs_common/Makefile | 3 ++ fs/nfs_common/nfslocalio.c | 71 ++++++++++++++++++++++++++++++++++++++ fs/nfsd/netns.h | 4 +++ fs/nfsd/nfssvc.c | 12 ++++++- include/linux/nfs_fs_sb.h | 9 +++++ include/linux/nfslocalio.h | 39 +++++++++++++++++++++ 7 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 fs/nfs_common/nfslocalio.c create mode 100644 include/linux/nfslocalio.h
fs/nfs/client.c +8 -0
@@ -178,6 +178,14 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) clp->cl_max_connect = cl_init->max_connect ? cl_init->max_connect :1 ; clp->cl_net =get_net (cl_init->net); +#if IS_ENABLED (CONFIG_NFS_LOCALIO ) +seqlock_init (&clp->cl_boot_lock); +ktime_get_real_ts64 (&clp->cl_nfssvc_boot); + clp->cl_rpcclient_localio =ERR_PTR (-EINVAL ); + clp->nfsd_open_local_fh =NULL ; + clp->cl_nfssvc_net =NULL ; +#endif /* CONFIG_NFS_LOCALIO */ + clp->cl_principal ="*" ; clp->cl_xprtsec = cl_init->xprtsec;return clp;
fs/nfs_common/Makefile +3 -0
@@ -6,5 +6,8 @@ obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o nfs_acl-objs := nfsacl.o +obj-$(CONFIG_NFS_COMMON_LOCALIO_SUPPORT) += nfs_localio.o +nfs_localio-objs := nfslocalio.o + obj-$(CONFIG_GRACE_PERIOD) += grace.o obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o
fs/nfs_common/nfslocalio.c new file +71 -0
71 lines not on this page · raw message
fs/nfsd/netns.h +4 -0
@@ -15,6 +15,7 @@#include <linux/percpu_counter.h> #include <linux/siphash.h> #include <linux/sunrpc/stats.h> +#include <linux/nfslocalio.h> /* Hash tables for nfs4_clientid state */ #define CLIENT_HASH_BITS 4
@@ -213,6 +214,9 @@ struct nfsd_net {/* last time an admin-revoke happened for NFSv4.0 */ time64_t nfs40_last_revoke; +#if IS_ENABLED (CONFIG_NFSD_LOCALIO ) +nfsd_uuid_t nfsd_uuid; +#endif };/* Simple check to find out if a given net was properly initialized */
fs/nfsd/nfssvc.c +11 -1
@@ -19,6 +19,7 @@#include <linux/sunrpc/svc_xprt.h> #include <linux/lockd/bind.h> #include <linux/nfsacl.h> +#include <linux/nfslocalio.h> #include <linux/seq_file.h> #include <linux/inetdevice.h> #include <net/addrconf.h>
@@ -427,6 +428,10 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)#ifdef CONFIG_NFSD_V4_2_INTER_SSC nfsd4_ssc_init_umount_work (nn); +#endif +#if IS_ENABLED (CONFIG_NFSD_LOCALIO ) +INIT_LIST_HEAD (&nn->nfsd_uuid.list); +list_add_tail_rcu (&nn->nfsd_uuid.list, &nfsd_uuids);#endif nn->nfsd_net_up = true;return 0 ;
@@ -456,6 +461,9 @@ static void nfsd_shutdown_net(struct net *net)lockd_down (net); nn->lockd_up = false; } +#if IS_ENABLED (CONFIG_NFSD_LOCALIO ) +list_del_rcu (&nn->nfsd_uuid.list); +#endif nn->nfsd_net_up = false;nfsd_shutdown_generic (); }
@@ -802,7 +810,9 @@ nfsd_svc(int n, int *nthreads, struct net *net, const struct cred *cred, const cstrscpy (nn->nfsd_name, scope ? scope :utsname ()->nodename,sizeof (nn->nfsd_name)); - +#if IS_ENABLED (CONFIG_NFSD_LOCALIO ) +uuid_gen (&nn->nfsd_uuid.uuid); +#endif error =nfsd_create_serv (net);if (error) goto out;
include/linux/nfs_fs_sb.h +9 -0
@@ -8,6 +8,7 @@#include <linux/wait.h> #include <linux/nfs_xdr.h> #include <linux/sunrpc/xprt.h> +#include <linux/nfslocalio.h> #include <linux/atomic.h> #include <linux/refcount.h>
@@ -125,6 +126,14 @@ struct nfs_client {struct net *cl_net;struct list_head pending_cb_stateids;struct rcu_head rcu; + +#if IS_ENABLED (CONFIG_NFS_LOCALIO ) +struct timespec64 cl_nfssvc_boot; +seqlock_t cl_boot_lock; +struct rpc_clnt * cl_rpcclient_localio; +struct net * cl_nfssvc_net; +nfs_to_nfsd_open_t nfsd_open_local_fh; +#endif /* CONFIG_NFS_LOCALIO */ };/*
include/linux/nfslocalio.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2024 Mike Snitzer <[email protected]> +*/ +#ifndef __LINUX_NFSLOCALIO_H +#define __LINUX_NFSLOCALIO_H + +#include <linux/list.h> +#include <linux/uuid.h> +#include <linux/nfs.h> +#include <net/net_namespace.h> + +/* +* Global list of nfsd_uuid_t instances, add/remove +* is protected by fs/nfsd/nfssvc.c:nfsd_mutex. +*/ +extern struct list_head nfsd_uuids; + +/* +* Each nfsd instance has an nfsd_uuid_t that is accessible through the +* global nfsd_uuids list. Useful to allow a client to negotiate if localio +* possible with its server. +*/ +typedef struct { +uuid_t uuid; +struct list_head list; +struct net *net;/* nfsd's network namespace */ +}nfsd_uuid_t ; + +bool nfsd_uuid_is_local (const uuid_t *uuid,struct net **netp); + +typedef int (*nfs_to_nfsd_open_t )(struct net *,struct rpc_clnt *, +const struct cred *,const struct nfs_fh *, +const fmode_t ,struct file **); + +nfs_to_nfsd_open_t get_nfsd_open_local_fh (void ); +void put_nfsd_open_local_fh (void ); + +#endif /* __LINUX_NFSLOCALIO_H */
Signature · 1 line
2.44.0
Re: [PATCH v6 05/18] nfs_common: add NFS LOCALIO auxiliary protocol enablement
On 6/19/24 13:40, Mike Snitzer wrote:
...
Quoted 6 lines
fs/nfs_common/nfslocalio.c new file +0
-0
fs/nfs_common/nfslocalio.c line 10
Quoted 10 lines
fs/nfs_common/nfslocalio.c new file +10
-0@@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2024 Mike Snitzer <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/rculist.h> +#include <linux/nfslocalio.h> + +MODULE_LICENSE ("GPL" );
also need a MODULE_DESCRIPTION()
Since commit 1fffe7a34c89 ("script: modpost: emit a warning when the description is missing") a module without a MODULE_DESCRIPTION() will result in a warning with make W=1
PATCH v6 6/18 nfs/nfsd: add "localio" support
In reply to Mike SnitzerFrom: Weston Andros Adamson <[email protected]>
Add client support for bypassing NFS for localhost reads, writes, and commits. This is only useful when the client and the server are running on the same host.
nfs_local_probe() is stubbed out, later commits will enable client and server handshake via a Linux-only LOCALIO auxiliary RPC protocol.
This has dynamic binding with the nfsd module (via nfs_localio module which is part of nfs_common). Localio will only work if nfsd is already loaded.
The "localio_enabled" nfs kernel module parameter can be used to disable and enable the ability to use localio support.
Tracepoints were added for nfs_local_open_fh, nfs_local_enable and nfs_local_disable.
Also, pass the stored cl_nfssvc_net from the client to the server as first argument to nfsd_open_local_fh() to ensure the proper network namespace is used for localio.
--- fs/nfs/Makefile | 1 + fs/nfs/client.c | 3 + fs/nfs/inode.c | 4 + fs/nfs/internal.h | 51 +++ fs/nfs/localio.c | 722 ++++++++++++++++++++++++++++++++++++++ fs/nfs/nfstrace.h | 61 ++++ fs/nfs/pagelist.c | 3 + fs/nfs/write.c | 3 + fs/nfsd/Makefile | 1 + fs/nfsd/filecache.c | 2 +- fs/nfsd/localio.c | 244 +++++++++++++ fs/nfsd/nfssvc.c | 1 + fs/nfsd/trace.h | 3 +- fs/nfsd/vfs.h | 9 + include/linux/nfs.h | 2 + include/linux/nfs_fs.h | 2 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 1 + 18 files changed, 1112 insertions(+), 2 deletions(-) create mode 100644 fs/nfs/localio.c create mode 100644 fs/nfsd/localio.c
fs/nfs/Makefile +1 -0
@@ -13,6 +13,7 @@ nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_SYSCTL) += sysctl.o nfs-$(CONFIG_NFS_FSCACHE) += fscache.o +nfs-$(CONFIG_NFS_LOCALIO) += localio.o obj-$(CONFIG_NFS_V2) += nfsv2.o nfsv2-y := nfs2super.o proc.o nfs2xdr.o
fs/nfs/client.c +3 -0
@@ -241,6 +241,8 @@ static void pnfs_init_server(struct nfs_server *server)*/ void nfs_free_client (struct nfs_client *clp) { +nfs_local_disable (clp); +/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))rpc_shutdown_client (clp->cl_rpcclient);
@@ -432,6 +434,7 @@ struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)list_add_tail (&new->cl_share_link, &nn->nfs_client_list);spin_unlock (&nn->nfs_client_lock); +nfs_local_probe (new);return rpc_ops->init_client (new, cl_init); }
fs/nfs/inode.c +4 -0
@@ -39,6 +39,7 @@#include <linux/slab.h> #include <linux/compat.h> #include <linux/freezer.h> +#include <linux/file.h> #include <linux/uaccess.h> #include <linux/iversion.h>
@@ -1053,6 +1054,7 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, ctx->lock_context.open_context = ctx;INIT_LIST_HEAD (&ctx->list); ctx->mdsthreshold =NULL ; + ctx->local_filp =NULL ;return ctx; }EXPORT_SYMBOL_GPL (alloc_nfs_open_context);
@@ -1084,6 +1086,8 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)nfs_sb_deactive (sb);put_rpccred (rcu_dereference_protected (ctx->ll_cred,1 ));kfree (ctx->mdsthreshold); +if (!IS_ERR_OR_NULL (ctx->local_filp)) +fput (ctx->local_filp);kfree_rcu (ctx, rcu_head); }
fs/nfs/internal.h +51 -0
57 lines not on this page · raw message
fs/nfs/localio.c new file +722 -0
722 lines not on this page · raw message
fs/nfs/nfstrace.h +61 -0
67 lines not on this page · raw message
fs/nfs/pagelist.c +3 -0
@@ -879,6 +879,9 @@ int nfs_initiate_pgio(struct nfs_pageio_descriptor *desc, hdr->args.count, (unsigned long long)hdr->args.offset); +if (localio) +return nfs_local_doio (clp, localio, hdr, call_ops); + task =rpc_run_task (&task_setup_data);if (IS_ERR (task))return PTR_ERR (task);
fs/nfs/write.c +3 -0
@@ -1700,6 +1700,9 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,dprintk ("NFS: initiated commit call\n" ); +if (localio) +return nfs_local_commit (localio, data, call_ops, how); + task =rpc_run_task (&task_setup_data);if (IS_ERR (task))return PTR_ERR (task);
fs/nfsd/Makefile +1 -0
@@ -23,3 +23,4 @@ nfsd-$(CONFIG_NFSD_PNFS) += nfs4layouts.o nfsd-$(CONFIG_NFSD_BLOCKLAYOUT) += blocklayout.o blocklayoutxdr.o nfsd-$(CONFIG_NFSD_SCSILAYOUT) += blocklayout.o blocklayoutxdr.o nfsd-$(CONFIG_NFSD_FLEXFILELAYOUT) += flexfilelayout.o flexfilelayoutxdr.o +nfsd-$(CONFIG_NFSD_LOCALIO) += localio.o
fs/nfsd/filecache.c +1 -1
@@ -52,7 +52,7 @@#define NFSD_FILE_CACHE_UP (0)/* We only care about NFSD_MAY_READ/WRITE for this cache */ -#define NFSD_FILE_MAY_MASK (NFSD_MAY_READ|NFSD_MAY_WRITE) +#define NFSD_FILE_MAY_MASK (NFSD_MAY_READ|NFSD_MAY_WRITE|NFSD_MAY_LOCALIO) static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits); static DEFINE_PER_CPU(unsigned long, nfsd_file_acquisitions);
fs/nfsd/localio.c new file +244 -0
244 lines not on this page · raw message
fs/nfsd/nfssvc.c +1 -0
@@ -431,6 +431,7 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)#endif #if IS_ENABLED (CONFIG_NFSD_LOCALIO )INIT_LIST_HEAD (&nn->nfsd_uuid.list); + nn->nfsd_uuid.net = net;list_add_tail_rcu (&nn->nfsd_uuid.list, &nfsd_uuids);#endif nn->nfsd_net_up = true;
fs/nfsd/trace.h +2 -1
@@ -86,7 +86,8 @@ DEFINE_NFSD_XDR_ERR_EVENT(cant_encode); { NFSD_MAY_NOT_BREAK_LEASE, "NOT_BREAK_LEASE" }, \ { NFSD_MAY_BYPASS_GSS, "BYPASS_GSS" }, \ { NFSD_MAY_READ_IF_EXEC, "READ_IF_EXEC" }, \ - { NFSD_MAY_64BIT_COOKIE, "64BIT_COOKIE" }) + { NFSD_MAY_64BIT_COOKIE, "64BIT_COOKIE" }, \ + { NFSD_MAY_LOCALIO, "LOCALIO" }) TRACE_EVENT(nfsd_compound, TP_PROTO(
fs/nfsd/vfs.h +9 -0
@@ -36,6 +36,8 @@#define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE)#define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC) +#define NFSD_MAY_LOCALIO 0x800000 +struct nfsd_file ;/*
@@ -158,6 +160,13 @@ __be32 nfsd_permission(struct svc_rqst *, struct svc_export *,void nfsd_filp_close (struct file *fp); +int nfsd_open_local_fh (struct net *net, +struct rpc_clnt *rpc_clnt, +const struct cred *cred, +const struct nfs_fh *nfs_fh, +const fmode_t fmode, +struct file **pfilp); +static inline int fh_want_write (struct svc_fh *fh) {int ret;
include/linux/nfs.h +2 -0
@@ -8,6 +8,8 @@#ifndef _LINUX_NFS_H#define _LINUX_NFS_H +#include <linux/cred.h> +#include <linux/sunrpc/auth.h> #include <linux/sunrpc/msg_prot.h> #include <linux/string.h> #include <linux/crc32.h>
include/linux/nfs_fs.h +2 -0
@@ -96,6 +96,8 @@ struct nfs_open_context {struct list_head list;struct nfs4_threshold *mdsthreshold;struct rcu_head rcu_head; + +struct file *local_filp; };struct nfs_open_dir_context {
include/linux/nfs_fs_sb.h +1 -0
@@ -50,6 +50,7 @@ struct nfs_client {#define NFS_CS_DS 7/* - Server is a DS */ #define NFS_CS_REUSEPORT 8/* - reuse src port on reconnect */ #define NFS_CS_PNFS 9/* - Server used for pnfs */ +#define NFS_CS_LOCAL_IO 10/* - client is local */ struct sockaddr_storage cl_addr;/* server identifier */ size_t cl_addrlen;char * cl_hostname;/* hostname of server */
include/linux/nfs_xdr.h +1 -0
@@ -1605,6 +1605,7 @@ enum {NFS_IOHDR_RESEND_PNFS ,NFS_IOHDR_RESEND_MDS ,NFS_IOHDR_UNSTABLE_WRITES , + NFS_IOHDR_ODIRECT, };struct nfs_io_completion ;
Signature · 1 line
2.44.0
Re: [PATCH v6 06/18] nfs/nfsd: add "localio" support
Quoted 429 lines · Mike Snitzer
From: Weston Andros Adamson <[email protected]>
Add client support for bypassing NFS for localhost reads, writes, and commits. This is only useful when the client and the server are running on the same host.
nfs_local_probe()is stubbed out, later commits will enable client and server handshake via a Linux-only LOCALIO auxiliary RPC protocol.This has dynamic binding with the nfsd module (via
nfs_localiomodule which is part ofnfs_common). Localio will only work if nfsd is already loaded.The "
localio_enabled" nfs kernel module parameter can be used to disable and enable the ability to use localio support.Tracepoints were added for
nfs_local_open_fh,nfs_local_enableandnfs_local_disable.Also, pass the stored
cl_nfssvc_netfrom the client to the server as first argument tonfsd_open_local_fh()to ensure the proper network namespace is used for localio.Signed-off-by Weston Andros Adamson <[email protected]>Signed-off-by Peng Tao <[email protected]>Signed-off-by Lance Shelton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>Signed-off-by Mike Snitzer <[email protected]>--- fs/nfs/Makefile | 1 + fs/nfs/client.c | 3 + fs/nfs/inode.c | 4 + fs/nfs/internal.h | 51 +++ fs/nfs/localio.c | 722 ++++++++++++++++++++++++++++++++++++++ fs/nfs/nfstrace.h | 61 ++++ fs/nfs/pagelist.c | 3 + fs/nfs/write.c | 3 + fs/nfsd/Makefile | 1 + fs/nfsd/filecache.c | 2 +- fs/nfsd/localio.c | 244 +++++++++++++ fs/nfsd/nfssvc.c | 1 + fs/nfsd/trace.h | 3 +- fs/nfsd/vfs.h | 9 + include/linux/nfs.h | 2 + include/linux/nfs_fs.h | 2 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 1 + 18 files changed, 1112 insertions(+), 2 deletions(-) create mode 100644 fs/nfs/localio.c create mode 100644 fs/nfsd/localio.cfs/nfs/Makefile +1
-0@@ -13,6 +13,7 @@ nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_SYSCTL) += sysctl.o nfs-$(CONFIG_NFS_FSCACHE) += fscache.o +nfs-$(CONFIG_NFS_LOCALIO) += localio.o obj-$(CONFIG_NFS_V2) += nfsv2.o nfsv2-y := nfs2super.o proc.o nfs2xdr.ofs/nfs/client.c +3
-0@@ -241,6 +241,8 @@ static void pnfs_init_server(struct nfs_server *server)*/ void nfs_free_client (struct nfs_client *clp) { +nfs_local_disable (clp); +/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))rpc_shutdown_client (clp->cl_rpcclient);@@ -432,6 +434,7 @@ struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)list_add_tail (&new->cl_share_link, &nn->nfs_client_list);spin_unlock (&nn->nfs_client_lock); +nfs_local_probe (new);return rpc_ops->init_client (new, cl_init); }fs/nfs/inode.c +4
-0@@ -39,6 +39,7 @@#include <linux/slab.h> #include <linux/compat.h> #include <linux/freezer.h> +#include <linux/file.h> #include <linux/uaccess.h> #include <linux/iversion.h> @@ -1053,6 +1054,7 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, ctx->lock_context.open_context = ctx;INIT_LIST_HEAD (&ctx->list); ctx->mdsthreshold =NULL ; + ctx->local_filp =NULL ;return ctx; }EXPORT_SYMBOL_GPL (alloc_nfs_open_context);@@ -1084,6 +1086,8 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)nfs_sb_deactive (sb);put_rpccred (rcu_dereference_protected (ctx->ll_cred,1 ));kfree (ctx->mdsthreshold); +if (!IS_ERR_OR_NULL (ctx->local_filp)) +fput (ctx->local_filp);kfree_rcu (ctx, rcu_head); }fs/nfs/internal.h +51
-0@@ -451,6 +451,57 @@ extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);extern bool nfs_check_cache_invalid (struct inode *,unsigned long );extern int nfs_wait_bit_killable (struct wait_bit_key *key,int mode); +#if IS_ENABLED (CONFIG_NFS_LOCALIO ) +/* localio.c */ +extern void nfs_local_disable (struct nfs_client *); +extern void nfs_local_probe (struct nfs_client *); +extern struct file *nfs_local_open_fh (struct nfs_client *,const struct cred *, +struct nfs_fh *,const fmode_t ); +extern struct file *nfs_local_file_open (struct nfs_client *clp, +const struct cred *cred, +struct nfs_fh *fh, +struct nfs_open_context *ctx); +extern int nfs_local_doio (struct nfs_client *,struct file *, +struct nfs_pgio_header *, +const struct rpc_call_ops *); +extern int nfs_local_commit (struct file *,struct nfs_commit_data *, +const struct rpc_call_ops *,int ); +extern bool nfs_server_is_local (const struct nfs_client *clp); + +#else +static inline void nfs_local_disable (struct nfs_client *clp) {} +static inline void nfs_local_probe (struct nfs_client *clp) {} +static inline struct file *nfs_local_open_fh (struct nfs_client *clp, +const struct cred *cred, +struct nfs_fh *fh, +const fmode_t mode) +{ +return ERR_PTR (-EINVAL ); +} +static inline struct file *nfs_local_file_open (struct nfs_client *clp, +const struct cred *cred, +struct nfs_fh *fh, +struct nfs_open_context *ctx) +{ +return NULL ; +} +static inline int nfs_local_doio (struct nfs_client *clp,struct file *filep, +struct nfs_pgio_header *hdr, +const struct rpc_call_ops *call_ops) +{ +return -EINVAL ; +} +static inline int nfs_local_commit (struct file *filep,struct nfs_commit_data *data, +const struct rpc_call_ops *call_ops,int how) +{ +return -EINVAL ; +} +static inline bool nfs_server_is_local (const struct nfs_client *clp) +{ +return false; +} +#endif /* CONFIG_NFS_LOCALIO */ +/* super.c */ extern const struct super_operations nfs_sops;bool nfs_auth_info_match (const struct nfs_auth_info *,rpc_authflavor_t );fs/nfs/localio.c new file +248
-0@@ -0,0 +1,722 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* NFS client support for local clients to bypass network stack +* +* Copyright (C) 2014 Weston Andros Adamson <[email protected]> +* Copyright (C) 2019 Trond Myklebust <[email protected]> +* Copyright (C) 2024 Mike Snitzer <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/vfs.h> +#include <linux/file.h> +#include <linux/inet.h> +#include <linux/sunrpc/addr.h> +#include <linux/inetdevice.h> +#include <net/addrconf.h> +#include <linux/module.h> +#include <linux/bvec.h> + +#include <linux/nfs.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_xdr.h> + +#include "internal.h" +#include "pnfs.h" +#include "nfstrace.h" + +#define NFSDBG_FACILITY NFSDBG_VFS + +struct nfs_local_kiocb { +struct kiocb kiocb; +struct bio_vec *bvec; +struct nfs_pgio_header *hdr; +struct work_struct work; +}; + +struct nfs_local_fsync_ctx { +struct file *filp; +struct nfs_commit_data *data; +struct work_struct work; +struct kref kref; +struct completion *done; +}; +static void nfs_local_fsync_work (struct work_struct *work); + +/* +* We need to translate between nfs status return values and +* the local errno values which may not be the same. +*/ +static struct { +__u32 stat; +int errno; +} nfs_errtbl[] = { + {NFS4_OK ,0 }, + {NFS4ERR_PERM , -EPERM }, + {NFS4ERR_NOENT , -ENOENT }, + {NFS4ERR_IO , -EIO }, + {NFS4ERR_NXIO , -ENXIO }, + {NFS4ERR_FBIG , -E2BIG }, + {NFS4ERR_STALE , -EBADF }, + {NFS4ERR_ACCESS , -EACCES }, + {NFS4ERR_EXIST , -EEXIST }, + {NFS4ERR_XDEV , -EXDEV }, + {NFS4ERR_MLINK , -EMLINK }, + {NFS4ERR_NOTDIR , -ENOTDIR }, + {NFS4ERR_ISDIR , -EISDIR }, + {NFS4ERR_INVAL , -EINVAL }, + {NFS4ERR_FBIG , -EFBIG }, + {NFS4ERR_NOSPC , -ENOSPC }, + {NFS4ERR_ROFS , -EROFS }, + {NFS4ERR_NAMETOOLONG , -ENAMETOOLONG }, + {NFS4ERR_NOTEMPTY , -ENOTEMPTY }, + {NFS4ERR_DQUOT , -EDQUOT }, + {NFS4ERR_STALE , -ESTALE }, + {NFS4ERR_STALE , -EOPENSTALE }, + {NFS4ERR_DELAY , -ETIMEDOUT }, + {NFS4ERR_DELAY , -ERESTARTSYS }, + {NFS4ERR_DELAY , -EAGAIN }, + {NFS4ERR_DELAY , -ENOMEM }, + {NFS4ERR_IO , -ETXTBSY }, + {NFS4ERR_IO , -EBUSY }, + {NFS4ERR_BADHANDLE , -EBADHANDLE }, + {NFS4ERR_BAD_COOKIE , -EBADCOOKIE }, + {NFS4ERR_NOTSUPP , -EOPNOTSUPP }, + {NFS4ERR_TOOSMALL , -ETOOSMALL }, + {NFS4ERR_SERVERFAULT , -ESERVERFAULT }, + {NFS4ERR_SERVERFAULT , -ENFILE }, + {NFS4ERR_IO , -EREMOTEIO }, + {NFS4ERR_IO , -EUCLEAN }, + {NFS4ERR_PERM , -ENOKEY }, + {NFS4ERR_BADTYPE , -EBADTYPE }, + {NFS4ERR_SYMLINK , -ELOOP }, + {NFS4ERR_DEADLOCK , -EDEADLK }, +}; + +/* +* Convert an NFS error code to a local one. +* This one is used jointly by NFSv2 and NFSv3. +*/ +static __u32 +nfs4errno (int errno) +{ +unsigned int i; +for (i =0 ; i <ARRAY_SIZE (nfs_errtbl); i++) { +if (nfs_errtbl[i].errno == errno) +return nfs_errtbl[i].stat; + } +/* If we cannot translate the error, the recovery routines should +* handle it. +* Note: remaining NFSv4 error codes have values > 10000, so should +* not conflict with native Linux error codes. +*/ +return NFS4ERR_SERVERFAULT ; +} + +static bool localio_enabled__read_mostly = true; +module_param (localio_enabled, bool,0644 ); + +bool nfs_server_is_local (const struct nfs_client *clp) +{ +return test_bit (NFS_CS_LOCAL_IO , &clp->cl_flags) !=0 && + localio_enabled; +} +EXPORT_SYMBOL_GPL (nfs_server_is_local); + +/* +* nfs_local_enable - attempt to enable local i/o for an nfs_client +*/ +static void nfs_local_enable (struct nfs_client *clp,struct net *net) +{ +if (READ_ONCE (clp->nfsd_open_local_fh)) { +set_bit (NFS_CS_LOCAL_IO , &clp->cl_flags); + clp->cl_nfssvc_net = net; +trace_nfs_local_enable (clp); + } +} + +/* +* nfs_local_disable - disable local i/o for an nfs_client +*/ +void nfs_local_disable (struct nfs_client *clp) +{ +if (test_and_clear_bit (NFS_CS_LOCAL_IO , &clp->cl_flags)) { +trace_nfs_local_disable (clp); + clp->cl_nfssvc_net =NULL ; + } +} + +/* +* nfs_local_probe - probe local i/o support for an nfs_client +*/ +void +nfs_local_probe (struct nfs_client *clp) +{ +bool enable = false; + +if (enable) +nfs_local_enable (clp); +} +EXPORT_SYMBOL_GPL (nfs_local_probe); + +/* +* nfs_local_open_fh - open a local filehandle +* +* Returns a pointer to a struct file or an ERR_PTR +*/ +struct file * +nfs_local_open_fh (struct nfs_client *clp,const struct cred *cred, +struct nfs_fh *fh,const fmode_t mode) +{ +struct file *filp; +int status; + +if (mode & ~(FMODE_READ |FMODE_WRITE )) +return ERR_PTR (-EINVAL ); + + status = clp->nfsd_open_local_fh (clp->cl_nfssvc_net, clp->cl_rpcclient, + cred, fh, mode, &filp); +if (status <0 ) { +dprintk ("%s: open local file failed error=%d\n" , + __func__, status); +trace_nfs_local_open_fh (fh, mode, status); +switch (status) { +case -ENXIO : +nfs_local_disable (clp); + fallthrough; +case -ETIMEDOUT : + status = -EAGAIN ; + } + filp =ERR_PTR (status); + } +return filp; +} +EXPORT_SYMBOL_GPL (nfs_local_open_fh); + +static struct bio_vec * +nfs_bvec_alloc_and_import_pagevec (struct page **pagevec, +unsigned int npages,gfp_t flags) +{ +struct bio_vec *bvec, *p; + + bvec =kmalloc_array (npages,sizeof (*bvec), flags); +if (bvec !=NULL ) { +for (p = bvec; npages >0 ; p++, pagevec++, npages--) { + p->bv_page = *pagevec; + p->bv_len =PAGE_SIZE ; + p->bv_offset =0 ; + } + } +return bvec; +} + +static void +nfs_local_iocb_free (struct nfs_local_kiocb *iocb) +{ +kfree (iocb->bvec); +kfree (iocb); +} + +static struct nfs_local_kiocb * +nfs_local_iocb_alloc (struct nfs_pgio_header *hdr,struct file *filp, +gfp_t flags) +{ +struct nfs_local_kiocb *iocb; + + iocb =kmalloc (sizeof (*iocb), flags); +if (iocb ==NULL ) +return NULL ; + iocb->bvec =nfs_bvec_alloc_and_import_pagevec (hdr->page_array.pagevec, + hdr->page_array.npages, flags); +if (iocb->bvec ==NULL ) { +kfree (iocb); +return NULL ; + } +init_sync_kiocb (&iocb->kiocb, filp); + iocb->kiocb.ki_pos = hdr->args.offset; + iocb->hdr = hdr; +/* FIXME: NFS_IOHDR_ODIRECT isn't ever set */ +if (test_bit (NFS_IOHDR_ODIRECT , &hdr->flags)) + iocb->kiocb.ki_flags |=IOCB_DIRECT |IOCB_DSYNC ; + iocb->kiocb.ki_flags &= ~IOCB_APPEND ; +return iocb; +} + +static void +nfs_local_iter_init (struct iov_iter *i,struct nfs_local_kiocb *iocb,int dir) +{
fs/nfs/localio.c line 258
Quoted 10 lines
fs/nfs/localio.c new file +10
-0+struct nfs_pgio_header *hdr = iocb->hdr; + +if (hdr->args.pgbase !=0 ) { +iov_iter_bvec (i, dir, iocb->bvec, + hdr->page_array.npages, + hdr->args.count + hdr->args.pgbase); +iov_iter_advance (i, hdr->args.pgbase); + }else +iov_iter_bvec (i, dir, iocb->bvec, + hdr->page_array.npages, hdr->args.count);
Both branches of this if() do exactly the same thing. iov_iter_advance is a no-op if the size arg is zero.
Is it really worth increasing the code size to sometimes avoid a function call?
At least we should for the iov_iter_bvec() inconditionally, then maybe call _advance().
Quoted 46 lines
fs/nfs/localio.c new file +46
-0+} + +static void +nfs_local_hdr_release (struct nfs_pgio_header *hdr, +const struct rpc_call_ops *call_ops) +{ + call_ops->rpc_call_done (&hdr->task, hdr); + call_ops->rpc_release (hdr); +} + +static void +nfs_local_pgio_init (struct nfs_pgio_header *hdr, +const struct rpc_call_ops *call_ops) +{ + hdr->task.tk_ops = call_ops; +if (!hdr->task.tk_start) + hdr->task.tk_start =ktime_get (); +} + +static void +nfs_local_pgio_done (struct nfs_pgio_header *hdr,long status) +{ +if (status >=0 ) { + hdr->res.count = status; + hdr->res.op_status =NFS4_OK ; + hdr->task.tk_status =0 ; + }else { + hdr->res.op_status =nfs4errno (status); + hdr->task.tk_status = status; + } +} + +static void +nfs_local_pgio_release (struct nfs_local_kiocb *iocb) +{ +struct nfs_pgio_header *hdr = iocb->hdr; + +fput (iocb->kiocb.ki_filp); +nfs_local_iocb_free (iocb); +nfs_local_hdr_release (hdr, hdr->task.tk_ops); +} + +static void +nfs_local_read_aio_complete_work (struct work_struct *work) +{ + struct nfs_local_kiocb *iocb = container_of(work,
fs/nfs/localio.c line 314
Quoted 10 lines
fs/nfs/localio.c new file +10
-0+ struct nfs_local_kiocb, work); + +nfs_local_pgio_release (iocb); +} + +/* +* Complete the I/O from iocb->kiocb.ki_complete() +* +* Note that this function can be called from a bottom half context, +* hence we need to queue the fput() etc to a workqueue
fput() is not a good excuse for a workqueue - the work is always deferred either to a workqueue or to a process return-from-syscall context.
However the ->rpc_call_done() and vfs_fsync_range() calls are excellent justification for a workqueue.
So I think the comment should be improved, but the code looks sensible.
Quoted 116 lines
fs/nfs/localio.c new file +116
-0+*/ +static void +nfs_local_pgio_complete (struct nfs_local_kiocb *iocb) +{ +queue_work (nfsiod_workqueue, &iocb->work); +} + +static void +nfs_local_read_done (struct nfs_local_kiocb *iocb,long status) +{ +struct nfs_pgio_header *hdr = iocb->hdr; +struct file *filp = iocb->kiocb.ki_filp; + +nfs_local_pgio_done (hdr, status); + +if (hdr->res.count != hdr->args.count || + hdr->args.offset + hdr->res.count >=i_size_read (file_inode (filp))) + hdr->res.eof = true; + +dprintk ("%s: read %ld bytes eof %d.\n" , __func__, + status >0 ? status :0 , hdr->res.eof); +} + +static void +nfs_local_read_aio_complete (struct kiocb *kiocb,long ret) +{ +struct nfs_local_kiocb *iocb =container_of (kiocb, + struct nfs_local_kiocb, kiocb); + +nfs_local_read_done (iocb, ret); +nfs_local_pgio_complete (iocb); +} + +static int +nfs_do_local_read (struct nfs_pgio_header *hdr,struct file *filp, +const struct rpc_call_ops *call_ops) +{ +struct nfs_local_kiocb *iocb; +struct iov_iter iter; +ssize_t status; + +dprintk ("%s: vfs_read count=%u pos=%llu\n" , + __func__, hdr->args.count, hdr->args.offset); + + iocb =nfs_local_iocb_alloc (hdr, filp,GFP_KERNEL ); +if (iocb ==NULL ) +return -ENOMEM ; +nfs_local_iter_init (&iter, iocb,READ ); + +nfs_local_pgio_init (hdr, call_ops); + hdr->res.eof = false; + +if (iocb->kiocb.ki_flags &IOCB_DIRECT ) { +INIT_WORK (&iocb->work, nfs_local_read_aio_complete_work); + iocb->kiocb.ki_complete = nfs_local_read_aio_complete; + } + + status = filp->f_op->read_iter (&iocb->kiocb, &iter); +if (status != -EIOCBQUEUED ) { +nfs_local_read_done (iocb, status); +nfs_local_pgio_release (iocb); + } +return 0 ; +} + +static void +nfs_copy_boot_verifier (struct nfs_write_verifier *verifier,struct inode *inode) +{ +struct nfs_client *clp =NFS_SERVER (inode)->nfs_client; +u32 *verf = (u32 *)verifier->data; +int seq =0 ; + +do { +read_seqbegin_or_lock (&clp->cl_boot_lock, &seq); + verf[0 ] = (u32 )clp->cl_nfssvc_boot.tv_sec; + verf[1 ] = (u32 )clp->cl_nfssvc_boot.tv_nsec; + }while (need_seqretry (&clp->cl_boot_lock, seq)); +done_seqretry (&clp->cl_boot_lock, seq); +} + +static void +nfs_reset_boot_verifier (struct inode *inode) +{ +struct nfs_client *clp =NFS_SERVER (inode)->nfs_client; + +write_seqlock (&clp->cl_boot_lock); +ktime_get_real_ts64 (&clp->cl_nfssvc_boot); +write_sequnlock (&clp->cl_boot_lock); +} + +static void +nfs_set_local_verifier (struct inode *inode, +struct nfs_writeverf *verf, +enum nfs3_stable_how how) +{ + +nfs_copy_boot_verifier (&verf->verifier, inode); + verf->committed = how; +} + +static void +nfs_get_vfs_attr (struct file *filp,struct nfs_fattr *fattr) +{ +struct kstat stat; + +if (fattr !=NULL &&vfs_getattr (&filp->f_path, &stat, +STATX_INO | +STATX_ATIME | +STATX_MTIME | +STATX_CTIME | +STATX_SIZE | +STATX_BLOCKS , +AT_STATX_SYNC_AS_STAT ) ==0 ) { + fattr->valid =NFS_ATTR_FATTR_FILEID | +NFS_ATTR_FATTR_CHANGE | + NFS_ATTR_FATTR_SIZE |
fs/nfs/localio.c line 440
Quoted 10 lines
fs/nfs/localio.c new file +10
-0+NFS_ATTR_FATTR_ATIME | +NFS_ATTR_FATTR_MTIME | +NFS_ATTR_FATTR_CTIME | +NFS_ATTR_FATTR_SPACE_USED ; + fattr->fileid = stat.ino; + fattr->size = stat.size; + fattr->atime = stat.atime; + fattr->mtime = stat.mtime; + fattr->ctime = stat.ctime; + fattr->change_attr =nfs_timespec_to_change_attr (&fattr->ctime);
This looks wrong for NFSv4. I think we should use nfsd4_change_attribute().
Maybe it isn't important, but if it isn't I'd like to see an explanation why.
Quoted 762 lines
fs/nfs/localio.c new file +282
-0+ fattr->du.nfs3.used = stat.blocks <<9 ; + } +} + +static void +nfs_local_write_done (struct nfs_local_kiocb *iocb,long status) +{ +struct nfs_pgio_header *hdr = iocb->hdr; + +dprintk ("%s: wrote %ld bytes.\n" , __func__, status >0 ? status :0 ); + +/* Handle short writes as if they are ENOSPC */ +if (status >0 && status < hdr->args.count) { + hdr->mds_offset += status; + hdr->args.offset += status; + hdr->args.pgbase += status; + hdr->args.count -= status; +nfs_set_pgio_error (hdr, -ENOSPC , hdr->args.offset); + status = -ENOSPC ; + } +if (status <0 ) +nfs_reset_boot_verifier (hdr->inode); +nfs_local_pgio_done (hdr, status); +} + +static void +nfs_local_write_aio_complete_work (struct work_struct *work) +{ +struct nfs_local_kiocb *iocb =container_of (work, + struct nfs_local_kiocb, work); + +nfs_get_vfs_attr (iocb->kiocb.ki_filp, iocb->hdr->res.fattr); +nfs_local_pgio_release (iocb); +} + +static void +nfs_local_write_aio_complete (struct kiocb *kiocb,long ret) +{ +struct nfs_local_kiocb *iocb =container_of (kiocb, + struct nfs_local_kiocb, kiocb); + +nfs_local_write_done (iocb, ret); +nfs_local_pgio_complete (iocb); +} + +static int +nfs_do_local_write (struct nfs_pgio_header *hdr,struct file *filp, +const struct rpc_call_ops *call_ops) +{ +struct nfs_local_kiocb *iocb; +struct iov_iter iter; +ssize_t status; + +dprintk ("%s: vfs_write count=%u pos=%llu %s\n" , + __func__, hdr->args.count, hdr->args.offset, + (hdr->args.stable ==NFS_UNSTABLE ) ?"unstable" :"stable" ); + + iocb =nfs_local_iocb_alloc (hdr, filp,GFP_NOIO ); +if (iocb ==NULL ) +return -ENOMEM ; +nfs_local_iter_init (&iter, iocb,WRITE ); + +switch (hdr->args.stable) { +default : +break ; +case NFS_DATA_SYNC : + iocb->kiocb.ki_flags |=IOCB_DSYNC ; +break ; +case NFS_FILE_SYNC : + iocb->kiocb.ki_flags |=IOCB_DSYNC |IOCB_SYNC ; + } +nfs_local_pgio_init (hdr, call_ops); + +if (iocb->kiocb.ki_flags &IOCB_DIRECT ) { +INIT_WORK (&iocb->work, nfs_local_write_aio_complete_work); + iocb->kiocb.ki_complete = nfs_local_write_aio_complete; + } + +nfs_set_local_verifier (hdr->inode, hdr->res.verf, hdr->args.stable); + +file_start_write (filp); + status = filp->f_op->write_iter (&iocb->kiocb, &iter); +file_end_write (filp); +if (status != -EIOCBQUEUED ) { +nfs_local_write_done (iocb, status); +nfs_get_vfs_attr (filp, hdr->res.fattr); +nfs_local_pgio_release (iocb); + } +return 0 ; +} + +static struct file * +nfs_local_file_open_cached (struct nfs_client *clp,const struct cred *cred, +struct nfs_fh *fh,struct nfs_open_context *ctx) +{ +struct file *filp = ctx->local_filp; + +if (!filp) { +struct file *new =nfs_local_open_fh (clp, cred, fh, ctx->mode); +if (IS_ERR_OR_NULL (new)) +return NULL ; +/* try to put this one in the slot */ + filp =cmpxchg (&ctx->local_filp,NULL , new); +if (filp !=NULL ) +fput (new); +else + filp = new; + } +return get_file (filp); +} + +struct file * +nfs_local_file_open (struct nfs_client *clp,const struct cred *cred, +struct nfs_fh *fh,struct nfs_open_context *ctx) +{ +if (!nfs_server_is_local (clp)) +return NULL ; +return nfs_local_file_open_cached (clp, cred, fh, ctx); +} + +int +nfs_local_doio (struct nfs_client *clp,struct file *filp, +struct nfs_pgio_header *hdr, +const struct rpc_call_ops *call_ops) +{ +int status =0 ; + +if (!hdr->args.count) + goto out_fput; +/* Don't support filesystems without read_iter/write_iter */ +if (!filp->f_op->read_iter || !filp->f_op->write_iter) { +nfs_local_disable (clp); + status = -EAGAIN ; + goto out_fput; + } + +switch (hdr->rw_mode) { +case FMODE_READ : + status =nfs_do_local_read (hdr, filp, call_ops); +break ; +case FMODE_WRITE : + status =nfs_do_local_write (hdr, filp, call_ops); +break ; +default : +dprintk ("%s: invalid mode: %d\n" , __func__, + hdr->rw_mode); + status = -EINVAL ; + } +out_fput: +if (status !=0 ) { +fput (filp); + hdr->task.tk_status = status; +nfs_local_hdr_release (hdr, call_ops); + } +return status; +} + +static void +nfs_local_init_commit (struct nfs_commit_data *data, +const struct rpc_call_ops *call_ops) +{ + data->task.tk_ops = call_ops; +} + +static int +nfs_local_run_commit (struct file *filp,struct nfs_commit_data *data) +{ +loff_t start = data->args.offset; +loff_t end =LLONG_MAX ; + +if (data->args.count >0 ) { + end = start + data->args.count -1 ; +if (end < start) + end =LLONG_MAX ; + } + +dprintk ("%s: commit %llu - %llu\n" , __func__, start, end); +return vfs_fsync_range (filp, start, end,0 ); +} + +static void +nfs_local_commit_done (struct nfs_commit_data *data,int status) +{ +if (status >=0 ) { +nfs_set_local_verifier (data->inode, + data->res.verf, +NFS_FILE_SYNC ); + data->res.op_status =NFS4_OK ; + data->task.tk_status =0 ; + }else { +nfs_reset_boot_verifier (data->inode); + data->res.op_status =nfs4errno (status); + data->task.tk_status = status; + } +} + +static void +nfs_local_release_commit_data (struct file *filp, +struct nfs_commit_data *data, +const struct rpc_call_ops *call_ops) +{ +fput (filp); + call_ops->rpc_call_done (&data->task, data); + call_ops->rpc_release (data); +} + +static struct nfs_local_fsync_ctx * +nfs_local_fsync_ctx_alloc (struct nfs_commit_data *data,struct file *filp, +gfp_t flags) +{ +struct nfs_local_fsync_ctx *ctx =kmalloc (sizeof (*ctx), flags); + +if (ctx !=NULL ) { + ctx->filp = filp; + ctx->data = data; +INIT_WORK (&ctx->work, nfs_local_fsync_work); +kref_init (&ctx->kref); + ctx->done =NULL ; + } +return ctx; +} + +static void +nfs_local_fsync_ctx_kref_free (struct kref *kref) +{ +kfree (container_of(kref ,struct nfs_local_fsync_ctx ,kref )); +} + +static void +nfs_local_fsync_ctx_put (struct nfs_local_fsync_ctx *ctx) +{ +kref_put (&ctx->kref, nfs_local_fsync_ctx_kref_free); +} + +static void +nfs_local_fsync_ctx_free (struct nfs_local_fsync_ctx *ctx) +{ +nfs_local_release_commit_data (ctx->filp, ctx->data, + ctx->data->task.tk_ops); +nfs_local_fsync_ctx_put (ctx); +} + +static void +nfs_local_fsync_work (struct work_struct *work) +{ +struct nfs_local_fsync_ctx *ctx; +int status; + + ctx = container_of(work, struct nfs_local_fsync_ctx, work); + + status =nfs_local_run_commit (ctx->filp, ctx->data); +nfs_local_commit_done (ctx->data, status); +if (ctx->done !=NULL ) +complete (ctx->done); +nfs_local_fsync_ctx_free (ctx); +} + +int +nfs_local_commit (struct file *filp,struct nfs_commit_data *data, +const struct rpc_call_ops *call_ops,int how) +{ +struct nfs_local_fsync_ctx *ctx; + + ctx =nfs_local_fsync_ctx_alloc (data, filp,GFP_KERNEL ); +if (!ctx) { +nfs_local_commit_done (data, -ENOMEM ); +nfs_local_release_commit_data (filp, data, call_ops); +return -ENOMEM ; + } + +nfs_local_init_commit (data, call_ops); +kref_get (&ctx->kref); +if (how &FLUSH_SYNC ) { +DECLARE_COMPLETION_ONSTACK (done); + ctx->done = &done; +queue_work (nfsiod_workqueue, &ctx->work); +wait_for_completion (&done); + }else +queue_work (nfsiod_workqueue, &ctx->work); +nfs_local_fsync_ctx_put (ctx); +return 0 ; +}fs/nfs/nfstrace.h +61
-0@@ -1681,6 +1681,67 @@ TRACE_EVENT(nfs_mount_path,TP_printk ("path='%s'" ,__get_str (path)) ); +TRACE_EVENT (nfs_local_open_fh, +TP_PROTO ( + const struct nfs_fh *fh, + fmode_t fmode, + int error + ), + +TP_ARGS (fh, fmode, error), + +TP_STRUCT__entry ( + __field(int, error) + __field(u32, fhandle) + __field(unsigned int, fmode) + ), + +TP_fast_assign ( + __entry->error = error; + __entry->fhandle = nfs_fhandle_hash(fh); + __entry->fmode = (__force unsigned int)fmode; + ), + +TP_printk ( +"error=%d fhandle=0x%08x mode=%s" , + __entry->error, + __entry->fhandle, +show_fs_fmode_flags (__entry->fmode) + ) +); + +DECLARE_EVENT_CLASS (nfs_local_client_event, +TP_PROTO ( + const struct nfs_client *clp + ), + +TP_ARGS (clp), + +TP_STRUCT__entry ( + __field(unsigned int, protocol) +__string (server, clp->cl_hostname) + ), + +TP_fast_assign ( + __entry->protocol = clp->rpc_ops->version; + __assign_str(server); + ), + +TP_printk ( +"server=%s NFSv%u" ,__get_str (server), __entry->protocol + ) +); + +#define DEFINE_NFS_LOCAL_CLIENT_EVENT (name) \ + DEFINE_EVENT(nfs_local_client_event, name, \ + TP_PROTO( \ + const struct nfs_client *clp \ + ), \ + TP_ARGS(clp)) + +DEFINE_NFS_LOCAL_CLIENT_EVENT (nfs_local_enable); +DEFINE_NFS_LOCAL_CLIENT_EVENT (nfs_local_disable); + DECLARE_EVENT_CLASS(nfs_xdr_event, TP_PROTO( const struct xdr_stream *xdr,fs/nfs/pagelist.c +3
-0@@ -879,6 +879,9 @@ int nfs_initiate_pgio(struct nfs_pageio_descriptor *desc, hdr->args.count, (unsigned long long)hdr->args.offset); +if (localio) +return nfs_local_doio (clp, localio, hdr, call_ops); + task =rpc_run_task (&task_setup_data);if (IS_ERR (task))return PTR_ERR (task);fs/nfs/write.c +3
-0@@ -1700,6 +1700,9 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,dprintk ("NFS: initiated commit call\n" ); +if (localio) +return nfs_local_commit (localio, data, call_ops, how); + task =rpc_run_task (&task_setup_data);if (IS_ERR (task))return PTR_ERR (task);fs/nfsd/Makefile +1
-0@@ -23,3 +23,4 @@ nfsd-$(CONFIG_NFSD_PNFS) += nfs4layouts.o nfsd-$(CONFIG_NFSD_BLOCKLAYOUT) += blocklayout.o blocklayoutxdr.o nfsd-$(CONFIG_NFSD_SCSILAYOUT) += blocklayout.o blocklayoutxdr.o nfsd-$(CONFIG_NFSD_FLEXFILELAYOUT) += flexfilelayout.o flexfilelayoutxdr.o +nfsd-$(CONFIG_NFSD_LOCALIO) += localio.ofs/nfsd/filecache.c +1
-1@@ -52,7 +52,7 @@#define NFSD_FILE_CACHE_UP (0)/* We only care about NFSD_MAY_READ/WRITE for this cache */ -#define NFSD_FILE_MAY_MASK (NFSD_MAY_READ|NFSD_MAY_WRITE) +#define NFSD_FILE_MAY_MASK (NFSD_MAY_READ|NFSD_MAY_WRITE|NFSD_MAY_LOCALIO) static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits); static DEFINE_PER_CPU(unsigned long, nfsd_file_acquisitions);fs/nfsd/localio.c new file +244
-0@@ -0,0 +1,244 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* NFS server support for local clients to bypass network stack +* +* Copyright (C) 2014 Weston Andros Adamson <[email protected]> +* Copyright (C) 2019 Trond Myklebust <[email protected]> +* Copyright (C) 2024 Mike Snitzer <[email protected]> +*/ + +#include <linux/exportfs.h> +#include <linux/sunrpc/svcauth_gss.h> +#include <linux/sunrpc/clnt.h> +#include <linux/nfs.h> +#include <linux/string.h> + +#include "nfsd.h" +#include "vfs.h" +#include "netns.h" +#include "filecache.h" + +#define NFSDDBG_FACILITY NFSDDBG_FH + +/* +* We need to translate between nfs status return values and +* the local errno values which may not be the same. +* - duplicated from fs/nfs/nfs2xdr.c to avoid needless bloat of +* all compiled nfs objects if it were in include/linux/nfs.h +*/ +static const struct { +int stat; +int errno; +} nfs_common_errtbl[] = { + {NFS_OK ,0 }, + {NFSERR_PERM , -EPERM }, + {NFSERR_NOENT , -ENOENT }, + {NFSERR_IO , -EIO }, + {NFSERR_NXIO , -ENXIO }, +/* { NFSERR_EAGAIN, -EAGAIN }, */ + {NFSERR_ACCES , -EACCES }, + {NFSERR_EXIST , -EEXIST }, + {NFSERR_XDEV , -EXDEV }, + {NFSERR_NODEV , -ENODEV }, + {NFSERR_NOTDIR , -ENOTDIR }, + {NFSERR_ISDIR , -EISDIR }, + {NFSERR_INVAL , -EINVAL }, + {NFSERR_FBIG , -EFBIG }, + {NFSERR_NOSPC , -ENOSPC }, + {NFSERR_ROFS , -EROFS }, + {NFSERR_MLINK , -EMLINK }, + {NFSERR_NAMETOOLONG , -ENAMETOOLONG }, + {NFSERR_NOTEMPTY , -ENOTEMPTY }, + {NFSERR_DQUOT , -EDQUOT }, + {NFSERR_STALE , -ESTALE }, + {NFSERR_REMOTE , -EREMOTE }, +#ifdef EWFLUSH + {NFSERR_WFLUSH , -EWFLUSH }, +#endif + {NFSERR_BADHANDLE , -EBADHANDLE }, + {NFSERR_NOT_SYNC , -ENOTSYNC }, + {NFSERR_BAD_COOKIE , -EBADCOOKIE }, + {NFSERR_NOTSUPP , -ENOTSUPP }, + {NFSERR_TOOSMALL , -ETOOSMALL }, + {NFSERR_SERVERFAULT , -EREMOTEIO }, + {NFSERR_BADTYPE , -EBADTYPE }, + {NFSERR_JUKEBOX , -EJUKEBOX }, + {-1 , -EIO } +}; + +/** +* nfs_stat_to_errno - convert an NFS status code to a local errno +* @status: NFS status code to convert +* +* Returns a local errno value, or -EIO if the NFS status code is +* not recognized. This function is used jointly by NFSv2 and NFSv3. +*/ +static int nfs_stat_to_errno (enum nfs_stat status) +{ +int i; + +for (i =0 ; nfs_common_errtbl[i].stat !=-1 ; i++) { +if (nfs_common_errtbl[i].stat == (int )status) +return nfs_common_errtbl[i].errno; + } +return nfs_common_errtbl[i].errno; +} + +static void +nfsd_local_fakerqst_destroy (struct svc_rqst *rqstp) +{ +if (rqstp->rq_client) +auth_domain_put (rqstp->rq_client); +if (rqstp->rq_cred.cr_group_info) +put_group_info (rqstp->rq_cred.cr_group_info); +/* rpcauth_map_to_svc_cred_local() clears cr_principal */ +WARN_ON_ONCE (rqstp->rq_cred.cr_principal !=NULL ); +kfree (rqstp->rq_xprt); +kfree (rqstp); +} + +static struct svc_rqst * +nfsd_local_fakerqst_create (struct net *net,struct rpc_clnt *rpc_clnt, +const struct cred *cred) +{ +struct svc_rqst *rqstp; +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +int status; + +/* FIXME: not running in nfsd context, must get reference on nfsd_serv */ +if (unlikely (!READ_ONCE (nn->nfsd_serv))) { +dprintk ("%s: localio denied. Server not running\n" , __func__); +return ERR_PTR (-ENXIO ); + } + + rqstp =kzalloc (sizeof (*rqstp),GFP_KERNEL ); +if (!rqstp) +return ERR_PTR (-ENOMEM ); + + rqstp->rq_xprt =kzalloc (sizeof (*rqstp->rq_xprt),GFP_KERNEL ); +if (!rqstp->rq_xprt) { + status = -ENOMEM ; + goto out_err; + } + + rqstp->rq_xprt->xpt_net = net; +__set_bit (RQ_SECURE , &rqstp->rq_flags); + rqstp->rq_proc =1 ; + rqstp->rq_vers =3 ; + rqstp->rq_prot =IPPROTO_TCP ; + rqstp->rq_server = nn->nfsd_serv; + +/* Note: we're connecting to ourself, so source addr == peer addr */ + rqstp->rq_addrlen =rpc_peeraddr (rpc_clnt, + (struct sockaddr *)&rqstp->rq_addr, +sizeof (rqstp->rq_addr)); + +rpcauth_map_to_svc_cred_local (rpc_clnt->cl_auth, cred, &rqstp->rq_cred); + +/* +* set up enough for svcauth_unix_set_client to be able to wait +* for the cache downcall. Note that we do _not_ want to allow the +* request to be deferred for later revisit since this rqst and xprt +* are not set up to run inside of the normal svc_rqst engine. +*/ +INIT_LIST_HEAD (&rqstp->rq_xprt->xpt_deferred); +kref_init (&rqstp->rq_xprt->xpt_ref); +spin_lock_init (&rqstp->rq_xprt->xpt_lock); + rqstp->rq_chandle.thread_wait =5 *HZ ; + + status =svcauth_unix_set_client (rqstp); +switch (status) { +case SVC_OK : +break ; +case SVC_DENIED : + status = -ENXIO ; +dprintk ("%s: client %pISpc denied localio access\n" , + __func__, (struct sockaddr *)&rqstp->rq_addr); + goto out_err; +default : + status = -ETIMEDOUT ; +dprintk ("%s: client %pISpc temporarily denied localio access\n" , + __func__, (struct sockaddr *)&rqstp->rq_addr); + goto out_err; + } + +return rqstp; + +out_err: +nfsd_local_fakerqst_destroy (rqstp); +return ERR_PTR (status); +} + +/* +* nfsd_open_local_fh - lookup a local filehandle @nfs_fh and map to @file +* +* This function maps a local fh to a path on a local filesystem. +* This is useful when the nfs client has the local server mounted - it can +* avoid all the NFS overhead with reads, writes and commits. +* +* on successful return, caller is responsible for calling path_put. Also +* note that this is called from nfs.ko via find_symbol() to avoid an explicit +* dependency on knfsd. So, there is no forward declaration in a header file +* for it. +*/ +int nfsd_open_local_fh (struct net *net, +struct rpc_clnt *rpc_clnt, +const struct cred *cred, +const struct nfs_fh *nfs_fh, +const fmode_t fmode, +struct file **pfilp) +{ +const struct cred *save_cred; +struct svc_rqst *rqstp; +struct svc_fh fh; +struct nfsd_file *nf; +int status =0 ; +int mayflags =NFSD_MAY_LOCALIO ; +__be32 beres; + +/* Save creds before calling into nfsd */ + save_cred =get_current_cred (); + + rqstp =nfsd_local_fakerqst_create (net, rpc_clnt, cred); +if (IS_ERR (rqstp)) { + status =PTR_ERR (rqstp); + goto out_revertcred; + } + +/* nfs_fh -> svc_fh */ +if (nfs_fh->size >NFS4_FHSIZE ) { + status = -EINVAL ; + goto out; + } +fh_init (&fh,NFS4_FHSIZE ); + fh.fh_handle.fh_size = nfs_fh->size; +memcpy (fh.fh_handle.fh_raw, nfs_fh->data, nfs_fh->size); + +if (fmode &FMODE_READ ) + mayflags |=NFSD_MAY_READ ; +if (fmode &FMODE_WRITE ) + mayflags |=NFSD_MAY_WRITE ; + + beres =nfsd_file_acquire (rqstp, &fh, mayflags, &nf); +if (beres) { + status =nfs_stat_to_errno (be32_to_cpu (beres)); +dprintk ("%s: fh_verify failed %d\n" , __func__, status); + goto out_fh_put; + } + + *pfilp =get_file (nf->nf_file); + +nfsd_file_put (nf); +out_fh_put: +fh_put (&fh); + +out: +nfsd_local_fakerqst_destroy (rqstp); +out_revertcred: +revert_creds (save_cred); +return status; +} +EXPORT_SYMBOL_GPL (nfsd_open_local_fh); + +/* Compile time type checking, not used by anything */ +static nfs_to_nfsd_open_t __maybe_unused nfsd_open_local_fh_typecheck = nfsd_open_local_fh;fs/nfsd/nfssvc.c +1
-0@@ -431,6 +431,7 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)#endif #if IS_ENABLED (CONFIG_NFSD_LOCALIO )INIT_LIST_HEAD (&nn->nfsd_uuid.list); + nn->nfsd_uuid.net = net;list_add_tail_rcu (&nn->nfsd_uuid.list, &nfsd_uuids);#endif nn->nfsd_net_up = true;fs/nfsd/trace.h +2
-1@@ -86,7 +86,8 @@ DEFINE_NFSD_XDR_ERR_EVENT(cant_encode); { NFSD_MAY_NOT_BREAK_LEASE, "NOT_BREAK_LEASE" }, \ { NFSD_MAY_BYPASS_GSS, "BYPASS_GSS" }, \ { NFSD_MAY_READ_IF_EXEC, "READ_IF_EXEC" }, \ - { NFSD_MAY_64BIT_COOKIE, "64BIT_COOKIE" }) + { NFSD_MAY_64BIT_COOKIE, "64BIT_COOKIE" }, \ + { NFSD_MAY_LOCALIO, "LOCALIO" }) TRACE_EVENT(nfsd_compound, TP_PROTO(fs/nfsd/vfs.h +9
-0@@ -36,6 +36,8 @@#define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE)#define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC) +#define NFSD_MAY_LOCALIO 0x800000 +struct nfsd_file ;/* @@ -158,6 +160,13 @@ __be32 nfsd_permission(struct svc_rqst *, struct svc_export *,void nfsd_filp_close (struct file *fp); +int nfsd_open_local_fh (struct net *net, +struct rpc_clnt *rpc_clnt, +const struct cred *cred, +const struct nfs_fh *nfs_fh, +const fmode_t fmode, +struct file **pfilp); +static inline int fh_want_write (struct svc_fh *fh) {int ret;include/linux/nfs.h +2
-0@@ -8,6 +8,8 @@#ifndef _LINUX_NFS_H#define _LINUX_NFS_H +#include <linux/cred.h> +#include <linux/sunrpc/auth.h> #include <linux/sunrpc/msg_prot.h> #include <linux/string.h> #include <linux/crc32.h> include/linux/nfs_fs.h +2
-0@@ -96,6 +96,8 @@ struct nfs_open_context {struct list_head list;struct nfs4_threshold *mdsthreshold;struct rcu_head rcu_head; + +struct file *local_filp; };struct nfs_open_dir_context {include/linux/nfs_fs_sb.h +1
-0@@ -50,6 +50,7 @@ struct nfs_client {#define NFS_CS_DS 7/* - Server is a DS */ #define NFS_CS_REUSEPORT 8/* - reuse src port on reconnect */ #define NFS_CS_PNFS 9/* - Server used for pnfs */ +#define NFS_CS_LOCAL_IO 10/* - client is local */ struct sockaddr_storage cl_addr;/* server identifier */ size_t cl_addrlen;char * cl_hostname;/* hostname of server */ include/linux/nfs_xdr.h +1
-0@@ -1605,6 +1605,7 @@ enum {NFS_IOHDR_RESEND_PNFS ,NFS_IOHDR_RESEND_MDS ,NFS_IOHDR_UNSTABLE_WRITES , + NFS_IOHDR_ODIRECT, };struct nfs_io_completion ;Signature · 1 line
2.44.0
Thanks,
NeilBrown
Re: [PATCH v6 06/18] nfs/nfsd: add "localio" support
Quoted 52 lines · NeilBrown
Quoted 51 lines · Mike Snitzer
From: Weston Andros Adamson <[email protected]>
Add client support for bypassing NFS for localhost reads, writes, and commits. This is only useful when the client and the server are running on the same host.
nfs_local_probe()is stubbed out, later commits will enable client and server handshake via a Linux-only LOCALIO auxiliary RPC protocol.This has dynamic binding with the nfsd module (via
nfs_localiomodule which is part ofnfs_common). Localio will only work if nfsd is already loaded.The "
localio_enabled" nfs kernel module parameter can be used to disable and enable the ability to use localio support.Tracepoints were added for
nfs_local_open_fh,nfs_local_enableandnfs_local_disable.Also, pass the stored
cl_nfssvc_netfrom the client to the server as first argument tonfsd_open_local_fh()to ensure the proper network namespace is used for localio.Signed-off-by Weston Andros Adamson <[email protected]>Signed-off-by Peng Tao <[email protected]>Signed-off-by Lance Shelton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>Signed-off-by Mike Snitzer <[email protected]>--- fs/nfs/Makefile | 1 + fs/nfs/client.c | 3 + fs/nfs/inode.c | 4 + fs/nfs/internal.h | 51 +++ fs/nfs/localio.c | 722 ++++++++++++++++++++++++++++++++++++++ fs/nfs/nfstrace.h | 61 ++++ fs/nfs/pagelist.c | 3 + fs/nfs/write.c | 3 + fs/nfsd/Makefile | 1 + fs/nfsd/filecache.c | 2 +- fs/nfsd/localio.c | 244 +++++++++++++ fs/nfsd/nfssvc.c | 1 + fs/nfsd/trace.h | 3 +- fs/nfsd/vfs.h | 9 + include/linux/nfs.h | 2 + include/linux/nfs_fs.h | 2 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 1 + 18 files changed, 1112 insertions(+), 2 deletions(-) create mode 100644 fs/nfs/localio.c create mode 100644 fs/nfsd/localio.c
<snip>
Quoted 5 lines
Quoted 5 lines
fs/nfs/localio.c new file +0
-0
<snip>
Quoted 8 lines
Quoted 8 lines
fs/nfs/localio.c new file +8
-0+static void +nfs_local_iter_init (struct iov_iter *i,struct nfs_local_kiocb *iocb,int dir) +{ +struct nfs_pgio_header *hdr = iocb->hdr; + +if (hdr->args.pgbase !=0 ) { + iov_iter_bvec(i, dir, iocb->bvec, + hdr->page_array.npages,
Quoted 8 lines
fs/nfs/localio.c line 258
Quoted 5 lines
fs/nfs/localio.c new file +5
-0+ hdr->args.count + hdr->args.pgbase); +iov_iter_advance (i, hdr->args.pgbase); + }else +iov_iter_bvec (i, dir, iocb->bvec, + hdr->page_array.npages, hdr->args.count);Both branches of this
if()do exactly the same thing.iov_iter_advanceis a no-op if the size arg is zero.
iov_iter_advance doesn't look to be a no-op if the size arg is zero.
Quoted 5 lines
Is it really worth increasing the code size to sometimes avoid a function call?
At least we should for the
iov_iter_bvec()inconditionally, then maybe call_advance().
For v7, I've fixed it so we do what you suggest.
Quoted 6 lines
Quoted 5 lines
+/*
+ * Complete the I/O fromiocb->kiocb.ki_complete()
+ *
+ * Note that this function can be called from a bottom half context,
+ * hence we need to queue thefput()etc to a workqueue
Quoted 6 lines
fput()is not a good excuse for a workqueue - the work is always deferred either to a workqueue or to a process return-from-syscall context.
However the ->rpc_call_done() andvfs_fsync_range()calls are excellent justification for a workqueue.
So I think the comment should be improved, but the code looks sensible.
OK.
Quoted 32 lines
Quoted 16 lines
fs/nfs/localio.c new file +16
-0+static void +nfs_get_vfs_attr (struct file *filp,struct nfs_fattr *fattr) +{ +struct kstat stat; + +if (fattr !=NULL &&vfs_getattr (&filp->f_path, &stat, +STATX_INO | +STATX_ATIME | +STATX_MTIME | +STATX_CTIME | +STATX_SIZE | +STATX_BLOCKS , +AT_STATX_SYNC_AS_STAT ) ==0 ) { + fattr->valid =NFS_ATTR_FATTR_FILEID | +NFS_ATTR_FATTR_CHANGE | + NFS_ATTR_FATTR_SIZE |fs/nfs/localio.c line 440
Quoted 10 lines
fs/nfs/localio.c new file +10
-0+NFS_ATTR_FATTR_ATIME | +NFS_ATTR_FATTR_MTIME | +NFS_ATTR_FATTR_CTIME | +NFS_ATTR_FATTR_SPACE_USED ; + fattr->fileid = stat.ino; + fattr->size = stat.size; + fattr->atime = stat.atime; + fattr->mtime = stat.mtime; + fattr->ctime = stat.ctime; + fattr->change_attr =nfs_timespec_to_change_attr (&fattr->ctime);This looks wrong for NFSv4. I think we should use
nfsd4_change_attribute().
Maybe it isn't important, but if it isn't I'd like to see an explanation why.
Quoted 3 lines
fs/nfs/localio.c line 443
Quoted 3 lines
fs/nfs/localio.c new file +3
-0+ fattr->du.nfs3.used = stat.blocks <<9 ; + } +}
Not following, this is client code so it doesn't have access to nfsd4_change_attribute().
Pending clarification, and further review on my part, leaving this item to one side (so won't be addressed in v7).
Thanks,
Mike
Re: [PATCH v6 06/18] nfs/nfsd: add "localio" support
Quoted 6 lines · Mike Snitzer
Quoted 3 lines · NeilBrown
Both branches of this
if()do exactly the same thing.iov_iter_advanceis a no-op if the size arg is zero.
iov_iter_advancedoesn't look to be a no-op if the size arg is zero.
void iov_iter_advance(struct iov_iter *i, size_t size)
{
if (unlikely(i->count < size))
size = i->count;
if (likely(iter_is_ubuf(i)) || unlikely(iov_iter_is_xarray(i))) {
i->iov_offset += size;
i->count -= size;
} else if (likely(iter_is_iovec(i) || iov_iter_is_kvec(i))) {
/* iovec and kvec have identical layouts */
iov_iter_iovec_advance(i, size);
} else if (iov_iter_is_bvec(i)) {
iov_iter_bvec_advance(i, size);
} else if (iov_iter_is_discard(i)) {
i->count -= size;
}
}This adds "size" to offset, and subtracts "size" from count. For iovec and bvec it is a slightly complicated dance to achieve this, but that is the net result.
So if "size" is zero there is no change to the iov_iter. Just some wasted cycles. Do those cycles justify the extra conditional branch? I don't know. I would generally prefer simpler code which is only optimised with evidence. Admittedly I don't always follow that preference myself and I won't hold you to it. But I thought the review would be incomplete without mentioning it.
Quoted 8 lines
Quoted 6 lines
Is it really worth increasing the code size to sometimes avoid a function call?
At least we should for the
iov_iter_bvec()inconditionally, then maybe call_advance().For v7, I've fixed it so we do what you suggest.
Thanks.
Quoted 32 lines
Quoted 32 lines
Quoted 16 lines
fs/nfs/localio.c new file +16
-0+static void +nfs_get_vfs_attr (struct file *filp,struct nfs_fattr *fattr) +{ +struct kstat stat; + +if (fattr !=NULL &&vfs_getattr (&filp->f_path, &stat, +STATX_INO | +STATX_ATIME | +STATX_MTIME | +STATX_CTIME | +STATX_SIZE | +STATX_BLOCKS , +AT_STATX_SYNC_AS_STAT ) ==0 ) { + fattr->valid =NFS_ATTR_FATTR_FILEID | +NFS_ATTR_FATTR_CHANGE | + NFS_ATTR_FATTR_SIZE |fs/nfs/localio.c line 440
Quoted 10 lines
fs/nfs/localio.c new file +10
-0+NFS_ATTR_FATTR_ATIME | +NFS_ATTR_FATTR_MTIME | +NFS_ATTR_FATTR_CTIME | +NFS_ATTR_FATTR_SPACE_USED ; + fattr->fileid = stat.ino; + fattr->size = stat.size; + fattr->atime = stat.atime; + fattr->mtime = stat.mtime; + fattr->ctime = stat.ctime; + fattr->change_attr =nfs_timespec_to_change_attr (&fattr->ctime);This looks wrong for NFSv4. I think we should use
nfsd4_change_attribute().
Maybe it isn't important, but if it isn't I'd like to see an explanation why.
Quoted 6 lines
Quoted 3 lines
fs/nfs/localio.c line 443
Quoted 3 lines
fs/nfs/localio.c new file +3
-0+ fattr->du.nfs3.used = stat.blocks <<9 ; + } +}Not following, this is client code so it doesn't have access to
nfsd4_change_attribute().
This is nfs-localio code which blurs the boundary between server and client...
The change_attr is used by NFS to detect if a file might have changed. This code is used to get the attributes after a write request. NFS uses a GETATTR request to the server at other times. The change_attr should be consistent between the two else comparisons will be meaningless.
So I think that nfs_get_vfs_attr() should use the same change_attr as the one that would be used if the NFS GETATTR request were made. For NFSv3, that is nfs_timespec_to_change_attr() as you have. For NFSv4 it is something different.
I think that having inconsistent change_attrs could cause NFS to flush its page cache unnecessarily. As it can read directly from the server-side where is likely is cached, that might not be a problem. If that reasoning does apply it should be explained.
However there is talk of exporting the "i_version" number to userspace through xattr. For NFS that is essentially the change_attr. If we did that we would really want to keep the number consistent.
We could easily move nfsd4_change_attribute() into nfs_common or even make it an inline in some common include file. It doesn't use any nfsd internals.
Thanks,
NeilBrown
Quoted 7 lines
Pending clarification, and further review on my part, leaving this item to one side (so won't be addressed in v7).
Thanks,
Mike
Re: [PATCH v6 06/18] nfs/nfsd: add "localio" support
Quoted 25 lines · NeilBrown
Quoted 6 lines · Mike Snitzer
Quoted 3 lines · NeilBrown
Both branches of this
if()do exactly the same thing.iov_iter_advanceis a no-op if the size arg is zero.
iov_iter_advancedoesn't look to be a no-op if the size arg is zero.void
iov_iter_advance(struct iov_iter *i, size_t size){ if (unlikely(i->count < size)) size = i->count; if (likely(iter_is_ubuf(i)) || unlikely(iov_iter_is_xarray(i))) { i->iov_offset += size; i->count -= size; } else if (likely(iter_is_iovec(i) || iov_iter_is_kvec(i))) { /* iovec and kvec have identical layouts */ iov_iter_iovec_advance(i, size); } else if (iov_iter_is_bvec(i)) { iov_iter_bvec_advance(i, size); } else if (iov_iter_is_discard(i)) { i->count -= size; } }
Quoted 9 lines
This adds "size" to offset, and subtracts "size" from count. For iovec and bvec it is a slightly complicated dance to achieve this, but that is the net result.
So if "size" is zero there is no change to theiov_iter. Just some wasted cycles. Do those cycles justify the extra conditional branch? I don't know. I would generally prefer simpler code which is only optimised with evidence. Admittedly I don't always follow that preference myself and I won't hold you to it. But I thought the review would be incomplete without mentioning it.
OK, thanks.
Quoted 58 lines
Quoted 32 lines
Quoted 32 lines
Quoted 16 lines
fs/nfs/localio.c new file +16
-0+static void +nfs_get_vfs_attr (struct file *filp,struct nfs_fattr *fattr) +{ +struct kstat stat; + +if (fattr !=NULL &&vfs_getattr (&filp->f_path, &stat, +STATX_INO | +STATX_ATIME | +STATX_MTIME | +STATX_CTIME | +STATX_SIZE | +STATX_BLOCKS , +AT_STATX_SYNC_AS_STAT ) ==0 ) { + fattr->valid =NFS_ATTR_FATTR_FILEID | +NFS_ATTR_FATTR_CHANGE | + NFS_ATTR_FATTR_SIZE |fs/nfs/localio.c line 440
Quoted 10 lines
fs/nfs/localio.c new file +10
-0+NFS_ATTR_FATTR_ATIME | +NFS_ATTR_FATTR_MTIME | +NFS_ATTR_FATTR_CTIME | +NFS_ATTR_FATTR_SPACE_USED ; + fattr->fileid = stat.ino; + fattr->size = stat.size; + fattr->atime = stat.atime; + fattr->mtime = stat.mtime; + fattr->ctime = stat.ctime; + fattr->change_attr =nfs_timespec_to_change_attr (&fattr->ctime);This looks wrong for NFSv4. I think we should use
nfsd4_change_attribute().
Maybe it isn't important, but if it isn't I'd like to see an explanation why.Quoted 6 lines
Quoted 3 lines
fs/nfs/localio.c line 443
Quoted 3 lines
fs/nfs/localio.c new file +3
-0+ fattr->du.nfs3.used = stat.blocks <<9 ; + } +}Not following, this is client code so it doesn't have access to
nfsd4_change_attribute().This is nfs-localio code which blurs the boundary between server and client...
The
change_attris used by NFS to detect if a file might have changed. This code is used to get the attributes after a write request. NFS uses a GETATTR request to the server at other times. Thechange_attrshould be consistent between the two else comparisons will be meaningless.So I think that
nfs_get_vfs_attr()should use the samechange_attras the one that would be used if the NFS GETATTR request were made. For NFSv3, that isnfs_timespec_to_change_attr()as you have. For NFSv4 it is something different.I think that having inconsistent
change_attrscould cause NFS to flush its page cache unnecessarily. As it can read directly from the server-side where is likely is cached, that might not be a problem. If that reasoning does apply it should be explained.
Quoted 7 lines
However there is talk of exporting the "
i_version" number to userspace through xattr. For NFS that is essentially thechange_attr. If we did that we would really want to keep the number consistent.We could easily move
nfsd4_change_attribute()intonfs_commonor even make it an inline in some common include file. It doesn't use any nfsd internals.
OK, makes sense, thanks for clarifying. I'll fix it for v8.
Mike
PATCH v6 7/18 nfsd/localio: manage netns reference in nfsd_open_local_fh
In reply to Mike SnitzerUse maybe_get_net() and put_net() in nfsd_open_local_fh(). Also refactor nfsd_open_local_fh() slightly.
--- fs/nfsd/localio.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-)
fs/nfsd/localio.c +26 -19
@@ -99,18 +99,11 @@ nfsd_local_fakerqst_destroy(struct svc_rqst *rqstp)static struct svc_rqst *nfsd_local_fakerqst_create (struct net *net,struct rpc_clnt *rpc_clnt, -const struct cred *cred) +const struct cred *cred,struct svc_serv *serv) {struct svc_rqst *rqstp; -struct nfsd_net *nn =net_generic (net, nfsd_net_id);int status; -/* FIXME: not running in nfsd context, must get reference on nfsd_serv */ -if (unlikely (!READ_ONCE (nn->nfsd_serv))) { -dprintk ("%s: localio denied. Server not running\n" , __func__); -return ERR_PTR (-ENXIO ); - } - rqstp =kzalloc (sizeof (*rqstp),GFP_KERNEL );if (!rqstp)return ERR_PTR (-ENOMEM );
@@ -120,13 +113,13 @@ nfsd_local_fakerqst_create(struct net *net, struct rpc_clnt *rpc_clnt, status = -ENOMEM ; goto out_err; } - rqstp->rq_xprt->xpt_net = net; +__set_bit (RQ_SECURE , &rqstp->rq_flags); rqstp->rq_proc =1 ; rqstp->rq_vers =3 ; rqstp->rq_prot =IPPROTO_TCP ; - rqstp->rq_server = nn->nfsd_serv; + rqstp->rq_server = serv;/* Note: we're connecting to ourself, so source addr == peer addr */ rqstp->rq_addrlen = rpc_peeraddr(rpc_clnt,
@@ -188,28 +181,44 @@ int nfsd_open_local_fh(struct net *net,const fmode_t fmode, struct file **pfilp) { + struct nfsd_net *nn;const struct cred *save_cred;struct svc_rqst *rqstp;struct svc_fh fh;struct nfsd_file *nf;int status =0 ;int mayflags =NFSD_MAY_LOCALIO ; +struct svc_serv *serv;__be32 beres; +if (nfs_fh->size >NFS4_FHSIZE ) +return -EINVAL ; + +/* Not running in nfsd context, must safely get reference on nfsd_serv */ + net =maybe_get_net (net); +if (!net) { +dprintk ("%s: localio denied. Server netns not available\n" , __func__); +return -ENXIO ; + } + nn =net_generic (net, nfsd_net_id); + + serv =READ_ONCE (nn->nfsd_serv); +if (unlikely (!serv)) { +dprintk ("%s: localio denied. Server not running\n" , __func__); + status = -ENXIO ; + goto out_net; + } +/* Save creds before calling into nfsd */ save_cred =get_current_cred (); - rqstp =nfsd_local_fakerqst_create (net, rpc_clnt, cred); + rqstp =nfsd_local_fakerqst_create (net, rpc_clnt, cred, serv);if (IS_ERR (rqstp)) { status =PTR_ERR (rqstp); goto out_revertcred; }/* nfs_fh -> svc_fh */ -if (nfs_fh->size >NFS4_FHSIZE ) { - status = -EINVAL ; - goto out; - }fh_init (&fh,NFS4_FHSIZE ); fh.fh_handle.fh_size = nfs_fh->size;memcpy (fh.fh_handle.fh_raw, nfs_fh->data, nfs_fh->size);
@@ -225,17 +234,15 @@ int nfsd_open_local_fh(struct net *net,dprintk ("%s: fh_verify failed %d\n" , __func__, status); goto out_fh_put; } - *pfilp =get_file (nf->nf_file); -nfsd_file_put (nf); out_fh_put:fh_put (&fh); - -out:nfsd_local_fakerqst_destroy (rqstp); out_revertcred:revert_creds (save_cred); +out_net: +put_net (net);return status; }EXPORT_SYMBOL_GPL (nfsd_open_local_fh);
Signature · 1 line
2.44.0
PATCH v6 8/18 NFS: Enable localio for non-pNFS I/O
In reply to Mike SnitzerFrom: Trond Myklebust <[email protected]>
Try a local open of the file we're writing to, and if it succeeds, then do local I/O.
--- fs/nfs/pagelist.c | 19 ++++++++++--------- fs/nfs/write.c | 7 ++++++- 2 files changed, 16 insertions(+), 10 deletions(-)
fs/nfs/pagelist.c +10 -9
@@ -1063,6 +1063,7 @@ EXPORT_SYMBOL_GPL(nfs_generic_pgio);static int nfs_generic_pg_pgios (struct nfs_pageio_descriptor *desc) {struct nfs_pgio_header *hdr; +struct file *filp;int ret;unsigned short task_flags =0 ;
@@ -1074,18 +1075,18 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)nfs_pgheader_init (desc, hdr, nfs_pgio_header_free); ret =nfs_generic_pgio (desc, hdr);if (ret ==0 ) { +struct nfs_client *clp =NFS_SERVER (hdr->inode)->nfs_client; + + filp =nfs_local_file_open (clp, hdr->cred, hdr->args.fh, + hdr->args.context); +if (NFS_SERVER (hdr->inode)->nfs_client->cl_minorversion) task_flags =RPC_TASK_MOVEABLE ; - ret =nfs_initiate_pgio (desc, -NFS_SERVER (hdr->inode)->nfs_client, -NFS_CLIENT (hdr->inode), - hdr, - hdr->cred, -NFS_PROTO (hdr->inode), - desc->pg_rpc_callops, - desc->pg_ioflags, + ret =nfs_initiate_pgio (desc, clp,NFS_CLIENT (hdr->inode), + hdr, hdr->cred,NFS_PROTO (hdr->inode), + desc->pg_rpc_callops, desc->pg_ioflags,RPC_TASK_CRED_NOREF | task_flags, -NULL ); + filp); }return ret; }
fs/nfs/write.c +6 -1
@@ -1802,6 +1802,8 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, struct nfs_commit_info *cinfo) {struct nfs_commit_data *data; +struct nfs_client *clp =NFS_SERVER (inode)->nfs_client; +struct file *filp;unsigned short task_flags =0 ;/* another commit raced with us */
@@ -1818,9 +1820,12 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,nfs_init_commit (data, head,NULL , cinfo);if (NFS_SERVER (inode)->nfs_client->cl_minorversion) task_flags =RPC_TASK_MOVEABLE ; + + filp =nfs_local_file_open (clp, data->cred, data->args.fh, + data->context);return nfs_initiate_commit (NFS_CLIENT (inode), data,NFS_PROTO (inode), data->mds_ops, how, -RPC_TASK_CRED_NOREF | task_flags,NULL ); +RPC_TASK_CRED_NOREF | task_flags, filp); }/*
Signature · 1 line
2.44.0
PATCH v6 9/18 pnfs/flexfiles: Enable localio for flexfiles I/O
In reply to Mike SnitzerFrom: Trond Myklebust <[email protected]>
If the DS is local to this client, then we should be able to use local I/O to write the data.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 113 ++++++++++++++++++++-- fs/nfs/flexfilelayout/flexfilelayout.h | 2 + fs/nfs/flexfilelayout/flexfilelayoutdev.c | 6 ++ 3 files changed, 112 insertions(+), 9 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +104 -9
@@ -11,6 +11,7 @@#include <linux/nfs_mount.h> #include <linux/nfs_page.h> #include <linux/module.h> +#include <linux/file.h> #include <linux/sched/mm.h> #include <linux/sunrpc/metrics.h>
@@ -162,6 +163,52 @@ decode_name(struct xdr_stream *xdr, u32 *id)return 0 ; } +static struct file * +ff_local_open_fh (struct pnfs_layout_segment *lseg, +u32 ds_idx, +struct nfs_client *clp, +const struct cred *cred, +struct nfs_fh *fh, +fmode_t mode) +{ +struct nfs4_ff_layout_mirror *mirror =FF_LAYOUT_COMP (lseg, ds_idx); +struct file *filp, *new,__rcu **pfile; + +if (!nfs_server_is_local (clp)) +return NULL ; +if (mode &FMODE_WRITE ) { +/* +* Always request read and write access since this corresponds +* to a rw layout. +*/ + mode |=FMODE_READ ; + pfile = &mirror->rw_file; + }else + pfile = &mirror->ro_file; + + new =NULL ; +rcu_read_lock (); + filp =rcu_dereference (*pfile); +if (!filp) { +rcu_read_unlock (); + new =nfs_local_open_fh (clp, cred, fh, mode); +if (IS_ERR (new)) +return NULL ; +rcu_read_lock (); +/* try to swap in the pointer */ + filp =cmpxchg (pfile,NULL , new); +if (!filp) { + filp = new; + new =NULL ; + } + } + filp =get_file_rcu (&filp); +rcu_read_unlock (); +if (new) +fput (new); +return filp; +} +static bool ff_mirror_match_fh (const struct nfs4_ff_layout_mirror *m1,const struct nfs4_ff_layout_mirror *m2) {
@@ -237,8 +284,15 @@ static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)static void ff_layout_free_mirror (struct nfs4_ff_layout_mirror *mirror) { +struct file *filp;const struct cred *cred; + filp =rcu_access_pointer (mirror->ro_file); +if (filp) +fput (filp); + filp =rcu_access_pointer (mirror->rw_file); +if (filp) +fput (filp);ff_layout_remove_mirror (mirror);kfree (mirror->fh_versions); cred =rcu_access_pointer (mirror->ro_cred);
@@ -414,6 +468,7 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,struct nfs4_ff_layout_mirror *mirror;struct cred *kcred;const struct cred __rcu *cred; +const struct cred __rcu *old;kuid_t uid;kgid_t gid;u32 ds_count, fh_count, id;
@@ -513,13 +568,26 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh, mirror =ff_layout_add_mirror (lh, fls->mirror_array[i]);if (mirror != fls->mirror_array[i]) { +struct file *filp; +/* swap cred ptrs so free_mirror will clean up old */ if (lgr->range.iomode ==IOMODE_READ ) { - cred =xchg (&mirror->ro_cred, cred); -rcu_assign_pointer (fls->mirror_array[i]->ro_cred, cred); + old =xchg (&mirror->ro_cred, cred); +rcu_assign_pointer (fls->mirror_array[i]->ro_cred, old); +/* drop file if creds changed */ +if (old != cred) { + filp =rcu_dereference_protected (xchg (&mirror->ro_file,NULL ),1 ); +if (filp) +fput (filp); + } }else { - cred =xchg (&mirror->rw_cred, cred); -rcu_assign_pointer (fls->mirror_array[i]->rw_cred, cred); + old =xchg (&mirror->rw_cred, cred); +rcu_assign_pointer (fls->mirror_array[i]->rw_cred, old); +if (old != cred) { + filp =rcu_dereference_protected (xchg (&mirror->rw_file,NULL ),1 ); +if (filp) +fput (filp); + } }ff_layout_free_mirror (fls->mirror_array[i]); fls->mirror_array[i] = mirror;
@@ -1757,6 +1825,7 @@ ff_layout_read_pagelist(struct nfs_pageio_descriptor *desc,struct pnfs_layout_segment *lseg = hdr->lseg;struct nfs4_pnfs_ds *ds;struct rpc_clnt *ds_clnt; +struct file *filp;struct nfs4_ff_layout_mirror *mirror;const struct cred *ds_cred;loff_t offset = hdr->args.offset;
@@ -1803,12 +1872,20 @@ ff_layout_read_pagelist(struct nfs_pageio_descriptor *desc, hdr->args.offset = offset; hdr->mds_offset = offset; +/* Start IO accounting for local read */ + filp =ff_local_open_fh (lseg, idx, ds->ds_clp, ds_cred, fh, +FMODE_READ ); +if (filp) { + hdr->task.tk_start =ktime_get (); +ff_layout_read_record_layoutstats_start (&hdr->task, hdr); + } +/* Perform an asynchronous read to ds */ nfs_initiate_pgio (desc, ds->ds_clp, ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_read_call_ops_v3 : &ff_layout_read_call_ops_v4, -0 ,RPC_TASK_SOFTCONN ,NULL ); +0 ,RPC_TASK_SOFTCONN , filp);put_cred (ds_cred);return PNFS_ATTEMPTED ;
@@ -1829,6 +1906,7 @@ ff_layout_write_pagelist(struct nfs_pageio_descriptor *desc,struct pnfs_layout_segment *lseg = hdr->lseg;struct nfs4_pnfs_ds *ds;struct rpc_clnt *ds_clnt; +struct file *filp;struct nfs4_ff_layout_mirror *mirror;const struct cred *ds_cred;loff_t offset = hdr->args.offset;
@@ -1873,12 +1951,20 @@ ff_layout_write_pagelist(struct nfs_pageio_descriptor *desc,*/ hdr->args.offset = offset; +/* Start IO accounting for local write */ + filp =ff_local_open_fh (lseg, idx, ds->ds_clp, ds_cred, fh, +FMODE_READ |FMODE_WRITE ); +if (filp) { + hdr->task.tk_start =ktime_get (); +ff_layout_write_record_layoutstats_start (&hdr->task, hdr); + } +/* Perform an asynchronous write */ nfs_initiate_pgio (desc, ds->ds_clp, ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, vers ==3 ? &ff_layout_write_call_ops_v3 : &ff_layout_write_call_ops_v4, - sync,RPC_TASK_SOFTCONN ,NULL ); + sync,RPC_TASK_SOFTCONN , filp);put_cred (ds_cred);return PNFS_ATTEMPTED ;
@@ -1912,6 +1998,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)struct pnfs_layout_segment *lseg = data->lseg;struct nfs4_pnfs_ds *ds;struct rpc_clnt *ds_clnt; +struct file *filp;struct nfs4_ff_layout_mirror *mirror;const struct cred *ds_cred;u32 idx;
@@ -1950,10 +2037,18 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)if (fh) data->args.fh = fh; +/* Start IO accounting for local commit */ + filp =ff_local_open_fh (lseg, idx, ds->ds_clp, ds_cred, fh, +FMODE_READ |FMODE_WRITE ); +if (filp) { + data->task.tk_start =ktime_get (); +ff_layout_commit_record_layoutstats_start (&data->task, data); + } + ret =nfs_initiate_commit (ds_clnt, data, ds->ds_clp->rpc_ops, - vers ==3 ? &ff_layout_commit_call_ops_v3 : - &ff_layout_commit_call_ops_v4, - how,RPC_TASK_SOFTCONN ,NULL ); + vers ==3 ? &ff_layout_commit_call_ops_v3 : + &ff_layout_commit_call_ops_v4, + how,RPC_TASK_SOFTCONN , filp);put_cred (ds_cred);return ret; out_err:
fs/nfs/flexfilelayout/flexfilelayout.h +2 -0
@@ -82,7 +82,9 @@ struct nfs4_ff_layout_mirror {struct nfs_fh *fh_versions;nfs4_stateid stateid;const struct cred __rcu *ro_cred; +struct file __rcu *ro_file;const struct cred __rcu *rw_cred; +struct file __rcu *rw_file;refcount_t ref;spinlock_t lock;unsigned long flags;
fs/nfs/flexfilelayout/flexfilelayoutdev.c +6 -0
@@ -395,6 +395,12 @@ nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg,/* connect success, check rsize/wsize limit */ if (!status) { +/* +* ds_clp is put in destroy_ds(). +* keep ds_clp even if DS is local, so that if local IO cannot +* proceed somehow, we can fall back to NFS whenever we want. +*/ +nfs_local_probe (ds->ds_clp); max_payload =nfs_block_size (rpc_max_payload (ds->ds_clp->cl_rpcclient),NULL );
Signature · 1 line
2.44.0
PATCH v6 10/18 nfs/localio: use dedicated workqueues for filesystem read and write
In reply to Mike SnitzerFrom: Trond Myklebust <[email protected]>
For localio access, don't call filesystem read() and write() routines directly.
Some filesystem writeback routines can end up taking up a lot of stack space (particularly xfs). Instead of risking running over due to the extra overhead from the NFS stack, we should just call these routines from a workqueue job.
Use of dedicated workqueues improves performance over using the system_unbound_wq. Localio is motivated by the promise of improved performance, it makes little sense to yield it back.
But further analysis of the latest stack depth requirements would be useful. It'd be nice to root cause and fix the latest stack hogs, because using workqueues at all can cause a loss in performance due to context switches.
--- fs/nfs/inode.c | 57 +++++++++++++++++--------- fs/nfs/internal.h | 1 + fs/nfs/localio.c | 102 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 118 insertions(+), 42 deletions(-)
fs/nfs/inode.c +38 -19
@@ -2394,35 +2394,54 @@ static void nfs_destroy_inodecache(void)kmem_cache_destroy (nfs_inode_cachep); } +struct workqueue_struct *nfslocaliod_workqueue;struct workqueue_struct *nfsiod_workqueue;EXPORT_SYMBOL_GPL (nfsiod_workqueue);/* -* start up the nfsiod workqueue -*/ -static int nfsiod_start (void ) -{ -struct workqueue_struct *wq; -dprintk ("RPC: creating workqueue nfsiod\n" ); - wq =alloc_workqueue ("nfsiod" ,WQ_MEM_RECLAIM |WQ_UNBOUND ,0 ); -if (wq ==NULL ) -return -ENOMEM ; - nfsiod_workqueue = wq; -return 0 ; -} - -/* -* Destroy the nfsiod workqueue +* Destroy the nfsiod workqueues */ static void nfsiod_stop (void ) {struct workqueue_struct *wq; wq = nfsiod_workqueue; -if (wq ==NULL ) -return ; - nfsiod_workqueue =NULL ; -destroy_workqueue (wq); +if (wq !=NULL ) { + nfsiod_workqueue =NULL ; +destroy_workqueue (wq); + } +#if IS_ENABLED (CONFIG_NFS_LOCALIO ) + wq = nfslocaliod_workqueue; +if (wq !=NULL ) { + nfslocaliod_workqueue =NULL ; +destroy_workqueue (wq); + } +#endif /* CONFIG_NFS_LOCALIO */ +} + +/* +* Start the nfsiod workqueues +*/ +static int nfsiod_start (void ) +{ +dprintk ("RPC: creating workqueue nfsiod\n" ); + nfsiod_workqueue =alloc_workqueue ("nfsiod" ,WQ_MEM_RECLAIM |WQ_UNBOUND ,0 ); +if (nfsiod_workqueue ==NULL ) +return -ENOMEM ; +#if IS_ENABLED (CONFIG_NFS_LOCALIO ) +/* +* localio writes need to use a normal (non-memreclaim) workqueue. +* When we start getting low on space, XFS goes and calls flush_work() on +* a non-memreclaim work queue, which causes a priority inversion problem. +*/ +dprintk ("RPC: creating workqueue nfslocaliod\n" ); + nfslocaliod_workqueue =alloc_workqueue ("nfslocaliod" ,WQ_UNBOUND ,0 ); +if (unlikely (nfslocaliod_workqueue ==NULL )) { +nfsiod_stop (); +return -ENOMEM ; + } +#endif /* CONFIG_NFS_LOCALIO */ +return 0 ; }unsigned int nfs_net_id;
fs/nfs/internal.h +1 -0
@@ -440,6 +440,7 @@ int nfs_check_flags(int);/* inode.c */ extern struct workqueue_struct *nfsiod_workqueue; +extern struct workqueue_struct *nfslocaliod_workqueue;extern struct inode *nfs_alloc_inode (struct super_block *sb);extern void nfs_free_inode (struct inode *);extern int nfs_write_inode (struct inode *,struct writeback_control *);
fs/nfs/localio.c +79 -23
152 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH v6 11/18 nfs: implement v3 and v4 client support for NFS_LOCALIO_PROGRAM
In reply to Mike SnitzerLOCALIOPROC_GETUUID allows client to discover server's uuid.
nfs_local_probe() will retrieve server's uuid via LOCALIO protocol and verify the server with that uuid it is known to be local. This ensures client and server 1: support localio 2: are local to each other.
While doing so, factor out nfs_init_localioclient() so it is used by both nfs3client.c and nfs4client.c
Get nfsd_open_local_fh and store it in rpc_client during client creation, put the symbol during nfs_local_disable -- which is also called during client destruction.
--- fs/nfs/client.c | 6 ++- fs/nfs/internal.h | 27 ++++++++++++ fs/nfs/localio.c | 90 ++++++++++++++++++++++++++++++++++++---- fs/nfs/nfs3_fs.h | 1 + fs/nfs/nfs3client.c | 25 +++++++++++ fs/nfs/nfs3proc.c | 3 ++ fs/nfs/nfs3xdr.c | 67 ++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 2 + fs/nfs/nfs4client.c | 23 ++++++++++ fs/nfs/nfs4proc.c | 3 ++ fs/nfs/nfs4xdr.c | 52 +++++++++++++++++++++++ include/linux/nfs_xdr.h | 10 +++++ include/uapi/linux/nfs.h | 4 ++ 13 files changed, 302 insertions(+), 11 deletions(-)
fs/nfs/client.c +4 -2
@@ -434,8 +434,10 @@ struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)list_add_tail (&new->cl_share_link, &nn->nfs_client_list);spin_unlock (&nn->nfs_client_lock); -nfs_local_probe (new); -return rpc_ops->init_client (new, cl_init); + new = rpc_ops->init_client (new, cl_init); +if (!IS_ERR (new)) +nfs_local_probe (new); +return new; }spin_unlock (&nn->nfs_client_lock);
fs/nfs/internal.h +27 -0
@@ -453,6 +453,33 @@ extern bool nfs_check_cache_invalid(struct inode *, unsigned long);extern int nfs_wait_bit_killable (struct wait_bit_key *key,int mode);#if IS_ENABLED (CONFIG_NFS_LOCALIO ) +/* +* Initialise an NFS localio client connection. +* Inlined here to allow nfs[34]client.c to share this code. +*/ +static __always_inline void +nfs_init_localioclient (struct nfs_client *clp, +const struct rpc_program *program,u32 vers) +{ +if (unlikely (!IS_ERR (clp->cl_rpcclient_localio))) + goto out; + clp->cl_rpcclient_localio =rpc_bind_new_program (clp->cl_rpcclient, + program, vers); +if (IS_ERR (clp->cl_rpcclient_localio)) + goto out; +/* No errors! Assume that localio is supported */ + clp->nfsd_open_local_fh =get_nfsd_open_local_fh (); +if (!clp->nfsd_open_local_fh) { +rpc_shutdown_client (clp->cl_rpcclient_localio); + clp->cl_rpcclient_localio =ERR_PTR (-EINVAL ); + } +out: +dfprintk_rcu (CLIENT ,"%s: server (%s) %s NFSv%u LOCALIO, nfsd_open_local_fh is %s.\n" , + __func__,rpc_peeraddr2str (clp->cl_rpcclient,RPC_DISPLAY_ADDR ), + (IS_ERR (clp->cl_rpcclient_localio) ?"does not support" :"supports" ), vers, + (clp->nfsd_open_local_fh ?"set" :"not set" )); +} +/* localio.c */ extern void nfs_local_disable (struct nfs_client *);extern void nfs_local_probe (struct nfs_client *);
fs/nfs/localio.c +81 -9
124 lines not on this page · raw message
fs/nfs/nfs3_fs.h +1 -0
@@ -30,6 +30,7 @@ static inline int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,struct nfs_server *nfs3_create_server (struct fs_context *);struct nfs_server *nfs3_clone_server (struct nfs_server *,struct nfs_fh *,struct nfs_fattr *,rpc_authflavor_t ); +void nfs3_init_localioclient (struct nfs_client *);/* nfs3super.c */ extern struct nfs_subversion nfs_v3;
fs/nfs/nfs3client.c +25 -0
@@ -7,6 +7,8 @@#include "netns.h" #include "sysfs.h" +#define NFSDBG_FACILITY NFSDBG_CLIENT +#ifdef CONFIG_NFS_V3_ACL static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; static const struct rpc_version *nfsacl_version[] = {
@@ -130,3 +132,26 @@ struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,return clp; }EXPORT_SYMBOL_GPL (nfs3_set_ds_client); + +#if defined(CONFIG_NFS_V3_LOCALIO ) +static struct rpc_stat nfslocalio_rpcstat = { &nfslocalio_program3 }; +static const struct rpc_version *nfslocalio_version[] = { + [3 ] = &nfslocalio_version3, +}; + +const struct rpc_program nfslocalio_program3 = { + .name ="nfslocalio" , + .number =NFS_LOCALIO_PROGRAM , + .nrvers =ARRAY_SIZE (nfslocalio_version), + .version = nfslocalio_version, + .stats = &nfslocalio_rpcstat, +}; + +/* +* Initialise an NFSv3 localio client connection +*/ +void nfs3_init_localioclient (struct nfs_client *clp) +{ +nfs_init_localioclient (clp, &nfslocalio_program3,3 ); +} +#endif /* CONFIG_NFS_V3_LOCALIO */
fs/nfs/nfs3proc.c +3 -0
@@ -1067,4 +1067,7 @@ const struct nfs_rpc_ops nfs_v3_clientops = { .free_client = nfs_free_client, .create_server = nfs3_create_server, .clone_server = nfs3_clone_server, +#if defined(CONFIG_NFS_V3_LOCALIO ) + .init_localioclient = nfs3_init_localioclient, +#endif };
fs/nfs/nfs3xdr.c +67 -0
70 lines not on this page · raw message
fs/nfs/nfs4_fs.h +2 -0
@@ -538,6 +538,8 @@ extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, structextern const nfs4_stateid zero_stateid;extern const nfs4_stateid invalid_stateid; +extern void nfs4_init_localioclient (struct nfs_client *); +/* nfs4super.c */ struct nfs_mount_info ;extern struct nfs_subversion nfs_v4;
fs/nfs/nfs4client.c +23 -0
@@ -1384,3 +1384,26 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname,return nfs_probe_server (server,NFS_FH (d_inode (server->super->s_root))); } + +#if defined(CONFIG_NFS_V4_LOCALIO ) +static struct rpc_stat nfslocalio_rpcstat = { &nfslocalio_program4 }; +static const struct rpc_version *nfslocalio_version[] = { + [4 ] = &nfslocalio_version4, +}; + +const struct rpc_program nfslocalio_program4 = { + .name ="nfslocalio" , + .number =NFS_LOCALIO_PROGRAM , + .nrvers =ARRAY_SIZE (nfslocalio_version), + .version = nfslocalio_version, + .stats = &nfslocalio_rpcstat, +}; + +/* +* Initialise an NFSv4 localio client connection +*/ +void nfs4_init_localioclient (struct nfs_client *clp) +{ +nfs_init_localioclient (clp, &nfslocalio_program4,4 ); +} +#endif /* CONFIG_NFS_V4_LOCALIO */
fs/nfs/nfs4proc.c +3 -0
@@ -10745,6 +10745,9 @@ const struct nfs_rpc_ops nfs_v4_clientops = { .discover_trunking = nfs4_discover_trunking, .enable_swap = nfs4_enable_swap, .disable_swap = nfs4_disable_swap, +#if defined(CONFIG_NFS_V4_LOCALIO ) + .init_localioclient = nfs4_init_localioclient, +#endif };static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
fs/nfs/nfs4xdr.c +52 -0
55 lines not on this page · raw message
include/linux/nfs_xdr.h +10 -0
@@ -1002,6 +1002,10 @@ struct nfs3_getaclres {struct posix_acl * acl_default; }; +struct nfs_getuuidres { +__u8 * uuid; +}; +#if IS_ENABLED (CONFIG_NFS_V4 )typedef u64 clientid4 ;
@@ -1819,6 +1823,7 @@ struct nfs_rpc_ops {int (*discover_trunking)(struct nfs_server *,struct nfs_fh *);void (*enable_swap)(struct inode *inode);void (*disable_swap)(struct inode *inode); +void (*init_localioclient)(struct nfs_client *); };/*
@@ -1834,4 +1839,9 @@ extern const struct rpc_version nfs_version4;extern const struct rpc_version nfsacl_version3;extern const struct rpc_program nfsacl_program; +extern const struct rpc_version nfslocalio_version3; +extern const struct rpc_program nfslocalio_program3; +extern const struct rpc_version nfslocalio_version4; +extern const struct rpc_program nfslocalio_program4; +#endif
include/uapi/linux/nfs.h +4 -0
@@ -33,6 +33,10 @@#define NFS_MNT_VERSION 1#define NFS_MNT3_VERSION 3 +#define NFS_LOCALIO_PROGRAM 0x20000002 +#define LOCALIOPROC_NULL 0 +#define LOCALIOPROC_GETUUID 1 +#define NFS_PIPE_DIRNAME "nfs"/*
Signature · 1 line
2.44.0
PATCH v6 12/18 nfsd: implement v3 and v4 server support for NFS_LOCALIO_PROGRAM
In reply to Mike SnitzerLOCALIOPROC_GETUUID encodes the server's uuid_t in terms of the fixed UUID_SIZE (16). The fixed size opaque encode and decode XDR methods are used instead of the less efficient variable sized methods.
--- fs/nfsd/localio.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfsd.h | 11 ++++ fs/nfsd/nfssvc.c | 80 ++++++++++++++++++++++++- fs/nfsd/xdr.h | 6 ++ 4 files changed, 244 insertions(+), 1 deletion(-)
fs/nfsd/localio.c +148 -0
@@ -17,6 +17,9 @@#include "vfs.h" #include "netns.h" #include "filecache.h" +#include "cache.h" +#include "xdr3.h" +#include "xdr4.h" #define NFSDDBG_FACILITY NFSDDBG_FH
@@ -249,3 +252,148 @@ EXPORT_SYMBOL_GPL(nfsd_open_local_fh);/* Compile time type checking, not used by anything */ static nfs_to_nfsd_open_t __maybe_unused nfsd_open_local_fh_typecheck = nfsd_open_local_fh; + +/* +* GETUUID XDR encode functions +*/ + +static __be32 nfsd_proc_null (struct svc_rqst *rqstp) +{ +return rpc_success; +} + +static __be32 nfsd_proc_getuuid (struct svc_rqst *rqstp) +{ +struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id); +struct nfsd_getuuidres *resp = rqstp->rq_resp; + +uuid_copy (&resp->uuid, &nn->nfsd_uuid.uuid); + resp->status = nfs_ok; + +return rpc_success; +} + +#define NFS_getuuid_sz XDR_QUADLEN(UUID_SIZE) + +static inline void encode_opaque_fixed (struct xdr_stream *xdr,const void *buf,size_t len) +{ +WARN_ON_ONCE (xdr_stream_encode_opaque_fixed (xdr, buf, len) <0 ); +} + +static void encode_uuid (struct xdr_stream *xdr,uuid_t *src_uuid) +{ +u8 uuid[UUID_SIZE ]; + +export_uuid (uuid, src_uuid); +encode_opaque_fixed (xdr, uuid,UUID_SIZE ); +dprintk ("%s: uuid=%pU\n" , __func__, uuid); +} + +#if defined(CONFIG_NFSD_V3_LOCALIO ) +static bool nfs3svc_encode_getuuidres (struct svc_rqst *rqstp, +struct xdr_stream *xdr) +{ +struct nfsd_getuuidres *resp = rqstp->rq_resp; + +if (!svcxdr_encode_nfsstat3 (xdr, resp->status)) +return false; +if (resp->status == nfs_ok) +encode_uuid (xdr, &resp->uuid); + +return true; +} + +#define ST 1/* status */ +#define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2)) + +static const struct svc_procedure nfsd_localio_procedures3[2 ] = { + [LOCALIOPROC_NULL ] = { + .pc_func = nfsd_proc_null, + .pc_decode = nfssvc_decode_voidarg, + .pc_encode = nfssvc_encode_voidres, + .pc_argsize =sizeof (struct nfsd_voidargs ), + .pc_ressize =sizeof (struct nfsd_voidres ), + .pc_cachetype =RC_NOCACHE , + .pc_xdrressize =1 , + .pc_name ="NULL" , + }, + [LOCALIOPROC_GETUUID ] = { + .pc_func = nfsd_proc_getuuid, + .pc_decode = nfssvc_decode_voidarg, + .pc_encode = nfs3svc_encode_getuuidres, + .pc_argsize =sizeof (struct nfsd_voidargs ), + .pc_ressize =sizeof (struct nfsd_getuuidres ), + .pc_cachetype =RC_NOCACHE , + .pc_xdrressize =1 +NFS_getuuid_sz, + .pc_name ="GETUUID" , + }, +}; + +static DEFINE_PER_CPU_ALIGNED(unsigned long, + nfsd_localio_count3[ARRAY_SIZE(nfsd_localio_procedures3)]); +const struct svc_version nfsd_localio_version3 = { + .vs_vers =3 , + .vs_nproc =2 , + .vs_proc = nfsd_localio_procedures3, + .vs_dispatch = nfsd_dispatch, + .vs_count = nfsd_localio_count3, + .vs_xdrsize =NFS3_SVC_XDRSIZE , +}; +#endif /* CONFIG_NFSD_V3_LOCALIO */ + +#if defined(CONFIG_NFSD_V4_LOCALIO ) +static bool nfs4svc_encode_getuuidres (struct svc_rqst *rqstp, +struct xdr_stream *xdr) +{ +struct nfsd_getuuidres *resp = rqstp->rq_resp; +__be32 *p; + + p =xdr_reserve_space (xdr,8 ); +if (!p) +return 0 ; + *p++ =cpu_to_be32 (LOCALIOPROC_GETUUID ); + *p++ = resp->status; + +if (resp->status == nfs_ok) +encode_uuid (xdr, &resp->uuid); + +return 1 ; +} + +static const struct svc_procedure nfsd_localio_procedures4[2 ] = { + [LOCALIOPROC_NULL ] = { + .pc_func = nfsd_proc_null, + .pc_decode = nfssvc_decode_voidarg, + .pc_encode = nfssvc_encode_voidres, + .pc_argsize =sizeof (struct nfsd_voidargs ), + .pc_ressize =sizeof (struct nfsd_voidres ), + .pc_cachetype =RC_NOCACHE , + .pc_xdrressize =1 , + .pc_name ="NULL" , + }, + [LOCALIOPROC_GETUUID ] = { + .pc_func = nfsd_proc_getuuid, + .pc_decode = nfssvc_decode_voidarg, + .pc_encode = nfs4svc_encode_getuuidres, + .pc_argsize =sizeof (struct nfsd_voidargs ), + .pc_ressize =sizeof (struct nfsd_getuuidres ), + .pc_cachetype =RC_NOCACHE , + .pc_xdrressize =2 +NFS_getuuid_sz, + .pc_name ="GETUUID" , + }, +}; + +static DEFINE_PER_CPU_ALIGNED(unsigned long, + nfsd_localio_count4[ARRAY_SIZE(nfsd_localio_procedures4)]); +const struct svc_version nfsd_localio_version4 = { + .vs_vers =4 , + .vs_nproc =2 , + .vs_proc = nfsd_localio_procedures4, + .vs_dispatch = nfsd_dispatch, + .vs_count = nfsd_localio_count4, + .vs_xdrsize =NFS4_SVC_XDRSIZE , + .vs_rpcb_optnl = true, + .vs_need_cong_ctrl = true, + +}; +#endif /* CONFIG_NFSD_V4_LOCALIO */
fs/nfsd/nfsd.h +11 -0
@@ -143,6 +143,17 @@ extern const struct svc_version nfsd_acl_version3;#endif #endif +#if defined(CONFIG_NFSD_V3_LOCALIO ) +extern const struct svc_version nfsd_localio_version3; +#else +#define nfsd_localio_version3 NULL +#endif +#if defined(CONFIG_NFSD_V4_LOCALIO ) +extern const struct svc_version nfsd_localio_version4; +#else +#define nfsd_localio_version4 NULL +#endif +struct nfsd_net ;enum vers_op {NFSD_SET ,NFSD_CLEAR ,NFSD_TEST ,NFSD_AVAIL };
fs/nfsd/nfssvc.c +79 -1
116 lines not on this page · raw message
fs/nfsd/xdr.h +6 -0
@@ -5,6 +5,7 @@#define LINUX_NFSD_H #include <linux/vfs.h> +#include <linux/uuid.h> #include "nfsd.h" #include "nfsfh.h"
@@ -123,6 +124,11 @@ struct nfsd_statfsres {struct kstatfs stats; }; +struct nfsd_getuuidres { +__be32 status; +uuid_t uuid; +}; +/* * Storage requirements for XDR arguments and results. */
Signature · 1 line
2.44.0
PATCH v6 13/18 nfs/nfsd: consolidate {encode,decode}_opaque_fixed in nfs_xdr.h
In reply to Mike SnitzerEliminates duplicate functions in various files.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 6 ------ fs/nfs/nfs3xdr.c | 9 --------- fs/nfs/nfs4xdr.c | 13 ------------- fs/nfsd/localio.c | 7 ++----- include/linux/nfs_xdr.h | 20 +++++++++++++++++++- 5 files changed, 21 insertions(+), 34 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +0 -6
@@ -2185,12 +2185,6 @@ static int ff_layout_encode_ioerr(struct xdr_stream *xdr,return ff_layout_encode_ds_ioerr (xdr, &ff_args->errors); } -static void -encode_opaque_fixed (struct xdr_stream *xdr,const void *buf,size_t len) -{ -WARN_ON_ONCE (xdr_stream_encode_opaque_fixed (xdr, buf, len) <0 ); -} - static void ff_layout_encode_ff_iostat_head(struct xdr_stream *xdr, const nfs4_stateid *stateid,
fs/nfs/nfs3xdr.c +0 -9
@@ -2591,15 +2591,6 @@ static void nfs3_xdr_enc_getuuidargs(struct rpc_rqst *req,/* void function */ } -// FIXME: factor out from fs/nfs/nfs4xdr.c -static int decode_opaque_fixed (struct xdr_stream *xdr,void *buf,size_t len) -{ -ssize_t ret =xdr_stream_decode_opaque_fixed (xdr, buf, len); -if (unlikely (ret <0 )) -return -EIO ; -return 0 ; -} -static inline int nfs3_decode_getuuidresok (struct xdr_stream *xdr,struct nfs_getuuidres *result) {
fs/nfs/nfs4xdr.c +0 -13
@@ -968,11 +968,6 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)return p; } -static void encode_opaque_fixed (struct xdr_stream *xdr,const void *buf,size_t len) -{ -WARN_ON_ONCE (xdr_stream_encode_opaque_fixed (xdr, buf, len) <0 ); -} -static void encode_string (struct xdr_stream *xdr,unsigned int len,const char *str) {WARN_ON_ONCE (xdr_stream_encode_opaque (xdr, str, len) <0 );
@@ -4352,14 +4347,6 @@ static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)return 0 ; } -static int decode_opaque_fixed (struct xdr_stream *xdr,void *buf,size_t len) -{ -ssize_t ret =xdr_stream_decode_opaque_fixed (xdr, buf, len); -if (unlikely (ret <0 )) -return -EIO ; -return 0 ; -} -static int decode_stateid (struct xdr_stream *xdr,nfs4_stateid *stateid) {return decode_opaque_fixed (xdr, stateid,NFS4_STATEID_SIZE );
fs/nfsd/localio.c +2 -5
@@ -11,6 +11,8 @@#include <linux/sunrpc/svcauth_gss.h> #include <linux/sunrpc/clnt.h> #include <linux/nfs.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_xdr.h> #include <linux/string.h> #include "nfsd.h"
@@ -275,11 +277,6 @@ static __be32 nfsd_proc_getuuid(struct svc_rqst *rqstp)#define NFS_getuuid_sz XDR_QUADLEN(UUID_SIZE) -static inline void encode_opaque_fixed (struct xdr_stream *xdr,const void *buf,size_t len) -{ -WARN_ON_ONCE (xdr_stream_encode_opaque_fixed (xdr, buf, len) <0 ); -} -static void encode_uuid (struct xdr_stream *xdr,uuid_t *src_uuid) {u8 uuid[UUID_SIZE ];
include/linux/nfs_xdr.h +19 -1
@@ -1826,6 +1826,24 @@ struct nfs_rpc_ops {void (*init_localioclient)(struct nfs_client *); }; +/* +* Helper functions used by NFS client and/or server +*/ +static inline void encode_opaque_fixed (struct xdr_stream *xdr, +const void *buf,size_t len) +{ +WARN_ON_ONCE (xdr_stream_encode_opaque_fixed (xdr, buf, len) <0 ); +} + +static inline int decode_opaque_fixed (struct xdr_stream *xdr, +void *buf,size_t len) +{ +ssize_t ret =xdr_stream_decode_opaque_fixed (xdr, buf, len); +if (unlikely (ret <0 )) +return -EIO ; +return 0 ; +} +/* * Function vectors etc. for the NFS client */
@@ -1844,4 +1862,4 @@ extern const struct rpc_program nfslocalio_program3;extern const struct rpc_version nfslocalio_version4;extern const struct rpc_program nfslocalio_program4; -#endif +#endif /* _LINUX_NFS_XDR_H */
Signature · 1 line
2.44.0
PATCH v6 14/18 nfsd: prepare to use SRCU to dereference nn->nfsd_serv
In reply to Mike SnitzerThe next commit switches the nfsd_serv member for struct nfsd_net over to a void pointer (void __rcu *). Prepare for this by assigning nn->nfsd_serv to an struct svc_serv pointer that is then happily dereferenced. This eliminates what would otherwise be numerous void pointer dereferences after the next commit.
All nfsd code what audited so that methods that hold nfsd_mutex will continue to directly dereference nn->nfsd_serv.
--- fs/nfsd/nfsctl.c | 21 +++++++++++++-------- fs/nfsd/nfssvc.c | 34 ++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 24 deletions(-)
fs/nfsd/nfsctl.c +13 -8
@@ -687,10 +687,11 @@ static ssize_t write_versions(struct file *file, char *buf, size_t size)static ssize_t __write_ports_names (char *buf,struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv = nn->nfsd_serv; -if (nn->nfsd_serv ==NULL ) +if (serv ==NULL )return 0 ; -return svc_xprt_names (nn->nfsd_serv, buf,SIMPLE_TRANSACTION_LIMIT ); +return svc_xprt_names (serv, buf,SIMPLE_TRANSACTION_LIMIT ); }/*
@@ -717,7 +718,7 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred serv = nn->nfsd_serv; err =svc_addsock (serv, net, fd, buf,SIMPLE_TRANSACTION_LIMIT , cred); -if (!serv->sv_nrthreads &&list_empty (&nn->nfsd_serv->sv_permsocks)) +if (!serv->sv_nrthreads &&list_empty (&serv->sv_permsocks))nfsd_destroy_serv (net);return err;
@@ -765,7 +766,7 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct crsvc_xprt_put (xprt); } out_err: -if (!serv->sv_nrthreads &&list_empty (&nn->nfsd_serv->sv_permsocks)) +if (!serv->sv_nrthreads &&list_empty (&serv->sv_permsocks))nfsd_destroy_serv (net);return err;
@@ -1674,6 +1675,7 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)int *nthreads, count =0 , nrpools, i, ret = -EOPNOTSUPP , rem;struct net *net =genl_info_net (info);struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv;const struct nlattr *attr;const char *scope =NULL ;
@@ -1708,7 +1710,8 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info) info->attrs[NFSD_A_SERVER_LEASETIME] || info->attrs[NFSD_A_SERVER_SCOPE]) { ret = -EBUSY ; -if (nn->nfsd_serv && nn->nfsd_serv->sv_nrthreads) + serv = nn->nfsd_serv; +if (serv && serv->sv_nrthreads) goto out_unlock; ret = -EINVAL ;
@@ -1757,6 +1760,7 @@ int nfsd_nl_threads_get_doit(struct sk_buff *skb, struct genl_info *info) {struct net *net =genl_info_net (info);struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv;void *hdr;int err;
@@ -1781,11 +1785,12 @@ int nfsd_nl_threads_get_doit(struct sk_buff *skb, struct genl_info *info)if (err) goto err_unlock; -if (nn->nfsd_serv) { + serv = nn->nfsd_serv; +if (serv) {int i;for (i =0 ; i <nfsd_nrpools (net); ++i) { -struct svc_pool *sp = &nn->nfsd_serv->sv_pools[i]; +struct svc_pool *sp = &serv->sv_pools[i]; err =nla_put_u32 (skb,NFSD_A_SERVER_THREADS ,atomic_read (&sp->sp_nrthreads));
@@ -2103,7 +2108,7 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info) err = ret; } -if (!serv->sv_nrthreads &&list_empty (&nn->nfsd_serv->sv_permsocks)) +if (!serv->sv_nrthreads &&list_empty (&serv->sv_permsocks))nfsd_destroy_serv (net); out_unlock_mtx:
fs/nfsd/nfssvc.c +18 -16
@@ -309,10 +309,12 @@ int nfsd_nrthreads(struct net *net) {int rv =0 ;struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv;mutex_lock (&nfsd_mutex); -if (nn->nfsd_serv) - rv = nn->nfsd_serv->sv_nrthreads; + serv = nn->nfsd_serv; +if (serv) + rv = serv->sv_nrthreads;mutex_unlock (&nfsd_mutex);return rv; }
@@ -321,16 +323,17 @@ static int nfsd_init_socks(struct net *net, const struct cred *cred) {int error;struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv = nn->nfsd_serv; -if (!list_empty (&nn->nfsd_serv->sv_permsocks)) +if (!list_empty (&serv->sv_permsocks))return 0 ; - error =svc_xprt_create (nn->nfsd_serv,"udp" , net,PF_INET ,NFS_PORT , + error =svc_xprt_create (serv,"udp" , net,PF_INET ,NFS_PORT ,SVC_SOCK_DEFAULTS , cred);if (error <0 )return error; - error =svc_xprt_create (nn->nfsd_serv,"tcp" , net,PF_INET ,NFS_PORT , + error =svc_xprt_create (serv,"tcp" , net,PF_INET ,NFS_PORT ,SVC_SOCK_DEFAULTS , cred);if (error <0 )return error;
@@ -742,11 +745,12 @@ int nfsd_create_serv(struct net *net)int nfsd_nrpools (struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv = nn->nfsd_serv; -if (nn->nfsd_serv ==NULL ) +if (serv ==NULL )return 0 ;else -return nn->nfsd_serv->sv_nrpools; +return serv->sv_nrpools; }int nfsd_get_nrthreads (int n,int *nthreads,struct net *net)
@@ -780,14 +784,15 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)int tot =0 ;int err =0 ;struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv = nn->nfsd_serv;lockdep_assert_held (&nfsd_mutex); -if (nn->nfsd_serv ==NULL || n <=0 ) +if (serv ==NULL || n <=0 )return 0 ; -if (n > nn->nfsd_serv->sv_nrpools) - n = nn->nfsd_serv->sv_nrpools; +if (n > serv->sv_nrpools) + n = serv->sv_nrpools;/* enforce a global maximum number of threads */ tot =0 ;
@@ -810,18 +815,15 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)/* apply the new numbers */ for (i =0 ; i < n; i++) { - err =svc_set_num_threads (nn->nfsd_serv, - &nn->nfsd_serv->sv_pools[i], + err =svc_set_num_threads (serv, &serv->sv_pools[i], nthreads[i]);if (err) goto out; }/* Anything undefined in array is considered to be 0 */ -for (i = n; i < nn->nfsd_serv->sv_nrpools; ++i) { - err =svc_set_num_threads (nn->nfsd_serv, - &nn->nfsd_serv->sv_pools[i], -0 ); +for (i = n; i < serv->sv_nrpools; ++i) { + err =svc_set_num_threads (serv, &serv->sv_pools[i],0 );if (err) goto out; }
Signature · 1 line
2.44.0
PATCH v6 15/18 nfsd: use SRCU to dereference nn->nfsd_serv
In reply to Mike SnitzerIntroduce nfsd_serv_get, nfsd_serv_put and nfsd_serv_sync and update the nfsd code to prevent nfsd_destroy_serv from destroying nn->nfsd_serv until all nfsd code is done with it (particularly the localio code that doesn't run in the context of nfsd's svc threads, nor does it take the nfsd_mutex).
Commit 83d5e5b0af90 ("dm: optimize use SRCU and RCU") provided a familiar well-worn pattern for how implement.
--- fs/nfsd/filecache.c | 13 ++++++++--- fs/nfsd/netns.h | 14 ++++++++++-- fs/nfsd/nfs4state.c | 25 ++++++++++++++------- fs/nfsd/nfsctl.c | 7 ++++-- fs/nfsd/nfssvc.c | 54 ++++++++++++++++++++++++++++++++++++--------- 5 files changed, 88 insertions(+), 25 deletions(-)
fs/nfsd/filecache.c +10 -3
@@ -413,12 +413,15 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose)struct nfsd_file *nf =list_first_entry (dispose, struct nfsd_file, nf_lru);struct nfsd_net *nn =net_generic (nf->nf_net, nfsd_net_id); +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);struct nfsd_fcache_disposal *l = nn->fcache_disposal;spin_lock (&l->lock);list_move_tail (&nf->nf_lru, &l->freeme);spin_unlock (&l->lock); -svc_wake_up (nn->nfsd_serv); +svc_wake_up (serv); +nfsd_serv_put (nn, srcu_idx); } }
@@ -443,11 +446,15 @@ void nfsd_file_net_dispose(struct nfsd_net *nn)for (i =0 ; i <8 && !list_empty (&l->freeme); i++)list_move (l->freeme.next, &dispose);spin_unlock (&l->lock); -if (!list_empty (&l->freeme)) +if (!list_empty (&l->freeme)) { +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);/* Wake up another thread to share the work * *before* doing any actual disposing. */ -svc_wake_up (nn->nfsd_serv); +svc_wake_up (serv); +nfsd_serv_put (nn, srcu_idx); + }nfsd_file_dispose_list (&dispose); } }
fs/nfsd/netns.h +12 -2
@@ -139,8 +139,14 @@ struct nfsd_net {u32 clverifier_counter;struct svc_info nfsd_info; -#define nfsd_serv nfsd_info.serv - +/* +* The current 'nfsd_serv' at nfsd_info.serv. Using 'void' rather than +* 'struct svc_serv' to guard against new code dereferencing nfsd_serv +* without using proper synchronization. +* Use nfsd_serv_get() or take nfsd_mutex to dereference. +*/ +void __rcu *nfsd_serv; +struct srcu_struct nfsd_serv_srcu;/* * clientid and stateid data for construction of net unique COPY
@@ -225,6 +231,10 @@ struct nfsd_net {extern bool nfsd_support_version (int vers);extern void nfsd_netns_free_versions (struct nfsd_net *nn); +extern struct svc_serv *nfsd_serv_get (struct nfsd_net *nn,int *srcu_idx); +extern void nfsd_serv_put (struct nfsd_net *nn,int srcu_idx); +extern void nfsd_serv_sync (struct nfsd_net *nn); +extern unsigned int nfsd_net_id;void nfsd_copy_write_verifier (__be32 verf[2 ],struct nfsd_net *nn);
fs/nfsd/nfs4state.c +17 -8
@@ -1919,6 +1919,8 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca, struct nfsd_net *nnu32 num = ca->maxreqs;unsigned long avail, total_avail;unsigned int scale_factor; +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);spin_lock (&nfsd_drc_lock);if (nfsd_drc_max_mem > nfsd_drc_mem_used)
@@ -1940,7 +1942,7 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca, struct nfsd_net *nn* Give the client one slot even if that would require * over-allocation--it is better than failure. */ - scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads); + scale_factor = max_t(unsigned int, 8, serv->sv_nrthreads); avail = clamp_t(unsigned long, avail, slotsize, total_avail/scale_factor);
@@ -1949,6 +1951,8 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca, struct nfsd_net *nn nfsd_drc_mem_used += num * slotsize;spin_unlock (&nfsd_drc_lock); +nfsd_serv_put (nn, srcu_idx); +return num; }
@@ -3702,12 +3706,16 @@ nfsd4_replay_create_session(struct nfsd4_create_session *cr_ses,static __be32 check_forechannel_attrs (struct nfsd4_channel_attrs *ca,struct nfsd_net *nn) { -u32 maxrpc = nn->nfsd_serv->sv_max_mesg; +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx); +u32 maxrpc = serv->sv_max_mesg; +__be32 status = nfs_ok; -if (ca->maxreq_sz <NFSD_MIN_REQ_HDR_SEQ_SZ ) -return nfserr_toosmall; -if (ca->maxresp_sz <NFSD_MIN_RESP_HDR_SEQ_SZ ) -return nfserr_toosmall; +if (ca->maxreq_sz <NFSD_MIN_REQ_HDR_SEQ_SZ || + ca->maxresp_sz <NFSD_MIN_RESP_HDR_SEQ_SZ ) { + status = nfserr_toosmall; + goto out; + } ca->headerpadsz =0 ; ca->maxreq_sz =min_t (u32, ca->maxreq_sz, maxrpc); ca->maxresp_sz =min_t (u32, ca->maxresp_sz, maxrpc);
@@ -3726,8 +3734,9 @@ static __be32 check_forechannel_attrs(struct nfsd4_channel_attrs *ca, struct nfs* accounting is soft and provides no guarantees either way. */ ca->maxreqs =nfsd4_get_drc_mem (ca, nn); - -return nfs_ok; +out: +nfsd_serv_put (nn, srcu_idx); +return status; }/*
fs/nfsd/nfsctl.c +5 -2
@@ -1569,10 +1569,12 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb, {struct nfsd_net *nn =net_generic (sock_net (skb->sk), nfsd_net_id);int i, ret, rqstp_index =0 ; +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);rcu_read_lock (); -for (i =0 ; i < nn->nfsd_serv->sv_nrpools; i++) { +for (i =0 ; i < serv->sv_nrpools; i++) {struct svc_rqst *rqstp;if (i < cb->args[0 ])/* already consumed */
@@ -1580,7 +1582,7 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb, rqstp_index =0 ;list_for_each_entry_rcu (rqstp, - &nn->nfsd_serv->sv_pools[i].sp_all_threads, + &serv->sv_pools[i].sp_all_threads, rq_all) {struct nfsd_genl_rqstp genl_rqstp;unsigned int status_counter;
@@ -1645,6 +1647,7 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb, ret = skb->len; out:rcu_read_unlock (); +nfsd_serv_put (nn, srcu_idx);return ret; }
fs/nfsd/nfssvc.c +44 -10
126 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH v6 15/18] nfsd: use SRCU to dereference nn->nfsd_serv
Quoted 67 lines · Mike Snitzer
Introduce
nfsd_serv_get,nfsd_serv_putandnfsd_serv_syncand update the nfsd code to preventnfsd_destroy_servfrom destroyingnn->nfsd_servuntil all nfsd code is done with it (particularly the localio code that doesn't run in the context of nfsd's svc threads, nor does it take thenfsd_mutex).Commit
83d5e5b0af90("dm: optimize use SRCU and RCU") provided a familiar well-worn pattern for how implement.Suggested-by NeilBrown <[email protected]>Signed-off-by Mike Snitzer <[email protected]>--- fs/nfsd/filecache.c | 13 ++++++++--- fs/nfsd/netns.h | 14 ++++++++++-- fs/nfsd/nfs4state.c | 25 ++++++++++++++------- fs/nfsd/nfsctl.c | 7 ++++-- fs/nfsd/nfssvc.c | 54 ++++++++++++++++++++++++++++++++++++--------- 5 files changed, 88 insertions(+), 25 deletions(-)fs/nfsd/filecache.c +10
-3@@ -413,12 +413,15 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose)struct nfsd_file *nf =list_first_entry (dispose, struct nfsd_file, nf_lru);struct nfsd_net *nn =net_generic (nf->nf_net, nfsd_net_id); +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);struct nfsd_fcache_disposal *l = nn->fcache_disposal;spin_lock (&l->lock);list_move_tail (&nf->nf_lru, &l->freeme);spin_unlock (&l->lock); -svc_wake_up (nn->nfsd_serv); +svc_wake_up (serv); +nfsd_serv_put (nn, srcu_idx); } }@@ -443,11 +446,15 @@ void nfsd_file_net_dispose(struct nfsd_net *nn)for (i =0 ; i <8 && !list_empty (&l->freeme); i++)list_move (l->freeme.next, &dispose);spin_unlock (&l->lock); -if (!list_empty (&l->freeme)) +if (!list_empty (&l->freeme)) { +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);/* Wake up another thread to share the work * *before* doing any actual disposing. */ -svc_wake_up (nn->nfsd_serv); +svc_wake_up (serv); +nfsd_serv_put (nn, srcu_idx); + }nfsd_file_dispose_list (&dispose); } }fs/nfsd/netns.h +0
-1@@ -139,8 +139,14 @@ struct nfsd_net {u32 clverifier_counter;struct svc_info nfsd_info; -#define nfsd_serv nfsd_info.serv
fs/nfsd/netns.h struct nfsd_net { · line 150
Quoted 10 lines
fs/nfsd/netns.h +8
-1- +/* +* The current 'nfsd_serv' at nfsd_info.serv. Using 'void' rather than +* 'struct svc_serv' to guard against new code dereferencing nfsd_serv +* without using proper synchronization. +* Use nfsd_serv_get() or take nfsd_mutex to dereference. +*/ +void __rcu *nfsd_serv; +struct srcu_struct nfsd_serv_srcu;
srcu_struct is not tiny. I think it would make sense to use a global struct for all net namespaces.
Most users do seem to be embed them in some other structure - but not all.... kfd_processes_srcu stm_source_srcu
Thanks,
NeilBrown
Re: [PATCH v6 15/18] nfsd: use SRCU to dereference nn->nfsd_serv
Quoted 66 lines · NeilBrown
Quoted 65 lines · Mike Snitzer
Introduce
nfsd_serv_get,nfsd_serv_putandnfsd_serv_syncand update the nfsd code to preventnfsd_destroy_servfrom destroyingnn->nfsd_servuntil all nfsd code is done with it (particularly the localio code that doesn't run in the context of nfsd's svc threads, nor does it take thenfsd_mutex).Commit
83d5e5b0af90("dm: optimize use SRCU and RCU") provided a familiar well-worn pattern for how implement.Suggested-by NeilBrown <[email protected]>Signed-off-by Mike Snitzer <[email protected]>--- fs/nfsd/filecache.c | 13 ++++++++--- fs/nfsd/netns.h | 14 ++++++++++-- fs/nfsd/nfs4state.c | 25 ++++++++++++++------- fs/nfsd/nfsctl.c | 7 ++++-- fs/nfsd/nfssvc.c | 54 ++++++++++++++++++++++++++++++++++++--------- 5 files changed, 88 insertions(+), 25 deletions(-)fs/nfsd/filecache.c +10
-3@@ -413,12 +413,15 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose)struct nfsd_file *nf =list_first_entry (dispose, struct nfsd_file, nf_lru);struct nfsd_net *nn =net_generic (nf->nf_net, nfsd_net_id); +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);struct nfsd_fcache_disposal *l = nn->fcache_disposal;spin_lock (&l->lock);list_move_tail (&nf->nf_lru, &l->freeme);spin_unlock (&l->lock); -svc_wake_up (nn->nfsd_serv); +svc_wake_up (serv); +nfsd_serv_put (nn, srcu_idx); } }@@ -443,11 +446,15 @@ void nfsd_file_net_dispose(struct nfsd_net *nn)for (i =0 ; i <8 && !list_empty (&l->freeme); i++)list_move (l->freeme.next, &dispose);spin_unlock (&l->lock); -if (!list_empty (&l->freeme)) +if (!list_empty (&l->freeme)) { +int srcu_idx; +struct svc_serv *serv =nfsd_serv_get (nn, &srcu_idx);/* Wake up another thread to share the work * *before* doing any actual disposing. */ -svc_wake_up (nn->nfsd_serv); +svc_wake_up (serv); +nfsd_serv_put (nn, srcu_idx); + }nfsd_file_dispose_list (&dispose); } }fs/nfsd/netns.h +0
-0@@ -139,8 +139,14 @@ struct nfsd_net {u32 clverifier_counter;
Quoted 15 lines
fs/nfsd/netns.h struct nfsd_net { · line 150
Quoted 12 lines
fs/nfsd/netns.h +8
-2struct svc_info nfsd_info; -#define nfsd_serv nfsd_info.serv - +/* +* The current 'nfsd_serv' at nfsd_info.serv. Using 'void' rather than +* 'struct svc_serv' to guard against new code dereferencing nfsd_serv +* without using proper synchronization. +* Use nfsd_serv_get() or take nfsd_mutex to dereference. +*/ +void __rcu *nfsd_serv; +struct srcu_struct nfsd_serv_srcu;
srcu_structis not tiny. I think it would make sense to use a global struct for all net namespaces.
Right, definitely _not_ tiny.
Quoted 2 lines
Most users do seem to be embed them in some other structure - but not all....
kfd_processes_srcustm_source_srcu
I haven't used a global SRCU (DEFINE_SRCU, etc) for multiple objects before. I'll look closer but this won't be addressed in v7.
Thanks,
Mike
PATCH v6 16/18 nfsd/localio: use SRCU to dereference nn->nfsd_serv in nfsd_open_local_fh
In reply to Mike SnitzerUse nfsd_serv_get to SRCU deference nn->nfsd_serv and pass the resulting svc_serv to nfsd_local_fakerqst_create, open the file handle and then drop the reference using nfsd_serv_put at the end of nfsd_open_local_fh.
Verified to fix an easy to hit crash that would occur if an nfsd instance running in a container, with a localio client mounted, is shutdown. Upon restart of the container and associated nfsd the client would go on to crash due to NULL pointer dereference that occuured due to the nfs client's localio attempting to nfsd_open_local_fh(), using nn->nfsd_serv, without having a proper reference on nn->nfsd_serv.
--- fs/nfsd/localio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfsd/localio.c +3 -1
@@ -193,6 +193,7 @@ int nfsd_open_local_fh(struct net *net,struct nfsd_file *nf;int status =0 ;int mayflags =NFSD_MAY_LOCALIO ; +int srcu_idx;struct svc_serv *serv;__be32 beres;
@@ -207,7 +208,7 @@ int nfsd_open_local_fh(struct net *net, } nn =net_generic (net, nfsd_net_id); - serv =READ_ONCE (nn->nfsd_serv); + serv =nfsd_serv_get (nn, &srcu_idx);if (unlikely (!serv)) {dprintk ("%s: localio denied. Server not running\n" , __func__); status = -ENXIO ;
@@ -247,6 +248,7 @@ int nfsd_open_local_fh(struct net *net, out_revertcred:revert_creds (save_cred); out_net: +nfsd_serv_put (nn, srcu_idx);put_net (net);return status; }
Signature · 1 line
2.44.0
PATCH v6 17/18 nfs: add Documentation/filesystems/nfs/localio.rst
In reply to Mike SnitzerThis document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rst
Documentation/filesystems/nfs/localio.rst new file +148 -0
@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1; + version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs: + +From fs/nfsd/xdr.h + +struct nfsd_getuuidres { + __be32 status; + uuid_t uuid; +}; + +From include/linux/nfs_xdr.h + +struct nfs_getuuidres { + __u8 * uuid; +}; + +The client ultimately decodes this XDR using: +xdr_stream_decode_opaque_fixed(xdr, result->uuid, UUID_SIZE); + +NFS Common and Server +--------------------- + +First use is in nfsd, to add access to a global nfsd_uuids list in +nfs_common that is used to register and then identify local nfsd +instances. + +nfsd_uuids is protected by the nfsd_mutex or RCU read lock and is +composed of nfsd_uuid_t instances that are managed as nfsd creates them +(per network namespace). + +nfsd_uuid_is_local() and nfsd_uuid_lookup() are used to search all local +nfsd for the client specified nfsd uuid. + +The nfsd_uuids list is the basis for localio enablement, as such it has +members that point to nfsd memory for direct use by the client +(e.g. 'net' is the server's network namespace, through it the client can +access nn->nfsd_serv with proper rcu read access). It is this client +and server synchronization that enables advanced usage and lifetime of +objects to span from the host kernel's nfsd to per-container knfsd +instances that are connected to nfs client's running on the same local +host. + +NFS Client +---------- + +fs/nfs/localio.c:nfs_local_probe() will retrieve a server's uuid via +LOCALIO protocol and check if the server with that uuid is known to be +local. This ensures client and server 1: support localio 2: are local +to each other. + +See fs/nfs/localio.c:nfs_local_open_fh() and +fs/nfsd/localio.c:nfsd_open_local_fh() for the interface that makes +focused use of nfsd_uuid_t struct to allow a client local to a server to +open a file pointer without needing to go over the network. + +The client's fs/nfs/localio.c:nfs_local_open_fh() will call into the +server's fs/nfsd/localio.c:nfsd_open_local_fh() and carefully access +both the nfsd network namespace and the associated nn->nfsd_serv in +terms of RCU. If nfsd_open_local_fh() finds that client no longer sees +valid nfsd objects (be it struct net or nn->nfsd_serv) it return ENXIO +to nfs_local_open_fh() and the client will try to reestablish the +LOCALIO resources needed by calling nfs_local_probe() again. This +recovery is needed if/when an nfsd instance running in a container were +to reboot while a localio client is connected to it. + +Testing +------- + +The LOCALIO auxiliary protocol and associated NFS localio read, right +and commit access have proven stable against various test scenarios but +these have not yet been formalized in any testsuite: + +- Client and server both on localhost (for both v3 and v4.2). + +- Various permutations of client and server support enablement for + both local and remote client and server. Testing against NFS storage + products that don't support the LOCALIO protocol was also performed. + +- Client on host, server within a container (for both v3 and v4.2) + The container testing was in terms of podman managed containers and + includes container stop/restart scenario.
include/linux/nfslocalio.h +2 -0
@@ -20,6 +20,8 @@ extern struct list_head nfsd_uuids;* Each nfsd instance has an nfsd_uuid_t that is accessible through the * global nfsd_uuids list. Useful to allow a client to negotiate if localio * possible with its server. +* +* See Documentation/filesystems/nfs/localio.rst for more detail. */ typedef struct { uuid_t uuid;
Signature · 1 line
2.44.0
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;
Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:
Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
/* raw RFC 9562 UUID */
#define UUID_SIZE 16
typedef u8 uuid_t<UUID_SIZE>;
union GETUUID1res switch (uint32 status) {
case 0:
uuid_t uuid;
default:
void;
};program NFS_LOCALIO_PROGRAM {
version LOCALIO_V1 {
void
NULL(void) = 0;
GETUUID1res
GETUUID(void) = 1;
} = 1;
} = 0x20000002;Then you need to discuss transport considerations:
- Whether this protocol is registered with the server's rpcbind service,
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).
Should it be supported on port 20049 with RDMA as well?
Quoted 59 lines
Documentation/filesystems/nfs/localio.rst new file +59
-0+ +From fs/nfsd/xdr.h + +struct nfsd_getuuidres { + __be32 status; + uuid_t uuid; +}; + +From include/linux/nfs_xdr.h + +struct nfs_getuuidres { + __u8 * uuid; +}; + +The client ultimately decodes this XDR using: +xdr_stream_decode_opaque_fixed(xdr, result->uuid, UUID_SIZE); + +NFS Common and Server +--------------------- + +First use is in nfsd, to add access to a global nfsd_uuids list in +nfs_common that is used to register and then identify local nfsd +instances. + +nfsd_uuids is protected by the nfsd_mutex or RCU read lock and is +composed of nfsd_uuid_t instances that are managed as nfsd creates them +(per network namespace). + +nfsd_uuid_is_local() and nfsd_uuid_lookup() are used to search all local +nfsd for the client specified nfsd uuid. + +The nfsd_uuids list is the basis for localio enablement, as such it has +members that point to nfsd memory for direct use by the client +(e.g. 'net' is the server's network namespace, through it the client can +access nn->nfsd_serv with proper rcu read access). It is this client +and server synchronization that enables advanced usage and lifetime of +objects to span from the host kernel's nfsd to per-container knfsd +instances that are connected to nfs client's running on the same local +host. + +NFS Client +---------- + +fs/nfs/localio.c:nfs_local_probe() will retrieve a server's uuid via +LOCALIO protocol and check if the server with that uuid is known to be +local. This ensures client and server 1: support localio 2: are local +to each other. + +See fs/nfs/localio.c:nfs_local_open_fh() and +fs/nfsd/localio.c:nfsd_open_local_fh() for the interface that makes +focused use of nfsd_uuid_t struct to allow a client local to a server to +open a file pointer without needing to go over the network. + +The client's fs/nfs/localio.c:nfs_local_open_fh() will call into the +server's fs/nfsd/localio.c:nfsd_open_local_fh() and carefully access +both the nfsd network namespace and the associated nn->nfsd_serv in +terms of RCU. If nfsd_open_local_fh() finds that client no longer sees +valid nfsd objects (be it struct net or nn->nfsd_serv) it return ENXIO +to nfs_local_open_fh() and the client will try to reestablish the
Documentation/filesystems/nfs/localio.rst line 138
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+LOCALIO resources needed by calling nfs_local_probe() again. This +recovery is needed if/when an nfsd instance running in a container were +to reboot while a localio client is connected to it. + +Testing +------- + +The LOCALIO auxiliary protocol and associated NFS localio read, right +and commit access have proven stable against various test scenarios but +these have not yet been formalized in any testsuite:
Is there anywhere that describes what is needed to set up clients and a server to do local I/O? Then running the usual suite of NFS tests on that set up and comparing the nfsstat output on the local and remote clients should be a basic "smoke test" kind of thing that maintainers can use as a check-in test.
Quoted 26 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ +- Client and server both on localhost (for both v3 and v4.2). + +- Various permutations of client and server support enablement for + both local and remote client and server. Testing against NFS storage + products that don't support the LOCALIO protocol was also performed. + +- Client on host, server within a container (for both v3 and v4.2) + The container testing was in terms of podman managed containers and + includes container stop/restart scenario.include/linux/nfslocalio.h +2
-0@@ -20,6 +20,8 @@ extern struct list_head nfsd_uuids;* Each nfsd instance has an nfsd_uuid_t that is accessible through the * global nfsd_uuids list. Useful to allow a client to negotiate if localio * possible with its server. +* +* See Documentation/filesystems/nfs/localio.rst for more detail. */ typedef struct { uuid_t uuid;Signature · 1 line
2.44.0
Signature · 1 line
Chuck Lever
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 116 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
case 0:uuid_t uuid; default: void; };
Quoted 9 lines
program NFS_LOCALIO_PROGRAM {
version LOCALIO_V1 {
void
NULL(void) = 0;
GETUUID1res
GETUUID(void) = 1;
} = 1;
} = 0x20000002;Thanks for this, nice to see I wasn't too far off.
Quoted 4 lines
Then you need to discuss transport considerations:
- Whether this protocol is registered with the server's rpcbind service,
It isn't, should it be? Not familiar with what needs updating to do it, but happy to work through it.
Quoted 3 lines
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).
Correct.
Quoted 1 line
Should it be supported on port 20049 with RDMA as well?
Unless there is some additional code needed, I don't see why it wouldn't. But I haven't tested it (will look at NFS's RDMA support and wrap my head around it).
Quoted 4 lines
Quoted 4 lines
Documentation/filesystems/nfs/localio.rst new file +4
-0+Testing +------- + +The LOCALIO auxiliary protocol and associated NFS localio read, right
Quoted 8 lines
Documentation/filesystems/nfs/localio.rst line 138
Quoted 2 lines
Documentation/filesystems/nfs/localio.rst new file +2
-0+and commit access have proven stable against various test scenarios but +these have not yet been formalized in any testsuite:Is there anywhere that describes what is needed to set up clients and a server to do local I/O? Then running the usual suite of NFS tests on that set up and comparing the nfsstat output on the local and remote clients should be a basic "smoke test" kind of thing that maintainers can use as a check-in test.
I just figured running nfsd and nfs client connecting to that localhost was obvious. But I can fill in more howto like info in this section.
What is "the usual suite of NFS tests"? I should run them ;)
(apologies if there is well established docs with pointers, still learning to fish, thanks for your help!)
Mike
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 129 lines · Mike Snitzer
Quoted 116 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
case 0:uuid_t uuid; default: void; };Quoted 9 lines
program NFS_LOCALIO_PROGRAM { version LOCALIO_V1 { void NULL(void) = 0; GETUUID1res GETUUID(void) = 1; } = 1; } = 0x20000002;Thanks for this, nice to see I wasn't too far off.
Quoted 7 lines
Quoted 4 lines
Then you need to discuss transport considerations:
- Whether this protocol is registered with the server's rpcbind service,
It isn't, should it be? Not familiar with what needs updating to do it, but happy to work through it.
Well the issue is whether a client can assume that LOCALIO will always be running on a fixed port. Which, IIUC, it will be. So I don't think registration is needed. The protocol spec needs to state that the LOCALIO server port is fixed, and that makes rpcbind registration optional.
Quoted 11 lines
Quoted 3 lines
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).
Correct.
Quoted 1 line
Should it be supported on port 20049 with RDMA as well?
Unless there is some additional code needed, I don't see why it wouldn't. But I haven't tested it (will look at NFS's RDMA support and wrap my head around it).
Head-wrapping NFS/RDMA is a multi-year project :-)
You probably do want to have LOCALIO available for NFS/RDMA connections. I'm not sure that requires extra code. I don't recall clearly, but I think there isn't anything extra done for NFSACL, for example.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Documentation/filesystems/nfs/localio.rst new file +4
-0+Testing +------- + +The LOCALIO auxiliary protocol and associated NFS localio read, rightQuoted 8 lines
Documentation/filesystems/nfs/localio.rst line 138
Quoted 2 lines
Documentation/filesystems/nfs/localio.rst new file +2
-0+and commit access have proven stable against various test scenarios but +these have not yet been formalized in any testsuite:Is there anywhere that describes what is needed to set up clients and a server to do local I/O? Then running the usual suite of NFS tests on that set up and comparing the nfsstat output on the local and remote clients should be a basic "smoke test" kind of thing that maintainers can use as a check-in test.
Quoted 5 lines
I just figured running nfsd and nfs client connecting to that localhost was obvious. But I can fill in more howto like info in this section.
What is "the usual suite of NFS tests"? I should run them ;)
Start with the cthon04 suite. We all seem to use fstests too. There are some others, but these should be sufficient for your purposes.
Signature · 1 line
Chuck Lever
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
In reply to Chuck LeverQuoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
I don't think we need the NULL procedure either, but that is such a deeply entrenched practice I won't argue the point.
Quoted 18 lines
case 0:
uuid_t uuid; default: void; };program NFS_LOCALIO_PROGRAM { version LOCALIO_V1 { void NULL(void) = 0; GETUUID1res GETUUID(void) = 1; } = 1; } = 0x20000002;Then you need to discuss transport considerations:
Quoted 7 lines
- Whether this protocol is registered with the server's rpcbind service,
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).Should it be supported on port 20049 with RDMA as well?
I don't think we should be that explicit. We should way that requests are sent to the same destination as the associated NFS requests. No mention of transports or addresses or ports.
NeilBrown
Quoted 109 lines
Quoted 61 lines
Documentation/filesystems/nfs/localio.rst new file +59
-0+ +From fs/nfsd/xdr.h + +struct nfsd_getuuidres { + __be32 status; + uuid_t uuid; +}; + +From include/linux/nfs_xdr.h + +struct nfs_getuuidres { + __u8 * uuid; +}; + +The client ultimately decodes this XDR using: +xdr_stream_decode_opaque_fixed(xdr, result->uuid, UUID_SIZE); + +NFS Common and Server +--------------------- + +First use is in nfsd, to add access to a global nfsd_uuids list in +nfs_common that is used to register and then identify local nfsd +instances. + +nfsd_uuids is protected by the nfsd_mutex or RCU read lock and is +composed of nfsd_uuid_t instances that are managed as nfsd creates them +(per network namespace). + +nfsd_uuid_is_local() and nfsd_uuid_lookup() are used to search all local +nfsd for the client specified nfsd uuid. + +The nfsd_uuids list is the basis for localio enablement, as such it has +members that point to nfsd memory for direct use by the client +(e.g. 'net' is the server's network namespace, through it the client can +access nn->nfsd_serv with proper rcu read access). It is this client +and server synchronization that enables advanced usage and lifetime of +objects to span from the host kernel's nfsd to per-container knfsd +instances that are connected to nfs client's running on the same local +host. + +NFS Client +---------- + +fs/nfs/localio.c:nfs_local_probe() will retrieve a server's uuid via +LOCALIO protocol and check if the server with that uuid is known to be +local. This ensures client and server 1: support localio 2: are local +to each other. + +See fs/nfs/localio.c:nfs_local_open_fh() and +fs/nfsd/localio.c:nfsd_open_local_fh() for the interface that makes +focused use of nfsd_uuid_t struct to allow a client local to a server to +open a file pointer without needing to go over the network. + +The client's fs/nfs/localio.c:nfs_local_open_fh() will call into the +server's fs/nfsd/localio.c:nfsd_open_local_fh() and carefully access +both the nfsd network namespace and the associated nn->nfsd_serv in +terms of RCU. If nfsd_open_local_fh() finds that client no longer sees +valid nfsd objects (be it struct net or nn->nfsd_serv) it return ENXIO +to nfs_local_open_fh() and the client will try to reestablish theDocumentation/filesystems/nfs/localio.rst line 138
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+LOCALIO resources needed by calling nfs_local_probe() again. This +recovery is needed if/when an nfsd instance running in a container were +to reboot while a localio client is connected to it. + +Testing +------- + +The LOCALIO auxiliary protocol and associated NFS localio read, right +and commit access have proven stable against various test scenarios but +these have not yet been formalized in any testsuite:Is there anywhere that describes what is needed to set up clients and a server to do local I/O? Then running the usual suite of NFS tests on that set up and comparing the nfsstat output on the local and remote clients should be a basic "smoke test" kind of thing that maintainers can use as a check-in test.
Quoted 26 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ +- Client and server both on localhost (for both v3 and v4.2). + +- Various permutations of client and server support enablement for + both local and remote client and server. Testing against NFS storage + products that don't support the LOCALIO protocol was also performed. + +- Client on host, server within a container (for both v3 and v4.2) + The container testing was in terms of podman managed containers and + includes container stop/restart scenario.include/linux/nfslocalio.h +2
-0@@ -20,6 +20,8 @@ extern struct list_head nfsd_uuids;* Each nfsd instance has an nfsd_uuid_t that is accessible through the * global nfsd_uuids list. Useful to allow a client to negotiate if localio * possible with its server. +* +* See Documentation/filesystems/nfs/localio.rst for more detail. */ typedef struct { uuid_t uuid;Signature · 1 line
2.44.0Signature · 1 line
Chuck Lever
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:nfs3svc_encode_getuuidres and nfs4svc_encode_getuuidres. nfs3_xdr_dec_getuuidres and nfs4_xdr_dec_getuuidres (and note the FIXME comment about abusing nfs_opnum4).
Not sure how the reality of piggbacking on NFS XDR should be captured in the protocol spec here.
Quoted 2 lines
I don't think we need the NULL procedure either, but that is such a deeply entrenched practice I won't argue the point.
The code required it be there, I unfortunately don't recall specifics on what failed if it wasn't there (may have been rpc_bind_new_program).
Quoted 24 lines
Quoted 24 lines
case 0:
uuid_t uuid; default: void; };program NFS_LOCALIO_PROGRAM { version LOCALIO_V1 { void NULL(void) = 0; GETUUID1res GETUUID(void) = 1; } = 1; } = 0x20000002;Then you need to discuss transport considerations:
- Whether this protocol is registered with the server's rpcbind service,
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).
Quoted 5 lines
Quoted 1 line
Should it be supported on port 20049 with RDMA as well?
I don't think we should be that explicit. We should way that requests are sent to the same destination as the associated NFS requests. No mention of transports or addresses or ports.
OK, I agree.
Thanks,
Mike
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 116 lines · Mike Snitzer
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
Quoted 7 lines
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:
nfs3svc_encode_getuuidresandnfs4svc_encode_getuuidres.nfs3_xdr_dec_getuuidresandnfs4_xdr_dec_getuuidres(and note the FIXME comment about abusingnfs_opnum4).
No, let's not piggyback like that. Please make it a separate XDR implementation just like NFSACL is. Again, LOCALIO is not an extension of the NFS protocol. Making that claim confuses people for whom the term "extension" has a very precise meaning. If we were extending NFS, then yes, adding the new procedures to the NFS XDR implementation is appropriate, but that's not what you are doing: you are adding a new side-band protocol.
I have a long-term goal to ensure we can generate the source code of the XDR layer of all the kernel RPC protocols via an rpcgen like tool. A code generator can ensure that the marshalling and unmarshalling code is memory-safe.
By piggybacking, you are building LOCALIO into another protocol's XDR implementation, which makes it a special case, and thus harder to implement via code that is generated automatically from unmodified XDR language specs.
Maybe the client side maintainers don't care about that, but please don't piggyback LOCALIO onto the NFSD's NFS XDR implementation.
Then, if it's a separate implementation, you can remove the status code. I was wondering why the server would reply with an error. If LOCALIO/GETUUID is not supported, then an RPC level error occurs anyway.
If you think you need an error like "Yes, I recognize that program and procedure, but this file system doesn't allow local access in any case" then that needs to be added to the protocol XDR specification.
Quoted 2 lines
Not sure how the reality of piggbacking on NFS XDR should be captured in the protocol spec here.
It's an implementation choice, so it doesn't belong in the protocol spec that, again, lays out only on-the-wire behavior,.
Implementation specifics can be discussed in another section of the document.
Quoted 5 lines
Quoted 2 lines
I don't think we need the NULL procedure either, but that is such a deeply entrenched practice I won't argue the point.
The code required it be there, I unfortunately don't recall specifics on what failed if it wasn't there (may have been
rpc_bind_new_program).
Please leave the NULL procedure where it is. Note that the NFS program's NULL procedure is used in two rather significant ways:
- As a carrier for GSSAPI messages
- As a probe for the RPC-with-TLS capability
The latter might be significant if a client sends a LOCALIO operation as the first RPC procedure when contacting an unfamiliar server -- if it wants TLS protection for that procedure, then it will need to send a NULL(RPC_AUTH_TLS) as the very first RPC transaction.
Since LOCALIO/GETUUID is going over the network sometimes, it's reasonable to expect that these security measures could be used.
Quoted 31 lines
Quoted 24 lines
Quoted 24 lines
case 0:
uuid_t uuid; default: void; };program NFS_LOCALIO_PROGRAM { version LOCALIO_V1 { void NULL(void) = 0; GETUUID1res GETUUID(void) = 1; } = 1; } = 0x20000002;Then you need to discuss transport considerations:
- Whether this protocol is registered with the server's rpcbind service,
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).Quoted 5 lines
Quoted 1 line
Should it be supported on port 20049 with RDMA as well?
I don't think we should be that explicit. We should way that requests are sent to the same destination as the associated NFS requests. No mention of transports or addresses or ports.
OK, I agree.
Signature · 1 line
Chuck Lever
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 125 lines · Chuck Lever
Quoted 116 lines · Mike Snitzer
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
Quoted 7 lines
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:
nfs3svc_encode_getuuidresandnfs4svc_encode_getuuidres.nfs3_xdr_dec_getuuidresandnfs4_xdr_dec_getuuidres(and note the FIXME comment about abusingnfs_opnum4).
Quoted 7 lines
No, let's not piggyback like that. Please make it a separate XDR implementation just like NFSACL is. Again, LOCALIO is not an extension of the NFS protocol. Making that claim confuses people for whom the term "extension" has a very precise meaning. If we were extending NFS, then yes, adding the new procedures to the NFS XDR implementation is appropriate, but that's not what you are doing: you are adding a new side-band protocol.
I'm currently working through the LOCALIO protocol code to make it a single version rather than '3' and '4'. In the process I'm making it completely separate from the NFS protocol implementation and cleaning up some other bits. e.g. it shouldn't register with rpcbind.
I'll hopefully post patches in a few hours. I writing this now to discourage Mike from starting work on this.
NeilBrown
Quoted 94 lines
I have a long-term goal to ensure we can generate the source code of the XDR layer of all the kernel RPC protocols via an rpcgen like tool. A code generator can ensure that the marshalling and unmarshalling code is memory-safe.
By piggybacking, you are building LOCALIO into another protocol's XDR implementation, which makes it a special case, and thus harder to implement via code that is generated automatically from unmodified XDR language specs.
Maybe the client side maintainers don't care about that, but please don't piggyback LOCALIO onto the NFSD's NFS XDR implementation.
Then, if it's a separate implementation, you can remove the status code. I was wondering why the server would reply with an error. If LOCALIO/GETUUID is not supported, then an RPC level error occurs anyway.
If you think you need an error like "Yes, I recognize that program and procedure, but this file system doesn't allow local access in any case" then that needs to be added to the protocol XDR specification.
Quoted 2 lines
Not sure how the reality of piggbacking on NFS XDR should be captured in the protocol spec here.
It's an implementation choice, so it doesn't belong in the protocol spec that, again, lays out only on-the-wire behavior,.
Implementation specifics can be discussed in another section of the document.
Quoted 5 lines
Quoted 2 lines
I don't think we need the NULL procedure either, but that is such a deeply entrenched practice I won't argue the point.
The code required it be there, I unfortunately don't recall specifics on what failed if it wasn't there (may have been
rpc_bind_new_program).Please leave the NULL procedure where it is. Note that the NFS program's NULL procedure is used in two rather significant ways:
- As a carrier for GSSAPI messages
- As a probe for the RPC-with-TLS capabilityThe latter might be significant if a client sends a LOCALIO operation as the first RPC procedure when contacting an unfamiliar server -- if it wants TLS protection for that procedure, then it will need to send a
NULL(RPC_AUTH_TLS)as the very first RPC transaction.Since LOCALIO/GETUUID is going over the network sometimes, it's reasonable to expect that these security measures could be used.
Quoted 31 lines
Quoted 24 lines
Quoted 24 lines
case 0:
uuid_t uuid; default: void; };program NFS_LOCALIO_PROGRAM { version LOCALIO_V1 { void NULL(void) = 0; GETUUID1res GETUUID(void) = 1; } = 1; } = 0x20000002;Then you need to discuss transport considerations:
- Whether this protocol is registered with the server's rpcbind service,
- Which TCP/UDP port number does it use? Assuming 2049, and that it will appear on the same transport connection as NFS traffic (just like NFACL).Quoted 5 lines
Quoted 1 line
Should it be supported on port 20049 with RDMA as well?
I don't think we should be that explicit. We should way that requests are sent to the same destination as the associated NFS requests. No mention of transports or addresses or ports.
OK, I agree.
Signature · 1 line
Chuck Lever
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 134 lines · NeilBrown
Quoted 125 lines · Chuck Lever
Quoted 116 lines · Mike Snitzer
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
Quoted 7 lines
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:
nfs3svc_encode_getuuidresandnfs4svc_encode_getuuidres.nfs3_xdr_dec_getuuidresandnfs4_xdr_dec_getuuidres(and note the FIXME comment about abusingnfs_opnum4).Quoted 7 lines
No, let's not piggyback like that. Please make it a separate XDR implementation just like NFSACL is. Again, LOCALIO is not an extension of the NFS protocol. Making that claim confuses people for whom the term "extension" has a very precise meaning. If we were extending NFS, then yes, adding the new procedures to the NFS XDR implementation is appropriate, but that's not what you are doing: you are adding a new side-band protocol.
Quoted 7 lines
I'm currently working through the LOCALIO protocol code to make it a single version rather than '3' and '4'. In the process I'm making it completely separate from the NFS protocol implementation and cleaning up some other bits. e.g. it shouldn't register with rpcbind.
I'll hopefully post patches in a few hours. I writing this now to discourage Mike from starting work on this.
Cool, thanks Neil!
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 140 lines · Mike Snitzer
Quoted 139 lines · NeilBrown
Quoted 125 lines · Chuck Lever
Quoted 116 lines · Mike Snitzer
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
Quoted 7 lines
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:
nfs3svc_encode_getuuidresandnfs4svc_encode_getuuidres.nfs3_xdr_dec_getuuidresandnfs4_xdr_dec_getuuidres(and note the FIXME comment about abusingnfs_opnum4).Quoted 7 lines
No, let's not piggyback like that. Please make it a separate XDR implementation just like NFSACL is. Again, LOCALIO is not an extension of the NFS protocol. Making that claim confuses people for whom the term "extension" has a very precise meaning. If we were extending NFS, then yes, adding the new procedures to the NFS XDR implementation is appropriate, but that's not what you are doing: you are adding a new side-band protocol.
I'm currently working through the LOCALIO protocol code to make it a single version rather than '3' and '4'. In the process I'm making it completely separate from the NFS protocol implementation and cleaning up some other bits. e.g. it shouldn't register with rpcbind.
Quoted 4 lines
Quoted 2 lines
I'll hopefully post patches in a few hours. I writing this now to discourage Mike from starting work on this.
Cool, thanks Neil!
Oh, please base your changes on my latest nfs-localio-for-6.11 branch:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-6.11
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
In reply to Chuck LeverQuoted 125 lines · Chuck Lever
Quoted 116 lines · Mike Snitzer
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>--- Documentation/filesystems/nfs/localio.rst | 148 ++++++++++++++++++++++ include/linux/nfslocalio.h | 2 + 2 files changed, 150 insertions(+) create mode 100644 Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
Quoted 7 lines
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:
nfs3svc_encode_getuuidresandnfs4svc_encode_getuuidres.nfs3_xdr_dec_getuuidresandnfs4_xdr_dec_getuuidres(and note the FIXME comment about abusingnfs_opnum4).
Quoted 7 lines
No, let's not piggyback like that. Please make it a separate XDR implementation just like NFSACL is. Again, LOCALIO is not an extension of the NFS protocol. Making that claim confuses people for whom the term "extension" has a very precise meaning. If we were extending NFS, then yes, adding the new procedures to the NFS XDR implementation is appropriate, but that's not what you are doing: you are adding a new side-band protocol.
I reworded yesterday, when you seized on my saying "extension" in the Documentation before and I changed it to "auxilliary" (I used "extension" because that's how NFS ACL was framed, I had no idea it was a loaded or nuanced term). localio the protocol amounts to a single RPC, no idea why I need to implement/duplicate a bunch of boilerplate code to add a single GETUUID RPC. Localio as submitted isn't concerned with some weird hijacking/extension of the NFS protocol, it is enabling the NFS client and server to be more efficient with how it fulfills IO. Localio has no tie to NFS other than it serves as connective glue between the NFS client and server to optimize reads, writes, and commits.
Quoted 4 lines
I have a long-term goal to ensure we can generate the source code of the XDR layer of all the kernel RPC protocols via an rpcgen like tool. A code generator can ensure that the marshalling and unmarshalling code is memory-safe.
The code doesn't show itself to be developed with such code generation at all. If anything it all feels very open-coded.
Quoted 4 lines
By piggybacking, you are building LOCALIO into another protocol's XDR implementation, which makes it a special case, and thus harder to implement via code that is generated automatically from unmodified XDR language specs.
GETUUID really couldn't be simpler. I'll do whatever you think best, but I just want to be clear: when told to implement a side-band protocol to coordinate I distilled it down to "I need a unique UUID from the server" (hence GETUUID). When implementing it I set out to work with what I saw in the existing code -- not reinvent boilerplate code. NFS ACL did that. If I went further by (ab)using NFS xdr helpers it was because I didn't want to write that code. If asked to decouple, I'm just going to factor out cleaner code that LOCALIO and NFS share to do what I already have it doing.
Quoted 8 lines
Maybe the client side maintainers don't care about that, but please don't piggyback LOCALIO onto the NFSD's NFS XDR implementation.
Then, if it's a separate implementation, you can remove the status code. I was wondering why the server would reply with an error. If LOCALIO/GETUUID is not supported, then an RPC level error occurs anyway.
In my extensive discovery by trial and error I found that the NFS status codes and infrastructure necessary. Otherwise basic/advanced connectivity issues with sunrpc et al aren't accounted for properly. NFS is pretty tightly coupled to sunrpc, and vice-versa. Not following why things have all of a sudden gotten "heightened", guess I chose the wrong word ("piggybacking") when being very clear about what the LOCALIO protocol does: piggyback on NFS XDR methods. I'm really caught out for that being viewed as so bad (but my FIXME in nfs4_xdr_dec_getuuidres really does need fixing).
Quoted 4 lines
If you think you need an error like "Yes, I recognize that program and procedure, but this file system doesn't allow local access in any case" then that needs to be added to the protocol XDR specification.
The NFS status baked into NFS RPCs offer utility.
LOCALIO is not a standard, and we all agreed it doesn't need to be. But it obviously cannot be fragile, etc. SO I'm the new guy, happy to "suffer".. however I would like to suffer less for being an open-book about the code I've written and submitted ;)
Quoted 22 lines
Quoted 2 lines
Not sure how the reality of piggbacking on NFS XDR should be captured in the protocol spec here.
It's an implementation choice, so it doesn't belong in the protocol spec that, again, lays out only on-the-wire behavior,.
Implementation specifics can be discussed in another section of the document.
Quoted 5 lines
Quoted 2 lines
I don't think we need the NULL procedure either, but that is such a deeply entrenched practice I won't argue the point.
The code required it be there, I unfortunately don't recall specifics on what failed if it wasn't there (may have been
rpc_bind_new_program).Please leave the NULL procedure where it is. Note that the NFS program's NULL procedure is used in two rather significant ways:
- As a carrier for GSSAPI messages
- As a probe for the RPC-with-TLS capability
Quoted 8 lines
The latter might be significant if a client sends a LOCALIO operation as the first RPC procedure when contacting an unfamiliar server -- if it wants TLS protection for that procedure, then it will need to send a
NULL(RPC_AUTH_TLS)as the very first RPC transaction.Since LOCALIO/GETUUID is going over the network sometimes, it's reasonable to expect that these security measures could be used.
LOCALIO's GETUUID goes over the network all the time. And it literally needs to, and does, clone the NFS rpc client with:
rpc_bind_new_program(clp->cl_rpcclient
Mike
Re: [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst
Quoted 138 lines · Mike Snitzer
Quoted 125 lines · Chuck Lever
Quoted 116 lines · Mike Snitzer
Quoted 106 lines · NeilBrown
Quoted 105 lines · Chuck Lever
Quoted 86 lines · Mike Snitzer
This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server (both v3 and v4) to allow a client and server to reliably handshake to determine if they are on the same host. The LOCALIO auxiliary protocol's implementation, which uses the same connection as NFS traffic, follows the pattern established by the NFS ACL protocol extension.
The robust handshake between local client and server is just the beginning, the ultimate usecase this locality makes possible is the client is able to issue reads, writes and commits directly to the server without having to go over the network. This is particularly useful for container usecases (e.g. kubernetes) where it is possible to run an IO job local to the server.
Signed-off-by Mike Snitzer <[email protected]>---
Documentation/filesystems/nfs/localio.rst| 148 ++++++++++++++++++++++include/linux/nfslocalio.h| 2 +2 files changed, 150 insertions(+)create mode 100644
Documentation/filesystems/nfs/localio.rstDocumentation/filesystems/nfs/localio.rst new file +59
-0@@ -0,0 +1,148 @@ +=========== +NFS localio +=========== + +This document gives an overview of the LOCALIO auxiliary RPC protocol +added to the Linux NFS client and server (both v3 and v4) to allow a +client and server to reliably handshake to determine if they are on the +same host. The LOCALIO auxiliary protocol's implementation, which uses +the same connection as NFS traffic, follows the pattern established by +the NFS ACL protocol extension. + +The LOCALIO auxiliary protocol is needed to allow robust discovery of +clients local to their servers. Prior to this LOCALIO protocol a +fragile sockaddr network address based match against all local network +interfaces was attempted. But unlike the LOCALIO protocol, the +sockaddr-based matching didn't handle use of iptables or containers. + +The robust handshake between local client and server is just the +beginning, the ultimate usecase this locality makes possible is the +client is able to issue reads, writes and commits directly to the server +without having to go over the network. This is particularly useful for +container usecases (e.g. kubernetes) where it is possible to run an IO +job local to the server. + +The performance advantage realized from localio's ability to bypass +using XDR and RPC for reads, writes and commits can be extreme, e.g.: +fio for 20 secs with 24 libaio threads, 64k directio reads, qd of 8, +- With localio: + read: IOPS=691k, BW=42.2GiB/s (45.3GB/s)(843GiB/20002msec) +- Without localio: + read: IOPS=15.7k, BW=984MiB/s (1032MB/s)(19.2GiB/20013msec) + +RPC +--- + +The LOCALIO auxiliary RPC protocol consists of a single "GETUUID" RPC +method that allows the Linux nfs client to retrieve a Linux nfs server's +uuid. This protocol isn't part of an IETF standard, nor does it need to +be considering it is Linux-to-Linux auxiliary RPC protocol that amounts +to an implementation detail. + +The GETUUID method encodes the server's uuid_t in terms of the fixed +UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR +methods are used instead of the less efficient variable sized methods. + +The RPC program number for the NFS_LOCALIO_PROGRAM is currently defined +as 0x20000002 (but a request for a unique RPC program number assignment +has been submitted to IANA.org). + +The following approximately describes the LOCALIO in a pseudo rpcgen .x +syntax: + +#define UUID_SIZE 16 +typedef u8 uuid_t<UUID_SIZE>; + +program NFS_LOCALIO_PROGRAM { + version NULLVERS { + void NULL(void) = 0; + } = 1;Documentation/filesystems/nfs/localio.rst line 69
Quoted 10 lines
Documentation/filesystems/nfs/localio.rst new file +10
-0+ version GETUUIDVERS { + uuid_t GETUUID(void) = 1; + } = 1; +} = 0x20000002; + +The above is the skeleton for the LOCALIO protocol, it doesn't account +for NFS v3 and v4 RPC boilerplate (which also marshalls RPC status) that +is used to implement GETUUID. + +Here are the respective XDR results for nfsd and nfs:Hi Mike!
A protocol spec describes the on-the-wire data formats, not the in-memory structure layouts. The below C structures are not relevant to this specification. This should be all you need here, if I understand your protocol correctly:
Quoted 8 lines
Quoted 5 lines
/* raw RFC 9562 UUID */
#defineUUID_SIZE16
typedef u8 uuid_t<UUID_SIZE>;union GETUUID1res switch (uint32 status) {
I don't think we need a status in the protocol. GETUUID always returns a UUID. There is no possible error condition.
Quoted 7 lines
By having localio use NFS's XDR we're able to piggyback on a status being returned by standard NFS RPC handling.
See:
nfs3svc_encode_getuuidresandnfs4svc_encode_getuuidres.nfs3_xdr_dec_getuuidresandnfs4_xdr_dec_getuuidres(and note the FIXME comment about abusingnfs_opnum4).Quoted 7 lines
No, let's not piggyback like that. Please make it a separate XDR implementation just like NFSACL is. Again, LOCALIO is not an extension of the NFS protocol. Making that claim confuses people for whom the term "extension" has a very precise meaning. If we were extending NFS, then yes, adding the new procedures to the NFS XDR implementation is appropriate, but that's not what you are doing: you are adding a new side-band protocol.
Quoted 11 lines
I reworded yesterday, when you seized on my saying "extension" in the Documentation before and I changed it to "auxilliary" (I used "extension" because that's how NFS ACL was framed, I had no idea it was a loaded or nuanced term). localio the protocol amounts to a single RPC, no idea why I need to implement/duplicate a bunch of boilerplate code to add a single GETUUID RPC. Localio as submitted isn't concerned with some weird hijacking/extension of the NFS protocol, it is enabling the NFS client and server to be more efficient with how it fulfills IO. Localio has no tie to NFS other than it serves as connective glue between the NFS client and server to optimize reads, writes, and commits.
What I'm saying is please don't implement this as
nfs3_xdr_dec_getuuidres and nfs4_xdr_dec_getuuidres
GETUUID is not an NFS procedure, as you say. Just use:
localio1_xdr_dec_getuuidres
Program name and version, XDR decoder, result data type name. This is consistent with every other modern (ie, recently-written) XDR function.
Quoted 7 lines
Quoted 4 lines
I have a long-term goal to ensure we can generate the source code of the XDR layer of all the kernel RPC protocols via an rpcgen like tool. A code generator can ensure that the marshalling and unmarshalling code is memory-safe.
The code doesn't show itself to be developed with such code generation at all. If anything it all feels very open-coded.
That's correct, it was open-coded in the 90's because back then that was the way to build code that was fast.
These days, compilers and CPUs optimize the shit out of the code and instruction sequence so it matters much less what we do in our source files. Since this is a community-maintained effort, it makes sense to spend our effort to use the source code as documentation for the humans who have to read it and update it, anywhere the utmost speed is not a requirement.
In particular, right now there's no easy way to audit our XDR implementation and prove/verify that we have implemented exactly what the spec says. And, the open coded nature of this implementation means it is subject to memory bugs, which is bad for a widely deployed network protocol.
In user space, RPC developers almost always start with a .x file and use rpcgen to generate C (or Python) code to handle marshaling of arguments and results. That way, the XDR implementation starts with C code that comes directly from the specification, untouched by human hands.
We really need to take that approach in the kernel too. The only reason not to do that is because there is decades of technical debt baked into the current open coded implementation. But I've spent a lot of effort to move the server over to consistent and properly layered XDR functions so that converting it to use machine-generated XDR will be a burp rather than a heart attack. Lots of work yet to do.
Quoted 5 lines
Quoted 4 lines
By piggybacking, you are building LOCALIO into another protocol's XDR implementation, which makes it a special case, and thus harder to implement via code that is generated automatically from unmodified XDR language specs.
Quoted 9 lines
GETUUID really couldn't be simpler. I'll do whatever you think best, but I just want to be clear: when told to implement a side-band protocol to coordinate I distilled it down to "I need a unique UUID from the server" (hence GETUUID). When implementing it I set out to work with what I saw in the existing code -- not reinvent boilerplate code. NFS ACL did that. If I went further by (ab)using NFS xdr helpers it was because I didn't want to write that code. If asked to decouple, I'm just going to factor out cleaner code that LOCALIO and NFS share to do what I already have it doing.
That "clean shared code" is the RPC XDR layer. There's really no need to share any NFS-specific code between NFS and LOCALIO. Please have a look at include/linux/sunrpc/xdr.h for utility functions to use for XDR; I suspect you will find everything you need.
And I recommend having a look at
https://www.rfc-editor.org/rfc/rfc4506
for more detail about what XDR is and why we use it.
Quoted 4 lines
Quoted 4 lines
Maybe the client side maintainers don't care about that, but please don't piggyback LOCALIO onto the NFSD's NFS XDR implementation.
Quoted 8 lines
Quoted 4 lines
Then, if it's a separate implementation, you can remove the status code. I was wondering why the server would reply with an error. If LOCALIO/GETUUID is not supported, then an RPC level error occurs anyway.
In my extensive discovery by trial and error I found that the NFS status codes and infrastructure necessary. Otherwise basic/advanced connectivity issues with sunrpc et al aren't accounted for properly.
That is quite the opposite of my experience in this code base. Can you share an example of the connectivity issues you encountered?
Quoted 6 lines
NFS is pretty tightly coupled to sunrpc, and vice-versa. Not following why things have all of a sudden gotten "heightened", guess I chose the wrong word ("piggybacking") when being very clear about what the LOCALIO protocol does: piggyback on NFS XDR methods. I'm really caught out for that being viewed as so bad (but my FIXME in
nfs4_xdr_dec_getuuidresreally does need fixing).
Thanks for being clear about it, that is quite helpful. But I'd rather this was implemented the way every other RPC protocol is already done in the kernel. There's more than one reason to do it that way.
Quoted 6 lines
Quoted 4 lines
If you think you need an error like "Yes, I recognize that program and procedure, but this file system doesn't allow local access in any case" then that needs to be added to the protocol XDR specification.
The NFS status baked into NFS RPCs offer utility.
I'm agnostic about whether GETUUID1res has a status field or not... When Neil pointed it out, I was just requesting that we have a little more rationale for it than "the XDR layer seems to need this" because, IME, it doesn't.
Note that RPC allows a little extensibility: if you send an unrecognized procedure number, the RPC server will bark at you. So we can add new procedures without much difficulty; the client can tell if the server doesn't support them.
And if the argument or result data items have to change in existing procedures, then we create a new version of the RPC program.
So there isn't a strong need to add fields we think might be needed some day but don't have a use for now, even in a private non-standard protocol.
--
Chuck Lever
PATCH v6 18/18 nfs/nfsd: add Kconfig options to allow localio to be enabled
In reply to Mike SnitzerNow that all the localio code is complete, allow users to enable it.
--- fs/Kconfig | 3 +++ fs/nfs/Kconfig | 30 ++++++++++++++++++++++++++++++ fs/nfsd/Kconfig | 30 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+)
fs/Kconfig +3 -0
@@ -377,6 +377,9 @@ config NFS_ACL_SUPPORT tristate select FS_POSIX_ACL +config NFS_COMMON_LOCALIO_SUPPORT + tristate + config NFS_COMMON bool depends on NFSD || NFS_FS || LOCKD
fs/nfs/Kconfig +30 -0
@@ -1,10 +1,16 @@ # SPDX-License-Identifier: GPL-2.0-only + +config NFS_LOCALIO + tristate + config NFS_FS tristate "NFS client support" depends on INET && FILE_LOCKING && MULTIUSER select LOCKD select SUNRPC select NFS_ACL_SUPPORT if NFS_V3_ACL + select NFS_LOCALIO if NFS_V3_LOCALIO || NFS_V4_LOCALIO + select NFS_COMMON_LOCALIO_SUPPORT if NFS_LOCALIO help Choose Y here if you want to access files residing on other computers using Sun's Network File System protocol. To compile
@@ -72,6 +78,18 @@ config NFS_V3_ACL If unsure, say N. +config NFS_V3_LOCALIO + bool "NFS client support for the NFSv3 LOCALIO protocol extension" + depends on NFS_V3 + help + Some NFS servers support an auxiliary NFSv3 LOCALIO protocol + that is not an official part of the NFS version 3 protocol. + + This option enables support for version 3 of the LOCALIO + protocol in the kernel's NFS client. + + If unsure, say N. + config NFS_V4 tristate "NFS client support for NFS version 4" depends on NFS_FS
@@ -86,6 +104,18 @@ config NFS_V4 If unsure, say Y. +config NFS_V4_LOCALIO + bool "NFS client support for the NFSv4 LOCALIO protocol extension" + depends on NFS_V4 + help + Some NFS servers support an auxiliary NFSv4 LOCALIO protocol + that is not an official part of the NFS version 4 protocol. + + This option enables support for version 4 of the LOCALIO + protocol in the kernel's NFS client. + + If unsure, say N. + config NFS_SWAP bool "Provide swap over NFS support" default n
fs/nfsd/Kconfig +30 -0
@@ -1,4 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only + +config NFSD_LOCALIO + tristate + config NFSD tristate "NFS server support" depends on INET
@@ -9,6 +13,8 @@ config NFSD select EXPORTFS select NFS_ACL_SUPPORT if NFSD_V2_ACL select NFS_ACL_SUPPORT if NFSD_V3_ACL + select NFSD_LOCALIO if NFSD_V3_LOCALIO || NFSD_V4_LOCALIO + select NFS_COMMON_LOCALIO_SUPPORT if NFSD_LOCALIO depends on MULTIUSER help Choose Y here if you want to allow other computers to access
@@ -69,6 +75,18 @@ config NFSD_V3_ACL If unsure, say N. +config NFSD_V3_LOCALIO + bool "NFS server support for the NFSv3 LOCALIO protocol extension" + depends on NFSD + help + Some NFS servers support an auxiliary NFSv3 LOCALIO protocol + that is not an official part of the NFS version 3 protocol. + + This option enables support for version 3 of the LOCALIO + protocol in the kernel's NFS server. + + If unsure, say N. + config NFSD_V4 bool "NFS server support for NFS version 4" depends on NFSD && PROC_FS
@@ -89,6 +107,18 @@ config NFSD_V4 If unsure, say N. +config NFSD_V4_LOCALIO + bool "NFS server support for the NFSv4 LOCALIO protocol extension" + depends on NFSD_V4 + help + Some NFS servers support an auxiliary NFSv4 LOCALIO protocol + that is not an official part of the NFS version 4 protocol. + + This option enables support for version 4 of the LOCALIO + protocol in the kernel's NFS server. + + If unsure, say N. + config NFSD_PNFS bool
Signature · 1 line
2.44.0
Quoted 15 lines · Mike Snitzer
Hi,
This v6 changes include:
- Quite a bit of rebasing to eliminate intermediate steps that include throwaway code (thanks to Jeff Layton for calling those out).
- Moved theKconfigchanges to the end of the series to ensure that localio cannot be enabled until the code is feature complete.
- Removed needlessnfsd_serv_sync()call fromnfsd_create_serv().
- Removed inline from fs/nfsd/localio.c:nfs_stat_to_errno
- Wrapped localio structnfs_clientmembers and relatedfs/nfs/client.cinit code with #ifIS_ENABLED(CONFIG_NFS_LOCALIO)
- Requested a unique RPC program number from IANA but switched to using0x20000002until one is assigned.
- Improved the Documentation and some code comments.
Quoted 4 lines
Otherwise, not a lot of actual code changes.
My git tree is here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/
FYI, I've staged some will-be v7 improvements (mainly to client code) in the nfs-localio-for-6.11 branch:
- factored out duplicate localio xdr code
- moved the too-large-to-inline nfs_init_localioclient to localio.c
Just a heads-up without spamming with another patchbomb.
Mike