Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs-progs: (chattr) Failure to create swapfile in fs with compression off in subvolume #384047

Open
3 tasks done
donottellmetonottellyou opened this issue Feb 21, 2025 · 1 comment
Labels
0.kind: bug Something is broken

Comments

@donottellmetonottellyou

Nixpkgs version

  • Stable (24.11)

Describe the bug

Btrfs supports both file compression and nodatacow, but not at the same time. btrfs-progs supports setting the compression algorithm at a per-subvolume level, without having to specify mount options for the subvolume. When this is done for a subvolume, btrfs will set the m attribute for each file in the subvolume:

A file with the 'm' attribute is excluded from compression on file systems that support per-file compression.

However, whether due to design or otherwise, chattr does not support setting +C (no copy-on-write) on files that have the m attribute. Trying to do so creates this error:

chattr: Invalid argument while setting flags on /path/to/file

This gets us to the core of the issue, which is that the command btrfs filesystem mkswapfile does not work in certain circumstances where it should. It creates this (obtuse) error:

ERROR: cannot set NOCOW flag: Invalid argument

Steps to reproduce

  1. use default or latest kernel
  2. Make a btrfs filesystem and mount it
  3. run btrfs property set compression zstd /path/to/mounted/fs
  4. make a new subvolume inside the fs: btrfs subvolume create /path/to/mounted/fs/@subvolume
  5. set compression off in the subvolume: btrfs property set compression none /path/to/mounted/fs/@subvolume
  6. attempt to create a swapfile: btrfs filesystem mkswapfile /path/to/mounted/fs/@subvolume/swapfile
  7. error occurs and swapfile creation is aborted

Expected behaviour

btrfs should remove the m attribute before setting the C attribute, this works fine in my testing

Screenshots

No response

Relevant log output

Additional context

There are two issues I can see here, first is that man chattr fails to document that the m attribute conflicts with the C attribute. An appropriate warning is on the c attribute:

Note: For btrfs, If the 'c' flag is set, then the 'C' flag cannot be set.

But for some reason the m attribute does not have this warning.

The second issue is that btrfs itself fails to document that removing the m attribute is necessary:

To create and activate a swapfile run the following commands:

# truncate -s 0 swapfile
# chattr +C swapfile
# fallocate -l 2G swapfile
# chmod 0600 swapfile
# mkswap swapfile
# swapon swapfile

These commands will not work on a subvolume with the property compression none.

This is likely an upstream issue?

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.12.10-zen1, NixOS, 24.11 (Vicuna), 24.11.714685.36864ed72f23
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.24.12
  • channels(root): "home-manager-24.11.tar.gz, nixos-24.11, nixos-unstable"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Notify maintainers

@7c6f434c @shlevy @alyssais @dezgeg @vcunat @K900 @edolstra @Ma27 @viric @globin @delroth

Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

@donottellmetonottellyou donottellmetonottellyou added the 0.kind: bug Something is broken label Feb 21, 2025
@donottellmetonottellyou
Copy link
Author

This may be caused by setting compression none instead of compression ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant