Skip to content

Commit

Permalink
Move adding VSMB share to internal/uvm/*
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
  • Loading branch information
kiashok committed Oct 2, 2023
1 parent 7f25b56 commit 182f512
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
28 changes: 4 additions & 24 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,29 +970,6 @@ func (ht *hcsTask) ProcessorInfo(ctx context.Context) (*processorInfo, error) {
}, nil
}

// Add mount as vSMB share to the UVM at the given destination path
func (ht *hcsTask) addMountToUVM(ctx context.Context, src string, dst string, isRO bool) (string, error) {
options := ht.host.DefaultVSMBOptions(isRO)
vsmbShare, err := ht.host.AddVSMB(ctx, src, options)
if err != nil {
return "", errors.Wrapf(err, "failed to add mount as vSMB share to UVM")
}

defer func() {
if err != nil {
_ = vsmbShare.Release(ctx)
}
}()

sharePath, err := ht.host.GetVSMBUvmPath(ctx, src, isRO)
if err != nil {
return "", errors.Wrapf(err, "failed to get vsmb path")
}
// Add mount to list of resources to be released on container cleanup
ht.cr.Add(vsmbShare)
return sharePath, nil
}

func (ht *hcsTask) requestAddContainerMount(ctx context.Context, resourcePath string, settings interface{}) error {
modification := &hcsschema.ModifySettingRequest{
ResourcePath: resourcePath,
Expand Down Expand Up @@ -1063,10 +1040,13 @@ func (ht *hcsTask) updateWCOWContainerMount(ctx context.Context, resources *ctrd
} else {
// if it is a mount request for a running hyperV WCOW container, we should first mount volume to the
// UVM as a VSMB share and then mount to the running container using the src path as seen by the UVM
guestPath, err := ht.addMountToUVM(ctx, resources.HostPath, resources.ContainerPath, resources.ReadOnly)
vsmbShare, guestPath, err := ht.host.AddVsmbAndGetSharePath(ctx, resources.HostPath, resources.ContainerPath, resources.ReadOnly)
if err != nil {
return err
}
// Add mount to list of resources to be released on container cleanup
ht.cr.Add(vsmbShare)

settings := hcsschema.MappedDirectory{
HostPath: guestPath,
ContainerPath: resources.ContainerPath,
Expand Down
34 changes: 22 additions & 12 deletions internal/uvm/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,34 @@ import (
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/protocol/guestrequest"
"github.com/Microsoft/hcsshim/internal/protocol/guestresource"
"github.com/pkg/errors"
)

func (uvm *UtilityVM) AddVsmbAndGetSharePath(ctx context.Context, reqHostPath, reqUVMPath string, readOnly bool) (*VSMBShare, string, error) {
options := uvm.DefaultVSMBOptions(readOnly)
vsmbShare, err := uvm.AddVSMB(ctx, reqHostPath, options)
if err != nil {
return nil, "", errors.Wrapf(err, "failed to add mount as vSMB share to UVM")
}
defer func() {
if err != nil {
_ = vsmbShare.Release(ctx)
}
}()

sharePath, err := uvm.GetVSMBUvmPath(ctx, reqHostPath, readOnly)
if err != nil {
return nil, "", errors.Wrapf(err, "failed to get vsmb path")
}

return vsmbShare, sharePath, nil
}

// 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)
_, sharePath, err := uvm.AddVsmbAndGetSharePath(ctx, reqHostPath, reqUVMPath, readOnly)
if err != nil {
return err
}
Expand Down

0 comments on commit 182f512

Please sign in to comment.