Skip to content

Commit ac1c13e

Browse files
committed
Merge tag 'nfsd-6.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
Pull nfsd fixes from Chuck Lever: - Address a few recently-introduced issues * tag 'nfsd-6.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux: SUNRPC: Revert 5f7fc5d NFSD: Revert 738401a NFSD: Revert 6c41d9a nfsd: hold nfsd_mutex across entire netlink operation nfsd: call nfsd_last_thread() before final nfsd_put()
2 parents 0a7a93d + bd018b9 commit ac1c13e

File tree

9 files changed

+29
-258
lines changed

9 files changed

+29
-258
lines changed

fs/nfsd/nfs4callback.c

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,7 @@ static void encode_uint32(struct xdr_stream *xdr, u32 n)
8484
static void encode_bitmap4(struct xdr_stream *xdr, const __u32 *bitmap,
8585
size_t len)
8686
{
87-
xdr_stream_encode_uint32_array(xdr, bitmap, len);
88-
}
89-
90-
static int decode_cb_fattr4(struct xdr_stream *xdr, uint32_t *bitmap,
91-
struct nfs4_cb_fattr *fattr)
92-
{
93-
fattr->ncf_cb_change = 0;
94-
fattr->ncf_cb_fsize = 0;
95-
if (bitmap[0] & FATTR4_WORD0_CHANGE)
96-
if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_change) < 0)
97-
return -NFSERR_BAD_XDR;
98-
if (bitmap[0] & FATTR4_WORD0_SIZE)
99-
if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_fsize) < 0)
100-
return -NFSERR_BAD_XDR;
101-
return 0;
87+
WARN_ON_ONCE(xdr_stream_encode_uint32_array(xdr, bitmap, len) < 0);
10288
}
10389

10490
/*
@@ -371,30 +357,6 @@ encode_cb_recallany4args(struct xdr_stream *xdr,
371357
hdr->nops++;
372358
}
373359

374-
/*
375-
* CB_GETATTR4args
376-
* struct CB_GETATTR4args {
377-
* nfs_fh4 fh;
378-
* bitmap4 attr_request;
379-
* };
380-
*
381-
* The size and change attributes are the only one
382-
* guaranteed to be serviced by the client.
383-
*/
384-
static void
385-
encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr,
386-
struct nfs4_cb_fattr *fattr)
387-
{
388-
struct nfs4_delegation *dp =
389-
container_of(fattr, struct nfs4_delegation, dl_cb_fattr);
390-
struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle;
391-
392-
encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR);
393-
encode_nfs_fh4(xdr, fh);
394-
encode_bitmap4(xdr, fattr->ncf_cb_bmap, ARRAY_SIZE(fattr->ncf_cb_bmap));
395-
hdr->nops++;
396-
}
397-
398360
/*
399361
* CB_SEQUENCE4args
400362
*
@@ -530,26 +492,6 @@ static void nfs4_xdr_enc_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr,
530492
xdr_reserve_space(xdr, 0);
531493
}
532494

533-
/*
534-
* 20.1. Operation 3: CB_GETATTR - Get Attributes
535-
*/
536-
static void nfs4_xdr_enc_cb_getattr(struct rpc_rqst *req,
537-
struct xdr_stream *xdr, const void *data)
538-
{
539-
const struct nfsd4_callback *cb = data;
540-
struct nfs4_cb_fattr *ncf =
541-
container_of(cb, struct nfs4_cb_fattr, ncf_getattr);
542-
struct nfs4_cb_compound_hdr hdr = {
543-
.ident = cb->cb_clp->cl_cb_ident,
544-
.minorversion = cb->cb_clp->cl_minorversion,
545-
};
546-
547-
encode_cb_compound4args(xdr, &hdr);
548-
encode_cb_sequence4args(xdr, cb, &hdr);
549-
encode_cb_getattr4args(xdr, &hdr, ncf);
550-
encode_cb_nops(&hdr);
551-
}
552-
553495
/*
554496
* 20.2. Operation 4: CB_RECALL - Recall a Delegation
555497
*/
@@ -605,42 +547,6 @@ static int nfs4_xdr_dec_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr,
605547
return 0;
606548
}
607549

