Commit graph

2974 commits

Author SHA1 Message Date
David Sterba c11bd9cfd2 btrfs-progs: pass OPEN_CTREE flags as unsigned
As we're passing a set of flags, the enum type is not appropriate.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:36:54 +02:00
David Sterba 4241e27ee1 btrfs-progs: build: add more debugging features
Add options to show file and line or stack trace for error/warning
messages that use the common helpers. Possible to let any error stop
execution for ease of analysis and debugging.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-22 16:44:22 +02:00
David Sterba 49184a737b btrfs-progs: switch ternary op to an if in cmd_subvol_show
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-19 15:45:04 +02:00
Qu Wenruo 1c202eb06d btrfs-progs: print-tree: Print hex and human readable root flags
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-19 13:54:05 +02:00
Qu Wenruo 44e2b7a7e5 btrfs-progs: print-tree: Print human readable inode flags
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-19 13:53:52 +02:00
Qu Wenruo 4f3ccdd518 btrfs-progs: convert-test: Check if the ext2_save/image is read only
Old convert codes uses both 0400 permission and INODE_READONLY flag to
make the converted ext2 image readonly.

While new convert treat the inode just as normal inode, with no special
inode flag and uses 0600 permission.
This makes user able to modify converted image unintentionally and make
rollback fails.

This test case will test the regression.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-19 13:53:28 +02:00
Qu Wenruo bdadea75e4 btrfs-progs: convert: Fix a regression that ext2_save/image is not readonly
The new convert treats the convert image as a normal file, without any
special flags and permissions.

This is different from original code:
1) Permission changed from 0400 to 0600
2) Inode lacks READONLY flag

This makes we can read-write mount the ext2 image and cause rollback
failure.

Follow old code behavior, use 0400 permission and add back READONLY
flag to fix it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-19 13:52:43 +02:00
David Sterba 55aa862ea2 btrfs-progs: docs: refer to btrfs(5) from btrfs(8)
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-18 19:50:43 +02:00
David Sterba 637c005ac8 btrfs-progs: docs: update btrfs-quota manual page, more sections
Add more overall sections.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-18 19:50:43 +02:00
David Sterba c7f8852296 btrfs-progs: docs: update btrfs-quota manual page
Copy the intoductory and usecases from the text written by Arne Jansen,

https://git.kernel.org/cgit/linux/kernel/git/arne/qgroups-doc.git/

The graphics missing for now.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-18 19:50:43 +02:00
David Sterba 4351c8fe3f btrfs-progs: mkfs: switch to new error message helpers
Do not use fprintf, adjust messages, add verbose errno or at least the
errorr code if there's no clear mapping to a string.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-18 18:38:34 +02:00
David Sterba 9109a8f44e btrfs-progs: no BUG_ON in close_ctree
There's no reason for it.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-18 17:44:18 +02:00
David Sterba 87c1bd13c1 btrfs-progs: check: adjust command line options for the low-memory mode
Change the single-purpose option --low-memory to a generic option that
takes the mode. Currently supported are the original mode and the
low-memory in the same way.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 20:00:00 +02:00
Lu Fengqi bfecd8bd6a btrfs-progs: check: introduce low memory mode
Introduce a new fsck mode: low memory mode.

Old btrfsck is working efficiently but uses some memory for each extent
item.  This method will ensure extents are only iterated once at
extent/chunk tree check process.

But since it uses some memory for each extent item, for a large fs with
several TB metadata, this can easily eat up memory and cause OOM.

To handle such limitation and improve scalability, the new low-memory
mode will not use any heap memory to record which extent is checked.
Instead it will use extent backref to avoid most of uneeded checks on
shared fs/subvolume tree blocks.
And with the use forward and backward reference cross check, we can also
ensure every tree block is at least checked once.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 19:04:51 +02:00
Lu Fengqi dad817d3ba btrfs-progs: check: introduce traversal function for fsck
Introduce a new function traverse_tree_block() to do pre-order
traversal, to co-operate with new fs/subvolume tree skip function.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:21 +02:00
Lu Fengqi 3974c9117e btrfs-progs: check: introduce function to speed up fs tree check
Introduce function should_check() to reduced duplicated tree block check
for fs/subvolume tree.

