loop: add get_status method

Implement a `Loop.get_status` method, to get the properties of the
loop device, corresponding to LOOP_GET_STATUS64, and counterpart
to the existing `Loop.set_status` method. Use the new `get_status`
call in the `set_status` call, replacing the existing code that
does the same thing.
Add a basic test for the `get_status` method. Also fix an actual
leak, where the loop device was closed but the fd was not cleared
inside the test.
This commit is contained in:
Christian Kellner 2021-08-07 16:06:28 +00:00 committed by Tom Gundersen
parent 2c64c65608
commit 73f24c68a2
2 changed files with 18 additions and 4 deletions

View file

@ -4,8 +4,6 @@
import contextlib
import os
from tempfile import TemporaryDirectory
import pytest
@ -39,9 +37,15 @@ def test_basic(tempdir):
f.flush()
lo = ctl.loop_for_fd(f.fileno())
sb = os.fstat(f.fileno())
assert lo
assert lo.devname
info = lo.get_status()
assert info.lo_inode == sb.st_ino
assert info.lo_number == lo.minor
finally:
if lo:
with contextlib.suppress(OSError):