From 98791175a05515ece8fef1f122c5dfae0d573839 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 92f2f2186a..5bcd27e2a0 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 @@ -57,7 +58,9 @@ func openNextAvailableLoopback(index int, sparseName string, sparseFile *os.File // 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. index, err = getNextFreeLoopbackIndex()