Commit Graph

5462 Commits

Author SHA1 Message Date
Qu Wenruo 82e0720312 btrfs-progs: tests: also check subpage warning for check_image cases
There are two types of test cases:

- Type 1 (without test.sh)
- Type 2 (test.sh, mostly will override check_image())

For Type 2 tests, we check subpage related warnings of btrfs-check, but
didn't check it for Type 1 test cases.

In fact, Type 1 test cases are more important, as they involve repair,
which can generate new tree blocks, and we want to make sure such new
tree blocks won't cause subpage related warnings.

This patch will add the extra check for Type 1 test cases.

And it will make sure the subpage related warnings are really from this
test case, to prevent false alerts.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:42:47 +02:00
David Sterba dc29a5c51d btrfs-progs: convert: update default output
The messages printed by convert are incomplete regarding the source and
target filesystems and can be improved and unified with the style we
already have eg. in mkfs:

  $ btrfs-convert image
  btrfs-convert from btrfs-progs v5.13.1

  Source filesystem:
    Type:           ext2
    Label:
    Blocksize:      4096
    UUID:           b9bb96e0-7b2f-44a1-9670-1b6da27b26b0
  Target filesystem:
    Label:          NEWLABEL
    Blocksize:      4096
    Nodesize:       16384
    UUID:           c7dd7532-7e17-41b0-bf7c-12d695bbf6d0
    Checksum:       crc32c
    Features:       extref, skinny-metadata (default)
      Data csum:    yes
      Inline data:  yes
      Copy xattr:   yes
  Reported stats:
    Total space:      1073741824
    Free space:        805240832 (74.99%)
    Inode count:           65536
    Free inodes:           65525
    Block count:          262144
  Create initial btrfs filesystem
  Create ext2 image file
  Create btrfs metadata
  Copy inodes [o] [         0/        11]
  Set label to 'NEWLABEL'
  Conversion complete

  $ btrfs-convert -r image
  btrfs-convert from btrfs-progs v5.13.1

  Open filesystem for rollback:
    Label:
    UUID:            c7dd7532-7e17-41b0-bf7c-12d695bbf6d0
    Restoring from:  ext2_saved/image

Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
David Sterba 33543eb2b1 btrfs-progs: remove stale command declarations
The declarations do not correspond to any command descriptors as they
have been moved to other command groups.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
David Sterba 9f2bfd966e btrfs-progs: convert: rename context volume_name to label
The name was derived from ext2 but we use label elsewhere.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
David Sterba 03a9dbf784 btrfs-progs: tests: add test for convert --uuid option
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
David Sterba bcae45d9e6 btrfs-progs: convert: new option to copy or specify uuid
Add new option --uuid to convert with the following modes:

- 'copy' -- copy the UUID from the source filesystem
- 'new' -- (default) generate new UUID
- UUID -- a valid UUID that will be set on btrfs

Based on patch from Florian

https://lore.kernel.org/linux-btrfs/1357486331-4615-2-git-send-email-falbrechtskirchinger@gmail.com/

and ported to contemporary codebase.

Issue: #391
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
Qu Wenruo 9d5d3de01c btrfs-progs: subvol delete: try to delete subvolume by id when its path can't be resolved
There is a recent report of ghost subvolumes where such subvolumes has
no ROOT_REF/BACKREF, and 0 root ref.  But without an orphan item, thus
kernel won't queue them for cleanup.

Such ghost subvolumes are just here to take up space, and no way to
delete them except by btrfs check, which will try to fix the problem by
adding orphan item.

There is a kernel patch submitted to allow btrfs to detect such ghost
subvolumes and queue them for cleanup.

But btrfs-progs will not continue to call the ioctl if it can't find the
full subvolume path.

Thus this patch will loose the restriction by allowing btrfs-progs to
continue to call the ioctl even if it can't grab the subvolume path.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
Qu Wenruo a138daac17 btrfs-progs: mkfs: set super_cache_generation to 0 if we're using free space tree
[HICCUP]
There is a bug report that mkfs.btrfs -R free-space-tree still makes
kernel to try to cleanup the v1 space cache:

  # mkfs.btrfs -R free-space-tree -f /dev/test/scratch1
  # mount /dev/test/scratch1 /mnt/btrfs
  # dmesg | grep cleaning
  BTRFS info (device dm-6): cleaning free space cache v1

[CAUSE]
By default, mkfs.btrfs will set super cache generation to (u64)-1, which
will inform kernel that the v1 space cache is invalid, needs to
regenerate it.

But for free space cache tree, kernel will set super cache generation to
0, to indicate v1 space cache is not in use.

