Commit Graph

63 Commits (master)

Author SHA1 Message Date
Marcos Paulo de Souza 6038a5686c btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit
When kernel returns ENOTCONN after the user tries to create a qgroup on
a subvolume without quota enabled, present a meaningful message to the
user. Kernels before 5.5 return EINVAL for that.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:10 +01:00
David Sterba ca210687f8 btrfs-progs: fi usage: print ratio of used/total for each chunk type
This is based on idea from Stanislaw Gruszka to print the ratio,
originally suggested for the 'fi df', but we don't want to add new
things there and let people use 'fi us' instead. The new output fits
there and is printed by default without options:

Example output:

  $ btrfs fi us /mnt
  [...]

  Data,single: Size:339.00GiB, Used:172.05GiB (50.75%)

  Metadata,single: Size:7.00GiB, Used:3.41GiB (48.70%)

  System,single: Size:32.00MiB, Used:64.00KiB (0.20%)

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:09:52 +01:00
David Sterba 1f5094bb5c btrfs-progs: add support for raid1c3 and raid1c4
Add support for 3- and 4- copy variants of RAID1. This adds resiliency
against 2 or resp. 3 devices lost or damaged.

$ ./mkfs.btrfs -m raid1c4 -d raid1c3 /dev/sd[abcd]

Label:              (null)
UUID:               f1f988ab-6750-4bc2-957b-98a4ebe98631
Node size:          16384
Sector size:        4096
Filesystem size:    8.00GiB
Block group profiles:
  Data:             RAID1C3         273.06MiB
  Metadata:         RAID1C4         204.75MiB
  System:           RAID1C4           8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata, raid1c34
Number of devices:  4
Devices:
   ID        SIZE  PATH
    1     2.00GiB  /dev/sda
    2     2.00GiB  /dev/sdb
    3     2.00GiB  /dev/sdc
    4     2.00GiB  /dev/sdd

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:09:50 +01:00
Qu Wenruo 9b01db7785 btrfs-progs: rescue/zero-log: Manually write all supers to handle extent tree error more gracefully
[BUG]
Even "btrfs rescue zero-log" only reset btrfs_super_block::log_root and
btrfs_super_block::log_root_level, we still use trasction to write all
super blocks for all devices.

This means we can't handle things like corrupted extent tree:

  checksum verify failed on 2172747776 found 000000B6 wanted 00000000
  checksum verify failed on 2172747776 found 000000B6 wanted 00000000
  bad tree block 2172747776, bytenr mismatch, want=2172747776, have=0
  WARNING: could not setup extent tree, skipping it
  Clearing log on /dev/nvme/btrfs, previous log_root 0, level 0
  ERROR: Corrupted fs, no valid METADATA block group found
  ERROR: attempt to start transaction over already running one

[CAUSE]
Because we have extra check in transaction code to ensure we have valid
METADATA block groups.

In fact we don't really need transaction at all.

[FIX]
Instead of commit transaction, we can just call write_all_supers()
manually, so we can still handle multi-device fs while avoid above
error.

Also, add OPEN_CTREE_NO_BLOCK_GROUPS open ctree flag to make it more
robust.

Link: https://lore.kernel.org/linux-btrfs/CAKbQEqG35D_=8raTFH75-yCYoqH2OvpPEmpj2dxgo+PTc=cfhA@mail.gmail.com/
Reported-by: Christian Pernegger <pernegger@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:07:21 +01:00
David Sterba cbe239bf71 btrfs-progs: fi usage: sort table by device id
The result of 'btrfs fi usate -T' looks strange when the devices are
sorted by path and not by id. It's harder to lookup and the device id
reflects "the order of appearance" in the filesystem.

Original output:
              Data      Metadata  System
Id Path       RAID0     RAID1     RAID1    Unallocated
-- ---------- --------- --------- -------- -----------
 6 /dev/loop0 204.75MiB         -        -     1.80GiB
 3 /dev/loop1 204.75MiB         -        -     1.80GiB
 8 /dev/loop2 204.75MiB 256.00MiB  8.00MiB     1.54GiB
 1 /dev/loop3 204.75MiB         -        -     1.80GiB
 5 /dev/loop4 204.75MiB         -        -     1.80GiB
 4 /dev/loop5 204.75MiB         -        -     1.80GiB
 2 /dev/loop6 204.75MiB         -        -     1.80GiB
 7 /dev/loop7 204.75MiB 256.00MiB  8.00MiB     1.54GiB
