Commit Graph

7149 Commits

Author SHA1 Message Date
Qu Wenruo
136c58617c btrfs-progs: convert: make sure the length of data chunks are also stripe aligned
Although kernel scrub code has been updated to handle the unaligned
chunk length, there is also no harm if we can allocate data chunk with
both start and length aligned.

This patch handles this by rounding up the end bytenr when allocating
data chunks for the conversion.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-16 19:11:54 +01:00
Jonas Malaco
1d37d3ef91 btrfs-progs: scrub start: consider the lowest non-zero limit
On multi-device filesystems, a scrub limit may be applied to any of the
devices. Ensure that any limit found is not disregarded.

Since it's more intuitive, keep the lowest non-zero limit found, even
though at the present we don't actually use the exact value.

Pull-request: #733
Issue: #727
Fixes: 7e4a235df1 ("btrfs-progs: scrub status: print device speed limit in status if set")
Signed-off-by: Jonas Malaco <jonas@protocubo.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-15 17:07:22 +01:00
Jonas Malaco
96011debe4 btrfs-progs: scrub status: consider the lowest non-zero limit
On multi-device filesystems, a scrub limit may be applied to any of the
devices. Ensure that any limit found is not disregarded.

Since it's more intuitive, keep the lowest non-zero limit found, even
though at the present we don't actually use the exact value.

Pull-request: #733
Issue: #727
Fixes: 7e4a235df1 ("btrfs-progs: scrub status: print device speed limit in status if set")
Signed-off-by: Jonas Malaco <jonas@protocubo.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-15 17:07:22 +01:00
Jonas Malaco
8bca55d1e7 btrfs-progs: scrub status: only report limits if at least one exists
On multi-device filesystems, scrub status should report "some limits
set" if at least one device has a scrub limit set.

However, with btrfs-progs 6.6.3, this was being reported regardless of
whether any limit actually being set:

    # sudo btrfs scrub limit /more/butter
    UUID: 989129d9-c96f-4d52-9d68-cbb6d9b2c499
    Id  Limit       Path
    --  -----  ---------
     1      -  /dev/sdc1
     2      -  /dev/sdd1

    # sudo btrfs scrub status /more/butter/
    UUID:             989129d9-c96f-4d52-9d68-cbb6d9b2c499
    Scrub started:    Mon Jan 15 02:00:30 2024
    Status:           running
    Duration:         6:23:19
    Time left:        0:49:08
    ETA:              Mon Jan 15 09:12:57 2024
    Total to scrub:   9.83TiB
    Bytes scrubbed:   8.72TiB  (88.64%)
    Rate:             397.47MiB/s (some device limits set)
    Error summary:    no errors found

Fix it by only setting `limit` to the special marker value 1 if at least
one actual limit is found.

Pull-request: #733
Issue: #727
Fixes: 7e4a235df1 ("btrfs-progs: scrub status: print device speed limit in status if set")
Signed-off-by: Jonas Malaco <jonas@protocubo.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-15 17:07:19 +01:00
Qu Wenruo
631ee66639 btrfs-progs: convert: for ext2, fix possible tree-checker error when converting a large fs
[BUG]
There is a report about failed btrfs-convert, which shows the following
error:

  corrupt leaf: root=5 block=5001928998912 slot=1 ino=89911763, invalid previous key objectid, have 89911762 expect 89911763
  ERROR: failed to copy ext2 inode 89911320: -5
  ERROR: error during copy_inodes -5
  WARNING: error during conversion, the original filesystem is not modified

[CAUSE]
Above error is triggered when checking the following items inside a
subvolume:

- inode ref
- dir item/index
- file extent
- xattr

This is to make sure these items have correct previous key.

However btrfs-convert is not following this requirement, it always
inserts those items first, then creates a btrfs_inode for it.

Thus it can lead to the error.

This can only happen for large fs, as for most cases we have all these
modified tree blocks cached, thus tree-checker won't be triggered.
But when the tree block cache is not hit, and we have to read from disk,
then such behavior can lead to above tree-checker error.

[FIX]
Make sure we insert the inode item first, then the file extents/dir
items/xattrs.  And after the file extents/dir items/xattrs inserted, we
update the existing inode (to update its size and bytes).

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-12 16:36:36 +01:00
Qu Wenruo
94ace90508 btrfs-progs: tree-checker: dump the tree block when hitting an error
Unlike kernel where tree-checker would provide enough info so later we
can use "btrfs inspect dump-tree" to catch the offending tree block, in
progs we may not even have a btrfs to start "btrfs inspect dump-tree".
E.g during btrfs-convert.

