qemu: Simplify (Object).Valid()

so that more object types can be added without going over cyclomatic
complexity limits

Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
This commit is contained in:
Jakob Naucke 2021-04-28 15:50:36 +02:00
parent a6cec2d38c
commit 7a367dc0a8
No known key found for this signature in database
GPG Key ID: 45FA1C7D310C0EBE

View File

@ -275,24 +275,14 @@ type Object struct {
func (object Object) Valid() bool {
switch object.Type {
case MemoryBackendFile:
if object.ID == "" || object.MemPath == "" || object.Size == 0 {
return false
}
return object.ID != "" && object.MemPath != "" && object.Size != 0
case TDXGuest:
if object.ID == "" || object.File == "" || object.DeviceID == "" {
return false
}
return object.ID != "" && object.File != "" && object.DeviceID != ""
case SEVGuest:
if object.ID == "" || object.File == "" || object.CBitPos == 0 || object.ReducedPhysBits == 0 {
return false
}
return object.ID != "" && object.File != "" && object.CBitPos != 0 && object.ReducedPhysBits != 0
default:
return false
}
return true
}
// QemuParams returns the qemu parameters built out of this Object device.