diff mbox series

[1/2] nfsdctl: make "autostart" default to 16 threads

Message ID 20240715-nfsdctl-v1-1-c09c314f540d@kernel.org (mailing list archive)
State New
Headers show
Series nfsdctl: fix default threads and clean up compiler warnings | expand

Commit Message

Jeff Layton July 15, 2024, 11:43 a.m. UTC
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.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 utils/nfsdctl/nfsdctl.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/utils/nfsdctl/nfsdctl.c b/utils/nfsdctl/nfsdctl.c
index 55bf5cd21783..eb2c8cca4f42 100644
--- a/utils/nfsdctl/nfsdctl.c
+++ b/utils/nfsdctl/nfsdctl.c
@@ -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);