From 280aca8f075abd944565f5ee93100a8563e2146e Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 12 Nov 2021 14:16:44 +0000 Subject: [PATCH] test/lvm2: use LoopControl.loop_for_fd Instead of having custom code that basically duplicates the functionality of `LoopControl.loop_for_fd` use that instead. Additionally, the version used in the test had a bug where it did not re-create the Loop device in the main loop when it was close due to an error, leading errors in subsequent usages of the device that would often manifest in CI runs: fcntl.ioctl(self.fd, self.LOOP_SET_FD, fd) ValueError: file descriptor cannot be a negative integer (-1) --- test/mod/test_util_lvm2.py | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/test/mod/test_util_lvm2.py b/test/mod/test_util_lvm2.py index eb37245e..81fd8f34 100644 --- a/test/mod/test_util_lvm2.py +++ b/test/mod/test_util_lvm2.py @@ -2,7 +2,6 @@ # Test for the util.lvm2 module # -import errno import os import json import subprocess @@ -41,8 +40,6 @@ def tempdir_fixture(): def make_loop(ctl, fd: int, offset, sizelimit, sector_size=512): - lo = loop.Loop(ctl.get_unbound()) - if not sizelimit: stat = os.fstat(fd) sizelimit = stat.st_size - offset @@ -50,27 +47,7 @@ def make_loop(ctl, fd: int, offset, sizelimit, sector_size=512): else: sizelimit *= sector_size - while True: - 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 - - return lo + return ctl.loop_for_fd(fd, offset, sizelimit=sizelimit, autoclear=True) def pvcreate(path: PathLike):