From cedfceded548ef3b8d80b4e46e64dbaa9de8bd93 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 25 Aug 2025 03:38:12 +0900 Subject: [PATCH] container/autoroot: remove prefix field This field has been a noop for a long time. Remove it to prevent further confusion. Signed-off-by: Ophestra --- container/autoroot.go | 10 ++-- container/autoroot_test.go | 85 +++++++++++-------------------- internal/app/app_pd_linux_test.go | 4 +- internal/app/container_linux.go | 2 +- 4 files changed, 37 insertions(+), 64 deletions(-) diff --git a/container/autoroot.go b/container/autoroot.go index e1c397c..69595c2 100644 --- a/container/autoroot.go +++ b/container/autoroot.go @@ -10,14 +10,13 @@ func init() { gob.Register(new(AutoRootOp)) } // Root appends an [Op] that expands a directory into a toplevel bind mount mirror on container root. // This is not a generic setup op. It is implemented here to reduce ipc overhead. -func (f *Ops) Root(host *Absolute, prefix string, flags int) *Ops { - *f = append(*f, &AutoRootOp{host, prefix, flags, nil}) +func (f *Ops) Root(host *Absolute, flags int) *Ops { + *f = append(*f, &AutoRootOp{host, flags, nil}) return f } type AutoRootOp struct { - Host *Absolute - Prefix string + Host *Absolute // passed through to bindMount Flags int @@ -71,12 +70,11 @@ func (r *AutoRootOp) Is(op Op) bool { vr, ok := op.(*AutoRootOp) return ok && r.Valid() && vr.Valid() && r.Host.Is(vr.Host) && - r.Prefix == vr.Prefix && r.Flags == vr.Flags } func (*AutoRootOp) prefix() string { return "setting up" } func (r *AutoRootOp) String() string { - return fmt.Sprintf("auto root %q prefix %s flags %#x", r.Host, r.Prefix, r.Flags) + return fmt.Sprintf("auto root %q flags %#x", r.Host, r.Flags) } // IsAutoRootBindable returns whether a dir entry name is selected for AutoRoot. diff --git a/container/autoroot_test.go b/container/autoroot_test.go index eb4d594..fcfc3f2 100644 --- a/container/autoroot_test.go +++ b/container/autoroot_test.go @@ -10,24 +10,22 @@ import ( func TestAutoRootOp(t *testing.T) { t.Run("nonrepeatable", func(t *testing.T) { wantErr := msg.WrapErr(fs.ErrInvalid, "autoroot is not repeatable") - if err := (&AutoRootOp{Prefix: "81ceabb30d37bbdb3868004629cb84e9"}).apply(&setupState{nonrepeatable: nrAutoRoot}, nil); !errors.Is(err, wantErr) { + if err := new(AutoRootOp).apply(&setupState{nonrepeatable: nrAutoRoot}, nil); !errors.Is(err, wantErr) { t.Errorf("apply: error = %v, want %v", err, wantErr) } }) checkOpBehaviour(t, []opBehaviourTestCase{ {"readdir", &Params{ParentPerm: 0750}, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: "81ceabb30d37bbdb3868004629cb84e9", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, []kexpect{ {"readdir", expectArgs{"/"}, stubDir(), errUnique}, }, wrapErrSelf(errUnique), nil, nil}, {"early", &Params{ParentPerm: 0750}, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: "81ceabb30d37bbdb3868004629cb84e9", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, []kexpect{ {"readdir", expectArgs{"/"}, stubDir("bin", "dev", "etc", "home", "lib64", "lost+found", "mnt", "nix", "proc", "root", "run", "srv", "sys", "tmp", "usr", "var"), nil}, @@ -35,9 +33,8 @@ func TestAutoRootOp(t *testing.T) { }, wrapErrSelf(errUnique), nil, nil}, {"apply", &Params{ParentPerm: 0750}, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: "81ceabb30d37bbdb3868004629cb84e9", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, []kexpect{ {"readdir", expectArgs{"/"}, stubDir("bin", "dev", "etc", "home", "lib64", "lost+found", "mnt", "nix", "proc", "root", "run", "srv", "sys", "tmp", "usr", "var"), nil}, @@ -58,9 +55,8 @@ func TestAutoRootOp(t *testing.T) { }, wrapErrSelf(errUnique)}, {"success pd", &Params{ParentPerm: 0750}, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: "81ceabb30d37bbdb3868004629cb84e9", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, []kexpect{ {"readdir", expectArgs{"/"}, stubDir("bin", "dev", "etc", "home", "lib64", "lost+found", "mnt", "nix", "proc", "root", "run", "srv", "sys", "tmp", "usr", "var"), nil}, @@ -90,8 +86,7 @@ func TestAutoRootOp(t *testing.T) { }, nil}, {"success", &Params{ParentPerm: 0750}, &AutoRootOp{ - Host: MustAbs("/var/lib/planterette/base/debian:f92c9052"), - Prefix: "81ceabb30d37bbdb3868004629cb84e9", + Host: MustAbs("/var/lib/planterette/base/debian:f92c9052"), }, []kexpect{ {"readdir", expectArgs{"/var/lib/planterette/base/debian:f92c9052"}, stubDir("bin", "dev", "etc", "home", "lib64", "lost+found", "mnt", "nix", "proc", "root", "run", "srv", "sys", "tmp", "usr", "var"), nil}, @@ -128,11 +123,10 @@ func TestAutoRootOp(t *testing.T) { }) checkOpsBuilder(t, []opsBuilderTestCase{ - {"pd", new(Ops).Root(MustAbs("/"), "048090b6ed8f9ebb10e275ff5d8c0659", BindWritable), Ops{ + {"pd", new(Ops).Root(MustAbs("/"), BindWritable), Ops{ &AutoRootOp{ - Host: MustAbs("/"), - Prefix: "048090b6ed8f9ebb10e275ff5d8c0659", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, }}, }) @@ -141,63 +135,44 @@ func TestAutoRootOp(t *testing.T) { {"zero", new(AutoRootOp), new(AutoRootOp), false}, {"internal ne", &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, &AutoRootOp{ Host: MustAbs("/"), - Prefix: ":3", Flags: BindWritable, resolved: []Op{new(BindMountOp)}, }, true}, - {"prefix differs", &AutoRootOp{ - Host: MustAbs("/"), - Prefix: "\x00", - Flags: BindWritable, - }, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, - }, false}, - {"flags differs", &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable | BindDevice, + Host: MustAbs("/"), + Flags: BindWritable | BindDevice, }, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, false}, {"host differs", &AutoRootOp{ - Host: MustAbs("/tmp/"), - Prefix: ":3", - Flags: BindWritable, + Host: MustAbs("/tmp/"), + Flags: BindWritable, }, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, false}, {"equals", &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, + Host: MustAbs("/"), + Flags: BindWritable, }, true}, }) checkOpMeta(t, []opMetaTestCase{ {"root", &AutoRootOp{ - Host: MustAbs("/"), - Prefix: ":3", - Flags: BindWritable, - }, "setting up", `auto root "/" prefix :3 flags 0x2`}, + Host: MustAbs("/"), + Flags: BindWritable, + }, "setting up", `auto root "/" flags 0x2`}, }) } diff --git a/internal/app/app_pd_linux_test.go b/internal/app/app_pd_linux_test.go index 96182d3..f3ce4cd 100644 --- a/internal/app/app_pd_linux_test.go +++ b/internal/app/app_pd_linux_test.go @@ -43,7 +43,7 @@ var testCasesPd = []sealTestCase{ "XDG_SESSION_TYPE=tty", }, Ops: new(container.Ops). - Root(m("/"), "4a450b6596d7bc15bd01780eb9a607ac", container.BindWritable). + Root(m("/"), container.BindWritable). Proc(m("/proc/")). Tmpfs(hst.AbsTmp, 4096, 0755). DevWritable(m("/dev/"), true). @@ -179,7 +179,7 @@ var testCasesPd = []sealTestCase{ "XDG_SESSION_TYPE=tty", }, Ops: new(container.Ops). - Root(m("/"), "ebf083d1b175911782d413369b64ce7c", container.BindWritable). + Root(m("/"), container.BindWritable). Proc(m("/proc/")). Tmpfs(hst.AbsTmp, 4096, 0755). DevWritable(m("/dev/"), true). diff --git a/internal/app/container_linux.go b/internal/app/container_linux.go index 2d0a236..b82a6b6 100644 --- a/internal/app/container_linux.go +++ b/internal/app/container_linux.go @@ -75,7 +75,7 @@ func newContainer(s *hst.ContainerConfig, os sys.State, prefix string, uid, gid } if s.AutoRoot != nil { - params.Root(s.AutoRoot, prefix, s.RootFlags) + params.Root(s.AutoRoot, s.RootFlags) } params.