-- ---------- --------- --------- -------- -----------
   Total        1.60GiB 256.00MiB  8.00MiB    13.88GiB
   Used           0.00B 112.00KiB 16.00KiB

New output:

              Data      Metadata  System
Id Path       RAID0     RAID1     RAID1    Unallocated
-- ---------- --------- --------- -------- -----------
 1 /dev/loop3 204.75MiB         -        -     1.80GiB
 2 /dev/loop6 204.75MiB         -        -     1.80GiB
 3 /dev/loop1 204.75MiB         -        -     1.80GiB
 4 /dev/loop5 204.75MiB         -        -     1.80GiB
 5 /dev/loop4 204.75MiB         -        -     1.80GiB
 6 /dev/loop0 204.75MiB         -        -     1.80GiB
 7 /dev/loop7 204.75MiB 256.00MiB  8.00MiB     1.54GiB
 8 /dev/loop2 204.75MiB 256.00MiB  8.00MiB     1.54GiB
-- ---------- --------- --------- -------- -----------
   Total        1.60GiB 256.00MiB  8.00MiB    13.88GiB
   Used           0.00B 112.00KiB 16.00KiB

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:07:21 +01:00
Qu Wenruo 989a99b5f8 btrfs-progs: Replace btrfs_block_group_cache::item with dedicated members
We access btrfs_block_group_cache::item mostly for @used and @flags.

@flags is already a dedicated member in btrfs_block_group_cache, only
@used doesn't have a dedicated member.

This patch will remove btrfs_block_group_cache::item and add
btrfs_block_group_cache::used.

It's the btrfs-progs equivalent of the following kernel patches:
btrfs: move block_group_item::used to block group
btrfs: move block_group_item::flags to block group
btrfs: remove embedded block_group_cache::item

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:09 +01:00
Anand Jain 5f9a4e6314 btrfs-progs: balance status: fix usage show long verbose
btrfs balance status supports both short and long option -v|--verbose
but usage failed to show it in its --help. This patch fixes the --help.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:09 +01:00
Anand Jain ac7ce38475 btrfs-progs: balance start: fix usage add long verbose
btrfs balance start supports both short and long option -v|--verbose
however usage failed to show the long option. This patch fixes the --help.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:09 +01:00
Anand Jain 161402cc5a btrfs-progs: receive: make option quiet work
Even when -q option specified, the receive sub-command is not quiet as
shown below.

 $ btrfs receive -q -f /tmp/t /btrfs1
 At snapshot ss3

It must be quiet at least when it's been asked to be quiet.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:08 +01:00
David Sterba 2047b6de3d btrfs-progs: add blake2b support
Add definition, crypto wrappers and support to mkfs for blake2 for
checksumming. There are 2 aliases either blake2 or blake2b.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:06 +01:00
Johannes Thumshirn ae9f8bff30 btrfs-progs: add sha256 as supported checksumming algorithm
Add the definition to the checksum types and let mkfs accept it.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:40 +01:00
Johannes Thumshirn c04bcdcacc btrfs-progs: move crc32c implementation to crypto/
With the introduction of xxhash64 to btrfs-progs we created a crypto/
directory for all the hashes used in btrfs (although no
cryptographically secure hash is there yet).

Move the crc32c implementation from kernel-lib/ to crypto/ as well so we
have all hashes consolidated.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:02 +01:00
Johannes Thumshirn f070ece2e9 btrfs-progs: add xxhash64 to mkfs
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:00 +01:00
Johannes Thumshirn e4a8e1916d btrfs-progs: add table for checksum type and name
Adding this table will make extending btrfs-progs with new checksum types
easier.

Also add accessor functions to access the table fields.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:29:05 +02:00
Johannes Thumshirn f3d7675c08 btrfs-progs: add is_valid_csum_type() helper
Add a helper to check if we have a valid csum type from the super block.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:54 +02:00
Johannes Thumshirn ed33908b44 btrfs-progs: update checksumming api
Update the checksumming API to be able to cope with more checksum types
than just CRC32C. The finalization call is merged into btrfs_csum_data.

There are some fixme's and asserts added that need to be resolved.

