From f2e89886a1cd82b64c212b37a810b2c1192cb439 Mon Sep 17 00:00:00 2001 From: Serguei Bezverkhi Date: Fri, 25 Aug 2017 16:47:33 -0400 Subject: [PATCH] Fixes cross platform build failure Closes #51358 --- pkg/volume/local/local.go | 17 +---------------- pkg/volume/volume_linux.go | 14 ++++++++++++++ pkg/volume/volume_unsupported.go | 4 ++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index 122993d6d2..350d7ceb29 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -20,7 +20,6 @@ import ( "fmt" "github.com/golang/glog" "os" - "syscall" "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -233,7 +232,7 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { if len(refs) > 0 { fsGroupNew := int64(*fsGroup) - fsGroupSame, fsGroupOld, err := isSameFSGroup(m.globalPath, fsGroupNew) + fsGroupSame, fsGroupOld, err := volume.IsSameFSGroup(m.globalPath, fsGroupNew) if err != nil { err = fmt.Errorf("failed to check fsGroup for %s (%v)", m.globalPath, err) return err @@ -293,20 +292,6 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { return nil } -// isSameFSGroup is called only for requests to mount an already mounted -// volume. It checks if fsGroup of new mount request is the same or not. -// It returns false if it not the same. It also returns current Gid of a path -// provided for dir variable. -func isSameFSGroup(dir string, fsGroup int64) (bool, int, error) { - info, err := os.Stat(dir) - if err != nil { - glog.Errorf("Error getting stats for %s (%v)", dir, err) - return false, 0, err - } - s := info.Sys().(*syscall.Stat_t) - return int(s.Gid) == int(fsGroup), int(s.Gid), nil -} - type localVolumeUnmounter struct { *localVolume } diff --git a/pkg/volume/volume_linux.go b/pkg/volume/volume_linux.go index ef1f45208c..d67ee4a95a 100644 --- a/pkg/volume/volume_linux.go +++ b/pkg/volume/volume_linux.go @@ -89,3 +89,17 @@ func SetVolumeOwnership(mounter Mounter, fsGroup *int64) error { return nil }) } + +// IsSameFSGroup is called only for requests to mount an already mounted +// volume. It checks if fsGroup of new mount request is the same or not. +// It returns false if it not the same. It also returns current Gid of a path +// provided for dir variable. +func IsSameFSGroup(dir string, fsGroup int64) (bool, int, error) { + info, err := os.Stat(dir) + if err != nil { + glog.Errorf("Error getting stats for %s (%v)", dir, err) + return false, 0, err + } + s := info.Sys().(*syscall.Stat_t) + return int(s.Gid) == int(fsGroup), int(s.Gid), nil +} diff --git a/pkg/volume/volume_unsupported.go b/pkg/volume/volume_unsupported.go index 45a6cc5ca7..46a6aeaf0a 100644 --- a/pkg/volume/volume_unsupported.go +++ b/pkg/volume/volume_unsupported.go @@ -21,3 +21,7 @@ package volume func SetVolumeOwnership(mounter Mounter, fsGroup *int64) error { return nil } + +func IsSameFSGroup(dir string, fsGroup int64) (bool, int, error) { + return true, int(fsGroup), nil +}