glusterfs: Fix all gid types to int to prevent failures on 32bit systems

This makes all types int until we hand the GID to heketi/gluster,
at which point it's converted to int64.

It also limits the maximum usable GID ti math.MaxInt32 = 2147483647.

Signed-off-by: Michael Adam <obnox@redhat.com>
This commit is contained in:
Michael Adam 2016-12-05 22:33:35 +01:00
parent 06ad835e48
commit 8a1752f2bb
3 changed files with 27 additions and 20 deletions

View File

@ -94,7 +94,7 @@ When both `restuserkey` and `secretNamespace` + `secretName` is specified, the s
Example of a secret can be found in [glusterfs-provisioning-secret.yaml](glusterfs-provisioning-secret.yaml).
* `gidMin` + `gidMax` : The minimum and maximum value of GID range for the storage class. A unique value (GID) in this range ( gidMin-gidMax ) will be used for dynamically provisioned volumes. These are optional values. If not specified, the volume will be provisioned with a value between 2000-4294967295 which are defaults for gidMin and gidMax respectively.
* `gidMin` + `gidMax` : The minimum and maximum value of GID range for the storage class. A unique value (GID) in this range ( gidMin-gidMax ) will be used for dynamically provisioned volumes. These are optional values. If not specified, the volume will be provisioned with a value between 2000-2147483647 which are defaults for gidMin and gidMax respectively.
Reference : ([How to configure Heketi](https://github.com/heketi/heketi/wiki/Setting-up-the-topology))

View File

@ -72,8 +72,8 @@ const (
secretKeyName = "key" // key name used in secret
gciGlusterMountBinariesPath = "/sbin/mount.glusterfs"
defaultGidMin = 2000
defaultGidMax = math.MaxUint32
absoluteGidMax = math.MaxUint32
defaultGidMax = math.MaxInt32
absoluteGidMax = math.MaxInt32
)
func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
@ -392,8 +392,8 @@ type provisioningConfig struct {
secretName string
secretValue string
clusterId string
gidMin uint32
gidMax uint32
gidMin int
gidMax int
}
type glusterfsVolumeProvisioner struct {
@ -402,13 +402,20 @@ type glusterfsVolumeProvisioner struct {
options volume.VolumeOptions
}
func convertGid(inputGid string) (uint32, error) {
inputGid32, err := strconv.ParseUint(inputGid, 10, 32)
func convertGid(gidString string) (int, error) {
gid64, err := strconv.ParseInt(gidString, 10, 32)
if err != nil {
return 0, fmt.Errorf("glusterfs: failed to parse gid %v ", inputGid)
return 0, fmt.Errorf("glusterfs: failed to parse gid %v ", gidString)
}
outputGid := uint32(inputGid32)
return outputGid, nil
if gid64 < 0 {
return 0, fmt.Errorf("glusterfs: negative GIDs are not allowed: %v", gidString)
}
// ParseInt returns a int64, but since we parsed only
// for 32 bit, we can cast to int without loss:
gid := int(gid64)
return gid, nil
}
func (plugin *glusterfsPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
@ -473,7 +480,7 @@ func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocato
continue
}
_, err = gidTable.Allocate(int(gid))
_, err = gidTable.Allocate(gid)
if err == ErrConflict {
glog.Warningf("glusterfs: gid %v found in pv %v was already allocated", gid)
} else if err != nil {
@ -491,14 +498,14 @@ func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocato
// used in PVs of this storage class by traversing the PVs.
// - Adapt the range of the table to the current range of the SC.
//
func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32) (*MinMaxAllocator, error) {
func (p *glusterfsPlugin) getGidTable(className string, min int, max int) (*MinMaxAllocator, error) {
var err error
p.gidTableLock.Lock()
gidTable, ok := p.gidTable[className]
p.gidTableLock.Unlock()
if ok {
err = gidTable.SetRange(int(min), int(max))
err = gidTable.SetRange(min, max)
if err != nil {
return nil, err
}
@ -519,7 +526,7 @@ func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32)
}
// and only reduce the range afterwards
err = newGidTable.SetRange(int(min), int(max))
err = newGidTable.SetRange(min, max)
if err != nil {
return nil, err
}
@ -531,7 +538,7 @@ func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32)
gidTable, ok = p.gidTable[className]
if ok {
err = gidTable.SetRange(int(min), int(max))
err = gidTable.SetRange(min, max)
if err != nil {
return nil, err
}
@ -544,7 +551,7 @@ func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32)
return newGidTable, nil
}
func (d *glusterfsVolumeDeleter) getGid() (uint32, bool, error) {
func (d *glusterfsVolumeDeleter) getGid() (int, bool, error) {
gidStr, ok := d.spec.Annotations[volumehelper.VolumeGidAnnotationKey]
if !ok {
@ -583,7 +590,7 @@ func (d *glusterfsVolumeDeleter) Delete() error {
return fmt.Errorf("glusterfs: failed to get gidTable: %v", err)
}
err = gidTable.Release(int(gid))
err = gidTable.Release(gid)
if err != nil {
return fmt.Errorf("glusterfs: failed to release gid %v: %v", gid, err)
}

View File

@ -270,7 +270,7 @@ func TestParseClassParameters(t *testing.T) {
userKey: "password",
secretValue: "password",
gidMin: 2000,
gidMax: 4294967295,
gidMax: 2147483647,
},
},
{
@ -290,7 +290,7 @@ func TestParseClassParameters(t *testing.T) {
secretNamespace: "default",
secretValue: "mypassword",
gidMin: 2000,
gidMax: 4294967295,
gidMax: 2147483647,
},
},
{
@ -304,7 +304,7 @@ func TestParseClassParameters(t *testing.T) {
&provisioningConfig{
url: "https://localhost:8080",
gidMin: 2000,
gidMax: 4294967295,
gidMax: 2147483647,
},
},
{