From patchwork Mon May 7 23:15:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 10384949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AC6C60353 for ; Mon, 7 May 2018 23:15:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4213328B7E for ; Mon, 7 May 2018 23:15:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34B6228B8C; Mon, 7 May 2018 23:15:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A0B128B7E for ; Mon, 7 May 2018 23:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753424AbeEGXPo (ORCPT ); Mon, 7 May 2018 19:15:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36286 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752954AbeEGXPo (ORCPT ); Mon, 7 May 2018 19:15:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B084A84250; Mon, 7 May 2018 23:15:43 +0000 (UTC) Received: from test1190.test.redhat.com (vpn2-54-81.bne.redhat.com [10.64.54.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCD3784424; Mon, 7 May 2018 23:15:42 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH] cifs: add lease tracking to the cached root fid Date: Tue, 8 May 2018 09:15:30 +1000 Message-Id: <20180507231530.28478-2-lsahlber@redhat.com> In-Reply-To: <20180507231530.28478-1-lsahlber@redhat.com> References: <20180507231530.28478-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 07 May 2018 23:15:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 07 May 2018 23:15:43 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lsahlber@redhat.com' RCPT:'' Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use a read lease for the cached root fid so that we can detect when the fid changes and thus we should not longer keep it cached. We detect the lease break in the context of the demultiplex loop when we receive an unsolicited lease break that matches the lease key for the root fid and setting a flag to indicate the fid is no longer valid. On next call to open_shroot() we forcibly close the fid and eventually re-open it, getting a new lease. Signed-off-by: Ronnie Sahlberg --- fs/cifs/cifsglob.h | 1 + fs/cifs/smb2misc.c | 9 +++++++++ fs/cifs/smb2ops.c | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 4f674b75bbc8..b9ec91ef3cba 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -982,6 +982,7 @@ struct cifs_tcon { #endif struct list_head pending_opens; /* list of incomplete opens */ bool valid_root_fid:1; /* Do we have a useable root fid */ + bool broken_root_fid:1; /* Has the lease been broken? */ struct mutex prfid_mutex; /* prevents reopen race after dead ses*/ struct cifs_fid *prfid; /* handle to the directory at top of share */ /* BB add field for back pointer to sb struct(s)? */ diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index f7f3ad760401..33b82de50540 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c @@ -608,6 +608,15 @@ smb2_is_valid_lease_break(char *buffer) spin_unlock(&cifs_tcp_ses_lock); return true; } + if (tcon->valid_root_fid && + !memcmp(rsp->LeaseKey, + tcon->prfid->lease_key, + SMB2_LEASE_KEY_SIZE)) { + tcon->broken_root_fid = true; + spin_unlock(&tcon->open_file_lock); + spin_unlock(&cifs_tcp_ses_lock); + return true; + } spin_unlock(&tcon->open_file_lock); } } diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index ceaa358723f0..c6edc99faac7 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -331,9 +331,16 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid) struct cifs_open_parms oparams; int rc; __le16 srch_path = 0; /* Null - since an open of top of share */ - u8 oplock = SMB2_OPLOCK_LEVEL_NONE; + u8 oplock = SMB2_OPLOCK_LEVEL_II; mutex_lock(&tcon->prfid_mutex); + if (tcon->valid_root_fid && tcon->broken_root_fid) { + cifs_dbg(FYI, "clear cached root file handle\n"); + SMB2_close(0, tcon, pfid->persistent_fid, pfid->volatile_fid); + tcon->valid_root_fid = false; + tcon->broken_root_fid = false; + } + if (tcon->valid_root_fid) { cifs_dbg(FYI, "found a cached root file handle\n"); memcpy(pfid, tcon->prfid, sizeof(struct cifs_fid)); @@ -352,6 +359,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid) if (rc == 0) { memcpy(tcon->prfid, pfid, sizeof(struct cifs_fid)); tcon->valid_root_fid = true; + tcon->broken_root_fid = false; } mutex_unlock(&tcon->prfid_mutex); return rc;