From patchwork Fri Sep 1 07:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 13372133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2CC4CA0FE6 for ; Fri, 1 Sep 2023 07:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbjIAHVO (ORCPT ); Fri, 1 Sep 2023 03:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231532AbjIAHVO (ORCPT ); Fri, 1 Sep 2023 03:21:14 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8462E7F for ; Fri, 1 Sep 2023 00:21:10 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2bbbda48904so27338451fa.2 for ; Fri, 01 Sep 2023 00:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693552869; x=1694157669; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=FRmhlKCecJgq19eOIbcoESnifBDr8W7TiGZLoV6LRy4=; b=Ey0LLRHtQRqzCZTnEx/rB+CS4uVyKgan3OO2ZTNQGw1XjTHGrLAejxVY2yiJtzo8Dr eXks3fmzYmfUkwJFrPJQSQi7nf1XRNfJoe4gM/v81e7dI7jWGUBgjZKSm1gnG82DaPfA 88+LgO7Hpg2ZCdVv1O8IapKPspj9NJtg8LVZXzzAXYmLScUG+mXPaQYn38vHsFYNMTgm lfg+JEtYGvI2VMT9UCUpq6nr1W9E+IpPfODEvh2DPp+vtzaICBefawygxvDzZSrDag/K VRQ9YbWqimkSJZBgFAiMwuWjUhm6Vf4pszlt2ySwycZ3WXfpQQpHqVTbJ3w+c9ndqadP zC6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693552869; x=1694157669; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FRmhlKCecJgq19eOIbcoESnifBDr8W7TiGZLoV6LRy4=; b=K6ewm+3+5f6C1GZMAXw8AR6pjXG/radg8OpHoUmA+uIhZL6fPNsJ9PqS6f3u/UdYXh jQ/iS9yl7bstN1uEwBqR1u1rN94r1QWhGT8ctaR2tEpfjLzcv6Bbw3tt0gYRBGaLaOhI 4MqVe3/WHDtUX3oDLZmx8b2K7hC0Noy1yRRqFFfrmXQ5myN1N76J2Dirc0hYVLTXn43c UPCEs4RxcwxWxtWdR3yuxYdoJ5D6YgVrWUVpvlk6W2jYwy4U/htNVXDjVWu7OumzyyU3 mTY7HTjXsL3/Uu7WVfu9qdwBlLH/bI5qlvsi2Jnxz78ohqtA7lnfPGDR3SzZCnKbBYH5 Tm4g== X-Gm-Message-State: AOJu0Yx2mRvl2dvqjuOko9JKms2KUCp+yVh2XzzemKH7gzpYKuUJkDNP PS2eRofxUSWekKbCT31b+GjK0HOY+/GEQny1+Gr6LdoCjeYG7dVX X-Google-Smtp-Source: AGHT+IEtv391QtBYrokvHPHFOpcmh2wHeyIQyPd278poK22enQpyRXonV4fhh0pnCL6AgtLA8RzR+kD8gLiIrGMNCGI= X-Received: by 2002:a2e:9dc9:0:b0:2bc:bc70:263f with SMTP id x9-20020a2e9dc9000000b002bcbc70263fmr941850ljj.0.1693552868485; Fri, 01 Sep 2023 00:21:08 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Fri, 1 Sep 2023 02:20:57 -0500 Message-ID: Subject: [PATCH][SMB3] add mount parm to allow controlling maximum number of cached directories To: CIFS Cc: Shyam Prasad N , Bharath S M Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Allow adjusting the maximum number of cached directories per share (defaults to 16) via mount parm "max_cached_dirs" See attached From 01ede5d92ce90fe45480059e98b080b23cb0b170 Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 1 Sep 2023 02:15:14 -0500 Subject: [PATCH] smb3: allow controlling maximum number of cached directories Allow adjusting the maximum number of cached directories per share (defaults to 16) via mount parm "max_cached_dirs" Signed-off-by: Steve French --- fs/smb/client/cached_dir.c | 7 ++++--- fs/smb/client/cached_dir.h | 2 +- fs/smb/client/cifsfs.c | 2 ++ fs/smb/client/cifsglob.h | 1 + fs/smb/client/connect.c | 1 + fs/smb/client/fs_context.c | 11 ++++++++++- fs/smb/client/fs_context.h | 4 +++- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c index fe483f163dbc..6206ddadd791 100644 --- a/fs/smb/client/cached_dir.c +++ b/fs/smb/client/cached_dir.c @@ -18,7 +18,8 @@ static void smb2_close_cached_fid(struct kref *ref); static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids, const char *path, - bool lookup_only) + bool lookup_only, + __u32 max_cached_dirs) { struct cached_fid *cfid; @@ -43,7 +44,7 @@ static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids, spin_unlock(&cfids->cfid_list_lock); return NULL; } - if (cfids->num_entries >= MAX_CACHED_FIDS) { + if (cfids->num_entries >= max_cached_dirs) { spin_unlock(&cfids->cfid_list_lock); return NULL; } @@ -162,7 +163,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, if (!utf16_path) return -ENOMEM; - cfid = find_or_create_cached_dir(cfids, path, lookup_only); + cfid = find_or_create_cached_dir(cfids, path, lookup_only, tcon->max_cached_dirs); if (cfid == NULL) { kfree(utf16_path); return -ENOENT; diff --git a/fs/smb/client/cached_dir.h b/fs/smb/client/cached_dir.h index facc9b154d00..a82ff2cea789 100644 --- a/fs/smb/client/cached_dir.h +++ b/fs/smb/client/cached_dir.h @@ -49,7 +49,7 @@ struct cached_fid { struct cached_dirents dirents; }; -#define MAX_CACHED_FIDS 16 +/* default MAX_CACHED_FIDS is 16 */ struct cached_fids { /* Must be held when: * - accessing the cfids->entries list diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index a4d8b0ea1c8c..ff404cda8309 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -695,6 +695,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root) seq_printf(s, ",snapshot=%llu", tcon->snapshot_time); if (tcon->handle_timeout) seq_printf(s, ",handletimeout=%u", tcon->handle_timeout); + if (tcon->max_cached_dirs != MAX_CACHED_FIDS) + seq_printf(s, ",max_cached_dirs=%u", tcon->max_cached_dirs); /* * Display file and directory attribute timeout in seconds. diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 657dee4b2c8c..2be6bdba37e0 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1191,6 +1191,7 @@ struct cifs_tcon { __u32 max_chunks; __u32 max_bytes_chunk; __u32 max_bytes_copy; + __u32 max_cached_dirs; #ifdef CONFIG_CIFS_FSCACHE u64 resource_id; /* server resource id */ struct fscache_volume *fscache; /* cookie for share */ diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 238538dde4e3..f99f3a3cd8a7 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -2656,6 +2656,7 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx) tcon->retry = ctx->retry; tcon->nocase = ctx->nocase; tcon->broken_sparse_sup = ctx->no_sparse; + tcon->max_cached_dirs = ctx->max_cached_dirs; if (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING) tcon->nohandlecache = ctx->nohandlecache; else diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c index 67e16c2ac90e..f61d74017bc8 100644 --- a/fs/smb/client/fs_context.c +++ b/fs/smb/client/fs_context.c @@ -150,6 +150,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = { fsparam_u32("closetimeo", Opt_closetimeo), fsparam_u32("echo_interval", Opt_echo_interval), fsparam_u32("max_credits", Opt_max_credits), + fsparam_u32("max_cached_dirs", Opt_max_cached_dirs), fsparam_u32("handletimeout", Opt_handletimeout), fsparam_u64("snapshot", Opt_snapshot), fsparam_u32("max_channels", Opt_max_channels), @@ -1165,6 +1166,14 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, if (result.uint_32 > 1) ctx->multichannel = true; break; + case Opt_max_cached_dirs: + if (result.uint_32 < 1) { + cifs_errorf(fc, "%s: Invalid max_cached_dirs, needs to be 1 or more\n", + __func__); + goto cifs_parse_mount_err; + } + ctx->max_cached_dirs = result.uint_32; + break; case Opt_handletimeout: ctx->handle_timeout = result.uint_32; if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) { @@ -1592,7 +1601,7 @@ int smb3_init_fs_context(struct fs_context *fc) ctx->acregmax = CIFS_DEF_ACTIMEO; ctx->acdirmax = CIFS_DEF_ACTIMEO; ctx->closetimeo = SMB3_DEF_DCLOSETIMEO; - + ctx->max_cached_dirs = MAX_CACHED_FIDS; /* Most clients set timeout to 0, allows server to use its default */ ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */ diff --git a/fs/smb/client/fs_context.h b/fs/smb/client/fs_context.h index f4eaf8558902..9d8d34af0211 100644 --- a/fs/smb/client/fs_context.h +++ b/fs/smb/client/fs_context.h @@ -128,6 +128,7 @@ enum cifs_param { Opt_closetimeo, Opt_echo_interval, Opt_max_credits, + Opt_max_cached_dirs, Opt_snapshot, Opt_max_channels, Opt_handletimeout, @@ -261,6 +262,7 @@ struct smb3_fs_context { __u32 handle_timeout; /* persistent and durable handle timeout in ms */ unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */ unsigned int max_channels; + unsigned int max_cached_dirs; __u16 compression; /* compression algorithm 0xFFFF default 0=disabled */ bool rootfs:1; /* if it's a SMB root file system */ bool witness:1; /* use witness protocol */ @@ -287,7 +289,7 @@ extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb); */ #define SMB3_MAX_DCLOSETIMEO (1 << 30) #define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */ - +#define MAX_CACHED_FIDS 16 extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp); #endif -- 2.39.2