Skip to content

Commit

Permalink
fix: error shadowing removing read-write mount tracking (microsoft#2208)
Browse files Browse the repository at this point in the history
When filesystem mount fails, we attempt to cleanup
read-write mount tracking. However, the return error is
being shadowed and `RemoveRWDevice` is never called.

Signed-off-by: Maksim An <[email protected]>
  • Loading branch information
anmaxvl authored Jul 18, 2024
1 parent ffe0492 commit c28c0b2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/guest/runtime/hcsv2/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
return c, nil
}

func (h *Host) modifyHostSettings(ctx context.Context, containerID string, req *guestrequest.ModificationRequest) (err error) {
func (h *Host) modifyHostSettings(ctx context.Context, containerID string, req *guestrequest.ModificationRequest) (retErr error) {
switch req.ResourceType {
case guestresource.ResourceTypeSCSIDevice:
return modifySCSIDevice(ctx, req.RequestType, req.Settings.(*guestresource.SCSIDevice))
case guestresource.ResourceTypeMappedVirtualDisk:
mvd := req.Settings.(*guestresource.LCOWMappedVirtualDisk)
// find the actual controller number on the bus and update the incoming request.
var cNum uint8
cNum, err = scsi.ActualControllerNumber(ctx, mvd.Controller)
cNum, err := scsi.ActualControllerNumber(ctx, mvd.Controller)
if err != nil {
return err
}
Expand All @@ -569,7 +569,7 @@ func (h *Host) modifyHostSettings(ctx context.Context, containerID string, req *
return err
}
defer func() {
if err != nil {
if retErr != nil {
_ = h.hostMounts.RemoveRWDevice(mvd.MountPath, source)
}
}()
Expand All @@ -578,7 +578,7 @@ func (h *Host) modifyHostSettings(ctx context.Context, containerID string, req *
return err
}
defer func() {
if err != nil {
if retErr != nil {
_ = h.hostMounts.AddRWDevice(mvd.MountPath, source, mvd.Encrypted)
}
}()
Expand Down

0 comments on commit c28c0b2

Please sign in to comment.