To make later debuging easier, let's call btrfs_print_tree() for every
error we hit inside tree-checker.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-12 16:34:44 +01:00
Anand Jain
8049446bb0 btrfs-progs: docs: placeholder for contents.rst file on older sphinx version
Older versions of sphinx require the contents.rst file otherwise the
build fails, while new versions don't need it and use index.rst.

Sphinx error:

master file btrfs-progs/Documentation/contents.rst not found
make[1]: *** [Makefile:37: man] Error 2
make: *** [Makefile:502: build-Documentation] Error 2

This build error is seen on version 1.7.6-3.

To make it work on old and new versions create a placeholder empty file
but make it a phony build target so new sphinx does not see it and
report as not in any TOC.

[ci skip]

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-11 17:04:48 +01:00
Anand Jain
2b3d95519e btrfs-progs: docs: fix sphinx code-block warnings
There are several warnings regarding the absence of an argument for the
code-block directive on some build servers using python3-sphinx 0.2.2-17.

For example:

Making all in Documentation
    [SPHINX] man
ch-subvolume-intro.rst:141: WARNING: Error in "code-block" directive:
1 argument(s) required, 0 supplied.

.. code-block::

   27 21 0:19 /subv1 /mnt rw,relatime - btrfs /dev/sda rw,space_cache

 Etc...

Add the none argument.

[ci skip]

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-10 22:49:06 +01:00
Qu Wenruo
dbd175734a btrfs-progs: cli-tests: add test case for return value of "btrfs subvlume create"
The test case would check if "btrfs subvolume create":

- Report error on an existing path
- Still report error if mulitple paths are given and one of them already
  exists
- For above case, still created a subvolume for the good parameter

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-10 16:31:39 +01:00
Qu Wenruo
3f988c9176 btrfs-progs: subvolume: fix return value when the target exists
[BUG]
When try to create a subvolume where the target path already exists, the
"btrfs" command doesn't return error code correctly.

  # mkfs.btrfs -f $dev
  # mount $dev $mnt
  # touch $mnt/subv1
  # btrfs subvolume create $mnt/subv1
  ERROR: target path already exists: $mnt/subv1
  # echo $?
  0

[CAUSE]
The check on whether target exists is done by path_is_dir(), if it
returns 0 or 1, it means there is something in that path already.

