...
1
2
3 package jobcontainers
4
5 import (
6 "context"
7 "fmt"
8 "os"
9 "path/filepath"
10
11 "github.com/Microsoft/hcsshim/internal/layers"
12 "github.com/Microsoft/hcsshim/internal/log"
13 "github.com/Microsoft/hcsshim/internal/resources"
14 "github.com/Microsoft/hcsshim/internal/wclayer"
15 specs "github.com/opencontainers/runtime-spec/specs-go"
16 "github.com/pkg/errors"
17 )
18
19
20
21
22 const fallbackRootfsFormat = `C:\hpc\%s\`
23
24
25
26
27 const defaultSiloRootfsLocation = `C:\hpc\`
28
29 func (c *JobContainer) mountLayers(ctx context.Context, containerID string, s *specs.Spec, volumeMountPath string) (_ resources.ResourceCloser, err error) {
30 if s == nil || s.Windows == nil || s.Windows.LayerFolders == nil {
31 return nil, errors.New("field 'Spec.Windows.Layerfolders' is not populated")
32 }
33
34
35 scratchFolder := s.Windows.LayerFolders[len(s.Windows.LayerFolders)-1]
36 if _, err := os.Stat(scratchFolder); os.IsNotExist(err) {
37 if err := os.MkdirAll(scratchFolder, 0777); err != nil {
38 return nil, fmt.Errorf("failed to auto-create container scratch folder %s: %w", scratchFolder, err)
39 }
40 }
41
42
43 if _, err := os.Stat(filepath.Join(scratchFolder, "sandbox.vhdx")); os.IsNotExist(err) {
44 if err := wclayer.CreateScratchLayer(ctx, scratchFolder, s.Windows.LayerFolders[:len(s.Windows.LayerFolders)-1]); err != nil {
45 return nil, fmt.Errorf("failed to CreateSandboxLayer: %w", err)
46 }
47 }
48
49 if s.Root == nil {
50 s.Root = &specs.Root{}
51 }
52
53 var closer resources.ResourceCloser
54 if s.Root.Path == "" {
55 log.G(ctx).Debug("mounting job container storage")
56 var rootPath string
57 rootPath, closer, err = layers.MountWCOWLayers(ctx, containerID, s.Windows.LayerFolders, "", volumeMountPath, nil)
58 if err != nil {
59 return nil, fmt.Errorf("failed to mount job container storage: %w", err)
60 }
61 s.Root.Path = rootPath + "\\"
62 }
63
64 return closer, nil
65 }
66
67
68
69 func (c *JobContainer) setupRootfsBinding(root, target string) error {
70 if err := c.job.ApplyFileBinding(root, target, false); err != nil {
71 return fmt.Errorf("failed to bind rootfs to %s: %w", root, err)
72 }
73 return nil
74 }
75
View as plain text