{"id":2229729,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229729/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-9-sprasad@microsoft.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260428160804.281745-9-sprasad@microsoft.com>","date":"2026-04-28T16:07:54","name":"[v3,09/19] cifs: query dir should reuse cfid even if not fully cached","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"343efc341bab3a242219c7d71bb483c241ce8380","submitter":{"id":79368,"url":"http://patchwork.ozlabs.org/api/1.1/people/79368/?format=json","name":"Shyam Prasad N","email":"nspmangalore@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-9-sprasad@microsoft.com/mbox/","series":[{"id":501896,"url":"http://patchwork.ozlabs.org/api/1.1/series/501896/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501896","date":"2026-04-28T16:07:57","name":"[v3,01/19] cifs: change_conf needs to be called for session setup","version":3,"mbox":"http://patchwork.ozlabs.org/series/501896/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229729/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229729/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-11246-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=d2SohE/y;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11246-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"d2SohE/y\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.216.45","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4mNb2kG7z1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 02:39:11 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 6C99731072CD\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 16:14:38 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A628044CF59;\n\tTue, 28 Apr 2026 16:08:31 +0000 (UTC)","from mail-pj1-f45.google.com (mail-pj1-f45.google.com\n [209.85.216.45])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C14844CAD7\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 16:08:28 +0000 (UTC)","by mail-pj1-f45.google.com with SMTP id\n 98e67ed59e1d1-35d94f4ee36so7041184a91.3\n        for <linux-cifs@vger.kernel.org>;\n Tue, 28 Apr 2026 09:08:28 -0700 (PDT)","from sprasad-dev1.corp.microsoft.com ([167.220.110.216])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b97ac7894csm30864465ad.50.2026.04.28.09.08.26\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 28 Apr 2026 09:08:27 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777392511; cv=none;\n b=gGiepxKK5oJSRdqCDGHA1DYSz3qXWK/u58tHxYZ3Wdeye8xc86Lqn10m5dYmwbL5klO3UMyXcTvyieok0OWrbHT5YXVw7f5EG9J1J1YxpGXJBwmylvQqB0ufvDvpS2KBqECQXsI8ANMjF8pQZVDm3HFxj9D5nXuqN8rGf4T+VeU=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777392511; c=relaxed/simple;\n\tbh=8sxUOa4GOq0ES6V2+B00JkoL9Pv89jv4RGkW+5b08nE=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=fuYMv+p5tqhv86YJrwPmYfIGL/GE1LD6+jxcEqTQ6/TC+vH7BNrrBMBSQVE7NT1K0mZxTODt8Q7x6H+yuARIlqABvOR1olnyxiXOFm1VVqQYbXXYYjIOWs5QHApdV8tcp5FCFQwPwrI+pUK7jXRzEMWlRC17nOYM/jpW6yyjeK4=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=d2SohE/y; arc=none smtp.client-ip=209.85.216.45","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777392508; x=1777997308;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=DEpNZWYhAGnzhrFxPDmeqdZuHK3C9i+Vxou+CJqZF6E=;\n        b=d2SohE/y3JiFblb30qqJhYW/axruYuQRoOuyJS8TA5jFm8qbuzXhrG+OU6+W+erXoj\n         DxvCwXgxZrpflMA6K7YUPMiuH4pLXv1lRrsCpbuyTmR1IgmhCoWiHQc+z2pPQ3bkL2lj\n         +a4u+H85I7n5DOzgrKdfFHvoJcHjPQhDywhCRL8Umj3OfvosQkCK5OXnQJ90ByvYf3O4\n         a4d+INbnwxuqdiUZH9J3pLeYYsOPLs7yRG1UjyMsZz41m0wvNMmJtzZ0Cz5oI16lT75U\n         vz02/bb68CpPkQqGXQCydpdx5Qn7UoZ9JMKbuEsJZ+Vg4AgTbnhYjHwmGZSaH4k6nRAz\n         8qoQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777392508; x=1777997308;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=DEpNZWYhAGnzhrFxPDmeqdZuHK3C9i+Vxou+CJqZF6E=;\n        b=VpPX1KA6J0mgEwNczdNB1f0U6iTLL0/EeYjAv8b5ztHGZ7hVBq/zkOTud3EzJxF1oE\n         xS7ZY64HvX4jwxzlVWCqSVjmnLobv9jlTEyEDfQARjlMsbh+LhQwryP9VRwgbH4Hr0Wo\n         F2hFO8DmtolkdtitE5RdFY6x3W9QqIY/FUe+qhehEF4wzPsokSLGroeBHBeJYD6VSpZS\n         nx1qU7QvCC0xxe/0Lz1tpUWP/qWJDIh94DX401i4l3GOKMLCAXLN5dSAp1eRLefzGgrT\n         DUnoPlaXclsTkxH4THzp70fhZHcRnR2Nn+lcgqJiN1lcuzs9REDaRfR5O246pQuFdAlM\n         c/+A==","X-Gm-Message-State":"AOJu0YxccggZzdw2hRZcbonYb5LT0b8uwxQyIo+DPQwclNHtOwJSBZlT\n\tvERAflK9HT+28tmt1Wn8cio2LVMh+c6YxYMxJ3F0InyGyrnFqTYVJjxvvliy03wA/8Q=","X-Gm-Gg":"AeBDiesZOtO8PGGs7gw8Tg+/xoZvl5VSGeAnRXXBTXFH1hdRDR7u90ZJEf/lhcgQ8GF\n\tN1A55Ep9B+Khm4FbEAU8kOxtiImEmLutARLyNC7kQDD/N7o0eD5dO6nm9s29i1iZ8HtAnqxJLgr\n\tJ9RMJqeVQC7Ibi/THQdgVgVIoBJLFfmDoQ0zvR1RjrKwYXOYv47qnCac5RsRWo74ZL5JOPmk7gp\n\t3RAjhELK+v2B8W2g3FYLQA6kJNojZt2tnhmF7V0yE+RScLu56xxNuwxicQ2N6InB2YdsVfJ81AY\n\txLKERiyVaU2JQiqxJVXwL9Ktbeetir/7lIkZ15A7Rj8TDGP/yXmFfmiBjWJ1abt75Sgu3C5dMlr\n\tYWPpPWi+GQ9L687l8XBYGFpZSshkCUK6s1Le6bzq2SeDcIVNeT+Rta4YZq476jiTn/yXSUOhztm\n\tP9dzbhH2hC60n6fGk2U8EaYZflV0gckVqBrmkcXLjMEX8Ri6mkAcbSqyJmVgFKyAtV","X-Received":"by 2002:a17:903:2ed0:b0:2ae:cb0e:fd59 with SMTP id\n d9443c01a7336-2b97c4120bdmr38474795ad.8.1777392507459;\n        Tue, 28 Apr 2026 09:08:27 -0700 (PDT)","From":"nspmangalore@gmail.com","X-Google-Original-From":"sprasad@microsoft.com","To":"linux-cifs@vger.kernel.org,\n\tsmfrench@gmail.com,\n\tpc@manguebit.org,\n\tbharathsm@microsoft.com,\n\tdhowells@redhat.com,\n\thenrique.carvalho@suse.com,\n\tematsumiya@suse.de","Cc":"Shyam Prasad N <sprasad@microsoft.com>","Subject":"[PATCH v3 09/19] cifs: query dir should reuse cfid even if not fully\n cached","Date":"Tue, 28 Apr 2026 21:37:54 +0530","Message-ID":"<20260428160804.281745-9-sprasad@microsoft.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260428160804.281745-1-sprasad@microsoft.com>","References":"<20260428160804.281745-1-sprasad@microsoft.com>","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"From: Shyam Prasad N <sprasad@microsoft.com>\n\nWhen a cached_dirents population is underway but not yet fully populated,\ncifs_readdir does not rely on the local cache, but makes a parallel\nstream of QueryDir calls to the server. However, these calls are made\nwithout lease key and that ends up breaking our dir lease.\n\nThis change will reuse the existing lease key for this scenario for the\nparallel QueryDir calls that are made.\n\nSigned-off-by: Shyam Prasad N <sprasad@microsoft.com>\n---\n fs/smb/client/cached_dir.c | 38 ++++++++++++++++++++++++++++++++++++\n fs/smb/client/cached_dir.h |  6 ++++++\n fs/smb/client/cifsglob.h   |  2 ++\n fs/smb/client/file.c       |  1 +\n fs/smb/client/readdir.c    | 40 ++++++++++++++++++++++++++------------\n fs/smb/client/smb2ops.c    | 19 ++++++++++++++++++\n 6 files changed, 94 insertions(+), 12 deletions(-)","diff":"diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c\nindex ad2439856a1fe..614a241393b59 100644\n--- a/fs/smb/client/cached_dir.c\n+++ b/fs/smb/client/cached_dir.c\n@@ -22,6 +22,20 @@ struct cached_dir_dentry {\n \tstruct dentry *dentry;\n };\n \n+bool cached_dir_is_valid(struct cached_fid *cfid)\n+{\n+\tbool valid;\n+\n+\tif (!cfid)\n+\t\treturn false;\n+\n+\tspin_lock(&cfid->cfid_lock);\n+\tvalid = is_valid_cached_dir(cfid);\n+\tspin_unlock(&cfid->cfid_lock);\n+\n+\treturn valid;\n+}\n+\n bool cached_dir_copy_lease_key(struct cached_fid *cfid,\n \t\t\t      __u8 lease_key[SMB2_LEASE_KEY_SIZE])\n {\n@@ -1132,3 +1146,27 @@ void free_cached_dirs(struct cached_fids *cfids)\n \n \tkfree(cfids);\n }\n+\n+void cifs_set_srch_inf_cfid(struct cifs_search_info *srch_inf,\n+\t\t\t   struct cached_fid *cfid)\n+{\n+\tif (srch_inf->cfid == cfid)\n+\t\treturn;\n+\n+\tif (cfid)\n+\t\tkref_get(&cfid->refcount);\n+\n+\tif (srch_inf->cfid)\n+\t\tclose_cached_dir(srch_inf->cfid);\n+\n+\tsrch_inf->cfid = cfid;\n+}\n+\n+void cifs_put_srch_inf_cfid(struct cifs_search_info *srch_inf)\n+{\n+\tif (!srch_inf->cfid)\n+\t\treturn;\n+\n+\tclose_cached_dir(srch_inf->cfid);\n+\tsrch_inf->cfid = NULL;\n+}\ndiff --git a/fs/smb/client/cached_dir.h b/fs/smb/client/cached_dir.h\nindex f82db6a7ca5b0..0767350b40fba 100644\n--- a/fs/smb/client/cached_dir.h\n+++ b/fs/smb/client/cached_dir.h\n@@ -8,6 +8,8 @@\n #ifndef _CACHED_DIR_H\n #define _CACHED_DIR_H\n \n+struct cifs_search_info;\n+\n struct cached_dirent {\n \tstruct list_head entry;\n \tchar *name;\n@@ -84,6 +86,7 @@ is_valid_cached_dir(struct cached_fid *cfid)\n \treturn cfid->time && cfid->has_lease;\n }\n \n+bool cached_dir_is_valid(struct cached_fid *cfid);\n bool cached_dir_copy_lease_key(struct cached_fid *cfid,\n \t\t\t      __u8 lease_key[SMB2_LEASE_KEY_SIZE]);\n \n@@ -95,6 +98,9 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, const char *path,\n int open_cached_dir_by_dentry(struct cifs_tcon *tcon, struct dentry *dentry,\n \t\t\t      struct cached_fid **ret_cfid);\n void close_cached_dir(struct cached_fid *cfid);\n+void cifs_set_srch_inf_cfid(struct cifs_search_info *srch_inf,\n+\t\t\t   struct cached_fid *cfid);\n+void cifs_put_srch_inf_cfid(struct cifs_search_info *srch_inf);\n bool emit_cached_dir_if_valid(struct cached_fid *cfid,\n \t\t\t      struct file *file,\n \t\t\t      struct dir_context *ctx);\ndiff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h\nindex a15971ffeee58..2a3fad071564a 100644\n--- a/fs/smb/client/cifsglob.h\n+++ b/fs/smb/client/cifsglob.h\n@@ -309,6 +309,7 @@ struct cifs_search_info;\n struct cifsInodeInfo;\n struct cifs_open_parms;\n struct cifs_credits;\n+struct cached_fid;\n \n struct smb_version_operations {\n \tint (*send_cancel)(struct cifs_ses *ses, struct TCP_Server_Info *server,\n@@ -1395,6 +1396,7 @@ struct cifs_search_info {\n \tbool unicode:1;\n \tbool smallBuf:1; /* so we know which buf_release function to call */\n \tbool is_dynamic_buf:1; /* dynamically allocated buffer - can be variable size */\n+\tstruct cached_fid *cfid; /* Reference to cached file id for directory enumeration */\n };\n \n /* Structure for QueryDirectory with multi-credit support */\ndiff --git a/fs/smb/client/file.c b/fs/smb/client/file.c\nindex 6a1419d59ed5a..9e3c07006f4f2 100644\n--- a/fs/smb/client/file.c\n+++ b/fs/smb/client/file.c\n@@ -1552,6 +1552,7 @@ int cifs_closedir(struct inode *inode, struct file *file)\n \t\t\tcifs_buf_release(buf);\n \t}\n \n+\tcifs_put_srch_inf_cfid(&cfile->srch_inf);\n \tcifs_put_tlink(cfile->tlink);\n \tkfree(file->private_data);\n \tfile->private_data = NULL;\ndiff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c\nindex 907e235ad1b8f..ef81fdb503c0a 100644\n--- a/fs/smb/client/readdir.c\n+++ b/fs/smb/client/readdir.c\n@@ -344,7 +344,7 @@ cifs_std_info_to_fattr(struct cifs_fattr *fattr, FIND_FILE_STANDARD_INFO *info,\n \n static int\n _initiate_cifs_search(const unsigned int xid, struct file *file,\n-\t\t     const char *full_path)\n+\t\t     const char *full_path, struct cached_fid *cfid)\n {\n \tstruct cifs_sb_info *cifs_sb = CIFS_SB(file);\n \tstruct tcon_link *tlink = NULL;\n@@ -368,9 +368,11 @@ _initiate_cifs_search(const unsigned int xid, struct file *file,\n \t\tspin_lock_init(&cifsFile->file_info_lock);\n \t\tfile->private_data = cifsFile;\n \t\tcifsFile->tlink = cifs_get_tlink(tlink);\n+\t\tcifs_set_srch_inf_cfid(&cifsFile->srch_inf, cfid);\n \t\ttcon = tlink_tcon(tlink);\n \t} else {\n \t\tcifsFile = file->private_data;\n+\t\tcifs_set_srch_inf_cfid(&cifsFile->srch_inf, cfid);\n \t\ttcon = tlink_tcon(cifsFile->tlink);\n \t}\n \n@@ -425,12 +427,12 @@ _initiate_cifs_search(const unsigned int xid, struct file *file,\n \n static int\n initiate_cifs_search(const unsigned int xid, struct file *file,\n-\t\t     const char *full_path)\n+\t\t     const char *full_path, struct cached_fid *cfid)\n {\n \tint rc, retry_count = 0;\n \n \tdo {\n-\t\trc = _initiate_cifs_search(xid, file, full_path);\n+\t\trc = _initiate_cifs_search(xid, file, full_path, cfid);\n \t\t/*\n \t\t * If we don't have enough credits to start reading the\n \t\t * directory just try again after short wait.\n@@ -742,7 +744,11 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,\n \t\t\tcfile->srch_inf.srch_entries_start = NULL;\n \t\t\tcfile->srch_inf.last_entry = NULL;\n \t\t}\n-\t\trc = initiate_cifs_search(xid, file, full_path);\n+\t\t/* Pass cfid only if still valid; srch_inf owns the reference. */\n+\t\tstruct cached_fid *rewind_cfid =\n+\t\t\tcached_dir_is_valid(cfile->srch_inf.cfid) ?\n+\t\t\tcfile->srch_inf.cfid : NULL;\n+\t\trc = initiate_cifs_search(xid, file, full_path, rewind_cfid);\n \t\tif (rc) {\n \t\t\tcifs_dbg(FYI, \"error %d reinitiating a search on rewind\\n\",\n \t\t\t\t rc);\n@@ -968,20 +974,31 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)\n \tif (emit_cached_dir_if_valid(cfid, file, ctx))\n \t\tgoto rddir2_exit;\n \n-\t/* Drop the cache while calling initiate_cifs_search and\n-\t * find_cifs_entry in case there will be reconnects during\n-\t * query_directory.\n+\t/*\n+\t * If cfid is valid but cache is invalid and not failed,\n+\t * keep cfid and pass it to initiate_cifs_search to populate.\n+\t * Otherwise (no cfid or cache is failed), close cfid and\n+\t * proceed without cache for this session.\n \t */\n-\tclose_cached_dir(cfid);\n-\tcfid = NULL;\n+\tif (cfid) {\n+\t\tbool cache_pending;\n+\n+\t\tmutex_lock(&cfid->dirents.de_mutex);\n+\t\tcache_pending = !cfid->dirents.is_valid && !cfid->dirents.is_failed;\n+\t\tmutex_unlock(&cfid->dirents.de_mutex);\n+\t\tif (!cache_pending) {\n+\t\t\tclose_cached_dir(cfid);\n+\t\t\tcfid = NULL;\n+\t\t}\n+\t}\n \n- cache_not_found:\n+cache_not_found:\n \t/*\n \t * Ensure FindFirst doesn't fail before doing filldir() for '.' and\n \t * '..'. Otherwise we won't be able to notify VFS in case of failure.\n \t */\n \tif (file->private_data == NULL) {\n-\t\trc = initiate_cifs_search(xid, file, full_path);\n+\t\trc = initiate_cifs_search(xid, file, full_path, cfid);\n \t\tcifs_dbg(FYI, \"initiate cifs search rc %d\\n\", rc);\n \t\tif (rc)\n \t\t\tgoto rddir2_exit;\n@@ -1009,7 +1026,6 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)\n \ttcon = tlink_tcon(cifsFile->tlink);\n \trc = find_cifs_entry(xid, tcon, ctx->pos, file, full_path,\n \t\t\t     &current_entry, &num_to_fill);\n-\topen_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);\n \tif (rc) {\n \t\tcifs_dbg(FYI, \"fce error %d\\n\", rc);\n \t\tgoto rddir2_exit;\ndiff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c\nindex 2df4d080e95f0..05b636fbb20a6 100644\n--- a/fs/smb/client/smb2ops.c\n+++ b/fs/smb/client/smb2ops.c\n@@ -2463,12 +2463,16 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,\n \tstruct smb2_query_directory_rsp *qd2_rsp = NULL;\n \tstruct smb2_create_rsp *op_rsp = NULL;\n \tstruct TCP_Server_Info *server;\n+\tstruct cached_fid *cfid = srch_inf ? srch_inf->cfid : NULL;\n \tint retries = 0, cur_sleep = 0;\n \tunsigned int compound_resp_bufsize;\n+\tbool use_cfid_lease = false;\n+\tbool cfid_open_locked = false;\n \n replay_again:\n \t/* reinitialize for possible replay */\n \tflags = 0;\n+\tuse_cfid_lease = false;\n \toplock = SMB2_OPLOCK_LEVEL_NONE;\n \tserver = cifs_pick_channel(tcon->ses);\n \n@@ -2476,6 +2480,15 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,\n \tif (!utf16_path)\n \t\treturn -ENOMEM;\n \n+\tif (cfid) {\n+\t\tmutex_lock(&cfid->cfid_open_mutex);\n+\t\tcfid_open_locked = true;\n+\t\tuse_cfid_lease = cached_dir_copy_lease_key(cfid,\n+\t\t\t\t\t\t      fid->lease_key);\n+\t\toplock = use_cfid_lease ?\n+\t\t\tSMB2_OPLOCK_LEVEL_II : SMB2_OPLOCK_LEVEL_NONE;\n+\t}\n+\n \tif (smb3_encryption_required(tcon))\n \t\tflags |= CIFS_TRANSFORM_REQ;\n \n@@ -2556,6 +2569,10 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,\n \trc = compound_send_recv(xid, tcon->ses, server,\n \t\t\t\tflags, 3, rqst,\n \t\t\t\tresp_buftype, rsp_iov);\n+\tif (cfid_open_locked) {\n+\t\tmutex_unlock(&cfid->cfid_open_mutex);\n+\t\tcfid_open_locked = false;\n+\t}\n \n \t/* If the open failed there is nothing to do */\n \top_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;\n@@ -2696,6 +2713,8 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,\n \t\t\ttcon->ses->Suid, 0, srch_inf->entries_in_buffer);\n \n  qdf_free:\n+\tif (cfid_open_locked)\n+\t\tmutex_unlock(&cfid->cfid_open_mutex);\n \tkfree(utf16_path);\n \tSMB2_open_free(&rqst[0]);\n \tSMB2_query_directory_free(&rqst[1]);\n","prefixes":["v3","09/19"]}