summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-09-27 10:25:19 -0700
committerShentubot <shentubot@google.com>2018-09-27 10:26:34 -0700
commitb514ab05897bca53c1d4f71c912f2977b3134daf (patch)
treefd900cccf6d4f8d9fe9a54ec4ea1e8de13df1bb8
parent6910ff36434f4bc5aa8c6b3094b617c7c92a9803 (diff)
Refactor 'runsc boot' to take container ID as argument
This makes the flow slightly simpler (no need to call Loader.SetRootContainer). And this is required change to tag tasks with container ID inside the Sentry. PiperOrigin-RevId: 214795210 Change-Id: I6ff4af12e73bb07157f7058bb15fd5bb88760884
-rw-r--r--runsc/boot/controller.go1
-rw-r--r--runsc/boot/loader.go12
-rw-r--r--runsc/boot/loader_test.go3
-rw-r--r--runsc/cmd/boot.go6
-rw-r--r--runsc/sandbox/sandbox.go3
5 files changed, 14 insertions, 11 deletions
diff --git a/runsc/boot/controller.go b/runsc/boot/controller.go
index 7d7803e92..bc33e028a 100644
--- a/runsc/boot/controller.go
+++ b/runsc/boot/controller.go
@@ -171,7 +171,6 @@ func (cm *containerManager) StartRoot(cid *string, _ *struct{}) error {
if err := <-cm.startResultChan; err != nil {
return fmt.Errorf("failed to start sandbox: %v", err)
}
- cm.l.setRootContainerID(*cid)
return nil
}
diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go
index 5867eec96..9a5d649ab 100644
--- a/runsc/boot/loader.go
+++ b/runsc/boot/loader.go
@@ -142,7 +142,7 @@ func init() {
// New initializes a new kernel loader configured by spec.
// New also handles setting up a kernel for restoring a container.
-func New(spec *specs.Spec, conf *Config, controllerFD, deviceFD int, goferFDs []int, console bool) (*Loader, error) {
+func New(id string, spec *specs.Spec, conf *Config, controllerFD, deviceFD int, goferFDs []int, console bool) (*Loader, error) {
if err := usage.Init(); err != nil {
return nil, fmt.Errorf("Error setting up memory usage: %v", err)
}
@@ -286,6 +286,9 @@ func New(spec *specs.Spec, conf *Config, controllerFD, deviceFD int, goferFDs []
spec: spec,
startSignalForwarding: startSignalForwarding,
rootProcArgs: procArgs,
+ sandboxID: id,
+ containerRootTGs: make(map[string]*kernel.ThreadGroup),
+ execProcesses: make(map[execID]*kernel.ThreadGroup),
}
ctrl.manager.l = l
return l, nil
@@ -420,10 +423,9 @@ func (l *Loader) run() error {
l.rootProcArgs.FDMap.DecRef()
}
- if l.execProcesses != nil {
- return fmt.Errorf("there shouldn't already be a cache of exec'd processes, but found: %v", l.execProcesses)
- }
- l.execProcesses = make(map[execID]*kernel.ThreadGroup)
+ l.mu.Lock()
+ l.containerRootTGs[l.sandboxID] = l.k.GlobalInit()
+ l.mu.Unlock()
// Start signal forwarding only after an init process is created.
l.stopSignalForwarding = l.startSignalForwarding()
diff --git a/runsc/boot/loader_test.go b/runsc/boot/loader_test.go
index a8a796445..0b363253d 100644
--- a/runsc/boot/loader_test.go
+++ b/runsc/boot/loader_test.go
@@ -101,7 +101,7 @@ func createLoader() (*Loader, func(), error) {
return nil, nil, err
}
- l, err := New(spec, conf, fd, -1 /* device fd */, []int{sandEnd}, false)
+ l, err := New("foo", spec, conf, fd, -1 /* device fd */, []int{sandEnd}, false)
if err != nil {
cleanup()
return nil, nil, err
@@ -129,7 +129,6 @@ func TestRun(t *testing.T) {
}()
// Run the container.
- l.setRootContainerID("foo")
if err := l.Run(); err != nil {
t.Errorf("error running container: %v", err)
}
diff --git a/runsc/cmd/boot.go b/runsc/cmd/boot.go
index 035147cf1..933ba2d9e 100644
--- a/runsc/cmd/boot.go
+++ b/runsc/cmd/boot.go
@@ -69,7 +69,7 @@ func (*Boot) Synopsis() string {
// Usage implements subcommands.Command.Usage.
func (*Boot) Usage() string {
- return `boot [flags]`
+ return `boot [flags] <container id>`
}
// SetFlags implements subcommands.Command.SetFlags.
@@ -86,7 +86,7 @@ func (b *Boot) SetFlags(f *flag.FlagSet) {
// Execute implements subcommands.Command.Execute. It starts a sandbox in a
// waiting state.
func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
- if b.specFD == -1 || b.controllerFD == -1 || f.NArg() != 0 {
+ if b.specFD == -1 || b.controllerFD == -1 || f.NArg() != 1 {
f.Usage()
return subcommands.ExitUsageError
}
@@ -138,7 +138,7 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...interface{})
}
// Create the loader.
- l, err := boot.New(spec, conf, b.controllerFD, b.deviceFD, b.ioFDs.GetArray(), b.console)
+ l, err := boot.New(f.Arg(0), spec, conf, b.controllerFD, b.deviceFD, b.ioFDs.GetArray(), b.console)
if err != nil {
Fatalf("error creating loader: %v", err)
}
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go
index 67244c725..c3d90d5f4 100644
--- a/runsc/sandbox/sandbox.go
+++ b/runsc/sandbox/sandbox.go
@@ -460,6 +460,9 @@ func (s *Sandbox) createSandboxProcess(spec *specs.Spec, conf *boot.Config, bund
}
}
+ // Add container as the last argument.
+ cmd.Args = append(cmd.Args, s.ID)
+
// Log the fds we are donating to the sandbox process.
for i, f := range cmd.ExtraFiles {
log.Debugf("Donating FD %d: %q", i+3, f.Name())