Commit graph

5668 commits

Author SHA1 Message Date
David Sterba 830422fa7e btrfs-progs: build: capitalize variable names in the summary
The CFLAGS and LDFLAGS should be referred to as they appear in the
makefile.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:44 +02:00
David Sterba 1d0fa3781e btrfs-progs: build: make libudev selectable
Previously the build would be optional based on what is installed on the
system. Add an option to make this selectable by user, ie. to allow
build without libudev even if it is installed on the system.

For most users and distros libudev dependency should be ok, but we've
had requests to disable various features (embedded, systems with
non-systemd user space base system) so let's do the same.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:43 +02:00
David Sterba c6c2e3da0a btrfs-progs: device scan: rename is_path_device
The term 'path' is confusing as we normally use it for filesystem paths,
while for multipath it's more related to the physical path by which the
devices are connected (though it also shows up as another path in the
filesystem).

Rename the helper doing the multipath detection so it's clear what path
is meant by that.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:42 +02:00
Nikolay Borisov 1b7128c152 btrfs-progs: add fallback code for multipath device detection for static build
Since libudev doesn't provide a static version of the library for static
build btrfs-progs will have to provide manual fallback. This change does
this by parsing the udev database files hosted at /run/udev/data/.
Under that directory every block device should have a file with the
following name: bMAJ:MIN. So implement the bare minimum code necessary
to parse this file and search for the presence of DM_MULTIPATH_DEVICE_PATH
udev attribute. This could likely be racy since access to the udev
database is done outside of libudev but that's the best that can be
done when implementing this manually and is only for a limited usecase
where static build has to be used.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:37 +02:00
Nikolay Borisov 681b4bd5e1 btrfs-progs: ignore devices representing paths in multipath
Currently btrfs-progs will happily enumerate any device which has a
btrfs filesystem on it irrespective of its type. For the majority of
use cases that's fine and there haven't been any problems with that.
However, there was a recent report that in multipath scenario when
running "btrfs fi show" after a path flap (path going down and then
coming back up) instead of the multipath device being show the device
which represents the flapped path is shown. So a multipath filesystem
might look like:

  Label: none  uuid: d3c1261f-18be-4015-9fef-6b35759dfdba
	  Total devices 1 FS bytes used 192.00KiB
	  devid    1 size 10.00GiB used 536.00MiB path /dev/mapper/3600140501cc1f49e5364f0093869c763

/dev/mapper/xxx is actually backed by an arbitrary number of paths,
which in turn are presented to the system as ordinary SCSI devices i.e
/dev/sdX. If a path flaps and a user re-runs 'btrfs fi show' the output
would look like:

  Label: none  uuid: d3c1261f-18be-4015-9fef-6b35759dfdba
	  Total devices 1 FS bytes used 192.00KiB
	  devid    1 size 10.00GiB used 536.00MiB path /dev/sdd

This only occurs on unmounted filesystems as those are enumerated by
btrfs-progs, for mounted filesystem the kernel properly deals only with
the actual multipath device.

Turns out the output of this command is consumed by libraries and the
presence of a path device rather than the actual multipath causes
issues.

Fix this by checking for the presence of DM_MULTIPATH_DEVICE_PATH
udev attribute as multipath path devices are tagged with this attribute
by the multipath udev scripts.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:35 +02:00
Nikolay Borisov f74ebeee5c btrfs-progs: build: add optional dependency on libudev
This is needed for future code which will make btrfs-progs' device
scanning logic a little smarter by filtering out path device in
multipath setups. libudev is added as an optional dependency since the
library doesn't have a static version so making it a hard dependency
means forfeiting static build support. To alleviate this a fallback code
will be added for the static build case which doesn't rely on libudev.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:32 +02:00
David Sterba 91c91c1632 btrfs-progs: sb-mod: improve help
Print the list of supported members to change and explain what the tool
does.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:30 +02:00
David Sterba f7e4860e9f btrfs-progs: sb-mod: don't fixup checksum for read-only ops
On images with some damage and mismatching checksum the read operations
will fixup the checksum. This may not be desired and does not make much
sense for read anyway.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:28 +02:00
Josef Bacik dd8e7477f7 btrfs-progs: remove data extents from the free space tree
Dave reported a failure of mkfs-test 009 with the free space tree
enabled by default.  This is because 009 pre-populates the file system
with a given directory, and for some reason our data allocation path
isn't the same as in the kernel.  Fix this by making sure when we
allocate a data extent we remove the space from the free space tree, and
with this our mkfs tests now pass.

