Feature: Make mkfs.btrfs allow the creation of subvolumes with nocow attributes
Since btrfs-progs 6.11, mkfs.btrfs has the option of creating subvolumes via the "--subvol TYPE:SUBDIR" parameter. This is a very nice feature leveraged by "systemd-repart" to create btrfs subvolumes without root, as does not requires loopback mounts.
Currently the supported types are "ro, rw, default, default-ro", but nocow is not supported. Extending this parameter to address the cow attribute will help to create images that uses btrfs nocow subvolumes via mkosi without root.
More info: https://github.com/systemd/mkosi/discussions/3711
What is the problem we are solving by using nocow? Remember that nocow also implies nodatasum, that is no checksums will be available for the user data.
The problem is purely related to the interface, NODATASUM/NODATACOW is a per-inode flag, not a per-subvolume one.
In theory we can add such subvolume flag for mkfs.btrfs, but it will eventually become problematic if we want to implement the full per-inode flag passing for mkfs.btrfs.
I can try to implement the per-subvolume one first, but it may need quite a lot of extra preparation work first, to implement the proper inode flag inheritance first.
Hi @Forza-tng !
What is the problem we are solving by using nocow?
In openSUSE we have this distribution (MicroOS) that is read-only and transactional (snapper + tukit). The subvolumes for /, /etc, /usr/local are ro, but for /var we need nocow (where usualy VMs, container, or larger data bases are stored)
For the mkosi/repart prototype we've ageed to have some way (probably a command line option --subvol-nocow) in experimental build so the use case can be tested. The final solution is the protofile which may take longer to implement.
Done in this PR: https://github.com/kdave/btrfs-progs/pull/987
The new option --inode-flags is very similar to --subvol, with the following differences:
-
The flag is mandatory
-
The path can be any file/directory/subvolume
-
The inode flag will be inherited by any child inode
So if one sets an inode flag for a subvolume (the root inode of that subvolume) or a directory, new files created under that inode will automatically inherit the flag.
The only thing one needs to pay attention is the inheritance ends at subvolume boundary, thus even if the parent directory inode has some inode flag, the new subvolume created under that directory will not inherit the flag.
The new option also works with --compress option, but nodatacow or nodatasum inode flags will reject compression.
Please give it a try and any feedback will be appreciated.
@aplanas Can you please check that the --inode-flags works for your usecase? It's now in the devel branch and the interface looks ok to me so it won't be under the experimental build.
The feature looks exactly what it is needed, and can be implemented in systemd-repart in a similar way that was done for --subvol.
Reading a bit seems that --inode-flags can specify file, directory or subvolume. IIUC for the MicroOS case, when mkfs.btrfs --subvol=ro:/var is used, then --inode-flags=nodatacow:/var can be used to set the nocow attrb.? That would be perfect.
works for your usecase?
Following the test case in https://github.com/kdave/btrfs-progs/commit/3eff85222fb83c7682c5d24c0a6351588594da9e locally, yes, #987 will close this issue.
Thanks, closing.