Skip to content

Commit

Permalink
Pass EnsureFilesystem and Filesystem from MountConfig through scsi stack
Browse files Browse the repository at this point in the history
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
  • Loading branch information
katiewasnothere committed May 15, 2023
1 parent 327db8c commit 2a76b0d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/guest/storage/crypt/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func cryptsetupClose(deviceName string) error {
// /dev/mapper/`cryptDeviceTemplate`. This can be mounted directly, but it
// doesn't have any format yet.
//
// 4. Prepare the unecrypted block device to be later encrypted as xfs
// 4. Prepare the unecrypted block device to be later formatted as xfs
// 4.1. Zero the first block. It appears that mkfs.xfs reads this before formatting.

func EncryptDevice(ctx context.Context, source string, dmCryptName string) (path string, err error) {
Expand Down
19 changes: 10 additions & 9 deletions internal/guest/storage/scsi/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func Mount(
data = "noload"
}

var deviceFS string
if config.Encrypted {
cryptDeviceName := fmt.Sprintf(cryptDeviceFmt, controller, lun, partition)
encryptedSource, err := encryptDevice(spnCtx, source, cryptDeviceName)
Expand All @@ -217,17 +218,17 @@ func Mount(
}
}
source = encryptedSource
}

// Get the filesystem that is already on the device (if any) and use that
// as the mountType unless `Filesystem` was given.
deviceFS, err := _getDeviceFsType(source)
if err != nil {
if config.Filesystem == "" || !errors.Is(err, ErrUnknownFilesystem) {
return fmt.Errorf("getting device's filesystem: %w", err)
} else {
// Get the filesystem that is already on the device (if any) and use that
// as the mountType unless `Filesystem` was given.
deviceFS, err = _getDeviceFsType(source)
if err != nil {
if config.Filesystem == "" || !errors.Is(err, ErrUnknownFilesystem) {
return fmt.Errorf("getting device's filesystem: %w", err)
}
}
log.G(ctx).WithField("filesystem", deviceFS).Debug("filesystem found on device")
}
log.G(ctx).WithField("filesystem", deviceFS).Debug("filesystem found on device")

mountType := deviceFS
if config.Filesystem != "" {
Expand Down
3 changes: 0 additions & 3 deletions internal/guest/storage/scsi/scsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,6 @@ func Test_Mount_EncryptDevice_Called(t *testing.T) {
return expectedDevicePath, nil
}
osStat = osStatNoop
_getDeviceFsType = getDeviceFsTypeUnknown

xfsFormat = func(arg string) error {
if arg != expectedDevicePath {
Expand Down Expand Up @@ -994,7 +993,6 @@ func Test_Mount_EncryptDevice_Mkfs_Error(t *testing.T) {
return expectedDevicePath, nil
}
osStat = osStatNoop
_getDeviceFsType = getDeviceFsTypeUnknown

xfsFormat = func(arg string) error {
if arg != expectedDevicePath {
Expand Down Expand Up @@ -1048,7 +1046,6 @@ func Test_Mount_RemoveAllCalled_When_EncryptDevice_Fails(t *testing.T) {
return nil
}
osStat = osStatNoop
_getDeviceFsType = getDeviceFsTypeUnknown

xfsFormat = func(arg string) error {
return nil
Expand Down
31 changes: 20 additions & 11 deletions internal/uvm/scsi/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ func (m *Manager) AddVirtualDisk(
var mcInternal *mountConfig
if mc != nil {
mcInternal = &mountConfig{
readOnly: readOnly,
encrypted: mc.Encrypted,
options: mc.Options,
verity: readVerityInfo(ctx, hostPath),
readOnly: readOnly,
partition: mc.Partition,
encrypted: mc.Encrypted,
options: mc.Options,
verity: readVerityInfo(ctx, hostPath),
ensureFileystem: mc.EnsureFileystem,
filesystem: mc.Filesystem,
}
}
return m.add(ctx,
Expand Down Expand Up @@ -186,10 +189,13 @@ func (m *Manager) AddPhysicalDisk(
var mcInternal *mountConfig
if mc != nil {
mcInternal = &mountConfig{
readOnly: readOnly,
encrypted: mc.Encrypted,
options: mc.Options,
verity: readVerityInfo(ctx, hostPath),
readOnly: readOnly,
partition: mc.Partition,
encrypted: mc.Encrypted,
options: mc.Options,
verity: readVerityInfo(ctx, hostPath),
ensureFileystem: mc.EnsureFileystem,
filesystem: mc.Filesystem,
}
}
return m.add(ctx,
Expand Down Expand Up @@ -228,9 +234,12 @@ func (m *Manager) AddExtensibleVirtualDisk(
var mcInternal *mountConfig
if mc != nil {
mcInternal = &mountConfig{
readOnly: readOnly,
encrypted: mc.Encrypted,
options: mc.Options,
readOnly: readOnly,
partition: mc.Partition,
encrypted: mc.Encrypted,
options: mc.Options,
ensureFileystem: mc.EnsureFileystem,
filesystem: mc.Filesystem,
}
}
return m.add(ctx,
Expand Down

0 comments on commit 2a76b0d

Please sign in to comment.