Commit Graph

5465 Commits

Author SHA1 Message Date
Naohiro Aota
3acac33e8c btrfs-progs: consolidate parameter initialization of regular allocator
Move parameter initialization code for regular allocator to
init_alloc_chunk_ctl_policy_regular(). This will help adding another
allocator in the future.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
Naohiro Aota
605ffad6f0 btrfs-progs: convert type of alloc_chunk_ctl::type
Convert alloc_chunk_ctl::type to take the original type in
btrfs_alloc_chunk(). This will help refactoring in the following commits.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
Naohiro Aota
ff65b83306 btrfs-progs: refactor find_free_dev_extent_start()
Factor out the function dev_extent_search_start() from
find_free_dev_extent_start() to decide the starting position of a device
extent search.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
Naohiro Aota
1da9fede64 btrfs-progs: introduce chunk allocation policy
Introduce chunk allocation policy for btrfs. This policy controls how
chunks and device extents are allocated from devices.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
David Sterba
016aa9102a btrfs-progs: docs: how to use swapfile from fstab
This was asked on reddit, how to automatically mount a swapfile from
fstab. As this is not completely obvious, document it with an example.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
David Sterba
743d280915 btrfs-progs: docs: update chattr attribute for NOCOMPRESS
There were plans to add X as flag to set/unset the btrfs NOCOMPRESS
attribute but that never materialized. In e2fsprogs the letter 'm' has
been assigned to the same functionality and released in version 1.46.2.

Update the docs and mention that the compression options are
conflicting.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
Su Yue
31934b1161 btrfs-progs: fi resize: fix false 0.00B size output
Resize to nums without sign prefix makes false output:

  $ btrfs fi resize 1:150g /srv/extra
  Resize device id 1 (/dev/sdb1) from 298.09GiB to 0.00B

The resize operation would take effect though.

Fix it by handling the case if mod is 0 in check_resize_args().

Issue: #307
Reported-by: Chris Murphy <lists@colorremedies.com>
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
Qu Wenruo
82611f51a5 btrfs-progs: mkfs: only output the warning if the sectorsize is not supported
Currently mkfs.btrfs will output a warning message if the sectorsize is
not the same as page size:

  WARNING: the filesystem may not be mountable, sectorsize 4096 doesn't match page size 65536

But since btrfs subpage support for 64K page size is coming, this output
is populating the golden output of fstests, causing tons of false
alerts.

This patch will teach mkfs.btrfs to check
/sys/fs/btrfs/features/supported_sectorsizes and check if the sector
size is supported.

Then only output above warning message if the sector size is not
supported or the file is not found (ie. kernel does not export the file
yet).

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:40:51 +02:00
Neal Gompa
9e30f779e3 libbtrfsutil: relicense to LGPLv2.1+
This relicenses the libbtrfsutil library to LGPLv2.1+ from LGPLv3.
People that have contributed non-trivial changes acknowledged the change
and are listed below.

There's a potential licensing conflict with the 'btrfs' utility that is
GPLv2 and statically links libbtrfsutil, this is not a valid combination
per the compatibility matrix as found in
https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility or
http://gplv3.fsf.org/dd3-faq .

