From patchwork Wed Oct 16 06:55:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 11192441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE83A17E6 for ; Wed, 16 Oct 2019 06:55:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE4A520873 for ; Wed, 16 Oct 2019 06:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732478AbfJPGzV (ORCPT ); Wed, 16 Oct 2019 02:55:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18457 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728468AbfJPGzV (ORCPT ); Wed, 16 Oct 2019 02:55:21 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id B25ED10C092B for ; Wed, 16 Oct 2019 06:55:20 +0000 (UTC) Received: from test1135.test.redhat.com (vpn2-54-116.bne.redhat.com [10.64.54.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 177CA60852; Wed, 16 Oct 2019 06:55:19 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Ronnie Sahlberg Subject: [PATCH] cifs: use the cached root handle for readdir() if possible Date: Wed, 16 Oct 2019 16:55:10 +1000 Message-Id: <20191016065510.31291-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Wed, 16 Oct 2019 06:55:20 +0000 (UTC) Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Signed-off-by: Ronnie Sahlberg --- fs/cifs/smb2ops.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 4c0922596467..7aab18552dd8 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -681,7 +681,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid) oparms.tcon = tcon; oparms.create_options = 0; - oparms.desired_access = FILE_READ_ATTRIBUTES; + oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; oparms.disposition = FILE_OPEN; oparms.fid = pfid; oparms.reconnect = false; @@ -1999,6 +1999,14 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, int rc; __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; struct cifs_open_parms oparms; + bool no_cached_open = tcon->nohandlecache; + + if (!strlen(path) && !no_cached_open) { + rc = open_shroot(xid, tcon, fid); + if (rc) + return rc; + goto after_open; + } utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); if (!utf16_path) @@ -2021,6 +2029,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, return rc; } + after_open: srch_inf->entries_in_buffer = 0; srch_inf->index_of_last_entry = 2; @@ -2046,6 +2055,13 @@ static int smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *fid) { + if (tcon->crfid.is_valid && + tcon->crfid.fid->persistent_fid == fid->persistent_fid && + tcon->crfid.fid->volatile_fid == fid->volatile_fid) { + close_shroot(&tcon->crfid); + return 0; + } + return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); }