MCPcopy
hub / github.com/containerd/containerd / Create

Method Create

core/runtime/v2/shim.go:611–685  ·  view source on GitHub ↗
(ctx context.Context, opts runtime.CreateOpts)

Source from the content-addressed store, hash-verified

609}
610
611func (s *shimTask) Create(ctx context.Context, opts runtime.CreateOpts) (runtime.Task, error) {
612 topts := opts.TaskOptions
613 if topts == nil || topts.GetValue() == nil {
614 topts = opts.RuntimeOptions
615 }
616 request := &task.CreateTaskRequest{
617 ID: s.ID(),
618 Bundle: s.Bundle(),
619 Stdin: opts.IO.Stdin,
620 Stdout: opts.IO.Stdout,
621 Stderr: opts.IO.Stderr,
622 Terminal: opts.IO.Terminal,
623 Checkpoint: opts.Checkpoint,
624 Options: typeurl.MarshalProto(topts),
625 }
626 for _, m := range opts.Rootfs {
627 request.Rootfs = append(request.Rootfs, &types.Mount{
628 Type: m.Type,
629 Source: m.Source,
630 Target: m.Target,
631 Options: m.Options,
632 })
633 }
634
635 _, err := s.task.Create(ctx, request)
636 if err != nil {
637 return nil, errgrpc.ToNative(err)
638 }
639
640 if opts.RestoreFromPath {
641 // Unpack rootfs-diff.tar if it exists.
642 // This needs to happen between the 'Create()' from above and before the 'Start()' from below.
643 rootfsDiff := filepath.Join(opts.Checkpoint, "..", crmetadata.RootFsDiffTar)
644
645 _, err = os.Stat(rootfsDiff)
646 if err == nil {
647 rootfsDiffTar, err := os.Open(rootfsDiff)
648 if err != nil {
649 return nil, fmt.Errorf("failed to open rootfs-diff archive %s for import: %w", rootfsDiffTar.Name(), err)
650 }
651 defer func(f *os.File) {
652 if err := f.Close(); err != nil {
653 log.G(ctx).Errorf("Unable to close file %s: %q", f.Name(), err)
654 }
655 }(rootfsDiffTar)
656
657 decompressed, err := compression.DecompressStream(rootfsDiffTar)
658 if err != nil {
659 return nil, fmt.Errorf("failed to decompress archive %s for import: %w", rootfsDiffTar.Name(), err)
660 }
661
662 rootfs := filepath.Join(s.Bundle(), "rootfs")
663 _, err = archive.Apply(
664 ctx,
665 rootfs,
666 decompressed,
667 )
668

Callers

nothing calls this directly

Calls 11

StartMethod · 0.95
DecompressStreamFunction · 0.92
ApplyFunction · 0.92
GetValueMethod · 0.80
IDMethod · 0.65
BundleMethod · 0.65
CreateMethod · 0.65
StatMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected