Report wipe progress every 30s for non terminal logging

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2022-05-02 15:24:07 +02:00 committed by Daniel Weiße
parent 3bb1ec96b1
commit 51d8bfddbe
2 changed files with 25 additions and 5 deletions

View File

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

View File

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