Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2942539pxb; Sun, 28 Feb 2021 19:24:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoV5nKzSspt75bWJ7U7u69WZTqTh5iBaikJKQQyPnGbIBtRPY0RvDZfiTb0+6JD12B5p06 X-Received: by 2002:aa7:db4f:: with SMTP id n15mr7101536edt.12.1614569073046; Sun, 28 Feb 2021 19:24:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614569073; cv=none; d=google.com; s=arc-20160816; b=iGUjlDsGa/WokfwOBi0DiKO+kksDedu8CvWTLnnihpxUrorFUeqjeBhFsZ+1zDo/h1 hKNDKYisg5nR9c3whqyLmJzTOk0TxASCXJlnG5I4KqYptnltsMuyzmoxoRX6mWsHyYDl +2mC8erSC6chCjp8GZ6s7nlINC0t1MjOEXtzc7yu6Xn9Deo07VjgGDlQIazy6YJUudjB iLbh59ThrMjIP5lUIDVlTRqDB99va0RfNNrAEcFesxt0ArwSDhDrjp31YGYc1yZrNZS1 9N9nGy3EJyV+PxNvDs9NGaL62pEq0I7cLHH2uPlNQ0CgUXJSQ/KElQaS07OedN/E4rwX wJdg== 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 :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from; bh=zh+fW5cXv23betkewk52nznXWlXmhQfyzh18Zn9zzOw=; b=vLXdJO1eBAaHFvKHtRvE2z5xCWdBGIdmBUa2CKfKrV5QAOrgv5P09WFSmukAsVzvFH 17Kha4E1FQNHWGUiPOzQ0bw8oyyrpIZp4zaAMoyNht2ggjMhS64FpS5p5NAszR5jqOm9 NbbWivDoCE7DKutmnHtxH5HL0GS8OObgiMGIMFaqexKSQdl5jlsIXJMz6nqPwG3BudFO 4xf2Yn/v7i6GXEQCgTLuPl8sx4EpVVzdaLUL6LA83f68VaZu4UfilgjMrXkW3Q1nHhtu IOtviaaH7BU57kbRnCkCDTPnWqL0hSvJdSs8U24y/nx5+PMPvsVRWag7GIbU8WHEEtL7 UW2Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i11si3420877edb.325.2021.02.28.19.24.10; Sun, 28 Feb 2021 19:24:33 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231811AbhCACTG (ORCPT + 99 others); Sun, 28 Feb 2021 21:19:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:58540 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231802AbhCACTE (ORCPT ); Sun, 28 Feb 2021 21:19:04 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6C0FEAF84; Mon, 1 Mar 2021 02:18:00 +0000 (UTC) From: NeilBrown To: Steve Dickson Date: Mon, 01 Mar 2021 13:17:15 +1100 Subject: [PATCH 5/5] mountd: make default ttl settable by option Cc: Linux NFS Mailing list Message-ID: <161456503510.22801.14509641806602250672.stgit@noble> In-Reply-To: <161456493684.22801.323431390819102360.stgit@noble> References: <161456493684.22801.323431390819102360.stgit@noble> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: NeilBrown The DEFAULT_TTL affects the rate at which authentication messages are logged. So it is useful to make it settable. Add "-ttl" and "-T", and add clear statement in the documentation of both the benefits and the possible negative effects of choosing a larger value Signed-off-by: NeilBrown --- support/export/cache.c | 6 +++--- support/export/v4root.c | 3 ++- support/include/exportfs.h | 3 ++- support/nfs/exports.c | 4 +++- utils/mountd/mountd.c | 20 ++++++++++++++++++-- utils/mountd/mountd.man | 19 ++++++++++++++++--- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/support/export/cache.c b/support/export/cache.c index 50f7c7a15ceb..c0848c3e437b 100644 --- a/support/export/cache.c +++ b/support/export/cache.c @@ -157,7 +157,7 @@ static void auth_unix_ip(int f) bp = buf; blen = sizeof(buf); qword_add(&bp, &blen, "nfsd"); qword_add(&bp, &blen, ipaddr); - qword_adduint(&bp, &blen, time(0) + DEFAULT_TTL); + qword_adduint(&bp, &blen, time(0) + default_ttl); if (use_ipaddr && client) { memmove(ipaddr + 1, ipaddr, strlen(ipaddr) + 1); ipaddr[0] = '$'; @@ -230,7 +230,7 @@ static void auth_unix_gid(int f) bp = buf; blen = sizeof(buf); qword_adduint(&bp, &blen, uid); - qword_adduint(&bp, &blen, time(0) + DEFAULT_TTL); + qword_adduint(&bp, &blen, time(0) + default_ttl); if (rv >= 0) { qword_adduint(&bp, &blen, ngroups); for (i=0; im_export; dupexportent(&eep, &pseudo_root.m_export); + eep.e_ttl = default_ttl; eep.e_hostname = curexp->e_hostname; strncpy(eep.e_path, path, sizeof(eep.e_path)-1); if (strcmp(path, "/") != 0) diff --git a/support/include/exportfs.h b/support/include/exportfs.h index daa7e2a06d82..81d137210862 100644 --- a/support/include/exportfs.h +++ b/support/include/exportfs.h @@ -105,7 +105,8 @@ typedef struct mexport { } nfs_export; #define HASH_TABLE_SIZE 1021 -#define DEFAULT_TTL (30 * 60) + +extern int default_ttl; typedef struct _exp_hash_entry { nfs_export * p_first; diff --git a/support/nfs/exports.c b/support/nfs/exports.c index 037febd08d9b..2c8f0752ad9d 100644 --- a/support/nfs/exports.c +++ b/support/nfs/exports.c @@ -47,6 +47,8 @@ struct flav_info flav_map[] = { const int flav_map_size = sizeof(flav_map)/sizeof(flav_map[0]); +int default_ttl = 30 * 60; + static char *efname = NULL; static XFILE *efp = NULL; static int first; @@ -100,7 +102,7 @@ static void init_exportent (struct exportent *ee, int fromkernel) ee->e_nsquids = 0; ee->e_nsqgids = 0; ee->e_uuid = NULL; - ee->e_ttl = DEFAULT_TTL; + ee->e_ttl = default_ttl; } struct exportent * diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index b9260aeb86a3..fce389661e7a 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -76,9 +76,10 @@ static struct option longopts[] = { "no-udp", 0, 0, 'u' }, { "log-auth", 0, 0, 'l'}, { "cache-use-ipaddr", 0, 0, 'i'}, + { "ttl", 1, 0, 'T'}, { NULL, 0, 0, 0 } }; -static char shortopts[] = "o:nFd:p:P:hH:N:V:vurs:t:gli"; +static char shortopts[] = "o:nFd:p:P:hH:N:V:vurs:t:gliT:"; #define NFSVERSBIT(vers) (0x1 << (vers - 1)) #define NFSVERSBIT_ALL (NFSVERSBIT(2) | NFSVERSBIT(3) | NFSVERSBIT(4)) @@ -672,6 +673,7 @@ inline static void read_mountd_conf(char **argv) { char *s; + int ttl; conf_init_file(NFS_CONFFILE); @@ -706,6 +708,10 @@ read_mountd_conf(char **argv) else NFSCTL_VERUNSET(nfs_version, vers); } + + ttl = conf_get_num("mountd", "ttl", default_ttl); + if (ttl > 0) + default_ttl = ttl; } int @@ -715,6 +721,7 @@ main(int argc, char **argv) unsigned int listeners = 0; int foreground = 0; int c; + int ttl; struct sigaction sa; struct rlimit rlim; @@ -809,6 +816,15 @@ main(int argc, char **argv) case 'i': use_ipaddr = 2; break; + case 'T': + ttl = atoi(optarg); + if (ttl <= 0) { + fprintf(stderr, "%s: bad ttl number of seconds: %s\n", + argv[0], optarg); + usage(argv[0], 1); + } + default_ttl = ttl; + break; case 0: break; case '?': @@ -924,7 +940,7 @@ usage(const char *prog, int n) { fprintf(stderr, "Usage: %s [-F|--foreground] [-h|--help] [-v|--version] [-d kind|--debug kind]\n" -" [-l|--log-auth] [-i|--cache-use-ipaddr]\n" +" [-l|--log-auth] [-i|--cache-use-ipaddr] [-T|--ttl ttl]\n" " [-o num|--descriptors num]\n" " [-p|--port port] [-V version|--nfs-version version]\n" " [-N version|--no-nfs-version version] [-n|--no-tcp]\n" diff --git a/utils/mountd/mountd.man b/utils/mountd/mountd.man index 44d237e56110..82e07cf221fa 100644 --- a/utils/mountd/mountd.man +++ b/utils/mountd/mountd.man @@ -99,9 +99,10 @@ Turn on debugging. Valid kinds are: all, auth, call, general and parse. .TP .BR \-l " or " \-\-log\-auth Enable logging of responses to authentication and access requests from -nfsd. Each response is then cached by the kernel for 30 minutes, and -will be refreshed after 15 minutes if the relevant client remains -active. +nfsd. Each response is then cached by the kernel for 30 minutes (or as set by +.B \-\-ttl +below), and will be refreshed after 15 minutes (half the ttl time) if +the relevant client remains active. Note that .B -l is equivalent to @@ -135,6 +136,17 @@ log messages produced by the .B -l option easier to read. .TP +.B \-T " or " \-\-ttl +Provide a time-to-live (TTL) for cached information given to the kernel. +The kernel will normally request an update if the information is needed +after half of this time has expired. Increasing the provided number, +which is in seconds, reduces the rate of cache update requests, and this +is particularly noticeable when these requests are logged with +.BR \-l . +However increasing also means that changes to hostname to address +mappings can take longer to be noticed. +The default TTL is 1800 (30 minutes). +.TP .B \-F " or " \-\-foreground Run in foreground (do not daemonize) .TP @@ -269,6 +281,7 @@ section include .BR descriptors , .BR port , .BR threads , +.BR ttl , .BR reverse-lookup ", and" .BR state-directory-path , .B ha-callout