fix(agent): accept empty libvirt backing sentinel

go
codex 3 weeks ago
parent 63f365d847
commit 0ba61d31bf

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"path/filepath"
"reflect"
"strings"
"time"
@ -234,9 +235,12 @@ func validateLiveBackupDefinition(definition *libvirtxml.Domain, managedRootPath
func domainBackingChainPresent(store *libvirtxml.DomainDiskBackingStore) bool {
for store != nil {
// libvirt commonly serializes an empty <backingStore/> sentinel for a
// standalone qcow2 disk. Only a described source/format is an actual
// backing layer which makes the portable snapshot unsafe.
if store.Source != nil || store.Format != nil {
// standalone qcow2 disk. libvirtxml materializes that sentinel with a
// non-nil, zero-valued Source, so pointer presence alone is not evidence
// of a backing layer. Any actual source content, format or index remains
// fail-closed because it makes the portable snapshot unsafe.
if store.Index != 0 || store.Format != nil ||
domainDiskSourcePresent(store.Source) {
return true
}
store = store.BackingStore
@ -244,6 +248,10 @@ func domainBackingChainPresent(store *libvirtxml.DomainDiskBackingStore) bool {
return false
}
func domainDiskSourcePresent(source *libvirtxml.DomainDiskSource) bool {
return source != nil && !reflect.ValueOf(*source).IsZero()
}
func validateStandaloneQCOW2Volume(volume qcow2VolumeInspector, expectedCapacity uint64) (*libvirt.StorageVolInfo, error) {
info, err := validateQCOW2Volume(volume, expectedCapacity)
if err != nil {

@ -87,6 +87,24 @@ func TestValidateLiveBackupDefinitionRejectsLiveOnlyDiskTopology(t *testing.T) {
}
}
func TestValidateLiveBackupDefinitionAcceptsSerializedEmptyBackingStoreSentinel(t *testing.T) {
const managedPath = "/var/lib/virt-cloud/managed/root.qcow2"
var domain libvirtxml.Domain
if err := domain.Unmarshal(`<domain><devices>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='` + managedPath + `' index='2'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
</disk>
</devices></domain>`); err != nil {
t.Fatalf("unmarshal live libvirt XML: %v", err)
}
if err := validateLiveBackupDefinition(&domain, managedPath); err != nil {
t.Fatalf("serialized empty libvirt backing-store sentinel rejected: %v", err)
}
}
func TestValidateStandaloneQCOW2RejectsBackingChain(t *testing.T) {
const capacity = 40 << 30
standalone := backupVolumeInspector{

Loading…
Cancel
Save