diff options
| author | garenchan <garenchan23@gmail.com> | 2022-07-07 10:39:55 +0800 |
|---|---|---|
| committer | garenchan <garenchan23@gmail.com> | 2022-07-07 10:39:55 +0800 |
| commit | 6ddcbbdcc3f7f3ad4c5eac20cff98fe46b0566a3 (patch) | |
| tree | 865285ad28cae33dd1ee2a61753d97c0365f24a2 /pkg/driver/utils.go | |
| parent | 96d415ad3e121518552629f31a7cbe6eee9c76e4 (diff) | |
| download | seaweedfs-csi-driver-6ddcbbdcc3f7f3ad4c5eac20cff98fe46b0566a3.tar.xz seaweedfs-csi-driver-6ddcbbdcc3f7f3ad4c5eac20cff98fe46b0566a3.zip | |
Pods using the same volume share mount
Diffstat (limited to 'pkg/driver/utils.go')
| -rw-r--r-- | pkg/driver/utils.go | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/pkg/driver/utils.go b/pkg/driver/utils.go index b783f99..0f45733 100644 --- a/pkg/driver/utils.go +++ b/pkg/driver/utils.go @@ -2,18 +2,23 @@ package driver import ( "fmt" + "os" "strings" + "sync" - "github.com/container-storage-interface/spec/lib/go/csi" "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util" + "github.com/container-storage-interface/spec/lib/go/csi" "golang.org/x/net/context" "google.golang.org/grpc" + "k8s.io/utils/mount" ) func NewNodeServer(n *SeaweedFsDriver) *NodeServer { return &NodeServer{ - Driver: n, + Driver: n, + volumeMutexes: NewKeyMutex(32), } } @@ -58,3 +63,39 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h glog.V(3).Infof("GRPC %s response %+v", info.FullMethod, resp) return resp, err } + +func checkMount(targetPath string) (bool, error) { + notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath) + if err != nil { + if os.IsNotExist(err) { + if err = os.MkdirAll(targetPath, 0750); err != nil { + return false, err + } + notMnt = true + } else { + return false, err + } + } + return notMnt, nil +} + +type KeyMutex struct { + mutexes []sync.RWMutex + size int32 +} + +func NewKeyMutex(size int32) *KeyMutex { + return &KeyMutex{ + mutexes: make([]sync.RWMutex, size), + size: size, + } +} + +func (km *KeyMutex) GetMutex(key string) *sync.RWMutex { + index := util.HashToInt32([]byte(key)) + if index < 0 { + index = -index + } + + return &km.mutexes[index%km.size] +} |
