Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2223134/?format=api
{ "id": 2223134, "url": "http://patchwork.ozlabs.org/api/patches/2223134/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260414135918.279802-7-sprasad@microsoft.com/", "project": { "id": 12, "url": "http://patchwork.ozlabs.org/api/projects/12/?format=api", "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": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260414135918.279802-7-sprasad@microsoft.com>", "list_archive_url": null, "date": "2026-04-14T13:59:18", "name": "[7/7] cifs: reorganize cached dir helpers", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "e1b8cfe9211f8643135d7c6a0ed5e502769f96cd", "submitter": { "id": 79368, "url": "http://patchwork.ozlabs.org/api/people/79368/?format=api", "name": "Shyam Prasad N", "email": "nspmangalore@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260414135918.279802-7-sprasad@microsoft.com/mbox/", "series": [ { "id": 499852, "url": "http://patchwork.ozlabs.org/api/series/499852/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=499852", "date": "2026-04-14T13:59:12", "name": "[1/7] cifs: change_conf needs to be called for session setup", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/499852/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2223134/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2223134/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linux-cifs+bounces-10808-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=aeXuIgd+;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10808-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=\"aeXuIgd+\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.173", "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 sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::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 4fw5cF0R2Wz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 00:04:13 +1000 (AEST)", "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id AABCB309FD4C\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 13:59:40 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id D41163B7760;\n\tTue, 14 Apr 2026 13:59:38 +0000 (UTC)", "from mail-pl1-f173.google.com (mail-pl1-f173.google.com\n [209.85.214.173])\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 27B303E6DF4\n\tfor <linux-cifs@vger.kernel.org>; Tue, 14 Apr 2026 13:59:37 +0000 (UTC)", "by mail-pl1-f173.google.com with SMTP id\n d9443c01a7336-2ad9f316d68so24907925ad.2\n for <linux-cifs@vger.kernel.org>;\n Tue, 14 Apr 2026 06:59:37 -0700 (PDT)", "from sprasad-dev1.corp.microsoft.com ([167.220.110.184])\n by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b4612e60dasm59779895ad.38.2026.04.14.06.59.35\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 14 Apr 2026 06:59:35 -0700 (PDT)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776175178; cv=none;\n b=Gr3+SYE6hFFXvv/Mt4sN09V0bjerzyjctI9HKt1NZhMSi4jGxUOqrt4nHcYdPgk555jmJdDHY9z9q2Z8TlTPBJwi0aYDqiWNnOhssK4xCxK1v+pgfasFFVLJH+NDFvr6FkdZ8hlDq//aDt8wUJWFlfDFgFRsK2Iqe1G/aduYGx8=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776175178; c=relaxed/simple;\n\tbh=YZ4iElVEnXDZYySVO3VBpfGCVaSUyJl4g2ffVrW1WgQ=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=fnzd2yBgr4oz3hSEA6t0bImtAGQIUwuP8Ctb7fitANIaaT4CxdqLHjckUCrhoHx/pehS06xSZWY48N61dSb/jGPO1l1pYCE7+vi/1GsjwsJh7H3FXubUY90kAywfiVvnQntNWTw92kDBKozZXFLCoAdOet3lH47EP6+y/XXKFo4=", "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=aeXuIgd+; arc=none smtp.client-ip=209.85.214.173", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776175176; x=1776779976;\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=ENAAh/1O3MhaZu/Z65n/crtkMvLMA8Mtex6JNce8d08=;\n b=aeXuIgd+IzPKMm4yGkNqg3z0ujg0cpjdWHQQqoPnFV3zfJXNjuPu7kraww01E5/bwQ\n GvKfwzh6yRW0XqDuQWKUkLWnEpcTt9T1vR6XugNr2kIMtEm3OHyyodojqGNJLChRwSXe\n CDhlq2rvPk5iMGjGPkqsYsWvfhGbpHp+H5VhI0uUp8vy5eEz565N1JpSepYt2kE8X6UM\n auJ2UZH1fF91HFJY9cIUFZNGv1Hlzt8gARgDsi4sjsU4QuNsJoE0aVNzj+oIYPZP8qlI\n RE3vzXiimC7dHtIth+NHmDIpC6Zu8BCWqelkIs7dz0Yua3FMIuaK3NALb1LJoOvGugK5\n XQFw==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776175176; x=1776779976;\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=ENAAh/1O3MhaZu/Z65n/crtkMvLMA8Mtex6JNce8d08=;\n b=QkSzij4OtTNHW5PzM+B4ccVgKZju+l//42FRmW/v6nbnbK/osbuTJtqIxNwET4xfLo\n 0BPbzJ7HdWAsWhJiVl0TehXvwPFcJz/l98lwztCL5zZEfncktTOqFmyUI9NsMaFatWAK\n wpZAqgg4XeBiRF/gwAG3Orom6BrtvefYQNemFUrliFN/ponzwFGSNCTofgE+qXtF+HGQ\n LukbBZ00XJ8yWcObXLmGd2U+EWJiq1bKphgPLYZX72OyHjykGUVbY/tk4PfA3e/Ec7oS\n /2/mdEdr6S/qV44kFDx4NdCXYHRoXMMUbznYzl0qwlBFq8SPwFwer3tWfT1UyR9crIOa\n 6q2Q==", "X-Gm-Message-State": "AOJu0Ywwyr1WSAndym1T/8yQoImAu1/r5J+lsv3Xsf3Ghj1Xq1UHA+Lt\n\tBvIwe1IUO3bltuZK8TKVkKVoZPvgfYDdfFu9281yPjmDrbnFwVauuUEIVzo+RpyJQcA=", "X-Gm-Gg": "AeBDietPaQuZEVicv+gfxB8NeRfEW3SQlDeeB+IjaHz92mFxDx+IAwD4mDxKVi3QD6S\n\tY1QaySPphSuinqBbtuxbpvHcImNQtpH6wNT4kuTU3g21zJyAX8M09xDBsrDsu+BvaAWfjQ8sTuU\n\t+L0E3779EVtxovDCI5uAwnPeJkPfIBQNF3BsK/eVacp8M/oal3fK9BN+ShoEyvEcPnsMrsiWWJk\n\t/VtbC9IRN0/oHRMrdJWvyvYVQw10x9cKaljLj1apc5Agcdl/z6MdwBLyTZEqa9OW62k+BB1/iCc\n\tGImqpv5KG4DXJCB635pjG/3INRaeBGyQhRZPUdCKD8rHvqe9AGe23722DcJWcoS0OB8WOsLhPOd\n\tEHeENfzq1OkG7wP62dLdOCiZy2PM4redYTce/UQPavNPKfWGBE27nOpHAZuO8A0sfIQxjmvQsU3\n\tibCeK4EZ/AMPQPRQ4Q3jP+lYvfrlF9yRWhRa7xpBfzXqzWJA1wOcBwPQXlHZQlq94=", "X-Received": "by 2002:a17:903:1a43:b0:2b0:ccad:de1a with SMTP id\n d9443c01a7336-2b2d5a2c035mr174646825ad.30.1776175175961;\n Tue, 14 Apr 2026 06:59:35 -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.com,\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 7/7] cifs: reorganize cached dir helpers", "Date": "Tue, 14 Apr 2026 19:29:18 +0530", "Message-ID": "<20260414135918.279802-7-sprasad@microsoft.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20260414135918.279802-1-sprasad@microsoft.com>", "References": "<20260414135918.279802-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\nCurrently, we have helper functions for cfid and dirent caching spread\nacross cached_dir.c and readdir.c, with de_mutex locking done inside\nthe calling functions. This change neatly wraps them in helper functions\nand keeps all such functions in cached_dir.c.\n\nThis code also splits the logic of dirent emit into cache and to VFS into\ndifferent functions.\n\nSigned-off-by: Shyam Prasad N <sprasad@microsoft.com>\n---\n fs/smb/client/cached_dir.c | 207 +++++++++++++++++++++++++++++++++++++\n fs/smb/client/cached_dir.h | 18 +++-\n fs/smb/client/readdir.c | 167 ++----------------------------\n 3 files changed, 231 insertions(+), 161 deletions(-)", "diff": "diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c\nindex e9917e5204b00..10fe703d353d1 100644\n--- a/fs/smb/client/cached_dir.c\n+++ b/fs/smb/client/cached_dir.c\n@@ -23,6 +23,213 @@ struct cached_dir_dentry {\n \tstruct dentry *dentry;\n };\n \n+static bool emit_cached_dirents(struct cached_dirents *cde,\n+\t\t\t\tstruct dir_context *ctx)\n+{\n+\tstruct cached_dirent *dirent;\n+\tbool rc;\n+\n+\tlockdep_assert_held(&cde->de_mutex);\n+\n+\tlist_for_each_entry(dirent, &cde->entries, entry) {\n+\t\t/*\n+\t\t * Skip all early entries prior to the current lseek()\n+\t\t * position.\n+\t\t */\n+\t\tif (ctx->pos > dirent->pos)\n+\t\t\tcontinue;\n+\t\t/*\n+\t\t * We recorded the current ->pos value for the dirent\n+\t\t * when we stored it in the cache.\n+\t\t * However, this sequence of ->pos values may have holes\n+\t\t * in it, for example dot-dirs returned from the server\n+\t\t * are suppressed.\n+\t\t * Handle this by forcing ctx->pos to be the same as the\n+\t\t * ->pos of the current dirent we emit from the cache.\n+\t\t * This means that when we emit these entries from the cache\n+\t\t * we now emit them with the same ->pos value as in the\n+\t\t * initial scan.\n+\t\t */\n+\t\tctx->pos = dirent->pos;\n+\t\trc = dir_emit(ctx, dirent->name, dirent->namelen,\n+\t\t\t dirent->fattr.cf_uniqueid,\n+\t\t\t dirent->fattr.cf_dtype);\n+\t\tif (!rc)\n+\t\t\treturn rc;\n+\t\tctx->pos++;\n+\t}\n+\treturn true;\n+}\n+\n+static bool add_cached_dirent(struct cached_dirents *cde,\n+\t\t\t struct dir_context *ctx, const char *name,\n+\t\t\t int namelen, struct cifs_fattr *fattr,\n+\t\t\t struct file *file)\n+{\n+\tstruct cached_dirent *de;\n+\n+\tlockdep_assert_held(&cde->de_mutex);\n+\n+\tif (cde->file != file)\n+\t\treturn false;\n+\tif (cde->is_valid || cde->is_failed)\n+\t\treturn false;\n+\tif (ctx->pos != cde->pos) {\n+\t\tcde->is_failed = 1;\n+\t\treturn false;\n+\t}\n+\tde = kzalloc_obj(*de, GFP_KERNEL);\n+\tif (de == NULL) {\n+\t\tcde->is_failed = 1;\n+\t\treturn false;\n+\t}\n+\tde->namelen = namelen;\n+\tde->name = kstrndup(name, namelen, GFP_KERNEL);\n+\tif (de->name == NULL) {\n+\t\tkfree(de);\n+\t\tcde->is_failed = 1;\n+\t\treturn false;\n+\t}\n+\tde->pos = ctx->pos;\n+\n+\tmemcpy(&de->fattr, fattr, sizeof(struct cifs_fattr));\n+\n+\tlist_add_tail(&de->entry, &cde->entries);\n+\t/* update accounting */\n+\tcde->entries_count++;\n+\tcde->bytes_used += sizeof(*de) + (size_t)namelen + 1;\n+\treturn true;\n+}\n+\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)\n+{\n+\tif (!cfid)\n+\t\treturn false;\n+\n+\tmutex_lock(&cfid->dirents.de_mutex);\n+\t/*\n+\t * If this was reading from the start of the directory\n+\t * we need to initialize scanning and storing the\n+\t * directory content.\n+\t */\n+\tif (ctx->pos == 0 && cfid->dirents.file == NULL) {\n+\t\tcfid->dirents.file = file;\n+\t\tcfid->dirents.pos = 2;\n+\t}\n+\n+\tif (!cfid->dirents.is_valid) {\n+\t\tmutex_unlock(&cfid->dirents.de_mutex);\n+\t\treturn false;\n+\t}\n+\n+\tif (dir_emit_dots(file, ctx))\n+\t\temit_cached_dirents(&cfid->dirents, ctx);\n+\n+\tmutex_unlock(&cfid->dirents.de_mutex);\n+\treturn true;\n+}\n+\n+bool add_to_cached_dir(struct cached_fid *cfid,\n+\t\t struct dir_context *ctx,\n+\t\t const char *name,\n+\t\t int namelen,\n+\t\t struct cifs_fattr *fattr,\n+\t\t struct file *file)\n+{\n+\tsize_t delta_bytes;\n+\tbool added = false;\n+\n+\tif (!cfid)\n+\t\treturn false;\n+\n+\t/* Cost of this entry */\n+\tdelta_bytes = sizeof(struct cached_dirent) + (size_t)namelen + 1;\n+\n+\tmutex_lock(&cfid->dirents.de_mutex);\n+\tadded = add_cached_dirent(&cfid->dirents, ctx, name, namelen,\n+\t\t\t\t fattr, file);\n+\tmutex_unlock(&cfid->dirents.de_mutex);\n+\n+\tif (added) {\n+\t\t/* per-tcon then global for consistency with free path */\n+\t\tatomic64_add((long long)delta_bytes, &cfid->cfids->total_dirents_bytes);\n+\t\tatomic_long_inc(&cfid->cfids->total_dirents_entries);\n+\t\tatomic64_add((long long)delta_bytes, &cifs_dircache_bytes_used);\n+\t}\n+\n+\treturn added;\n+}\n+\n+static void update_cached_dirents_count(struct cached_dirents *cde,\n+\t\t\t\t\tstruct file *file)\n+{\n+\tif (cde->file != file)\n+\t\treturn;\n+\tif (cde->is_valid || cde->is_failed)\n+\t\treturn;\n+\n+\tcde->pos++;\n+}\n+\n+static void finished_cached_dirents_count(struct cached_dirents *cde,\n+\t\t\t\t\t struct dir_context *ctx,\n+\t\t\t\t\t struct file *file)\n+{\n+\tif (cde->file != file)\n+\t\treturn;\n+\tif (cde->is_valid || cde->is_failed)\n+\t\treturn;\n+\tif (ctx->pos != cde->pos)\n+\t\treturn;\n+\n+\tcde->is_valid = 1;\n+}\n+\n+void update_pos_cached_dir(struct cached_fid *cfid,\n+\t\t\t\t struct file *file)\n+{\n+\tif (!cfid)\n+\t\treturn;\n+\n+\tmutex_lock(&cfid->dirents.de_mutex);\n+\tupdate_cached_dirents_count(&cfid->dirents, file);\n+\tmutex_unlock(&cfid->dirents.de_mutex);\n+}\n+\n+void complete_cached_dir(struct cached_fid *cfid,\n+\t\t\t\t\tstruct dir_context *ctx,\n+\t\t\t\t\tstruct file *file)\n+{\n+\tif (!cfid)\n+\t\treturn;\n+\n+\tmutex_lock(&cfid->dirents.de_mutex);\n+\tfinished_cached_dirents_count(&cfid->dirents, ctx, file);\n+\tmutex_unlock(&cfid->dirents.de_mutex);\n+}\n+\n+struct cached_dirent *lookup_cached_dirent(struct cached_dirents *cde,\n+\t\t\t\t const char *name,\n+\t\t\t\t unsigned int namelen)\n+{\n+\tstruct cached_dirent *entry;\n+\n+\tif (!cde)\n+\t\treturn NULL;\n+\n+\tlockdep_assert_held(&cde->de_mutex);\n+\n+\tlist_for_each_entry(entry, &cde->entries, entry) {\n+\t\tif (entry->namelen == namelen &&\n+\t\t memcmp(entry->name, name, namelen) == 0)\n+\t\t\treturn entry;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,\n \t\t\t\t\t\t const char *path,\n \t\t\t\t\t\t bool lookup_only,\ndiff --git a/fs/smb/client/cached_dir.h b/fs/smb/client/cached_dir.h\nindex 19d5592512e4b..09f1f488059c9 100644\n--- a/fs/smb/client/cached_dir.h\n+++ b/fs/smb/client/cached_dir.h\n@@ -8,7 +8,6 @@\n #ifndef _CACHED_DIR_H\n #define _CACHED_DIR_H\n \n-\n struct cached_dirent {\n \tstruct list_head entry;\n \tchar *name;\n@@ -87,6 +86,23 @@ 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+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);\n+bool add_to_cached_dir(struct cached_fid *cfid,\n+\t\t struct dir_context *ctx,\n+\t\t const char *name,\n+\t\t int namelen,\n+\t\t struct cifs_fattr *fattr,\n+\t\t struct file *file);\n+void update_pos_cached_dir(struct cached_fid *cfid,\n+\t\t\t\t struct file *file);\n+void complete_cached_dir(struct cached_fid *cfid,\n+\t\t\t\t\tstruct dir_context *ctx,\n+\t\t\t\t\tstruct file *file);\n+struct cached_dirent *lookup_cached_dirent(struct cached_dirents *cde,\n+\t\t\t\t const char *name,\n+\t\t\t\t unsigned int namelen);\n void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,\n \t\t\t const char *name, struct cifs_sb_info *cifs_sb);\n void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);\ndiff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c\nindex 8a444f97e0ae9..907e235ad1b8f 100644\n--- a/fs/smb/client/readdir.c\n+++ b/fs/smb/client/readdir.c\n@@ -817,136 +817,13 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,\n \treturn rc;\n }\n \n-static bool emit_cached_dirents(struct cached_dirents *cde,\n-\t\t\t\tstruct dir_context *ctx)\n-{\n-\tstruct cached_dirent *dirent;\n-\tbool rc;\n-\n-\tlist_for_each_entry(dirent, &cde->entries, entry) {\n-\t\t/*\n-\t\t * Skip all early entries prior to the current lseek()\n-\t\t * position.\n-\t\t */\n-\t\tif (ctx->pos > dirent->pos)\n-\t\t\tcontinue;\n-\t\t/*\n-\t\t * We recorded the current ->pos value for the dirent\n-\t\t * when we stored it in the cache.\n-\t\t * However, this sequence of ->pos values may have holes\n-\t\t * in it, for example dot-dirs returned from the server\n-\t\t * are suppressed.\n-\t\t * Handle this by forcing ctx->pos to be the same as the\n-\t\t * ->pos of the current dirent we emit from the cache.\n-\t\t * This means that when we emit these entries from the cache\n-\t\t * we now emit them with the same ->pos value as in the\n-\t\t * initial scan.\n-\t\t */\n-\t\tctx->pos = dirent->pos;\n-\t\trc = dir_emit(ctx, dirent->name, dirent->namelen,\n-\t\t\t dirent->fattr.cf_uniqueid,\n-\t\t\t dirent->fattr.cf_dtype);\n-\t\tif (!rc)\n-\t\t\treturn rc;\n-\t\tctx->pos++;\n-\t}\n-\treturn true;\n-}\n-\n-static void update_cached_dirents_count(struct cached_dirents *cde,\n-\t\t\t\t\tstruct file *file)\n-{\n-\tif (cde->file != file)\n-\t\treturn;\n-\tif (cde->is_valid || cde->is_failed)\n-\t\treturn;\n-\n-\tcde->pos++;\n-}\n-\n-static void finished_cached_dirents_count(struct cached_dirents *cde,\n-\t\t\t\t\tstruct dir_context *ctx, struct file *file)\n-{\n-\tif (cde->file != file)\n-\t\treturn;\n-\tif (cde->is_valid || cde->is_failed)\n-\t\treturn;\n-\tif (ctx->pos != cde->pos)\n-\t\treturn;\n-\n-\tcde->is_valid = 1;\n-}\n-\n-static bool add_cached_dirent(struct cached_dirents *cde,\n-\t\t\t struct dir_context *ctx, const char *name,\n-\t\t\t int namelen, struct cifs_fattr *fattr,\n-\t\t\t struct file *file)\n-{\n-\tstruct cached_dirent *de;\n-\n-\tif (cde->file != file)\n-\t\treturn false;\n-\tif (cde->is_valid || cde->is_failed)\n-\t\treturn false;\n-\tif (ctx->pos != cde->pos) {\n-\t\tcde->is_failed = 1;\n-\t\treturn false;\n-\t}\n-\tde = kzalloc_obj(*de, GFP_ATOMIC);\n-\tif (de == NULL) {\n-\t\tcde->is_failed = 1;\n-\t\treturn false;\n-\t}\n-\tde->namelen = namelen;\n-\tde->name = kstrndup(name, namelen, GFP_ATOMIC);\n-\tif (de->name == NULL) {\n-\t\tkfree(de);\n-\t\tcde->is_failed = 1;\n-\t\treturn false;\n-\t}\n-\tde->pos = ctx->pos;\n-\n-\tmemcpy(&de->fattr, fattr, sizeof(struct cifs_fattr));\n-\n-\tlist_add_tail(&de->entry, &cde->entries);\n-\t/* update accounting */\n-\tcde->entries_count++;\n-\tcde->bytes_used += sizeof(*de) + (size_t)namelen + 1;\n-\treturn true;\n-}\n-\n static bool cifs_dir_emit(struct dir_context *ctx,\n \t\t\t const char *name, int namelen,\n-\t\t\t struct cifs_fattr *fattr,\n-\t\t\t struct cached_fid *cfid,\n-\t\t\t struct file *file)\n+\t\t\t struct cifs_fattr *fattr)\n {\n-\tsize_t delta_bytes = 0;\n-\tbool rc, added = false;\n \tino_t ino = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid);\n \n-\trc = dir_emit(ctx, name, namelen, ino, fattr->cf_dtype);\n-\tif (!rc)\n-\t\treturn rc;\n-\n-\tif (cfid) {\n-\t\t/* Cost of this entry */\n-\t\tdelta_bytes = sizeof(struct cached_dirent) + (size_t)namelen + 1;\n-\n-\t\tmutex_lock(&cfid->dirents.de_mutex);\n-\t\tadded = add_cached_dirent(&cfid->dirents, ctx, name, namelen,\n-\t\t\t\t\t fattr, file);\n-\t\tmutex_unlock(&cfid->dirents.de_mutex);\n-\n-\t\tif (added) {\n-\t\t\t/* per-tcon then global for consistency with free path */\n-\t\t\tatomic64_add((long long)delta_bytes, &cfid->cfids->total_dirents_bytes);\n-\t\t\tatomic_long_inc(&cfid->cfids->total_dirents_entries);\n-\t\t\tatomic64_add((long long)delta_bytes, &cifs_dircache_bytes_used);\n-\t\t}\n-\t}\n-\n-\treturn rc;\n+\treturn dir_emit(ctx, name, namelen, ino, fattr->cf_dtype);\n }\n \n static int cifs_filldir(char *find_entry, struct file *file,\n@@ -1040,10 +917,10 @@ static int cifs_filldir(char *find_entry, struct file *file,\n \t\t */\n \t\tfattr.cf_flags |= CIFS_FATTR_NEED_REVAL;\n \n+\tadd_to_cached_dir(cfid, ctx, name.name, name.len, &fattr, file);\n \tcifs_prime_dcache(file_dentry(file), &name, &fattr);\n \n-\treturn !cifs_dir_emit(ctx, name.name, name.len,\n-\t\t\t &fattr, cfid, file);\n+\treturn !cifs_dir_emit(ctx, name.name, name.len, &fattr);\n }\n \n \n@@ -1088,30 +965,8 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)\n \tif (rc)\n \t\tgoto cache_not_found;\n \n-\tmutex_lock(&cfid->dirents.de_mutex);\n-\t/*\n-\t * If this was reading from the start of the directory\n-\t * we need to initialize scanning and storing the\n-\t * directory content.\n-\t */\n-\tif (ctx->pos == 0 && cfid->dirents.file == NULL) {\n-\t\tcfid->dirents.file = file;\n-\t\tcfid->dirents.pos = 2;\n-\t}\n-\t/*\n-\t * If we already have the entire directory cached then\n-\t * we can just serve the cache.\n-\t */\n-\tif (cfid->dirents.is_valid) {\n-\t\tif (!dir_emit_dots(file, ctx)) {\n-\t\t\tmutex_unlock(&cfid->dirents.de_mutex);\n-\t\t\tgoto rddir2_exit;\n-\t\t}\n-\t\temit_cached_dirents(&cfid->dirents, ctx);\n-\t\tmutex_unlock(&cfid->dirents.de_mutex);\n+\tif (emit_cached_dir_if_valid(cfid, file, ctx))\n \t\tgoto rddir2_exit;\n-\t}\n-\tmutex_unlock(&cfid->dirents.de_mutex);\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@@ -1161,11 +1016,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)\n \t} else if (current_entry != NULL) {\n \t\tcifs_dbg(FYI, \"entry %lld found\\n\", ctx->pos);\n \t} else {\n-\t\tif (cfid) {\n-\t\t\tmutex_lock(&cfid->dirents.de_mutex);\n-\t\t\tfinished_cached_dirents_count(&cfid->dirents, ctx, file);\n-\t\t\tmutex_unlock(&cfid->dirents.de_mutex);\n-\t\t}\n+\t\tcomplete_cached_dir(cfid, ctx, file);\n \t\tcifs_dbg(FYI, \"Could not find entry\\n\");\n \t\tgoto rddir2_exit;\n \t}\n@@ -1202,11 +1053,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)\n \t\t}\n \n \t\tctx->pos++;\n-\t\tif (cfid) {\n-\t\t\tmutex_lock(&cfid->dirents.de_mutex);\n-\t\t\tupdate_cached_dirents_count(&cfid->dirents, file);\n-\t\t\tmutex_unlock(&cfid->dirents.de_mutex);\n-\t\t}\n+\t\tupdate_pos_cached_dir(cfid, file);\n \n \t\tif (ctx->pos ==\n \t\t\tcifsFile->srch_inf.index_of_last_entry) {\n", "prefixes": [ "7/7" ] }