From c11646e08c1f7110b97b3df1a636fe713efe77e1 Mon Sep 17 00:00:00 2001 From: Mehran Kholdi Date: Sat, 26 Jun 2021 01:38:53 +0430 Subject: [PATCH] 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 --- declarative.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/declarative.py b/declarative.py index f91372e..e06e9db 100644 --- a/declarative.py +++ b/declarative.py @@ -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):