Issue: #410
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:52 +02:00
David Sterba 64ed09c318 btrfs-progs: mkfs: switch to global verbosity options
Use the bconf verbosity so that other code outside of main.c respects
the command line settings.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:42 +02:00
David Sterba 2814ec6b1f btrfs-progs: mkfs: add option -v/--verbose
The default output of mkfs is intentionally verbose so we did not need
the verbosity option. For some additional information it could be useful
to increase the level in case it's wired to the global verbosity
settings.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:39 +02:00
David Sterba 2d50b98189 btrfs-progs: replace start: add option -K/--nodiscard
The commands initializing a new device (mkfs, device add) do discard by
default, while this is missing from replace start. For parity add the
options with same name and semantics.

Issue: #390
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:35 +02:00
David Sterba c50c448518 btrfs-progs: do sysfs detection of device discard capability
The detection of the discard status of a device is done by issuing a
real discard request but on an empty range. This works in most cases.
However there's a case of a VirtualBox driver that returns 'Operation
not supported' in that case, and then discard is skipped during mkfs.

The other tools like fstrim check the sysfs queue file
discard_granularity which is the recommended way. Do that as well.

Issue: #390
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:30 +02:00
David Sterba 6887a3192f btrfs-progs: tests: fix fsck/024 to work with free-space-tree
The test looks for a pattern FREE_SPACE that also matches
FREE_SPACE_TREE when it's enabled. Use word regexp to match the whole
word only.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:25 +02:00
Nikolay Borisov 451db51bdb btrfs-progs: remove support for BTRFS_SUBVOL_CREATE_ASYNC
Kernel has removed support for this feature in 5.7 so let's remove
support from progs as well.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:21 +02:00
Naohiro Aota 85e102f212 btrfs-progs: properly format btrfs_header in btrfs_create_root()
Enabling quota in zoned mored hits the following assertion:

    $ mkfs.btrfs -f -d single -m single -R quota /dev/nullb0
    btrfs-progs v5.11
    See http://btrfs.wiki.kernel.org for more information.

    Zoned: /dev/nullb0: host-managed device detected, setting zoned feature
    Resetting device zones /dev/nullb0 (1600 zones) ...
    bad tree block 25395200, bytenr mismatch, want=25395200, have=0
    kernel-shared/disk-io.c:549: write_tree_block: BUG_ON `1` triggered, value 1
    ./mkfs.btrfs(+0x26aaa)[0x564d1a7ccaaa]
    ./mkfs.btrfs(write_tree_block+0xb8)[0x564d1a7cee29]
    ./mkfs.btrfs(__commit_transaction+0x91)[0x564d1a7e3740]
    ./mkfs.btrfs(btrfs_commit_transaction+0x135)[0x564d1a7e39aa]
    ./mkfs.btrfs(main+0x1fe9)[0x564d1a7b442a]
    /lib64/libc.so.6(__libc_start_main+0xcd)[0x7f36377d37fd]
    ./mkfs.btrfs(_start+0x2a)[0x564d1a7b1fda]
    zsh: IOT instruction  sudo ./mkfs.btrfs -f -d single -m single -R quota /dev/nullb0

The issue occurs because btrfs_create_root() is not formatting the root
node properly. This is fine in regular mode, because it's fortunately
reusing an once freed buffer. As the previous tree node allocation
kindly formatted the header, it will see the proper bytenr and pass the
checks.

However, we never reuse a once freed buffer on zoned filesystem. As a
result, we have zero-filled bytenr, FSID, and chunk-tree UUID, hitting
the asserts in check_tree_block().

Reported-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-10-06 16:49:11 +02:00
Johannes Thumshirn c22e9487a7 btrfs-progs: remove max_zone_append_size logic
max_zone_append_size is unused and can as well be removed just like we
did on the kernel side.

