Commit Graph

7449 Commits

Author SHA1 Message Date
David Sterba
2f09d42d6b btrfs-progs: docs: update sysfs descriptions
Add sections for each directory so it's more visible where the sections
start and end. Update formatting, enhance descriptions.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
ea421ec2a2 btrfs-progs: docs: fix typos
Thanks to hunspell.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
06d01abe82 btrfs-progs: docs: update json API
Add currently implemented types and update recommendations.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
7e0f506241 btrfs-progs: scrub status: fix rate units
There's a special case when scrub rate is printed, the device sizes and
rate use different units. The size can be in terabytes while the rate
can be in hundreds of megabytes (contemporary 10-20T disks, 250MB/s).

The sizes use what is set on command line (or human readable by
default), while the rate is always human readable with exception to
the option --raw to provide a way to print the exact numbers without any
conversions.

This got broken in commit ec3c842859 ("btrfs-progs: scrub status:
with --si, show rate in metric units") that forced the command line mode
to the rate as well.

Instead of that we need to detect the SI/IEC mode and set it to the
human readable format of rate.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
cab2eeb9ff btrfs-progs: fix UNITS_DECIMAL and UNITS_NEGATIVE bit definitions
The values of UNITS_ modes are supposed to be unique and
non-overlapping. Due to wrong definition this was not true for
UNITS_DECIMAL which set 2 bits. This breaks code that strictly depends
on the uniqueness of the bits and not on the order of processing of the
constants.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
6f0b332de2 btrfs-progs: README: add status badge of codeql workflow
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
5b5a2d25fa btrfs-progs: ci: add workflow for CodeQL
Enable CodeQL code scanning checks. For that the automatically detected
build steps don't work as the documentation is expected to build. Add
the manual steps.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
912dcd5bff btrfs-progs: ci: update Dockerfile CMD syntax
Docker warns about CMD syntax, which is harmless in our case but let's
fix the warning by using the json (quoted strings in array) syntax.

  JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 29)

Explained in https://docs.docker.com/reference/build-checks/json-args-recommended .

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
460dd6a32e btrfs-progs: docs: update mkfs.btrfs manual page
Fix missing or wrong formatting, enhance descriptions or add more
references.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
4bfcadabdf btrfs-progs: mkfs: print type of subvolume in the listing
Print indicators in the summary if the subvolume is read-write,
read-only or default:

$ mkfs.btrfs --subvol ro:subvolro --subvol rw:subvolrw --subvol default-ro:defaultro --rootdir /rootdir/path img
...
Rootdir from:       /rootdir/path
  Compress:         no
  Subvolume (rw):   subvolrw
  Subvolume (ro):   subvolro
  Subvolume (dro):  defaultro
...

The path is relative to the rootdir path and may not be a subvolume in
the source directory so drop the rootdir as this may be confusing.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
6a5e20ebde btrfs-progs: mkfs: fix printing of subvolumes in the summary
The subvolumes created during mkfs are not printed in the summary
because btrfs_mkfs_fill_dir() deletes them from the list as they get
created.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
260ddff355 btrfs-progs: mkfs: print errno string instead of numeric values
The preferred error message should have a prefix with problem
description and then the errno description as we use the negative errno
convention almost everywhere.

- drop additional %d in the message if %m is present
- replace %d with %m

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:32 +01:00
David Sterba
6afa173ce9 btrfs-progs: mkfs: update subvolume related error messages
Unify the error message style a bit, print the relevant path if missing.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-15 00:08:22 +01:00
David Sterba
e5d3ba75ab btrfs-progs: mkfs: factor out parsing of option --subovlume
Keep the case code to minimum and move the parsing to a helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
c92b635cb7 btrfs-progs: unify init sequence of standalone utilities
Each utility that starts from main() (and is considered commonly used)
should init fastest checksum implementation and set up config. This was
properly done only in btrfs.c, fix it in btrfs-image, btrfs-convert and
btrfstune as all of them do a lot of checksum calculations. Other
standalone utilities do not need to do that.

