nfsdctl: fix default threads and clean up compiler warnings
Subsystems (2)
Jeff Layton
maintainercover nfsdctl: fix default threads and clean up compiler warnings
Steve noticed while playing with the nfsdctl patches that I had goofed setting the default number of threads when it wasn't specified in nfs.conf. The first patch fixes that. The second patch cleans up a bunch of compiler warnings that I missed in the original submission.
Both should apply cleanly on top of the v5 nfsdctl series [1] that I sent last month.
[1]: https://lore.kernel.org/linux-nfs/[email protected]/
---
Jeff Layton (2):
nfsdctl: make "autostart" default to 16 threads
nfsdctl: fix compiler warnings
utils/nfsdctl/nfsdctl.c | 80 ++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 47 deletions(-)
---
base-commit: 44dd12f5a715b419d83f81657ea68ea435f6c248
change-id: 20240715-nfsdctl-caa54bd2885f
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH 1/2 nfsdctl: make "autostart" default to 16 threads
The original nfsdctl posting required the user to set a threads= value in nfs.conf, or autostart wouldn't work properly. rpc.nfsd has a default of 8 threads, which is pitifully low in the modern age. For nfsdctl, double that value to default to 16 threads.
--- utils/nfsdctl/nfsdctl.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
utils/nfsdctl/nfsdctl.c +19 -13
@@ -1356,9 +1356,12 @@ static void autostart_usage(void)printf (" Start the server with the settings in /etc/nfs.conf.\n" ); } +/* default number of nfsd threads when not specified in nfs.conf */ +#define DEFAULT_AUTOSTART_THREADS 16 +static int autostart_func (struct nl_sock *sock,int argc,char ** argv) { -int *threads, grace, lease, idx, ret, opt; +int *threads, grace, lease, idx, ret, opt, pools;struct conf_list *thread_str;struct conf_list_node *n;char *scope, *pool_mode;
@@ -1399,26 +1402,29 @@ static int autostart_func(struct nl_sock *sock, int argc, char ** argv) scope =conf_get_str ("nfsd" ,"scope" ); thread_str =conf_get_list ("nfsd" ,"threads" ); -if (!thread_str || thread_str->cnt ==0 ) -return 0 ; + pools = thread_str ? thread_str->cnt :1 ; - threads =calloc (thread_str->cnt,sizeof (int )); + threads =calloc (pools,sizeof (int ));if (!threads)return -ENOMEM ; - idx =0 ; - TAILQ_FOREACH(n, &(thread_str->fields), link) { -char *endptr =NULL ; +if (thread_str) { + idx =0 ; + TAILQ_FOREACH(n, &(thread_str->fields), link) { +char *endptr =NULL ; - threads[idx++] =strtol (n->field, &endptr,0 ); -if (!endptr || *endptr !='\0' ) { -fprintf (stderr,"Invalid threads value %s.\n" , n->field); - ret = -EINVAL ; - goto out; + threads[idx++] =strtol (n->field, &endptr,0 ); +if (!endptr || *endptr !='\0' ) { +fprintf (stderr,"Invalid threads value %s.\n" , n->field); + ret = -EINVAL ; + goto out; + } } + }else { + threads[0 ] =DEFAULT_AUTOSTART_THREADS ; } - ret =threads_doit (sock,NFSD_CMD_THREADS_SET , grace, lease, thread_str->cnt, + ret =threads_doit (sock,NFSD_CMD_THREADS_SET , grace, lease, pools, threads, scope); out:free (threads);
Signature · 1 line
2.45.2
Jeff Layton
maintainerPATCH 2/2 nfsdctl: fix compiler warnings
In reply to Jeff LaytonFix a pile of compiler warnings.
--- utils/nfsdctl/nfsdctl.c | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-)
utils/nfsdctl/nfsdctl.c +14 -34
@@ -44,7 +44,6 @@*/ static int debug_level; -static int nl_family_id;struct nfs_version {uint8_t major;
@@ -84,16 +83,6 @@ static const struct option help_only_options[] = { { }, }; -static void debug (int level,const char *fmt, ...) -{ -va_list args; - -va_start (args, fmt); -if (level <= debug_level) -vprintf (fmt, args); -va_end (args); -} -#define NFSD4_OPS_MAX_LEN sizeof(nfsd4_ops) / sizeof(nfsd4_ops[0])static const char *nfsd4_ops[] = { [OP_ACCESS ] ="OP_ACCESS" ,
@@ -317,8 +306,6 @@ static void parse_threads_get(struct genlmsghdr *gnlh)nla_for_each_attr (attr,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ), rem) { -struct nlattr *a; -switch (nla_type (attr)) {case NFSD_A_SERVER_GRACETIME :printf ("gracetime: %u\n" ,nla_get_u32 (attr));
@@ -327,7 +314,7 @@ static void parse_threads_get(struct genlmsghdr *gnlh)printf ("leasetime: %u\n" ,nla_get_u32 (attr));break ;case NFSD_A_SERVER_SCOPE : -printf ("scope: %s\n" ,nla_data (attr)); +printf ("scope: %s\n" , (const char *)nla_data (attr));break ;case NFSD_A_SERVER_THREADS : pool_threads[i++] =nla_get_u32 (attr);
@@ -352,7 +339,7 @@ static void parse_pool_mode_get(struct genlmsghdr *gnlh) genlmsg_attrlen(gnlh, 0), rem) {switch (nla_type (attr)) {case NFSD_A_POOL_MODE_MODE : -printf ("pool-mode: %s\n" ,nla_data (attr)); +printf ("pool-mode: %s\n" , (const char *)nla_data (attr));break ;case NFSD_A_POOL_MODE_NPOOLS :printf ("npools: %u\n" ,nla_get_u32 (attr));
@@ -366,7 +353,6 @@ static void parse_pool_mode_get(struct genlmsghdr *gnlh)static int recv_handler (struct nl_msg *msg,void *arg) {struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -const struct nlattr *attr =genlmsg_attrdata (gnlh,0 );switch (gnlh->cmd) {case NFSD_CMD_RPC_STATUS_GET :
@@ -573,7 +559,7 @@ static void threads_usage(void)static int threads_func (struct nl_sock *sock,int argc,char **argv) {uint8_t cmd =NFSD_CMD_THREADS_GET ; -uint32_t *pool_threads =NULL ; +int *pool_threads =NULL ;int opt, pools =0 ; optind =1 ;
@@ -589,7 +575,7 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)char **targv = &argv[optind];int i; - pools = argc - optind, i; + pools = argc - optind; pool_threads =alloca (pools *sizeof (*pool_threads)); cmd =NFSD_CMD_THREADS_SET ;
@@ -785,8 +771,7 @@ static void version_usage(void)static int version_func (struct nl_sock *sock,int argc,char ** argv) { -char *endptr =NULL ; -int opt, ret, threads, i; +int ret, i;/* help is only valid as first argument after command */ if (argc > 1 &&
@@ -940,7 +925,7 @@ static int update_listeners(const char *str)char buf[INET6_ADDRSTRLEN +16 ];char sign = *str;char *netid, *addr, *port, *end; -struct addrinfo *res, *ai; +struct addrinfo *res;int i, ret;struct addrinfo hints = { .ai_flags =AI_PASSIVE , .ai_family =AF_INET ,
@@ -1156,9 +1141,7 @@ static void listener_usage(void)static int listener_func (struct nl_sock *sock,int argc,char ** argv) { -char *endptr =NULL ; -int ret, opt, threads, i; -int argidx; +int ret, i;/* help is only valid as first argument after command */ if (argc > 1 &&
@@ -1255,16 +1238,14 @@ static int pool_mode_func(struct nl_sock *sock, int argc, char **argv)if (optind < argc) {char **targv = &argv[optind]; -int i; cmd =NFSD_CMD_POOL_MODE_SET ;/* empty string? */ -if (targv[i][0 ] =='\0' ) { -fprintf (stderr,"Invalid threads value %s.\n" , targv[i]); +if (*targv[0 ] =='\0' ) { +fprintf (stderr,"Invalid threads value %s.\n" , targv[0 ]);return 1 ; } - pool_mode = targv[0 ]; }return pool_mode_doit (sock, cmd, pool_mode);
@@ -1272,18 +1253,17 @@ static int pool_mode_func(struct nl_sock *sock, int argc, char **argv)#define MAX_LISTENER_LEN (64 * 2 + 16) -static int +static void add_listener (const char *netid,const char *addr,const char *port) {char buf[MAX_LISTENER_LEN ]; -int ret;if (strchr (addr,':' )) - ret =snprintf (buf,MAX_LISTENER_LEN ,"+%s:[%s]:%s" , - netid, addr, port); +snprintf (buf,MAX_LISTENER_LEN ,"+%s:[%s]:%s" , + netid, addr, port);else - ret =snprintf (buf,MAX_LISTENER_LEN ,"+%s:%s:%s" , - netid, addr, port); +snprintf (buf,MAX_LISTENER_LEN ,"+%s:%s:%s" , + netid, addr, port); buf[MAX_LISTENER_LEN -1 ] ='\0' ;update_listeners (buf); }
Signature · 1 line
2.45.2