The idea is, we only check the fs/subvolue tree block if we have the
lowest referencer rootid, according to extent tree.

In that case, we can skip a lot of fs/subvolume tree block checks if
there are a lot of snapshots.

Although we will do a lot of extent tree searches for it.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:21 +02:00
Lu Fengqi fbf33f2ffd btrfs-progs: check: introduce main entry function for checking leaf items
Introduce an entry function, check_leaf_items() to check all
known/valuable items and update related accounting like total_bytes and
csum_bytes.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:21 +02:00
Lu Fengqi f6647e2131 btrfs-progs: check: introduce function to check chunk item
Introduce function check_chunk_item() to check a chunk item.
It will check all chunk stripes with dev extents and the corresponding
block group item.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi 406a4cdea4 btrfs-progs: check: introduce function to check block group item
Introduce function check_block_group_item() to check a block group item.
It will check the referencer chunk and the used space accounting with
extent tree.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi f9ed952b37 btrfs-progs: check: introduce function to check dev used space
Introduce function check_dev_item() to check used space with dev extent
items.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi d93fde8234 btrfs-progs: check: introduce function to check dev extent item
Introduce function check_dev_extent_item() to find its referencer chunk.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi ea5052e51f btrfs-progs: check: introduce function to check an extent
Introduce function check_extent_item() using previously introduced
functions.

With previous function to check referencer and backref, this function
can be quite easy.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi bf5e74204e btrfs-progs: check: introduce function to check shared data backref
Introduce the function check_shared_data_backref() to check the
referencer of a given shared data backref.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi 4e6bbaebb8 btrfs-progs: check: introduce function to check referencer for data backref
Introduce new function check_extent_data_backref() to search referencer
for a given data backref.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi 1035ca5118 btrfs-progs: check: introduce function to check shared block ref
Introduce function check_shared_block_backref() to check shared block
ref.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi d07873c007 btrfs-progs: check: introduce function to check referencer of a backref
Introduce a new function check_tree_block_backref() to check if a
backref points to correct referencer.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:20 +02:00
Lu Fengqi ae5271dd52 btrfs-progs: check: introduce function to query tree block level
Introduce function query_tree_block_level() to resolve tree block level
by the following method:
1) tree block backref level
2) tree block header level

And only when header level == backref level, and transid matches, it will
return the tree block level.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:19 +02:00
Lu Fengqi b0d360b541 btrfs-progs: check: introduce function to check data backref in extent tree
Introduce a new function check_data_extent_item() to check if the
corresponding data backref exists in extent tree.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:19 +02:00
Lu Fengqi ae60006cee btrfs-progs: check: introduce function to check tree block backref in extent tree
Introduce function check_tree_block_ref() to check whether a tree block
has correct backref in extent tree.

Unlike old extent tree check method, we only use search_slot() to search
reference, no extra structure will be allocated in heap to record what we
have checked.

This method may cause a little more IO, but should work for super large
fs without triggering OOM.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-17 18:51:19 +02:00
Wang Xiaoguang a13bfba3e2 btrfs-progs: eliminate some unnecessary btrfs_lookup_extent_info() calls in walk_down_tree()
In walk_down_tree(), we may call btrfs_lookup_extent_info() for same tree
block many times, obviously unnecessary. Here we define a simple struct to
record whether we already have gotten tree block's refs:
        struct node_refs {
                u64 bytenr[BTRFS_MAX_LEVEL];
                u64 refs[BTRFS_MAX_LEVEL];
        };

I fill a disk partition with linux kernel source codes and use below
test script to have performance test.
	#!/bin/bash

	echo 3 > /proc/sys/vm/drop_caches
	for ((i = 0; i < 20; i++)); do
		time ./btrfsck  /dev/sdc5
	done 2>&1 | grep real | awk -F "[ms]" '{run_time += $2} END{print run_time / 20}'

