Commit e47f972d authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Ben Walker
Browse files

scripts/setup.sh: add cleanup command



From now on remove any SPDK artifacts just use:

./scripts/setup.sh cleanup

Fixes #302

Change-Id: I5ebe522fecfcb8a867a96ab10bacda6083c8c224
Signed-off-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/419575


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 1f5c8233
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ source "$rootdir/scripts/common.sh"
function usage()
{
	if [ `uname` = Linux ]; then
		options="[config|reset|status|help]"
		options="[config|reset|status|cleanup|help]"
	else
		options="[config|reset|help]"
	fi
@@ -22,6 +22,9 @@ function usage()
	echo
	echo "$options - as following:"
	echo "config            Default mode. Allocate hugepages and bind PCI devices."
	if [ `uname` = Linux ]; then
		echo "cleanup            Remove any orphaned files that can be left in the system after SPDK application exit"
	fi
	echo "reset             Rebind PCI devices back to their original drivers."
	echo "                  Also cleanup any leftover spdk files/resources."
	echo "                  Hugepage memory size will remain unchanged."
@@ -234,6 +237,39 @@ function configure_linux_pci {
	echo "1" > "/sys/bus/pci/rescan"
}

function cleanup_linux {
	files_to_clean="$(echo /dev/shm/* | egrep '(spdk_tgt|iscsi|vhost|nvmf|rocksdb)_trace|spdk_iscsi_conns' || true)"
	files_to_clean="$(readlink -e assert_not_empty $files_to_clean || true)"
	if [[ -z "$files_to_clean" ]]; then
		echo "Clean"
		return 0;
	fi

	shopt -s extglob
	for fd_dir in $(echo /proc/+([0-9])); do
		opened_files+="$(readlink -e assert_not_empty $fd_dir/fd/* || true)"
	done
	shopt -u extglob

	if [[ -z "$opened_files" ]]; then
		echo "Can't get list of opened files!"
		exit 1
	fi

	echo 'Cleaning'
	for f in $files_to_clean; do
		if ! echo "$opened_files" | egrep -q "^$f\$"; then
			echo "Removing:    $f"
			rm $f
		else
			echo "Still open: $f"
		fi
	done
	echo "Clean"

	unset files_to_clean opened_files
}

function configure_linux {
	configure_linux_pci
	hugetlbfs_mounts=$(linux_hugetlbfs_mounts)
@@ -518,6 +554,8 @@ if [ `uname` = Linux ]; then

	if [ "$mode" == "config" ]; then
		configure_linux
	elif [ "$mode" == "cleanup" ]; then
		cleanup_linux
	elif [ "$mode" == "reset" ]; then
		reset_linux
	elif [ "$mode" == "status" ]; then