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: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/419575
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Pawel Wodkowski 2018-07-17 21:43:33 +02:00 committed by Ben Walker
parent 1f5c8233da
commit e47f972dff

View File

@ -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