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:
parent
7762f46594
commit
43fb869860
1 changed files with 14 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import os
|
||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from .util import linux
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Loop",
|
"Loop",
|
||||||
|
|
@ -163,6 +164,19 @@ class Loop:
|
||||||
|
|
||||||
fcntl.flock(self.fd, op)
|
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):
|
def set_fd(self, fd):
|
||||||
"""Bind a file descriptor to the loopback device
|
"""Bind a file descriptor to the loopback device
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue