Skip to content

Commit 862bee8

Browse files
committed
NFSD: Revert 6c41d9a
For some reason, the wait_on_bit() in nfsd4_deleg_getattr_conflict() is waiting forever, preventing a clean server shutdown. The requesting client might also hang waiting for a reply to the conflicting GETATTR. Invoking wait_on_bit() in an nfsd thread context is a hazard. The correct fix is to replace this wait_on_bit() call site with a mechanism that defers the conflicting GETATTR until the CB_GETATTR completes or is known to have failed. That will require some surgery and extended testing and it's late in the v6.7-rc cycle, so I'm reverting now in favor of trying again in a subsequent kernel release. This is my fault: I should have recognized the ramifications of calling wait_on_bit() in here before accepting this patch. Thanks to Dai Ngo <dai.ngo@oracle.com> for diagnosing the issue. Reported-by: Wolfgang Walter <linux-nfs@stwm.de> Closes: https://lore.kernel.org/linux-nfs/e3d43ecdad554fbdcaa7181833834f78@stwm.de/ Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 1bd773b commit 862bee8

File tree

3 files changed

+14
-118
lines changed

3 files changed

+14
-118
lines changed

fs/nfsd/nfs4state.c

Lines changed: 11 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static void free_session(struct nfsd4_session *);
127127

128128
static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
129129
static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
130-
static const struct nfsd4_callback_ops nfsd4_cb_getattr_ops;
131130

132131
static struct workqueue_struct *laundry_wq;
133132

@@ -1190,10 +1189,6 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp,
11901189
dp->dl_recalled = false;
11911190
nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client,
11921191
&nfsd4_cb_recall_ops, NFSPROC4_CLNT_CB_RECALL);
1193-
nfsd4_init_cb(&dp->dl_cb_fattr.ncf_getattr, dp->dl_stid.sc_client,
1194-
&nfsd4_cb_getattr_ops, NFSPROC4_CLNT_CB_GETATTR);
1195-
dp->dl_cb_fattr.ncf_file_modified = false;
1196-
dp->dl_cb_fattr.ncf_cb_bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE;
11971192
get_nfs4_file(fp);
11981193
dp->dl_stid.sc_file = fp;
11991194
return dp;
@@ -2901,56 +2896,11 @@ nfsd4_cb_recall_any_release(struct nfsd4_callback *cb)
29012896
spin_unlock(&nn->client_lock);
29022897
}
29032898

2904-
static int
2905-
nfsd4_cb_getattr_done(struct nfsd4_callback *cb, struct rpc_task *task)
2906-
{
2907-
struct nfs4_cb_fattr *ncf =
2908-
container_of(cb, struct nfs4_cb_fattr, ncf_getattr);
2909-
2910-
ncf->ncf_cb_status = task->tk_status;
2911-
switch (task->tk_status) {
2912-
case -NFS4ERR_DELAY:
2913-
rpc_delay(task, 2 * HZ);
2914-
return 0;
2915-
default:
2916-
return 1;
2917-
}
2918-
}
2919-
2920-
static void
2921-
nfsd4_cb_getattr_release(struct nfsd4_callback *cb)
2922-
{
2923-
struct nfs4_cb_fattr *ncf =
2924-
container_of(cb, struct nfs4_cb_fattr, ncf_getattr);
2925-
struct nfs4_delegation *dp =
2926-
container_of(ncf, struct nfs4_delegation, dl_cb_fattr);
2927-
2928-
nfs4_put_stid(&dp->dl_stid);
2929-
clear_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags);
2930-
wake_up_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY);
2931-
}
2932-
29332899
static const struct nfsd4_callback_ops nfsd4_cb_recall_any_ops = {
29342900
.done = nfsd4_cb_recall_any_done,
29352901
.release = nfsd4_cb_recall_any_release,
29362902
};
29372903