This means, even we enabled free space tree with all the RO compatible
bits and new tree, as long as super cache generation is not 0, kernel
still consider the fs has some invalid v1 space cache, and will try to
remove them.

[FIX]
This is not a big deal, but to make the "-R free-space-tree" to really
work as kernel, we also need to set super cache generation to 0.

Reported-by: Chris Murphy <lists@colorremedies.com>
Link: https://lore.kernel.org/linux-btrfs/CAJCQCtSvgzyOnxtrqQZZirSycEHp+g0eDH5c+Kw9mW=PgxuXmw@mail.gmail.com/
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
David Sterba e4ac7d4f67
Btrfs progs v5.13.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-30 16:14:58 +02:00
David Sterba 612512a99c btrfs-progs: update CHANGES for 5.13.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-30 16:14:29 +02:00
David Sterba 2f867c21e2 btrfs-progs: mkfs: update message when creating zoned fs with non-single profiles
The defaults for rotational devices are to enable DUP for metadata, this
does not yet work on zoned devices and fails with messages like:

  Zoned: /dev/sda: host-managed device detected, setting zoned feature
  ERROR: cannot use RAID/DUP profile in zoned mode

The RAID/DUP support will be implemented in the future and we don't want
to change the defaults to revert them back again. This makes it a bit
awkward for the user until this happens, so at least print a hint what
to do that single/single must be set manually.

Link: https://lore.kernel.org/linux-btrfs/20210706091922.38650-1-johannes.thumshirn@wdc.com/
Reported-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-30 16:13:58 +02:00
Qu Wenruo af62875784 btrfs-progs: tests: check nlinks for directories
Make sure btrfs check can detect such problem.  Right now we have no way
to fix it yet.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-30 15:52:57 +02:00
Qu Wenruo 478e98cd01 btrfs-progs: check/original: detect directory inode with nlinks >= 2
Linux VFS doesn't allow directory to have hard links, thus for btrfs
on-disk directory inode items, their nlinks should never go beyond 1.

Lowmem mode already has the check and will report it without problem.
Only original mode needs this update.

Reported-by: Pepperpoint <pepperpoint@mb.ardentcoding.com>
Link: https://lore.kernel.org/linux-btrfs/162648632340.7.1932907459648384384.10178178@mb.ardentcoding.com/
Reviewed-by: Su Yue <l@damenly.su>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-30 15:50:48 +02:00
Omar Sandoval e9c2942f38 libbtrfsutil: fix race between subvolume iterator and deletion
Subvolume iteration has a window between when we get a root ref (with
BTRFS_IOC_TREE_SEARCH or BTRFS_IOC_GET_SUBVOL_ROOTREF) and when we look
up the path of the parent directory (with BTRFS_IOC_INO_LOOKUP{,_USER}).
If the subvolume is moved or deleted and its old parent directory is
deleted during that window, then BTRFS_IOC_INO_LOOKUP{,_USER} will fail
with ENOENT. The iteration will then fail with ENOENT as well.

We originally encountered this bug with an application that called
`btrfs subvolume show` (which iterates subvolumes to find snapshots) in
parallel with other threads creating and deleting subvolumes. It can be
reproduced almost instantly with the included test cases.

Subvolume iteration should be robust against concurrent modifications to
subvolumes. So, if a subvolume's parent directory no longer exists, just
skip the subvolume, as it must have been deleted or moved elsewhere.

Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-29 13:01:55 +02:00
David Sterba 1907cd64db btrfs-progs: ci: add script to do build test on musl
Run ci/ci-build-musl to verify build of current branch works in
environment with musl libc. Also works for a given branch name.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-26 13:45:35 +02:00
er888kh f9979f9dd6 libbtrfsutil: fix typo in README example
Fix misplaced quote.

Pull-request: #387
Author: er888kh <45465346+er888kh@users.noreply.github.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-26 13:30:40 +02:00
Sidong Yang d302bf5b34 btrfs-progs: cmds: fix build on musl when using NAME_MAX
There is some code that using NAME_MAX but it doesn't include header
that is defined. This patch adds a line that includes linux/limits.h
which defines NAME_MAX.

Issue: #386
Issue: #385
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-26 13:28:22 +02:00
David Sterba 6527771668 btrfs-progs: add nparity for raid1c34 definitions
The values of .ncopies was not explicitly set.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-23 00:59:27 +02:00
Qu Wenruo 07ecf878c1 btrfs-progs: check: batch v1 space cache inodes when clearing
Currently v1 space cache clearing will delete one cache inode just in
one transaction, and then start a new transaction to delete the next
inode.

This is far from efficient and can make the already slow v1 space cache
deleting even slower, as large fs has tons of cache inodes to delete.

This patch will speed up the process by batching up to 16 inode deletion
into one transaction.

