I have a btrfs partition mounted on / with compression enabled:
mount -o subvol=@,defaults,noatime,nodiratime,compress=zstd,space_cache=v2 /dev/mapper/archlinux /mnt
I want to disable the CoW mecanism on some folders such as:
- The folder which contains my VM disks
- Any folder that might contain SQLite databases (mostly for browsers)
Here's what btrfs documentation states :
If compression is enabled, nodatacow and nodatasum are disabled.
But it also states
If nodatacow or nodatasum are enabled, compression is disabled.
I'm ok with the fact that they are mutually exclusive, however I do wonder which one will take priority if I set chattr +C to a folder. Will my change remain permanent ? Or will it be overriden during the next boot when my partition is remounted with the compress option ? My guts tell me that chattr +C will take precedence, but I've been unable to find any documentation that would confirm that.
Second question is: is there a way to automatically disable CoW on all newly created SQLite databases ? At first I wanted to write a systemd timer which would scan the whole file system to look for SQLite databases and set chattr +C on it. But then in the chattr man page I read the following:
If it is set on a file which already has data blocks, it is undefined when the blocks assigned to the file will be fully stable.
So basically I should not use chattr +C on existing non-empty files. Is there a way to hook into the filesystem so that any file that ends with \.(sqlite|db) or has the SQLite magic bytes won't use CoW ? Or do I have no other choice but to manually create the NoCoW folder before I install the targetted application ? I don't necessarily know if X or Y app is using an SQLite backend, it would be very inconvenient to remove all the app data to set NoCoW every time I realise an app is using SQLite. What would you recommend to somehow automate this process ?
EDIT:
Do you think it should be distributions maintainers responsibility to set chattr +C during installation of packages that use SQLite ?