btrfs: Mount with `flushoncommit` flag

Not an expert on this, but my understanding is that without this flag,
outages will result in a state that despite being consistent, most
applications are not mature enough to handle. Namely, we ran benchmarks
that reproduced appearance of zero-length files upon sudden poweroffs.

Databases should be fine since they know well about the guarantees the
filesystem must provide, but not applications are databases. So let's
play safe about this.

See:
- https://thunk.org/tytso/blog/2009/03/12/delayed-allocation-and-the-zero-length-file-problem/
- https://github.com/Zygo/bees/issues/68#issuecomment-403262059
This commit is contained in:
Mehran Kholdi 2021-06-26 01:38:53 +04:30
parent d52f8ffbe0
commit c11646e08c
1 changed files with 7 additions and 1 deletions

View File

@ -40,7 +40,13 @@ def be_mounted(dev, mountpoint):
# noinspection PyUnreachableCode
be_unmounted(mountpoint)
run(f"mount {dev} {mountpoint}")
fs = current_fs(dev)
if fs == "ext4":
run(f"mount {dev} {mountpoint}")
elif fs == "btrfs":
run(f"mount -o flushoncommit {dev} {mountpoint}")
else:
raise Exception(f"Unsupported fs type: {fs}")
def be_unmounted(path):