- cpu_detect_flags();
- hash_init_accel();
- btrfs_config_init();

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
ffe019e367 btrfs-progs: tune: print builtin features in --version output
For parity with 'btrfs', also print the builtin features.

  $ btrfstune --version
  btrfs-image, part of btrfs-progs v6.12
  +EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=builtin

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
0df367aec9 btrfs-progs: image: print builtin features in --version output
For parity with 'btrfs', also print the builtin features.

  $ btrfs-image --version
  btrfs-image, part of btrfs-progs v6.12
  +EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=builtin

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
65ad4e466f btrfs-progs: convert: print builtin features in --version output
For parity with 'btrfs', also print the builtin features, although not
all of them are relevant.

  $ btrfs-convert --version
  btrfs-convert, part of btrfs-progs v6.12
  +EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=builtin

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
2e118b1fc3 btrfs-progs: mkfs: print builtin features in --version output
For parity with 'btrfs', also print the builtin features as the
compression is now available.

  $ mkfs.btrfs --version
  mkfs.btrfs, part of btrfs-progs v6.12
  +EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=builtin

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
773efda132 btrfs-progs: factor out builtin feature string
We have more optionally built features, like compression for mkfs and
want to print that too. Factor out the common code.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
6e52a4e6be btrfs-progs: mkfs: use verbosity helpers
The message helpers can be used in some places instead of raw printf or
open coded level checks.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
abc2497465 btrfs-progs: mkfs: completely remove --leafsize option
This has been deprecated since 4.0 and mkfs fails since 6.0 with that
option. No need to keep it around anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
Qu Wenruo
7c1c88e416 btrfs-progs: scrub: add the new --limit option to set the throughput limit at runtime
Add a new option `--limit <throughput_limit>` to `btrfs scrub start`.

This has some extra behavior differences compared to `btrfs scrub limit`:

- Only set the value for the involved scrub device(s)
  If it's a full fs scrub, it will be the same as
  `btrfs scrub limit -a -l <value>`.
  If it's a single device, it will bt the same as
  `btrfs scrub limit -d <devid> -l <value>`.

- Automatically revert to the old limit after scrub is finished

- It only needs one single command line to set the limit