We also have an explicit request to change the license [1] (issue #323)
from LGPLv3 to allow use in environments that don't like GPLv3. Though
the library license is not GPLv3, the full text of the license is in the
repository and the 'lesser' part is an addendum. This was perhaps a bit
confusing, nevertheless this gets clarified as well.

[1] https://lore.kernel.org/linux-btrfs/b927ca28-e280-4d79-184f-b72867dbdaa8@denx.de/

Acked-by: Omar Sandoval <osandov@fb.com>
Acked-by: Misono Tomhiro <misono.tomohiro@jp.fujitsu.com>
Acked-by: Qu Wenruo <wqu@suse.com>
Acked-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Acked-by: Anand Jain <anand.jain@oracle.com>
Acked-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Link: https://bugs.debian.org/985400
Issue: #323
Signed-off-by: Neal Gompa <ngompa@fedoraproject.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-04-19 18:58:26 +02:00
Nikolay Borisov
0595309541 btrfs-progs: fix null pointer deref in balance_level
In case the right buffer is emptied it's first set to NULL and
subsequently it's dereferenced to get its size to pass to root_sub_used.
This naturally leads to a NULL pointer dereference. The correct thing to
do is to pass the stashed right->len in "blocksize".

Issue: #296
Pull-request: #360
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-04-19 18:58:26 +02:00
Naohiro Aota
c6b585034f btrfs-progs: mark BUG() as unreachable
Marking BUG() unreachable helps us silence unnecessary warnings e.g.
"warning: control reaches end of non-void function [-Wreturn-type]" like
the code below.

   int foo()
   {
   ...
   	if (XXX)
   		return 0;
	else if (YYY)
		return 1;
   	else
   		BUG();
   }

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-04-16 19:34:07 +02:00
David Sterba
4a9b83c7a4 btrfs-progs: docs: add more general ioctl description
Add general paragraphs and establish per-ioctl argument description
formatting, using [horizontal] where the struct member and the
description are on the same line, unlike ordinary ::.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
eb84891443 btrfs-progs: build: note about 32bit build on 64bit host
Notes for making it work:

- "CFLAGS=-m32 LDFLAGS=-m32 ./configure ..." passes the right flags
  everywhere, otherwise just passing it by EXTRA_CFLAGS/EXTRA_LDFLAGS
  might miss some binaries or libraries

- note that passing CFLAGS/LDFLAGS to configure will override the
  default flags

- libbtrfsutil and python bindings require to pass the -m32 flags via
  EXTRA_PYTHON_CFLAGS/EXTRA_PYTHON_LDFLAGS

- all the e2fsprogs, zlib, lzo, util-linux etc need packaging changes to
  provide static libraries - usually frowned upon by distribution unless
  justified, even less so for static + 32bit versions, very niche
  use case

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
f537bf6bd7 btrfs-progs: mkfs: remove stale csum_type initialization
The correct checksum type value is set a few lines below, there seems
to be stale crc32 initialization. Also remove the crc32c.h include as
it's not used directly anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
fb98c1e9fc btrfs-progs: crypto: remove unused sha256 definitions
Remove:

- sha1, sha384, sha512 related structures and helpers
- HKDF definitions
- USHA definitions

Keep HMAC.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
Johannes Thumshirn
94b60b67a9 btrfs-progs: pass in fs_info to btrfs_csum_data
For passing authentication keys to the checksumming functions we need a
container for the key.

Pass in a btrfs_fs_info to btrfs_csum_data() so we can use the fs_info
as a container for the authentication key.

Note this is not always possible for all callers of btrfs_csum_data() so
we're just passing in NULL for now

Functions calling btrfs_csum_data() with a NULL fs_info argument are
currently not supported in the context of an authenticated file system.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
6bb6d1215d btrfs-progs: factor open_ctree parameters to a structure
Extending open_ctree with more parameters would be difficult, we'll need
to add more so factor out the parameters to a structure for easier
extension.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
f0d226fa48 btrfs-progs: tests: add missing variable setup to test-console
The paths are not adapted to the TEST_TOP added long time ago in
e44f595dd7 ("btrfs-progs: tests: unify test drivers, make ready for
extenral testsuite").

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
05a92e6424 btrfs-progs: crypto: add test vectors
Add test vectors, a subset without keys as found in linux kernel sources
in crypto/test-mgr.h for all supported hash algorithms.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba
8d5051f279
Btrfs progs v5.11.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 19:35:32 +01:00
David Sterba
cb8b79b0bf btrfs-progs: update CHANGES for 5.11.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 19:34:03 +01:00
Pierre Labastie
b9f7f3f428 btrfs-progs: build: do not use AC_DEFINE twice for a FIEMAP define
Autoheader uses the AC_DEFINE macros (and a few others) to populate
the config.h.in file. The autotools documentation does not tell
what happens if AC_DEFINE is used twice for the same identifier.

This patch prevents using AC_DEFINE twice for
HAVE_OWN_FIEMAP_EXTENT_DEFINE, preserving the logic (using the
fact that an undefined identifier in a preprocessor directive is
taken as zero).

Signed-off-by: Pierre Labastie <pierre.labastie@neuf.fr>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:11:49 +01:00
Jaak Ristioja
2f9736d051 btrfs-progs: check: fix typos in code comment and 1 typo in warning
Pull-request: #356
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
Sidong Yang
78aa1d95dd btrfs-progs: fi resize: make output more readable
Make output of 'btrfs filesystem resize' command more readable and
describe the changes in more detail.

Before:
Resize '/mnt' of '1:-1G'

After:
Resize device id 1 (/dev/vdb) from 4.00GiB to 3.00GiB

Issue: #307
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
David Sterba
0c6e50dddd btrfs-progs: tests: verify that ext4 supports extra_isize
To properly check the 64bit timestamp conversion, the filesystem must
support it. Check that a freshly created filesystem contains the
feature.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
Pierre Labastie
1b49370973 btrfs-progs: build: fix the test for EXT4_EPOCH_MASK
Commit b3df561fbf ("btrfs-progs: convert: copy extra timespec on
ext4") has introduced the ability to convert extended inode time
precision on ext4, but this breaks builds on older distros, where ext4
does not have the nsec time precision.

Commit c615287cc0 ("btrfs-progs: a bunch of typo fixes") tried to fix
that by testing the availability of the EXT4_EPOCH_MASK macro, but the
test is not complete.

This patch aims at fixing the macro test, and changes the
name of the associated HAVE_ macro, since the logic is reverted.

This fixes #353 when ext4 has nsec time precision. Note that the test
convert/019-ext4-copy-timestamps fails when ext4 does not have the nsec
time precision and needs to check for the support.

Issue: #353
Signed-off-by: Pierre Labastie <pierre.labastie@neuf.fr>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
David Sterba
3a22f0b25b btrfs-progs: balance: fix raid56 warning for other profiles
The warning is printed for profiles where it's not intended (like raid0
or raid1c4). Check the correct variable for the target profiles.

Issue: #355
Fixes: 1ed5db8db4 ("btrfs-progs: balance convert: add a warning and countdown for RAID56 conversion")
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
David Sterba
cbadf0f1ae btrfs-progs: docs: change wording about required fsck
Make running the 'fsck' more explicit and add the commands with
recommended options.

Issue: #348
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
David Sterba
5d80df6065 btrfs-progs: tests: add crafted image to test needs_recovery
Image of ext4 with needs_recovery incompat bit set. This bit cannot be
set by regular tune2fs so was created on an empty 4M image by patched
tune2fs that set the bit unconditionally (the image still passed e2fsck,
with journal recovery).

Issue: #348
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:21 +01:00
David Sterba
2c53231af9 btrfs-progs: convert: refuse to convert filesystem with 'needs_recovery' set
As Chris reports: This ext4 file system has 'needs_recovery' feature set, and
if mounted rw, log replay happens. But btrfs-convert doesn't check for it and
converts anyway. It probably shouldn't.

  # debugfs -R stats /dev/loop0
  debugfs 1.45.6 (20-Mar-2020)
  Filesystem volume name:   <none>
  Last mounted on:          /mnt/0
  Filesystem UUID:          d3e3862e-f892-4ab7-ae91-84eb4be4a3ef
  Filesystem magic number:  0xEF53
  Filesystem revision #:    1 (dynamic)
  Filesystem features:      has_journal ext_attr resize_inode dir_index
			    filetype needs_recovery extent 64bit flex_bg
			    sparse_super large_file huge_file dir_nlink
			    extra_isize metadata_csum
  Filesystem flags:         signed_directory_hash
  Default mount options:    user_xattr acl
  Filesystem state:         clean
  Errors behavior:          Continue
  ...

Then 'btrfs-convert' proceeds, while 'e2fsck -fvn /dev/loop1' finds some
problems and wants to fix them.

Add a check for the 'needs_recovery' incompat bit set and don't convert
the filesystem.

Issue: #348
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
Heiko Becker
098e08b269 btrfs-progs: build: Use PKG_CONFIG instead of pkg-config
Hard-coding the pkg-config executable might result in build errors
on system and cross environments that have prefixed toolchains. The
PKG_CONFIG variable already holds the proper one and is already used
in a few other places.

Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Signed-off-by: Heiko Becker <heirecka@exherbo.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
David Sterba
542718c8d0 btrfs-progs: mkfs: enumerate all supported checksum algorithms in help text
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
Pierre Labastie
ea1e4c8a7b btrfs-progs: tests: fix quoting of sudo helper in misc/046-seed-multi-mount
When running the tests as root SUDO_HELPER is empty, so that
`run_check "" dd ...` is run, and it fails because the empty command is
not found.

Pull-request: #351
Issue: #352
Author: Pierre Labastie <pierre.labastie@neuf.fr>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
David Sterba
833bf64762 btrfs-progs: tests: extend mkfs/001 to look for warnings after mkfs
Patch "btrfs-progs: fix false alert on tree block crossing 64K page
boundary" fixes a false alert (warning) when 'btrfs check' is called
right after mkfs.

As we have an extensive mkfs coverage in test mkfs/001, add the check for
the warning there instead of a separate test.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
Qu Wenruo
33d84be030 btrfs-progs: fix false alert on tree block crossing 64K page boundary
[BUG]
When btrfs-check is executed on even newly created fs, it can report
tree blocks crossing 64K page boundary like this:

  Opening filesystem to check...
  Checking filesystem on /dev/test/test
  UUID: 80d734c8-dcbc-411b-9623-a10bd9e7767f
  [1/7] checking root items
  [2/7] checking extents
  WARNING: tree block [30523392, 30539776) crosses 64K page boudnary, may cause problem for 64K page system
  [3/7] checking free space cache
  [4/7] checking fs roots
  [5/7] checking only csums items (without verifying data)
  [6/7] checking root refs
  [7/7] checking quota groups skipped (not enabled on this FS)
  found 131072 bytes used, no error found
  total csum bytes: 0
  total tree bytes: 131072
  total fs tree bytes: 32768
  total extent tree bytes: 16384
  btree space waste bytes: 125199
  file data blocks allocated: 0
   referenced 0

[CAUSE]
Tree block [30523392, 30539776) is at the last 16K slot of page.
As 30523392 % 65536 = 49152, and 30539776 % 65536 = 0.

The cross boundary check is using exclusive end, which causes false
alerts.

[FIX]
Use inclusive end to do the cross 64K boundary check.

Reported-by: Wang Yugui <wangyugui@e16-tech.com>
Issue: #352
Issue: #354
Fixes: fc38ae7f48 ("btrfs-progs: check: detect and warn about tree blocks crossing 64K page boundary")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:48 +01:00
David Sterba
66931220e2 btrfs-progs: ci: fix symlink paths of helper scripts
Switch absolute symlink path to relative.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 14:59:42 +01:00
Dāvis Mosāns
a2ccf96d76 btrfs-progs: fix checksum output for "checksum verify failed"
Currently only single checksum byte is printed.  Fix it so that
the whole checksum is printed, in the order as the bytes are stored in
the buffer. This matches what kernel does, though it might not
correspond to the cases of CRC32C and XXHASH as if they were stored in
integer variable and printed in the native format. For consistency we
need to print the same format.

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 14:59:40 +01:00
David Sterba
3ea5d6584c
Btrfs progs v5.11
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-05 14:22:17 +01:00
David Sterba
622752ae2c btrfs-progs: update CHANGES for 5.11
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-05 00:01:40 +01:00
David Sterba
922797e155 btrfs-progs: docs: add section about raid56
Used sources:

- wiki
- IRC discussions
- https://lore.kernel.org/linux-btrfs/20200627032414.GX10769@hungrycats.org

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
David Sterba
2aeaea41a8 btrfs-progs: docs: add raid1c34 profiles to balance convert
The extended raid1 profiles are missing from the list.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
David Sterba
2910ca8009 btrfs-progs: balance: use --force to override timeout for raid56 conversions
Enhance --force to also skip the timeout, similar to what --full-balance
does. As this is only to warn about RAID56 that won't be necessary in
the future, don't add a separate option. The warning is still printed.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
Josef Bacik
1ed5db8db4 btrfs-progs: balance convert: add a warning and countdown for RAID56 conversion
Similar to the mkfs warning, add a warning to btrfs balance convert
options, with a countdown to allow the user to have time to cancel the
operation.

Issue: #265
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
Josef Bacik
73487311e9 btrfs-progs: mkfs: add a warning label for RAID5/6
We all know there's some dark and scary corners with RAID5/6, but users
may not know.  Add a warning message in mkfs so anybody trying to use
this will know things can go very wrong.

Issue: #265
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
[ reword message ]
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
David Sterba
b127845f9c btrfs-progs: link nested README.md from the main one
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
David Sterba
ee59a58112 btrfs-progs: ci: add README
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-04 21:14:41 +01:00
David Sterba
06bf4d0e8b btrfs-progs: tests: use force when decompressing images
Some tests report that decompressing the image failed, which did not
fail the test but could lead to wrong errors in case the image is not
overwritten and leaves some old state. Use --force parameter.

    [TEST]   fuzz-tests.sh
    [TEST/fuzz]   001-simple-check-unmounted
xz: btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw: File exists
failed to decompress image btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz
    [TEST/fuzz]   002-simple-image
xz: btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw: File exists
failed to decompress image btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-01 16:47:15 +01:00
David Sterba
464e73ff0d btrfs-progs: tests: add test for seeding device mounts
Test multiple mounts of a single device.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-01 16:47:15 +01:00
David Sterba
fc6818a46c btrfs-progs: docs: add section about seeding device
Issue: #341
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-01 16:47:15 +01:00
David Sterba
1304eb9e12 btrfs-progs: ci: add CentOS 8 image
Build tests inside CentOS 8, long term support distro.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-01 16:47:14 +01:00