From 43fb8698602e63b39b376d15c24adedcca17d63f Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 13 Aug 2021 10:02:45 +0000 Subject: [PATCH] loop: helper to call `ioctl_blockdev_flushbuf` Add a small new helper that calls `linux.ioctl_blockdev_flushbuf` for the block device. --- osbuild/loop.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osbuild/loop.py b/osbuild/loop.py index 3710c3d3..0fd0f4e9 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -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