Skip to content

Commit 2c04075

Browse files
author
CKI KWF Bot
committed
Merge: NFS/NFSD/LOCKD/SUNRPC fixes/stable updates for RHEL 9.8
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7471 NFS/NFSD/LOCKD/SUNRPC fixes/stable updates for RHEL 9.8. We already got most of the commits we want via RHEL-108616, so this is mostly a handful of commits from v6.17 and later. JIRA: https://issues.redhat.com/browse/RHEL-115855 Signed-off-by: Scott Mayhew <smayhew@redhat.com> Approved-by: Steve Dickson <steved@redhat.com> Approved-by: Olga Kornievskaia <okorniev@redhat.com> Approved-by: Benjamin Coddington <bcodding@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 4052919 + 2e49be0 commit 2c04075

File tree

17 files changed

+135
-31
lines changed

17 files changed

+135
-31
lines changed

fs/nfs/file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,11 @@ static void nfs_invalidate_folio(struct folio *folio, size_t offset,
409409
dfprintk(PAGECACHE, "NFS: invalidate_folio(%lu, %zu, %zu)\n",
410410
folio->index, offset, length);
411411

412-
if (offset != 0 || length < folio_size(folio))
413-
return;
414412
/* Cancel any unstarted writes on this page */
415-
nfs_wb_folio_cancel(inode, folio);
413+
if (offset != 0 || length < folio_size(folio))
414+
nfs_wb_folio(inode, folio);
415+
else
416+
nfs_wb_folio_cancel(inode, folio);
416417
folio_wait_fscache(folio);
417418
trace_nfs_invalidate_folio(inode, folio_pos(folio) + offset, length);
418419
}

fs/nfs/inode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,10 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
721721
trace_nfs_setattr_enter(inode);
722722

723723
/* Write all dirty data */
724-
if (S_ISREG(inode->i_mode))
724+
if (S_ISREG(inode->i_mode)) {
725+
nfs_file_block_o_direct(NFS_I(inode));
725726
nfs_sync_inode(inode);
727+
}
726728

727729
fattr = nfs_alloc_fattr_with_label(NFS_SERVER(inode));
728730
if (fattr == NULL) {

fs/nfs/internal.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,16 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
478478
return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
479479
}
480480

481+
/* Must be called with exclusively locked inode->i_rwsem */
482+
static inline void nfs_file_block_o_direct(struct nfs_inode *nfsi)
483+
{
484+
if (test_bit(NFS_INO_ODIRECT, &nfsi->flags)) {
485+
clear_bit(NFS_INO_ODIRECT, &nfsi->flags);
486+
inode_dio_wait(&nfsi->vfs_inode);
487+
}
488+
}
489+
490+
481491
/* namespace.c */
482492
#define NFS_PATH_CANONICAL 1
483493
extern char *nfs_path(char **p, struct dentry *dentry,

fs/nfs/io.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414

1515
#include "internal.h"
1616

17-
/* Call with exclusively locked inode->i_rwsem */
18-
static void nfs_block_o_direct(struct nfs_inode *nfsi, struct inode *inode)
19-
{
20-
if (test_bit(NFS_INO_ODIRECT, &nfsi->flags)) {
21-
clear_bit(NFS_INO_ODIRECT, &nfsi->flags);
22-
inode_dio_wait(inode);
23-
}
24-
}
25-
2617
/**
2718
* nfs_start_io_read - declare the file is being used for buffered reads
2819
* @inode: file inode
@@ -50,7 +41,7 @@ nfs_start_io_read(struct inode *inode)
5041
up_read(&inode->i_rwsem);
5142
/* Slow path.... */
5243
down_write(&inode->i_rwsem);
53-
nfs_block_o_direct(nfsi, inode);
44+
nfs_file_block_o_direct(nfsi);
5445
downgrade_write(&inode->i_rwsem);
5546
}
5647

@@ -78,7 +69,7 @@ void
7869
nfs_start_io_write(struct inode *inode)
7970
{
8071
down_write(&inode->i_rwsem);
81-
nfs_block_o_direct(NFS_I(inode), inode);
72+
nfs_file_block_o_direct(NFS_I(inode));
8273
}
8374

8475
/**

fs/nfs/nfs42proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
112112
exception.inode = inode;
113113
exception.state = lock->open_context->state;
114114

115+
nfs_file_block_o_direct(NFS_I(inode));
115116
err = nfs_sync_inode(inode);
116117
if (err)
117118
goto out;
@@ -355,6 +356,7 @@ static ssize_t _nfs42_proc_copy(struct file *src,
355356
return status;
356357
}
357358

359+
nfs_file_block_o_direct(NFS_I(dst_inode));
358360
status = nfs_sync_inode(dst_inode);
359361
if (status)
360362
return status;

fs/nfs/nfs4file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ static loff_t nfs42_remap_file_range(struct file *src_file, loff_t src_off,
282282

283283
/* flush all pending writes on both src and dst so that server
284284
* has the latest data */
285+
nfs_file_block_o_direct(NFS_I(src_inode));
285286
ret = nfs_sync_inode(src_inode);
286287
if (ret)
287288
goto out_unlock;
289+
nfs_file_block_o_direct(NFS_I(dst_inode));
288290
ret = nfs_sync_inode(dst_inode);
289291
if (ret)
290292
goto out_unlock;

