Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp8288041pxb; Fri, 19 Feb 2021 12:08:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7BA+tYYwVvSAqkgZDhIfFxG4XiVTV6Bf21VMg8ZTxsrrybOmmYt8jYkwUzA9zly9VXP1f X-Received: by 2002:a17:906:33c5:: with SMTP id w5mr10210915eja.319.1613765332044; Fri, 19 Feb 2021 12:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613765332; cv=none; d=google.com; s=arc-20160816; b=T6LJVCX/PH/b5t36LOtQrCPqKIli+1J7c6cmjkGXx/1KXQREkQ2qg/E4CJn2fWIeNh /VE+dgk84YUwU/BfggS6FSPRegKtiaEX/GZVnY/g2kQ+wq4CyBi3N0yR7TblXAnPWnCc H+oDR9bgd6xY8oDyoXItWOp8pxg3+WnS6NieQg1ivJlMvfbvVSwLxqJorevWQyV8sTko DRthh/+yTs9plH76LOrezG1hbIgz9ZpuJFSAKGxYV7EET4B+osLC6qXv3t+ypJncMypS hF5H7slcs0aXuEMHf0e+7URahEps3XLkdRwTSjv1w59Bj1nUXng4AtwiAVnOpXuDLL9N t0XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=fFODysaqX4A8EM2/2WwDkgJzlhOBo7iP0CWKIr428fU=; b=vJLX5PdZCoqY35uN4Nfivsd+m6V9f7vJ6dfeEV90h851dzfOz2ZDpVaUvXw8UalwbI ViDDeGTKZe4jfePqH4HgrMEJfojtynC9K1PoILEZMnwXVtj9Tri0pBsBj/VbhfAn0mh1 7SRGQ5OOtsBSqzvo8eAUNo/klTCNkLhjULvFOsvneZtpQgTeEg12a3hV/WmhOAL4AEWk TGbTFmgbfmatcqOBLPCuX2Wt4FOXmNegwK28so7LIRRfNtZOFjKh4xVn5pTaRDlATlQ1 B4MRYd7HxKbYf7xicSl8VWRDR9jRlOu4XUBTqTdYdCoxQjrVhO2X542G7FXJ9T1sJB4i z3hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uqfo3ecb; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jx6si6374755ejc.37.2021.02.19.12.08.15; Fri, 19 Feb 2021 12:08:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uqfo3ecb; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbhBSUIK (ORCPT + 99 others); Fri, 19 Feb 2021 15:08:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21580 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbhBSUIJ (ORCPT ); Fri, 19 Feb 2021 15:08:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613765202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fFODysaqX4A8EM2/2WwDkgJzlhOBo7iP0CWKIr428fU=; b=Uqfo3ecb9uNNvfwBOe0eYFzTgLZpGCuFBT+FgCbH4x6LChR/+LNKyDTX6QpEftjjx6cq0A LI8hJ+DL3RVQ0pTAlsjR5Dg7wkehNceIjlI1hrK5WeT/Pti1Upol8mlLRUV4ETcUsaOvVv U/r8JGfl/aV9uUMmTe+IdE3uwx+Q7uY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-278-o6mOoZj5P2e-WMN_rDpsIQ-1; Fri, 19 Feb 2021 15:06:41 -0500 X-MC-Unique: o6mOoZj5P2e-WMN_rDpsIQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24AA41005501 for ; Fri, 19 Feb 2021 20:06:40 +0000 (UTC) Received: from madhat.home.dicksonnet.net (ovpn-112-108.phx2.redhat.com [10.3.112.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7ED3189C4 for ; Fri, 19 Feb 2021 20:06:39 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 3/7] exportd: multiple threads Date: Fri, 19 Feb 2021 15:08:11 -0500 Message-Id: <20210219200815.792667-4-steved@redhat.com> In-Reply-To: <20210219200815.792667-1-steved@redhat.com> References: <20210219200815.792667-1-steved@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Ported the multiple thread code from mountd (commit 11d34d11) Signed-off-by: Steve Dickson --- nfs.conf | 3 + systemd/nfs.conf.man | 9 +++ utils/exportd/exportd.c | 118 ++++++++++++++++++++++++++++++++++++-- utils/exportd/exportd.man | 7 +++ 4 files changed, 133 insertions(+), 4 deletions(-) diff --git a/nfs.conf b/nfs.conf index 9fcf1bf..4b344fa 100644 --- a/nfs.conf +++ b/nfs.conf @@ -29,6 +29,9 @@ # port=0 # udp-port=0 # +[exportd] +# debug="all|auth|call|general|parse" +# threads=1 [mountd] # debug="all|auth|call|general|parse" # manage-gids=n diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index 16e0ec4..a4379fd 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -128,6 +128,15 @@ then the client will be able to mount the path as but on the server, this will resolve to the path .BR /my/root/filesystem . +.TP +.B exportd +Recognized values: +.B threads + +See +.BR exportd (8) +for details. + .TP .B nfsdcltrack Recognized values: diff --git a/utils/exportd/exportd.c b/utils/exportd/exportd.c index 2f67e3b..c814503 100644 --- a/utils/exportd/exportd.c +++ b/utils/exportd/exportd.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "nfslib.h" #include "conffile.h" @@ -26,6 +28,13 @@ extern void my_svc_run(void); struct state_paths etab; struct state_paths rmtab; +/* Number of mountd threads to start. Default is 1 and + * that's probably enough unless you need hundreds of + * clients to be able to mount at once. */ +static int num_threads = 1; +/* Arbitrary limit on number of threads */ +#define MAX_THREADS 64 + int manage_gids; int use_ipaddr = -1; @@ -34,6 +43,7 @@ static struct option longopts[] = { "foreground", 0, 0, 'F' }, { "debug", 1, 0, 'd' }, { "help", 0, 0, 'h' }, + { "num-threads", 1, 0, 't' }, { NULL, 0, 0, 0 } }; @@ -42,10 +52,85 @@ static struct option longopts[] = */ inline static void set_signals(void); +/* Wait for all worker child processes to exit and reap them */ +static void +wait_for_workers (void) +{ + int status; + pid_t pid; + + for (;;) { + + pid = waitpid(0, &status, 0); + + if (pid < 0) { + if (errno == ECHILD) + return; /* no more children */ + xlog(L_FATAL, "mountd: can't wait: %s\n", + strerror(errno)); + } + + /* Note: because we SIG_IGN'd SIGCHLD earlier, this + * does not happen on 2.6 kernels, and waitpid() blocks + * until all the children are dead then returns with + * -ECHILD. But, we don't need to do anything on the + * death of individual workers, so we don't care. */ + xlog(L_NOTICE, "mountd: reaped child %d, status %d\n", + (int)pid, status); + } +} + +/* Fork num_threads worker children and wait for them */ +static void +fork_workers(void) +{ + int i; + pid_t pid; + + xlog(L_NOTICE, "mountd: starting %d threads\n", num_threads); + + for (i = 0 ; i < num_threads ; i++) { + pid = fork(); + if (pid < 0) { + xlog(L_FATAL, "mountd: cannot fork: %s\n", + strerror(errno)); + } + if (pid == 0) { + /* worker child */ + + /* Re-enable the default action on SIGTERM et al + * so that workers die naturally when sent them. + * Only the parent unregisters with pmap and + * hence needs to do special SIGTERM handling. */ + struct sigaction sa; + sa.sa_handler = SIG_DFL; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGHUP, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + + /* fall into my_svc_run in caller */ + return; + } + } + + /* in parent */ + wait_for_workers(); + xlog(L_NOTICE, "exportd: no more workers, exiting\n"); + exit(0); +} + static void killer (int sig) { + if (num_threads > 1) { + /* play Kronos and eat our children */ + kill(0, SIGTERM); + wait_for_workers(); + } xlog (L_NOTICE, "Caught signal %d, exiting.", sig); + exit(0); } static void @@ -78,10 +163,20 @@ static void usage(const char *prog, int n) { fprintf(stderr, - "Usage: %s [-f|--foreground] [-h|--help] [-d kind|--debug kind]\n", prog); + "Usage: %s [-f|--foreground] [-h|--help] [-d kind|--debug kind]\n" +" [-t num|--num-threads=num]\n", prog); exit(n); } +inline static void +read_exportd_conf(char *progname) +{ + conf_init_file(NFS_CONFFILE); + + xlog_set_debug(progname); + + num_threads = conf_get_num("exportd", "threads", num_threads); +} int main(int argc, char **argv) { @@ -98,10 +193,10 @@ main(int argc, char **argv) /* Initialize logging. */ xlog_open(progname); - conf_init_file(NFS_CONFFILE); - xlog_set_debug(progname); + /* Read in config setting */ + read_exportd_conf(progname); - while ((c = getopt_long(argc, argv, "d:fh", longopts, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "d:fht:", longopts, NULL)) != EOF) { switch (c) { case 'd': xlog_sconfig(optarg, 1); @@ -112,6 +207,9 @@ main(int argc, char **argv) case 'h': usage(progname, 0); break; + case 't': + num_threads = atoi (optarg); + break; case '?': default: usage(progname, 1); @@ -132,6 +230,18 @@ main(int argc, char **argv) set_signals(); daemon_ready(); + /* silently bounds check num_threads */ + if (foreground) + num_threads = 1; + else if (num_threads < 1) + num_threads = 1; + else if (num_threads > MAX_THREADS) + num_threads = MAX_THREADS; + + if (num_threads > 1) + fork_workers(); + + /* Open files now to avoid sharing descriptors among forked processes */ cache_open(); diff --git a/utils/exportd/exportd.man b/utils/exportd/exportd.man index d786e57..1d65b5e 100644 --- a/utils/exportd/exportd.man +++ b/utils/exportd/exportd.man @@ -44,6 +44,13 @@ Run in foreground (do not daemonize) .TP .B \-h " or " \-\-help Display usage message. +.TP +.BR "\-t N" " or " "\-\-num\-threads=N " or " \-\-num\-threads N " +This option specifies the number of worker threads that rpc.mountd +spawns. The default is 1 thread, which is probably enough. More +threads are usually only needed for NFS servers which need to handle +mount storms of hundreds of NFS mounts in a few seconds, or when +your DNS server is slow or unreliable. .SH CONFIGURATION FILE Many of the options that can be set on the command line can also be controlled through values set in the -- 2.29.2