Skip to content

Commit

Permalink
loopback: treat ENXIO as ENOENT
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jul 23, 2024
1 parent 01c633e commit 998e6d4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/loopback/attach_loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"syscall"

"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

// Loopback related errors
Expand Down Expand Up @@ -71,7 +72,9 @@ func openNextAvailableLoopback(sparseName string, sparseFile *os.File) (loopFile
// OpenFile adds O_CLOEXEC
loopFile, err = os.OpenFile(target, os.O_RDWR, 0o644)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// The kernel returns ENXIO when opening a device that is in the "deleting" or "rundown" state, so
// just treat ENXIO as if the device does not exist.
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, unix.ENXIO) {
// Another process could have taken the loopback device in the meantime. So repeat
// the process with the next loopback device.
continue
Expand Down

0 comments on commit 998e6d4

Please sign in to comment.