Skip to content

Commit

Permalink
ksmbd-tools: add max connections parameter to global section
Browse files Browse the repository at this point in the history
Add max connections parameter to limit number of maximum simultaneous
connections. The default value is 128. And the maximum value is 64k.
Values greater than 64k or 0 will be silently set to 64k.

Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Jan 12, 2023
1 parent a09f767 commit 785a9d2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/linux/ksmbd_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct ksmbd_startup_request {
__u32 sub_auth[3];
__u32 smb2_max_credits;
__u32 smbd_max_io_size; /* smbd read write size */
__u32 reserved[127]; /* Reserved room */
__u32 max_connections; /* Number of maximum simultaneous connections */
__u32 reserved[126]; /* Reserved room */
__u32 ifc_list_sz;
__s8 ____payload[];
};
Expand Down
4 changes: 4 additions & 0 deletions include/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct smbconf_global {
unsigned int smb2_max_trans;
unsigned int smb2_max_credits;
unsigned int smbd_max_io_size;
unsigned int max_connections;
unsigned int share_fake_fscaps;
unsigned int gen_subauth[3];
char *krb5_keytab_file;
Expand Down Expand Up @@ -84,6 +85,9 @@ extern struct smbconf_global global_conf;

#define KSMBD_CONF_FILE_MAX 10000

#define KSMBD_CONF_DEFAULT_CONNECTIONS 128
#define KSMBD_CONF_MAX_CONNECTIONS 65536

#define PATH_PWDDB SYSCONFDIR "/ksmbd/ksmbdpwd.db"
#define PATH_SMBCONF SYSCONFDIR "/ksmbd/ksmbd.conf"
#define PATH_SMBCONF_FALLBACK SYSCONFDIR "/ksmbd/smb.conf"
Expand Down
6 changes: 3 additions & 3 deletions ksmbd.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ Maximum number of simultaneous sessions to all shares.

Default: \fBmax active sessions = 1024\fR \" KSMBD_CONF_DEFAULT_SESS_CAP
.TP
\fBmax connections\fR (S)
\fBmax connections\fR (G)
Maximum number of simultaneous connections to the share.
With \fBmax connections = 0\fR, any number of connections may be made.
The maximum value is 64k. Values greater than 64k or 0 will be silently set to 64k.

Default: \fBmax connections = 0\fR
Default: \fBmax connections = 128\fR
.TP
\fBmax open files\fR (G)
Maximum number of simultaneous open files for a client.
Expand Down
3 changes: 2 additions & 1 deletion ksmbd.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
smbd max io size = 8MB
tcp port = 445
workgroup = WORKGROUP
max connections = 128

; share parameters for all sections
browseable = yes
Expand All @@ -44,7 +45,7 @@
hide dot files = yes
inherit owner = no
invalid users =
max connections = 0
max connections = 128
oplocks = yes
path =
read list =
Expand Down
1 change: 1 addition & 0 deletions mountd/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static int ipc_ksmbd_starting_up(void)
ev->smb2_max_write = global_conf.smb2_max_write;
ev->smb2_max_trans = global_conf.smb2_max_trans;
ev->smbd_max_io_size = global_conf.smbd_max_io_size;
ev->max_connections = global_conf.max_connections;
ev->share_fake_fscaps = global_conf.share_fake_fscaps;
memcpy(ev->sub_auth, global_conf.gen_subauth, sizeof(ev->sub_auth));
ev->smb2_max_credits = global_conf.smb2_max_credits;
Expand Down
12 changes: 12 additions & 0 deletions tools/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ static gboolean global_group_kv(gpointer _k, gpointer _v, gpointer user_data)
return TRUE;
}

if (!cp_key_cmp(_k, "max connections")) {
global_conf.max_connections = memparse(_v);
if (!global_conf.max_connections ||
global_conf.max_connections > KSMBD_CONF_MAX_CONNECTIONS) {
pr_info("Limits exceeding the maximum simultaneous connections(%d)\n",
KSMBD_CONF_MAX_CONNECTIONS);
global_conf.max_connections = KSMBD_CONF_MAX_CONNECTIONS;
}
return TRUE;
}

/* At this point, this is an option that must be applied to all shares */
return FALSE;
}
Expand All @@ -556,6 +567,7 @@ static void global_conf_default(void)
{
/* The SPARSE_FILES file system capability flag is set by default */
global_conf.share_fake_fscaps = 64;
global_conf.max_connections = KSMBD_CONF_DEFAULT_CONNECTIONS;
}

static void global_conf_create(void)
Expand Down
7 changes: 7 additions & 0 deletions tools/management/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ static void process_group_kv(gpointer _k, gpointer _v, gpointer user_data)

if (shm_share_config(k, KSMBD_SHARE_CONF_MAX_CONNECTIONS)) {
share->max_connections = cp_get_group_kv_long_base(v, 10);
if (!share->max_connections ||
share->max_connections > KSMBD_CONF_MAX_CONNECTIONS) {
pr_info("Limits exceeding the maximum simultaneous connections(%d)\n",
KSMBD_CONF_MAX_CONNECTIONS);
share->max_connections = KSMBD_CONF_MAX_CONNECTIONS;
}
return;
}

Expand Down Expand Up @@ -643,6 +649,7 @@ static void init_share_from_group(struct ksmbd_share *share,
share->directory_mask = KSMBD_SHARE_DEFAULT_DIRECTORY_MASK;
share->force_create_mode = 0;
share->force_directory_mode = 0;
share->max_connections = KSMBD_CONF_DEFAULT_CONNECTIONS;

share->force_uid = KSMBD_SHARE_INVALID_UID;
share->force_gid = KSMBD_SHARE_INVALID_GID;
Expand Down

0 comments on commit 785a9d2

Please sign in to comment.