fs/nfs/nfs4proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7826,10 +7826,10 @@ int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state,
78267826
return err;
78277827
do {
78287828
err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
7829-
if (err != -NFS4ERR_DELAY)
7829+
if (err != -NFS4ERR_DELAY && err != -NFS4ERR_GRACE)
78307830
break;
78317831
ssleep(1);
7832-
} while (err == -NFS4ERR_DELAY);
7832+
} while (err == -NFS4ERR_DELAY || err == -NFSERR_GRACE);
78337833
return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err);
78347834
}
78357835

fs/nfs/write.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,7 @@ int nfs_wb_folio_cancel(struct inode *inode, struct folio *folio)
20502050
* release it */
20512051
nfs_inode_remove_request(req);
20522052
nfs_unlock_and_release_request(req);
2053+
folio_cancel_dirty(folio);
20532054
}
20542055

20552056
return ret;

fs/nfsd/export.c

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,28 +1086,62 @@ static struct svc_export *exp_find(struct cache_detail *cd,
10861086
return exp;
10871087
}
10881088

1089-
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
1089+
/**
1090+
* check_xprtsec_policy - check if access to export is allowed by the
1091+
* xprtsec policy
1092+
* @exp: svc_export that is being accessed.
1093+
* @rqstp: svc_rqst attempting to access @exp.
1094+
*
1095+
* Helper function for check_nfsd_access(). Note that callers should be
1096+
* using check_nfsd_access() instead of calling this function directly. The
1097+
* one exception is fh_verify() since it has logic that may result in one
1098+
* or both of the helpers being skipped.
1099+
*
1100+
* Return values:
1101+
* %nfs_ok if access is granted, or
1102+
* %nfserr_acces or %nfserr_wrongsec if access is denied
1103+
*/
1104+
__be32 check_xprtsec_policy(struct svc_export *exp, struct svc_rqst *rqstp)
10901105
{
1091-
struct exp_flavor_info *f, *end = exp->ex_flavors + exp->ex_nflavors;
10921106
struct svc_xprt *xprt = rqstp->rq_xprt;
10931107

10941108
if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_NONE) {
10951109
if (!test_bit(XPT_TLS_SESSION, &xprt->xpt_flags))
1096-
goto ok;
1110+
return nfs_ok;
10971111
}
10981112
if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_TLS) {
10991113
if (test_bit(XPT_TLS_SESSION, &xprt->xpt_flags) &&
11001114
!test_bit(XPT_PEER_AUTH, &xprt->xpt_flags))
1101-
goto ok;
1115+
return nfs_ok;
11021116
}
11031117
if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_MTLS) {
11041118
if (test_bit(XPT_TLS_SESSION, &xprt->xpt_flags) &&
11051119
test_bit(XPT_PEER_AUTH, &xprt->xpt_flags))
1106-
goto ok;
1120+
return nfs_ok;
11071121
}
1108-
goto denied;
11091122

1110-
ok:
1123+
return nfserr_wrongsec;
1124+
}
1125+
1126+
/**
1127+
* check_security_flavor - check if access to export is allowed by the
1128+
* xprtsec policy
1129+
* @exp: svc_export that is being accessed.
1130+
* @rqstp: svc_rqst attempting to access @exp.
1131+
*
1132+
* Helper function for check_nfsd_access(). Note that callers should be
1133+
* using check_nfsd_access() instead of calling this function directly. The
1134+
* one exception is fh_verify() since it has logic that may result in one
1135+
* or both of the helpers being skipped.
1136+
*
1137+
* Return values:
1138+
* %nfs_ok if access is granted, or
1139+
* %nfserr_acces or %nfserr_wrongsec if access is denied
1140+
*/
1141+
__be32 check_security_flavor(struct svc_export *exp, struct svc_rqst *rqstp)
1142+
{
1143+
struct exp_flavor_info *f, *end = exp->ex_flavors + exp->ex_nflavors;
1144+
11111145
/* legacy gss-only clients are always OK: */
11121146
if (exp->ex_client == rqstp->rq_gssclient)
11131147
return 0;
@@ -1132,10 +1166,20 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
11321166
if (nfsd4_spo_must_allow(rqstp))
11331167
return 0;
11341168

1135-
denied:
11361169
return nfserr_wrongsec;
11371170
}
11381171

1172+
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
1173+
{
1174+
__be32 status;
1175+
1176+
status = check_xprtsec_policy(exp, rqstp);
1177+
if (status != nfs_ok)
1178+
return status;
1179+
1180+
return check_security_flavor(exp, rqstp);
1181+
}
1182+
11391183
/*
11401184
* Uses rq_client and rq_gssclient to find an export; uses rq_client (an
11411185
* auth_unix client) if it's available and has secinfo information;

fs/nfsd/export.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ struct svc_expkey {
100100
#define EX_WGATHER(exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
101101

102102
int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
103+
__be32 check_xprtsec_policy(struct svc_export *exp, struct svc_rqst *rqstp);
104+
__be32 check_security_flavor(struct svc_export *exp, struct svc_rqst *rqstp);
103105
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
104106

105107
/*

0 commit comments

Comments
 (0)