@@ -637,9 +637,8 @@ func (pm *VolumePluginMgr) initProbedPlugin(probedPlugin VolumePlugin) error {
637
637
// specification. If no plugins can support or more than one plugin can
638
638
// support it, return error.
639
639
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 ()
643
642
if spec == nil {
644
643
return nil , fmt .Errorf ("could not find plugin because volume spec is nil" )
645
644
}
@@ -652,8 +651,8 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
652
651
matchedPluginNames = append (matchedPluginNames , v .GetPluginName ())
653
652
}
654
653
}
655
-
656
654
pm .refreshProbedPlugins ()
655
+
657
656
for _ , plugin := range pm .probedPlugins {
658
657
if plugin .CanSupport (spec ) {
659
658
match = plugin
@@ -673,14 +672,13 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
673
672
674
673
// FindPluginByName fetches a plugin by name. If no plugin is found, returns error.
675
674
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 ()
678
677
679
678
var match VolumePlugin
680
679
if v , found := pm .plugins [name ]; found {
681
680
match = v
682
681
}
683
-
684
682
pm .refreshProbedPlugins ()
685
683
if plugin , found := pm .probedPlugins [name ]; found {
686
684
if match != nil {
@@ -707,6 +705,7 @@ func (pm *VolumePluginMgr) refreshProbedPlugins() {
707
705
// because the probe function can return a list of valid plugins
708
706
// even when an error is present we still must add the plugins
709
707
// or they will be skipped because each event only fires once
708
+
710
709
for _ , event := range events {
711
710
if event .Op == ProbeAddOrUpdate {
712
711
if err := pm .initProbedPlugin (event .Plugin ); err != nil {
0 commit comments