Keep one sanity check though, so we're not adding devices to a zoned FS
that aren't supporting zone append.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:07 +02:00
Qu Wenruo 9d2460fb3f btrfs-progs: check: fix indentation of --clear-ino-cache option
Help string for "--clear-ino-cache" option is not following the
indentation of other help strings:

      repair options:
           --init-csum-tree            create a new CRC tree
           --init-extent-tree          create a new extent tree
           --clear-space-cache v1|v2   clear space cache for v1 or v2
           --clear-ino-cache 	    clear ino cache leftover items

The problem is caused by the usage of tab instead of space.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:00 +02:00
Naohiro Aota 53ec59ead0 btrfs-progs: do not zone reset on emulated zoned mode
We cannot zone reset a regular file with emulated zones. So, mkfs.btrfs
on such a file causes the following error.

  ERROR: zoned: failed to reset device '/home/naota/tmp/btrfs.img' zones: Inappropriate ioctl for device

Introduce btrfs_zoned_device_info->emulated to distinguish the zones are
emulated or not. And, use it to decide it needs zone reset or not.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:48:56 +02:00
David Sterba 0ccf519678
Btrfs progs v5.14.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 18:09:16 +02:00
David Sterba acd57f2356 btrfs-progs: update CHANGES for 5.14.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 18:08:31 +02:00
David Sterba 88de623dd2 btrfs-progs: convert: allow to set a duplicate uuid
Relax the condition about a unique uuid for convert, only print a
warning. In case we copy the uuid, it's expected that at the time the
conversion starts the uuid is not unique as it sill exists on the source
filesystem.

In case user sets the uuid manually but it's still the same one as on
the source filesystem we should also allow that, so it warns in this
case as well.

Update the test so it creates a block device where the uuid would be
also cached by blkid and lets the non-unique check succeed.

Issue: #404
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 16:58:13 +02:00
Qu Wenruo 3c7e75eefb btrfs-progs: tests: test case to make sure btrfstune rejects corrupted fs
Although btrfstune will already warn users to make sure the fs is not
corrupted, we can never trust end users.

If the target fs has transid error, btrfstune can cause further damage,
thus we need to make sure btrfstune can safely reject fs with transid
error, other than ignoring the problem.

The image is copied from fsck-tests/002, just override check_image() to
run "btrfstune -u" instead.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 12:26:20 +02:00
Qu Wenruo 60651ad9da btrfs-progs: introduce OPEN_CTREE_ALLOW_TRANSID_MISMATCH flag
[BUG]
There is a report that, btrfstune can even work while the fs has transid
mismatch problems.

  $ btrfstune -f -u /dev/sdb1
  Current fsid: b2b5ae8d-4c49-45f0-b42e-46fe7dcfcb07
  New fsid: b2b5ae8d-4c49-45f0-b42e-46fe7dcfcb07
  Set superblock flag CHANGING_FSID
  Change fsid in extents
  parent transid verify failed on 792854528 wanted 20103 found 20091
  parent transid verify failed on 792854528 wanted 20103 found 20091
  parent transid verify failed on 792854528 wanted 20103 found 20091
  Ignoring transid failure
  parent transid verify failed on 792870912 wanted 20103 found 20091
  parent transid verify failed on 792870912 wanted 20103 found 20091
  parent transid verify failed on 792870912 wanted 20103 found 20091
  Ignoring transid failure
  parent transid verify failed on 792887296 wanted 20103 found 20091
  parent transid verify failed on 792887296 wanted 20103 found 20091
  parent transid verify failed on 792887296 wanted 20103 found 20091
  Ignoring transid failure
  ERROR: child eb corrupted: parent bytenr=38010880 item=69 parent level=1 child level=1
  ERROR: failed to change UUID of metadata: -5
  ERROR: btrfstune failed

This leaves a corrupted fs even more corrupted, and due to the extra
CHANGING_FSID flag, btrfs check will not even try to run on it:

  Opening filesystem to check...
  ERROR: Filesystem UUID change in progress
  ERROR: cannot open file system

