fix multiple possible concurrent map write issues,
fix issue with VM instacne types returning prematurely
This commit is contained in:
+18
-5
@@ -186,8 +186,6 @@ func (cluster *Cluster) BuildNode(nodeName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster.Nodes[nodeName] = node
|
|
||||||
|
|
||||||
// get node's VMs
|
// get node's VMs
|
||||||
vms, err := node.VirtualMachines()
|
vms, err := node.VirtualMachines()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -242,6 +240,10 @@ func (cluster *Cluster) BuildNode(nodeName string) error {
|
|||||||
|
|
||||||
node.cluster = cluster
|
node.cluster = cluster
|
||||||
|
|
||||||
|
cluster.NodesLock.Lock()
|
||||||
|
cluster.Nodes[nodeName] = node
|
||||||
|
cluster.NodesLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,12 +319,11 @@ func (node *Node) BuildInstance(instancetype InstanceType, vmid uint) error {
|
|||||||
|
|
||||||
if err != nil && node.Instances[instanceID] != nil { // node is unreachable and did exist previously
|
if err != nil && node.Instances[instanceID] != nil { // node is unreachable and did exist previously
|
||||||
// assume the instance is gone and delete from cluster
|
// assume the instance is gone and delete from cluster
|
||||||
|
log.Printf("[ERR ] error retrieving %s.%d: %s", node.Name, instanceID, err)
|
||||||
delete(node.Instances, instanceID)
|
delete(node.Instances, instanceID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
node.Instances[instanceID] = instance
|
|
||||||
|
|
||||||
for volid := range instance.configDisks {
|
for volid := range instance.configDisks {
|
||||||
wg.Go(func() error {
|
wg.Go(func() error {
|
||||||
err = instance.RebuildVolume(node, volid)
|
err = instance.RebuildVolume(node, volid)
|
||||||
@@ -363,11 +364,16 @@ func (node *Node) BuildInstance(instancetype InstanceType, vmid uint) error {
|
|||||||
err = instance.RebuildBoot(node)
|
err = instance.RebuildBoot(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[ERR ] error rebuilding boot: %s", err)
|
log.Printf("[ERR ] error rebuilding boot: %s", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.node = node
|
instance.node = node
|
||||||
|
|
||||||
|
node.InstancesLock.Lock()
|
||||||
|
node.Instances[instanceID] = instance
|
||||||
|
node.InstancesLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +388,10 @@ func (instance *Instance) RebuildVolume(node *Node, volid string) error {
|
|||||||
voltype := AnyPrefixes(volid, paas.VolumeTypes)
|
voltype := AnyPrefixes(volid, paas.VolumeTypes)
|
||||||
volume.Type = voltype
|
volume.Type = voltype
|
||||||
volume.Volume_ID = VolumeID(volid)
|
volume.Volume_ID = VolumeID(volid)
|
||||||
|
|
||||||
|
instance.VolumesLock.Lock()
|
||||||
instance.Volumes[VolumeID(volid)] = volume
|
instance.Volumes[VolumeID(volid)] = volume
|
||||||
|
instance.VolumesLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -396,7 +405,9 @@ func (instance *Instance) RebuildNet(node *Node, netid string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.NetsLock.Lock()
|
||||||
instance.Nets[NetID(netid)] = netinfo
|
instance.Nets[NetID(netid)] = netinfo
|
||||||
|
instance.NetsLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -420,7 +431,9 @@ func (instance *Instance) RebuildDevice(node *Node, deviceid string) error {
|
|||||||
// sub function assignment not supported yet
|
// sub function assignment not supported yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.DevicesLock.Lock()
|
||||||
instance.Devices[DeviceID(instanceDeviceBusID)].Device_ID = DeviceID(deviceid)
|
instance.Devices[DeviceID(instanceDeviceBusID)].Device_ID = DeviceID(deviceid)
|
||||||
|
instance.DevicesLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-8
@@ -14,10 +14,11 @@ import (
|
|||||||
// override Nodes map to new custom Node type
|
// override Nodes map to new custom Node type
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
paas.Cluster
|
paas.Cluster
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
pve ProxmoxClient
|
pve ProxmoxClient
|
||||||
Nodes map[string]*Node `json:"nodes"`
|
NodesLock sync.Mutex
|
||||||
OK bool
|
Nodes map[string]*Node `json:"nodes"`
|
||||||
|
OK bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// add mutex and pve api Node object
|
// add mutex and pve api Node object
|
||||||
@@ -25,10 +26,11 @@ type Cluster struct {
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
paas.Node
|
paas.Node
|
||||||
Instances map[InstanceID]*Instance `json:"instances"`
|
InstancesLock sync.Mutex // lock for Instances map
|
||||||
pvenode *proxmox.Node
|
Instances map[InstanceID]*Instance `json:"instances"`
|
||||||
storage map[string][]*proxmox.StorageContent
|
pvenode *proxmox.Node
|
||||||
cluster *Cluster
|
storage map[string][]*proxmox.StorageContent
|
||||||
|
cluster *Cluster
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstanceID = paas.InstanceID
|
type InstanceID = paas.InstanceID
|
||||||
@@ -41,6 +43,9 @@ const CT InstanceType = paas.CT
|
|||||||
type Instance struct {
|
type Instance struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
paas.Instance
|
paas.Instance
|
||||||
|
VolumesLock sync.Mutex // lock for Volumes map
|
||||||
|
NetsLock sync.Mutex // lock for Nets map
|
||||||
|
DevicesLock sync.Mutex // lock for Devices map
|
||||||
pveconfig any
|
pveconfig any
|
||||||
configDisks map[string]string
|
configDisks map[string]string
|
||||||
configNets map[string]string
|
configNets map[string]string
|
||||||
|
|||||||
Reference in New Issue
Block a user