From patchwork Wed Apr 14 18:10:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 12203507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04B0EC433B4 for ; Wed, 14 Apr 2021 18:10:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBBE061179 for ; Wed, 14 Apr 2021 18:10:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbhDNSKq (ORCPT ); Wed, 14 Apr 2021 14:10:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38717 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234410AbhDNSI6 (ORCPT ); Wed, 14 Apr 2021 14:08:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618423715; 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=NgvXjxwHZxyvRYhr8rfe9hAeXuiLeqwKflwN/sJy8eQ=; b=SB21a9BgSLLhec2JZqHiD8YrVVYWg0+9rhq8JExVt8gbL6AWyzO93Q1B/vjZ/7j9K/9+2g EWdRgK070VCajiAbe0VawNYuHIUWy8eKxE/pb5tm/y/zlyFZWT9qf/91kPfbFp7zdb9ux+ EZG3PXqnaViCtTFKwiJuGr22KQ6i9Nw= 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-201-vZX0n6D3NFC5M-EyDHVRVg-1; Wed, 14 Apr 2021 14:08:33 -0400 X-MC-Unique: vZX0n6D3NFC5M-EyDHVRVg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0669F107ACCD for ; Wed, 14 Apr 2021 18:08:33 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-83.phx2.redhat.com [10.3.112.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id B67DD60862 for ; Wed, 14 Apr 2021 18:08:32 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 1/3] nfs-utils: Enable the retrieval of raw config settings without expansion Date: Wed, 14 Apr 2021 14:10:38 -0400 Message-Id: <20210414181040.7108-2-steved@redhat.com> In-Reply-To: <20210414181040.7108-1-steved@redhat.com> References: <20210414181040.7108-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Alice Mitchell Config entries sometimes contain variable expansions, this adds options to retrieve the config entry rather than its current expanded value. Signed-off-by: Alice Mitchell Signed-off-by: Steve Dickson --- support/include/conffile.h | 1 + support/nfs/conffile.c | 23 +++++++++++++++++++++++ tools/nfsconf/nfsconf.man | 10 +++++++++- tools/nfsconf/nfsconfcli.c | 22 ++++++++++++++++------ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/support/include/conffile.h b/support/include/conffile.h index 7d974fe9..c4a3ca62 100644 --- a/support/include/conffile.h +++ b/support/include/conffile.h @@ -61,6 +61,7 @@ extern _Bool conf_get_bool(const char *, const char *, _Bool); extern char *conf_get_str(const char *, const char *); extern char *conf_get_str_with_def(const char *, const char *, char *); extern char *conf_get_section(const char *, const char *, const char *); +extern char *conf_get_entry(const char *, const char *, const char *); extern int conf_init_file(const char *); extern void conf_cleanup(void); extern int conf_match_num(const char *, const char *, int); diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 1e15e7d5..fd4a17ad 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -891,6 +891,29 @@ conf_get_str_with_def(const char *section, const char *tag, char *def) return result; } +/* + * Retrieve an entry without interpreting its contents + */ +char * +conf_get_entry(const char *section, const char *arg, const char *tag) +{ + struct conf_binding *cb; + + cb = LIST_FIRST (&conf_bindings[conf_hash (section)]); + for (; cb; cb = LIST_NEXT (cb, link)) { + if (strcasecmp(section, cb->section) != 0) + continue; + if (arg && (cb->arg == NULL || strcasecmp(arg, cb->arg) != 0)) + continue; + if (!arg && cb->arg) + continue; + if (strcasecmp(tag, cb->tag) != 0) + continue; + return cb->value; + } + return 0; +} + /* * Find a section that may or may not have an argument */ diff --git a/tools/nfsconf/nfsconf.man b/tools/nfsconf/nfsconf.man index 30791988..d44e86fb 100644 --- a/tools/nfsconf/nfsconf.man +++ b/tools/nfsconf/nfsconf.man @@ -11,6 +11,12 @@ nfsconf \- Query various NFS configuration settings .IR infile.conf ] .RI [ outfile ] .P +.B nfsconf \-\-entry +.RB [ \-\-arg +.IR subsection] +.IR section +.IR tag +.P .B nfsconf \-\-get .RB [ \-v | \-\-verbose ] .RB [ \-f | \-\-file @@ -58,6 +64,8 @@ from a range of nfs-utils configuration files. The following modes are available: .IP "\fB\-d, \-\-dump\fP" Output an alphabetically sorted dump of the current configuration in conf file format. Accepts an optional filename in which to write the output. +.IP "\fB\-e, \-\-entry\fP" +retrieve the config entry rather than its current expanded value .IP "\fB\-i, \-\-isset\fP" Test if a specific tag has a value set. .IP "\fB\-g, \-\-get\fP" @@ -75,7 +83,7 @@ Increase verbosity and print debugging information. .B \-f, \-\-file \fIinfile\fR Select a different config file to operate upon, default is .I /etc/nfs.conf -.SS Options only valid in \fB\-\-get\fR and \fB\-\-isset\fR modes. +.SS Options only valid in \fB\-\-entry\fR and \fB\-\-get\fR and \fB\-\-isset\fR modes. .TP .B \-a, \-\-arg \fIsubsection\fR Select a specific sub-section diff --git a/tools/nfsconf/nfsconfcli.c b/tools/nfsconf/nfsconfcli.c index 361d386e..b2ef96d1 100644 --- a/tools/nfsconf/nfsconfcli.c +++ b/tools/nfsconf/nfsconfcli.c @@ -11,6 +11,7 @@ typedef enum { MODE_NONE, MODE_GET, + MODE_ENTRY, MODE_ISSET, MODE_DUMP, MODE_SET, @@ -30,6 +31,8 @@ static void usage(const char *name) fprintf(stderr, " Outputs the configuration to the named file\n"); fprintf(stderr, " --get [--arg subsection] {section} {tag}\n"); fprintf(stderr, " Output one specific config value\n"); + fprintf(stderr, " --entry [--arg subsection] {section} {tag}\n"); + fprintf(stderr, " Output the uninterpreted config entry\n"); fprintf(stderr, " --isset [--arg subsection] {section} {tag}\n"); fprintf(stderr, " Return code indicates if config value is present\n"); fprintf(stderr, " --set [--arg subsection] {section} {tag} {value}\n"); @@ -55,6 +58,7 @@ int main(int argc, char **argv) int index = 0; struct option long_options[] = { {"get", no_argument, 0, 'g' }, + {"entry", no_argument, 0, 'e' }, {"set", no_argument, 0, 's' }, {"unset", no_argument, 0, 'u' }, {"arg", required_argument, 0, 'a' }, @@ -66,7 +70,7 @@ int main(int argc, char **argv) {NULL, 0, 0, 0 } }; - c = getopt_long(argc, argv, "gsua:id::f:vm:", long_options, &index); + c = getopt_long(argc, argv, "gesua:id::f:vm:", long_options, &index); if (c == -1) break; switch (c) { @@ -86,6 +90,9 @@ int main(int argc, char **argv) case 'g': mode = MODE_GET; break; + case 'e': + mode = MODE_ENTRY; + break; case 's': mode = MODE_SET; break; @@ -167,8 +174,8 @@ int main(int argc, char **argv) if (dumpfile) fclose(out); } else - /* --iset and --get share a lot of code */ - if (mode == MODE_GET || mode == MODE_ISSET) { + /* --isset and --get share a lot of code */ + if (mode == MODE_GET || mode == MODE_ISSET || mode == MODE_ENTRY) { char * section = NULL; char * tag = NULL; const char * val; @@ -186,14 +193,17 @@ int main(int argc, char **argv) tag = argv[optind++]; /* retrieve the specified tags value */ - val = conf_get_section(section, arg, tag); + if (mode == MODE_ENTRY) + val = conf_get_entry(section, arg, tag); + else + val = conf_get_section(section, arg, tag); if (val != NULL) { /* ret=0, success, mode --get wants to output the value as well */ - if (mode == MODE_GET) + if (mode != MODE_ISSET) printf("%s\n", val); } else { /* ret=1, no value found, tell the user if they asked */ - if (mode == MODE_GET && verbose) + if (mode != MODE_ISSET && verbose) fprintf(stderr, "Tag '%s' not found\n", tag); ret = 1; } From patchwork Wed Apr 14 18:10:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 12203501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2734C433ED for ; Wed, 14 Apr 2021 18:09:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDE1161153 for ; Wed, 14 Apr 2021 18:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351719AbhDNSJA (ORCPT ); Wed, 14 Apr 2021 14:09:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36249 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234472AbhDNSI7 (ORCPT ); Wed, 14 Apr 2021 14:08:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618423717; 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=TsouOU8zyOOx+wxkCbPTK0hBOcc15DhOMQfLZVoHO2g=; b=eFW03uva37Sgd81wrGzkYp2zNQbR4TFagkX8hyGtYZfpJ52Nr/Qv9IwmOTFM97aBqb6rps 1lw54vuDZmprjyVa3oQBEoK2gexSowI+9/s1xtTEe7d72/DZVJo5Zm+9NOk8iuqb+Jbqkm Cb92omBHg2xEHhjWneZIeJaW9u36F8U= 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-223-vxF9mEIeMGCwAnrviJT-Wg-1; Wed, 14 Apr 2021 14:08:34 -0400 X-MC-Unique: vxF9mEIeMGCwAnrviJT-Wg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BADB801814 for ; Wed, 14 Apr 2021 18:08:33 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-83.phx2.redhat.com [10.3.112.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29E0860862 for ; Wed, 14 Apr 2021 18:08:33 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 2/3] nfs-utils: Add support for further ${variable} expansions in nfs.conf Date: Wed, 14 Apr 2021 14:10:39 -0400 Message-Id: <20210414181040.7108-3-steved@redhat.com> In-Reply-To: <20210414181040.7108-1-steved@redhat.com> References: <20210414181040.7108-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Alice Mitchell This adds support for substituting in the systems machine_id or the hostname as the unique id, and caches the results Signed-off-by: Alice Mitchell Signed-off-by: Steve Dickson --- support/nfs/conffile.c | 260 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 249 insertions(+), 11 deletions(-) diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index fd4a17ad..d03de012 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -114,12 +115,66 @@ struct conf_binding { char *tag; char *value; int is_default; + char *cache; }; LIST_HEAD (conf_bindings, conf_binding) conf_bindings[256]; +typedef char * (*expand_fn_t)(void); +struct expansion_types { + const char *name; + expand_fn_t func; +}; + +typedef struct { + uint8_t bytes[16]; +} id128_t; + +/* + * Application ID for use with generating a machine-id string + */ +static id128_t nfs_appid = {.bytes = {0xff,0x3b,0xf0,0x0f,0x34,0xa6,0x43,0xc5, \ + 0x93,0xdd,0x16,0xdc,0x7c,0xeb,0x88,0xc8}}; + const char *modified_by = NULL; +static __inline__ char +hexchar(int x) { + static const char table[16] = "0123456789abcdef"; + return table[x & 15]; +} + +static __inline__ int +unhexchar(char h) +{ + if (h >= '0' && h <= '9') + return h - '0'; + if (h >= 'a' && h <= 'f') + return h - 'a' + 10; + if (h >= 'A' && h <= 'F') + return h - 'A' + 10; + return -1; +} + +static char * +tohexstr(const unsigned char *data, int len) +{ + int i; + char *result = NULL; + + result = calloc(1, (len*2)+1); + if (!result) { + xlog(L_ERROR, "malloc error formatting string"); + return NULL; + } + + for (i = 0; i < len; i++) { + result[i*2] = hexchar(data[i] >> 4); + result[i*2+1] = hexchar(data[i] & 0x0F); + } + return result; +} + static __inline__ uint8_t conf_hash(const char *s) { @@ -132,6 +187,193 @@ conf_hash(const char *s) return hash; } +static int +id128_from_string(const char s[], id128_t *ret) +{ + id128_t t; + unsigned int n, i; + for (n=0, i=0; n<16; ) { + int a, b; + a = unhexchar(s[i++]); + if (a < 0) + return 1; + b = unhexchar(s[i++]); + if (b < 0) + return 1; + + t.bytes[n++] = (a << 4) | b; + } + if (s[i] != 0) + return 1; + if (ret) + *ret = t; + return 0; +} + +/* + * cryptographic hash (sha256) data into a hex encoded string + */ +static char * +strhash(unsigned char *key, size_t keylen, unsigned char *data, size_t dlen) +{ + union { + struct sockaddr sa; + struct sockaddr_alg alg; + } sa; + int sock = -1; + int hfd = -1; + uint8_t digest[129]; + int n; + char *result = NULL; + + memset(&sa, 0, sizeof(sa)); + sa.alg.salg_family = AF_ALG; + strcpy((char *)sa.alg.salg_type, "hash"); + strcpy((char *)sa.alg.salg_name, "hmac(sha256)"); + + sock = socket(AF_ALG, SOCK_SEQPACKET|SOCK_CLOEXEC, 0); + if (sock < 0) { + xlog(L_ERROR, "error creating socket"); + goto cleanup; + } + + if (bind(sock, (struct sockaddr *)&sa.sa, sizeof(sa)) < 0) { + xlog(L_ERROR, "error opening khash interface"); + goto cleanup; + } + + if (key && keylen > 0) { + if (setsockopt(sock, SOL_ALG, ALG_SET_KEY, key, keylen) < 0) { + xlog(L_ERROR, "Error setting key: %s", strerror(errno)); + goto cleanup; + } + } + + hfd = accept4(sock, NULL, 0, SOCK_CLOEXEC); + if (hfd < 0) { + xlog(L_ERROR, "Error initiating khash: %s", strerror(errno)); + goto cleanup; + } + + n = send(hfd, data, dlen, 0); + if (n < 0) { + xlog(L_ERROR, "Error updating khash: %s", strerror(errno)); + goto cleanup; + } + + n = recv(hfd, digest, sizeof(digest), 0); + if (n < 0) { + xlog(L_ERROR, "Error fetching khash: %s", strerror(errno)); + goto cleanup; + } + + result = tohexstr(digest, n); +cleanup: + if (sock != -1) + close(sock); + if (hfd != -1) + close(hfd); + if (hfd != -1) + close(hfd); + + return result; +} + +/* + * Read one line of content from a file + */ +static char * +read_oneline(const char *filename) +{ + char *content = conf_readfile(filename); + char *end; + + if (content == NULL) + return NULL; + + /* trim to only the first line */ + end = strchr(content, '\n'); + if (end != NULL) + *end = '\0'; + end = strchr(content, '\r'); + if (end != NULL) + *end = '\0'; + + return content; +} + +static char * +expand_machine_id(void) +{ + char *key = read_oneline("/etc/machine-id"); + id128_t mid; + char * result = NULL; + size_t idlen = 0; + + if (key == NULL) + return NULL; + + idlen = strlen(key); + if (!id128_from_string(key, &mid)) { + result = strhash(mid.bytes, sizeof(mid), nfs_appid.bytes, sizeof(nfs_appid)); + if (result && strlen(result) > idlen) + result[idlen]=0; + } + free(key); + return result; +} + +static char * +expand_hostname(void) +{ + int maxlen = HOST_NAME_MAX + 1; + char * hostname = calloc(1, maxlen); + + if (!hostname) + return NULL; + if ((gethostname(hostname, maxlen)) == -1) { + free(hostname); + return NULL; + } + return hostname; +} + +static struct expansion_types var_expansions[] = { + { "machine-id", expand_machine_id }, + { "hostname", expand_hostname }, +}; + +/* Deal with more complex variable substitutions */ +static char * +expand_variable(const char *name) +{ + size_t len; + + if (name == NULL || name[0] != '$') + return NULL; + + len = strlen(name); + if (name[1] == '{' && name[len-1] == '}') { + char *varname = strndupa(&name[2], len-3); + + for (size_t i=0; itag); if (cb->value) free(cb->value); + if (cb->cache) + free(cb->cache); free(cb); } @@ -921,7 +1165,7 @@ char * conf_get_section(const char *section, const char *arg, const char *tag) { struct conf_binding *cb; -retry: + cb = LIST_FIRST (&conf_bindings[conf_hash (section)]); for (; cb; cb = LIST_NEXT (cb, link)) { if (strcasecmp(section, cb->section) != 0) @@ -933,19 +1177,13 @@ retry: if (strcasecmp(tag, cb->tag) != 0) continue; if (cb->value[0] == '$') { - /* expand $name from [environment] section, - * or from environment - */ - char *env = getenv(cb->value+1); - if (env && *env) - return env; - section = "environment"; - tag = cb->value + 1; - goto retry; + if (!cb->cache) + cb->cache = expand_variable(cb->value); + return cb->cache; } return cb->value; } - return 0; + return NULL; } /* From patchwork Wed Apr 14 18:10:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 12203503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CFE2C433B4 for ; Wed, 14 Apr 2021 18:09:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 717C161179 for ; Wed, 14 Apr 2021 18:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbhDNSJq (ORCPT ); Wed, 14 Apr 2021 14:09:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48932 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351728AbhDNSJD (ORCPT ); Wed, 14 Apr 2021 14:09:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618423721; 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=jsnJj+9/9XbK0c0AA4WngcXNll8DiPUseToJ3rpbxjw=; b=fR9lyWyibRIO/2p/PQqTarjSE5zi0+Qy00wOdJPRHytAlk01UmKB9rQrDLxKbKSZ9W9VBs kZdIb+qjVSrcwefhHUF6rU/oK4WpRzQcLz50JtIHovwjHhovdUA7Pe3TcjRVsNuQcmTqnG jlsyNmBuiDRllAAcPbJ+FTCZ7gAbef4= 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-398-yrrpW3oLNfmRsrgtEQO0AA-1; Wed, 14 Apr 2021 14:08:34 -0400 X-MC-Unique: yrrpW3oLNfmRsrgtEQO0AA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D38A410054F6 for ; Wed, 14 Apr 2021 18:08:33 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-83.phx2.redhat.com [10.3.112.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FA3760862 for ; Wed, 14 Apr 2021 18:08:33 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 3/3] nfs-utils: Update nfs4_unique_id module parameter from the nfs.conf value Date: Wed, 14 Apr 2021 14:10:40 -0400 Message-Id: <20210414181040.7108-4-steved@redhat.com> In-Reply-To: <20210414181040.7108-1-steved@redhat.com> References: <20210414181040.7108-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Alice Mitchell systemd service to grab the config value and feed it to the kernel module Signed-off-by: Alice Mitchell Signed-off-by: Steve Dickson --- configure.ac | 1 + nfs.conf | 4 +++- systemd/Makefile.am | 3 +++ systemd/nfs-client.target | 3 +++ systemd/nfs-conf-export.sh | 28 ++++++++++++++++++++++++++++ systemd/nfs-config.service.in | 18 ++++++++++++++++++ systemd/nfs.conf.man | 19 ++++++++++++++++++- 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100755 systemd/nfs-conf-export.sh create mode 100644 systemd/nfs-config.service.in diff --git a/configure.ac b/configure.ac index f2e1bd30..2db7214e 100644 --- a/configure.ac +++ b/configure.ac @@ -684,6 +684,7 @@ AC_CONFIG_COMMANDS_PRE([eval eval _sysconfdir=$sysconfdir]) AC_CONFIG_FILES([ Makefile systemd/rpc-gssd.service + systemd/nfs-config.service linux-nfs/Makefile support/Makefile support/export/Makefile diff --git a/nfs.conf b/nfs.conf index 31994f61..faa58071 100644 --- a/nfs.conf +++ b/nfs.conf @@ -1,9 +1,11 @@ # # This is a general configuration for the -# NFS daemons and tools +# NFS daemons and tools and kernel module parameters # [general] # pipefs-directory=/var/lib/nfs/rpc_pipefs +[kernel] +# nfs4_unique_id = [${machine-id} || ${hostname}] # [exports] # rootdir=/export diff --git a/systemd/Makefile.am b/systemd/Makefile.am index 650ad25c..c48fc80d 100644 --- a/systemd/Makefile.am +++ b/systemd/Makefile.am @@ -9,6 +9,7 @@ unit_files = \ nfs-mountd.service \ nfs-server.service \ nfs-utils.service \ + nfs-config.service \ rpc-statd-notify.service \ rpc-statd.service \ \ @@ -75,4 +76,6 @@ genexec_PROGRAMS = nfs-server-generator rpc-pipefs-generator install-data-hook: $(unit_files) mkdir -p $(DESTDIR)/$(unitdir) cp $(unit_files) $(DESTDIR)/$(unitdir) + mkdir -p $(DESTDIR)/$(libexecdir)/nfs-utils + install nfs-conf-export.sh $(DESTDIR)/$(libexecdir)/nfs-utils/ endif diff --git a/systemd/nfs-client.target b/systemd/nfs-client.target index 8a8300a1..3ca45752 100644 --- a/systemd/nfs-client.target +++ b/systemd/nfs-client.target @@ -11,6 +11,9 @@ Wants=rpc-statd-notify.service Wants=auth-rpcgss-module.service After=rpc-gssd.service rpc-svcgssd.service gssproxy.service +# Run the config settings that are in nfs.conf +After=nfs-config.service + [Install] WantedBy=multi-user.target WantedBy=remote-fs.target diff --git a/systemd/nfs-conf-export.sh b/systemd/nfs-conf-export.sh new file mode 100755 index 00000000..905ece1b --- /dev/null +++ b/systemd/nfs-conf-export.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# This script pulls values out of /etc/nfs.conf and configures +# the appropriate kernel modules which cannot read it directly + +NFSMOD=/sys/module/nfs/parameters/nfs4_unique_id +NFSPROBE=/etc/modprobe.d/nfs.conf + +# Now read the values from nfs.conf +MACHINEID=`nfsconf --get kernel nfs4_unique_id` +if [ $? -ne 0 ] || [ "$MACHINEID" == "" ] +then +# No config value found, nothing to do + exit 0 +fi + +# Kernel module is already loaded, update the live one +if [ -e $NFSMOD ]; then +echo -n "$MACHINEID" >> $NFSMOD +fi + +# Rewrite the modprobe file for next reboot +echo "# This file is overwritten by systemd nfs-config.service" > $NFSPROBE +echo "# with values taken from /etc/nfs.conf" >> $NFSPROBE +echo "# Do not hand modify" >> $NFSPROBE +echo "options nfs nfs4_unique_id=\"$MACHINEID\"" >> $NFSPROBE + +echo "Set to: $MACHINEID" diff --git a/systemd/nfs-config.service.in b/systemd/nfs-config.service.in new file mode 100644 index 00000000..08a09a5c --- /dev/null +++ b/systemd/nfs-config.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Preprocess NFS configuration +PartOf=nfs-client.target +Before=nfs-client.target +After=local-fs.target +DefaultDependencies=no + +[Service] +Type=oneshot +# This service needs to run any time any nfs service +# is started, so changes to local config files get +# incorporated. Having "RemainAfterExit=no" (the default) +# ensures this happens. +RemainAfterExit=no +ExecStart=/usr/libexec/nfs-utils/nfs-conf-export.sh + +[Install] +WantedBy=nfs-client.target diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index 4436a38a..8f073fe5 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -101,7 +101,7 @@ When a list is given, the members should be comma-separated. .TP .B general Recognized values: -.BR pipefs-directory . +.BR pipefs-directory. See .BR blkmapd (8), @@ -148,6 +148,23 @@ is equivalent to providing the .B \-\-log\-auth option. +.TP +.B kernel +.br +Recognized value: +.BR nfs4_unique_id . + +Setting +.B "nfs4_unique_id= ${machine-id}" +will set the nfs4_unique_id kernel module parameter +to the systems machine_id (/etc/machine-id) +.BR + +Setting +.BR "nfs4_unique_id= ${hostname}" +will set the nfs4_unique_id kernel module parameter +to the systems hostname (/etc/hostname) + .TP .B nfsdcltrack Recognized values: