Skip to content

Commit

Permalink
Revert "osbuild: ensure loop.Loop() has the required device node"
Browse files Browse the repository at this point in the history
This reverts commit 158acaa.

With osbuild/bootc-image-builder#238 the
original reason to call mknod goes away so we can just revert
it. osbuild now requires not only the loop device but also uses
`losetup --partscan` quite a lot now so the mknod approach becomes
impractical and the consumers of osbuild in a container should
just setup devtmpfs.
  • Loading branch information
mvo5 authored and bcl committed Mar 12, 2024
1 parent dd57546 commit c0c386e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
13 changes: 2 additions & 11 deletions osbuild/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"UnexpectedDevice"
]

# can be mocked in tests
DEV_PATH = "/dev"


class UnexpectedDevice(Exception):
def __init__(self, expected_minor, rdev, mode):
Expand Down Expand Up @@ -127,14 +124,8 @@ def __init__(self, minor, dir_fd=None):

with contextlib.ExitStack() as stack:
if not dir_fd:
dir_fd = os.open(DEV_PATH, os.O_DIRECTORY)
dir_fd = os.open("/dev", os.O_DIRECTORY)
stack.callback(lambda: os.close(dir_fd))
# ensure the device node is availale, in containers it may
# not get dynamically created
try:
self.mknod(dir_fd)
except FileExistsError:
pass
self.fd = os.open(self.devname, os.O_RDWR, dir_fd=dir_fd)

info = os.stat(self.fd)
Expand Down Expand Up @@ -543,7 +534,7 @@ def __init__(self, dir_fd=None):

with contextlib.ExitStack() as stack:
if not dir_fd:
dir_fd = os.open(DEV_PATH, os.O_DIRECTORY)
dir_fd = os.open("/dev", os.O_DIRECTORY)
stack.callback(lambda: os.close(dir_fd))

self.fd = os.open("loop-control", os.O_RDWR, dir_fd=dir_fd)
Expand Down
11 changes: 0 additions & 11 deletions test/mod/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import contextlib
import fcntl
import os
import pathlib
import threading
import time
from tempfile import TemporaryDirectory, TemporaryFile
Expand Down Expand Up @@ -261,13 +260,3 @@ def on_close(l):
def test_loop_handles_error_in_init(mocked_open): # pylint: disable=unused-argument
with pytest.raises(FileNotFoundError):
loop.Loop(999)


@pytest.mark.skipif(os.getuid() != 0, reason="root only")
def test_loop_create_mknod():
# tmpdir must be /var/tmp because /tmp is usually mounted with "nodev"
with TemporaryDirectory(dir="/var/tmp") as tmpdir:
with patch.object(loop, "DEV_PATH", new=tmpdir):
lopo = loop.Loop(1337)
assert lopo.devname == "loop1337"
assert pathlib.Path(f"{tmpdir}/loop1337").is_block_device()

0 comments on commit c0c386e

Please sign in to comment.