[CAUSE]
Unlike kernel, btrfs-progs has a less strict check on transid mismatch.

In read_tree_block() we will fall back to use the tree block even its
transid mismatch if we can't find any better copy.

However not all commands in btrfs-progs needs this feature, only
btrfs-check (which may fix the problem) and btrfs-restore (it just tries
to ignore any problems) really utilize this feature.

[FIX]
Introduce a new open ctree flag, OPEN_CTREE_ALLOW_TRANSID_MISMATCH, to
be explicit about whether we really want to ignore transid error.

Currently only btrfs-check and btrfs-restore will utilize this new flag.

Also add btrfs-image to allow opening such fs with transid error.

Link: https://www.reddit.com/r/btrfs/comments/pivpqk/failure_during_btrfstune_u/
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 12:17:29 +02:00
David Sterba 7d16785ab4 btrfs-progs: tests: test options for defrag -c
Regression test for "btrfs-progs: fix defrag -c option parsing"

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 11:46:24 +02:00
David Sterba 96a5cf0719 btrfs-progs: handle EINVAL when reading zone size on older kernels
A combination of new progs and old kernel may lead to problems with
detecting zone size by ioctl. Fixed by #376 but still incomplete because
old kernels may return EINVAL for unsupported ioctl. This should be
ENOTTY but hasn't been like that until kernel 5.11.

As we always pass valid arguments to the ioctl we can't conflate the two
and can EINVAL the same way as ENOTTY.

