Commit graph

5049 commits

Author SHA1 Message Date
Anand Jain b5a6cff94d btrfs-progs: split global help HELPINFO_INSERT_GLOBALS
As of now the define HELPINFO_INSERT_GLOBALS if used as in the example
as below (as of now its not been used anywhere) will print the help
texts as shown below

$ ./btrfs fi show --help

 <snip>

    Global options:
    --format TYPE      where TYPE is: text

So in preparation to add --verbose and --quiet global options, and
apparently --format is not being used yet, this patch splits the global
options into two defines.

                                       "Global options:"

So that the currently added global options --verbose and --quiet can use
the define HELPINFO_INSERT_GLOBALS header as shown below.

$ ./btrfs fi show --help
<snip>

    Global options:

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:30:36 +02:00
David Sterba 7e3f269cb9 btrfs-progs: docs: remove option logreplay
There's no such option 'logreplay', only 'nologreplay'. Remove it from
the list and update the help text.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-10 17:27:11 +02:00
David Sterba 70e3d52d7b btrfs-progs: docs: add discard=async to mount options
Document the new discard mode.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:10 +02:00
David Sterba 62ee9a50bf btrfs-progs: docs: update conventions
Rename to asciidoc as that's the format we use for manual page source.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba b79683252a btrfs-progs: docs: update balance
- note the faster cancellation
- redundancy reduction
- system also gets converted with metadata conversion

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba 0015e8ff26 btrfs-progs: docs: clarify file attributes and flags
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba 7462b0af16 btrfs-progs: docs: update list of features exported in sysfs
List remaining entries in /sys/fs/btrfs/features available in kernel
5.6.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba 08a0cc8cab btrfs-progs: move btrfs_find_free_objectid to inode.c
The inode-map feature is not implemented in userspace and the only
function does the ordinary free inode number lookup. Move it to inode.c
and delte inode-map.c

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba f7fe7de64c btrfs-progs: move uuid-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba a656166d11 btrfs-progs: move root-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba fdf058ac0f btrfs-progs: move inode-item.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba a067ecef0a btrfs-progs: move file-item.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba 925bf01f5d btrfs-progs: move dir-item.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:08 +02:00
David Sterba 297c71ee3b btrfs-progs: build: add support for libkcapi as crypto backend
https://github.com/smuellerDD/libkcapi allows user-space to access the
Linux kernel crypto API.  Uses netlink interface and exports easy to use
APIs.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:07 +02:00
cezarmathe dbf60b488e libbtrfsutil: update btrfs_util_delete_subvolume docs
btrfs_util_error btrfs_util_delete_subvolume requires elevated
privileges, despite the fact that the documentation does not say that.

The following does not work in all scenarios:

	$ btrfs subvolume create ~/mytest
	$ btrfs subvolume delete ~/mytest

Document the additional requirements.

Pull-request: #253
Issue: #252
Author: cezarmathe <me@cezarmathe.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo b602b22884 btrfs-progs: image: pin down log tree blocks before fixup
Although btrfs-image will dump log tree, we will modify the restored
image if it's not a multi-device restore.

In that case, since log tree blocks are not recorded in the extent tree,
extent allocator will try to re-use the tree blocks belonging to log
trees, this would lead to transid mismatch if btrfs-restore chooses to
do device/chunk fixup.

This patch will fix such problem by pinning down all the log trees
blocks before fixing up the device and chunk trees.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo 73dd4e3c87 btrfs-progs: image: Don't modify the chunk and device tree if the source dump is single device
Btrfs-image -r doesn't always create exactly the same fs of the original
fs, this is because btrfs-image can create dump from multi-device, and
restore it to single device.

Thus we need some special modification to chunk and device tree. This
behavior is mostly to handle the old behavior where we always restore
the metadata into SINGLE profile no matter what.

However this is not needed if the source fs only has one device, in that
case, we can use all the metadata as is, no need to modify the fs at
all, resulting an exact copy of metadata.

