From patchwork Mon Mar 8 23:07:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Di/1lTBU; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYtg5Jdfz9sWT for ; Tue, 9 Mar 2021 10:08:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230343AbhCHXI0 (ORCPT ); Mon, 8 Mar 2021 18:08:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25656 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbhCHXIB (ORCPT ); Mon, 8 Mar 2021 18:08:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=fD3+k/MsaAqe7vanPt2856Nv40cCFrPvn/hwPBMOt+8=; b=Di/1lTBUuw4VoLxw1LrOFUGlQe+ODLJeytB2XM25L9OloyYuXaqIgqMlwgj+F5RnbHZ2mN zDcEhUAapzXL/aC7GTb0ADE0Mh7/B6oBBp3DV97s+OZZgakItR3YnR8A4XBmPk1/1vBVt0 JNGdEnHSFy2EaMnDIDO2xGwNmXHLJyc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-i-YmUoa5MyeC3-DTxbQHZA-1; Mon, 08 Mar 2021 18:07:59 -0500 X-MC-Unique: i-YmUoa5MyeC3-DTxbQHZA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BD92814314; Mon, 8 Mar 2021 23:07:58 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07B246085A; Mon, 8 Mar 2021 23:07:57 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 1/9] cifs: move the check for nohandlecache into open_shroot Date: Tue, 9 Mar 2021 09:07:27 +1000 Message-Id: <20210308230735.337-2-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org instead of doing it in the callsites for open_shroot. Signed-off-by: Ronnie Sahlberg --- fs/cifs/smb2inode.c | 24 +++++++++++------------- fs/cifs/smb2ops.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index 1f900b81c34a..3d59614cbe8f 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c @@ -511,7 +511,6 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, int rc; struct smb2_file_all_info *smb2_data; __u32 create_options = 0; - bool no_cached_open = tcon->nohandlecache; struct cifsFileInfo *cfile; struct cached_fid *cfid = NULL; @@ -524,23 +523,22 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, return -ENOMEM; /* If it is a root and its handle is cached then use it */ - if (!strlen(full_path) && !no_cached_open) { + if (!strlen(full_path)) { rc = open_shroot(xid, tcon, cifs_sb, &cfid); - if (rc) - goto out; - - if (tcon->crfid.file_all_info_is_valid) { - move_smb2_info_to_cifs(data, + if (!rc) { + if (tcon->crfid.file_all_info_is_valid) { + move_smb2_info_to_cifs(data, &tcon->crfid.file_all_info); - } else { - rc = SMB2_query_info(xid, tcon, + } else { + rc = SMB2_query_info(xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); - if (!rc) - move_smb2_info_to_cifs(data, smb2_data); + if (!rc) + move_smb2_info_to_cifs(data, smb2_data); + } + close_shroot(cfid); + goto out; } - close_shroot(cfid); - goto out; } cifs_get_readable_path(tcon, full_path, &cfile); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index f5087295424c..7ee6926153b8 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -746,6 +746,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, u8 oplock = SMB2_OPLOCK_LEVEL_II; struct cifs_fid *pfid; + if (tcon->nohandlecache) + return -ENOTSUPP; + mutex_lock(&tcon->crfid.fid_mutex); if (tcon->crfid.is_valid) { cifs_dbg(FYI, "found a cached root file handle\n"); @@ -914,7 +917,6 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, u8 oplock = SMB2_OPLOCK_LEVEL_NONE; struct cifs_open_parms oparms; struct cifs_fid fid; - bool no_cached_open = tcon->nohandlecache; struct cached_fid *cfid = NULL; oparms.tcon = tcon; @@ -924,14 +926,12 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - if (no_cached_open) { + rc = open_shroot(xid, tcon, cifs_sb, &cfid); + if (rc == 0) + memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); + else rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL, NULL); - } else { - rc = open_shroot(xid, tcon, cifs_sb, &cfid); - if (rc == 0) - memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); - } if (rc) return; @@ -945,7 +945,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, FS_VOLUME_INFORMATION); SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ - if (no_cached_open) + if (cfid == NULL) SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); else close_shroot(cfid); From patchwork Mon Mar 8 23:07:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=asaQt/u/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYtf0HCNz9sVv for ; Tue, 9 Mar 2021 10:08:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231176AbhCHXI0 (ORCPT ); Mon, 8 Mar 2021 18:08:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56164 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbhCHXH6 (ORCPT ); Mon, 8 Mar 2021 18:07:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=AVxGdr7lDl56PxhdLiS/DNr7Pme1x2/5gez8xA/7O4E=; b=asaQt/u/VSjpau/6cthT6WpbSR7s9poj1rXc4Rl7UijY9dZZb5P47B/mPEp0mxqjtrthVR JqVQBgW4dPF30poTlmyWdRWaXCBQ+T3LWy5hZdVCNlG6uXa9QGFwgQ4pLXoS4Ap42taD83 KqoZgCBBfczscHbknfaPucHkNHb1/No= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-321-vcw2LaBYOQab_Nlkfsp5_Q-1; Mon, 08 Mar 2021 18:07:56 -0500 X-MC-Unique: vcw2LaBYOQab_Nlkfsp5_Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 185C21823E44; Mon, 8 Mar 2021 23:07:55 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 787321A8A3; Mon, 8 Mar 2021 23:07:54 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 2/9] cifs: pass a path to open_shroot and check if it is the root or not Date: Tue, 9 Mar 2021 09:07:28 +1000 Message-Id: <20210308230735.337-3-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Move the check for the directory path into the open_shroot() function but still fail for any non-root directories. This is preparation for later when we will start using the cache also for other directories than the root. Signed-off-by: Ronnie Sahlberg --- fs/cifs/smb2inode.c | 22 ++++++++++------------ fs/cifs/smb2ops.c | 6 +++++- fs/cifs/smb2proto.h | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index 3d59614cbe8f..67f80c9561fc 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c @@ -523,22 +523,20 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, return -ENOMEM; /* If it is a root and its handle is cached then use it */ - if (!strlen(full_path)) { - rc = open_shroot(xid, tcon, cifs_sb, &cfid); - if (!rc) { - if (tcon->crfid.file_all_info_is_valid) { - move_smb2_info_to_cifs(data, + rc = open_shroot(xid, tcon, full_path, cifs_sb, &cfid); + if (!rc) { + if (tcon->crfid.file_all_info_is_valid) { + move_smb2_info_to_cifs(data, &tcon->crfid.file_all_info); - } else { - rc = SMB2_query_info(xid, tcon, + } else { + rc = SMB2_query_info(xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); - if (!rc) - move_smb2_info_to_cifs(data, smb2_data); - } - close_shroot(cfid); - goto out; + if (!rc) + move_smb2_info_to_cifs(data, smb2_data); } + close_shroot(cfid); + goto out; } cifs_get_readable_path(tcon, full_path, &cfile); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 7ee6926153b8..96ff946674e6 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -728,6 +728,7 @@ smb2_cached_lease_break(struct work_struct *work) * Open the directory at the root of a share */ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, + const char *path, struct cifs_sb_info *cifs_sb, struct cached_fid **cfid) { @@ -749,6 +750,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, if (tcon->nohandlecache) return -ENOTSUPP; + if (strlen(path)) + return -ENOTSUPP; + mutex_lock(&tcon->crfid.fid_mutex); if (tcon->crfid.is_valid) { cifs_dbg(FYI, "found a cached root file handle\n"); @@ -926,7 +930,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc = open_shroot(xid, tcon, cifs_sb, &cfid); + rc = open_shroot(xid, tcon, "", cifs_sb, &cfid); if (rc == 0) memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); else diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index 9565e27681a5..7e4fc69c8b01 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h @@ -70,6 +70,7 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid); extern int open_shroot(unsigned int xid, struct cifs_tcon *tcon, + const char *path, struct cifs_sb_info *cifs_sb, struct cached_fid **cfid); extern void close_shroot(struct cached_fid *cfid); From patchwork Mon Mar 8 23:07:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VGG/GFna; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYt12ghJz9sVv for ; Tue, 9 Mar 2021 10:08:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbhCHXHx (ORCPT ); Mon, 8 Mar 2021 18:07:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41518 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbhCHXHu (ORCPT ); Mon, 8 Mar 2021 18:07:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=vPScEQVToWeWYSQZ6qRplx5pZyMNo8DfrEbKPjr7sps=; b=VGG/GFna6Ewr+rI43BIdyu2+9azoLyN0z1jz46Zev7TpdtX7U5GEQ1SoHuPicwByacwo9Q ngY9TSdQ9QxKiUzf5vlYGRuyVQWwAr5MndDzZJXydvhrouO43DmZbwBau/uZC2uYDWBrr8 dfLBq4ViVJgybylBfxS865VsGkAXz00= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-591-B6ha9cDuP1Sw1elI9rFLUg-1; Mon, 08 Mar 2021 18:07:48 -0500 X-MC-Unique: B6ha9cDuP1Sw1elI9rFLUg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77BCF1823E37; Mon, 8 Mar 2021 23:07:47 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8D675C5E1; Mon, 8 Mar 2021 23:07:46 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 3/9] cifs: rename the *_shroot* functions to *_cached_dir* Date: Tue, 9 Mar 2021 09:07:29 +1000 Message-Id: <20210308230735.337-4-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org These functions will eventually be used to cache any directory, not just the root so change the names. Signed-off-by: Ronnie Sahlberg --- fs/cifs/cifssmb.c | 2 +- fs/cifs/smb2inode.c | 4 ++-- fs/cifs/smb2ops.c | 19 ++++++++++--------- fs/cifs/smb2pdu.c | 2 +- fs/cifs/smb2proto.h | 14 +++++++------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 0496934feecb..3419289b7663 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -114,7 +114,7 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon) mutex_lock(&tcon->crfid.fid_mutex); tcon->crfid.is_valid = false; /* cached handle is not valid, so SMB2_CLOSE won't be sent below */ - close_shroot_lease_locked(&tcon->crfid); + close_cached_dir_lease_locked(&tcon->crfid); memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid)); mutex_unlock(&tcon->crfid.fid_mutex); diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index 67f80c9561fc..0d0bc0b878be 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c @@ -523,7 +523,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, return -ENOMEM; /* If it is a root and its handle is cached then use it */ - rc = open_shroot(xid, tcon, full_path, cifs_sb, &cfid); + rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid); if (!rc) { if (tcon->crfid.file_all_info_is_valid) { move_smb2_info_to_cifs(data, @@ -535,7 +535,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, if (!rc) move_smb2_info_to_cifs(data, smb2_data); } - close_shroot(cfid); + close_cached_dir(cfid); goto out; } diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 96ff946674e6..d2858c25ff17 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -693,14 +693,14 @@ smb2_close_cached_fid(struct kref *ref) } } -void close_shroot(struct cached_fid *cfid) +void close_cached_dir(struct cached_fid *cfid) { mutex_lock(&cfid->fid_mutex); kref_put(&cfid->refcount, smb2_close_cached_fid); mutex_unlock(&cfid->fid_mutex); } -void close_shroot_lease_locked(struct cached_fid *cfid) +void close_cached_dir_lease_locked(struct cached_fid *cfid) { if (cfid->has_lease) { cfid->has_lease = false; @@ -708,10 +708,10 @@ void close_shroot_lease_locked(struct cached_fid *cfid) } } -void close_shroot_lease(struct cached_fid *cfid) +void close_cached_dir_lease(struct cached_fid *cfid) { mutex_lock(&cfid->fid_mutex); - close_shroot_lease_locked(cfid); + close_cached_dir_lease_locked(cfid); mutex_unlock(&cfid->fid_mutex); } @@ -721,13 +721,14 @@ smb2_cached_lease_break(struct work_struct *work) struct cached_fid *cfid = container_of(work, struct cached_fid, lease_break); - close_shroot_lease(cfid); + close_cached_dir_lease(cfid); } /* - * Open the directory at the root of a share + * Open the and cache a directory handle. + * Only supported for the root handle. */ -int open_shroot(unsigned int xid, struct cifs_tcon *tcon, +int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, const char *path, struct cifs_sb_info *cifs_sb, struct cached_fid **cfid) @@ -930,7 +931,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc = open_shroot(xid, tcon, "", cifs_sb, &cfid); + rc = open_cached_dir(xid, tcon, "", cifs_sb, &cfid); if (rc == 0) memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); else @@ -952,7 +953,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, if (cfid == NULL) SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); else - close_shroot(cfid); + close_cached_dir(cfid); } static void diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 4bbb6126b14d..0a03f8d88173 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -1857,7 +1857,7 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) return 0; - close_shroot_lease(&tcon->crfid); + close_cached_dir_lease(&tcon->crfid); rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, ses->server, (void **) &req, diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index 7e4fc69c8b01..ddbdf9923625 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h @@ -69,13 +69,13 @@ extern struct cifs_ses *smb2_find_smb_ses(struct TCP_Server_Info *server, extern int smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid); -extern int open_shroot(unsigned int xid, struct cifs_tcon *tcon, - const char *path, - struct cifs_sb_info *cifs_sb, - struct cached_fid **cfid); -extern void close_shroot(struct cached_fid *cfid); -extern void close_shroot_lease(struct cached_fid *cfid); -extern void close_shroot_lease_locked(struct cached_fid *cfid); +extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, + const char *path, + struct cifs_sb_info *cifs_sb, + struct cached_fid **cfid); +extern void close_cached_dir(struct cached_fid *cfid); +extern void close_cached_dir_lease(struct cached_fid *cfid); +extern void close_cached_dir_lease_locked(struct cached_fid *cfid); extern void move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src); extern int smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon, From patchwork Mon Mar 8 23:07:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bkcn+Q+c; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYtg31DDz9sVv for ; Tue, 9 Mar 2021 10:08:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbhCHXI1 (ORCPT ); Mon, 8 Mar 2021 18:08:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55894 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231126AbhCHXIG (ORCPT ); Mon, 8 Mar 2021 18:08:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=no5NsuOA8XUrKAX3gcb2zK9l8qYmpCZDnx9e6UlyZwY=; b=Bkcn+Q+c+ujrFVRhIpFjmBTMcxcPt7W27uC2a+6b+7ihpSCIFBJ5NEXG4ZiRGhUQPXpqhs EErUwU2cvNsaWkihhV9VtcrRBaJN7Zk4ZT6+tMilSHhdV+s+7/T8tHOSJ558SF15TKRAzK TYSgOM5SuRB9E/RuwD/9SnMZDBJ47aQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-oe6y8tVsONm8uSTQHHk8SA-1; Mon, 08 Mar 2021 18:08:01 -0500 X-MC-Unique: oe6y8tVsONm8uSTQHHk8SA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D444E801814; Mon, 8 Mar 2021 23:08:00 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CAAE1A8A6; Mon, 8 Mar 2021 23:08:00 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 4/9] cifs: store a pointer to the root dentry in cifs_sb_info once we have completed mounting the share Date: Tue, 9 Mar 2021 09:07:30 +1000 Message-Id: <20210308230735.337-5-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org And use this to only allow to take out a shared handle once the mount has completed and the sb becomes available. This will become important in follow up patches where we will start holding a reference to the directory dentry for the shared handle during the lifetime of the handle. Signed-off-by: Ronnie Sahlberg --- fs/cifs/cifs_fs_sb.h | 4 ++++ fs/cifs/cifsfs.c | 9 +++++++++ fs/cifs/smb2ops.c | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h index aa77edc12212..2a5325a7ae49 100644 --- a/fs/cifs/cifs_fs_sb.h +++ b/fs/cifs/cifs_fs_sb.h @@ -81,5 +81,9 @@ struct cifs_sb_info { * (cifs_autodisable_serverino) in order to match new mounts. */ bool mnt_cifs_serverino_autodisabled; + /* + * Available once the mount has completed. + */ + struct dentry *root; }; #endif /* _CIFS_FS_SB_H */ diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 3b61f09f3e1b..c075ef1dd755 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -257,6 +257,12 @@ cifs_read_super(struct super_block *sb) static void cifs_kill_sb(struct super_block *sb) { struct cifs_sb_info *cifs_sb = CIFS_SB(sb); + + if (cifs_sb->root) { + dput(cifs_sb->root); + cifs_sb->root = NULL; + } + kill_anon_super(sb); cifs_umount(cifs_sb); } @@ -886,6 +892,9 @@ cifs_smb3_do_mount(struct file_system_type *fs_type, if (IS_ERR(root)) goto out_super; + if (cifs_sb) + cifs_sb->root = dget(root); + cifs_dbg(FYI, "dentry root is: %p\n", root); return root; diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index d2858c25ff17..7f4da573b9e8 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -751,8 +751,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, if (tcon->nohandlecache) return -ENOTSUPP; + if (cifs_sb->root == NULL) + return -ENOENT; + if (strlen(path)) - return -ENOTSUPP; + return -ENOENT; mutex_lock(&tcon->crfid.fid_mutex); if (tcon->crfid.is_valid) { From patchwork Mon Mar 8 23:07:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PZyeVmWj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYth0nDbz9sVv for ; Tue, 9 Mar 2021 10:09:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbhCHXI0 (ORCPT ); Mon, 8 Mar 2021 18:08:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43418 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbhCHXIA (ORCPT ); Mon, 8 Mar 2021 18:08:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=zna/7Vms2Vhrs3mK9TzMyvMz/ZPu5E5/6bUbYn0zO/U=; b=PZyeVmWjVbUw8b66/2g9ZDAd4J6/Ge1QK0pltagHr+lRmSK4oGKlKYuHpvhwJd4S9TUPdl 5m6Gdg8JqwBvtKGr5UVlEMsrTGd6GqXBmytxsxg1GSHa4T1DUv2xws69wtufYmqh0gQSjl +b2Fnj9RCWOl7p2zc4Z6yqo2NZhUAG4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-399-hBRWTDhtM4GAbPWP_CM2Fw-1; Mon, 08 Mar 2021 18:07:57 -0500 X-MC-Unique: hBRWTDhtM4GAbPWP_CM2Fw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D43FF1823E24; Mon, 8 Mar 2021 23:07:56 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FB846085A; Mon, 8 Mar 2021 23:07:56 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 5/9] cifs: Grab a reference for the dentry of the cached directory during the lifetime of the cache Date: Tue, 9 Mar 2021 09:07:31 +1000 Message-Id: <20210308230735.337-6-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org We need to hold both a reference for the root/superblock as well as the directory that we are caching. We need to drop these references before we call kill_anon_sb(). At this point, the root and the cached dentries are always the same but this will change once we start caching other directories as well. Signed-off-by: Ronnie Sahlberg --- fs/cifs/cifsfs.c | 17 +++++++++++++++++ fs/cifs/cifsglob.h | 1 + fs/cifs/smb2ops.c | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index c075ef1dd755..154f1c94ea46 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -257,11 +257,28 @@ cifs_read_super(struct super_block *sb) static void cifs_kill_sb(struct super_block *sb) { struct cifs_sb_info *cifs_sb = CIFS_SB(sb); + struct cifs_tcon *tcon; + struct cached_fid *cfid; + /* + * We ned to release all dentries for the cached directories + * before we kill the sb. + */ if (cifs_sb->root) { dput(cifs_sb->root); cifs_sb->root = NULL; } + tcon = cifs_sb_master_tcon(cifs_sb); + if (tcon) { + cfid = &tcon->crfid; + mutex_lock(&cfid->fid_mutex); + if (cfid->dentry) { + + dput(cfid->dentry); + cfid->dentry = NULL; + } + mutex_unlock(&cfid->fid_mutex); + } kill_anon_super(sb); cifs_umount(cifs_sb); diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 3de3c5908a72..7d9b47f2f04f 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -992,6 +992,7 @@ struct cached_fid { struct cifs_fid *fid; struct mutex fid_mutex; struct cifs_tcon *tcon; + struct dentry *dentry; struct work_struct lease_break; struct smb2_file_all_info file_all_info; }; diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 7f4da573b9e8..81eb7f10368b 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -690,6 +690,10 @@ smb2_close_cached_fid(struct kref *ref) cfid->is_valid = false; cfid->file_all_info_is_valid = false; cfid->has_lease = false; + if (cfid->dentry) { + dput(cfid->dentry); + cfid->dentry = NULL; + } } } @@ -747,6 +751,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, __le16 utf16_path = 0; /* Null - since an open of top of share */ u8 oplock = SMB2_OPLOCK_LEVEL_II; struct cifs_fid *pfid; + struct dentry *dentry; if (tcon->nohandlecache) return -ENOTSUPP; @@ -757,6 +762,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, if (strlen(path)) return -ENOENT; + dentry = cifs_sb->root; + mutex_lock(&tcon->crfid.fid_mutex); if (tcon->crfid.is_valid) { cifs_dbg(FYI, "found a cached root file handle\n"); @@ -881,6 +888,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid)); tcon->crfid.tcon = tcon; tcon->crfid.is_valid = true; + tcon->crfid.dentry = dentry; + dget(dentry); kref_init(&tcon->crfid.refcount); /* BB TBD check to see if oplock level check can be removed below */ From patchwork Mon Mar 8 23:07:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OX5EYfya; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYt1527Yz9sWT for ; Tue, 9 Mar 2021 10:08:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229488AbhCHXHx (ORCPT ); Mon, 8 Mar 2021 18:07:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32463 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbhCHXHt (ORCPT ); Mon, 8 Mar 2021 18:07:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=81wsiKfCl4t7ZFP8lVjcPTP/RflB7DvlahVcI2y5ICY=; b=OX5EYfyaZDGz9EwrOp6DIMPKVrHqWpbxMO7eixLDaXXs7sFqgSm3A+rsauIjlaRw3ZkcMK ScjGC4ckNuzEXAC+wct2PqBtmgwg7SlYz4yuUgDbhK8xP8QhgP4ns4gFUc1W32sJipAFyK dpK0hU3wuuWUIA9JVOliB7gP00ZtgyU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-WAB-fLZdOpCloNdq2Fwy7Q-1; Mon, 08 Mar 2021 18:07:46 -0500 X-MC-Unique: WAB-fLZdOpCloNdq2Fwy7Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0D6D26864; Mon, 8 Mar 2021 23:07:45 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D1DC1A8A3; Mon, 8 Mar 2021 23:07:44 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 6/9] cifs: add a function to get a cached dir based on its dentry Date: Tue, 9 Mar 2021 09:07:32 +1000 Message-Id: <20210308230735.337-7-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Signed-off-by: Ronnie Sahlberg --- fs/cifs/smb2ops.c | 16 ++++++++++++++++ fs/cifs/smb2proto.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 81eb7f10368b..9e2e1ce915c9 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -925,6 +925,22 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, return rc; } +int open_cached_dir_by_dentry(struct cifs_tcon *tcon, + struct dentry *dentry, + struct cached_fid **cfid) +{ + mutex_lock(&tcon->crfid.fid_mutex); + if (tcon->crfid.dentry == dentry) { + cifs_dbg(FYI, "found a cached root file handle by dentry\n"); + *cfid = &tcon->crfid; + kref_get(&tcon->crfid.refcount); + mutex_unlock(&tcon->crfid.fid_mutex); + return 0; + } + mutex_unlock(&tcon->crfid.fid_mutex); + return -ENOENT; +} + static void smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb) diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index ddbdf9923625..3b1cc27947df 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h @@ -73,6 +73,9 @@ extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, const char *path, struct cifs_sb_info *cifs_sb, struct cached_fid **cfid); +extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon, + struct dentry *dentry, + struct cached_fid **cfid); extern void close_cached_dir(struct cached_fid *cfid); extern void close_cached_dir_lease(struct cached_fid *cfid); extern void close_cached_dir_lease_locked(struct cached_fid *cfid); From patchwork Mon Mar 8 23:07:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gAH/81X7; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYtd2JNVz9sVv for ; Tue, 9 Mar 2021 10:08:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbhCHXIY (ORCPT ); Mon, 8 Mar 2021 18:08:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34654 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbhCHXHx (ORCPT ); Mon, 8 Mar 2021 18:07:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=5krstQ0Ej+bZU1eaUHAxKsElSoV/U8pvdwM/1u8T+lA=; b=gAH/81X7hB4qt2ZidZt24OQM8tnaBNGp1mrwor9zFG/bcQzBGeNPBQ69L8Q+2e3y6T6qF/ aMrxapVEXGa9AHYnHOohqplVPQa1J8X8j2URgZLwt1WpU4IUaL3jm8wcs2soL4hz1mZ0FY sY5SAW8CJ8Hwbp414kzpVolZ+aIzxxU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-eaJINqqHOD-KnMWQB5eAVA-1; Mon, 08 Mar 2021 18:07:50 -0500 X-MC-Unique: eaJINqqHOD-KnMWQB5eAVA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADDA3814313; Mon, 8 Mar 2021 23:07:49 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 194E060C13; Mon, 8 Mar 2021 23:07:48 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 7/9] cifs: add a timestamp to track when the lease of the cached dir was taken Date: Tue, 9 Mar 2021 09:07:33 +1000 Message-Id: <20210308230735.337-8-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org and clear the timestamp when we receive a lease break. Signed-off-by: Ronnie Sahlberg --- fs/cifs/cifsglob.h | 1 + fs/cifs/smb2misc.c | 1 + fs/cifs/smb2ops.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 7d9b47f2f04f..f6cebb36a27c 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -988,6 +988,7 @@ struct cached_fid { bool is_valid:1; /* Do we have a useable root fid */ bool file_all_info_is_valid:1; bool has_lease:1; + unsigned long time; /* jiffies of when lease was taken */ struct kref refcount; struct cifs_fid *fid; struct mutex fid_mutex; diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index 60d4bd1eae2b..e617d2975c99 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c @@ -667,6 +667,7 @@ smb2_is_valid_lease_break(char *buffer) !memcmp(rsp->LeaseKey, tcon->crfid.fid->lease_key, SMB2_LEASE_KEY_SIZE)) { + tcon->crfid.time = 0; INIT_WORK(&tcon->crfid.lease_break, smb2_cached_lease_break); queue_work(cifsiod_wq, diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 9e2e1ce915c9..34419b2af8e8 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -912,6 +912,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, &rsp_iov[1], sizeof(struct smb2_file_all_info), (char *)&tcon->crfid.file_all_info)) tcon->crfid.file_all_info_is_valid = true; + tcon->crfid.time = jiffies; + oshr_exit: mutex_unlock(&tcon->crfid.fid_mutex); From patchwork Mon Mar 8 23:07:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dymD37/8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYtf2ZMkz9sWc for ; Tue, 9 Mar 2021 10:08:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbhCHXIZ (ORCPT ); Mon, 8 Mar 2021 18:08:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46670 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbhCHXH4 (ORCPT ); Mon, 8 Mar 2021 18:07:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=K5SY4vh5dWvxmic2TwQVghVkdghisbxFUamT5maed74=; b=dymD37/8YymL9HllLb9DETcpjoAZBPcrp5fBfVJ1cp0rKVXoIA07tNN6VfUXaNV8EAKsKs KYiUkLY/S3oB5RkHy6ThwrdTGgwJs6+0Qd3XwOM0mnh3yipCRdxLcadZ0tMVovhRxhL5mm 0qDjI3ITqOSDcBfmo2BvsnEEByN+WWY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-E4YX-y-5NwKAz4odAGr9CA-1; Mon, 08 Mar 2021 18:07:53 -0500 X-MC-Unique: E4YX-y-5NwKAz4odAGr9CA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6F171005D4A; Mon, 8 Mar 2021 23:07:52 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71C5C6062F; Mon, 8 Mar 2021 23:07:52 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 8/9] cifs: pass the dentry instead of the inode down to the revalidation check functions Date: Tue, 9 Mar 2021 09:07:34 +1000 Message-Id: <20210308230735.337-9-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Signed-off-by: Ronnie Sahlberg --- fs/cifs/inode.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 0b0b01ef3ecb..98dc6d70d4fa 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -2184,8 +2184,9 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, } static bool -cifs_inode_needs_reval(struct inode *inode) +cifs_dentry_needs_reval(struct dentry *dentry) { + struct inode *inode = d_inode(dentry); struct cifsInodeInfo *cifs_i = CIFS_I(inode); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); @@ -2296,10 +2297,10 @@ cifs_zap_mapping(struct inode *inode) int cifs_revalidate_file_attr(struct file *filp) { int rc = 0; - struct inode *inode = file_inode(filp); + struct dentry *dentry = file_dentry(filp); struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data; - if (!cifs_inode_needs_reval(inode)) + if (!cifs_dentry_needs_reval(dentry)) return rc; if (tlink_tcon(cfile->tlink)->unix_ext) @@ -2322,7 +2323,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry) if (inode == NULL) return -ENOENT; - if (!cifs_inode_needs_reval(inode)) + if (!cifs_dentry_needs_reval(dentry)) return rc; xid = get_xid(); From patchwork Mon Mar 8 23:07:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 1449451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bJbkA9My; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DvYt20Vqvz9sWc for ; Tue, 9 Mar 2021 10:08:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbhCHXHx (ORCPT ); Mon, 8 Mar 2021 18:07:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56705 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbhCHXHr (ORCPT ); Mon, 8 Mar 2021 18:07:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615244866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=LOgKLEx8udn89jzrKoGF0NPeq7tNeDwRvj1/u3Rc4Q0=; b=bJbkA9MyZfCfca4y5/0m/FSCp+/tO5DEg4+G8zNkvqsh/IxxSFA9y3j4NkmNA2OwIUJv26 6sW7+0YEthRuXJJtUY6en6bFTrJUqzAE4v6Pze+V+Z+UYTCSoI1ne8Q48+s6B+pjtOoOmO oKT9GeD3FvjBGxI7vTRBu2pKfwDGhEk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-578-GquZNT9RN-KO-PkirFruNw-1; Mon, 08 Mar 2021 18:07:44 -0500 X-MC-Unique: GquZNT9RN-KO-PkirFruNw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E93981823DC7; Mon, 8 Mar 2021 23:07:43 +0000 (UTC) Received: from test1103.test.redhat.com (vpn2-54-42.bne.redhat.com [10.64.54.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 832B26085A; Mon, 8 Mar 2021 23:07:43 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 9/9] cifs: check the timestamp for the cached dirent when deciding on revalidate Date: Tue, 9 Mar 2021 09:07:35 +1000 Message-Id: <20210308230735.337-10-lsahlber@redhat.com> In-Reply-To: <20210308230735.337-1-lsahlber@redhat.com> References: <20210308230735.337-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Signed-off-by: Ronnie Sahlberg --- fs/cifs/inode.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 98dc6d70d4fa..95326025d77d 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -2189,6 +2189,8 @@ cifs_dentry_needs_reval(struct dentry *dentry) struct inode *inode = d_inode(dentry); struct cifsInodeInfo *cifs_i = CIFS_I(inode); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); + struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); + struct cached_fid *cfid = NULL; if (cifs_i->time == 0) return true; @@ -2199,6 +2201,16 @@ cifs_dentry_needs_reval(struct dentry *dentry) if (!lookupCacheEnabled) return true; + if (!open_cached_dir_by_dentry(tcon, dentry->d_parent, &cfid)) { + mutex_lock(&cfid->fid_mutex); + if (cfid->time && cifs_i->time > cfid->time) { + mutex_unlock(&cfid->fid_mutex); + close_cached_dir(cfid); + return false; + } + mutex_unlock(&cfid->fid_mutex); + close_cached_dir(cfid); + } /* * depending on inode type, check if attribute caching disabled for * files or directories