2938-
static const struct nfsd4_callback_ops nfsd4_cb_getattr_ops = {
2939-
.done = nfsd4_cb_getattr_done,
2940-
.release = nfsd4_cb_getattr_release,
2941-
};
2942-
2943-
void nfs4_cb_getattr(struct nfs4_cb_fattr *ncf)
2944-
{
2945-
struct nfs4_delegation *dp =
2946-
container_of(ncf, struct nfs4_delegation, dl_cb_fattr);
2947-
2948-
if (test_and_set_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags))
2949-
return;
2950-
refcount_inc(&dp->dl_stid.sc_count);
2951-
nfsd4_run_cb(&ncf->ncf_getattr);
2952-
}
2953-
29542904
static struct nfs4_client *create_client(struct xdr_netobj name,
29552905
struct svc_rqst *rqstp, nfs4_verifier *verf)
29562906
{
@@ -5686,8 +5636,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
56865636
struct svc_fh *parent = NULL;
56875637
int cb_up;
56885638
int status = 0;
5689-
struct kstat stat;
5690-
struct path path;
56915639

56925640
cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client);
56935641
open->op_recall = false;
@@ -5725,18 +5673,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
57255673
if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) {
57265674
open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE;
57275675
trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid);
5728-
path.mnt = currentfh->fh_export->ex_path.mnt;
5729-
path.dentry = currentfh->fh_dentry;
5730-
if (vfs_getattr(&path, &stat,
5731-
(STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE),
5732-
AT_STATX_SYNC_AS_STAT)) {
5733-
nfs4_put_stid(&dp->dl_stid);
5734-
destroy_delegation(dp);
5735-
goto out_no_deleg;
5736-
}
5737-
dp->dl_cb_fattr.ncf_cur_fsize = stat.size;
5738-
dp->dl_cb_fattr.ncf_initial_cinfo =
5739-
nfsd4_change_attribute(&stat, d_inode(currentfh->fh_dentry));
57405676
} else {
57415677
open->op_delegate_type = NFS4_OPEN_DELEGATE_READ;
57425678
trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid);
@@ -8489,8 +8425,6 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate,
84898425
* nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
84908426
* @rqstp: RPC transaction context
84918427
* @inode: file to be checked for a conflict
8492-
* @modified: return true if file was modified
8493-
* @size: new size of file if modified is true
84948428
*
84958429
* This function is called when there is a conflict between a write
84968430
* delegation and a change/size GETATTR from another client. The server
@@ -8499,23 +8433,21 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate,
84998433
* delegation before replying to the GETATTR. See RFC 8881 section
85008434
* 18.7.4.
85018435
*
8436+
* The current implementation does not support CB_GETATTR yet. However
8437+
* this can avoid recalling the delegation could be added in follow up
8438+
* work.
8439+
*
85028440
* Returns 0 if there is no conflict; otherwise an nfs_stat
85038441
* code is returned.
85048442
*/
85058443
__be32
8506-
nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode,
8507-
bool *modified, u64 *size)
8444+
nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode)
85088445
{
8446+
__be32 status;
85098447
struct file_lock_context *ctx;
8510-
struct nfs4_delegation *dp;
8511-
struct nfs4_cb_fattr *ncf;
85128448
struct file_lock *fl;
8513-
struct iattr attrs;
8514-
__be32 status;
8515-
8516-
might_sleep();
8449+
struct nfs4_delegation *dp;
85178450

8518-
*modified = false;
85198451
ctx = locks_inode_context(inode);
85208452
if (!ctx)
85218453
return 0;
@@ -8542,34 +8474,10 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode,
85428474
break_lease:
85438475
spin_unlock(&ctx->flc_lock);
85448476
nfsd_stats_wdeleg_getattr_inc();
8545-
8546-
dp = fl->fl_owner;
8547-
ncf = &dp->dl_cb_fattr;
8548-
nfs4_cb_getattr(&dp->dl_cb_fattr);
8549-
wait_on_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, TASK_INTERRUPTIBLE);
8550-
if (ncf->ncf_cb_status) {
8551-
status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
8552-
if (status != nfserr_jukebox ||
8553-
!nfsd_wait_for_delegreturn(rqstp, inode))
8554-
return status;
8555-
}
8556-
if (!ncf->ncf_file_modified &&
8557-
(ncf->ncf_initial_cinfo != ncf->ncf_cb_change ||
8558-
ncf->ncf_cur_fsize != ncf->ncf_cb_fsize))
8559-
ncf->ncf_file_modified = true;
8560-
if (ncf->ncf_file_modified) {
8561-
/*
8562-
* The server would not update the file's metadata
8563-
* with the client's modified size.
8564-
*/
8565-
attrs.ia_mtime = attrs.ia_ctime = current_time(inode);
8566-
attrs.ia_valid = ATTR_MTIME | ATTR_CTIME;
8567-
setattr_copy(&nop_mnt_idmap, inode, &attrs);
8568-
mark_inode_dirty(inode);
8569-
ncf->ncf_cur_fsize = ncf->ncf_cb_fsize;
8570-
*size = ncf->ncf_cur_fsize;
8571-
*modified = true;
8572-
}
8477+
status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
8478+
if (status != nfserr_jukebox ||
8479+
!nfsd_wait_for_delegreturn(rqstp, inode))
8480+
return status;
85738481
return 0;
85748482
}
85758483
break;

fs/nfsd/nfs4xdr.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,9 +3505,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
35053505
u32 attrmask[3];
35063506
unsigned long mask[2];
35073507
} u;
3508-
bool file_modified;
35093508
unsigned long bit;
3510-
u64 size = 0;
35113509

35123510
WARN_ON_ONCE(bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1);
35133511
WARN_ON_ONCE(!nfsd_attrs_supported(minorversion, bmval));
@@ -3534,8 +3532,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
35343532
}
35353533
args.size = 0;
35363534
if (u.attrmask[0] & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) {
3537-
status = nfsd4_deleg_getattr_conflict(rqstp, d_inode(dentry),
3538-
&file_modified, &size);
3535+
status = nfsd4_deleg_getattr_conflict(rqstp, d_inode(dentry));
35393536
if (status)
35403537
goto out;
35413538
}
@@ -3545,7 +3542,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
35453542
AT_STATX_SYNC_AS_STAT);
35463543
if (err)
35473544
goto out_nfserr;
3548-
args.size = file_modified ? size : args.stat.size;
3545+
args.size = args.stat.size;
35493546

35503547
if (!(args.stat.result_mask & STATX_BTIME))
35513548
/* underlying FS does not offer btime so we can't share it */

fs/nfsd/state.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,8 @@ struct nfs4_cb_fattr {
125125
/* from CB_GETATTR reply */
126126
u64 ncf_cb_change;
127127
u64 ncf_cb_fsize;
128-
129-
unsigned long ncf_cb_flags;
130-
bool ncf_file_modified;
131-
u64 ncf_initial_cinfo;
132-
u64 ncf_cur_fsize;
133128
};
134129

135-
/* bits for ncf_cb_flags */
136-
#define CB_GETATTR_BUSY 0
137-
138130
/*
139131
* Represents a delegation stateid. The nfs4_client holds references to these
140132
* and they are put when it is being destroyed or when the delegation is
@@ -754,6 +746,5 @@ static inline bool try_to_expire_client(struct nfs4_client *clp)
754746
}
755747

756748
extern __be32 nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp,
757-
struct inode *inode, bool *file_modified, u64 *size);
758-
extern void nfs4_cb_getattr(struct nfs4_cb_fattr *ncf);
749+
struct inode *inode);
759750
#endif /* NFSD4_STATE_H */

0 commit comments

Comments
 (0)