Fix random panics during autoballonning. (#17)

There is a race condition, when good behaving VMs will temporarily
truncate .memory_used to 0 bytes (update is not atomic).

Also, as a matter of principle, VMs should not crash the host,
ever.

Co-authored-by: msm <msm@cert.pl>
This commit is contained in:
msm-code 2020-03-30 21:53:02 +00:00 committed by GitHub
parent 63cd3fc79d
commit c0801541b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -310,6 +310,10 @@ func autoBalloon(l *libvirt.Libvirt, memoryMin, adjustPercent uint64) {
log.Println(err)
continue
}
if len(memoryUsedRaw) == 0 {
log.Println("Empty .memory_used file for domain", name)
continue
}
memoryUsedMiB, err := strconv.Atoi(string(memoryUsedRaw[0 : len(memoryUsedRaw)-1]))
if err != nil {
log.Println(err)