Co-developed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:34 +02:00
Johannes Thumshirn 7b4f1035a6 btrfs-progs: pass checksum type to btrfs_csum_data()/btrfs_csum_final()
In preparation to supporting new checksum algorithm pass the checksum type
to btrfs_csum_data/btrfs_csum_final, this allows us to encapsulate any
differences in processing into the respective functions

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:28 +02:00
Johannes Thumshirn de68086e35 btrfs-progs: don't assume checksums are always 4 bytes
Pass pointer to a generic buffer instead of fixed size that crc32c
currently uses.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:25 +02:00
Johannes Thumshirn a38eb3d426 btrfs-progs: add checksum type to checksumming functions
Add the checksum type to csum_tree_block_size(), __csum_tree_block_size()
and verify_tree_block_csum_silent().

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:22 +02:00
Johannes Thumshirn b8f3290fe6 btrfs-progs: cache csum_type in recover_control
Cache the super-block's checksum type field in 'struct recover_control'.
This will be needed for further refactoring the checksum handling.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:21 +02:00
Jeff Mahoney b74d0dffb1 btrfs-progs: qgroups: use parse_size instead of open coding it
The only difference between parse_limit and parse_size is that
parse_limit accepts "none" as a valid input.  That's easy enough to
handle as a special case and lets us drop the duplicate code.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:27:46 +02:00
David Sterba 1b42e71053 btrfs-progs: copy btrfsck.h to check/common.h
We want just one header for the check API (similar to what mkfs does)
but as btrfsck.h is exported header (libbtrfs), it needs some
deprecation beriod before it's moved through there are probably no users
of that header file in particular.

Copy the header to check, all modifications and cleanups won't affect
the public header.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:27:37 +02:00
David Sterba f55bdde2f9 btrfs-progs: dump-tree: update help and docs regarding DFS/BFS
The default traversal has been switched to BFS due, update the
documentation accordingly. Also fix the help text of the command that
ommitted to mention the options.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:27:31 +02:00
Vladimir Panteleev f972ef650b btrfs-progs: balance: check for full-balance before background fork
Move the full-balance warning to before the fork, so that the user can
see and react to it.

Notes on test:

- Don't use grep -q, as it causes a SIGPIPE during the countdown, and
  the balance thus doesn't start.

- The "balance cancel" is superfluous as the last command, but it
  provides some idempotence and allows adding more tests below it.

Issue: #168
Signed-off-by: Vladimir Panteleev <git@vladimir.panteleev.md>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:06:42 +02:00
David Sterba 4b09ba4b78 btrfs-progs: restore: fix chown of a symlink
User reports:

"When I execute btrfs restore -S to restore a symlink, it prints:

SYMLINK: 'dest/path/of/symlink' => 'symlink/target'
Failed to change owner: Bad file descriptor

And at cmds-restore.c#L937:

ret = fchownat(-1, file, btrfs_inode_uid(path.nodes[0], inode_item),
                           btrfs_inode_gid(path.nodes[0], inode_item),
                           AT_SYMLINK_NOFOLLOW);
"

The -1 is indeed a bad descriptor, and should be probably AT_FDCWD as
this is documented. The path passed as 'file' is always absolute, so the
semantics are unaffected.

Issue: #183
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:43 +02:00
Grzegorz Kowal 0d7159807f btrfs-progs: scrub: fix status lines alignment
Pull-request: #190
Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:43 +02:00
Grzegorz Kowal 96ed8e801f btrfs-progs: scrub: fix ETA calculation
ETA is calculated in a wrong way. It should be just current time in
seconds + sec_left, independently if the job was resumed or not.

Pull-request: #190
Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:43 +02:00
Omar Sandoval 4a714918f0 btrfs-progs: receive: get rid of unnecessary strdup()
In process_clone(), we're not checking the return value of strdup().
But, there's no reason to strdup() in the first place: we just pass the
path into path_cat_out(). Get rid of the strdup().

Fixes: f1c24cd80d ("Btrfs-progs: add btrfs send/receive commands")
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:42 +02:00
David Sterba 40347be06d btrfs-progs: props: update help texts
- add first line of the long description
- list the type values in all commands (set, get, list)
- enhance
- split option description

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:42 +02:00
Anand Jain 03241303eb btrfs-progs: dump-tree: add noscan option
The comman 'btrfs inspect dump-tree <dev>' will scan all the devices
from the filesystem by defaul.

So as of now you can not inspect each mirrored device independently.

This patch adds option --noscan, which when used won't scan the system
for the partner devices, instead it just uses the devices provided in
the argument.

