Skip to content

Commit afdc62e

Browse files
authored
Merge pull request kubernetes#129755 from niranjandarshann/conmap
Concurrentmap Iteration
2 parents e7eb076 + 7f76676 commit afdc62e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pkg/volume/plugins.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,8 @@ func (pm *VolumePluginMgr) initProbedPlugin(probedPlugin VolumePlugin) error {
637637
// specification. If no plugins can support or more than one plugin can
638638
// support it, return error.
639639
func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
640-
pm.mutex.RLock()
641-
defer pm.mutex.RUnlock()
642-
640+
pm.mutex.Lock()
641+
defer pm.mutex.Unlock()
643642
if spec == nil {
644643
return nil, fmt.Errorf("could not find plugin because volume spec is nil")
645644
}
@@ -652,8 +651,8 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
652651
matchedPluginNames = append(matchedPluginNames, v.GetPluginName())
653652
}
654653
}
655-
656654
pm.refreshProbedPlugins()
655+
657656
for _, plugin := range pm.probedPlugins {
658657
if plugin.CanSupport(spec) {
659658
match = plugin
@@ -673,14 +672,13 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
673672

674673
// FindPluginByName fetches a plugin by name. If no plugin is found, returns error.
675674
func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
676-
pm.mutex.RLock()
677-
defer pm.mutex.RUnlock()
675+
pm.mutex.Lock()
676+
defer pm.mutex.Unlock()
678677

679678
var match VolumePlugin
680679
if v, found := pm.plugins[name]; found {
681680
match = v
682681
}
683-
684682
pm.refreshProbedPlugins()
685683
if plugin, found := pm.probedPlugins[name]; found {
686684
if match != nil {
@@ -707,6 +705,7 @@ func (pm *VolumePluginMgr) refreshProbedPlugins() {
707705
// because the probe function can return a list of valid plugins
708706
// even when an error is present we still must add the plugins
709707
// or they will be skipped because each event only fires once
708+
710709
for _, event := range events {
711710
if event.Op == ProbeAddOrUpdate {
712711
if err := pm.initProbedPlugin(event.Plugin); err != nil {

0 commit comments

Comments
 (0)