MCPcopy
hub / github.com/google/gvisor / RestoreSubcontainer

Method RestoreSubcontainer

runsc/boot/controller.go:808–895  ·  view source on GitHub ↗
(args *StartArgs, _ *struct{})

Source from the content-addressed store, hash-verified

806}
807
808func (cm *containerManager) RestoreSubcontainer(args *StartArgs, _ *struct{}) (retErr error) {
809 log.Debugf("containerManager.RestoreSubcontainer, cid: %s, args: %+v", args.CID, args)
810 cm.l.mu.Lock()
811 state := cm.l.state
812 cm.l.mu.Unlock()
813 if state != restoringUnstarted {
814 return fmt.Errorf("sandbox is not being restored, cannot restore subcontainer: state=%s", state)
815 }
816 defer func() {
817 if retErr != nil {
818 cm.onRestoreFailed(fmt.Errorf("RestoreSubcontainer failed: %w", retErr))
819 }
820 }()
821
822 // Validate arguments.
823 if args.Spec == nil {
824 return errors.New("start arguments missing spec")
825 }
826 if args.Conf == nil {
827 return errors.New("start arguments missing config")
828 }
829 if args.CID == "" {
830 return errors.New("start argument missing container ID")
831 }
832 expectedFDs := 1 // At least one FD for the root filesystem.
833 expectedFDs += args.NumGoferFilestoreFDs
834 if args.IsDevIoFilePresent {
835 expectedFDs++
836 }
837 if !args.Spec.Process.Terminal {
838 expectedFDs += 3
839 }
840 if args.IsRootfsUpperTarFilePresent {
841 return errors.New("rootfs upper tar file is not supported during restore")
842 }
843 if len(args.Files) < expectedFDs {
844 return fmt.Errorf("restore arguments must contain at least %d FDs, but only got %d", expectedFDs, len(args.Files))
845 }
846
847 // All validation passed, logs the spec for debugging.
848 specutils.LogSpecDebug(args.Spec, args.Conf.OCISeccomp)
849
850 goferFiles := args.Files
851 var stdios []*fd.FD
852 if !args.Spec.Process.Terminal {
853 // When not using a terminal, stdios come as the first 3 files in the
854 // payload.
855 var err error
856 stdios, err = fd.NewFromFiles(goferFiles[:3])
857 if err != nil {
858 return fmt.Errorf("error dup'ing stdio files: %w", err)
859 }
860 goferFiles = goferFiles[3:]
861 }
862
863 var goferFilestoreFDs []*fd.FD
864 for i := 0; i < args.NumGoferFilestoreFDs; i++ {
865 overlayFilestoreFD, err := fd.NewFromFile(goferFiles[i])

Callers 1

StartSubcontainerMethod · 0.95

Calls 10

onRestoreFailedMethod · 0.95
DebugfFunction · 0.92
LogSpecDebugFunction · 0.92
NewFromFilesFunction · 0.92
NewFromFileFunction · 0.92
restoreSubcontainerMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
ErrorfMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected