Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit e5cec8c

Browse files
committed
add debug logging. tighten NFS_VERSION regex
1 parent 41d522a commit e5cec8c

File tree

2 files changed

+92
-17
lines changed

2 files changed

+92
-17
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [2.1.1] - unreleased
7+
## [2.2.0] - unreleased
8+
## Added
9+
* Enhanced debugging via environment variable: `NFS_LOG_LEVEL=DEBUG`. This also produces less cluttered log output
10+
during regular, non-debug operation.
811
## Fixed
9-
* `idmapd` was not able to be started when `NFS_VERSION=3`
10-
* `idmapd` isn't required for Kerberos, so don't force the user to provide `idmapd.conf`
12+
* `idmapd` would not start when `NFS_VERSION=3`
13+
* allow Kerberos without `idmapd`. Most users will probably want to run them together, but
14+
it isn't required.
15+
* `NFS_VERSION` environment variable sanity check allowed invalid values
16+
* status code of `rpc.svcgssd` was not properly checked
17+
* `idmapd` debug output was invisible
1118

1219
## [2.1.0] - 2019-10-31
1320
### Added

entrypoint.sh

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly ENV_VAR_NFS_PORT='NFS_PORT'
3232
readonly ENV_VAR_NFS_PORT_STATD_IN='NFS_PORT_STATD_IN'
3333
readonly ENV_VAR_NFS_PORT_STATD_OUT='NFS_PORT_STATD_OUT'
3434
readonly ENV_VAR_NFS_VERSION='NFS_VERSION'
35+
readonly ENV_VAR_NFS_LOG_LEVEL='NFS_LOG_LEVEL'
3536

3637
readonly DEFAULT_NFS_SERVER_THREAD_COUNT="$(grep -Ec ^processor /proc/cpuinfo)"
3738
readonly DEFAULT_NFS_PORT=2049
@@ -150,9 +151,17 @@ stop_mount() {
150151
local -r type=$(basename "$path")
151152

152153
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+
153161
log "un-mounting $type filesystem from $path"
154-
umount -v "$path"
162+
umount "${args[@]}"
155163
on_failure warn "unable to un-mount $type filesystem from $path"
164+
156165
else
157166
log "no active mount at $path"
158167
fi
@@ -167,8 +176,13 @@ stop_nfsd() {
167176

168177
stop_exportfs() {
169178

179+
local args=('-ua')
180+
if is_debug_requested; then
181+
args+=('-v')
182+
fi
183+
170184
log 'un-exporting filesystem(s)'
171-
$PATH_BIN_EXPORTFS -uav
185+
$PATH_BIN_EXPORTFS "${args[@]}"
172186
on_failure warn 'unable to un-export filesystem(s)'
173187
}
174188

@@ -285,6 +299,15 @@ has_linux_capability() {
285299
return 1
286300
}
287301

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+
288311
######################################################################################
289312
### runtime configuration assertions
290313
######################################################################################
@@ -331,7 +354,7 @@ assert_nfs_version() {
331354

332355
local -r requested_version="$(get_requested_nfs_version)"
333356

334-
echo "$requested_version" | grep -Eq '^3|4(\.[1-2])?$'
357+
echo "$requested_version" | grep -Eq '^3$|^4(\.[1-2])?$'
335358
on_failure bail "please set $ENV_VAR_NFS_VERSION to one of: 4.2, 4.1, 4, 3"
336359

337360
if ! is_nfs3_enabled && [[ "$requested_version" = '3' ]]; then
@@ -477,7 +500,11 @@ boot_helper_mount() {
477500

478501
local -r path=$1
479502
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
481508

482509
log "mounting $type filesystem onto $path"
483510
mount "${args[@]}"
@@ -500,6 +527,16 @@ boot_helper_get_version_flags() {
500527
echo "${flags[@]}"
501528
}
502529

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+
}
503540

504541
######################################################################################
505542
### primary boot
@@ -514,8 +551,13 @@ boot_main_mounts() {
514551

515552
boot_main_exportfs() {
516553

554+
local args=('-ar')
555+
if is_debug_requested; then
556+
args+=('-v')
557+
fi
558+
517559
log 'exporting filesystem(s)'
518-
$PATH_BIN_EXPORTFS -arv
560+
$PATH_BIN_EXPORTFS "${args[@]}"
519561
on_failure stop 'exportfs failed'
520562
}
521563

@@ -524,7 +566,10 @@ boot_main_mountd() {
524566
local version_flags
525567
read -r -a version_flags <<< "$(boot_helper_get_version_flags)"
526568
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
528573

529574
# yes, rpc.mountd is required even for NFS v4: https://forums.gentoo.org/viewtopic-p-7724856.html#7724856
530575
log "starting rpc.mountd on port $port"
@@ -544,11 +589,18 @@ boot_main_rpcbind() {
544589

545590
boot_main_idmapd() {
546591

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')
551599
fi
600+
601+
log 'starting idmapd'
602+
$PATH_BIN_IDMAPD "${args[@]}" &
603+
boot_helper_check_backgrounded_process $PATH_BIN_IDMAPD
552604
}
553605

554606
boot_main_statd() {
@@ -572,7 +624,11 @@ boot_main_nfsd() {
572624
read -r -a version_flags <<< "$(boot_helper_get_version_flags)"
573625
local -r threads=$(get_requested_count_nfsd_threads)
574626
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
576632

577633
log "starting rpc.nfsd on port $port with $threads server thread(s)"
578634
$PATH_BIN_NFSD "${args[@]}"
@@ -589,9 +645,14 @@ boot_main_svcgssd() {
589645
return
590646
fi
591647

648+
local args=('-f')
649+
if is_debug_requested; then
650+
args+=('-vvv')
651+
fi
652+
592653
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
595656
}
596657

597658

@@ -630,6 +691,13 @@ summarize_exports() {
630691

631692
log 'list of container exports:'
632693

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+
633701
while read -r export; do
634702

635703
# skip comments and empty lines
@@ -640,7 +708,7 @@ summarize_exports() {
640708
# log it w/out leading and trailing whitespace
641709
log " $(echo -e "$export" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
642710

643-
done < "$PATH_FILE_ETC_EXPORTS"
711+
done < "$file_to_read"
644712
}
645713

646714
summarize_ports() {

0 commit comments

Comments
 (0)