Skip to content

Commit

Permalink
fix: workaround problems with udevd races
Browse files Browse the repository at this point in the history
When `udevd` rescans block device partitions while Talos is doing
partitions, it might be that Talos can hit the following error
while trying to open/mount a partition:

```
no such device or address
```

Previous attempts to fix that were using `ENODEV`, while the proper code
is `ENXIO`.

Also take exclusive lock while working with user disks to prevent
concurrent udevd rescan.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed May 24, 2024
1 parent 31b24ea commit 92a274e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func retryBlockdeviceOpen(device string) (*blockdevice.BlockDevice, error) {
switch {
case os.IsNotExist(openErr):
return retry.ExpectedError(openErr)
case errors.Is(openErr, syscall.ENODEV):
case errors.Is(openErr, syscall.ENODEV), errors.Is(openErr, syscall.ENXIO):
return retry.ExpectedError(openErr)
default:
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func partitionAndFormatDisks(logger *log.Logger, r runtime.Runtime) error {

for _, disk := range r.Config().Machine().Disks() {
if err := func() error {
bd, err := blockdevice.Open(disk.Device(), blockdevice.WithMode(blockdevice.ReadonlyMode))
bd, err := blockdevice.Open(disk.Device(), blockdevice.WithMode(blockdevice.ReadonlyMode), blockdevice.WithExclusiveLock(true))
if err != nil {
return err
}
Expand Down Expand Up @@ -921,7 +921,7 @@ func mountDisks(logger *log.Logger, r runtime.Runtime) (err error) {
mountpoints := mount.NewMountPoints()

for _, disk := range r.Config().Machine().Disks() {
bd, err := blockdevice.Open(disk.Device(), blockdevice.WithMode(blockdevice.ReadonlyMode))
bd, err := blockdevice.Open(disk.Device(), blockdevice.WithMode(blockdevice.ReadonlyMode), blockdevice.WithExclusiveLock(true))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func mountRetry(f RetryFunc, p *Point, isUnmount bool) (err error) {
switch err {
case unix.EBUSY:
return retry.ExpectedError(err)
case unix.ENOENT, unix.ENODEV:
case unix.ENOENT, unix.ENXIO:
// if udevd triggers BLKRRPART ioctl, partition device entry might disappear temporarily
return retry.ExpectedError(err)
case unix.EUCLEAN, unix.EIO:
Expand Down

0 comments on commit 92a274e

Please sign in to comment.