Skip to content

Commit

Permalink
Merge 92de2a0 into 69730e1
Browse files Browse the repository at this point in the history
  • Loading branch information
clintkitson committed Dec 15, 2015
2 parents 69730e1 + 92de2a0 commit 073cb19
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .docs/user-guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,32 @@ will cause issues if *multiple containers* are sharing a volume. If you are
sharing volumes, it is recommended that you reset the service along with the
accompanying container runtime (if this setting is false) to ensure they are
synchronized.

## Volume Path (0.3.1)
When volumes are mounted there can be an additional path that is specified to
be created and passed as the valid mount point. This is required for certain
applications that do not want to place data from the root of a mount point.
The default is the `/data` path. If a value is set by `linux.volume.rootPath`,
then the default will be overwritten.

If upgrading to 0.3.1 then you can either set this to an empty value, or move
the internal directory in your existing volumes to `/data`.

```yaml
rexray:
linux:
volume:
rootPath: /data
```

## Volume FileMode (0.3.1)
The permissions of the `linux.volume.rootPath` can be set to default values. At
each mount, the permissions will be written based on this value. The default
is to include the `0700` mode.

```yaml
rexray:
linux:
volume:
fileMode: 0700
```
36 changes: 36 additions & 0 deletions drivers/os/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

log "github.com/Sirupsen/logrus"
"github.com/akutz/gofig"
"github.com/akutz/goof"
"github.com/docker/docker/pkg/mount"
"github.com/opencontainers/runc/libcontainer/label"
Expand All @@ -21,6 +22,7 @@ const providerName = "linux"

func init() {
core.RegisterDriver(providerName, newDriver)
gofig.Register(configRegistration())
}

type driver struct {
Expand Down Expand Up @@ -90,13 +92,25 @@ func (d *driver) nfsMount(device, target string) error {
return nil
}

func (d *driver) fileModeMountPath() (fileMode os.FileMode) {
return os.FileMode(d.volumeFileMode())
}

func (d *driver) Mount(
device, target, mountOptions, mountLabel string) error {

if d.isNfsDevice(device) {
if err := d.Unmount(target); err != nil {
return err
}

if err := d.nfsMount(device, target); err != nil {
return err
}

os.MkdirAll(d.volumeMountPath(target), d.fileModeMountPath())
os.Chmod(d.volumeMountPath(target), d.fileModeMountPath())

return nil
}

Expand All @@ -119,6 +133,9 @@ func (d *driver) Mount(
return fmt.Errorf("Couldn't mount directory %s at %s: %s", device, target, err)
}

os.MkdirAll(d.volumeMountPath(target), d.fileModeMountPath())
os.Chmod(d.volumeMountPath(target), d.fileModeMountPath())

return nil
}

Expand Down Expand Up @@ -213,3 +230,22 @@ func probeFsType(device string) (string, error) {

return "", errors.ErrUnknownFileSystem
}

func (d *driver) volumeMountPath(target string) string {
return fmt.Sprintf("%s%s", target, d.volumeRootPath())
}

func (d *driver) volumeFileMode() int {
return d.r.Config.GetInt("linux.volume.filemode")
}

func (d *driver) volumeRootPath() string {
return d.r.Config.GetString("linux.volume.rootpath")
}

func configRegistration() *gofig.Registration {
r := gofig.NewRegistration("Linux")
r.Key(gofig.Int, "", 0700, "", "linux.volume.filemode")
r.Key(gofig.String, "", "/data", "", "linux.volume.rootpath")
return r
}
15 changes: 12 additions & 3 deletions drivers/volume/docker/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (d *driver) Mount(volumeName, volumeID string, overwriteFs bool, newFsType
}

if len(mounts) > 0 {
return mounts[0].Mountpoint, nil
return d.volumeMountPath(mounts[0].Mountpoint), nil
}

switch {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (d *driver) Mount(volumeName, volumeID string, overwriteFs bool, newFsType
return "", err
}

return mountPath, nil
return d.volumeMountPath(mountPath), nil
}

// Unmount will perform the steps to unmount and existing volume and detach
Expand Down Expand Up @@ -269,7 +269,7 @@ func (d *driver) Path(volumeName, volumeID string) (string, error) {
return "", nil
}

return mounts[0].Mountpoint, nil
return d.volumeMountPath(mounts[0].Mountpoint), nil
}

// Create will create a remote volume
Expand Down Expand Up @@ -674,11 +674,20 @@ func (d *driver) NetworkName(volumeName, instanceID string) (string, error) {
return volumes[0].NetworkName, nil
}

func (d *driver) volumeMountPath(target string) string {
return fmt.Sprintf("%s%s", target, d.volumeRootPath())
}

func (d *driver) volumeRootPath() string {
return d.r.Config.GetString("linux.volume.rootPath")
}

func configRegistration() *gofig.Registration {
r := gofig.NewRegistration("Docker")
r.Key(gofig.String, "", "", "", "docker.volumeType")
r.Key(gofig.Int, "", 0, "", "docker.iops")
r.Key(gofig.Int, "", 0, "", "docker.size")
r.Key(gofig.String, "", "", "", "docker.availabilityZone")
r.Key(gofig.String, "", "/data", "", "linux.volume.rootpath")
return r
}

0 comments on commit 073cb19

Please sign in to comment.