Skip to content

Commit

Permalink
overlay: honor ro option
Browse files Browse the repository at this point in the history
if "ro" is specified when mounting overlay, configure overlay without
any upper layer and workdir so the file system doesn't attempt to
write any file.

Closes: containers/buildah#2359

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed May 17, 2020
1 parent c37a306 commit cb48094
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,13 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
}
readWrite := true

for _, o := range options.Options {
if o == "ro" {
readWrite = false
break
}
}

lowers, err := ioutil.ReadFile(path.Join(dir, lowerFile))
if err != nil && !os.IsNotExist(err) {
return "", err
Expand Down Expand Up @@ -886,7 +893,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO

// if we are doing a readOnly mount, and there is only one lower
// We should just return the lower directory, no reason to mount.
if !readWrite {
if !readWrite && d.options.mountProgram == "" {
if len(absLowers) == 0 {
return path.Join(dir, "empty"), nil
}
Expand All @@ -904,10 +911,8 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
return "", err
}
diffDir := path.Join(dir, "diff")
if readWrite {
if err := idtools.MkdirAllAs(diffDir, 0755, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
}
if err := idtools.MkdirAllAs(diffDir, 0755, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
}

mergedDir := path.Join(dir, "merged")
Expand All @@ -932,7 +937,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
if readWrite {
opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(absLowers, ":"), diffDir, path.Join(dir, "work"))
} else {
opts = fmt.Sprintf("lowerdir=%s", strings.Join(absLowers, ":"))
opts = fmt.Sprintf("lowerdir=%s:%s", diffDir, strings.Join(absLowers, ":"))
}
if len(options.Options) > 0 {
opts = fmt.Sprintf("%s,%s", strings.Join(options.Options, ","), opts)
Expand Down

0 comments on commit cb48094

Please sign in to comment.