A quick benchmark of deleting 702 v1 space cache inodes would look like
this:

Unpatched:		4.898s
Patched:		0.087s

Which is obviously a big win.

Reported-by: Joshua <joshua@mailmag.net>
Link: https://lore.kernel.org/linux-btrfs/0b4cf70fc883e28c97d893a3b2f81b11@mailmag.net/
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-22 16:26:05 +02:00
Qu Wenruo 42566a50ec btrfs-progs: docs: fix the out-of-date comment about free space tree support
Since v4.19, btrfs-progs has full write support to free space tree, the
out-of-date warning in btrfs(5) has already confused some end user.

Update the content to avoid further confusion.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-22 16:00:10 +02:00
David Sterba de4914dbfd
Btrfs progs v5.13
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-13 14:31:38 +02:00
David Sterba 811371998c btrfs-progs: update CHANGES for 5.13
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-13 14:30:47 +02:00
David Sterba 562f06f22f btrfs-progs: README: update links
Make the libbtrfsutil library and license more visible in the overview.
Drop link to travis-ci.org CI as it's not used anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-08 14:53:16 +02:00
David Sterba dcb2ebd6ab btrfs-progs: docs: more hw considerations
Add section about NVME and hints what to do to some other sections.  The
rest are typo or style fixes.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-07 20:45:45 +02:00
David Sterba 78501931de btrfs-progs: docs: more about hardware considerations
Make it a new chapter with sections. The SSD and firmware parts were
inspired by a more detailed Zygo's writeup at
https://github.com/kdave/btrfs-progs/issues/319#issuecomment-739423260

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
Sidong Yang 94f3b75c00 btrfs-progs: zoned: fix memory leak in btrfs_sb_io()
In btrfs_sb_io(), blk_zone_report is used for getting information about
zones. But it is not freed if code goes in usual path. This patch frees
the variable just after it used.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
Goldwyn Rodrigues a7ed5b0ced btrfs-progs: correct check_running_fs_exclop() return value
check_running_fs_exclop() can return 1 when exclop is changed to "none"
The ret is set by the return value of the select() operation. Checking
the exclusive op changes just the exclop variable while ret is still
set to 1.

Set ret = 0 if exclop is set to BTRFS_EXCL_NONE or BTRFS_EXCL_UNKNOWN.
Remove unnecessary continue statement at the end of the block.

The command appears to have executed, but does not. This was found when
balance which typically reports chunks relocated did not print anything
on screen.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 5ffbbcedb1 btrfs-progs: docs: document zone device stats
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 96aedd1121 btrfs-progs: fi usage: swap order of Used and zoned information
The Used and Free should be together, while all the device information
is in the first section.

Example:

  Overall:
      Device size:                 128.00GiB
      Device allocated:             24.00GiB
      Device unallocated:          104.00GiB
      Device missing:                  0.00B
      Device zone unusable:          5.13MiB
      Device zone size:            256.00MiB
      Used:                        213.33MiB
      Free (estimated):            111.79GiB      (min: 111.79GiB)
      Free (statfs, df):           111.79GiB
      Data ratio:                       1.00
      Metadata ratio:                   1.00
      Global reserve:               25.58MiB      (used: 16.00KiB)
      Multiple profiles:                  no

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba a410805acc btrfs-progs: fi usage: print zone size in the overview
Read device size and print it in the overall overview in zoned mode. The
total unusable size is there so the zone size is complementing it. It's
read from the first device assuming that kernel mandates that all
devices have the same zone size.

Example:

  Overall:
      Device size:                 128.00GiB
      Device allocated:             24.00GiB
      Device unallocated:          104.00GiB
      Device missing:                  0.00B
      Used:                        213.33MiB
      Device zone unusable:          5.13MiB
      Device zone size:            256.00MiB
      Free (estimated):            111.79GiB      (min: 111.79GiB)
      Free (statfs, df):           111.79GiB
      Data ratio:                       1.00
      Metadata ratio:                   1.00
      Global reserve:               25.58MiB      (used: 16.00KiB)
      Multiple profiles:                  no

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 3d52313591 btrfs-progs: add helper to read zone size from sysfs
Sysfs hides the zone size of a block device in the queue/chunk_sectors
file, so add a helper that will read it for us when given the short
device name (that can be found in FSID/devices).

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba e25c8f00a3 btrfs-progs: add helper for opening sysfs fsid directory
There are several directories in /sys/fs/btrfs/FSID that contain more
than one file/directory. Add a helper to open the directory so that the
file descriptor can be used for fdopendir.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 1dc6f33c28 btrfs-progs: zoned: use fixed width type when reading zone size
The ioctl BLKGETZONESZ expects 32bit integer, declare the target
variable as such.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 4d86d928c1 btrfs-progs: mkfs: print note about loading sha256 when used
The module loading issue is documented but make it more visible at mkfs
time.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 0a020ba2d9 btrfs-progs: docs: note about loading accelerated sha256
If there's CONFIG_CRYPTO_SHA256=y in /proc/config.gz and no line with
'sha256' in /proc/modules, then the mount will use the generic
implementation.

