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 11, 2024
1 parent 5f606ed commit 844dce9
Showing 1 changed file with 5 additions and 37 deletions.
42 changes: 5 additions & 37 deletions pkg/wekafs/nfsmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"time"
)

type nfsMount struct {
fsName string
mountPoint string
refCount int
lock sync.Mutex
kMounter mount.Interface
debugPath string
mountOptions MountOptions
Expand All @@ -33,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 @@ -53,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 844dce9

Please sign in to comment.