...
1
2
3 package uvm
4
5 import (
6 "context"
7 "fmt"
8 "strings"
9
10 "github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
11 hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
12 "github.com/Microsoft/hcsshim/internal/protocol/guestrequest"
13 specs "github.com/opencontainers/runtime-spec/specs-go"
14 )
15
16 const pipePrefix = `\\.\pipe\`
17
18
19 type PipeMount struct {
20
21 vm *UtilityVM
22 HostPath string
23 }
24
25
26 func (pipe *PipeMount) Release(ctx context.Context) error {
27 if err := pipe.vm.RemovePipe(ctx, pipe.HostPath); err != nil {
28 return fmt.Errorf("failed to remove pipe mount: %s", err)
29 }
30 return nil
31 }
32
33
34 func (uvm *UtilityVM) AddPipe(ctx context.Context, hostPath string) (*PipeMount, error) {
35 modification := &hcsschema.ModifySettingRequest{
36 RequestType: guestrequest.RequestTypeAdd,
37 ResourcePath: fmt.Sprintf(resourcepaths.MappedPipeResourceFormat, hostPath),
38 }
39 if err := uvm.modify(ctx, modification); err != nil {
40 return nil, err
41 }
42 return &PipeMount{uvm, hostPath}, nil
43 }
44
45
46 func (uvm *UtilityVM) RemovePipe(ctx context.Context, hostPath string) error {
47 modification := &hcsschema.ModifySettingRequest{
48 RequestType: guestrequest.RequestTypeRemove,
49 ResourcePath: fmt.Sprintf(resourcepaths.MappedPipeResourceFormat, hostPath),
50 }
51 if err := uvm.modify(ctx, modification); err != nil {
52 return err
53 }
54 return nil
55 }
56
57
58 func IsPipe(hostPath string) bool {
59 return strings.HasPrefix(hostPath, pipePrefix)
60 }
61
62
63
64 func GetContainerPipeMapping(uvm *UtilityVM, mount specs.Mount) (src string, dst string) {
65 if uvm == nil {
66 src = mount.Source
67 } else {
68 src = vsmbSharePrefix + `IPC$\` + strings.TrimPrefix(mount.Source, pipePrefix)
69 }
70 dst = strings.TrimPrefix(mount.Destination, pipePrefix)
71 return src, dst
72 }
73
View as plain text