Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scsi: Support optional guest path for mount, add tests, refcount fix #2278

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/devices/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func InstallDrivers(ctx context.Context, vm *uvm.UtilityVM, share string) (close
share,
true,
vm.ID(),
"",
&scsi.MountConfig{},
)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/hcsoci/resources_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func allocateLinuxResources(ctx context.Context, coi *createOptionsInternal, r *
hostPath,
readOnly,
coi.HostingSystem.ID(),
"",
&scsi.MountConfig{Options: mount.Options, BlockDev: isBlockDev},
)
if err != nil {
Expand All @@ -114,6 +115,7 @@ func allocateLinuxResources(ctx context.Context, coi *createOptionsInternal, r *
hostPath,
readOnly,
coi.HostingSystem.ID(),
"",
&scsi.MountConfig{Options: mount.Options, BlockDev: isBlockDev},
)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/hcsoci/resources_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R
mount.Source,
readOnly,
coi.HostingSystem.ID(),
"",
&scsi.MountConfig{},
)
case MountTypeVirtualDisk:
Expand All @@ -153,6 +154,7 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R
mount.Source,
readOnly,
coi.HostingSystem.ID(),
"",
&scsi.MountConfig{},
)
case MountTypeExtensibleVirtualDisk:
Expand All @@ -161,6 +163,7 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R
ctx,
mount.Source,
readOnly,
"",
&scsi.MountConfig{},
)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/layers/lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func MountLCOWLayers(ctx context.Context, containerID string, layers *LCOWLayers
hostPath,
false,
vm.ID(),
guestRoot,
mConfig,
)
if err != nil {
Expand Down Expand Up @@ -194,6 +195,7 @@ func addLCOWLayer(ctx context.Context, vm *uvm.UtilityVM, layer *LCOWLayer) (uvm
layer.VHDPath,
true,
"",
"",
&scsi.MountConfig{
Partition: layer.Partition,
Options: []string{"ro"},
Expand Down
2 changes: 1 addition & 1 deletion internal/layers/wcow_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func mountHypervIsolatedWCIFSLayers(ctx context.Context, l *wcowWCIFSLayers, vm
hostPath := filepath.Join(l.scratchLayerPath, "sandbox.vhdx")
log.G(ctx).WithField("hostPath", hostPath).Debug("mounting scratch VHD")

scsiMount, err := vm.SCSIManager.AddVirtualDisk(ctx, hostPath, false, vm.ID(), &scsi.MountConfig{})
scsiMount, err := vm.SCSIManager.AddVirtualDisk(ctx, hostPath, false, vm.ID(), "", &scsi.MountConfig{})
if err != nil {
return nil, nil, fmt.Errorf("failed to add SCSI scratch VHD: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lcow/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func FormatDisk(ctx context.Context, lcowUVM *uvm.UtilityVM, destPath string) er
}).Debug("lcow::FormatDisk opts")

// Attach without mounting.
scsi, err := lcowUVM.SCSIManager.AddPhysicalDisk(ctx, destPath, false, lcowUVM.ID(), nil)
scsi, err := lcowUVM.SCSIManager.AddPhysicalDisk(ctx, destPath, false, lcowUVM.ID(), "", nil)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions internal/lcow/scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func CreateScratch(ctx context.Context, lcowUVM *uvm.UtilityVM, destFile string,
destFile,
false,
lcowUVM.ID(),
"",
&scsi.MountConfig{
BlockDev: true,
},
Expand Down
1 change: 1 addition & 0 deletions internal/tools/uvmboot/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func mountSCSI(ctx context.Context, c *cli.Context, vm *uvm.UtilityVM) error {
m.host,
!m.writable,
vm.ID(),
"",
&scsi.MountConfig{},
)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/uvm/scsi/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (m *Manager) AddVirtualDisk(
hostPath string,
readOnly bool,
vmID string,
guestPath string,
mc *MountConfig,
) (*Mount, error) {
if m == nil {
Expand Down Expand Up @@ -169,6 +170,7 @@ func (m *Manager) AddVirtualDisk(
readOnly: readOnly,
typ: "VirtualDisk",
},
guestPath,
mcInternal)
}

Expand All @@ -187,6 +189,7 @@ func (m *Manager) AddPhysicalDisk(
hostPath string,
readOnly bool,
vmID string,
guestPath string,
mc *MountConfig,
) (*Mount, error) {
if m == nil {
Expand Down Expand Up @@ -215,6 +218,7 @@ func (m *Manager) AddPhysicalDisk(
readOnly: readOnly,
typ: "PassThru",
},
guestPath,
mcInternal)
}

Expand All @@ -233,6 +237,7 @@ func (m *Manager) AddExtensibleVirtualDisk(
ctx context.Context,
hostPath string,
readOnly bool,
guestPath string,
mc *MountConfig,
) (*Mount, error) {
if m == nil {
Expand Down Expand Up @@ -260,10 +265,11 @@ func (m *Manager) AddExtensibleVirtualDisk(
typ: "ExtensibleVirtualDisk",
evdType: evdType,
},
guestPath,
mcInternal)
}

func (m *Manager) add(ctx context.Context, attachConfig *attachConfig, mountConfig *mountConfig) (_ *Mount, err error) {
func (m *Manager) add(ctx context.Context, attachConfig *attachConfig, guestPath string, mountConfig *mountConfig) (_ *Mount, err error) {
controller, lun, err := m.attachManager.attach(ctx, attachConfig)
if err != nil {
return nil, err
Expand All @@ -274,9 +280,8 @@ func (m *Manager) add(ctx context.Context, attachConfig *attachConfig, mountConf
}
}()

var guestPath string
if mountConfig != nil {
guestPath, err = m.mountManager.mount(ctx, controller, lun, mountConfig)
guestPath, err = m.mountManager.mount(ctx, controller, lun, guestPath, mountConfig)
if err != nil {
return nil, err
}
Expand All @@ -287,14 +292,9 @@ func (m *Manager) add(ctx context.Context, attachConfig *attachConfig, mountConf

func (m *Manager) remove(ctx context.Context, controller, lun uint, guestPath string) error {
if guestPath != "" {
removed, err := m.mountManager.unmount(ctx, guestPath)
if err != nil {
if err := m.mountManager.unmount(ctx, guestPath); err != nil {
return err
}

if !removed {
return nil
}
}

if _, err := m.attachManager.detach(ctx, controller, lun); err != nil {
Expand Down
Loading