This patch will do extra check when doing restore, to avoid modify the
restored fs if the source is also single device.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo 23bee6a7b5 btrfs-progs: tests: update fsck/035-inline-bad-ram-bytes image
The image used in test case 035 has one problem:

- Bad total_bytes of device item in chunk tree
        item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 16185 itemsize 98
                devid 1 total_bytes 72564736 bytes_used 92274688
  The total_bytes is even smaller than bytes_used.
  While the dev_item in super block contains the correct value:
    dev_item.total_bytes    134217728
    dev_item.bytes_used     92274688

This patch will update the image, using the correct value in super block
to replace the wrong one in chunk tree.

So that later btrfs-image restore without device/chunk fixup can still
pass fsck-tests.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo 2f8071b6d3 btrfs-progs: tests: update fsck/012-leaf-corruption image
The image used in 012 has several problems:

- Bad dev_item total_bytes in superblock
    dev_item.total_bytes    20918272
    dev_item.bytes_used     67108864

  The fs has 64M chunks allocated, and the original fs is also 64M.
  Thus the total_bytes is completely wrong.

- Bad total_bytes in chunk tree
          item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 3897 itemsize 98
                devid 1 total_bytes 20918272 bytes_used 67108864
  The same problem as super block.

This problem is covered by btrfs-image, as it will recalculate the
device size.

However if btrfs-image is doing exactly same data replay without any
modification, such bad image would cause test failure, as we're unable
to fix such bad total_bytes.

This patch will update the image to fix such problem.
Also since we're here, there is no need to use custom .tar.gz image, as
we have extra_image() to handle the uncompression.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo 71d02f90e7 btrfs-progs: print-tree: export dump_superblock()
dump_superblock() is useful to debug eg. btrfs-image errors, like
fsck/012-* test case, where the superblock itself has something wrong
from the original image.

Export it so that we can call it in gdb.

Since we're exporting dump_superblock(), rename it to
btrfs_print_superblock() to following the existing naming schema.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo e9a17c3804 btrfs-progs: allow btrfs_print_leaf to be called on dummy eb
In certain call sites, like btrfs-image, we want full extent_buffer
accessors, but don't have a btrfs_fs_info.

In that case, if an extent buffer whose fs_info is NULL, then
btrfs_print_leaf() is called on such eb, we will trigger a NULL pointer
dereference, at BTRFS_LEAF_DATA_SIZE(fs_info).

Fix this by using __BTRFS_LEAF_DATA_SIZE(), which only needs nodesize,
and nodesize can be extracted from extent_buffer::len.

This allows us to call btrfs_print_leaf() on any extent buffer, which is
super handy in gdb.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
David Sterba ba689a384f btrfs-progs: docs: update 'fi us' examples
Add description of each line, update the per-type output.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Goffredo Baroncelli cf15c0eb0e btrfs-progs: fi usage: add support for RAID5/6
The function print_filesystem_usage_overall() prints the info on the
basis of the r_*_chunk, r_*_used and l_*_chunks values computed for
data, metadata and system chunks.

For the RAID1/10/1C3/1C4/DUP these info are easily accessible from the
info returned by load_space_info().

However for RAID5/6 this is not true because the ratios between the l_*
and r_* values are not fixed but depend by the number of devices
involved in the chunk.

A new function called get_raid56_space_info() is created to compute
the values r_*_chunk, and r_*_used for data, metadata and system
chunks in case of a RAID5/6 profile.

The r_*_chunk values are computed from the chunk_info array.

In order to compute the r_*_used values, a new function
get_raid56_logical_ratio() is created. This function computes the ratio
l_*_used / l_*_chunk from the ioctl_space_args array.  So we can get:

	'r_*_used' = 'r_*_chunk' * 'l_*_used' / 'l_*_chunk'

