Skip to content

Commit

Permalink
Merge pull request #201 from rhatdan/mountopt
Browse files Browse the repository at this point in the history
Fix overlay to handle mountopt properly
  • Loading branch information
rhatdan authored Jul 25, 2018
2 parents 7098fdc + 2569af9 commit afdedba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
15 changes: 8 additions & 7 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,11 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {

workDir := path.Join(dir, "work")
opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(absLowers, ":"), diffDir, workDir)
if d.options.mountOptions != "" {
opts = fmt.Sprintf("%s,%s", d.options.mountOptions, opts)
}
mountData := label.FormatMountLabel(opts, mountLabel)
mount := unix.Mount
mountFunc := unix.Mount
mountTarget := mergedDir

pageSize := unix.Getpagesize()
Expand All @@ -719,28 +722,26 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {
if len(mountData) > pageSize || d.options.mountProgram != "" {
//FIXME: We need to figure out to get this to work with additional stores
opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(relLowers, ":"), path.Join(id, "diff"), path.Join(id, "work"))
if d.options.mountOptions != "" {
opts = fmt.Sprintf("%s,%s", d.options.mountOptions, opts)
}
mountData = label.FormatMountLabel(opts, mountLabel)
if len(mountData) > pageSize {
return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))
}

if d.options.mountProgram != "" {
mount = func(source string, target string, mType string, flags uintptr, label string) error {
mountFunc = func(source string, target string, mType string, flags uintptr, label string) error {
mountProgram := exec.Command(d.options.mountProgram, "-o", label, target)
mountProgram.Dir = d.home
return mountProgram.Run()
}
} else {
mount = func(source string, target string, mType string, flags uintptr, label string) error {
mountFunc = func(source string, target string, mType string, flags uintptr, label string) error {
return mountFrom(d.home, source, target, mType, flags, label)
}
}
mountTarget = path.Join(id, "merged")
}
if err := mount("overlay", mountTarget, "overlay", 0, mountData); err != nil {
flags, data := mount.ParseOptions(mountData)
if err := mountFunc("overlay", mountTarget, "overlay", uintptr(flags), data); err != nil {
return "", fmt.Errorf("error creating overlay mount to %s: %v", mountTarget, err)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/mount/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func MergeTmpfsOptions(options []string) ([]string, error) {
return newOptions, nil
}

// Parse fstab type mount options into mount() flags
// ParseOptions parses fstab type mount options into mount() flags
// and device specific data
func parseOptions(options string) (int, string) {
func ParseOptions(options string) (int, string) {
var (
flag int
data []string
Expand All @@ -138,7 +138,7 @@ func parseOptions(options string) (int, string) {

// ParseTmpfsOptions parse fstab type mount options into flags and data
func ParseTmpfsOptions(options string) (int, string, error) {
flags, data := parseOptions(options)
flags, data := ParseOptions(options)
for _, o := range strings.Split(data, ",") {
opt := strings.SplitN(o, "=", 2)
if !validFlags[opt[0]] {
Expand Down
4 changes: 2 additions & 2 deletions pkg/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Mounted(mountpoint string) (bool, error) {
// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See
// flags.go for supported option flags.
func Mount(device, target, mType, options string) error {
flag, _ := parseOptions(options)
flag, _ := ParseOptions(options)
if flag&REMOUNT != REMOUNT {
if mounted, err := Mounted(target); err != nil || mounted {
return err
Expand All @@ -53,7 +53,7 @@ func Mount(device, target, mType, options string) error {
// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See
// flags.go for supported option flags.
func ForceMount(device, target, mType, options string) error {
flag, data := parseOptions(options)
flag, data := ParseOptions(options)
return mount(device, target, mType, uintptr(flag), data)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/mount/mount_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestMountOptionsParsing(t *testing.T) {
options := "noatime,ro,size=10k"

flag, data := parseOptions(options)
flag, data := ParseOptions(options)

if data != "size=10k" {
t.Fatalf("Expected size=10 got %s", data)
Expand Down

0 comments on commit afdedba

Please sign in to comment.