@@ -64,6 +64,7 @@ readonly LOG_LEVEL_DEBUG='DEBUG'
64
64
readonly STATE_LOG_LEVEL=' log_level'
65
65
readonly STATE_IS_LOGGING_DEBUG=' is_logging_debug'
66
66
readonly STATE_IS_LOGGING_INFO=' is_logging_info'
67
+ readonly STATE_NFSD_THREAD_COUNT=' nfsd_thread_count'
67
68
68
69
# "state" is our only global variable, which is an associative array of normalized data
69
70
declare -A state
@@ -315,13 +316,7 @@ has_linux_capability() {
315
316
316
317
get_requested_count_nfsd_threads () {
317
318
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]} "
325
320
}
326
321
327
322
is_logging_debug () {
@@ -384,13 +379,6 @@ assert_nfs_version() {
384
379
fi
385
380
}
386
381
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
-
394
382
assert_at_least_one_export () {
395
383
396
384
# ensure /etc/exports has at least one line
@@ -434,6 +422,36 @@ init_state_logging() {
434
422
fi
435
423
}
436
424
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
+
437
455
init_trap () {
438
456
439
457
trap stop SIGTERM SIGINT
@@ -519,7 +537,6 @@ init_assertions() {
519
537
assert_port " $ENV_VAR_NFS_PORT_STATD_IN "
520
538
assert_port " $ENV_VAR_NFS_PORT_STATD_OUT "
521
539
assert_nfs_version
522
- assert_nfsd_threads
523
540
524
541
# check kernel modules
525
542
assert_kernel_mod nfs
@@ -798,6 +815,7 @@ init() {
798
815
799
816
init_state_logging
800
817
init_exports
818
+ init_state_nfsd_thread_count
801
819
init_assertions
802
820
init_trap
803
821
0 commit comments