Skip to content

Commit 83ca7f5

Browse files
chuckleverTrond Myklebust
authored andcommitted
NFS: Avoid PUTROOTFH when managing leases
Currently, the compound operation the Linux NFS client sends to the server to confirm a client ID looks like this: { SETCLIENTID_CONFIRM; PUTROOTFH; GETATTR(lease_time) } Once the lease is confirmed, it makes sense to know how long before the client will have to renew it. And, performing these operations in the same compound saves a round trip. Unfortunately, this arrangement assumes that the security flavor used for establishing a client ID can also be used to access the server's pseudo-fs. If the server requires a different security flavor to access its pseudo-fs than it allowed for the client's SETCLIENTID operation, the PUTROOTFH in this compound fails with NFS4ERR_WRONGSEC. Even though the SETCLIENTID_CONFIRM succeeded, our client's trunking detection logic interprets the failure of the compound as a failure by the server to confirm the client ID. As part of server trunking detection, the client then begins another SETCLIENTID pass with the same nfs4_client_id. This fails with NFS4ERR_CLID_INUSE because the first SETCLIENTID/SETCLIENTID_CONFIRM already succeeded in confirming that client ID -- it was the PUTROOTFH operation that caused the SETCLIENTID_CONFIRM compound to fail. To address this issue, separate the "establish client ID" step from the "accessing the server's pseudo-fs root" step. The first access of the server's pseudo-fs may require retrying the PUTROOTFH operation with different security flavors. This access is done in nfs4_proc_get_rootfh(). That leaves the matter of how to retrieve the server's lease time. nfs4_proc_fsinfo() already retrieves the lease time value, though none of its callers do anything with the retrieved value (nor do they mark the lease as "renewed"). Note that NFSv4.1 state recovery invokes nfs4_proc_get_lease_time() using the lease management security flavor. This may cause some heartburn if that security flavor isn't the same as the security flavor the server requires for accessing the pseudo-fs. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Cc: Bryan Schumaker <bjschuma@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 2ed4b95 commit 83ca7f5

2 files changed

Lines changed: 15 additions & 28 deletions

File tree

‎fs/nfs/nfs4proc.c‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,12 +3455,21 @@ static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
34553455
static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
34563456
{
34573457
struct nfs4_exception exception = { };
3458+
unsigned long now = jiffies;
34583459
int err;
34593460

34603461
do {
3461-
err = nfs4_handle_exception(server,
3462-
_nfs4_do_fsinfo(server, fhandle, fsinfo),
3463-
&exception);
3462+
err = _nfs4_do_fsinfo(server, fhandle, fsinfo);
3463+
if (err == 0) {
3464+
struct nfs_client *clp = server->nfs_client;
3465+
3466+
spin_lock(&clp->cl_lock);
3467+
clp->cl_lease_time = fsinfo->lease_time * HZ;
3468+
clp->cl_last_renewal = now;
3469+
spin_unlock(&clp->cl_lock);
3470+
break;
3471+
}
3472+
err = nfs4_handle_exception(server, err, &exception);
34643473
} while (exception.retry);
34653474
return err;
34663475
}
@@ -4301,27 +4310,17 @@ int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
43014310
struct nfs4_setclientid_res *arg,
43024311
struct rpc_cred *cred)
43034312
{
4304-
struct nfs_fsinfo fsinfo;
43054313
struct rpc_message msg = {
43064314
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
43074315
.rpc_argp = arg,
4308-
.rpc_resp = &fsinfo,
43094316
.rpc_cred = cred,
43104317
};
4311-
unsigned long now;
43124318
int status;
43134319

43144320
dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
43154321
clp->cl_rpcclient->cl_auth->au_ops->au_name,
43164322
clp->cl_clientid);
4317-
now = jiffies;
43184323
status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4319-
if (status == 0) {
4320-
spin_lock(&clp->cl_lock);
4321-
clp->cl_lease_time = fsinfo.lease_time * HZ;
4322-
clp->cl_last_renewal = now;
4323-
spin_unlock(&clp->cl_lock);
4324-
}
43254324
dprintk("NFS reply setclientid_confirm: %d\n", status);
43264325
return status;
43274326
}

‎fs/nfs/nfs4xdr.c‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,10 @@ static int nfs4_stat_to_errno(int);
530530
decode_setclientid_maxsz)
531531
#define NFS4_enc_setclientid_confirm_sz \
532532
(compound_encode_hdr_maxsz + \
533-
encode_setclientid_confirm_maxsz + \
534-
encode_putrootfh_maxsz + \
535-
encode_fsinfo_maxsz)
533+
encode_setclientid_confirm_maxsz)
536534
#define NFS4_dec_setclientid_confirm_sz \
537535
(compound_decode_hdr_maxsz + \
538-
decode_setclientid_confirm_maxsz + \
539-
decode_putrootfh_maxsz + \
540-
decode_fsinfo_maxsz)
536+
decode_setclientid_confirm_maxsz)
541537
#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
542538
encode_sequence_maxsz + \
543539
encode_putfh_maxsz + \
@@ -2608,12 +2604,9 @@ static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
26082604
struct compound_hdr hdr = {
26092605
.nops = 0,
26102606
};
2611-
const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
26122607

26132608
encode_compound_hdr(xdr, req, &hdr);
26142609
encode_setclientid_confirm(xdr, arg, &hdr);
2615-
encode_putrootfh(xdr, &hdr);
2616-
encode_fsinfo(xdr, lease_bitmap, &hdr);
26172610
encode_nops(&hdr);
26182611
}
26192612

@@ -6647,19 +6640,14 @@ static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
66476640
* Decode SETCLIENTID_CONFIRM response
66486641
*/
66496642
static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6650-
struct xdr_stream *xdr,
6651-
struct nfs_fsinfo *fsinfo)
6643+
struct xdr_stream *xdr)
66526644
{
66536645
struct compound_hdr hdr;
66546646
int status;
66556647

66566648
status = decode_compound_hdr(xdr, &hdr);
66576649
if (!status)
66586650
status = decode_setclientid_confirm(xdr);
6659-
if (!status)
6660-
status = decode_putrootfh(xdr);
6661-
if (!status)
6662-
status = decode_fsinfo(xdr, fsinfo);
66636651
return status;
66646652
}
66656653

0 commit comments

Comments
 (0)