From c1379f63abe28ca575d467d5f2dff9ada44cd9b2 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Mon, 9 Aug 2021 16:08:22 +0200 Subject: [PATCH] devices/loopback: explicitly clear the fd Explicitly clear the fd. There might be a race with udev or some other process that still as a reference to the loop device so we might not be able to immediately clear it. Thus wait for it with a timeout of 30 seconds which should hopefully be enough. If the device does not clear then any consecutive action that involves it might not be safe to execute so we let the timeout exception be reported to osbuild. --- devices/org.osbuild.loopback | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/devices/org.osbuild.loopback b/devices/org.osbuild.loopback index d0ac1f81..444f7098 100755 --- a/devices/org.osbuild.loopback +++ b/devices/org.osbuild.loopback @@ -114,6 +114,11 @@ class LoopbackService(devices.DeviceService): self.ctl.close() if self.lo: + # clear the fd. Since it might not immediately be + # cleared (due to a race with udev or some other + # process still having a reference to the loop dev) + # we give it some time and wait for the clearing + self.lo.clear_fd_wait(self.fd, 30) self.lo.close() self.lo = None