From 6e2eba6bab026ecc927a1b85f4a95ee268165003 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 23 Jul 2024 13:00:17 +0200 Subject: [PATCH] loopback: treat ENXIO as ENOENT Signed-off-by: Giuseppe Scrivano --- pkg/loopback/attach_loopback.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/loopback/attach_loopback.go b/pkg/loopback/attach_loopback.go index 763dea2966..80a6e91924 100644 --- a/pkg/loopback/attach_loopback.go +++ b/pkg/loopback/attach_loopback.go @@ -11,6 +11,7 @@ import ( "syscall" "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" ) // Loopback related errors @@ -62,7 +63,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