Issue: #943
Signed-off-by: Qu Wenruo <wqu@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
9794c739ca btrfs-progs: device add: update --nodiscard spec to take no argument
By mistake in the original commit 992fd23180 ("btrfs-progs: add
nodiscard option to device add") the --nodiscard could take an optional
parameter but this was not intended. This is also not documented so
there's little chance somebody would actually use it like that.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
b6bfaa72f3 btrfs-progs: docs: update command line and UI conventions
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
d27df0a2a3 btrfs-progs: docs: move command line guidelines do dev
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
df7aa728b0 btrfs-progs: tests: add cases to combine --help with other options
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
ec5ebf35ec btrfs-progs: help: recognize --help option among other options
There's a report that handling of --help in connection with other option
is confusing in some cases:

Various sub-commands to btrfs claim --help is an unrecognized option if
there are any other options on the CLI.

Examples of --help being unrecognized.

  $ btrfs filesystem defragment -v --help
  btrfs filesystem defragment: unrecognized option '--help'
  Try 'btrfs filesystem defragment --help' for more information

  $ btrfs balance start -v --help
  $ btrfs balabtrfs balance start -v --help
  btrfs balance start: unrecognized option '--help'
  Try 'btrfs balance start --help' for more information

Alternatively, some sub-commands support --help even if there are extra
options on the CLI:

  $ btrfs filesystem df -v --help
  usage: btrfs filesystem df [options] <path>

      Show space usage information for a mount point

      -b|--raw                  raw numbers in bytes
      -h|--human-readable       human friendly numbers, base 1024 (default)
      -H                        human friendly numbers, base 1000
      --iec                     use 1024 as a base (KiB, MiB, GiB, TiB)
      --si                      use 1000 as a base (kB, MB, GB, TB)
      -k|--kbytes               show sizes in KiB, or kB with --si
      -m|--mbytes               show sizes in MiB, or MB with --si
      -g|--gbytes               show sizes in GiB, or GB with --si
      -t|--tbytes               show sizes in TiB, or TB with --si

      Global options:
      --format TYPE             where TYPE is: text

Update clean_args_no_options() to detect unrecognized options properly
and do not show full help text (which usued to be done in the past but
is confusing and not pointing to the problem).

There's also a mixup of global verbosity options and command-specific
verbosity options (now deprecated), so in some commands they are
recognized.

Also handle the --help option for commands without options so the
following works:

  $ btrfs fi df -v --help /
  btrfs filesystem df: invalid option 'v'
  Try 'btrfs filesystem df --help' for more information

  $ btrfs fi df -H --help /
  usage: btrfs filesystem df [options] <path>

      Show space usage information for a mount point

      -b|--raw                  raw numbers in byte
  ...

Issue: #889
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
998a690670 btrfs-progs: qgroup clear-stale: check if qgroup enabled first
If qgroups are not enabled the 'clear-stale' command unconditionally
calls sync on the whole filesystem, which is unnecessary and can slow
down the system. Do a check first if qgroups are enabled.

Issue: #942
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
Qu Wenruo
fe27c052cb btrfs-progs: docs: extra notes about read-only scrub on read-write fs
[BUG]
There is a bug report that read-only scrub on a read-write fs still
causes writes into the fs, and that will be caught if there is a
read-only block device among the storage stack.

This will cause a kernel warning on failed transaction commit:

  BTRFS info (device dm-3): first mount of filesystem e18f0c40-88de-413f-9d7e-dcc8136ad6dd
  BTRFS info (device dm-3): using crc32c (crc32c-intel) checksum algorithm
  BTRFS info (device dm-3): using free-space-tree
  BTRFS info (device dm-3): scrub: started on devid 1
  Trying to write to read-only block-device md127
  btrfs_dev_stat_inc_and_print: 362 callbacks suppressed
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 1, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 2, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 3, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 4, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 5, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 6, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 7, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 8, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 9, rd 0, flush 0, corrupt 0, gen 0
  BTRFS error (device dm-3): bdev /dev/mapper/data errs: wr 10, rd 0, flush 0, corrupt 0, gen 0
  BTRFS: error (device dm-3) in btrfs_commit_transaction:2523: errno=-5 IO failure (Error while writing out transaction)
  BTRFS info (device dm-3 state E): forced readonly
  BTRFS warning (device dm-3 state E): Skipping commit of aborted transaction.
  BTRFS error (device dm-3 state EA): Transaction aborted (error -5)
  BTRFS: error (device dm-3 state EA) in cleanup_transaction:2017: errno=-5 IO failure
  BTRFS warning (device dm-3 state EA): failed setting block group ro: -5
  BTRFS info (device dm-3 state EA): scrub: not finished on devid 1 with status: -5

[CAUSE]
The root cause is inside btrfs_inc_block_group_ro(), where we need to
hold a transaction handle, to prevent the transaction to be committed,
until we hold ro_block_group_mutex.

This will cause an empty transaction by itself, thus even if we can mark
the block group read-only without any extra workload, we still need to
commit the new and empty transaction.

Unfortunately this means RO scrub on RW filesystem will always cause the
fs to be updated.

[FIX]
The best fix is to make btrfs to avoid empty commit transaction, but
even with that done, read-only scrub on rw mount can still cause real
metadata updates (e.g. allocate new chunks and update device error
statistics).

It will be very complex to make read-only scrub to be fully read-only
on a read-write btrfs.

Thankfully read-only scrub on read-write mount with read-only device in
the storage stack is pretty rare, thus a documentation update should be
enough.

Issue: #934
Pull-request: #935
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
8a9f351812 btrfs-progs: docs: mention CONFIG_BTRFS_EXPERIMENTAL if relevant
The new option for experimental featues was added in 6.12, mention it
where the DEBUG option was previously used for the same purpose.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
b5e7734220 btrfs-progs: mkfs: update help text
Enhance information in the help text where some interesting information
was not missing and would require looking up the documentation.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
0552d219b6 btrfs-progs: convert: add option --version, update help text
For completeness and parity with other tools add the option --version
and mention --help.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
014dbcd4d7 btrfs-progs: btrfstune: add option --version, update help text
For completeness and parity with other tools add the option --version
and mention --help.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
ff360123c4 btrfs-progs: image: add option --version, update help text
For completeness and parity with other tools add the option --version
and mention --help.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
50f725b707 btrfs-progs: build: move --disable-lzo option closer to zstd
There are two configure options for compression so group them and update
the description so it mentions all commands that use compression.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
451bf7390f btrfs-progs: mkfs: print in summary if compression is used
$ mkfs.btrfs --compress zlib:9 --rootdir Documentation img
  ...
  Rootdir from:       /path/Documentation
    Compress:         zlib:9
    Shrink:           no
  ...

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
97127657b0 btrfs-progs: mkfs: add --compress and --rootdir constraints
It does not make sense to pass only the compression option when there
are no files being added by --rootdir.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
1285676253 btrfs-progs: mkfs: document level ranges for zlib and zstd in help
Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
765cda8ca6 btrfs-progs: mkfs: validate compression levels while parsing options
Report invalid compression specification while parsing the options. Now
an ivalid level won't be silently accepted and capped when processing
the files. Other checks regarding conditional support of LZO and ZSTD
are left in place.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
9e641d7f76 btrfs-progs: mkfs: move compression level definitions to rootdir.h
The constants will be used in main() to validate command line options.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
65aa8a16c7 btrfs-progs: mkfs: change compression level type to 32bit type
The level is a small number, no need to pass it around as u64.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
c36a428d6c btrfs-progs: mkfs: factor out compression option parsing
Put option parsing to its own helper to keep the switch/case smaller.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
d23cfb860f btrfs-progs: mkfs: print which compression algos are compiled in
The compression support is optional, eg. also in 'btrfs-restore', so
print the support in help text.

usage: mkfs.btrfs [options] <dev> [<dev...>]

...
    --compress ALGO[:LEVEL]   compress files by algorithm and level, ALGO can be 'no' (default), zstd, lzo, zlib
                              Built-in:
                              - ZSTD: yes
                              - LZO: yes
                              - ZLIB: yes
...

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:28 +01:00
David Sterba
4f4b173269 btrfs-progs: mkfs: update compression help and documentation
Move the option documentation next to --rootdir, reword documentation.

Signed-off-by: David Sterba <dsterba@suse.com>
2025-02-11 20:43:23 +01:00
David Sterba
52379d2dcd btrfs-progs: mkfs: insert newline between sections in help
Improve readability and add space between sections.

usage: mkfs.btrfs [options] <dev> [<dev...>]

    Create a BTRFS filesystem on a device or multiple devices

    Allocation profiles:
    -d|--data PROFILE         data profile, raid0, raid1, raid1c3, raid1c4, raid5, raid6, raid10, dup or single
    -m|--metadata PROFILE     metadata profile, values like for data profile
    -M|--mixed                mix metadata and data together

    Features:
    --csum TYPE
    --checksum TYPE           checksum algorithm to use, crc32c (default), xxhash, sha256, blake2
    -n|--nodesize SIZE        size of btree nodes
    -s|--sectorsize SIZE      data block size (may not be mountable by current kernel)
    -O|--features LIST        comma separated list of filesystem features (use '-O list-all' to list features)
    -L|--label LABEL          set the filesystem label
    -U|--uuid UUID            specify the filesystem UUID (must be unique for a filesystem with multiple devices)
    --device-uuid UUID        Specify the filesystem device UUID (a.k.a sub-uuid) (for single device filesystem
                              only)
...

Signed-off-by: David Sterba <dsterba@suse.com>
2025-01-22 20:25:48 +01:00
David Sterba
e93bbeb0bd btrfs-progs: docs: documentation updates and fixes
Signed-off-by: David Sterba <dsterba@suse.com>
2025-01-22 20:24:26 +01:00
David Sterba
79895689df btrfs-progs: docs: add headings for 6.12 and 6.13 changelogs
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2025-01-21 21:31:14 +01:00
David Sterba
52c0bf4bab btrfs-progs: docs: document new ioctl SYNC_WAIT
Signed-off-by: David Sterba <dsterba@suse.com>
2025-01-21 21:19:00 +01:00
David Sterba
1c219aeaf9 btrfs-progs: docs: update status page and features
Signed-off-by: David Sterba <dsterba@suse.com>
2025-01-20 18:29:32 +01:00