mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Prevent data race in volume plugin manager
This commit is contained in:
parent
7df379d751
commit
80bd46ce46
@ -459,7 +459,7 @@ type VolumeHost interface {
|
|||||||
|
|
||||||
// VolumePluginMgr tracks registered plugins.
|
// VolumePluginMgr tracks registered plugins.
|
||||||
type VolumePluginMgr struct {
|
type VolumePluginMgr struct {
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
plugins map[string]VolumePlugin
|
plugins map[string]VolumePlugin
|
||||||
prober DynamicPluginProber
|
prober DynamicPluginProber
|
||||||
probedPlugins map[string]VolumePlugin
|
probedPlugins map[string]VolumePlugin
|
||||||
@ -659,8 +659,8 @@ func (pm *VolumePluginMgr) initProbedPlugin(probedPlugin VolumePlugin) error {
|
|||||||
// specification. If no plugins can support or more than one plugin can
|
// specification. If no plugins can support or more than one plugin can
|
||||||
// support it, return error.
|
// support it, return error.
|
||||||
func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
|
func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
|
||||||
pm.mutex.Lock()
|
pm.mutex.RLock()
|
||||||
defer pm.mutex.Unlock()
|
defer pm.mutex.RUnlock()
|
||||||
|
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
return nil, fmt.Errorf("Could not find plugin because volume spec is nil")
|
return nil, fmt.Errorf("Could not find plugin because volume spec is nil")
|
||||||
@ -699,8 +699,8 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
|
|||||||
// FindPluginByName fetches a plugin by name or by legacy name. If no plugin
|
// FindPluginByName fetches a plugin by name or by legacy name. If no plugin
|
||||||
// is found, returns error.
|
// is found, returns error.
|
||||||
func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
|
func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
|
||||||
pm.mutex.Lock()
|
pm.mutex.RLock()
|
||||||
defer pm.mutex.Unlock()
|
defer pm.mutex.RUnlock()
|
||||||
|
|
||||||
// Once we can get rid of legacy names we can reduce this to a map lookup.
|
// Once we can get rid of legacy names we can reduce this to a map lookup.
|
||||||
matches := []VolumePlugin{}
|
matches := []VolumePlugin{}
|
||||||
@ -768,6 +768,9 @@ func (pm *VolumePluginMgr) refreshProbedPlugins() {
|
|||||||
|
|
||||||
// ListVolumePluginWithLimits returns plugins that have volume limits on nodes
|
// ListVolumePluginWithLimits returns plugins that have volume limits on nodes
|
||||||
func (pm *VolumePluginMgr) ListVolumePluginWithLimits() []VolumePluginWithAttachLimits {
|
func (pm *VolumePluginMgr) ListVolumePluginWithLimits() []VolumePluginWithAttachLimits {
|
||||||
|
pm.mutex.RLock()
|
||||||
|
defer pm.mutex.RUnlock()
|
||||||
|
|
||||||
matchedPlugins := []VolumePluginWithAttachLimits{}
|
matchedPlugins := []VolumePluginWithAttachLimits{}
|
||||||
for _, v := range pm.plugins {
|
for _, v := range pm.plugins {
|
||||||
if plugin, ok := v.(VolumePluginWithAttachLimits); ok {
|
if plugin, ok := v.(VolumePluginWithAttachLimits); ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user