Merge ~ahasenack/ubuntu/+source/samba:jammy-ctdb-nfs-mvp-fixes into ubuntu/+source/samba:ubuntu/devel

Proposed by Andreas Hasenack
Status: Merged
Merged at revision: b7f95dfc7e76d7946589abe99860206092326867
Proposed branch: ~ahasenack/ubuntu/+source/samba:jammy-ctdb-nfs-mvp-fixes
Merge into: ubuntu/+source/samba:ubuntu/devel
Diff against target: 356 lines (+104/-78)
7 files modified
debian/changelog (+18/-0)
debian/ctdb.example.enable.nfs.sh (+22/-32)
debian/ctdb.example.nfs.conf (+20/-0)
debian/ctdb.example.quota (+5/-0)
debian/patches/fix-nfs-service-name-to-nfs-kernel-server.patch (+37/-28)
debian/rules (+2/-2)
dev/null (+0/-16)
Reviewer Review Type Date Requested Status
Miriam España Acebal (community) Approve
Canonical Server Core Reviewers Pending
Review via email: mp+417186@code.launchpad.net

Description of the change

Small, if not minimal, set of changes to make ctdb compatible with the new nfs-utils NFS server/client in jammy. Without these, it still somewhat works, but there are corner cases due to the debian packaging not removing the now obsolete /etc/default/nfs-* config files.

Some remarks:

# quota rpc service
The debian/ubuntu/ quota rpc (rpc.rquotad) service has a quirk that it will scan /etc/fstab and only start if it detects relevant quota mount options. When no such options exist, the service will stop with exit 0. ctdb eventually detects that rpc.rquotad isn't running, and tries to start it again, and this loops forever.
I contacted upstream[1] for a way to signal the scripts that quota isn't mandatory, and there is a series of commits[2] to address that, but too fresh for jammy I think, and somewhat of a feature change. I then went with the workaround that Rafael had used already, which is to not define nfs_rquotad_service, in which case ctdb will try to handle it manually and not via the service command.
For users who know they will really not need rpc.rquotad running, they can then just remove the /etc/ctdb/nfs-checks.d/50.rquotad.check file, and ctdb won't check (nor restart) this quota service anymore.

