-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #907 from katiewasnothere/uvm_share
Add utility function for sharing files into UVMs from the host
- v0.13.0-rc.3
- v0.13.0-rc.2
- v0.13.0-rc.1
- v0.12.9
- v0.12.8
- v0.12.7
- v0.12.6
- v0.12.5
- v0.12.4
- v0.12.3
- v0.12.2
- v0.12.1
- v0.12.0
- v0.12.0-rc.3
- v0.12.0-rc.2
- v0.12.0-rc.1
- v0.12.0-rc.0
- v0.11.8
- v0.11.7
- v0.11.6
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.0
- v0.10.0-rc.9
- v0.10.0-rc.8
- v0.10.0-rc.7
- v0.10.0-rc.6
- v0.10.0-rc.5
- v0.10.0-rc.4
- v0.10.0-rc.3
- v0.10.0-rc.2
- v0.10.0-rc.1
- v0.10.0-rc.0
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.9.0-rc0
- v0.8.26
- v0.8.25
- v0.8.24
- v0.8.23
- v0.8.23-rc0
- v0.8.22
- v0.8.21
- v0.8.20
- v0.8.18
- v0.8.17
- v0.8.16
- v0.8.15
- v0.8.14
- k8s1.32-0.12.6.1
Showing
2 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package uvm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/Microsoft/hcsshim/internal/guestrequest" | ||
"github.com/Microsoft/hcsshim/internal/requesttype" | ||
hcsschema "github.com/Microsoft/hcsshim/internal/schema2" | ||
) | ||
|
||
// Share shares in file(s) from `reqHostPath` on the host machine to `reqUVMPath` inside the UVM. | ||
// This function handles both LCOW and WCOW scenarios. | ||
func (uvm *UtilityVM) Share(ctx context.Context, reqHostPath, reqUVMPath string, readOnly bool) (err error) { | ||
if uvm.OS() == "windows" { | ||
options := uvm.DefaultVSMBOptions(readOnly) | ||
vsmbShare, err := uvm.AddVSMB(ctx, reqHostPath, options) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if err != nil { | ||
vsmbShare.Release(ctx) | ||
} | ||
}() | ||
|
||
sharePath, err := uvm.GetVSMBUvmPath(ctx, reqHostPath, readOnly) | ||
if err != nil { | ||
return err | ||
} | ||
guestReq := guestrequest.GuestRequest{ | ||
ResourceType: guestrequest.ResourceTypeMappedDirectory, | ||
RequestType: requesttype.Add, | ||
Settings: &hcsschema.MappedDirectory{ | ||
HostPath: sharePath, | ||
ContainerPath: reqUVMPath, | ||
ReadOnly: readOnly, | ||
}, | ||
} | ||
if err := uvm.GuestRequest(ctx, guestReq); err != nil { | ||
return err | ||
} | ||
} else { | ||
st, err := os.Stat(reqHostPath) | ||
if err != nil { | ||
return fmt.Errorf("could not open '%s' path on host: %s", reqHostPath, err) | ||
} | ||
var ( | ||
hostPath string = reqHostPath | ||
restrictAccess bool | ||
fileName string | ||
allowedNames []string | ||
) | ||
if !st.IsDir() { | ||
hostPath, fileName = filepath.Split(hostPath) | ||
allowedNames = append(allowedNames, fileName) | ||
restrictAccess = true | ||
} | ||
plan9Share, err := uvm.AddPlan9(ctx, hostPath, reqUVMPath, readOnly, restrictAccess, allowedNames) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if err != nil { | ||
plan9Share.Release(ctx) | ||
} | ||
}() | ||
} | ||
return nil | ||
} |