Skip to content

Commit

Permalink
fix: handle overlay xattr opaque bit
Browse files Browse the repository at this point in the history
Current behavior determines if a path is a whiteout if a overlay char
dev is present.

Additionally, also check the extended attrs.

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha committed Mar 25, 2024
1 parent 555a0af commit fc29e2e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/opencontainers/runc v1.1.8
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.9
github.com/rootless-containers/proto/go-proto v0.0.0-20230421021042-4cd87ebadd67
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.12
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.m
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE=
github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -123,6 +125,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
4 changes: 2 additions & 2 deletions oci/layer/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func GenerateLayer(path string, deltas []mtree.InodeDelta, opt *RepackOptions) (
return errors.Wrapf(err, "couldn't determine overlay whiteout for %s", fullPath)
}

whiteout, err := isOverlayWhiteout(fi)
whiteout, err := isOverlayWhiteout(fi, fullPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func GenerateInsertLayer(root string, target string, opaque bool, opt *RepackOpt
}

pathInTar := path.Join(target, curPath[len(root):])
whiteout, err := isOverlayWhiteout(info)
whiteout, err := isOverlayWhiteout(info, filepath.Join(curPath, info.Name()))
if err != nil {
return err
}
Expand Down
19 changes: 16 additions & 3 deletions oci/layer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package layer

import (
"archive/tar"
"fmt"
"os"
"path/filepath"
"syscall"
Expand All @@ -27,6 +28,7 @@ import (
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/umoci/pkg/idtools"
"github.com/pkg/errors"
"github.com/pkg/xattr"
rootlesscontainers "github.com/rootless-containers/proto/go-proto"
"golang.org/x/sys/unix"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -230,7 +232,7 @@ func InnerErrno(err error) error {

// isOverlayWhiteout returns true if the FileInfo represents an overlayfs style
// whiteout (i.e. mknod c 0 0) and false otherwise.
func isOverlayWhiteout(info os.FileInfo) (bool, error) {
func isOverlayWhiteout(info os.FileInfo, path string) (bool, error) {
var major, minor uint32
switch stat := info.Sys().(type) {
case *unix.Stat_t:
Expand All @@ -243,6 +245,17 @@ func isOverlayWhiteout(info os.FileInfo) (bool, error) {
return false, errors.Errorf("[internal error] unknown stat info type %T", info.Sys())
}

return major == 0 && minor == 0 &&
info.Mode()&os.ModeCharDevice != 0, nil
if major == 0 && minor == 0 &&
info.Mode()&os.ModeCharDevice != 0 {
return true, nil
}

attr, err := xattr.LGet("user.overlay.opaque", path)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return false, errors.Errorf("[internal error] failed to get extended attrs for %s, err:%v", path, err)
}

fmt.Printf("ATTR=%+v\n", attr)

return false, nil
}
3 changes: 3 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ github.com/opencontainers/runtime-spec/specs-go
# github.com/pkg/errors v0.9.1
## explicit
github.com/pkg/errors
# github.com/pkg/xattr v0.4.9
## explicit; go 1.14
github.com/pkg/xattr
# github.com/pmezard/go-difflib v1.0.0
## explicit
github.com/pmezard/go-difflib/difflib
Expand Down

0 comments on commit fc29e2e

Please sign in to comment.