Skip to content

Commit 7f76676

Browse files
Updated Concurrentmap iter
1 parent 84b8f18 commit 7f76676

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

pkg/volume/plugins.go

Lines changed: 5 additions & 15 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,12 +651,7 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
652651
matchedPluginNames = append(matchedPluginNames, v.GetPluginName())
653652
}
654653
}
655-
656-
pm.mutex.RUnlock()
657-
pm.mutex.Lock()
658654
pm.refreshProbedPlugins()
659-
pm.mutex.Unlock()
660-
pm.mutex.RLock()
661655

662656
for _, plugin := range pm.probedPlugins {
663657
if plugin.CanSupport(spec) {
@@ -678,19 +672,14 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
678672

679673
// FindPluginByName fetches a plugin by name. If no plugin is found, returns error.
680674
func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
681-
pm.mutex.RLock()
682-
defer pm.mutex.RUnlock()
675+
pm.mutex.Lock()
676+
defer pm.mutex.Unlock()
683677

684678
var match VolumePlugin
685679
if v, found := pm.plugins[name]; found {
686680
match = v
687681
}
688-
689-
pm.mutex.RUnlock()
690-
pm.mutex.Lock()
691682
pm.refreshProbedPlugins()
692-
pm.mutex.Unlock()
693-
pm.mutex.RLock()
694683
if plugin, found := pm.probedPlugins[name]; found {
695684
if match != nil {
696685
return nil, fmt.Errorf("multiple volume plugins matched: %s and %s", match.GetPluginName(), plugin.GetPluginName())
@@ -716,6 +705,7 @@ func (pm *VolumePluginMgr) refreshProbedPlugins() {
716705
// because the probe function can return a list of valid plugins
717706
// even when an error is present we still must add the plugins
718707
// or they will be skipped because each event only fires once
708+
719709
for _, event := range events {
720710
if event.Op == ProbeAddOrUpdate {
721711
if err := pm.initProbedPlugin(event.Plugin); err != nil {

0 commit comments

Comments
 (0)