From 840df1dc928d3ec79c26c92eea877833cc7d2b7e Mon Sep 17 00:00:00 2001 From: Michael Hofmann Date: Sun, 18 Jun 2023 11:12:41 +0200 Subject: [PATCH] Restore LOOP_CONFIGURE fallback for kernel < 5.8 The fallback that was initially present in #1253 is needed for the current GitLab runners which have a Container-Optimized OS [1] with kernel 5.4 [2] without support for LOOP_CONFIGURE [3]. [1] https://docs.gitlab.com/ee/ci/runners/saas/linux_saas_runner.html [2] https://gitlab.com/cki-project/containers/-/jobs/4381560305#L31 [3] https://gitlab.com/cki-project/containers/-/jobs/4381560305#L1166 Signed-off-by: Michael Hofmann --- osbuild/loop.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osbuild/loop.py b/osbuild/loop.py index 679eb75a..5e1725f0 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -381,6 +381,7 @@ class Loop: Bind and configure in a single operation a file descriptor to the loopback device. Only supported for kenel >= 5.8 + Will fall back to set_fd/set_status otherwise. The loopback device must be unbound. The backing file must be either a regular file or a block device. If the backing file is @@ -430,7 +431,13 @@ class Loop: # Keep same behavior here by setting the value to 0. config.block_size = 0 config.info = self._config_info(LoopInfo(), offset, sizelimit, autoclear, partscan) - fcntl.ioctl(self.fd, self.LOOP_CONFIGURE, config) + try: + fcntl.ioctl(self.fd, self.LOOP_CONFIGURE, config) + except OSError as e: + if e.errno != errno.EINVAL: + raise + fcntl.ioctl(self.fd, self.LOOP_SET_FD, config.fd) + fcntl.ioctl(self.fd, self.LOOP_SET_STATUS64, config.info) def get_status(self) -> LoopInfo: """Get properties of the loopback device