get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2231760/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2231760,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2231760/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260501112023.338005-7-sprasad@microsoft.com/",
    "project": {
        "id": 12,
        "url": "http://patchwork.ozlabs.org/api/1.1/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": ""
    },
    "msgid": "<20260501112023.338005-7-sprasad@microsoft.com>",
    "date": "2026-05-01T11:20:10",
    "name": "[v4,07/19] 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/1.1/people/79368/?format=api",
        "name": "Shyam Prasad N",
        "email": "nspmangalore@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260501112023.338005-7-sprasad@microsoft.com/mbox/",
    "series": [
        {
            "id": 502444,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/502444/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=502444",
            "date": "2026-05-01T11:20:06",
            "name": "[v4,01/19] cifs: change_conf needs to be called for session setup",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/502444/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2231760/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2231760/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "\n <linux-cifs+bounces-11331-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=VJSOcYmn;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11331-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=\"VJSOcYmn\"",
            "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.215.171",
            "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 [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g6TSD5R5Fz1yHZ\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 01 May 2026 21:33:16 +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 F2AE930BF13E\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  1 May 2026 11:22:49 +0000 (UTC)",
            "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 2E0183AA4F9;\n\tFri,  1 May 2026 11:20:41 +0000 (UTC)",
            "from mail-pg1-f171.google.com (mail-pg1-f171.google.com\n [209.85.215.171])\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 5364B3A0B1F\n\tfor <linux-cifs@vger.kernel.org>; Fri,  1 May 2026 11:20:39 +0000 (UTC)",
            "by mail-pg1-f171.google.com with SMTP id\n 41be03b00d2f7-c7973bbc16dso1095170a12.0\n        for <linux-cifs@vger.kernel.org>;\n Fri, 01 May 2026 04:20:39 -0700 (PDT)",
            "from sprasad-dev1.corp.microsoft.com ([167.220.110.216])\n        by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-8351587db67sm2331922b3a.13.2026.05.01.04.20.36\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Fri, 01 May 2026 04:20:37 -0700 (PDT)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777634441; cv=none;\n b=N/FCHFoviE59XIn5i5NVZ04tQgNGpoTNAN4zjaxHoQrc5ZgnZqMAfY22VjNBYudG9VEDx2rmcuk3sb1TBkbswMVZFf7Gg+5TW+7axJuazaMsFB52j9IIih0c5JI67/aXpCJjp5zA+F/gKBV811hGhjm/UPEGipWiQwWge3GMDAQ=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777634441; c=relaxed/simple;\n\tbh=yQDGUugMgmyKUZ0z5Lq2sQESbHDF2/K5IdaSCxIi0YA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=ib9TJcaf92vBeuNIhczHM20jytlFvOYO1qoNQkILPFWchPlUp4V67XxXOxecgaVI6+A/A1zQz6GTYI4Uc6RqGCLx/wiMdQIGqciYUDaxlnU7j3k04tLzq2HMc+GDWz6VYS+Auqlyri/qDRuaeM+ubqmCWMsYUDkuh6iiHL6fsHk=",
        "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=VJSOcYmn; arc=none smtp.client-ip=209.85.215.171",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777634438; x=1778239238;\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=IXcR03k3xJhfx1FDqTSaR+BYNjaTbVzhTjZ49oxLsl0=;\n        b=VJSOcYmnYVdRQv2vZpRBA9mWOURMjRC7mvi61/zhrUGEIs3yzV7YbnyeahxeXqyQMR\n         u3mFei5YIGZr/7jJSLE9aBIuuSurO3p0xX/mbnukh51at/2bxNuF0dWWYuloKC1gOiXd\n         hSkJ+ARb9OtRPbo0IUS8q4mPaSNCLqO6cH/PAPT8cktsq1Mus0yMOWQlYVeg3/NDU26q\n         Q97lo+/QdeSZZnWDReTR/zhhkbHgsFCvxFnvaK++itFYVEC3jznO0XKrwwWBHKnfNT8u\n         SO4cI03Qoo2BMZXPWd1uLCh0/XLNlaq4vQ9a0dWbwA9eRAy1yQE+0rsaI2mj+gz/LVh8\n         GPFQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777634438; x=1778239238;\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=IXcR03k3xJhfx1FDqTSaR+BYNjaTbVzhTjZ49oxLsl0=;\n        b=oMlLtiAWfKjXCoPcd0yvmn9FYN5QagEAcyz4HkVAX9MU4b2qBARldSwIL7Xi4JrCv7\n         4OJKBdAtW4fHzhtPFiMQVtT8d3WuDqkULD0To/yAFs/DvynVP8NTqVUdw/PV6tcc4ANp\n         d2yuBiAURh9LWd6u+ywgTSeK0Gt8U8bF3POEuimEPMrgYp4WdZi3dLua7vYD5Q1J3xAW\n         ynUNYVPMOGooJAVu/Iw2MjJCugABv20SPfvKCcgaU/2v09OCBFuj4/XGXToFPJPjhiDC\n         AAhoHZ7MIn/OY+uGypq1SrcvcJPTPZl3BHV1MSD6WiUrw+1tR3BBb8hB/inLdo5b844v\n         d9Vw==",
        "X-Gm-Message-State": "AOJu0Yw7bZPgZWfGPNnynlQbrteiYUvY14ns3rACdzQij3G5LZIXa/D/\n\tAkGtqrscGNNspf9hrUPugUEMQWC//LmcBPn5AiArPk4+/36gBhFfBanVX1a66SjNBsU=",
        "X-Gm-Gg": "AeBDievEGJQkOHgm8pPOkDPCKhRe3zzXJDglZqGRtZiBJP0JWCDWfyPAo+366dGwR/N\n\tuMwB2sPXFQDZczflqddNGz+DlpPNZmRUAX7ix1K3TQ7F4vh2y+B5/jRvUiiZnhM6pkgoH2ggu3w\n\tlmYtoRb3D3KMGB9KYH93X7FAnVnm2iXNvPPjrtxspmsOw0PLRKZ6xnRcpuPqHTcrLLob+gl2P3Q\n\tik5tZPuOcRFxa+H/XdPe3uas/41K9z8itVkLBccpIygpd+fO0W/woEwDhnfzTo9F6YDqxEVx9bI\n\t9UIHdF1DyzGKOSzRk2Fl//ycaIHPU7SlCAVU09SFmkJHkdaIQ3u7Y8pRHT8A8vc6wRMtcdUhab9\n\twCs8Z7zPxdH3w14HZJ0BvkZtu18ENSp2e7B8ak1Ghl9JNR6OukXKTbZApvr33QJteD15lDrnt1C\n\tw2r4hpTaRFx+O/fofxXKE74B5qWomYK94J6vIDEWG7r3vHTQBZLgloN0BkaKXN8Xeg",
        "X-Received": "by 2002:a05:6a00:90a3:b0:82a:65fa:cecf with SMTP id\n d2e1a72fcca58-834fdb0dfcemr8074287b3a.4.1777634438148;\n        Fri, 01 May 2026 04:20:38 -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 v4 07/19] cifs: reorganize cached dir helpers",
        "Date": "Fri,  1 May 2026 16:50:10 +0530",
        "Message-ID": "<20260501112023.338005-7-sprasad@microsoft.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20260501112023.338005-1-sprasad@microsoft.com>",
        "References": "<20260501112023.338005-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 64e22c064fa0a..a9bc0c81868c8 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": [
        "v4",
        "07/19"
    ]
}