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

Commit bc3f702

Browse files
committed
adding nfsd thread count to state
1 parent a09b0b2 commit bc3f702

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

entrypoint.sh

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ readonly LOG_LEVEL_DEBUG='DEBUG'
6464
readonly STATE_LOG_LEVEL='log_level'
6565
readonly STATE_IS_LOGGING_DEBUG='is_logging_debug'
6666
readonly STATE_IS_LOGGING_INFO='is_logging_info'
67+
readonly STATE_NFSD_THREAD_COUNT='nfsd_thread_count'
6768

6869
# "state" is our only global variable, which is an associative array of normalized data
6970
declare -A state
@@ -315,13 +316,7 @@ has_linux_capability() {
315316

316317
get_requested_count_nfsd_threads() {
317318

318-
if [[ -n "${!ENV_VAR_NFS_SERVER_THREAD_COUNT}" ]]; then
319-
echo "${!ENV_VAR_NFS_SERVER_THREAD_COUNT}"
320-
else
321-
local -r cpu_count="$(grep -Ec ^processor /proc/cpuinfo)"
322-
on_failure bail 'unable to detect CPU count. set NFS_SERVER_THREAD_COUNT environment variable'
323-
echo "$cpu_count";
324-
fi
319+
echo "${state[$STATE_NFSD_THREAD_COUNT]}"
325320
}
326321

327322
is_logging_debug() {
@@ -384,13 +379,6 @@ assert_nfs_version() {
384379
fi
385380
}
386381

387-
assert_nfsd_threads() {
388-
389-
if [[ "$(get_requested_count_nfsd_threads)" -lt 1 ]]; then
390-
bail "please set $ENV_VAR_NFS_SERVER_THREAD_COUNT to a positive integer"
391-
fi
392-
}
393-
394382
assert_at_least_one_export() {
395383

396384
# ensure /etc/exports has at least one line
@@ -434,6 +422,36 @@ init_state_logging() {
434422
fi
435423
}
436424

425+
init_state_nfsd_thread_count() {
426+
427+
local count
428+
429+
if [[ -n "${!ENV_VAR_NFS_SERVER_THREAD_COUNT}" ]]; then
430+
431+
count="${!ENV_VAR_NFS_SERVER_THREAD_COUNT}"
432+
433+
if [[ $count -lt 1 ]]; then
434+
bail "please set $ENV_VAR_NFS_SERVER_THREAD_COUNT to a positive integer"
435+
fi
436+
437+
if is_logging_debug; then
438+
log "will use requested rpc.nfsd thread count of $count"
439+
fi
440+
441+
else
442+
443+
count="$(grep -Ec ^processor /proc/cpuinfo)"
444+
on_failure bail "unable to detect CPU count. set $ENV_VAR_NFS_SERVER_THREAD_COUNT environment variable"
445+
446+
if is_logging_debug; then
447+
log "will use $count rpc.nfsd server thread(s) (1 thread per CPU)"
448+
fi
449+
450+
fi
451+
452+
state[$STATE_NFSD_THREAD_COUNT]=$count
453+
}
454+
437455
init_trap() {
438456

439457
trap stop SIGTERM SIGINT
@@ -519,7 +537,6 @@ init_assertions() {
519537
assert_port "$ENV_VAR_NFS_PORT_STATD_IN"
520538
assert_port "$ENV_VAR_NFS_PORT_STATD_OUT"
521539
assert_nfs_version
522-
assert_nfsd_threads
523540

524541
# check kernel modules
525542
assert_kernel_mod nfs
@@ -798,6 +815,7 @@ init() {
798815

799816
init_state_logging
800817
init_exports
818+
init_state_nfsd_thread_count
801819
init_assertions
802820
init_trap
803821

0 commit comments

Comments
 (0)