Before this patch, it averagely took 0.8447s for every btrfsck execution,
and with this patch, it averagely took 0.7807s.

Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-16 16:02:03 +02:00
David Sterba 9d2ea014f0
Btrfs progs v4.7
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-29 15:06:42 +02:00
David Sterba 6dcfd667de btrfs-progs: update CHANGES for 4.7
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-29 15:05:47 +02:00
Justin Maggard c52762b4c6 btrfs-progs: fix memory leak with missing device
In read_one_chunk(), we may add an empty entry for a missing device.
However, this entry wasn't being added to the dev_list, and so it never
got freed.

Signed-off-by: Justin Maggard <jmaggard@netgear.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-29 15:04:54 +02:00
David Sterba af1812090b btrfs-progs: fix unaligned access in raid6 calculations
The raid6 code matches kernel implementation that also does the
unaligned access. So to keep the code close, add helpers for unaligned
native access and use them. The helpers are local as we don't plan to
use them elsewhere.

Reported-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-29 15:04:54 +02:00
David Sterba 4e4c1e6039 btrfs-progs: use proper unaligned helper in btrfs_csum_final
This will not cause unaligned access as the checksum is at the beginning
of btrfs_header and thus aligned to a page, but for clarity use the
helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-29 15:04:54 +02:00
David Sterba 2f732723d6 btrfs-progs: fi defrag: change default extent target size to 32 MiB
The kernel default is too low, 32 MiB is recommended and should give
better results.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
Qu Wenruo 2542112e0c btrfs-progs: Doc: Fix format error in btrfs-send
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 96bc7f17df btrfs-progs: handler memory allocation error in write_data_to_disk
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 02e22dbc1c btrfs-progs: handle memory allocation error in __alloc_extent_buffer
Drop the BUG() as all callers handle errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 002812542c btrfs-progs: update values of EXTENT_* bits
Make the values unsigned as we do various bit operations.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 5407ee85fc btrfs-progs: refactor and extend btrfs_prepare_device arguments
The message about discard is printed unconditionally and does not
conform to the --quite option eg. in mkfs. Consolidate the operation
flags into one argument and add support for verbosity.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 9c92c4eb92 btrfs-progs: use values directly for BLOCK_GROUP_ macros
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba bf3a4c5f1b btrfs-progs: use unsigned type for extent_buffer flags
We're doing bit operations.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 24f1713777 btrfs-progs: fix unaligned access calculating raid56 data
The extent_buffer::data might be unaligned wrt unsigned long, depends on
acutal layout of the structure and width of the int types. Use explicit
unaligned access helpers.

Reported-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 1c47e5b039 btrfs-progs: kerncompat: introduce put_unaligned_x helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 7ce43670da btrfs-progs: docs: update btrfs-balance manual page
Update the new options.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:29 +02:00
David Sterba f6534e766a btrfs-progs: balance: add another (shorter) option for background
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-26 19:30:39 +02:00
David Sterba 6cd3ed9e7e btrfs-progs: balance: silence compiler warning
cmds-balance.c: In function 'cmd_balance_start':
cmds-balance.c:654:6: warning: ignoring return value of 'chdir', declared with
		attribute warn_unused_result [-Wunused-result]
	chdir("/");

Reported-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-26 19:27:41 +02:00
Austin S. Hemmelgarn fe520b5cdc btrfs-progs: add option to run balance as daemon
Currently, balance operations are run synchronously in the foreground.
This is nice for interactive management, but is kind of crappy when you
start looking at automation and similar things.

This patch adds an option to `btrfs balance start` to tell it to
daemonize prior to running the balance operation, thus allowing us to
preform balances asynchronously.  The two biggest use cases I have for
this are starting a balance on a remote server without establishing a
full shell session, and being able to background the balance in a
recovery shell (which usually has no job control) so I can still get
progress information.

Because it simply daemonizes prior to calling the balance ioctl, this
doesn't actually need any kernel support.

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-26 19:26:29 +02:00
Omar Sandoval 1d6c7cb725 btrfs-progs: fix btrfsck of space_cache=v2 bitmaps on big-endian
Copy le_test_bit() from the kernel and use that for the free space tree
bitmaps.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-26 18:35:05 +02:00