After 'modprobe sha256' there's 'sha256_ssse3' in /proc/modules and the
sysfs checksum file would show e.g. 'sha256-avx2'.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
Hugo Mills 373def57ce btrfs-progs: docs: minor fixes for spelling and idiom
Author: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba 9b027ac64e btrfs-progs: docs: add section about hardware considerations
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:53 +02:00
David Sterba cb11769cd3 btrfs-progs: docs: write section about storage model
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:52 +02:00
David Sterba 63794e7016 btrfs-progs: docs: update device related info
- recently added stripe count in device usage
- other minor updates

Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:52 +02:00
David Sterba 6710641ad5 btrfs-progs: docs: add section about zoned devices
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-02 17:27:52 +02:00
Sidong Yang 4693e82261 btrfs-progs: device usage: print number of stripes in relevant profiles
Print number of stripes for striped profiles in device usage commands.
It helps to see profiles easily. The output is like below.

/dev/vdc, ID: 1
   Device size:             1.00GiB
   Device slack:              0.00B
   Data,RAID0/2:          912.62MiB
   Data,RAID0/3:          912.62MiB
   Metadata,RAID1:        102.38MiB
   System,RAID1:            8.00MiB
   Unallocated:             1.00MiB

Multiple lines can appear in case a balance conversion process was
interrupted or if there's been a new device added and new data written
to the full stripe.

Issue: #372
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-23 13:47:35 +02:00
David Sterba c3acaee63a btrfs-progs: docs: add more results for checksums
Update the table with AVX2 accelerated versions provided by libgcrypt
and libsodium.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-23 13:47:35 +02:00
David Sterba ae59e39531 btrfs-progs: docs: add section about compression
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-23 13:47:35 +02:00
David Sterba 1eb7b11303 btrfs-progs: remove stale user transaction ioctl definitions
The user transaction ioctls have been removed in kernel 4.17 by commit
7a5a07a81062 ("btrfs: Remove userspace transaction ioctls"), the
definitions are not relevant and can be removed.

The numbers could be reused in the future, eg. when there are no
maintained LTS kernels older than 4.19.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:50 +02:00
David Sterba d51075f05b btrfs-progs: restore: group help options
Group the options in the help text by the purpose for clarity.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00
David Sterba 9a83a0b5c0 btrfs-progs: restore: remove loop check during directory scan
There's another loop protection during scan of directory items. This can
fire under invalid conditions, ie. when there's no real endless loop.
The layout of b-tree items could trigger that and has been observed in
practice. This prevents automated restoration as it requires user
attention.

The number of loops is 1024, unjustified and without explanation. Errors
during traversing the leaves are checked so most errors would be caught.
A real loop in the directory items would require some crafting and would
not happen on a normal filesystem.

Issue: #59
Issue: #164
Issue: #237
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00
David Sterba 4258b7161f btrfs-progs: restore: remove loop check during file copy
There's some kind of looping protection during copying file extents,
mostly likely to avoid endless loops on severely damaged filesystems.
This has been bothering users and makes restoring hard to automate as
it requires user attention to press 'y' or 'a'. This has not been well
documented either.

The number of loops is 1024 which looks arbitrary and hard to justify.
This eg. means that a file with many fragments hits the interactive
question more than once.

There are other checks when iterating the leaves that would catch
corruptions or other errors, so the looping would happen in some rare
and rather artificial case when some kind of loop exists inside the
extent items. This is not easily possible if possible at all as the
items do not directly reference other.

In case there's some genuine error found that would require a looping
protection, we'll add it or extend the checks to identify the loop.

Issue: #59
Issue: #164
Issue: #237
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00
David Sterba afe055f438 btrfs-progs: restore: convert to error message helpers
- convert to error() helpers, remove trailing \n
- switch messages printing %d as errno to %m
- rewording

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00
David Sterba b1f374dd1d btrfs-progs: switch %Lu to %llu format
The %Lu format is not standard and we use %llu everywhere else, so
switch the remaining cases.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00
Qu Wenruo ab0d369525 btrfs-progs: tests/fsck: add test case to make sure btrfs check can reset btrfs_dev_item::bytes_used
The test image is manually crafted with 1MiB offset in the device item
of devid 1.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00