emmc_log: Fix exit condition on vacuum logs
The logic used to check for `req_size > perst_size` then exit, however,
this means that the the persistent size left over in eMMC after dumping
run/logs is greater than the current persistent log usage. It should be
checking for less than, because that would mean the free persistent size
doesn't fix the run/logs.
This can lead to a corner cases where we never exit the loop.
Refactor the check to clear up the confusion.
Tested:
|-------total-------|
|--free--|---used---|
|--run--|
if run + 1M > free, then we can't dump the log and exit.
Google-Bug-Id: 299976757
Change-Id: Ie783dbda6aeb707932c318c66dabcdb6dd0e3086
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/recipes-google/emmc/emmc-logs/start_emmc_logging.sh b/recipes-google/emmc/emmc-logs/start_emmc_logging.sh
index a30d307..b4b200b 100644
--- a/recipes-google/emmc/emmc-logs/start_emmc_logging.sh
+++ b/recipes-google/emmc/emmc-logs/start_emmc_logging.sh
@@ -22,8 +22,9 @@
run_size="$(du -bs /run/log/journal | awk '{print $1}')"
perst_size="$(du -bs "$EMMC_LOG_DIR" | awk '{print $1}')"
# Determine the required vacuum amount + 1MB of slop for new logs
- req_size=$((max - (run_size + 1024*1024)))
- (( req_size > perst_size )) && break
+ req_size=$(( run_size + 1024*1024 ))
+ free_size=$(( max - perst_size ))
+ (( req_size > free_size )) && break
# Sum all but the biggest filesize to guarantee we vacuum some contents
vsize=$(find "$EMMC_LOG_DIR" -type f -exec stat -c '%s' {} \; \