Skip to content

Commit 56927bc

Browse files
ayushr2gvisor-bot
authored andcommitted
Exclude adding the self filestore whiteout to rootfs upper layer TAR archive.
Fixes #12056 PiperOrigin-RevId: 798050567
1 parent b60a9bd commit 56927bc

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

pkg/fsutil/fsutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package fsutil
1818

1919
import "golang.org/x/sys/unix"
2020

21+
// SelfFilestorePrefix is the prefix of the self filestore file name.
22+
const SelfFilestorePrefix = ".gvisor.filestore."
23+
2124
// DirentHandler is a function that handles a dirent.
2225
type DirentHandler func(ino uint64, off int64, ftype uint8, name string, reclen uint16)
2326

pkg/sentry/fsimpl/tmpfs/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ go_library(
106106
"//pkg/errors/linuxerr",
107107
"//pkg/fd",
108108
"//pkg/fspath",
109+
"//pkg/fsutil",
109110
"//pkg/hostarch",
110111
"//pkg/log",
111112
"//pkg/refs",

pkg/sentry/fsimpl/tmpfs/device_file.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ package tmpfs
1616

1717
import (
1818
"fmt"
19+
"strings"
1920

2021
"gvisor.dev/gvisor/pkg/abi/linux"
2122
"gvisor.dev/gvisor/pkg/atomicbitops"
23+
"gvisor.dev/gvisor/pkg/fsutil"
2224
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
2325
"gvisor.dev/gvisor/pkg/sentry/vfs"
2426
)
@@ -31,6 +33,18 @@ type deviceFile struct {
3133
minor uint32
3234
}
3335

36+
// Precondition: fs.mu must be locked for at least reading.
37+
func (d *dentry) isSelfFilestoreWhiteout() bool {
38+
if !strings.HasPrefix(d.name, fsutil.SelfFilestorePrefix) {
39+
return false
40+
}
41+
dev, ok := d.inode.impl.(*deviceFile)
42+
if !ok {
43+
return false
44+
}
45+
return d.inode.fs.ovlWhiteout == dev
46+
}
47+
3448
func isOvlWhiteoutDev(mode linux.FileMode, major, minor uint32) bool {
3549
return mode.FileType() == linux.S_IFCHR &&
3650
mode.Permissions() == linux.WHITEOUT_MODE &&

pkg/sentry/fsimpl/tmpfs/tar.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func (d *dentry) writeToTar(ctx context.Context, tw *tar.Writer, baseDir string,
8888

8989
// createTarHeader creates a tar header for the given dentry.
9090
func (d *dentry) createTarHeader(path string, inoToPath map[uint64]string) (*tar.Header, error) {
91+
if d.isSelfFilestoreWhiteout() {
92+
// Skip the self filestore whiteout.
93+
return nil, nil
94+
}
95+
9196
header := &tar.Header{
9297
Name: path,
9398
Mode: int64(d.inode.mode.Load() & ^uint32(linux.S_IFMT)),

runsc/boot/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ go_library(
4747
"//pkg/fd",
4848
"//pkg/flipcall",
4949
"//pkg/fspath",
50+
"//pkg/fsutil",
5051
"//pkg/gomaxprocs",
5152
"//pkg/hostos",
5253
"//pkg/log",

runsc/boot/vfs.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"gvisor.dev/gvisor/pkg/errors/linuxerr"
3535
"gvisor.dev/gvisor/pkg/fd"
3636
"gvisor.dev/gvisor/pkg/fspath"
37+
"gvisor.dev/gvisor/pkg/fsutil"
3738
"gvisor.dev/gvisor/pkg/log"
3839
"gvisor.dev/gvisor/pkg/sentry/devices/memdev"
3940
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
@@ -70,9 +71,6 @@ const (
7071
Nonefs = "none"
7172
)
7273

73-
// SelfFilestorePrefix is the prefix of the self filestore file name.
74-
const SelfFilestorePrefix = ".gvisor.filestore."
75-
7674
// SelfFilestorePath returns the path at which the self filestore file is
7775
// stored for a given mount.
7876
func SelfFilestorePath(mountSrc, sandboxID string) string {
@@ -84,7 +82,7 @@ func SelfFilestorePath(mountSrc, sandboxID string) string {
8482
}
8583

8684
func selfFilestoreName(sandboxID string) string {
87-
return SelfFilestorePrefix + sandboxID
85+
return fsutil.SelfFilestorePrefix + sandboxID
8886
}
8987

9088
// tmpfs has some extra supported options that we must pass through.

test/e2e/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ go_test(
4444
],
4545
visibility = ["//:sandbox"],
4646
deps = [
47+
"//pkg/fsutil",
4748
"//pkg/test/dockerutil",
4849
"//pkg/test/testutil",
49-
"//runsc/boot",
5050
"@com_github_docker_docker//api/types/mount:go_default_library",
5151
"@org_golang_x_sys//unix:go_default_library",
5252
],

test/e2e/integration_runtime_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ import (
3636

3737
"github.com/docker/docker/api/types/mount"
3838
"golang.org/x/sys/unix"
39+
"gvisor.dev/gvisor/pkg/fsutil"
3940
"gvisor.dev/gvisor/pkg/test/dockerutil"
4041
"gvisor.dev/gvisor/pkg/test/testutil"
41-
"gvisor.dev/gvisor/runsc/boot"
4242
)
4343

4444
const (
@@ -237,10 +237,10 @@ func TestOverlayRootfsWhiteout(t *testing.T) {
237237
opts := dockerutil.RunOpts{
238238
Image: "basic/ubuntu",
239239
}
240-
if got, err := d.Run(ctx, opts, "bash", "-c", fmt.Sprintf("ls -al / | grep %q || true", boot.SelfFilestorePrefix)); err != nil {
240+
if got, err := d.Run(ctx, opts, "bash", "-c", fmt.Sprintf("ls -al / | grep %q || true", fsutil.SelfFilestorePrefix)); err != nil {
241241
t.Fatalf("docker run failed: %s, %v", got, err)
242242
} else if got != "" {
243-
t.Errorf("root directory contains a file/directory whose name contains %q: output = %q", boot.SelfFilestorePrefix, got)
243+
t.Errorf("root directory contains a file/directory whose name contains %q: output = %q", fsutil.SelfFilestorePrefix, got)
244244
}
245245
}
246246

0 commit comments

Comments
 (0)