608-
/*
609-
* 20.1. Operation 3: CB_GETATTR - Get Attributes
610-
*/
611-
static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp,
612-
struct xdr_stream *xdr,
613-
void *data)
614-
{
615-
struct nfsd4_callback *cb = data;
616-
struct nfs4_cb_compound_hdr hdr;
617-
int status;
618-
u32 bitmap[3] = {0};
619-
u32 attrlen;
620-
struct nfs4_cb_fattr *ncf =
621-
container_of(cb, struct nfs4_cb_fattr, ncf_getattr);
622-
623-
status = decode_cb_compound4res(xdr, &hdr);
624-
if (unlikely(status))
625-
return status;
626-
627-
status = decode_cb_sequence4res(xdr, cb);
628-
if (unlikely(status || cb->cb_seq_status))
629-
return status;
630-
631-
status = decode_cb_op_status(xdr, OP_CB_GETATTR, &cb->cb_status);
632-
if (status)
633-
return status;
634-
if (xdr_stream_decode_uint32_array(xdr, bitmap, 3) < 0)
635-
return -NFSERR_BAD_XDR;
636-
if (xdr_stream_decode_u32(xdr, &attrlen) < 0)
637-
return -NFSERR_BAD_XDR;
638-
if (attrlen > (sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize)))
639-
return -NFSERR_BAD_XDR;
640-
status = decode_cb_fattr4(xdr, bitmap, ncf);
641-
return status;
642-
}
643-
644550
/*
645551
* 20.2. Operation 4: CB_RECALL - Recall a Delegation
646552
*/
@@ -949,7 +855,6 @@ static const struct rpc_procinfo nfs4_cb_procedures[] = {
949855
PROC(CB_NOTIFY_LOCK, COMPOUND, cb_notify_lock, cb_notify_lock),
950856
PROC(CB_OFFLOAD, COMPOUND, cb_offload, cb_offload),
951857
PROC(CB_RECALL_ANY, COMPOUND, cb_recall_any, cb_recall_any),
952-
PROC(CB_GETATTR, COMPOUND, cb_getattr, cb_getattr),
953858
};
954859

955860
static unsigned int nfs4_cb_counts[ARRAY_SIZE(nfs4_cb_procedures)];

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
{
@@ -5685,8 +5635,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
56855635
struct svc_fh *parent = NULL;
56865636
int cb_up;
56875637
int status = 0;
5688-
struct kstat stat;
5689-
struct path path;
56905638

56915639
cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client);
56925640
open->op_recall = false;
@@ -5724,18 +5672,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
57245672
if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) {
57255673
open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE;
57265674
trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid);
5727-
path.mnt = currentfh->fh_export->ex_path.mnt;
5728-
path.dentry = currentfh->fh_dentry;
5729-
if (vfs_getattr(&path, &stat,
5730-
(STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE),
5731-
AT_STATX_SYNC_AS_STAT)) {
5732-
nfs4_put_stid(&dp->dl_stid);
5733-
destroy_delegation(dp);
5734-
goto out_no_deleg;
5735-
}
5736-
dp->dl_cb_fattr.ncf_cur_fsize = stat.size;
5737-
dp->dl_cb_fattr.ncf_initial_cinfo =
5738-
nfsd4_change_attribute(&stat, d_inode(currentfh->fh_dentry));
57395675
} else {
57405676
open->op_delegate_type = NFS4_OPEN_DELEGATE_READ;
57415677
trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid);
@@ -8492,8 +8428,6 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate,
84928428
* nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
84938429
* @rqstp: RPC transaction context
84948430
* @inode: file to be checked for a conflict
8495-
* @modified: return true if file was modified
8496-
* @size: new size of file if modified is true
84978431
*
84988432
* This function is called when there is a conflict between a write
84998433
* delegation and a change/size GETATTR from another client. The server
@@ -8502,23 +8436,21 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate,
85028436
* delegation before replying to the GETATTR. See RFC 8881 section
85038437
* 18.7.4.
85048438
*
8439+
* The current implementation does not support CB_GETATTR yet. However
8440+
* this can avoid recalling the delegation could be added in follow up
8441+
* work.
8442+
*
85058443
* Returns 0 if there is no conflict; otherwise an nfs_stat
85068444
* code is returned.
85078445
*/
85088446
__be32
8509-
nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode,
8510-
bool *modified, u64 *size)
8447+
nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode)
85118448
{
8449+
__be32 status;
85128450
struct file_lock_context *ctx;
8513-
struct nfs4_delegation *dp;
8514-
struct nfs4_cb_fattr *ncf;
85158451
struct file_lock *fl;
8516-
struct iattr attrs;
8517-
__be32 status;
8518-
8519-
might_sleep();
8452+
struct nfs4_delegation *dp;
85208453

8521-
*modified = false;
85228454
ctx = locks_inode_context(inode);
85238455
if (!ctx)
85248456
return 0;
@@ -8545,34 +8477,10 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode,
85458477
break_lease:
85468478
spin_unlock(&ctx->flc_lock);
85478479
nfsd_stats_wdeleg_getattr_inc();
8548-
8549-
dp = fl->fl_owner;
8550-
ncf = &dp->dl_cb_fattr;
8551-
nfs4_cb_getattr(&dp->dl_cb_fattr);
8552-
wait_on_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, TASK_INTERRUPTIBLE);
8553-
if (ncf->ncf_cb_status) {
8554-
status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
8555-
if (status != nfserr_jukebox ||
8556-
!nfsd_wait_for_delegreturn(rqstp, inode))
8557-
return status;
8558-
}
8559-
if (!ncf->ncf_file_modified &&
8560-
(ncf->ncf_initial_cinfo != ncf->ncf_cb_change ||
8561-
ncf->ncf_cur_fsize != ncf->ncf_cb_fsize))
8562-
ncf->ncf_file_modified = true;
8563-
if (ncf->ncf_file_modified) {
8564-
/*
8565-
* The server would not update the file's metadata
8566-
* with the client's modified size.
8567-
*/
8568-
attrs.ia_mtime = attrs.ia_ctime = current_time(inode);
8569-
attrs.ia_valid = ATTR_MTIME | ATTR_CTIME;
8570-
setattr_copy(&nop_mnt_idmap, inode, &attrs);
8571-
mark_inode_dirty(inode);
8572-
ncf->ncf_cur_fsize = ncf->ncf_cb_fsize;
8573-
*size = ncf->ncf_cur_fsize;
8574-
*modified = true;
8575-
}
8480+
status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
8481+
if (status != nfserr_jukebox ||
8482+
!nfsd_wait_for_delegreturn(rqstp, inode))
8483+
return status;
85768484
return 0;
85778485
}
85788486
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/nfsctl.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,10 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred
705705

