@@ -32,6 +32,7 @@ readonly ENV_VAR_NFS_PORT='NFS_PORT'
32
32
readonly ENV_VAR_NFS_PORT_STATD_IN=' NFS_PORT_STATD_IN'
33
33
readonly ENV_VAR_NFS_PORT_STATD_OUT=' NFS_PORT_STATD_OUT'
34
34
readonly ENV_VAR_NFS_VERSION=' NFS_VERSION'
35
+ readonly ENV_VAR_NFS_LOG_LEVEL=' NFS_LOG_LEVEL'
35
36
36
37
readonly DEFAULT_NFS_SERVER_THREAD_COUNT=" $( grep -Ec ^processor /proc/cpuinfo) "
37
38
readonly DEFAULT_NFS_PORT=2049
@@ -150,9 +151,17 @@ stop_mount() {
150
151
local -r type=$( basename " $path " )
151
152
152
153
if mount | grep -Eq ^" $type on $path \\ s+" ; then
154
+
155
+ local args=()
156
+ if is_debug_requested; then
157
+ args+=(' -v' )
158
+ fi
159
+ args+=(" $path " )
160
+
153
161
log " un-mounting $type filesystem from $path "
154
- umount -v " $path "
162
+ umount " ${args[@]} "
155
163
on_failure warn " unable to un-mount $type filesystem from $path "
164
+
156
165
else
157
166
log " no active mount at $path "
158
167
fi
@@ -167,8 +176,13 @@ stop_nfsd() {
167
176
168
177
stop_exportfs () {
169
178
179
+ local args=(' -ua' )
180
+ if is_debug_requested; then
181
+ args+=(' -v' )
182
+ fi
183
+
170
184
log ' un-exporting filesystem(s)'
171
- $PATH_BIN_EXPORTFS -uav
185
+ $PATH_BIN_EXPORTFS " ${args[@]} "
172
186
on_failure warn ' unable to un-export filesystem(s)'
173
187
}
174
188
@@ -285,6 +299,15 @@ has_linux_capability() {
285
299
return 1
286
300
}
287
301
302
+ is_debug_requested () {
303
+
304
+ if echo " ${! ENV_VAR_NFS_LOG_LEVEL} " | grep -Eqi ' ^DEBUG$' ; then
305
+ return 0
306
+ fi
307
+
308
+ return 1
309
+ }
310
+
288
311
# #####################################################################################
289
312
# ## runtime configuration assertions
290
313
# #####################################################################################
@@ -331,7 +354,7 @@ assert_nfs_version() {
331
354
332
355
local -r requested_version=" $( get_requested_nfs_version) "
333
356
334
- echo " $requested_version " | grep -Eq ' ^3| 4(\.[1-2])?$'
357
+ echo " $requested_version " | grep -Eq ' ^3$|^ 4(\.[1-2])?$'
335
358
on_failure bail " please set $ENV_VAR_NFS_VERSION to one of: 4.2, 4.1, 4, 3"
336
359
337
360
if ! is_nfs3_enabled && [[ " $requested_version " = ' 3' ]]; then
@@ -477,7 +500,11 @@ boot_helper_mount() {
477
500
478
501
local -r path=$1
479
502
local -r type=$( basename " $path " )
480
- local -r args=(' -vt' " $type " " $path " )
503
+ local args=(' -t' " $type " " $path " )
504
+
505
+ if is_debug_requested; then
506
+ args+=(' -vvv' )
507
+ fi
481
508
482
509
log " mounting $type filesystem onto $path "
483
510
mount " ${args[@]} "
@@ -500,6 +527,16 @@ boot_helper_get_version_flags() {
500
527
echo " ${flags[@]} "
501
528
}
502
529
530
+ boot_helper_check_backgrounded_process () {
531
+
532
+ local -r bg_pid=$!
533
+
534
+ # somewhat arbitrary assumption that if the process isn't dead already, it will die within 1/20 of a second. for our
535
+ # purposes this works just fine, but if someone has a better solution please open a PR.
536
+ sleep .05
537
+ kill -0 $bg_pid 2> /dev/null
538
+ on_failure stop " $1 failed"
539
+ }
503
540
504
541
# #####################################################################################
505
542
# ## primary boot
@@ -514,8 +551,13 @@ boot_main_mounts() {
514
551
515
552
boot_main_exportfs () {
516
553
554
+ local args=(' -ar' )
555
+ if is_debug_requested; then
556
+ args+=(' -v' )
557
+ fi
558
+
517
559
log ' exporting filesystem(s)'
518
- $PATH_BIN_EXPORTFS -arv
560
+ $PATH_BIN_EXPORTFS " ${args[@]} "
519
561
on_failure stop ' exportfs failed'
520
562
}
521
563
@@ -524,7 +566,10 @@ boot_main_mountd() {
524
566
local version_flags
525
567
read -r -a version_flags <<< " $(boot_helper_get_version_flags)"
526
568
local -r port=$( get_requested_port_mountd)
527
- local -r args=(' --debug' ' all' ' --port' " $port " " ${version_flags[@]} " )
569
+ local args=(' --port' " $port " " ${version_flags[@]} " )
570
+ if is_debug_requested; then
571
+ args+=(' --debug' ' all' )
572
+ fi
528
573
529
574
# yes, rpc.mountd is required even for NFS v4: https://forums.gentoo.org/viewtopic-p-7724856.html#7724856
530
575
log " starting rpc.mountd on port $port "
@@ -544,11 +589,18 @@ boot_main_rpcbind() {
544
589
545
590
boot_main_idmapd () {
546
591
547
- if is_idmapd_requested; then
548
- log ' starting idmapd'
549
- $PATH_BIN_IDMAPD -v -S
550
- on_failure stop ' idmapd failed'
592
+ if ! is_idmapd_requested; then
593
+ return
594
+ fi
595
+
596
+ local args=(' -f -S' )
597
+ if is_debug_requested; then
598
+ args+=(' -vvv' )
551
599
fi
600
+
601
+ log ' starting idmapd'
602
+ $PATH_BIN_IDMAPD " ${args[@]} " &
603
+ boot_helper_check_backgrounded_process $PATH_BIN_IDMAPD
552
604
}
553
605
554
606
boot_main_statd () {
@@ -572,7 +624,11 @@ boot_main_nfsd() {
572
624
read -r -a version_flags <<< " $(boot_helper_get_version_flags)"
573
625
local -r threads=$( get_requested_count_nfsd_threads)
574
626
local -r port=$( get_requested_port_nfsd)
575
- local -r args=(' --debug' 8 ' --tcp' ' --udp' ' --port' " $port " " ${version_flags[@]} " " $threads " )
627
+ local args=(' --tcp' ' --udp' ' --port' " $port " " ${version_flags[@]} " " $threads " )
628
+
629
+ if is_debug_requested; then
630
+ args+=(' --debug' )
631
+ fi
576
632
577
633
log " starting rpc.nfsd on port $port with $threads server thread(s)"
578
634
$PATH_BIN_NFSD " ${args[@]} "
@@ -589,9 +645,14 @@ boot_main_svcgssd() {
589
645
return
590
646
fi
591
647
648
+ local args=(' -f' )
649
+ if is_debug_requested; then
650
+ args+=(' -vvv' )
651
+ fi
652
+
592
653
log ' starting rpc.svcgssd'
593
- $PATH_BIN_RPC_SVCGSSD -f &
594
- on_failure stop ' rpc.svcgssd failed '
654
+ $PATH_BIN_RPC_SVCGSSD " ${args[@]} " &
655
+ boot_helper_check_backgrounded_process $PATH_BIN_RPC_SVCGSSD
595
656
}
596
657
597
658
@@ -630,6 +691,13 @@ summarize_exports() {
630
691
631
692
log ' list of container exports:'
632
693
694
+ # if debug is enabled, read /var/lib/nfs/etab as it contains the "real" export data. but it also contains more
695
+ # information that most people will usually need to see
696
+ local file_to_read=" $PATH_FILE_ETC_EXPORTS "
697
+ if is_debug_requested; then
698
+ file_to_read=' /var/lib/nfs/etab'
699
+ fi
700
+
633
701
while read -r export ; do
634
702
635
703
# skip comments and empty lines
@@ -640,7 +708,7 @@ summarize_exports() {
640
708
# log it w/out leading and trailing whitespace
641
709
log " $( echo -e " $export " | sed -e ' s/^[[:space:]]*//' -e ' s/[[:space:]]*$//' ) "
642
710
643
- done < " $PATH_FILE_ETC_EXPORTS "
711
+ done < " $file_to_read "
644
712
}
645
713
646
714
summarize_ports () {
0 commit comments