Skip to content

Commit a27ac53

Browse files
Martzkidavem330
authored andcommitted
samples: pktgen: fix append mode failed issue
Each sample script sources functions.sh before parameters.sh which makes $APPEND undefined when trapping EXIT no matter in append mode or not. Due to this when sample scripts finished they always do "pgctrl reset" which resets pktgen config. So move trap to each script after sourcing parameters.sh and trap EXIT explicitly. Signed-off-by: J.J. Martzki <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f56d1ee commit a27ac53

9 files changed

+37
-6
lines changed

samples/pktgen/functions.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ function pgset() {
108108
fi
109109
}
110110

111-
if [[ -z "$APPEND" ]]; then
112-
if [[ $EUID -eq 0 ]]; then
113-
# Cleanup pktgen setup on exit if thats not "append mode"
114-
trap 'pg_ctrl "reset"' EXIT
115-
fi
116-
fi
111+
function trap_exit()
112+
{
113+
# Cleanup pktgen setup on exit if thats not "append mode"
114+
if [[ -z "$APPEND" ]] && [[ $EUID -eq 0 ]]; then
115+
trap 'pg_ctrl "reset"' EXIT
116+
fi
117+
}
117118

118119
## -- General shell tricks --
119120

samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ root_check_run_with_sudo "$@"
3333

3434
# Parameter parsing via include
3535
source ${basedir}/parameters.sh
36+
37+
# Trap EXIT first
38+
trap_exit
39+
3640
# Using invalid DST_MAC will cause the packets to get dropped in
3741
# ip_rcv() which is part of the test
3842
if [ -z "$DEST_IP" ]; then

samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ root_check_run_with_sudo "$@"
1414

1515
# Parameter parsing via include
1616
source ${basedir}/parameters.sh
17+
18+
# Trap EXIT first
19+
trap_exit
20+
1721
if [ -z "$DEST_IP" ]; then
1822
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
1923
fi

samples/pktgen/pktgen_sample01_simple.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ root_check_run_with_sudo "$@"
1313
# - go look in parameters.sh to see which setting are avail
1414
# - required param is the interface "-i" stored in $DEV
1515
source ${basedir}/parameters.sh
16+
17+
# Trap EXIT first
18+
trap_exit
19+
1620
#
1721
# Set some default params, if they didn't get set
1822
if [ -z "$DEST_IP" ]; then

samples/pktgen/pktgen_sample02_multiqueue.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ root_check_run_with_sudo "$@"
1414
# Required param: -i dev in $DEV
1515
source ${basedir}/parameters.sh
1616

17+
# Trap EXIT first
18+
trap_exit
19+
1720
[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely
1821

1922
# Base Config

samples/pktgen/pktgen_sample03_burst_single_flow.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ root_check_run_with_sudo "$@"
2525

2626
# Parameter parsing via include
2727
source ${basedir}/parameters.sh
28+
29+
# Trap EXIT first
30+
trap_exit
31+
2832
# Set some default params, if they didn't get set
2933
if [ -z "$DEST_IP" ]; then
3034
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"

samples/pktgen/pktgen_sample04_many_flows.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ root_check_run_with_sudo "$@"
1212

1313
# Parameter parsing via include
1414
source ${basedir}/parameters.sh
15+
16+
# Trap EXIT first
17+
trap_exit
18+
1519
# Set some default params, if they didn't get set
1620
if [ -z "$DEST_IP" ]; then
1721
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"

samples/pktgen/pktgen_sample05_flow_per_thread.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ root_check_run_with_sudo "$@"
1616

1717
# Parameter parsing via include
1818
source ${basedir}/parameters.sh
19+
20+
# Trap EXIT first
21+
trap_exit
22+
1923
# Set some default params, if they didn't get set
2024
if [ -z "$DEST_IP" ]; then
2125
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"

samples/pktgen/pktgen_sample06_numa_awared_queue_irq_affinity.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ root_check_run_with_sudo "$@"
1414
# Required param: -i dev in $DEV
1515
source ${basedir}/parameters.sh
1616

17+
# Trap EXIT first
18+
trap_exit
19+
1720
# Base Config
1821
[ -z "$COUNT" ] && COUNT="20000000" # Zero means indefinitely
1922
[ -z "$CLONE_SKB" ] && CLONE_SKB="0"

0 commit comments

Comments
 (0)