Even tough this is not mathematically true every time, it is true on
"average" (for example if the RAID5 chunks use different number of disks
the real values depend by which chunk contains the data).

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:48 +02:00
Qu Wenruo 5ba0f70c60 btrfs-progs: tests: add test for quotas and --rootdir
Basic test of mkfs-time enabled quotas and filesystem filled with files.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:48 +02:00
Qu Wenruo 6ee4ab24da btrfs-progs: mkfs: introduce quota runtime feature
Add support for enabling quotas at mkfs time. The qgroup accounting will
be consistent, ie. works with --rootdir.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo 5ac6e02665 btrfs-progs: mkfs: add -R|--runtime-features option
Just like -O|--features, introduce -R|--runtime-features to enable
features that are now enabled on a mounted filesystem

Currently only mkfs is supported, convert is not supported yet.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo 7ddd0a1d1e btrfs-progs: fsfeatures: introduce runtime features
Make the features structures more generic to allow mkfs-time and
mount-time sets to be defined.

This provides base for later mkfs support of mount-time features like
quotas.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo 21c0de4489 btrfs-progs: mkfs: introduce function to setup quota root and rescan
Introduce a new function, setup_quota_root(), which will create quota
root, and do an offline rescan to ensure all quota accounting numbers
are correct.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ minor improvement in the fail path ]
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo 83ad692230 btrfs-progs: mkfs: introduce function to insert qgroup info and limit items
Introduce a new function, insert_qgroup_items(), to insert qgroup info
item and qgroup limit item for later mkfs qgroup support.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo e0e047f292 btrfs-progs: ctree: introduce function to create an empty tree
Introduce a new function, btrfs_create_tree(), to create an empty tree.

Currently, there is only one caller to create new tree, namely data
reloc tree in mkfs.  However it's copying fs tree to create a new root.

This copy fs tree method is not a good idea if we only need an empty
tree.

So here introduce a new function, btrfs_create_tree() to create new tree.
Which will handle the following things:

1) New tree root leaf
   Using generic tree allocation

2) New root item in tree root

3) Modify special tree root pointers in fs_info
   Only quota_root is supported yet, but can be expended easily

This patch provides the basis to implement quota support in mkfs.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ solved minor conflicts ]
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo ca4cbfaba5 btrfs-progs: qgroup-verify: allow repair_qgroups to do silent repair
Allow repair_qgroups() to do silent repair, so it can acts as offline
qgroup rescan.

This provides the basis for later mkfs quota support.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo f2292a9f17 btrfs-progs: qgroup-verify: move qgroup classification out of report_qgroups
The original qgroup-verify integrates qgroup classification into
report_qgroups().  This behavior makes silent qgroup repair (or offline
rescan) impossible.

To repair qgroup, we must call report_qgroups() to trigger bad qgroup
classification, which will output error message.

This patch moves bad qgroup classification from report_qgroups() to
qgroup_verify_all().  Now report_qgroups() is pretty lightweight, only
doing basic qgroup difference report thus change it type to void.

And since the functionality of qgroup_verify_all() changes, change
callers to handle the new return value correctly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ removed some comments ]
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:56 +02:00
Qu Wenruo a5d136b540 btrfs-progs: qgroup-verify: use fs_info::readonly to check if we should repair qgroups
In fact qgroup-verify is just kind of offline qgroup rescan, and later
mkfs qgroup support will reuse it.

So qgroup-verify doesn't really need to rely the global variable @repair
to check if it should repair qgroups.

Instead check fs_info->readonly to do the repair.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:55 +02:00
Qu Wenruo b95e7e87bb btrfs-progs: qgroup-verify: also repair qgroup status version
Current kernel only supports qgroup version 1.  Make qgroup-verify to
follow this standard.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:55 +02:00
Qu Wenruo b917a4bd93 btrfs-progs: qgroup-verify: avoid NULL pointer dereference for later silent qgroup repair
Commit 078e9a1cc9 ("btrfs-progs: check: enhanced progress indicator")
introduced @qgroup_item_count for progress indicator.

However since we will later introduce silent qgroup rescan
functionality, the @qgroup_item_count pointer can be NULL.

