Skip to content

Commit

Permalink
Minor fixes to SCSI mount operation (#1798)
Browse files Browse the repository at this point in the history
During a recent refactor SCSI mount operation code removed a retry logic that is needed when examining the
filesystem type on a SCSI device. Retry is needed because sometimes attempting to open a SCSI devices
immediately after attaching it results in ENXIO/ENOENT errors. This adds the retry logic back.

Names of some images used in the tests had changed, this commit updates those names too.

Signed-off-by: Amit Barve <ambarve@microsoft.com>
  • Loading branch information
ambarve committed Jun 2, 2023
1 parent 8a094ae commit 8d4a20c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ext4/tar2ext4/tar2ext4.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Microsoft/hcsshim/ext4/dmverity"
"github.com/Microsoft/hcsshim/ext4/internal/compactext4"
"github.com/Microsoft/hcsshim/ext4/internal/format"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -259,6 +260,9 @@ func IsDeviceExt4(devicePath string) bool {
// ReadExt4SuperBlock will check the superblock magic number for us,
// so we know if no error is returned, this is an ext4 device.
_, err := ReadExt4SuperBlock(devicePath)
if err != nil {
log.L.Warnf("failed to read Ext4 superblock: %s", err)
}
return err == nil
}

Expand Down
11 changes: 9 additions & 2 deletions internal/guest/storage/scsi/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,15 @@ func Mount(
// 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)
// TODO (ambarve): add better retry logic, SCSI mounts sometimes return ENONENT or
// ENXIO error if we try to open those devices immediately after mount. retry after a
// few milliseconds.
log.G(ctx).WithError(err).Trace("get device filesystem failed, retrying in 500ms")
time.Sleep(500 * time.Millisecond)
if deviceFS, err = _getDeviceFsType(source); 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")
Expand Down
2 changes: 1 addition & 1 deletion test/cri-containerd/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,9 @@ func Test_Container_NFSMount_LCOW(t *testing.T) {
defer stopContainer(t, client, ctx, containerID)

execHelper := func(ctrID string, cmd []string) {
t.Helper()
stdout, stderr, errcode := execContainer(t, client, ctx, ctrID, cmd)
if errcode != 0 {
t.Helper()
t.Logf("stdout: %s \n\n stderr: %s\n\n", stdout, stderr)
t.Fatalf("failed to run '%v'\n: errcode: %d", cmd, errcode)
}
Expand Down
2 changes: 1 addition & 1 deletion test/cri-containerd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
alpineAspnetUpgrade = "mcr.microsoft.com/dotnet/core/aspnet:3.1.2-alpine3.11"

imageWindowsProcessDump = "cplatpublic.azurecr.io/crashdump:latest"
imageWindowsArgsEscaped = "cplatpublic.azurecr.io/argsescaped:latest"
imageWindowsArgsEscaped = "cplatpublic.azurecr.io/args-escaped-test-image-ns:latest"
imageWindowsTimezone = "cplatpublic.azurecr.io/timezone:latest"

imageJobContainerHNS = "cplatpublic.azurecr.io/jobcontainer_hns:latest"
Expand Down

0 comments on commit 8d4a20c

Please sign in to comment.