For example:
  btrfs inspect dump-tree --noscan <dev> [<dev>..]

This helps to debug degraded raid1 and raid10.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:00 +02:00
pjw91 064341dca9 btrfs-progs: restore: Fix input buffer handling
fgets consumes n-1 bytes from input buffer.

When a user types y\n, the newline is left in the buffer.  As a result,
the next fgets uses that \n as answer without waiting for the user to
type.

This patch also fix a bug that dereference the ret without checking if
it's NULL.

* Consumes the `\n` from stdin buffer
* Avoid NULL pointer dereference: treat EOF as default value

Pull-request: #182
Author: pjw91 <mail6543210@yahoo.com.tw>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba a62b7854de btrfs-progs: utils: split device scanning functions to own file
All helpers and data structures that are used for device registration.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba ccbea0977b btrfs-progs: utils: split device handling functions to own file
Helpers that read size, do zeoring, trim or prepare/finalize the device.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba b98a984f0b btrfs-progs: path-utils: rename test_isdir
Rename so it follows the path_ conventions.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba c3b0e6970b btrfs-progs: path-utils: rename is_block_device
Add the path_ prefix and update all callers.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba f83e81c61b btrfs-progs: utils: split path related utils to own file
Group helpers that return some status of a given path to own file so we
debloat utils.c a bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:31 +02:00
Graham R. Cobb bb1b07848e btrfs-progs: scrub: Fix scrub cancel/resume not to skip most of the disk
When a scrub completes or is cancelled, statistics are updated for
reporting in a later btrfs scrub status command and for resuming the
scrub. Most statistics (such as bytes scrubbed) are additive so scrub
adds the statistics from the current run to the saved statistics.

However, the last_physical statistic is not additive. The value from the
current run should replace the saved value. The current code incorrectly
adds the last_physical from the current run to the previous saved value.

This bug causes the resume point to be incorrectly recorded, so large
areas of the disk are skipped when the scrub resumes. As an example,
assume a disk had 1000000 bytes and scrub was cancelled and resumed each
time 10% (100000 bytes) had been scrubbed.

Run | Start byte | bytes scrubbed | kernel last_physical | saved last_physical
  1 |          0 |         100000 |               100000 |              100000
  2 |     100000 |         100000 |               200000 |              300000
  3 |     300000 |         100000 |               400000 |              700000
  4 |     700000 |         100000 |               800000 |             1500000
  5 |    1500000 |              0 | immediately completes| completed

In this example, only 40% of the disk is actually scrubbed.

This patch changes the saved/displayed last_physical to track the last
reported value from the kernel.

Signed-off-by: Graham R. Cobb <g.btrfs@cobb.uk.net>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 54fbdafdc5 btrfs-progs: help: define helper for command with flags
Add macro to define a simple command that also gets some non-default
flags, eg. the output formats.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 17aee13fcd btrfs-progs: define new output format: json
Add the definition, the format is not implemented in any command.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
Jeff Mahoney a1a5000984 btrfs-progs: add support for output formats
This adds a global --format option to request extended output formats
from each command.

We currently only support text mode.  Command help reports what
output formats are available for each command.  Global help reports
what valid formats are.

If an invalid format is requested, an error is reported and lists the
valid formats.

Each command sets a bitmask that describes which formats it is capable
of outputting.  If a globally valid format is requested of a command
that doesn't support it, an error is reported and command usage dumped.

Commands don't need to specify that they support text output.  All
commands are required to output text.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
[ use global config instead of passing cmd_context ]
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba add5079974 btrfs-progs: fix helpinfo formats, short and options separation
For options that do not have the long description, the empty string is
required to mark where the options start. Some commands were missing
that.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 94fced6353 btrfs-progs: build: drop kernel-lib from -I and update paths
Include the files by full path to avoid any confusion in case of
potentially duplicate names.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba c07960c8be btrfs-progs: move utils.[ch] to common/
Update include paths and remove some duplicates.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 408cec5086 btrfs-progs: move string-table.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 07ca08ffba btrfs-progs: move fsfeatures.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba aac564aca6 btrfs-progs: move commonh to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba f93b471143 btrfs-progs: move help.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 96f58629c6 btrfs-progs: move cmds-send.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 4f398726d3 btrfs-progs: move all cmds-fi*.c to cmds/
This is the filesystem command group.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 3bfc7bcfba btrfs-progs: move all cmds-inspect*.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00