|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # fasterdata-tuning.sh |
3 | 3 | # -------------------- |
4 | | -# Version: 1.3.7 |
| 4 | +# Version: 1.3.8 |
5 | 5 | # Author: Shawn McKee, University of Michigan |
6 | 6 | # Acknowledgements: Supported by IRIS-HEP and OSG-LHC |
7 | 7 | # |
|
24 | 24 | # --diff-state/--restore-state can parse saved files reliably. |
25 | 25 | # NEW in v1.3.6: Respect --dry-run for packet pacing; audit checks actual qdisc. |
26 | 26 | # NEW in v1.3.7: Fix summary display of packet pacing status to correctly detect applied qdisc. |
| 27 | +# NEW in v1.3.8: Validate required option arguments up front to avoid unbound-variable errors and provide clearer CLI feedback. |
27 | 28 | # |
28 | 29 | # Sources: https://fasterdata.es.net/host-tuning/ , /network-tuning/ , /DTN/ |
29 | 30 | # |
@@ -129,6 +130,17 @@ State Management Options: |
129 | 130 | EOF |
130 | 131 | } |
131 | 132 |
|
| 133 | +# Ensure required option arguments are present; fail fast with a helpful message |
| 134 | +require_arg() { |
| 135 | + local flag="$1" |
| 136 | + local val="${2-}" |
| 137 | + if [[ -z "$val" || "$val" == -* ]]; then |
| 138 | + echo "ERROR: $flag requires an argument" >&2 |
| 139 | + usage |
| 140 | + exit 1 |
| 141 | + fi |
| 142 | +} |
| 143 | + |
132 | 144 | # Speed-specific tuning recommendations from ESnet fasterdata.es.net |
133 | 145 | # Values indexed by link speed in Mbps: [rmem_max, wmem_max, tcp_rmem_max, tcp_wmem_max, netdev_max_backlog] |
134 | 146 | # For measurement hosts (perfSONAR): optimized for moderate RTT (50-100ms) paths |
@@ -3184,30 +3196,30 @@ print_summary() { |
3184 | 3196 | main() { |
3185 | 3197 | while [[ $# -gt 0 ]]; do |
3186 | 3198 | case "$1" in |
3187 | | - --mode) MODE="$2"; shift 2;; |
3188 | | - --ifaces) IFACES="$2"; shift 2;; |
3189 | | - --target) TARGET_TYPE="$2"; shift 2;; |
3190 | | - --tbf-cap-rate) TBF_CAP_RATE="$2"; USE_TBF_CAP=1; shift 2;; |
3191 | | - --packet-pacing-rate) TBF_CAP_RATE="$2"; USE_TBF_CAP=1; log_warn "--packet-pacing-rate is deprecated; use --tbf-cap-rate"; shift 2;; |
| 3199 | + --mode) require_arg "$1" "${2-}"; MODE="$2"; shift 2;; |
| 3200 | + --ifaces) require_arg "$1" "${2-}"; IFACES="$2"; shift 2;; |
| 3201 | + --target) require_arg "$1" "${2-}"; TARGET_TYPE="$2"; shift 2;; |
| 3202 | + --tbf-cap-rate) require_arg "$1" "${2-}"; TBF_CAP_RATE="$2"; USE_TBF_CAP=1; shift 2;; |
| 3203 | + --packet-pacing-rate) require_arg "$1" "${2-}"; TBF_CAP_RATE="$2"; USE_TBF_CAP=1; log_warn "--packet-pacing-rate is deprecated; use --tbf-cap-rate"; shift 2;; |
3192 | 3204 | --apply-packet-pacing) APPLY_PACKET_PACING=1; shift;; |
3193 | 3205 | --use-tbf-cap) USE_TBF_CAP=1; shift;; |
3194 | 3206 | --color) USE_COLOR=1; shift;; |
3195 | 3207 | --nocolor) USE_COLOR=0; shift;; |
3196 | 3208 | --apply-iommu) APPLY_IOMMU=1; shift;; |
3197 | | - --iommu-args) IOMMU_ARGS="$2"; shift 2;; |
3198 | | - --apply-smt) APPLY_SMT="$2"; shift 2;; |
| 3209 | + --iommu-args) require_arg "$1" "${2-}"; IOMMU_ARGS="$2"; shift 2;; |
| 3210 | + --apply-smt) require_arg "$1" "${2-}"; APPLY_SMT="$2"; shift 2;; |
3199 | 3211 | --persist-smt) PERSIST_SMT=1; shift;; |
3200 | | - --apply-tcp-cc) APPLY_TCP_CC="$2"; shift 2;; |
| 3212 | + --apply-tcp-cc) require_arg "$1" "${2-}"; APPLY_TCP_CC="$2"; shift 2;; |
3201 | 3213 | --apply-jumbo) APPLY_JUMBO=1; shift;; |
3202 | 3214 | --yes) AUTO_YES=1; shift;; |
3203 | 3215 | --dry-run) DRY_RUN=1; shift;; |
3204 | 3216 | --json) OUTPUT_JSON=1; shift;; |
3205 | 3217 | --save-state) SAVE_STATE=1; shift;; |
3206 | | - --label) STATE_LABEL="$2"; shift 2;; |
3207 | | - --restore-state) RESTORE_STATE="$2"; shift 2;; |
| 3218 | + --label) require_arg "$1" "${2-}"; STATE_LABEL="$2"; shift 2;; |
| 3219 | + --restore-state) require_arg "$1" "${2-}"; RESTORE_STATE="$2"; shift 2;; |
3208 | 3220 | --list-states) LIST_STATES=1; shift;; |
3209 | | - --diff-state) DIFF_STATE="$2"; shift 2;; |
3210 | | - --delete-state) DELETE_STATE="$2"; shift 2;; |
| 3221 | + --diff-state) require_arg "$1" "${2-}"; DIFF_STATE="$2"; shift 2;; |
| 3222 | + --delete-state) require_arg "$1" "${2-}"; DELETE_STATE="$2"; shift 2;; |
3211 | 3223 | --auto-save-before) AUTO_SAVE_BEFORE=1; shift;; |
3212 | 3224 | -h|--help) usage; exit 0;; |
3213 | 3225 | -v|--version) echo "fasterdata-tuning.sh v$(get_script_version)"; exit 0;; |
|
0 commit comments