Skip to content

Commit

Permalink
feat(CSI-247): optimize NFS by utilizing multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyberezansky committed Sep 5, 2024
1 parent cce551b commit b01ce5e
Showing 1 changed file with 5 additions and 36 deletions.
41 changes: 5 additions & 36 deletions pkg/wekafs/nfsmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
type nfsMount struct {
fsName string
mountPoint string
refCount int
lock sync.Mutex
kMounter mount.Interface
debugPath string
mountOptions MountOptions
Expand All @@ -32,7 +30,7 @@ func (m *nfsMount) getMountPoint() string {
}

func (m *nfsMount) getRefCount() int {
return m.refCount
return 0
}

func (m *nfsMount) getMountOptions() MountOptions {
Expand All @@ -52,44 +50,15 @@ func (m *nfsMount) isMounted() bool {
}

func (m *nfsMount) incRef(ctx context.Context, apiClient *apiclient.ApiClient) error {
logger := log.Ctx(ctx)
m.lock.Lock()
defer m.lock.Unlock()
if m.refCount < 0 {
logger.Error().Str("mount_point", m.mountPoint).Int("refcount", m.refCount).Msg("During incRef negative refcount encountered")
m.refCount = 0 // to make sure that we don't have negative refcount later
}
if m.refCount == 0 {
if err := m.doMount(ctx, apiClient, m.mountOptions); err != nil {
return err
}
} else if !m.isMounted() {
logger.Warn().Str("mount_point", m.mountPoint).Int("refcount", m.refCount).Msg("Mount not exists although should!")
if err := m.doMount(ctx, apiClient, m.mountOptions); err != nil {
return err
}

if err := m.doMount(ctx, apiClient, m.mountOptions); err != nil {
return err
}
m.refCount++
logger.Trace().Int("refcount", m.refCount).Strs("mount_options", m.mountOptions.Strings()).Str("filesystem_name", m.fsName).Msg("RefCount increased")
return nil
}

func (m *nfsMount) decRef(ctx context.Context) error {
logger := log.Ctx(ctx)
m.lock.Lock()
defer m.lock.Unlock()
m.refCount--
m.lastUsed = time.Now()
logger.Trace().Int("refcount", m.refCount).Strs("mount_options", m.mountOptions.Strings()).Str("filesystem_name", m.fsName).Msg("RefCount decreased")
if m.refCount < 0 {
logger.Error().Int("refcount", m.refCount).Msg("During decRef negative refcount encountered")
m.refCount = 0 // to make sure that we don't have negative refcount later
}
if m.refCount == 0 {
if err := m.doUnmount(ctx); err != nil {
return err
}
if err := m.doUnmount(ctx); err != nil {
return err
}
return nil
}
Expand Down

0 comments on commit b01ce5e

Please sign in to comment.