linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Dickson <steved@redhat.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
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	[thread overview]
Message-ID: <20210414181040.7108-4-steved@redhat.com> (raw)
In-Reply-To: <20210414181040.7108-1-steved@redhat.com>

From: Alice Mitchell <ajmitchell@redhat.com>

systemd service to grab the config value and feed it to the kernel module

Signed-off-by: Alice Mitchell <ajmitchell@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
---
 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:
-- 
2.30.2


  parent reply	other threads:[~2021-04-14 18:09 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 18:10 [PATCH 0/3] Enable the setting of a kernel module parameter from nfs.conf Steve Dickson
2021-04-14 18:10 ` [PATCH 1/3] nfs-utils: Enable the retrieval of raw config settings without expansion Steve Dickson
2021-05-06 17:29   ` Steve Dickson
2021-04-14 18:10 ` [PATCH 2/3] nfs-utils: Add support for further ${variable} expansions in nfs.conf Steve Dickson
2021-04-14 18:10 ` Steve Dickson [this message]
2021-04-14 23:26 ` [PATCH 0/3] Enable the setting of a kernel module parameter from nfs.conf Chuck Lever III
2021-04-15 15:33   ` Steve Dickson
2021-04-15 16:37     ` Chuck Lever III
2021-04-15 23:30       ` Trond Myklebust
2021-04-16  0:40         ` Trond Myklebust
2021-04-17 16:33           ` Steve Dickson
2021-04-17 18:09             ` Trond Myklebust
2021-04-17 16:18       ` Steve Dickson
2021-04-17 16:36         ` Chuck Lever III
2021-04-17 17:50           ` Steve Dickson
2021-04-18 16:51             ` Chuck Lever III
2021-04-20 13:11               ` Steve Dickson
2021-04-20 14:09                 ` Chuck Lever III
2021-04-20 14:31                   ` Trond Myklebust
2021-04-20 17:18                     ` J. Bruce Fields
2021-04-20 17:28                       ` Trond Myklebust
2021-04-20 17:40                         ` bfields
2021-04-20 17:53                           ` Trond Myklebust
2021-04-20 18:16                             ` bfields
2021-04-20 19:30                               ` Steve Dickson
2021-04-20 18:47                     ` Steve Dickson
2021-04-20 18:26                   ` Steve Dickson
2021-05-13  0:29     ` NeilBrown
2021-05-18 12:38       ` Steve Dickson
2021-05-21  2:39         ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210414181040.7108-4-steved@redhat.com \
    --to=steved@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).