@@ -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,12 +651,7 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
652
651
matchedPluginNames = append (matchedPluginNames , v .GetPluginName ())
653
652
}
654
653
}
655
-
656
- pm .mutex .RUnlock ()
657
- pm .mutex .Lock ()
658
654
pm .refreshProbedPlugins ()
659
- pm .mutex .Unlock ()
660
- pm .mutex .RLock ()
661
655
662
656
for _ , plugin := range pm .probedPlugins {
663
657
if plugin .CanSupport (spec ) {
@@ -678,19 +672,14 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
678
672
679
673
// FindPluginByName fetches a plugin by name. If no plugin is found, returns error.
680
674
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 ()
683
677
684
678
var match VolumePlugin
685
679
if v , found := pm .plugins [name ]; found {
686
680
match = v
687
681
}
688
-
689
- pm .mutex .RUnlock ()
690
- pm .mutex .Lock ()
691
682
pm .refreshProbedPlugins ()
692
- pm .mutex .Unlock ()
693
- pm .mutex .RLock ()
694
683
if plugin , found := pm .probedPlugins [name ]; found {
695
684
if match != nil {
696
685
return nil , fmt .Errorf ("multiple volume plugins matched: %s and %s" , match .GetPluginName (), plugin .GetPluginName ())
@@ -716,6 +705,7 @@ func (pm *VolumePluginMgr) refreshProbedPlugins() {
716
705
// because the probe function can return a list of valid plugins
717
706
// even when an error is present we still must add the plugins
718
707
// or they will be skipped because each event only fires once
708
+
719
709
for _ , event := range events {
720
710
if event .Op == ProbeAddOrUpdate {
721
711
if err := pm .initProbedPlugin (event .Plugin ); err != nil {
0 commit comments