From eb38aeb99f442dc638fbf9c963859b9a13ebe675 Mon Sep 17 00:00:00 2001 From: JiangboHe <57433992+JiangboHe@users.noreply.github.com> Date: Sat, 21 Nov 2020 02:37:08 +0800 Subject: [PATCH] fix error: interface counters is mismatch after warm-reboot (#1099) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - What I did There is a issue for counters after warm-reboot: If I clear counters by command "sonic-clear counters", then execute 'warm-reboot' and whenSONiC is restart, the counters showed with command "show interface counters" is still old counters before "sonic-clear". It is not the right counters because the counters file in '/tmp' is lost in warm-reboot process. - How I did it I fixed it by saving '/tmp/portstat-0' folders in '/host/' before executing 'warm-reboot', and restore the counters folders back to '/tmp/' after warm-reboot process is finished (in pull request Azure/sonic-buildimage#5346 ). - How to verify it Clear counters by command 'sonic-clear' sonic-clear counters sonic-clear dropcounters sonic-clear pfccounters sonic-clear queuecounters sonic-clear rifcounters Execute 'warm-reboot' Use command ‘show interface counters’ to see if the counters is right. --- scripts/fast-reboot | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index acc7764b48..341e0855c9 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -362,6 +362,25 @@ function unload_kernel() fi } +function save_counters_folder() { + debug "Saving counters folder before warmboot..." + + counters_folder="/host/counters" + if [[ ! -d $counters_folder ]]; then + mkdir $counters_folder + fi + if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then + modules=("portstat-0" "dropstat" "pfcstat-0" "queuestat-0" "intfstat-0") + for module in ${modules[@]} + do + statfile="/tmp/$module" + if [[ -d $statfile ]]; then + cp -rf $statfile $counters_folder + fi + done + fi +} + # main starts here parseOptions $@ @@ -401,6 +420,8 @@ case "$REBOOT_TYPE" in ;; esac +save_counters_folder + unload_kernel setup_reboot_variables