From 51d8bfddbebcfb582fba8a2f192444746ce0ae9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= Date: Mon, 2 May 2022 15:24:07 +0200 Subject: [PATCH] Report wipe progress every 30s for non terminal logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- mount/README.md | 4 ++-- mount/cryptmapper/cryptmapper.go | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/mount/README.md b/mount/README.md index 64298ba2a..be7a7a86d 100644 --- a/mount/README.md +++ b/mount/README.md @@ -12,8 +12,8 @@ sudo apt install libcryptsetup-dev ## Testing -A small test programm is available in `test/main.go`. -To build the programm run: +A small test program is available in `test/main.go`. +To build the program run: ```shell go build -o test/crypt ./test/ ``` diff --git a/mount/cryptmapper/cryptmapper.go b/mount/cryptmapper/cryptmapper.go index 7cc6e1a25..35095df51 100644 --- a/mount/cryptmapper/cryptmapper.go +++ b/mount/cryptmapper/cryptmapper.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" "sync" + "time" cryptsetup "github.com/martinjungblut/go-cryptsetup" "k8s.io/klog" @@ -293,9 +294,28 @@ func performWipe(device DeviceMapper, volumeID, dek string) error { return 0 } } else { - // No terminal available, disable callbacks to not fill up logs with large amount of progress updates - klog.V(4).Info("Progress updates not available") - progressCallback = nil + // No terminal available, limit callbacks to once every 30 seconds to not fill up logs with large amount of progress updates + ticker := time.NewTicker(30 * time.Second) + firstReq := make(chan struct{}, 1) + firstReq <- struct{}{} + defer ticker.Stop() + + logProgress := func(size, offset uint64) { + prog := (float64(offset) / float64(size)) * 100 + klog.V(4).Infof("Wipe in progress: %.2f%%", prog) + } + + progressCallback = func(size, offset uint64) int { + select { + case <-firstReq: + logProgress(size, offset) + case <-ticker.C: + logProgress(size, offset) + default: + } + + return 0 + } } // Wipe the device using the same options as used in cryptsetup: https://gitlab.com/cryptsetup/cryptsetup/-/blob/master/src/cryptsetup.c#L1178