So check if @qgroup_item_count is NULL before accessing it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:55 +02:00
Qu Wenruo 2df82a2da6 btrfs-progs: tests: add test image for overlapping csum item
The image has a csum item overlap with next csum item, make sure btrfs
check can detect it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:38 +02:00
Qu Wenruo f0a8324d50 btrfs-progs: check: detect checksum item overlap
There is a report about checksum item overlap, which makes newer btrfs
kernel to reject it due to tree-checker.

Now let btrfs-progs have the same ability to detect such problem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-25 15:46:11 +02:00
Qu Wenruo 516f1e963a btrfs-progs: block-group: rename write_one_cache_group()
The name of this function contains the word "cache", which is left from
the era where btrfs_block_group is called btrfs_block_group_cache.

Now this "cache" doesn't match anything, and we have better namings for
functions like read/insert/remove_block_group_item().

Rename it to update_block_group_item().

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 21:31:48 +02:00
Qu Wenruo 24557bb4f9 btrfs-progs: block-group: refactor how we insert a block group item
Currently the block group item insert is pretty straight forward, fill
the block group item structure and insert it into extent tree.

However the incoming skinny block group feature is going to change this,
so this patch will refactor such insert into a new function,
insert_block_group_item(), to make the incoming feature easier to add.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 21:27:45 +02:00
Qu Wenruo 772ba86e5e btrfs-progs: rename btrfs_remove_block_group() and free_block_group_item()
To sync with the refactored kernel code.  Also since we're here, sync
the function parameters with kernel too.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 21:27:30 +02:00
Qu Wenruo b2c8f806c4 btrfs-progs: block-group: refactor how we read one block group item
Structure btrfs_block_group has the following members which are
currently read from on-disk block group item and key:

- length - from item key
- used
- flags - from block group item

However for incoming skinny block group tree, we are going to read those
members from different sources.

This patch will refactor such read by:

- Refactor length/used/flags initialization into one function
  The new function, fill_one_block_group() will handle the
  initialization of such members.

- Use btrfs_block_group::length to replace key::offset
  Since skinny block group item would have a different meaning for its
  key offset.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 21:24:00 +02:00
Qu Wenruo e815f5734b btrfs-progs: check/lowmem: lookup block group item in a separate function
In check_chunk_item() we search extent tree for block group item.
Refactor this part into a separate function, find_block_group_item(), so
that later skinny-bg-tree feature can reuse it.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 21:23:35 +02:00
Qu Wenruo ccad599701 btrfs-progs: rename btrfs_block_group_cache to btrfs_block_group
To keep the same naming across kernel and btrfs-progs.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:50:00 +02:00
Qu Wenruo 6d95973371 btrfs-progs: remove the unused btrfs_block_group_cache::cache
There is no user of that member.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:49:56 +02:00
Qu Wenruo 5bc44891c9 btrfs-progs: kill block_group_cache::key
This would sync the code between kernel and btrfs-progs, and save at
least 1 byte for each btrfs_block_group_cache.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:49:50 +02:00
Qu Wenruo 877f512c55 btrfs-progs: sync block group item accessors from kernel
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:49:46 +02:00
Qu Wenruo 2a1823875c btrfs-progs: don't abuse READA_* for extent tree search
For extent tree search, we are only search two things: either
EXTENT_ITEM/METADATA_ITEM (inlined) or SHARED_BLOCK_REF/SHARED_DATA_REF
(keyed).

Except certain situation like cache_block_group(), we never read tree
blocks in a forward or backward sequence.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:46:22 +02:00
Qu Wenruo 2b6af38f72 btrfs-progs: check: don't exit if maybe_repair_root_item() can't find needed root extent
The whole maybe_repair_root_item() and repair_root_items() functions are
introduced to handle an ancient bug in v3.17.

However in certain extent tree corruption case, such early exit would
only exit the whole check process early on, preventing user to know
what's really wrong about the fs.

So this patch will allow the check to continue, since the ancient bug is
no long that common.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:44:51 +02:00
David Sterba 2a74d408f4
Btrfs progs v5.6.1
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-07 13:54:24 +02:00
David Sterba 3ce8bac132 btrfs-progs: update CHANGES for 5.6.1
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-07 13:54:01 +02:00