706706
err = svc_addsock(nn->nfsd_serv, net, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred);
707707

708-
if (err >= 0 &&
709-
!nn->nfsd_serv->sv_nrthreads && !xchg(&nn->keep_active, 1))
708+
if (err < 0 && !nn->nfsd_serv->sv_nrthreads && !nn->keep_active)
709+
nfsd_last_thread(net);
710+
else if (err >= 0 &&
711+
!nn->nfsd_serv->sv_nrthreads && !xchg(&nn->keep_active, 1))
710712
svc_get(nn->nfsd_serv);
711713

712714
nfsd_put(net);
@@ -757,6 +759,9 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct cr
757759
svc_xprt_put(xprt);
758760
}
759761
out_err:
762+
if (!nn->nfsd_serv->sv_nrthreads && !nn->keep_active)
763+
nfsd_last_thread(net);
764+
760765
nfsd_put(net);
761766
return err;
762767
}
@@ -1510,11 +1515,10 @@ int nfsd_nl_rpc_status_get_start(struct netlink_callback *cb)
15101515
int ret = -ENODEV;
15111516

15121517
mutex_lock(&nfsd_mutex);
1513-
if (nn->nfsd_serv) {
1514-
svc_get(nn->nfsd_serv);
1518+
if (nn->nfsd_serv)
15151519
ret = 0;
1516-
}
1517-
mutex_unlock(&nfsd_mutex);
1520+
else
1521+
mutex_unlock(&nfsd_mutex);
15181522

15191523
return ret;
15201524
}
@@ -1686,8 +1690,6 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb,
16861690
*/
16871691
int nfsd_nl_rpc_status_get_done(struct netlink_callback *cb)
16881692
{
1689-
mutex_lock(&nfsd_mutex);
1690-
nfsd_put(sock_net(cb->skb->sk));
16911693
mutex_unlock(&nfsd_mutex);
16921694

16931695
return 0;

fs/nfsd/nfsd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);
155155
int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change);
156156
void nfsd_reset_versions(struct nfsd_net *nn);
157157
int nfsd_create_serv(struct net *net);
158+
void nfsd_last_thread(struct net *net);
158159

159160
extern int nfsd_max_blksize;
160161

0 commit comments

Comments
 (0)