Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp518760ybl; Tue, 28 Jan 2020 07:13:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw30BkNyywiruYzTsyhrywPfNvgx645S9S6uR2cCvG8Tlw0dVFE+yXmDJCwuPBo3me6T4sZ X-Received: by 2002:a05:6830:15c2:: with SMTP id j2mr9307543otr.351.1580224389599; Tue, 28 Jan 2020 07:13:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580224389; cv=none; d=google.com; s=arc-20160816; b=EU3KYCFzSc3iArCmJBJ9bOE2aq/swmoRTwTKRr86am0hEznkhRZjdw3zQdx0oRfE/x hklqjG6nw5jhVRh8I/GylYSt8HZjuhPvM79zsZ/qsHUidDTEAUYuB8flh/uwfhHynKCY 47Xgz6lZENuLakLoRLRq8EkGJiZqAndy2kasOSHfgjqXC806UDcDKW8dGfgMFkSC6h8u fWqO2LBshG6C+oW8f2CYIg1hlJIBAp+ogILquocm1XRbeaPz0dD3ZJNWpuBMwpYVjuqn pRCw30n+6lHuHuXOFUHeGqX2Z0Jq10nY7phdD62Tn2NmBLR9oD8IZ4jDQGeFJRlH6v8x w9lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:content-language :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=FHCjbQa1iFpsgX64Wzl1txNaIuacqKkOV6H+LDHHMuE=; b=F14WEYei346NOktrckOTlgeRRRxnA3THWV/UJsBNdtT5hb9CM6WJv2tP4fHAhvnj+K qp8t7ZVycKHDJIn4dd3tbgNDb+TNAgZ2X0JeKH8Tk7IuvANcolyv+uAZ+r+H6TrJ5kdo wiSvtU3kQ7L4085AbjEZ7mMM89a8y7D6TpVBKDjKkBFW29ldwaS7rJlurUerMuKjZ4yu n6SFGF9CFOkDlwhW+Sh0zHUfd3RA9NTmeiw6gumLAxyZ87DdeiKOfPYvOsk6+zQ2ObYg 5VoY7B/zsg7UyD9HiiS9Ilz5+XEuSfVp7L34uiJEXVGw70O7JRUeEF6M8MIGyA3yAOxi PtYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="WdMjo/Yx"; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q202si658802oic.160.2020.01.28.07.12.42; Tue, 28 Jan 2020 07:13:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="WdMjo/Yx"; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgA1PMi (ORCPT + 99 others); Tue, 28 Jan 2020 10:12:38 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37225 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726072AbgA1PMi (ORCPT ); Tue, 28 Jan 2020 10:12:38 -0500 Received: by mail-wm1-f67.google.com with SMTP id f129so2954979wmf.2; Tue, 28 Jan 2020 07:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-language:thread-index; bh=FHCjbQa1iFpsgX64Wzl1txNaIuacqKkOV6H+LDHHMuE=; b=WdMjo/YxfmC3NVae9Rt9TyqK0TjSap9gGpE/uYxmQKxDNtFylAp6hJgROFX5QT+pOv M/yuDpUb5MitQ0MaENNRk7ALdsDtLnGTaklDD/ug+ozOICrSHzdlsd5MmnqtpTrQRdlV k3Ygsk7u8nK5w6tIIc7mXR3jxyBUmglqnWv0Q6T5m7d7DoWdu++y2HjyysHKg68cNUS0 EPpqPpMRiWhmUksCn/OUiD7ee1MWd7keZF5pD9sBrlMViO0/+OedXXgd7kFUndkSaGgK obmlh9piuWhcV6Eh+CMtbNXI/TKmkkR23mqqYNm8/g3Z8gEqUXpG4+G4z6TGe0xdv4Eb 4xYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-language:thread-index; bh=FHCjbQa1iFpsgX64Wzl1txNaIuacqKkOV6H+LDHHMuE=; b=q2uccemY2dMLfScLcWUOUYsTUdsu/nA/RZ3buPBF2t+TdgPTu0N1wGUpEQ/GstAQdO Oxmo7cGkE3+8mdD8xGR4ea8wK4hh+DTF5nPaA3SC0Qu+VeGsog4IydVxd0X3YTic+p/V 804mW1R5lrREuCe4L+uegCPnw5ks9RFeAf+cUDHE+D0bjVXXlo+ALPMxnnNxZXvuZRBQ by9IoedjyazFI05ffH2ByLDARBbkH6sCv7V/XTWFxHmhynOhz6uSBFwkugu9PGJXPIXM OUeANk06rt/kPkvCYCZrxbqMQU0WtAi13ZJ2jeLBvqcnAKVgGt3biXrhlX3nAUypoR+w ZKpA== X-Gm-Message-State: APjAAAVroq1AbLkfiWCI+xDSg+33l7IrixMZPG9FIgv33B9FpKMIS4Vv Mn45utuE3t07dKxFxU1po/Q= X-Received: by 2002:a1c:4144:: with SMTP id o65mr5373755wma.81.1580224355666; Tue, 28 Jan 2020 07:12:35 -0800 (PST) Received: from loulrmilkow1 ([213.52.196.70]) by smtp.gmail.com with ESMTPSA id t131sm3468772wmb.13.2020.01.28.07.12.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 07:12:35 -0800 (PST) From: "Robert Milkowski" To: , "'Trond Myklebust'" Cc: "'Anna Schumaker'" , "'Chuck Lever'" , , "'Trond Myklebust'" Subject: [PATCH v4] NFSv4.0: nfs4_do_fsinfo() should not do implicit lease renewals Date: Tue, 28 Jan 2020 15:12:33 -0000 Message-ID: <004e01d5d5ed$5e7ca490$1b75edb0$@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Content-Language: en-gb Thread-Index: AdXV6tGXVv4pqJJkS9G0izuAHIy3vA== Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Robert Milkowski Currently, each time nfs4_do_fsinfo() is called it will do an implicit NFS4 lease renewal, which is not compliant with the NFS4 specification. This can result in a lease being expired by an NFS server. Commit 83ca7f5ab31f ("NFS: Avoid PUTROOTFH when managing leases") introduced implicit client lease renewal in nfs4_do_fsinfo(), which can result in the NFSv4.0 lease to expire on a server side, and servers returning NFS4ERR_EXPIRED or NFS4ERR_STALE_CLIENTID. This can easily be reproduced by frequently unmounting a sub-mount, then stat'ing it to get it mounted again, which will delay or even completely prevent client from sending RENEW operations if no other NFS operations are issued. Eventually nfs server will expire client's lease and return an error on file access or next RENEW. This can also happen when a sub-mount is automatically unmounted due to inactivity (after nfs_mountpoint_expiry_timeout), then it is mounted again via stat(). This can result in a short window during which client's lease will expire on a server but not on a client. This specific case was observed on production systems. This patch removes the implicit lease renewal from nfs4_do_fsinfo(). Fixes: 83ca7f5ab31f ("NFS: Avoid PUTROOTFH when managing leases") Signed-off-by: Robert Milkowski --- fs/nfs/nfs4_fs.h | 4 +--- fs/nfs/nfs4proc.c | 12 ++++++++---- fs/nfs/nfs4renewd.c | 5 +---- fs/nfs/nfs4state.c | 4 +--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index a7a73b1..a5db055 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -446,9 +446,7 @@ extern int nfs4_detect_session_trunking(struct nfs_client *clp, extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); extern void nfs4_kill_renewd(struct nfs_client *); extern void nfs4_renew_state(struct work_struct *); -extern void nfs4_set_lease_period(struct nfs_client *clp, - unsigned long lease, - unsigned long lastrenewed); +extern void nfs4_set_lease_period(struct nfs_client *clp, unsigned long lease); /* nfs4state.c */ diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 76d3716..7b2d88b 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -5019,16 +5019,13 @@ static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, str struct nfs4_exception exception = { .interruptible = true, }; - unsigned long now = jiffies; int err; do { err = _nfs4_do_fsinfo(server, fhandle, fsinfo); trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); if (err == 0) { - nfs4_set_lease_period(server->nfs_client, - fsinfo->lease_time * HZ, - now); + nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); break; } err = nfs4_handle_exception(server, err, &exception); @@ -6084,6 +6081,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, .callback_data = &setclientid, .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, }; + unsigned long now = jiffies; int status; /* nfs_client_id4 */ @@ -6116,6 +6114,9 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); put_rpccred(setclientid.sc_cred); } + + if(status == 0) + do_renew_lease(clp, now); out: trace_nfs4_setclientid(clp, status); dprintk("NFS reply setclientid: %d\n", status); @@ -8203,6 +8204,7 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cre struct rpc_task *task; struct nfs41_exchange_id_args *argp; struct nfs41_exchange_id_res *resp; + unsigned long now = jiffies; int status; task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); @@ -8223,6 +8225,8 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cre if (status != 0) goto out; + do_renew_lease(clp, now); + clp->cl_clientid = resp->clientid; clp->cl_exchange_flags = resp->flags; clp->cl_seqid = resp->seqid; diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c index 6ea431b..ff876dd 100644 --- a/fs/nfs/nfs4renewd.c +++ b/fs/nfs/nfs4renewd.c @@ -138,15 +138,12 @@ * * @clp: pointer to nfs_client * @lease: new value for lease period - * @lastrenewed: time at which lease was last renewed */ void nfs4_set_lease_period(struct nfs_client *clp, - unsigned long lease, - unsigned long lastrenewed) + unsigned long lease) { spin_lock(&clp->cl_lock); clp->cl_lease_time = lease; - clp->cl_last_renewal = lastrenewed; spin_unlock(&clp->cl_lock); /* Cap maximum reconnect timeout at 1/2 lease period */ diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 3455232..f0b0027 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -92,17 +92,15 @@ static int nfs4_setup_state_renewal(struct nfs_client *clp) { int status; struct nfs_fsinfo fsinfo; - unsigned long now; if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) { nfs4_schedule_state_renewal(clp); return 0; } - now = jiffies; status = nfs4_proc_get_lease_time(clp, &fsinfo); if (status == 0) { - nfs4_set_lease_period(clp, fsinfo.lease_time * HZ, now); + nfs4_set_lease_period(clp, fsinfo.lease_time * HZ); nfs4_schedule_state_renewal(clp); } -- 1.8.3.1