Nonnumeric input check for Setting hugepages
diff mbox series

Message ID 20200406085018.25957-1-m.bilal@emumba.com
State New
Delegated to: Thomas Monjalon
Headers show
Series
  • Nonnumeric input check for Setting hugepages
Related show

Checks

Context Check Description
ci/iol-testing success Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Muhammad Bilal April 6, 2020, 8:50 a.m. UTC
Bugzilla ID: 432
Cc: dev@dpdk.org
Cc: stable@dpdk.org
Cc: john.mcnamara@intel.com
Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
---
 usertools/dpdk-setup.sh | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
index e5bbe9fee..b0535be34 100755
--- a/usertools/dpdk-setup.sh
+++ b/usertools/dpdk-setup.sh
@@ -321,13 +321,19 @@  set_non_numa_pages()
 	echo -n "Number of pages: "
 	read Pages
 
-	echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
 
-	echo "Reserving hugepages"
-	sudo sh .echo_tmp
-	rm -f .echo_tmp
+	numeric="^[[:digit:]]+$"
+	PG_PATH="/sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}"
+    	if [[ $Pages =~ $numeric ]]; then
+		echo "echo $Pages > $PG_PATH/nr_hugepages" > .echo_tmp
+		echo "Reserving hugepages"
+		sudo sh .echo_tmp
+		rm -f .echo_tmp
 
-	create_mnt_huge
+		create_mnt_huge
+	else
+		echo "Please enter a numeric value"
+	fi
 }
 
 #
@@ -343,10 +349,17 @@  set_numa_pages()
 	echo "  enter '64' to reserve 64 * 2MB pages on each node"
 
 	echo > .echo_tmp
+	numeric="^[[:digit:]]+$"
 	for d in /sys/devices/system/node/node? ; do
 		node=$(basename $d)
 		echo -n "Number of pages for $node: "
 		read Pages
+		while [[ ! "$Pages" =~ $numeric ]]; do
+			echo "Please enter a numeric value"
+			echo -n "Number of pages for $node: "
+			read Pages
+		done
+
 		echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
 	done
 	echo "Reserving hugepages"