Skip to content

Commit 6a50d71

Browse files
author
Steve French
committed
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 <[email protected]>
1 parent feeec63 commit 6a50d71

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

fs/smb/client/cached_dir.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ static void smb2_close_cached_fid(struct kref *ref);
1818

1919
static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,
2020
const char *path,
21-
bool lookup_only)
21+
bool lookup_only,
22+
__u32 max_cached_dirs)
2223
{
2324
struct cached_fid *cfid;
2425

@@ -43,7 +44,7 @@ static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,
4344
spin_unlock(&cfids->cfid_list_lock);
4445
return NULL;
4546
}
46-
if (cfids->num_entries >= MAX_CACHED_FIDS) {
47+
if (cfids->num_entries >= max_cached_dirs) {
4748
spin_unlock(&cfids->cfid_list_lock);
4849
return NULL;
4950
}
@@ -162,7 +163,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
162163
if (!utf16_path)
163164
return -ENOMEM;
164165

165-
cfid = find_or_create_cached_dir(cfids, path, lookup_only);
166+
cfid = find_or_create_cached_dir(cfids, path, lookup_only, tcon->max_cached_dirs);
166167
if (cfid == NULL) {
167168
kfree(utf16_path);
168169
return -ENOENT;

fs/smb/client/cached_dir.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct cached_fid {
4949
struct cached_dirents dirents;
5050
};
5151

52-
#define MAX_CACHED_FIDS 16
52+
/* default MAX_CACHED_FIDS is 16 */
5353
struct cached_fids {
5454
/* Must be held when:
5555
* - accessing the cfids->entries list

fs/smb/client/cifsfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
699699
seq_printf(s, ",snapshot=%llu", tcon->snapshot_time);
700700
if (tcon->handle_timeout)
701701
seq_printf(s, ",handletimeout=%u", tcon->handle_timeout);
702+
if (tcon->max_cached_dirs != MAX_CACHED_FIDS)
703+
seq_printf(s, ",max_cached_dirs=%u", tcon->max_cached_dirs);
702704

703705
/*
704706
* Display file and directory attribute timeout in seconds.

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ struct cifs_tcon {
12101210
__u32 max_chunks;
12111211
__u32 max_bytes_chunk;
12121212
__u32 max_bytes_copy;
1213+
__u32 max_cached_dirs;
12131214
#ifdef CONFIG_CIFS_FSCACHE
12141215
u64 resource_id; /* server resource id */
12151216
struct fscache_volume *fscache; /* cookie for share */

fs/smb/client/connect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,6 +2657,7 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
26572657
tcon->retry = ctx->retry;
26582658
tcon->nocase = ctx->nocase;
26592659
tcon->broken_sparse_sup = ctx->no_sparse;
2660+
tcon->max_cached_dirs = ctx->max_cached_dirs;
26602661
if (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)
26612662
tcon->nohandlecache = ctx->nohandlecache;
26622663
else

fs/smb/client/fs_context.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {
150150
fsparam_u32("closetimeo", Opt_closetimeo),
151151
fsparam_u32("echo_interval", Opt_echo_interval),
152152
fsparam_u32("max_credits", Opt_max_credits),
153+
fsparam_u32("max_cached_dirs", Opt_max_cached_dirs),
153154
fsparam_u32("handletimeout", Opt_handletimeout),
154155
fsparam_u64("snapshot", Opt_snapshot),
155156
fsparam_u32("max_channels", Opt_max_channels),
@@ -1165,6 +1166,14 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
11651166
if (result.uint_32 > 1)
11661167
ctx->multichannel = true;
11671168
break;
1169+
case Opt_max_cached_dirs:
1170+
if (result.uint_32 < 1) {
1171+
cifs_errorf(fc, "%s: Invalid max_cached_dirs, needs to be 1 or more\n",
1172+
__func__);
1173+
goto cifs_parse_mount_err;
1174+
}
1175+
ctx->max_cached_dirs = result.uint_32;
1176+
break;
11681177
case Opt_handletimeout:
11691178
ctx->handle_timeout = result.uint_32;
11701179
if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
@@ -1592,7 +1601,7 @@ int smb3_init_fs_context(struct fs_context *fc)
15921601
ctx->acregmax = CIFS_DEF_ACTIMEO;
15931602
ctx->acdirmax = CIFS_DEF_ACTIMEO;
15941603
ctx->closetimeo = SMB3_DEF_DCLOSETIMEO;
1595-
1604+
ctx->max_cached_dirs = MAX_CACHED_FIDS;
15961605
/* Most clients set timeout to 0, allows server to use its default */
15971606
ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
15981607

fs/smb/client/fs_context.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum cifs_param {
128128
Opt_closetimeo,
129129
Opt_echo_interval,
130130
Opt_max_credits,
131+
Opt_max_cached_dirs,
131132
Opt_snapshot,
132133
Opt_max_channels,
133134
Opt_handletimeout,
@@ -261,6 +262,7 @@ struct smb3_fs_context {
261262
__u32 handle_timeout; /* persistent and durable handle timeout in ms */
262263
unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
263264
unsigned int max_channels;
265+
unsigned int max_cached_dirs;
264266
__u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
265267
bool rootfs:1; /* if it's a SMB root file system */
266268
bool witness:1; /* use witness protocol */
@@ -287,7 +289,7 @@ extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
287289
*/
288290
#define SMB3_MAX_DCLOSETIMEO (1 << 30)
289291
#define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */
290-
292+
#define MAX_CACHED_FIDS 16
291293
extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
292294

293295
#endif

0 commit comments

Comments
 (0)