Issue: #399
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 11:31:09 +02:00
David Sterba 61e00694e7 btrfs-progs: fix defrag -c option parsing
The refactoring f3a132fa1b ("btrfs-progs: factor out compression type
name parsing to common utils") caused a bug with parsing option -c with
defrag:

  # btrfs fi defrag -v -czstd file
  ERROR: unknown compression type: zstd

  # btrfs fi defrag -v -clzo file
  ERROR: unknown compression type: lzo

  # btrfs fi defrag -v -czlib file
  ERROR: unknown compression type: zlib

Fix it by properly checking the value representing unknown compression
algorithm.

Issue: #403
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-18 17:48:32 +02:00
David Sterba 38f19d161c
Btrfs progs v5.14
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-10 16:47:28 +02:00
David Sterba 8a6ad8c8d7 btrfs-progs: update CHANGES for 5.14
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-10 14:53:30 +02:00
David Sterba 4980de3a5f btrfs-progs: read partition size from sysfs as fallback
Reading partition size using an ioctl requires the device open, but that
does not work for unprivileged users. This leads to 0 size in device
info structures filled by device_get_partition_size.

As a consequence, this also misreports such devices as missing in 'fi
us' overview:

 $ btrfs fi us /
 WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
 Overall:
     Device size:		 411.35GiB
     Device allocated:		  53.01GiB
     Device unallocated:	 358.34GiB
     Device missing:		 411.35GiB
     Used:			  31.99GiB
     Free (estimated):		 379.16GiB	(min: 379.16GiB)
     Free (statfs, df):		 379.35GiB
     Data ratio:		      1.00
     Metadata ratio:		      1.00
     Global reserve:		 194.77MiB	(used: 0.00B)
     Multiple profiles:		        no

There should be 0 for 'Device missing'.

Add a fallback to read the device size from sysfs in case the ioctl is
not available.

Issue: #395
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-10 13:09:05 +02:00
David Sterba 56e9963474 btrfs-progs: libbtrfs: hide unused symbols, same version
Another step to decommission libbtrfs in favor of libbtrfsutil. Remove
all symbols that are not used by snapper, as this is the only known
widely distributed tool that uses some of the librarized functionality,
apart from the ioctls.

The symbol versioning does not allow to remove once exported symbol so
this is a dirty trick that works only in this situation. The unused
symbols are not exported anymore BUT the library has the same version.
This would be normally an ABI violation, but there's no change for
snapper (build and runtime verified on version 0.9.0).

The known used symbols are preserved.

* btrfs_subvolid_resolve
* btrfs_read_and_process_send_stream
* subvol_uuid_search_init
* subvol_uuid_search

Issue: #218
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 18:17:30 +02:00
David Sterba 80c9c31055 btrfs-progs: libbtrfs: cleanup libbtrfs.sym exports
Move wrongly placed functions and remove duplicates. Library not
affected.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 18:17:30 +02:00
David Sterba 53c9618ce0 btrfs-progs: libbtrfs: drop btrfs-list.h, raid56.h and btrfsck.h
libbtrfs isn't a proper library and exports internal headers that aren't
included from other headers and their use in public API does not make
sense. There are no known applications using them so don't install them.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 18:17:29 +02:00
David Sterba 7b2d6cd778 btrfs-progs: tests: add more API coverage to library-test
Update the library test stub to cover all the API functions we care
about (send stream, subvol search) and drop the rootid lookup that's
trivial to do via raw ioctls.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 18:16:16 +02:00
David Sterba 419cb3011c btrfs-progs: open code btrfs_list_get_path_rootid
The function btrfs_list_get_path_rootid is exported to libbtrfs so it
needs to stay, but we can inline the implementation.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 16:35:47 +02:00
David Sterba 400b66689e btrfs-progs: move btrfsck.h to check/
This is part of the checker and unfortunately also the public header, so
we can only copy it to the right directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:49:33 +02:00
David Sterba 50292bc009 btrfs-progs: merge props.c to cmds/property.c
The property definitions and handlers are for the command line
processing, so merge it with the main source file.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:41:24 +02:00
David Sterba 022a560033 btrfs-progs: move props.h to cmds/
This is included only by the command line handler, move it there.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:33:24 +02:00
David Sterba ee17bcec33 btrfs-progs: remove stale declaration from send.h
We don't use this header for kernel compilation so the guarded
declaration is pointless.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:27:59 +02:00
David Sterba e86425242f btrfs-progs: move send.h to kernel-shared/
The header contains the protocol definitions and is almost exactly the
same as the kernel version, move it to the proper directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:26:46 +02:00
David Sterba c1953c36dd btrfs-progs: move all private definitions to cmds/qgroup.c
Move everything related to the output formatting and filtering out of
qgroup.h and leave only the structures used by the public API.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:21:14 +02:00
David Sterba f67e5da2fa btrfs-progs: remove prefix from all static qgroup helpers
The exported functions provided by qgroups have been changed, now remove
the prefix from the local helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:15:55 +02:00
David Sterba 49671bf29e btrfs-progs: add prefixes to exported qgroup helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:09:33 +02:00
David Sterba 353b55a5cf btrfs-progs: unexport local qgroup helpers
After merging the files, many functions can be made static, leaving only
a few helpers that are used by subvolume.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:07:54 +02:00
David Sterba ae56c6a071 btrfs-progs: merge qgroup.c into cmds/qgroup.c
The contents of top level qgroups.c is only for command line output and
filtering, we already have cmds/qgroup.c for that so merge the files.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 18:59:43 +02:00
David Sterba 6e0e0d467f btrfs-progs: move qgroup.h to cmds/
There are declarations that are namely for the command line out put,
filters and formatting. Move it to cmds/.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 18:45:59 +02:00
David Sterba 9d98ad1db5 btrfs-progs: tests: add templates for most common test types
Create a ready-to-use templates for the most common tests, copied from
readme.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 18:10:56 +02:00
David Sterba 5b0e18ce6c btrfs-progs: tests: properly load dm-thin in mkfs/017
The test started to fail some time ago when dm-thin was changed to
dm-thin-pool that loads 2 targets dm-thin and dm-thin-pool. We can now
properly detect both and run the test.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 16:58:43 +02:00
David Sterba 37e0aa576c btrfs-progs: tests: allow alternate name for dm target detection
Some dm target name and module do not match exacly, extend the helper to
take optional 2nd parameter that will be checked in case loading by the
first parameter fails.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 16:57:06 +02:00
David Sterba 6694fe5de9 btrfs-progs: tests: do dm target detection by one
Switch the helper to take only one parameter, the target name. This can
be used to extend the helper with additional parameters for the target.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 16:48:42 +02:00