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.
This commit is contained in:
Christian Kellner 2021-08-09 16:08:22 +02:00 committed by Tom Gundersen
parent 43ae79cabf
commit c1379f63ab

View file

@ -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