Repository navigation
ateom-gvisor: take the actor directories from the request #1865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Benjamin Elder (BenTheElder)
merged 2 commits into
agent-substrate:main
from
HavenXia:ateom-gvisor-dirs
Sep 28, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //go:build linux | ||
|
|
||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // The paths ateom-gvisor derives from the ActorDirs atelet sends. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/agent-substrate/substrate/internal/imagecache" | ||
| "github.com/agent-substrate/substrate/internal/proto/ateompb" | ||
| ) | ||
|
|
||
| // ociBundlePath is the container's OCI bundle. | ||
| func ociBundlePath(actorDirs *ateompb.ActorDirs, containerName string) string { | ||
| return filepath.Join(actorDirs.GetOciBundleDir(), containerName) | ||
| } | ||
|
|
||
| // runscStateDir is runsc --root for the actor's sandbox. | ||
| func runscStateDir(actorDirs *ateompb.ActorDirs) string { | ||
| return filepath.Join(actorDirs.GetRootDir(), "runsc-state") | ||
| } | ||
|
|
||
| // pidFileDir is where runsc writes <container>.pid. | ||
| func pidFileDir(actorDirs *ateompb.ActorDirs) string { | ||
| return filepath.Join(actorDirs.GetRootDir(), "pidfiles") | ||
| } | ||
|
|
||
| // pidFilePath is where runsc writes the container's pid. | ||
| func pidFilePath(actorDirs *ateompb.ActorDirs, containerName string) string { | ||
| return filepath.Join(pidFileDir(actorDirs), containerName+".pid") | ||
| } | ||
|
|
||
| // resolvConfPath is the resolver bind source outside the actor's rootfs. | ||
| func resolvConfPath(actorDirs *ateompb.ActorDirs) string { | ||
| return filepath.Join(actorDirs.GetRootDir(), "resolv.conf") | ||
| } | ||
|
|
||
| // resetRunscStateAndPidFileDirs empties both directories for a new activation. | ||
| // runsc can leave mounts behind in its state directory (its null-netns), which | ||
| // must be detached in this mount namespace before they can be removed. | ||
| func resetRunscStateAndPidFileDirs(actorDirs *ateompb.ActorDirs) error { | ||
| for _, dir := range []string{runscStateDir(actorDirs), pidFileDir(actorDirs)} { | ||
| if err := imagecache.UnmountAllUnder(dir); err != nil { | ||
| return fmt.Errorf("while unmounting under %q: %w", dir, err) | ||
| } | ||
| if err := os.RemoveAll(dir); err != nil { | ||
| return fmt.Errorf("while clearing %q: %w", dir, err) | ||
| } | ||
| if err := os.MkdirAll(dir, 0o700); err != nil { | ||
| return fmt.Errorf("while creating %q: %w", dir, err) | ||
| } | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //go:build linux | ||
|
|
||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
|
|
||
| "github.com/agent-substrate/substrate/internal/proto/ateompb" | ||
| "github.com/agent-substrate/substrate/internal/roottest" | ||
| ) | ||
|
|
||
| func TestResetRunscStateAndPidFileDirs(t *testing.T) { | ||
| actorDirs := &ateompb.ActorDirs{RootDir: t.TempDir()} | ||
| if err := os.MkdirAll(filepath.Join(runscStateDir(actorDirs), "stale"), 0o700); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := resetRunscStateAndPidFileDirs(actorDirs); err != nil { | ||
| t.Fatalf("resetRunscStateAndPidFileDirs() = %v", err) | ||
| } | ||
| for _, dir := range []string{runscStateDir(actorDirs), pidFileDir(actorDirs)} { | ||
| if entries, err := os.ReadDir(dir); err != nil || len(entries) != 0 { | ||
| t.Errorf("ReadDir(%q) = %v, %v; want an empty directory", dir, entries, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // runsc leaves mounts in its state directory; unlinking one fails with EBUSY | ||
| // until it is detached. | ||
| func TestResetRunscStateAndPidFileDirs_DetachesMounts(t *testing.T) { | ||
| roottest.Require(t, "mount/unmount") | ||
| actorDirs := &ateompb.ActorDirs{RootDir: t.TempDir()} | ||
| if err := os.MkdirAll(runscStateDir(actorDirs), 0o700); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| src := filepath.Join(t.TempDir(), "netns") | ||
| target := filepath.Join(runscStateDir(actorDirs), "null-netns") | ||
| for _, f := range []string{src, target} { | ||
| if err := os.WriteFile(f, nil, 0o600); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| if err := unix.Mount(src, target, "", unix.MS_BIND, ""); err != nil { | ||
| t.Fatalf("bind mount: %v", err) | ||
| } | ||
| t.Cleanup(func() { _ = unix.Unmount(target, unix.MNT_DETACH) }) | ||
|
|
||
| if err := resetRunscStateAndPidFileDirs(actorDirs); err != nil { | ||
| t.Fatalf("resetRunscStateAndPidFileDirs() = %v", err) | ||
| } | ||
| if entries, err := os.ReadDir(runscStateDir(actorDirs)); err != nil || len(entries) != 0 { | ||
| t.Errorf("ReadDir(%q) = %v, %v; want an empty directory", runscStateDir(actorDirs), entries, err) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ import ( | |
|
|
||
| // durableTarFile is the snapshot file holding the tar of the actor's durable-dir | ||
| // volumes. Its entries are <volumeName>/... relative to | ||
| // ateompath.DurableDirVolumeMountsDir, so extraction restores the same layout. | ||
| // ActorDirs.durable_dir_volume_mounts_dir, so extraction restores the same layout. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still TODO to stop sharing this info entirely. |
||
| // The name is shared with atelet, which uses it to carve durable data out of a | ||
| // FULL snapshot's file set when uploading a paused checkpoint as DATA. | ||
| const durableTarFile = resources.DurableDirTarFile | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.