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

hack: add blanket retries on device-mapper failures with SCSI #1720

Merged
merged 1 commit into from
Apr 10, 2023
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
15 changes: 13 additions & 2 deletions internal/guest/storage/devicemapper/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package devicemapper
import (
"context"
"fmt"
"time"

"github.com/pkg/errors"
"go.opencensus.io/trace"
Expand Down Expand Up @@ -34,7 +35,12 @@ func CreateZeroSectorLinearTarget(ctx context.Context, devPath, devName string,

devMapperPath, err := CreateDevice(devName, CreateReadOnly, []Target{linearTarget})
if err != nil {
return "", errors.Wrapf(err, "failed to create dm-linear target, device=%s, offset=%d", devPath, mappingInfo.DeviceOffsetInBytes)
// todo (maksiman): add better retry logic, similar to how SCSI device mounts are
// retried on unix.ENOENT and unix.ENXIO.
time.Sleep(500 * time.Millisecond)
if devMapperPath, err = CreateDevice(devName, CreateReadOnly, []Target{linearTarget}); err != nil {
return "", errors.Wrapf(err, "failed to create dm-linear target, device=%s, offset=%d", devPath, mappingInfo.DeviceOffsetInBytes)
}
}

return devMapperPath, nil
Expand Down Expand Up @@ -82,7 +88,12 @@ func CreateVerityTarget(ctx context.Context, devPath, devName string, verityInfo

mapperPath, err := CreateDevice(devName, CreateReadOnly, []Target{verityTarget})
if err != nil {
return "", errors.Wrapf(err, "failed to create dm-verity target. device=%s", devPath)
// todo (maksiman): add better retry logic, similar to how SCSI device mounts are
// retried on unix.ENOENT and unix.ENXIO
time.Sleep(500 * time.Millisecond)
if mapperPath, err = CreateDevice(devName, CreateReadOnly, []Target{verityTarget}); err != nil {
return "", errors.Wrapf(err, "failed to create dm-verity target. device=%s", devPath)
}
}

return mapperPath, nil
Expand Down
8 changes: 7 additions & 1 deletion internal/guest/storage/scsi/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ func Mount(
cryptDeviceName := fmt.Sprintf(cryptDeviceFmt, controller, lun)
encryptedSource, err := encryptDevice(spnCtx, source, cryptDeviceName)
if err != nil {
return fmt.Errorf("failed to mount encrypted device %s: %w", source, err)
// todo (maksiman): add better retry logic, similar to how SCSI device mounts are
// retried on unix.ENOENT and unix.ENXIO. The retry should probably be on an
// error message rather than actual error, because we shell-out to cryptsetup.
time.Sleep(500 * time.Millisecond)
if encryptedSource, err = encryptDevice(spnCtx, source, cryptDeviceName); err != nil {
return fmt.Errorf("failed to mount encrypted device %s: %w", source, err)
}
}
source = encryptedSource
mountType = "xfs"
Expand Down