@@ -11,17 +11,18 @@ import (
1111)
1212
1313type macvtapLister struct {
14- DeviceList map [string ]* v1beta1.LAN //key is the res name in the LAN
15- // lock *sync.RWMutex
16- // NetNsPath is the path to the network namespace the lister operates in.
14+ DeviceList map [string ]* v1beta1.LAN //key is the res name in the LAN
15+ deviceListLock * sync.RWMutex
1716 AddChan chan v1beta1.AddRequest
1817 RemovChan chan * v1beta1.LAN
1918 ExistingNSList []string
20- ExistingNSListLock * sync.RWMutex
19+ existingNSListLock * sync.RWMutex
2120}
2221
2322func (ml * macvtapLister ) getCurrentPlugins () dpm.PluginNameList {
2423 r := make (dpm.PluginNameList , 0 )
24+ ml .deviceListLock .RLock ()
25+ defer ml .deviceListLock .RUnlock ()
2526 for name := range ml .DeviceList {
2627 r = append (r , name )
2728 }
@@ -33,7 +34,8 @@ func NewMacvtapLister(netNsPath string, add chan v1beta1.AddRequest, remove chan
3334 AddChan : add ,
3435 RemovChan : remove ,
3536 DeviceList : make (map [string ]* v1beta1.LAN ),
36- ExistingNSListLock : new (sync.RWMutex ),
37+ deviceListLock : new (sync.RWMutex ),
38+ existingNSListLock : new (sync.RWMutex ),
3739 }
3840}
3941
@@ -55,22 +57,26 @@ func (ml *macvtapLister) Discover(pluginListCh chan dpm.PluginNameList) {
5557
5658 lan := req .NewLan
5759 log .Info ("got a new lan" , "name" , lan .Name )
58- ml .ExistingNSListLock .Lock ()
60+ ml .existingNSListLock .Lock ()
5961 ml .ExistingNSList = req .ExistingNSNames
60- ml .ExistingNSListLock .Unlock ()
62+ ml .existingNSListLock .Unlock ()
63+ ml .deviceListLock .Lock ()
6164 for _ , spokeName := range lan .Spec .SpokeList {
6265 ml .DeviceList [v1beta1 .GetDPResouceName (lan .Name , spokeName , true )] = lan
6366 ml .DeviceList [v1beta1 .GetDPResouceName (lan .Name , spokeName , false )] = lan
6467 }
68+ ml .deviceListLock .Unlock ()
6569 ml .report (pluginListCh )
6670 log .Info ("report the new lan" , "name" , lan .Name )
6771
6872 case lan := <- ml .RemovChan :
6973 log .Info ("got a lan to remove" , "name" , lan .Name )
74+ ml .deviceListLock .Lock ()
7075 for _ , spokeName := range lan .Spec .SpokeList {
7176 delete (ml .DeviceList , v1beta1 .GetDPResouceName (lan .Name , spokeName , true ))
7277 delete (ml .DeviceList , v1beta1 .GetDPResouceName (lan .Name , spokeName , false ))
7378 }
79+ ml .deviceListLock .Unlock ()
7480 ml .report (pluginListCh )
7581 log .Info ("report new dev list after removal" , "name" , lan .Name )
7682
@@ -82,7 +88,9 @@ func (ml *macvtapLister) Discover(pluginListCh chan dpm.PluginNameList) {
8288// also vlanName in k8slan case
8389func (ml * macvtapLister ) NewPlugin (name string ) dpm.PluginInterface {
8490 log := ctrl .Log .WithName ("deviceplugin" )
91+ ml .deviceListLock .RLock ()
8592 lan , ok := ml .DeviceList [name ]
93+ ml .deviceListLock .RUnlock ()
8694 if ! ok {
8795 return nil
8896 }
0 commit comments