# the nfs_*_service variables in the nfs-linux-kernel-callout script
The content of those variables, if defined, will be used as the service name in the service command, like "service $nfs_rquotad_service start".
Some nfs services, however, start other services. NFS is that complicated, yes. So if a service variable is not defined, it doesn't really mean it won't be started. They can still be started by the checks, individually. That's what happened with the rpc.rquotad service described above.
The previous version of the fix-nfs-service-name-to-nfs-kernel-server was undefining basically all service variables, and then having the script rely on its own parsing of /etc/default/nfs-* scripts to find out which command line options it should use, and start the services manually. I chose to define the variables instead, so normal systemd units would be used, and no command-line option figuring out is needed, because the daemons all read from /etc/nfs.conf{,.d/*}. The exception being rpc.rquotad, as explained above, but it uses its own config in /etc/default/quota, so not really affected by the nfs-utils config file change.

# nfsconf changes
The meat of this MP. I tried the less invasive alternative for this. I changed Rafael's patch, isntead of creating a new one on top of it with the nfsconf changes. The patch name isn't that great anymore, but I thought renaming the patch would be worse for a review. If you prefer, I can add a patch on top of the original one that just changes the service name.

# ctdb "service" name
There is a mistake in the original patch where it was renaming "nfs" to "nfs-common" or "nfs-kernel-server", but in some cases that was incorrect. The "nfs" key was used for a directory in /var/lib//var/lib/ctdb/scripts/service/<key>, and as a result the previous package, and this one (because I didn't change it) have:

/var/lib/ctdb/scripts/service/nfs
/var/lib/ctdb/scripts/service/nfs-kernel-server

Fixing that now would mean moving state files from nfs-kernel-server into nfs in a maintainer script, and that's too big a change for this MVP branch. As far as I can tell, things are working as they are, fortunately or unfortunately.

# the enable-nfs.sh
This is a script written by Rafael back when he first tackled ctdb in ubuntu and made it work. It came as a result of his work in bug #722201[3] and this discourse post[4]. I changed it for the new nfs-utils version we have, but didn't make other big improvements to the script. Keep in mind it's an example script. It complements and implements parts of the upstream documentation[5].

PPA: https://launchpad.net/~ahasenack/+archive/ubuntu/samba-ctdb-nfs-mvp-fixes/+packages

If you want to test this on your own, get in touch. That discourse post is a start, but there are many details.

1. https://lists.samba.org/archive/samba-technical/2022-March/137176.html
2. https://git.samba.org/?p=martins/samba.git;a=shortlog;h=refs/heads/ctdb-nfs
3. https://bugs.launchpad.net/debian/+source/ctdb/+bug/722201
4. https://discourse.ubuntu.com/t/ctdb-create-a-3-node-nfs-ha-backed-by-a-clustered-filesystem/11608
5. https://wiki.samba.org/index.php/Setting_up_CTDB_for_Clustered_NFS

To post a comment you must log in.
Revision history for this message
Miriam España Acebal (mirespace) wrote :

Hi Andreas,

intense merge proposal! As spoken, I did a review of the code without testing itself, checking for typos or missed things and trying to understand the a bit the logic.

I don't find any strange. At the beginning, the changes around nfs-kernel-server files confuse me a bit because I was seeing service and conf didn't match or removed but after reading carefully your "# ctdb "service" name" I totally agree that is out of the scope of this MP.

Also, I checked that the new files are shipped in the *.deb from your PPA (I've checked what I might have forgotten).

Thanks for this MP.

review: Approve
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Thanks a lot Miriam!

Update scan failed

At least one of the branches involved have failed to scan. You can manually schedule a rescan if required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 7f8f905..88d399e 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,21 @@
6+samba (2:4.15.5~dfsg-0ubuntu3) jammy; urgency=medium
7+
8+ * Update nfs scripts for new nfs.conf config (LP: #1961840):
9+ - d/p/fix-nfs-service-name-to-nfs-kernel-server.patch: updated to use
10+ nfsconf(8) if it's available, instead of parsing the old config
11+ files in /etc/default/nfs-*
12+ - d/ctdb.example.nfs.conf: /etc/nfs.conf to be used by the example
13+ enable-nfs.sh example script
14+ - d/ctdb.example.quota: quota config file to be used by the example
15+ enable-nfs.sh script
16+ - d/ctdb.example.nfs-{common,kernel-server}: obsolete, replaced by
17+ nfs.conf
18+ - d/ctdb.example.enable.nfs.sh: handle new nfs.conf and other
19+ changes in the new nfs server packages
20+ - d/rules: install the new/changed ctdb example nfs files
21+
22+ -- Andreas Hasenack <andreas@canonical.com> Mon, 21 Mar 2022 11:55:54 -0300
23+
24 samba (2:4.15.5~dfsg-0ubuntu2) jammy; urgency=medium
25
26 * d/p/lp-1951490-fix-printing-KB5006743.patch: Fix printing after
27diff --git a/debian/ctdb.example.enable.nfs.sh b/debian/ctdb.example.enable.nfs.sh
28index 2a99074..f719e63 100755
29--- a/debian/ctdb.example.enable.nfs.sh
30+++ b/debian/ctdb.example.enable.nfs.sh
31@@ -19,6 +19,14 @@ backupfile() {
32 [ -f $1 ] && cp $1 $1.prvctdb || true
33 }
34
35+renamefiles() {
36+ for f; do
37+ [ -f "$f" ] || continue
38+ echo "Renaming $f to $f.prvctdb"
39+ mv "$f" "$f".prvctdb
40+ done
41+}
42+
43 checkservice() {
44 (systemctl list-unit-files | grep -q $1.service) || die "service $1 not found"
45 }
46@@ -46,20 +54,6 @@ appendfile() {
47 cat $base/$origfile >> $replfile
48 }
49
50-appendnfsenv() {
51-
52- file=$1 ; [ -f $file ] || die "inexistent file $file";
53-
54- echo appending NFS_HOSTNAME to $file...
55-
56- grep -q "NFS_HOSTNAME" $file || \
57- {
58- echo
59- echo "echo NFS_HOSTNAME=\\\"\$NFS_HOSTNAME\\\"" \>\> \/run\/sysconfig\/nfs-utils
60- echo
61- } >> $file
62-}
63-
64 execnfsenv() {
65
66 file=$1 ; [ -f $file ] || due "inexistent file $file";
67@@ -71,7 +65,7 @@ execnfsenv() {
68
69 fixnfshostname() {
70
71- file=$1 ; [ -f $file ] || due "inexistent file $file";
72+ type nfsconf > /dev/null 2>&1 || die "nfsconf(8) not found"
73
74 if [ "$ghostname" == "" ]; then
75 echo "What is the FQDN for the public IP address of this host ?"
76@@ -79,8 +73,8 @@ fixnfshostname() {
77 read ghostname
78 fi
79
80- echo placing hostname $ghostname into $file...
81- sed -i "s:PLACE_HOSTNAME_HERE:$ghostname:g" $file
82+ echo "Setting $ghostname in nfs.conf..."
83+ nfsconf --set statd name "$ghostname"
84 }
85
86 # end of functions --
87@@ -90,13 +84,14 @@ fixnfshostname() {
88 echo """
89 This script will enable CTDB NFS HA by changing the following files:
90
91-(1) /etc/default/nfs-common ( replace )
92-(2) /etc/default/nfs-kernel-server ( replace )
93+(1) /etc/nfs.conf ( replace )
94+(2) /etc/nfs.conf.d/*.conf ( rename )
95 (3) /etc/services ( append )
96 (4) /etc/sysctl.d/99-nfs-static-ports.conf ( create )
97-(5) /usr/lib/systemd/scripts/nfs-utils_env.sh ( modify )
98+(5) /etc/default/quota ( replace )
99
100-and disabling the following services:
101+and disabling the following services, as they will be managed
102+by ctdb:
103
104 (1) rpcbind
105 (2) nfs-kernel-server
106@@ -124,10 +119,10 @@ checkservice rpcbind
107 echo "requirements okay!"
108 echo
109
110-backupfile /etc/default/nfs-common
111-backupfile /etc/default/nfs-kernel-server
112+backupfile /etc/nfs.conf
113+renamefiles /etc/nfs.conf.d/*.conf
114 backupfile /etc/services
115-backupfile /usr/lib/systemd/scripts/nfs-utils_env.sh
116+backupfile /etc/default/quota
117 echo
118
119 set +e
120@@ -150,20 +145,15 @@ echo
121
122 set -e
123
124-replacefile nfs-common /etc/default/nfs-common
125-replacefile nfs-kernel-server /etc/default/nfs-kernel-server
126+replacefile nfs.conf /etc/nfs.conf
127 replacefile 99-nfs-static-ports.conf /etc/sysctl.d/99-nfs-static-ports.conf
128+replacefile quota /etc/default/quota
129 echo
130
131 appendfile services /etc/services
132 echo
133
134-fixnfshostname /etc/default/nfs-common
135-fixnfshostname /etc/default/nfs-kernel-server
136-echo
137-
138-appendnfsenv /usr/lib/systemd/scripts/nfs-utils_env.sh
139-execnfsenv /usr/lib/systemd/scripts/nfs-utils_env.sh
140+fixnfshostname
141 echo
142
143 sysctlrefresh
144diff --git a/debian/ctdb.example.nfs-common b/debian/ctdb.example.nfs-common
145deleted file mode 100644
146index 9d4f22c..0000000
147--- a/debian/ctdb.example.nfs-common
148+++ /dev/null
149@@ -1,19 +0,0 @@
150-# CTDB: /etc/default/nfs-common for clustering
151-
152-NFS_HOSTNAME="PLACE_HOSTNAME_HERE"
153-
154-# rpc.statd - daemon listening for reboot notifications (locks related)
155-NEED_STATD="yes"
156-STATDOPTS="-n ${NFS_HOSTNAME} -p 32765 -o 32766 -H /etc/ctdb/statd-callout -T 32768 -U 32768"
157-STATD_HOSTNAME="$NFS_HOSTNAME"
158-
159-# rpc.gssd - security context for rpc connections
160-NEED_GSSD="no"
161-
162-# rpc.idmapd - NFSv4 <-> name mapping daemon (fallback nowadays)
163-# recent kernels use nfsidmap(8) instead
164-NEED_IDMAPD="no"
165-
166-# rpc.quota - usage quota
167-RPCRQUOTADOPTS="-p 32769"
168-
169diff --git a/debian/ctdb.example.nfs-kernel-server b/debian/ctdb.example.nfs-kernel-server
170deleted file mode 100644
171index 6aa5df9..0000000
172--- a/debian/ctdb.example.nfs-kernel-server
173+++ /dev/null
174@@ -1,16 +0,0 @@
175-# CTDB: /etc/default/nfs-kernel-server for clustering
176-
177-NFS_HOSTNAME="PLACE_HOSTNAME_HERE"
178-
179-# rpc.nfsd - user level part of nfs service (kernel: nfsd module)
180-RPCNFSDPRIORITY=0
181-RPCNFSDCOUNT=8
182-RPCNFSDOPTS="-N 4"
183-
184-# rpc.mountd - server side of nfs mount protocol
185-RPCMOUNTDOPTS="-p 32767 --manage-gids --no-nfs-version 4"
186-
187-# rpc.svcgssd - userspace daemon to handle sec context for kernel rpcsec_gss
188-NEED_SVCGSSD="no"
189-RPCSVCGSSDOPTS=""
190-
191diff --git a/debian/ctdb.example.nfs.conf b/debian/ctdb.example.nfs.conf
192new file mode 100644
193index 0000000..5cfa13a
194--- /dev/null
195+++ b/debian/ctdb.example.nfs.conf
196@@ -0,0 +1,20 @@
197+[general]
198+pipefs-directory = /run/rpc_pipefs
199+
200+[lockd]
201+port = 32768
202+udp-port = 32768
203+
204+[mountd]
205+manage-gids = 1
206+port = 32767
207+
208+[nfsd]
209+threads = 8
210+vers4 = n
211+
212+[statd]
213+ha-callout = /etc/ctdb/statd-callout
214+name = @NFS_HOSTNAME@
215+outgoing-port = 32766
216+port = 32765
217diff --git a/debian/ctdb.example.quota b/debian/ctdb.example.quota
218new file mode 100644
219index 0000000..00eab66
220--- /dev/null
221+++ b/debian/ctdb.example.quota
222@@ -0,0 +1,5 @@
223+# Set to "true" if warnquota should be run in cron.daily
224+run_warnquota=
225+
226+# Add options to rpc.rquotad here
227+RPCRQUOTADOPTS="-p 32769"
228diff --git a/debian/patches/fix-nfs-service-name-to-nfs-kernel-server.patch b/debian/patches/fix-nfs-service-name-to-nfs-kernel-server.patch
229index 70afeba..0010ab2 100644
230--- a/debian/patches/fix-nfs-service-name-to-nfs-kernel-server.patch
231+++ b/debian/patches/fix-nfs-service-name-to-nfs-kernel-server.patch
232@@ -4,13 +4,15 @@ Subject: fix nfs related service names
233 Upstream defines nfs related service names based on the Linux
234 distribution. This patch fixes the names for Debian and derivatives.
235
236+Update by Andreas Hasenack <andreas@canonical.com> (LP: #1961840):
237+Use nfsconf(8) if it's available, instead of parsing the old config
238+files in /etc/default/nfs-*
239+
240 Bug-Debian: https://bugs.debian.org/929931
241 Bug-Ubuntu: https://bugs.launchpad.net/bugs/722201
242-Last-Update: 2018-08-05
243-Index: samba/ctdb/config/events/legacy/06.nfs.script
244-===================================================================
245---- samba.orig/ctdb/config/events/legacy/06.nfs.script 2020-11-24 18:11:53.506104058 -0500
246-+++ samba/ctdb/config/events/legacy/06.nfs.script 2020-11-24 18:11:53.502104093 -0500
247+Last-Update: 2022-03-16
248+--- a/ctdb/config/events/legacy/06.nfs.script
249++++ b/ctdb/config/events/legacy/06.nfs.script
250 @@ -6,7 +6,7 @@
251
252 . "${CTDB_BASE}/functions"
253@@ -20,11 +22,9 @@ Index: samba/ctdb/config/events/legacy/06.nfs.script
254
255 load_script_options "service" "60.nfs"
256
257-Index: samba/ctdb/config/events/legacy/60.nfs.script
258-===================================================================
259---- samba.orig/ctdb/config/events/legacy/60.nfs.script 2020-11-24 18:11:53.506104058 -0500
260-+++ samba/ctdb/config/events/legacy/60.nfs.script 2020-11-24 18:11:53.502104093 -0500
261-@@ -6,9 +6,9 @@
262+--- a/ctdb/config/events/legacy/60.nfs.script
263++++ b/ctdb/config/events/legacy/60.nfs.script
264+@@ -6,9 +6,11 @@
265
266 . "${CTDB_BASE}/functions"
267
268@@ -32,14 +32,14 @@ Index: samba/ctdb/config/events/legacy/60.nfs.script
269 +service_name="nfs-kernel-server"
270
271 -load_system_config "nfs"
272-+load_system_config "nfs-kernel-server"
273++if ! type nfsconf > /dev/null 2>&1; then
274++ load_system_config "nfs-kernel-server"
275++fi
276
277 load_script_options
278
279-Index: samba/ctdb/config/nfs-linux-kernel-callout
280-===================================================================
281---- samba.orig/ctdb/config/nfs-linux-kernel-callout 2020-11-24 18:11:53.506104058 -0500
282-+++ samba/ctdb/config/nfs-linux-kernel-callout 2020-11-24 18:11:53.502104093 -0500
283+--- a/ctdb/config/nfs-linux-kernel-callout
284++++ b/ctdb/config/nfs-linux-kernel-callout
285 @@ -14,7 +14,7 @@
286
287 # As above, edit the default value below. CTDB_NFS_DISTRO_STYLE is a
288@@ -49,31 +49,40 @@ Index: samba/ctdb/config/nfs-linux-kernel-callout
289
290 case "$nfs_distro_style" in
291 systemd-*)
292-@@ -33,6 +33,14 @@
293+@@ -32,7 +32,22 @@
294+ : # Defaults only
295 ;;
296 *-debian)
297- nfs_rquotad_service="quotarpc"
298-+ nfs_lock_service=""
299-+ nfs_lock_service=""
300-+ nfs_mountd_service=""
301-+ nfs_status_service=""
302+- nfs_rquotad_service="quotarpc"
303++ # XXX
304++ # Undefine nfs_rquotad_services because the quotarpc service won't
305++ # start unless there are specific "quota" mount options in /etc/fstab.
306++ # In this way, we let ctdb start it up manually once the
307++ # /etc/ctdb/nfs-checks.d/50.rquotad.check detects rpc.rquotad isn't
308++ # running.
309++ # Users who really don't want rpc.rquotad running should then move
310++ # the 50.rquotad.check script away.
311 + nfs_rquotad_service=""
312 + nfs_service="nfs-kernel-server"
313-+ nfs_config="/etc/default/nfs-kernel-server"
314++ if type nfsconf >/dev/null 2>&1; then
315++ nfs_config=""
316++ else
317++ nfs_config="/etc/default/nfs-kernel-server"
318++ fi
319 + nfs_rquotad_config="/etc/default/quota"
320 ;;
321 *)
322 echo "Internal error"
323-Index: samba/ctdb/config/statd-callout
324-===================================================================
325---- samba.orig/ctdb/config/statd-callout 2020-11-24 18:11:53.506104058 -0500
326-+++ samba/ctdb/config/statd-callout 2020-11-24 18:11:53.502104093 -0500
327-@@ -29,7 +29,7 @@
328+--- a/ctdb/config/statd-callout
329++++ b/ctdb/config/statd-callout
330+@@ -29,7 +29,9 @@
331 }
332
333 # Try different variables to find config file for NFS_HOSTNAME
334 -load_system_config "nfs" "nfs-common"
335-+load_system_config "nfs-kernel-server"
336++if ! type nfsconf > /dev/null 2>&1; then
337++ load_system_config "nfs-common" "nfs-kernel-server"
338++fi
339
340 # If NFS_HOSTNAME not set then try to pull it out of /etc/nfs.conf
341 if [ -z "$NFS_HOSTNAME" ] && type nfsconf >/dev/null 2>&1 ; then
342diff --git a/debian/rules b/debian/rules
343index 26d2df6..655be1a 100755
344--- a/debian/rules
345+++ b/debian/rules
346@@ -222,8 +222,8 @@ override_dh_installexamples-arch:
347 # CTDB config examples and helper scripts
348 mkdir -p ctdb/doc/examples/nfs-kernel-server
349 cp debian/ctdb.example.enable.nfs.sh ctdb/doc/examples/nfs-kernel-server/enable-nfs.sh
350- cp debian/ctdb.example.nfs-common ctdb/doc/examples/nfs-kernel-server/nfs-common
351- cp debian/ctdb.example.nfs-kernel-server ctdb/doc/examples/nfs-kernel-server/nfs-kernel-server
352+ cp debian/ctdb.example.nfs.conf ctdb/doc/examples/nfs-kernel-server/nfs.conf
353+ cp debian/ctdb.example.quota ctdb/doc/examples/nfs-kernel-server/quota
354 cp debian/ctdb.example.services ctdb/doc/examples/nfs-kernel-server/services
355 cp debian/ctdb.example.sysctl-nfs-static-ports.conf ctdb/doc/examples/nfs-kernel-server/99-nfs-static-ports.conf
356 dh_installexamples

Subscribers

People subscribed via source and target branches