Fixes cross platform build failure

Closes #51358
pull/6/head
Serguei Bezverkhi 2017-08-25 16:47:33 -04:00
parent acdf625e46
commit f2e89886a1
3 changed files with 19 additions and 16 deletions

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"github.com/golang/glog" "github.com/golang/glog"
"os" "os"
"syscall"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/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 { if len(refs) > 0 {
fsGroupNew := int64(*fsGroup) fsGroupNew := int64(*fsGroup)
fsGroupSame, fsGroupOld, err := isSameFSGroup(m.globalPath, fsGroupNew) fsGroupSame, fsGroupOld, err := volume.IsSameFSGroup(m.globalPath, fsGroupNew)
if err != nil { if err != nil {
err = fmt.Errorf("failed to check fsGroup for %s (%v)", m.globalPath, err) err = fmt.Errorf("failed to check fsGroup for %s (%v)", m.globalPath, err)
return err return err
@ -293,20 +292,6 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
return nil 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 { type localVolumeUnmounter struct {
*localVolume *localVolume
} }

View File

@ -89,3 +89,17 @@ func SetVolumeOwnership(mounter Mounter, fsGroup *int64) error {
return nil 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
}

View File

@ -21,3 +21,7 @@ package volume
func SetVolumeOwnership(mounter Mounter, fsGroup *int64) error { func SetVolumeOwnership(mounter Mounter, fsGroup *int64) error {
return nil return nil
} }
func IsSameFSGroup(dir string, fsGroup int64) (bool, int, error) {
return true, int(fsGroup), nil
}