But unfortunately commit 5aa959fb34 ("btrfs-progs: subvolume create:
accept multiple arguments") only changed the out label, which would
directly return @ret, not updating the return value correctly.

[FIX]
Make sure all error out branch has their @ret manually updated.

Fixes: 5aa959fb34 ("btrfs-progs: subvolume create: accept multiple arguments")
Issue: #730
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-10 04:16:13 +01:00
David Sterba
faa75347f6 btrfs-progs: docs: update status
Bump version, all the new features in 6.7 have been already added.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-09 17:00:39 +01:00
David Sterba
228848aabe btrfs-progs: docs: add 6.7 kernel development statistics
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-09 16:53:17 +01:00
Sam James
46101b0137 btrfs-progs: build: use AS_IF for target_cpu condition
The autoconf manual recommends AS_IF [1] nowadays rather than bare shell
if tests as they can interfere with quoting and macro expansion.

[1] https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AS_005fIF-1

Pull-request: #721
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-04 18:43:05 +01:00
Sam James
a79560163c btrfs-progs: build: fix bashism in target_cpu comparison
The "=" operator should be used as configure may be run by a POSIX shell
at /bin/sh (like dash). Bash recognises "=" too so this retains
compatibility with it.

Pull-request: #721
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-04 18:43:02 +01:00
David Sterba
92e18dbce5
Btrfs progs v6.6.3
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-14 15:27:36 +01:00
David Sterba
d11bd4cb6a btrfs-progs: update CHANGES for 6.6.3
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-14 15:26:13 +01:00
David Sterba
eaa54973b6 btrfs-progs: scrub limit: add option to apply the limit to all devices
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:57:29 +01:00
David Sterba
30d1a2d390 btrfs-progs: scrub limit: allow to set the limit
Add new options to set the per-device limit (requires root privileges as
it writes to the sysfs files).

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:57:27 +01:00
David Sterba
87dba20daf btrfs-progs: change all sysfs helpers to return errno
To be consistent with the rest of the code the sysfs helper should
return the -errno instead of passing -1 from various syscalls. Update
callers that relied on -1 as the invalid file descriptor.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Sterba
4576029dfd btrfs-progs: add write helpers for sysfs files
Add convenience wrappers for writing a buffer or u64 to toplevel or FSID
file in sysfs.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Disseldorp
b3b38751e9 btrfs-progs: scrub status: improve Rate reporting for sub-second durations
Scrubs which complete in under one second may carry a duration rounded
down to zero. This subsequently results in a bytes_per_sec value of
zero, which corresponds to the Rate metric output, causing intermittent
tests/btrfs/282 failures.

This change ensures that Rate reflects any sub-second bytes processed.
Time left and ETA metrics are also affected by this change, in that they
increase to account for (sub-second) bytes_per_sec.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Sterba
7f869161b7 btrfs-progs: docs: update scrub io limiting
[ci skip]

Issue: #402
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Sterba
9a044fa0ff btrfs-progs: scrub start: print device limit if set
Print one message per scrubbed device and also print the limit if set:

  $ btrfs scrub start /mnt
  scrub started on /mnt, fsid 9ee93131-f680-4d6c-8ca4-a194506e3081 (pid=27257)
  Starting scrub on devid 1 (limit 100.00MiB/s)

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Sterba
6e96df640b btrfs-progs: tests: add case for scrub limit
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Sterba
fbf211459a btrfs-progs: srcub: new subcommand limit
Add new command to read the scrub limits set via the sysfs file (no root
access needed).

Example output:

  $ btrfs scrub limit /mnt
  UUID: 57a05502-9e81-4b21-ad9d-0fc31863ed11
  Id  Limit            Path
  --  -----  --------------
   1      -  /dev/nvme0n1p1
   2      -  /dev/nvme0n1p2
   3      -  /dev/nvme0n1p3
   4      -  /dev/nvme2n1p4
   5      -  /dev/nvme0n1p5
   6      -  /dev/nvme0n1p6

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-09 01:17:22 +01:00
David Sterba
deffef9cec btrfs-progs: README: add compatibility
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-08 17:08:55 +01:00
David Sterba
b5909e62b2 btrfs-progs: use statvfs() in print_filesystem_usage_overall
The statfs(2) syscall is deprecated by LSB in favor of statvfs(2),
however we can't replace all uses because we still need the
statfs::f_type to determine the filesystem by magic numer.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-08 17:08:55 +01:00
David Sterba
71ad6f2f53 btrfs-progs: subvol sync: check if the filesystem is writable
The subvolume cleaning is done by polling but it's possible that the
filesystem turns to read-only (as reported), either due to an error
intentionally. In that case the waiting would be indefinite without an
obvious reason.

To fix that check if the filesystem is still writable in each iteration.

Issue: #535
Link: https://github.com/btrfs/fstests/issues/40
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-08 17:08:55 +01:00
David Sterba
7e4a235df1 btrfs-progs: scrub status: print device speed limit in status if set
When there's a speed limit set for a device via
/sysfs/fs/btrfs/FSID/devinfo/scrub_speed_max, show it in the scrub status
output like below:

  $ btrfs scrub status -d /mnt
  ...
  Rate:              47.98MiB/s (limit 60MiB/s)
  ...

If the limit is 0 this means unlimited and is not printed.

For a single device filesystem the limit is printed even without '-d' as
it's clear which device limit applies. For multi-device filesysetms,
without any limits nothing is printed, if there at least one device
limit set then the following is printed:

  Rate:             36.37MiB/s (some device limits set)

More details with the -d option.

Issue: #531
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-08 17:08:33 +01:00
David Sterba
f8711016eb btrfs-progs: receive: properly report lack of zstd support
If zstd is not compiled in then a stream fails with a generic error
message:

ERROR: unknown compression: 2

Where BTRFS_ENCODED_IO_COMPRESSION_ZSTD is 2 and there's a case for that
but behind the '#if COMPRESSION_ZSTD'.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-07 14:29:54 +01:00
David Sterba
9aafb384cb btrfs-progs: docs: cross references, ioctl updates
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-06 17:44:28 +01:00
David Sterba
478a295b00 btrfs-progs: docs: document label ioctls
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-06 17:44:28 +01:00
David Sterba
f9ebee6838 btrfs-progs: ci: install RTD sphinx theme for devel workflow
With the recent updates to documentation build the theme must be now
installed as a package. Disable building documentation in all workflows
that do functional tests.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-06 16:03:37 +01:00
David Sterba
c1ce48ed3f btrfs-progs: docs: document device add and remove ioctls
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 20:17:31 +01:00
David Sterba
216c9f0ffb btrfs-progs: docs: move doc conventions to developer docs
The DocConventions are now fairly complete and can be moved to the
proper section.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 19:33:28 +01:00
Qu Wenruo
eae4109054 btrfs-progs: check: remove inode cache clearing functionality
Since we're already directing the end user to use "btrfs rescue
clear-ino-cache" command, there is not much need to support it in
btrfs-check.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 17:57:04 +01:00
Qu Wenruo
171dd56995 btrfs-progs: docs: update the man page for btrfs check lowmem mode
Lowmem mode has improved quite a lot since its introduction, for
read-only check it's definitely fine.

For repair mode, both lowmem and original mode are considered dangerous
especially for complex corruptions with unknown cause.

For now lowmem mode is only bad at fixing fundamentally corrupted cases,
like bad shift offsets or transid, which in real world it's not an easy
repair for the original mode either.

This patch would move the --mode option out of the dangerous section and
update the notes for the lowmem mode on its limitation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 17:37:25 +01:00
David Sterba
5c91264d2d btrfs-progs: subvol delete: print the id of the deleted subvolume
Currently the path of deleted subvolume is printed, we should also print
the numeric id as it's another identifier commonly found and can be used
for a cross reference. In connection with the qgroup deletion it's
making the output clear:

...
Delete subvolume 258 (no-commit): '/mnt/subv1'
Delete qgroup 0/258
...

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 17:08:42 +01:00
David Sterba
8b9684f965 btrfs-progs: docs: add config file for readthedocs.io
There's another config required for building the RTD documentation,
https://docs.readthedocs.io/en/stable/config-file/ .

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 16:36:24 +01:00
David Sterba
cc2e3ab03d btrfs-progs: docs: update and restyle links of source repositories
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 16:19:09 +01:00
David Sterba
71042e8bb0 btrfs-progs: tests: add test for subvolume delete and qgroups
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 12:36:44 +01:00
David Sterba
9da773aa46 btrfs-progs: subvol delete: add options to delete the qgroup
The 0/subvolid qgroups are not automatically deleted when the subvolume
is deleted, for historical reasons. There's a command to clean up all
such stale qgroups (btrfs qgroup clean-stale) but this should be also
possible with the subvolume deletion.

With the options we can switch the default to delete the qgroup by
default eventually, if somebody depends on the not deleting behaviour
the negation option can be used.

Issue: #366
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 12:36:44 +01:00
David Sterba
a396f49cb8 btrfs-progs: build: conditionally detect x86_64 compiler flags
Compiling with clang on aarch64 leads to an error when detecting the
SIMD instruction support. Gcc ignores the arch/feature mismatch.
Conditionally detect the -m flags only on x86_64.

Issue: #712
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-05 12:36:44 +01:00
David Sterba
bc70e12877 btrfs-progs: ci: add clang to devel build tests
Add clang as compiler for the basic build checks in the CI.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-04 18:55:47 +01:00
David Sterba
4ac630b5dc btrfs-progs: ci: update packages providing pahole
Centos 8 does not provide the package at all, on musl it's in the
package 'pahole'.

Issue: #710
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-04 18:47:31 +01:00
David Sterba
8ea9a3e2c6 btrfs-progs: print a message when enqueued operation is waiting
The enqueue option should let the user know that the expected operation
hasn't started yet and that it's waiting for another one. Although the
exclusive operations can take long, the two reason should be
distinguished.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-01 03:22:29 +01:00
David Sterba
c0592c5591 btrfs-progs: tests: warning and timeout when removing multiple devices
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-01 03:04:58 +01:00
David Sterba
9e55abfd77 btrfs-progs: device delete: add timeout when removing multiple devices
Reported on IRC, that it's unexpected that passing several devices on
command line for 'btrfs device delete' still uses some of the devices
during deletion. The expectation was that they'd be removed at once (and
thus not used for the intermediate chunk relocation).

As it works now, the ioctl removes only one device. As a workaround, add
a timeout (like we have for the full balance and others) when there are
more devices passed on the command line. This can be skipped by the
--force parameter.

Issue: #708
Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-01 02:54:09 +01:00
David Sterba
a0468efe86 btrfs-progs: reset errno before strtoull()
strtoull may return the boundary values, if the callers could expect
that and verify it then the errno must be reset before the call.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-01 02:13:37 +01:00
David Sterba
e9a66cde91 btrfs-progs: use get_sysfs_proto_supported() in device_get_zone_unusable()
Use the sysfs helper to read u64 values of the zoned stats.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-12-01 02:08:37 +01:00