From 998e6d433d3aaab0408c8d033aea3e7d43b4a198 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 f9f0134984..067dd7cd90 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 @@ -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