Assorted patches for knfsd
Subsystems (4)
[email protected]
maintainercover Assorted patches for knfsd
From: Trond Myklebust <[email protected]>
The following patchset is mainly for improving support for re-exporting NFSv4 as NFSv3. However it also includes one generic bugfix for NFSv3 to allow zero length writes. It also improves the writeback performance by replacing the rwsem with a lock-free errseq_t-based method.
Jeff Layton (3):
nfsd: Add errno mapping for EREMOTEIO
nfsd: Retry once in nfsd_open on an -EOPENSTALE return
nfsd: allow lockd to be forcibly disabled
Peng Tao (1):
nfsd: map EBADF
Trond Myklebust (5):
nfs: Add export support for weak cache consistency attributes
nfsd: NFSv3 should allow zero length writes
nfsd: Add a tracepoint for errors in nfsd4_clone_file_range()
nfsd: Replace use of rwsem with errseq_t
nfsd: Ignore rpcbind errors on nfsd startup
fs/nfs/export.c | 24 ++++++++++ fs/nfsd/filecache.c | 1 - fs/nfsd/filecache.h | 1 - fs/nfsd/nfs3xdr.c | 83 ++++++++++++++++++++++----------- fs/nfsd/nfs4proc.c | 18 +++---- fs/nfsd/nfs4xdr.c | 6 +-- fs/nfsd/nfsctl.c | 7 ++- fs/nfsd/nfsd.h | 1 + fs/nfsd/nfsproc.c | 3 ++ fs/nfsd/nfssvc.c | 29 +++++++++++- fs/nfsd/trace.h | 50 ++++++++++++++++++++ fs/nfsd/vfs.c | 85 +++++++++++++++++++++++----------- fs/nfsd/vfs.h | 8 ++-- include/linux/exportfs.h | 3 ++ include/linux/sunrpc/svcsock.h | 5 +- net/sunrpc/svc.c | 2 +- net/sunrpc/svcsock.c | 14 +++--- 17 files changed, 257 insertions(+), 83 deletions(-)
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 1/9 nfsd: map EBADF
From: Peng Tao <[email protected]>
Now that we have open file cache, it is possible that another client deletes the file and DP will not know about it. Then IO to MDS would fail with BADSTATEID and knfsd would start state recovery, which should fail as well and then nfs read/write will fail with EBADF. And it triggers a WARN() in nfserrno().
-----------[ cut here ]------------
WARNING: CPU: 0 PID: 13529 at fs/nfsd/nfsproc.c:758 nfserrno+0x58/0x70 [nfsd]() nfsd: non-standard errno: -9 modules linked in: nfsv3 nfs_layout_flexfiles rpcsec_gss_krb5 nfsv4 dns_resolver nfs fscache ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_connt pata_acpi floppy CPU: 0 PID: 13529 Comm: nfsd Tainted: G W 4.1.5-00307-g6e6579b #7 Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2014 0000000000000000 00000000464e6c9c ffff88079085fba8 ffffffff81789936 0000000000000000 ffff88079085fc00 ffff88079085fbe8 ffffffff810a08ea ffff88079085fbe8 ffff88080f45c900 ffff88080f627d50 ffff880790c46a48 all Trace: [<ffffffff81789936>] dump_stack+0x45/0x57 [<ffffffff810a08ea>] warn_slowpath_common+0x8a/0xc0 [<ffffffff810a0975>] warn_slowpath_fmt+0x55/0x70 [<ffffffff81252908>] ? splice_direct_to_actor+0x148/0x230 [<ffffffffa02fb8c0>] ? fsid_source+0x60/0x60 [nfsd] [<ffffffffa02f9918>] nfserrno+0x58/0x70 [nfsd] [<ffffffffa02fba57>] nfsd_finish_read+0x97/0xb0 [nfsd] [<ffffffffa02fc7a6>] nfsd_splice_read+0x76/0xa0 [nfsd] [<ffffffffa02fcca1>] nfsd_read+0xc1/0xd0 [nfsd] [<ffffffffa0233af2>] ? svc_tcp_adjust_wspace+0x12/0x30 [sunrpc] [<ffffffffa03073da>] nfsd3_proc_read+0xba/0x150 [nfsd] [<ffffffffa02f7a03>] nfsd_dispatch+0xc3/0x210 [nfsd] [<ffffffffa0233af2>] ? svc_tcp_adjust_wspace+0x12/0x30 [sunrpc] [<ffffffffa0232913>] svc_process_common+0x453/0x6f0 [sunrpc] [<ffffffffa0232cc3>] svc_process+0x113/0x1b0 [sunrpc] [<ffffffffa02f740f>] nfsd+0xff/0x170 [nfsd] [<ffffffffa02f7310>] ? nfsd_destroy+0x80/0x80 [nfsd] [<ffffffff810bf3a8>] kthread+0xd8/0xf0 [<ffffffff810bf2d0>] ? kthread_create_on_node+0x1b0/0x1b0 [<ffffffff817912a2>] ret_from_fork+0x42/0x70 [<ffffffff810bf2d0>] ? kthread_create_on_node+0x1b0/0x1b0
--- fs/nfsd/nfsproc.c | 1 + 1 file changed, 1 insertion(+)
fs/nfsd/nfsproc.c +1 -0
@@ -851,6 +851,7 @@ nfserrno (int errno) { nfserr_io, -EIO }, { nfserr_nxio, -ENXIO }, { nfserr_fbig, -E2BIG }, + { nfserr_stale, -EBADF }, { nfserr_acces, -EACCES }, { nfserr_exist, -EEXIST }, { nfserr_xdev, -EXDEV },
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 2/9 nfsd: Add errno mapping for EREMOTEIO
From: Jeff Layton <[email protected]>
The NFS client can occasionally return EREMOTEIO when signalling issues with the server. ...map to NFSERR_IO.
--- fs/nfsd/nfsproc.c | 1 + 1 file changed, 1 insertion(+)
fs/nfsd/nfsproc.c +1 -0
@@ -880,6 +880,7 @@ nfserrno (int errno) { nfserr_toosmall, -ETOOSMALL }, { nfserr_serverfault, -ESERVERFAULT }, { nfserr_serverfault, -ENFILE }, + { nfserr_io, -EREMOTEIO }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, { nfserr_no_grace, -ENOGRACE},
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 3/9 nfsd: Retry once in nfsd_open on an -EOPENSTALE return
From: Jeff Layton <[email protected]>
If we get back -EOPENSTALE from an NFSv4 open, then we either got some unhandled error or the inode we got back was not the same as the one associated with the dentry.
We really have no recourse in that situation other than to retry the open, and if it fails to just return nfserr_stale back to the client.
--- fs/nfsd/nfsproc.c | 1 + fs/nfsd/vfs.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
fs/nfsd/nfsproc.c +1 -0
@@ -881,6 +881,7 @@ nfserrno (int errno) { nfserr_serverfault, -ESERVERFAULT }, { nfserr_serverfault, -ENFILE }, { nfserr_io, -EREMOTEIO }, + { nfserr_stale, -EOPENSTALE }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, { nfserr_no_grace, -ENOGRACE},
fs/nfsd/vfs.c +9 -1
@@ -779,6 +779,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int may_flags, struct file **filp) { __be32 err; +bool retried = false;validate_process_creds ();/*
@@ -794,9 +795,16 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,*/ if (type ==S_IFREG ) may_flags |=NFSD_MAY_OWNER_OVERRIDE ; +retry: err =fh_verify (rqstp, fhp, type, may_flags); -if (!err) +if (!err) { err =__nfsd_open (rqstp, fhp, type, may_flags, filp); +if (err == nfserr_stale && !retried) { + retried = true; +fh_put (fhp); + goto retry; + } + }validate_process_creds ();return err; }
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 4/9 nfs: Add export support for weak cache consistency attributes
From: Trond Myklebust <[email protected]>
Allow knfsd to request weak cache consistency attributes on files that have delegations and/or have up to date attribute caches.
--- fs/nfs/export.c | 24 ++++++++++++ fs/nfsd/nfs3xdr.c | 83 +++++++++++++++++++++++++++------------- fs/nfsd/nfs4xdr.c | 6 +-- fs/nfsd/vfs.c | 14 +++++++ fs/nfsd/vfs.h | 5 ++- include/linux/exportfs.h | 3 ++ 6 files changed, 103 insertions(+), 32 deletions(-)
fs/nfs/export.c +24 -0
@@ -151,10 +151,34 @@ static u64 nfs_fetch_iversion(struct inode *inode)return inode_peek_iversion_raw (inode); } +static int nfs_exp_getattr (struct path *path,struct kstat *stat,bool force) +{ +const unsigned long check_valid = +NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_ATIME | +NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME | +NFS_INO_INVALID_SIZE |/* NFS_INO_INVALID_BLOCKS | */ +NFS_INO_INVALID_OTHER |NFS_INO_INVALID_NLINK ; +struct inode *inode =d_inode (path->dentry); +int flags = force ?AT_STATX_SYNC_AS_STAT :AT_STATX_DONT_SYNC ; +int ret, ret2 =0 ; + +if (!force &&nfs_check_cache_invalid (inode, check_valid)) + ret2 = -EAGAIN ; + ret =vfs_getattr (path, stat,STATX_BASIC_STATS & ~STATX_BLOCKS , flags); +if (ret <0 ) +return ret; + stat->blocks =nfs_calc_block_size (stat->size); +if (S_ISDIR (inode->i_mode)) + stat->blksize =NFS_SERVER (inode)->dtsize; + stat->result_mask |=STATX_BLOCKS ; +return ret2; +} +const struct export_operations nfs_export_ops = { .encode_fh = nfs_encode_fh, .fh_to_dentry = nfs_fh_to_dentry, .get_parent = nfs_get_parent, + .getattr = nfs_exp_getattr, .fetch_iversion = nfs_fetch_iversion, .flags =EXPORT_OP_NOWCC |EXPORT_OP_NOSUBTREECHK | EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS|
fs/nfsd/nfs3xdr.c +56 -27
172 lines not on this page · raw message
fs/nfsd/nfs4xdr.c +3 -3
@@ -2865,9 +2865,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, goto out; } - err =vfs_getattr (&path, &stat,STATX_BASIC_STATS ,AT_STATX_SYNC_AS_STAT ); -if (err) - goto out_nfserr; + status =nfsd_getattr (&path, &stat, true); +if (status) + goto out; if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
fs/nfsd/vfs.c +14 -0
@@ -2412,3 +2412,17 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,return err?nfserrno (err) :0 ; } + + +__be32 +nfsd_getattr (struct path *p,struct kstat *stat,bool force) +{ +const struct export_operations *ops = p->dentry->d_sb->s_export_op; +int err; + +if (ops->getattr) + err = ops->getattr (p, stat, force); +else + err =vfs_getattr (p, stat,STATX_BASIC_STATS ,AT_STATX_SYNC_AS_STAT ); +return err ?nfserrno (err) :0 ; +}
fs/nfsd/vfs.h +3 -2
@@ -132,6 +132,8 @@ __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,__be32 nfsd_permission (struct svc_rqst *,struct svc_export *,struct dentry *,int ); +__be32 nfsd_getattr (struct path *p,struct kstat *,bool ); +static inline int fh_want_write (struct svc_fh *fh) {int ret;
@@ -156,8 +158,7 @@ static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat) {struct path p = {.mnt = fh->fh_export->ex_path.mnt, .dentry = fh->fh_dentry}; -return nfserrno (vfs_getattr (&p, stat,STATX_BASIC_STATS , -AT_STATX_SYNC_AS_STAT )); +return nfsd_getattr (&p, stat, true); }static inline int nfsd_create_is_exclusive (int createmode)
include/linux/exportfs.h +3 -0
@@ -10,6 +10,8 @@ struct inode;struct iomap ;struct super_block ;struct vfsmount ; +struct path ; +struct kstat ;/* limit the handle size to NFSv4 handle size now */ #define MAX_HANDLE_SZ 128
@@ -224,6 +226,7 @@ struct export_operations {#define EXPORT_OP_SYNC_LOCKS (0x20)/* Filesystem can't do asychronous blocking locks */ unsigned long flags; +int (*getattr)(struct path *,struct kstat *,bool ); }; extern int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid,
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 5/9 nfsd: NFSv3 should allow zero length writes
From: Trond Myklebust <[email protected]>
According to RFC1813: "If count is 0, the WRITE will succeed and return a count of 0, barring errors due to permissions checking."
--- fs/nfsd/vfs.c | 3 +++ net/sunrpc/svc.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
fs/nfsd/vfs.c +3 -0
@@ -969,6 +969,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,trace_nfsd_write_opened (rqstp, fhp, offset, *cnt); +if (!*cnt) +return nfs_ok; +if (sb->s_export_op) exp_op_flags = sb->s_export_op->flags;
net/sunrpc/svc.c +1 -1
@@ -1692,7 +1692,7 @@ unsigned int svc_fill_write_vector(struct svc_rqst *rqstp, struct page **pages,* entirely in rq_arg.pages. In this case, @first is empty. */ i =0 ; -if (first->iov_len) { +if (first->iov_len || !total) { vec[i].iov_base = first->iov_base; vec[i].iov_len =min_t (size_t, total, first->iov_len); total -= vec[i].iov_len;
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 6/9 nfsd: Add a tracepoint for errors in nfsd4_clone_file_range()
From: Trond Myklebust <[email protected]>
Since a clone error commit can cause the boot verifier to change, we should trace those errors.
--- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/trace.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/vfs.c | 18 +++++++++++++++-- fs/nfsd/vfs.h | 3 ++- 4 files changed, 69 insertions(+), 4 deletions(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1102,7 +1102,7 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; - status =nfsd4_clone_file_range (src, clone->cl_src_pos, + status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export));
fs/nfsd/trace.h +50 -0
56 lines not on this page · raw message
fs/nfsd/vfs.c +16 -2
@@ -40,6 +40,7 @@#include "../internal.h" #include "acl.h" #include "idmap.h" +#include "xdr4.h" #endif /* CONFIG_NFSD_V4 */ #include "nfsd.h"
@@ -516,8 +517,15 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif -__be32 nfsd4_clone_file_range (struct nfsd_file *nf_src,u64 src_pos, -struct nfsd_file *nf_dst,u64 dst_pos,u64 count,bool sync) +static struct nfsd4_compound_state *nfsd4_get_cstate (struct svc_rqst *rqstp) +{ +return &((struct nfsd4_compoundres *)rqstp->rq_resp)->cstate; +} + +__be32 nfsd4_clone_file_range (struct svc_rqst *rqstp, +struct nfsd_file *nf_src,u64 src_pos, +struct nfsd_file *nf_dst,u64 dst_pos, +u64 count,bool sync) {struct file *src = nf_src->nf_file;struct file *dst = nf_dst->nf_file;
@@ -541,6 +549,12 @@ __be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos,if (!status) status =commit_inode_metadata (file_inode (src));if (status <0 ) { +trace_nfsd_clone_file_range_err (rqstp, + &nfsd4_get_cstate (rqstp)->save_fh, + src_pos, + &nfsd4_get_cstate (rqstp)->current_fh, + dst_pos, + count, status);nfsd_reset_boot_verifier (net_generic (nf_dst->nf_net, nfsd_net_id)); ret =nfserrno (status);
fs/nfsd/vfs.h +2 -1
@@ -57,7 +57,8 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *);__be32 nfsd4_vfs_fallocate (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,loff_t ,int ); -__be32 nfsd4_clone_file_range (struct nfsd_file *nf_src,u64 src_pos, +__be32 nfsd4_clone_file_range (struct svc_rqst *, +struct nfsd_file *nf_src,u64 src_pos,struct nfsd_file *nf_dst,u64 dst_pos,u64 count,bool sync);#endif /* CONFIG_NFSD_V4 */
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 7/9 nfsd: Replace use of rwsem with errseq_t
From: Trond Myklebust <[email protected]>
The nfsd_file nf_rwsem is currently being used to separate file write and commit instances to ensure that we catch errors and apply them to the correct write/commit.
We can improve scalability at the expense of a little accuracy (some extra false positives) by replacing the nf_rwsem with more careful use of the errseq_t mechanism to track errors across the different operations.
--- fs/nfsd/filecache.c | 1 - fs/nfsd/filecache.h | 1 - fs/nfsd/nfs4proc.c | 16 +++++++++------- fs/nfsd/vfs.c | 40 +++++++++++++++------------------------- 4 files changed, 24 insertions(+), 34 deletions(-)
fs/nfsd/filecache.c +0 -1
@@ -194,7 +194,6 @@ nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval,__set_bit (NFSD_FILE_BREAK_READ , &nf->nf_flags); } nf->nf_mark =NULL ; -init_rwsem (&nf->nf_rwsem);trace_nfsd_file_alloc (nf); }return nf;
fs/nfsd/filecache.h +0 -1
@@ -46,7 +46,6 @@ struct nfsd_file {refcount_t nf_ref;unsigned char nf_may;struct nfsd_file_mark *nf_mark; -struct rw_semaphore nf_rwsem; };int nfsd_file_cache_init (void );
fs/nfsd/nfs4proc.c +9 -7
@@ -1511,6 +1511,9 @@ static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)static ssize_t _nfsd_copy_file_range (struct nfsd4_copy *copy) { +struct file *dst = copy->nf_dst->nf_file; +struct file *src = copy->nf_src->nf_file; +errseq_t since;ssize_t bytes_copied =0 ;u64 bytes_total = copy->cp_count;u64 src_pos = copy->cp_src_pos;
@@ -1523,9 +1526,8 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) do { if (kthread_should_stop()) break; - bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file, - src_pos, copy->nf_dst->nf_file, dst_pos, - bytes_total); + bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos, + bytes_total); if (bytes_copied <= 0) break; bytes_total -= bytes_copied;
@@ -1535,11 +1537,11 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) }while (bytes_total >0 && !copy->cp_synchronous);/* for a non-zero asynchronous copy do a commit of data */ if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written >0 ) { -down_write (©->nf_dst->nf_rwsem); - status =vfs_fsync_range (copy->nf_dst->nf_file, - copy->cp_dst_pos, + since =READ_ONCE (dst->f_wb_err); + status =vfs_fsync_range (dst, copy->cp_dst_pos, copy->cp_res.wr_bytes_written,0 ); -up_write (©->nf_dst->nf_rwsem); +if (!status) + status =filemap_check_wb_err (dst->f_mapping, since);if (!status) copy->committed = true; }
fs/nfsd/vfs.c +15 -25
@@ -529,10 +529,11 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, {struct file *src = nf_src->nf_file;struct file *dst = nf_dst->nf_file; +errseq_t since;loff_t cloned;__be32 ret =0 ; -down_write (&nf_dst->nf_rwsem); + since =READ_ONCE (dst->f_wb_err); cloned =vfs_clone_file_range (src, src_pos, dst, dst_pos, count,0 );if (cloned <0 ) { ret =nfserrno (cloned);
@@ -546,6 +547,8 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp,loff_t dst_end = count ? dst_pos + count -1 :LLONG_MAX ;int status =vfs_fsync_range (dst, dst_pos, dst_end,0 ); +if (!status) + status =filemap_check_wb_err (dst->f_mapping, since);if (!status) status =commit_inode_metadata (file_inode (src));if (status <0 ) {
@@ -561,7 +564,6 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, } } out_err: -up_write (&nf_dst->nf_rwsem);return ret; }
@@ -972,6 +974,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,struct super_block *sb =file_inode (file)->i_sb;struct svc_export *exp;struct iov_iter iter; +errseq_t since;__be32 nfserr;int host_err;int use_wgather;
@@ -1012,21 +1015,18 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, flags |=RWF_SYNC ;iov_iter_kvec (&iter,WRITE , vec, vlen, *cnt); + since =READ_ONCE (file->f_wb_err);if (flags &RWF_SYNC ) { -down_write (&nf->nf_rwsem); host_err =vfs_iter_write (file, &iter, &pos, flags);if (host_err <0 )nfsd_reset_boot_verifier (net_generic (SVC_NET (rqstp), nfsd_net_id)); -up_write (&nf->nf_rwsem); }else { -down_read (&nf->nf_rwsem);if (verf)nfsd_copy_boot_verifier (verf,net_generic (SVC_NET (rqstp), nfsd_net_id)); host_err =vfs_iter_write (file, &iter, &pos, flags); -up_read (&nf->nf_rwsem); }if (host_err <0 ) { nfsd_reset_boot_verifier(net_generic(SVC_NET(rqstp),
@@ -1036,6 +1036,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, *cnt = host_err;nfsd_stats_io_write_add (exp, *cnt);fsnotify_modify (file); + host_err =filemap_check_wb_err (file->f_mapping, since); +if (host_err <0 ) + goto out_nfserr;if (stable && use_wgather) { host_err =wait_for_concurrent_writes (file);
@@ -1116,19 +1119,6 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, }#ifdef CONFIG_NFSD_V3 -static int -nfsd_filemap_write_and_wait_range (struct nfsd_file *nf,loff_t offset, -loff_t end) -{ -struct address_space *mapping = nf->nf_file->f_mapping; -int ret =filemap_fdatawrite_range (mapping, offset, end); - -if (ret) -return ret; -filemap_fdatawait_range_keep_errors (mapping, offset, end); -return 0 ; -} -/* * Commit all pending writes to stable storage. *
@@ -1159,25 +1149,25 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,if (err) goto out;if (EX_ISSYNC (fhp->fh_export)) { -int err2 =nfsd_filemap_write_and_wait_range (nf, offset, end); +errseq_t since =READ_ONCE (nf->nf_file->f_wb_err); +int err2; -down_write (&nf->nf_rwsem); -if (!err2) - err2 =vfs_fsync_range (nf->nf_file, offset, end,0 ); + err2 =vfs_fsync_range (nf->nf_file, offset, end,0 );switch (err2) {case 0 :nfsd_copy_boot_verifier (verf,net_generic (nf->nf_net, nfsd_net_id)); + err2 =filemap_check_wb_err (nf->nf_file->f_mapping, + since);break ;case -EINVAL : err = nfserr_notsupp;break ;default : - err =nfserrno (err2);nfsd_reset_boot_verifier (net_generic (nf->nf_net, nfsd_net_id)); } -up_write (&nf->nf_rwsem); + err =nfserrno (err2); }else nfsd_copy_boot_verifier (verf,net_generic (nf->nf_net, nfsd_net_id));
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 8/9 nfsd: allow lockd to be forcibly disabled
From: Jeff Layton <[email protected]>
In some cases, we may want to use a userland NLM server which will require that we turn off lockd.
--- fs/nfsd/nfssvc.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/nfsd/nfssvc.c +11 -0
@@ -340,8 +340,19 @@ static void nfsd_shutdown_generic(void)nfsd_file_cache_shutdown (); } +/* +* Allow admin to disable lockd. This would typically be used to allow (e.g.) +* a userspace NLM server of some sort to be used. +*/ +static bool nfsd_disable_lockd = false; +module_param (nfsd_disable_lockd, bool,0644 ); +MODULE_PARM_DESC (nfsd_disable_lockd,"Allow lockd to be manually disabled." ); +static bool nfsd_needs_lockd (struct nfsd_net *nn) { +if (nfsd_disable_lockd) +return false; +return nfsd_vers (nn,2 ,NFSD_TEST ) ||nfsd_vers (nn,3 ,NFSD_TEST ); }
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 9/9 nfsd: Ignore rpcbind errors on nfsd startup
From: Trond Myklebust <[email protected]>
NFSv4 doesn't need rpcbind, so let's not refuse to start up just because the rpcbind registration failed.
--- fs/nfsd/nfsctl.c | 7 ++++++- fs/nfsd/nfsd.h | 1 + fs/nfsd/nfssvc.c | 18 ++++++++++++++++-- include/linux/sunrpc/svcsock.h | 5 +++-- net/sunrpc/svcsock.c | 14 ++++++++------ 5 files changed, 34 insertions(+), 11 deletions(-)
fs/nfsd/nfsctl.c +6 -1
@@ -727,6 +727,7 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct credchar *mesg = buf;int fd, err;struct nfsd_net *nn =net_generic (net, nfsd_net_id); +int flags =SVC_SOCK_DEFAULTS ; err =get_int (&mesg, &fd);if (err !=0 || fd <0 )
@@ -741,7 +742,11 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct credif (err !=0 )return err; - err =svc_addsock (nn->nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT , cred); +if (!nfsd_rpcbind_error_is_fatal ()) + flags |=SVC_SOCK_RPCBIND_NOERR ; + + err =svc_addsock (nn->nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT , + flags, cred);if (err <0 ) {nfsd_destroy (net);return err;
fs/nfsd/nfsd.h +1 -0
@@ -132,6 +132,7 @@ int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);int nfsd_minorversion (struct nfsd_net *nn,u32 minorversion,enum vers_op change);void nfsd_reset_versions (struct nfsd_net *nn);int nfsd_create_serv (struct net *net); +extern bool nfsd_rpcbind_error_is_fatal (void );extern int nfsd_max_blksize;
fs/nfsd/nfssvc.c +16 -2
@@ -289,17 +289,21 @@ static int nfsd_init_socks(struct net *net, const struct cred *cred) {int error;struct nfsd_net *nn =net_generic (net, nfsd_net_id); +int flags =SVC_SOCK_DEFAULTS ;if (!list_empty (&nn->nfsd_serv->sv_permsocks))return 0 ; +if (!nfsd_rpcbind_error_is_fatal ()) + flags |=SVC_SOCK_RPCBIND_NOERR ; + error =svc_create_xprt (nn->nfsd_serv,"udp" , net,PF_INET ,NFS_PORT , -SVC_SOCK_DEFAULTS , cred); + flags, cred);if (error <0 )return error; error =svc_create_xprt (nn->nfsd_serv,"tcp" , net,PF_INET ,NFS_PORT , -SVC_SOCK_DEFAULTS , cred); + flags, cred);if (error <0 )return error;
@@ -340,6 +344,16 @@ static void nfsd_shutdown_generic(void)nfsd_file_cache_shutdown (); } +static bool nfsd_rpcbind_error_fatal = false; +module_param (nfsd_rpcbind_error_fatal, bool,0644 ); +MODULE_PARM_DESC (nfsd_rpcbind_error_fatal, +"rpcbind errors are fatal when starting nfsd." ); + +bool nfsd_rpcbind_error_is_fatal (void ) +{ +return nfsd_rpcbind_error_fatal; +} +/* * Allow admin to disable lockd. This would typically be used to allow (e.g.) * a userspace NLM server of some sort to be used.
include/linux/sunrpc/svcsock.h +3 -2
@@ -61,8 +61,8 @@ void svc_drop(struct svc_rqst *);void svc_sock_update_bufs (struct svc_serv *serv);bool svc_alien_sock (struct net *net,int fd);int svc_addsock (struct svc_serv *serv,const int fd, -char *name_return,const size_t len, -const struct cred *cred); +char *name_return,const size_t len,int flags, +const struct cred *cred);void svc_init_xprt_sock (void );void svc_cleanup_xprt_sock (void );struct svc_xprt *svc_sock_create (struct svc_serv *serv,int prot);
@@ -74,5 +74,6 @@ void svc_sock_destroy(struct svc_xprt *);#define SVC_SOCK_DEFAULTS (0U)#define SVC_SOCK_ANONYMOUS (1U << 0)/* don't register with pmap */ #define SVC_SOCK_TEMPORARY (1U << 1)/* flag socket as temporary */ +#define SVC_SOCK_RPCBIND_NOERR (1U << 2)/* Ignore pmap errors */ #endif /* SUNRPC_SVCSOCK_H */
net/sunrpc/svcsock.c +8 -6
@@ -1309,14 +1309,15 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, inet = sock->sk;/* Register socket with portmapper */ -if (pmap_register) +if (pmap_register) { err =svc_register (serv,sock_net (sock->sk), inet->sk_family, inet->sk_protocol,ntohs (inet_sk (inet)->inet_sport)); -if (err <0 ) { -kfree (svsk); -return ERR_PTR (err); +if (err <0 && !(flags &SVC_SOCK_RPCBIND_NOERR )) { +kfree (svsk); +return ERR_PTR (err); + } } svsk->sk_sock = sock;
@@ -1364,6 +1365,7 @@ EXPORT_SYMBOL_GPL(svc_alien_sock);* @fd: file descriptor of the new listener * @name_return: pointer to buffer to fill in with name of listener * @len: size of the buffer +* @flags: flags argument for svc_setup_socket() * @cred: credential * * Fills in socket name and returns positive length of name if successful.
@@ -1371,7 +1373,7 @@ EXPORT_SYMBOL_GPL(svc_alien_sock);* value. */ int svc_addsock (struct svc_serv *serv,const int fd,char *name_return, -const size_t len,const struct cred *cred) +const size_t len,int flags,const struct cred *cred) {int err =0 ;struct socket *so =sockfd_lookup (fd, &err);
@@ -1395,7 +1397,7 @@ int svc_addsock(struct svc_serv *serv, const int fd, char *name_return, err = -ENOENT ;if (!try_module_get (THIS_MODULE )) goto out; - svsk =svc_setup_socket (serv, so,SVC_SOCK_DEFAULTS ); + svsk =svc_setup_socket (serv, so, flags);if (IS_ERR (svsk)) {module_put (THIS_MODULE ); err =PTR_ERR (svsk);
Signature · 1 line
2.33.1
Re: [PATCH 8/9] nfsd: allow lockd to be forcibly disabled
In reply to [email protected]Quoted 8 lines · On Dec 17, 2021, at 4:50 PM, [email protected] wrote:
From: Jeff Layton <[email protected]>
In some cases, we may want to use a userland NLM server which will require that we turn off lockd.
Does this adminstrative interface need to be container-aware?
Quoted 34 lines
Signed-off-by Jeff Layton <[email protected]>Signed-off-by Lance Shelton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>---
fs/nfsd/nfssvc.c| 11 +++++++++++1 file changed, 11 insertions(+)fs/nfsd/nfssvc.c +11
-0@@ -340,8 +340,19 @@ static void nfsd_shutdown_generic(void)nfsd_file_cache_shutdown (); } +/* +* Allow admin to disable lockd. This would typically be used to allow (e.g.) +* a userspace NLM server of some sort to be used. +*/ +static bool nfsd_disable_lockd = false; +module_param (nfsd_disable_lockd, bool,0644 ); +MODULE_PARM_DESC (nfsd_disable_lockd,"Allow lockd to be manually disabled." ); +static bool nfsd_needs_lockd (struct nfsd_net *nn) { +if (nfsd_disable_lockd) +return false; +return nfsd_vers (nn,2 ,NFSD_TEST ) ||nfsd_vers (nn,3 ,NFSD_TEST ); }Signature · 1 line
2.33.1
--
Chuck Lever
Re: [PATCH 8/9] nfsd: allow lockd to be forcibly disabled
In reply to [email protected]This seems like a really specialized requirement. Is anyone outside hammerspace doing this?
--b.
Quoted 40 lines · On Fri, Dec 17, 2021 at 5:02 PM <[email protected]> wrote:
From: Jeff Layton <[email protected]>
In some cases, we may want to use a userland NLM server which will require that we turn off lockd.
Signed-off-by Jeff Layton <[email protected]>Signed-off-by Lance Shelton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/nfssvc.c | 11 +++++++++++ 1 file changed, 11 insertions(+)fs/nfsd/nfssvc.c +11
-1@@ -340,8 +340,19 @@ static void nfsd_shutdown_generic(void)nfsd_file_cache_shutdown (); } +/* +* Allow admin to disable lockd. This would typically be used to allow (e.g.) +* a userspace NLM server of some sort to be used. +*/ +static bool nfsd_disable_lockd = false; +module_param (nfsd_disable_lockd, bool,0644 ); +MODULE_PARM_DESC (nfsd_disable_lockd,"Allow lockd to be manually disabled." ); +static bool nfsd_needs_lockd (struct nfsd_net *nn) { +if (nfsd_disable_lockd) +return false; +return nfsd_vers (nn,2 ,NFSD_TEST ) ||nfsd_vers (nn,3 ,NFSD_TEST ); } --2.33.1
Re: [PATCH 5/9] nfsd: NFSv3 should allow zero length writes
In reply to [email protected]Quoted 5 lines · On Fri, Dec 17, 2021 at 5:07 PM <[email protected]> wrote:
From: Trond Myklebust <[email protected]>
According to RFC1813: "If count is 0, the WRITE will succeed and return a count of 0, barring errors due to permissions checking."
Yes, I'm surprised we're not already doing this right.
I wonder how far back this bug goes.
The svc.c code is from 8154ef2776aa "NFSD: Clean up legacy NFS WRITE argument XDR decoders", but the behavior might predate that code. The nfsd_vfs_write() logic, I'm not sure I understand.
We have a pynfs test for the v4 case (WRT4), but I guess we must have nothing testing the v3 case.
--b.
Quoted 37 lines
Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/vfs.c | 3 +++ net/sunrpc/svc.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +3
-0@@ -969,6 +969,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,trace_nfsd_write_opened (rqstp, fhp, offset, *cnt); +if (!*cnt) +return nfs_ok; +if (sb->s_export_op) exp_op_flags = sb->s_export_op->flags;net/sunrpc/svc.c +1
-2@@ -1692,7 +1692,7 @@ unsigned int svc_fill_write_vector(struct svc_rqst *rqstp, struct page **pages,* entirely in rq_arg.pages. In this case, @first is empty. */ i =0 ; -if (first->iov_len) { +if (first->iov_len || !total) { vec[i].iov_base = first->iov_base; vec[i].iov_len =min_t (size_t, total, first->iov_len); total -= vec[i].iov_len; --2.33.1
Re: [PATCH 5/9] nfsd: NFSv3 should allow zero length writes
Quoted 11 lines · Bruce Fields
Quoted 5 lines · On Fri, Dec 17, 2021 at 5:07 PM <[email protected]> wrote:
From: Trond Myklebust <[email protected]>
According to RFC1813: "If count is 0, the WRITE will succeed and return a count of 0, barring errors due to permissions checking."
Quoted 7 lines
Yes, I'm surprised we're not already doing this right.
I wonder how far back this bug goes.
The
svc.ccode is from8154ef2776aa"NFSD: Clean up legacy NFS WRITE argument XDR decoders", but the behavior might predate that code. Thenfsd_vfs_write()logic, I'm not sure I understand.
The new check in nfsd_vfs_write() might circumvent the VFS layer's security checks, so I agree, that is a little suspect.
Quoted 2 lines
We have a pynfs test for the v4 case (WRT4), but I guess we must have nothing testing the v3 case.
I guess cthon04 doesn't check this case.
But it seems to me WRT4 should already tickle any problems with nfsd_vfs_write(), shouldn't it?
Quoted 23 lines
--b.
Quoted 21 lines
Signed-off-by Trond Myklebust <[email protected]>---
fs/nfsd/vfs.c| 3 +++net/sunrpc/svc.c| 2 +-2 files changed, 4 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +3
-0@@ -969,6 +969,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,trace_nfsd_write_opened (rqstp, fhp, offset, *cnt); +if (!*cnt) +return nfs_ok; +if (sb->s_export_op) exp_op_flags = sb->s_export_op->flags;
Quoted 17 lines
Quoted 14 lines
net/sunrpc/svc.c +1
-2@@ -1692,7 +1692,7 @@ unsigned int svc_fill_write_vector(struct svc_rqst *rqstp, struct page **pages,* entirely in rq_arg.pages. In this case, @first is empty. */ i =0 ; -if (first->iov_len) { +if (first->iov_len || !total) { vec[i].iov_base = first->iov_base; vec[i].iov_len =min_t (size_t, total, first->iov_len); total -= vec[i].iov_len; --Quoted 2 lines
2.33.1
--
Chuck Lever
Re: [PATCH 5/9] nfsd: NFSv3 should allow zero length writes
Quoted 2 lines · Chuck Lever III
But it seems to me WRT4 should already tickle any problems with
nfsd_vfs_write(), shouldn't it?
I was just taking Trond's word that this is NFSv3-specific, but it's not clear to me why from the code, and I know that WRT4 is passing. Something's weird. I'm travelling or I'd test it.
--b.
Re: [PATCH 4/9] nfs: Add export support for weak cache consistency attributes
In reply to [email protected]Quoted 11 lines · On Dec 17, 2021, at 4:50 PM, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Allow knfsd to request weak cache consistency attributes on files that have delegations and/or have up to date attribute caches.
Signed-off-by Trond Myklebust <[email protected]>Signed-off-by Lance Shelton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>
This one does not apply to v5.16-rc. Please rebase this series and resend.
More below:
Quoted 111 lines
---
fs/nfs/export.c | 24 ++++++++++++ fs/nfsd/nfs3xdr.c | 83 +++++++++++++++++++++++++++------------- fs/nfsd/nfs4xdr.c | 6 +-- fs/nfsd/vfs.c | 14 +++++++ fs/nfsd/vfs.h | 5 ++- include/linux/exportfs.h | 3 ++ 6 files changed, 103 insertions(+), 32 deletions(-)fs/nfs/export.c +24
-0@@ -151,10 +151,34 @@ static u64 nfs_fetch_iversion(struct inode *inode)return inode_peek_iversion_raw (inode); } +static int nfs_exp_getattr (struct path *path,struct kstat *stat,bool force) +{ +const unsigned long check_valid = +NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_ATIME | +NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME | +NFS_INO_INVALID_SIZE |/* NFS_INO_INVALID_BLOCKS | */ +NFS_INO_INVALID_OTHER |NFS_INO_INVALID_NLINK ; +struct inode *inode =d_inode (path->dentry); +int flags = force ?AT_STATX_SYNC_AS_STAT :AT_STATX_DONT_SYNC ; +int ret, ret2 =0 ; + +if (!force &&nfs_check_cache_invalid (inode, check_valid)) + ret2 = -EAGAIN ; + ret =vfs_getattr (path, stat,STATX_BASIC_STATS & ~STATX_BLOCKS , flags); +if (ret <0 ) +return ret; + stat->blocks =nfs_calc_block_size (stat->size); +if (S_ISDIR (inode->i_mode)) + stat->blksize =NFS_SERVER (inode)->dtsize; + stat->result_mask |=STATX_BLOCKS ; +return ret2; +} +const struct export_operations nfs_export_ops = { .encode_fh = nfs_encode_fh, .fh_to_dentry = nfs_fh_to_dentry, .get_parent = nfs_get_parent, + .getattr = nfs_exp_getattr, .fetch_iversion = nfs_fetch_iversion, .flags =EXPORT_OP_NOWCC |EXPORT_OP_NOSUBTREECHK | EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS|fs/nfsd/nfs3xdr.c +23
-15@@ -415,21 +415,14 @@ svcxdr_encode_pre_op_attr(struct xdr_stream *xdr, const struct svc_fh *fhp)return svcxdr_encode_wcc_attr (xdr, fhp); } -/** -* svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes -* @rqstp: Context of a completed RPC transaction -* @xdr: XDR stream -* @fhp: File handle to encode -* -* Return values: -* %false: Send buffer space was exhausted -* %true: Success -*/ -bool -svcxdr_encode_post_op_attr (struct svc_rqst *rqstp,struct xdr_stream *xdr, -const struct svc_fh *fhp) +static bool +__svcxdr_encode_post_op_attr (struct svc_rqst *rqstp,struct xdr_stream *xdr, +const struct svc_fh *fhp,bool force) {struct dentry *dentry = fhp->fh_dentry; +struct path path = { + .dentry = dentry, + };struct kstat stat;/* @@ -437,9 +430,10 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr,* stale file handle. In this case, no attributes are * returned. */ -if (fhp->fh_no_wcc || !dentry || !d_really_is_positive (dentry)) +if (!dentry || !d_really_is_positive (dentry)) goto no_post_op_attrs; -if (fh_getattr (fhp, &stat) != nfs_ok) + path.mnt = fhp->fh_export->ex_path.mnt; +if (nfsd_getattr (&path, &stat, force) != nfs_ok) goto no_post_op_attrs;if (xdr_stream_encode_item_present (xdr) <0 )@@ -454,6 +448,31 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr,return xdr_stream_encode_item_absent (xdr) >0 ; } +/** +* svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes +* @rqstp: Context of a completed RPC transaction +* @xdr: XDR stream +* @fhp: File handle to encode +* +* Return values: +* %false: Send buffer space was exhausted +* %true: Success +*/ +bool +svcxdr_encode_post_op_attr (struct svc_rqst *rqstp,struct xdr_stream *xdr, +const struct svc_fh *fhp) +{
fs/nfsd/nfs3xdr.c svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, · line 474
Quoted 10 lines
fs/nfsd/nfs3xdr.c +10
-0+return __svcxdr_encode_post_op_attr (rqstp, xdr, fhp, true); +} + +static bool +svcxdr_encode_post_op_attr_opportunistic (struct svc_rqst *rqstp, +struct xdr_stream *xdr, +const struct svc_fh *fhp) +{ +return __svcxdr_encode_post_op_attr (rqstp, xdr, fhp, !fhp->fh_no_wcc); +}
I don't quite understand the need for splitting encode_post_op_attr. At the least, more commentary in the patch description would help. For now, I will study this and get back to you.
Quoted 145 lines
fs/nfsd/nfs3xdr.c +1
-0+/* * Encode weak cache consistency data */ @@ -481,7 +500,7 @@ svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr,neither:
if (xdr_stream_encode_item_absent(xdr) < 0) return false;fs/nfsd/nfs3xdr.c +1
-1-if (!svcxdr_encode_post_op_attr (rqstp, xdr, fhp)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, fhp))return false; return true;fs/nfsd/nfs3xdr.c +21
-11@@ -879,11 +898,13 @@ int nfs3svc_encode_lookupres(struct svc_rqst *rqstp, __be32 *p)return 0 ;if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh))return 0 ; -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->dirfh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->dirfh))return 0 ;break ;default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->dirfh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->dirfh))return 0 ; }@@ -901,13 +922,15 @@ nfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p)return 0 ;switch (resp->status) {case nfs_ok: -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ;if (xdr_stream_encode_u32 (xdr, resp->access) <0 )return 0 ;break ;default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ; }@@ -926,7 +949,8 @@ nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p)return 0 ;switch (resp->status) {case nfs_ok: -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ;if (xdr_stream_encode_u32 (xdr, resp->len) <0 )return 0 ;@@ -935,7 +959,8 @@ nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p)return 0 ;break ;default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ; }@@ -954,7 +979,8 @@ nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p)return 0 ;switch (resp->status) {case nfs_ok: -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ;if (xdr_stream_encode_u32 (xdr, resp->count) <0 )return 0 ;@@ -968,7 +994,8 @@ nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p)return 0 ;break ;default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ; }@@ -1065,7 +1092,8 @@ nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p)return 0 ;switch (resp->status) {case nfs_ok: -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ;if (!svcxdr_encode_cookieverf3 (xdr, resp->verf))return 0 ;@@ -1077,7 +1105,8 @@ nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p)return 0 ;break ;default : -if (!svcxdr_encode_post_op_attr (rqstp, xdr, &resp->fh)) +if (!svcxdr_encode_post_op_attr_opportunistic (rqstp, xdr, + &resp->fh))return 0 ; }@@ -1221,7 +1250,7 @@ svcxdr_encode_entry3_plus(struct nfsd3_readdirres *resp, const char *name,if (compose_entry_fh (resp, fhp, name, namlen, ino) != nfs_ok) goto out_noattrs; -if (!svcxdr_encode_post_op_attr (resp->rqstp, xdr, fhp)) +if (!svcxdr_encode_post_op_attr_opportunistic (resp->rqstp, xdr, fhp)) goto out;if (!svcxdr_encode_post_op_fh3 (xdr, fhp)) goto out;fs/nfsd/nfs4xdr.c +3
-3@@ -2865,9 +2865,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, goto out; } - err =vfs_getattr (&path, &stat,STATX_BASIC_STATS ,AT_STATX_SYNC_AS_STAT ); -if (err) - goto out_nfserr; + status =nfsd_getattr (&path, &stat, true); +if (status) + goto out; if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |fs/nfsd/vfs.c +4
-0@@ -2412,3 +2412,17 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,return err?nfserrno (err) :0 ; } + + +__be32 +nfsd_getattr (struct path *p,struct kstat *stat,bool force)
fs/nfsd/vfs.c nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp, · line 2428
Quoted 10 lines
fs/nfsd/vfs.c +10
-0+{ +const struct export_operations *ops = p->dentry->d_sb->s_export_op; +int err; + +if (ops->getattr) + err = ops->getattr (p, stat, force); +else + err =vfs_getattr (p, stat,STATX_BASIC_STATS ,AT_STATX_SYNC_AS_STAT ); +return err ?nfserrno (err) :0 ; +}
Please add nfsd_getattr() in a separate patch ("Refactor:"). And please include a kerneldoc comment for it.
Quoted 47 lines
fs/nfsd/vfs.h +3
-2@@ -132,6 +132,8 @@ __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,__be32 nfsd_permission (struct svc_rqst *,struct svc_export *,struct dentry *,int ); +__be32 nfsd_getattr (struct path *p,struct kstat *,bool ); +static inline int fh_want_write (struct svc_fh *fh) {int ret;@@ -156,8 +158,7 @@ static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat) {struct path p = {.mnt = fh->fh_export->ex_path.mnt, .dentry = fh->fh_dentry}; -return nfserrno (vfs_getattr (&p, stat,STATX_BASIC_STATS , -AT_STATX_SYNC_AS_STAT )); +return nfsd_getattr (&p, stat, true); }static inline int nfsd_create_is_exclusive (int createmode)include/linux/exportfs.h +3
-0@@ -10,6 +10,8 @@ struct inode;struct iomap ;struct super_block ;struct vfsmount ; +struct path ; +struct kstat ;/* limit the handle size to NFSv4 handle size now */ #define MAX_HANDLE_SZ 128@@ -224,6 +226,7 @@ struct export_operations {#define EXPORT_OP_SYNC_LOCKS (0x20)/* Filesystem can't do asychronous blocking locks */ unsigned long flags; +int (*getattr)(struct path *,struct kstat *,bool ); }; extern int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid,Signature · 1 line
2.33.1
--
Chuck Lever