loop: helper to call ioctl_blockdev_flushbuf

Add a small new helper that calls `linux.ioctl_blockdev_flushbuf`
for the block device.
This commit is contained in:
Christian Kellner 2021-08-13 10:02:45 +00:00 committed by Achilleas Koutsou
parent 7762f46594
commit 43fb869860

View file

@ -6,6 +6,7 @@ import os
import stat
import time
from .util import linux
__all__ = [
"Loop",
@ -163,6 +164,19 @@ class Loop:
fcntl.flock(self.fd, op)
def flush_buf(self) -> None:
"""Flush the buffer cache of the loopback device
This function might be required to be called before the usage
of `clear_fd`. It seems that the kernel (as of version 5.13.8)
is not clearing the buffer cache of the block device layer in
case the fd is manually cleared.
NB: This function needs the `CAP_SYS_ADMIN` capability.
"""
linux.ioctl_blockdev_flushbuf(self.fd)
def set_fd(self, fd):
"""Bind a file descriptor to the loopback device