From a891afad6d7e3b09bafdccb4cc4b9fc4e577620e Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Fri, 28 Dec 2018 13:47:19 -0800 Subject: Simplify synchronization between runsc and sandbox process Make 'runsc create' join cgroup before creating sandbox process. This removes the need to synchronize platform creation and ensure that sandbox process is charged to the right cgroup from the start. PiperOrigin-RevId: 227166451 Change-Id: Ieb4b18e6ca0daf7b331dc897699ca419bc5ee3a2 --- runsc/cmd/boot.go | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'runsc/cmd/boot.go') diff --git a/runsc/cmd/boot.go b/runsc/cmd/boot.go index 192df7d3c..bb3435284 100644 --- a/runsc/cmd/boot.go +++ b/runsc/cmd/boot.go @@ -159,14 +159,6 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) panic("setCapsAndCallSelf must never return success") } - // Wait until this process has been moved into cgroups. - startSyncFile := os.NewFile(uintptr(b.startSyncFD), "start-sync file") - defer startSyncFile.Close() - buf := make([]byte, 1) - if r, err := startSyncFile.Read(buf); err != nil || r != 1 { - Fatalf("Unable to read from the start-sync descriptor: %v", err) - } - // Create the loader. bootArgs := boot.Args{ ID: f.Arg(0), @@ -186,21 +178,20 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) Fatalf("error creating loader: %v", err) } - // Fatalf exits the process and doesn't run defers. 'l' must be destroyed - // explicitly! + // Fatalf exits the process and doesn't run defers. + // 'l' must be destroyed explicitly after this point! - // Notify the parent process the controller has been created. + // Notify the parent process the sandbox has booted (and that the controller + // is up). + startSyncFile := os.NewFile(uintptr(b.startSyncFD), "start-sync file") + buf := make([]byte, 1) if w, err := startSyncFile.Write(buf); err != nil || w != 1 { l.Destroy() Fatalf("Unable to write into the start-sync descriptor: %v", err) } - // startSyncFile is closed here to be sure that starting with this point - // the runsc process will not write anything into it. + // Closes startSyncFile because 'l.Run()' only returns when the sandbox exits. startSyncFile.Close() - // Notify other processes the loader has been created. - l.NotifyLoaderCreated() - // Wait for the start signal from runsc. l.WaitForStartSignal() -- cgit v1.2.3