devices/loopback: use new loop_for_fd helper

Use the new `LoopControl.loop_for_fd` helper, which is basically
a modified version of the existing code in `make_loop`.
This commit is contained in:
Christian Kellner 2021-08-03 12:20:02 +00:00 committed by Tom Gundersen
parent d5ded743bd
commit 6293da5874

View file

@ -66,29 +66,10 @@ class LoopbackService(devices.DeviceService):
else:
sizelimit *= self.sector_size
while True:
# Getting an unbound loopback device and attaching a backing
# file descriptor to it is racy, so we must use a retry loop
lo = loop.Loop(self.ctl.get_unbound())
try:
lo.set_fd(fd)
except OSError as e:
lo.close()
if e.errno == errno.EBUSY:
continue
raise e
# `set_status` returns EBUSY when the pages from the previously
# bound file have not been fully cleared yet.
try:
lo.set_status(offset=offset,
sizelimit=sizelimit,
autoclear=True)
except BlockingIOError:
lo.clear_fd()
lo.close()
continue
break
lo = self.ctl.loop_for_fd(fd,
offset=offset,
sizelimit=sizelimit,
autoclear=True)
return lo