platform/upstream/btrfs-progs.git
6 years agobtrfs-progs: check: Move __create_inode_item function to check/common.c
Qu Wenruo [Thu, 18 Jan 2018 08:03:09 +0000 (16:03 +0800)]
btrfs-progs: check: Move __create_inode_item function to check/common.c

Move __create_inode_item() function to check/common.c and rename it to
insert_inode_item(), with comment added.

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move count_csum_range function to check/common.c
Qu Wenruo [Thu, 18 Jan 2018 07:49:39 +0000 (15:49 +0800)]
btrfs-progs: check: Move count_csum_range function to check/common.c

Despite of moving it to check/common.c, also:

1) Add extra comment of the function
2) Change @root parameter to @fs_info
   Since @root is never used, csum_root is picked from fs_info anyway.

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move fs_root_objectid function to check/common.h
Qu Wenruo [Thu, 18 Jan 2018 07:41:15 +0000 (15:41 +0800)]
btrfs-progs: check: Move fs_root_objectid function to check/common.h

Just another small wrapper shared between original and lowmem mode.

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move imode_to_type function to check/common.h
Qu Wenruo [Thu, 18 Jan 2018 07:38:45 +0000 (15:38 +0800)]
btrfs-progs: check: Move imode_to_type function to check/common.h

This function is shared between original and lowmem mode, and it's small
enough, so move it to check/common.h.

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Export check global variables to check/common.h
Qu Wenruo [Thu, 18 Jan 2018 07:31:53 +0000 (15:31 +0800)]
btrfs-progs: check: Export check global variables to check/common.h

There are a dozen of variables which are used as "check global"
variables, like @total_csum_bytes or @no_holes.

These variables are used freely across the check code, however since
we're splitting check code, they need to be exported so they can be used
in other files.

This patch just export them and add declarations for them in
check/common.h.

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move node_refs structure to check/common.h
Qu Wenruo [Thu, 18 Jan 2018 05:52:16 +0000 (13:52 +0800)]
btrfs-progs: check: Move node_refs structure to check/common.h

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h
Qu Wenruo [Wed, 17 Jan 2018 07:24:05 +0000 (15:24 +0800)]
btrfs-progs: check: Move definitions of lowmem mode to check/lowmem.h

Unlike original mode, lowmem mode mostly uses normal tree operations, so
no structure definitions, only a lot of random error bits.

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move original mode definitions to check/original.h
Qu Wenruo [Wed, 17 Jan 2018 07:16:51 +0000 (15:16 +0800)]
btrfs-progs: check: Move original mode definitions to check/original.h

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Move cmds-check.c to check/main.c
Qu Wenruo [Wed, 17 Jan 2018 07:01:56 +0000 (15:01 +0800)]
btrfs-progs: Move cmds-check.c to check/main.c

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: chang tree-reloc-tree test number from 027 to 015
Qu Wenruo [Wed, 31 Jan 2018 02:40:36 +0000 (10:40 +0800)]
btrfs-progs: tests: chang tree-reloc-tree test number from 027 to 015

There are 2 fsck tests with the same number 027:
tree-reloc-tree
bad-extent-inline-ref-type

And we also have a hole in 015, so just rename tree-reloc-tree to 015,
to get rid of the duplicated test number and fill in the hole.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Cleanup use of root in leaf_data_end
Gu Jinxiang [Wed, 31 Jan 2018 03:09:19 +0000 (11:09 +0800)]
btrfs-progs: Cleanup use of root in leaf_data_end

In function leaf_data_end, root is just used to get fs_info, so change
the parameter of this function from btrfs_root to btrfs_fs_info.  And
also make it consistent with kernel.

Add const to parameter leaf of function btrfs_item_offset_nr to keep
type consistent with leaf_data_end.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: remove no longer used btrfs_alloc_extent
Gu Jinxiang [Fri, 26 Jan 2018 07:26:05 +0000 (15:26 +0800)]
btrfs-progs: remove no longer used btrfs_alloc_extent

Function btrfs_alloc_extent is no longer be used.  So let's remove it.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: do clean up for redundancy value assignment
Gu Jinxiang [Fri, 26 Jan 2018 07:26:04 +0000 (15:26 +0800)]
btrfs-progs: do clean up for redundancy value assignment

Although skinny_metadata's type is int, its value just can be 0/1.  And
if condition be true only when skinny_metadata equals 1, so in if's
executive part, set skinny_metadata to 1 is redundancy.  Remove it.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Use fs_info instead of root for BTRFS_MAX_XATTR_SIZE
Gu Jinxiang [Fri, 26 Jan 2018 07:26:03 +0000 (15:26 +0800)]
btrfs-progs: Use fs_info instead of root for BTRFS_MAX_XATTR_SIZE

Do a cleanup. Also make it consistent with kernel.  Use fs_info instead
of root for BTRFS_MAX_XATTR_SIZE, since maybe in some situation we do
not know root, but just know fs_info.

To be consistent with kernel, change macro to inline function.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Sync code with kernel for BTRFS_MAX_INLINE_DATA_SIZE
Gu Jinxiang [Fri, 26 Jan 2018 07:26:02 +0000 (15:26 +0800)]
btrfs-progs: Sync code with kernel for BTRFS_MAX_INLINE_DATA_SIZE

Do a cleanup. Also make it consistent with kernel.  Use fs_info instead
of root for BTRFS_MAX_INLINE_DATA_SIZE, since maybe in some situation we
do not know root, but just know fs_info.

Change macro to inline function to be consistent with kernel.  And
change the function body to match kernel.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK
Gu Jinxiang [Fri, 26 Jan 2018 07:26:01 +0000 (15:26 +0800)]
btrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK

Do a cleanup. Also make it consistent with kernel.  Use fs_info instead
of root for BTRFS_NODEPTRS_PER_BLOCK, since maybe in some situation we
do not know root, but just know fs_info.

To be consistent with kernel, change macro to inline function.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Use fs_info instead of root for BTRFS_LEAF_DATA_SIZE
Gu Jinxiang [Fri, 26 Jan 2018 07:26:00 +0000 (15:26 +0800)]
btrfs-progs: Use fs_info instead of root for BTRFS_LEAF_DATA_SIZE

Do a cleanup. Also make it consistent with kernel.  Use fs_info instead
of root for BTRFS_LEAF_DATA_SIZE, since maybe in some situation we do
not know root, but just know fs_info.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agoBtrfs progs v4.15
David Sterba [Fri, 2 Feb 2018 14:51:18 +0000 (15:51 +0100)]
Btrfs progs v4.15

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: update CHANGES for v4.15
David Sterba [Tue, 14 Nov 2017 14:52:26 +0000 (15:52 +0100)]
btrfs-progs: update CHANGES for v4.15

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: fix typo in btrfs-filesystem manual page
William Giokas [Mon, 22 Jan 2018 18:25:49 +0000 (11:25 -0700)]
btrfs-progs: docs: fix typo in btrfs-filesystem manual page

Pull-request: #86
Signed-off-by: William Giokas <1007380@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: fixup mount tests of fsck/028-unaligned-super-dev-sizes
David Sterba [Tue, 30 Jan 2018 17:26:46 +0000 (18:26 +0100)]
btrfs-progs: tests: fixup mount tests of fsck/028-unaligned-super-dev-sizes

This test was broken because it tried to mount a different image than
what it had repaired.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: enhance common umount helper to take optional paths
David Sterba [Tue, 30 Jan 2018 17:51:25 +0000 (18:51 +0100)]
btrfs-progs: tests: enhance common umount helper to take optional paths

The run_check_umount_test_dev umounts the TEST_DEV and also optionally
uses the arguments but this would not work as expected if the TEST_DEV
is not a vald path for umount (eg. a restored image).

Update the helper so it tries to umount all paths, or fallback to
TEST_DEV to keep the current behaviour.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: disable some mkfs/010 testcases inside travis
David Sterba [Tue, 30 Jan 2018 14:46:05 +0000 (15:46 +0100)]
btrfs-progs: tests: disable some mkfs/010 testcases inside travis

Node sizes larger than 16k will fail due to enospc in the mount test.
This is likely caused by the kernel. Keep the condition only local to
travis so any other testing environment could see the failure
eventually.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: clean all generated files
David Sterba [Mon, 29 Jan 2018 17:26:30 +0000 (18:26 +0100)]
btrfs-progs: docs: clean all generated files

The section 3 manual page btrfs-ioctl was not deleted.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: build: update help text for zstd
David Sterba [Mon, 29 Jan 2018 16:46:42 +0000 (17:46 +0100)]
btrfs-progs: build: update help text for zstd

The enable/disable does not take an argument and we don't autodetect
zstd anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Remove unnecessary parameter for btrfs_add_block_group
Qu Wenruo [Wed, 24 Jan 2018 02:30:28 +0000 (10:30 +0800)]
btrfs-progs: Remove unnecessary parameter for btrfs_add_block_group

@chunk_objectid of btrfs_make_block_group() function is always fixed to
BTRFS_FIRST_FREE_OBJECTID, so there is no need to pass it as parameter
explicitly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: treewide: Replace strerror(errno) with %m.
Rosen Penev [Sun, 7 Jan 2018 21:54:21 +0000 (13:54 -0800)]
btrfs-progs: treewide: Replace strerror(errno) with %m.

As btrfs is specific to Linux, %m can be used instead of strerror(errno)
in format strings. This has some size reduction benefits for embedded
systems.

glibc, musl, and uclibc-ng all support %m as a modifier to printf.
A quick glance at the BIONIC libc source indicates that it has
support for %m as well. BSDs and Windows do not but I do believe
them to be beyond the scope of btrfs-progs.

Compiled sizes on Ubuntu 16.04:

Before:
3916512 btrfs
233688  libbtrfs.so.0.1
4899    bcp
2367672 btrfs-convert
2208488 btrfs-corrupt-block
13302   btrfs-debugfs
2152160 btrfs-debug-tree
2136024 btrfs-find-root
2287592 btrfs-image
2144600 btrfs-map-logical
2130760 btrfs-select-super
2152608 btrfstune
2131760 btrfs-zero-log
2277752 mkfs.btrfs
9166    show-blocks

After:
3908744 btrfs
233256  libbtrfs.so.0.1
4899    bcp
2366560 btrfs-convert
2207432 btrfs-corrupt-block
13302   btrfs-debugfs
2151104 btrfs-debug-tree
2134968 btrfs-find-root
2281864 btrfs-image
2143536 btrfs-map-logical
2129704 btrfs-select-super
2151552 btrfstune
2130696 btrfs-zero-log
2276272 mkfs.btrfs
9166    show-blocks

Total savings: 23928 (24 kilo)bytes

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: don't clobber errno in close_file_or_dir
David Sterba [Thu, 25 Jan 2018 12:37:13 +0000 (13:37 +0100)]
btrfs-progs: don't clobber errno in close_file_or_dir

Preserve the errno value for the caller in case closing happens in the
middle of eg. an ioctl and reporing the failure. The errors that could
happen in close/closedir do not bother us.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: volumes: Remove unnecessary parameters when allocating device extent
Qu Wenruo [Wed, 3 Jan 2018 07:13:05 +0000 (15:13 +0800)]
btrfs-progs: volumes: Remove unnecessary parameters when allocating device extent

@chunk_tree and @chunk_objectid of device extent is fixed to
BTRFS_CHUNK_TREE_OBJECTID and BTRFS_FIRST_CHUNK_TREE_OBJECTID
respectively.

There is no need to pass them as parameter explicitly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: volumes: Remove unnecessary trans parameter
Qu Wenruo [Wed, 3 Jan 2018 07:13:04 +0000 (15:13 +0800)]
btrfs-progs: volumes: Remove unnecessary trans parameter

Remove @trans parameter for find_free_dev_extent_start() and its
callers.

The function itself is doing read-only tree search, no use of
transaction.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: volumes: Make find_free_dev_extent_start static
Qu Wenruo [Wed, 3 Jan 2018 07:13:03 +0000 (15:13 +0800)]
btrfs-progs: volumes: Make find_free_dev_extent_start static

The function is not used by anyone else outside of volumes.c, make it
static.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Use bool parameter to determine if we're allocating data extent
Qu Wenruo [Wed, 3 Jan 2018 07:13:02 +0000 (15:13 +0800)]
btrfs-progs: Use bool parameter to determine if we're allocating data extent

btrfs_reserve_extent() uses int @data to determine if we're allocating
data extent, while reuse the parameter later to pass it as profile
(data/meta/sys).

It's a little confusing, this patch will follow kernel parameter to use
bool @is_data to replace it.
And in btrfs_reserve_extent(), use dedicated u64 @profile.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: truncate test image to 0 first
David Sterba [Tue, 23 Jan 2018 16:22:30 +0000 (17:22 +0100)]
btrfs-progs: tests: truncate test image to 0 first

We use the prepare_test_dev helper to make sure the image has at least
this size. The "at least" part is not desired by some tests as the
device might be larger than the test expects.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: add more coverage to mkfs-tests/013-reserved-1M-for-single
David Sterba [Tue, 23 Jan 2018 15:57:57 +0000 (16:57 +0100)]
btrfs-progs: tests: add more coverage to mkfs-tests/013-reserved-1M-for-single

Though the newly added mkfs profiles should not be affected, let's add
the remaining valid single device profiles for better coverage.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: mkfs: don't overwrite first 1M for single
Qu Wenruo [Wed, 10 Jan 2018 04:56:48 +0000 (12:56 +0800)]
btrfs-progs: tests: mkfs: don't overwrite first 1M for single

Add test case to check if the first device extent is occupying reserved
0~1M range.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests:mkfs/010: Output minimal device size
Qu Wenruo [Wed, 24 Jan 2018 02:38:30 +0000 (10:38 +0800)]
btrfs-progs: tests:mkfs/010: Output minimal device size

To make debugging a little easier.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Prevent temporary system chunk to use space in reserved 1M range
Qu Wenruo [Wed, 10 Jan 2018 04:56:47 +0000 (12:56 +0800)]
btrfs-progs: mkfs: Prevent temporary system chunk to use space in reserved 1M range

When creating btrfs, mkfs.btrfs will firstly create a temporary system
chunk as basis, and then created needed trees or new devices.

However the layout temporary system chunk is hard-coded and uses
reserved [0, 1M) range of devid 1.

Change the temporary chunk layout from old:

0 1M 4M 5M
|<----------- temp chunk -------------->|
  And it's 1:1 mapped, which means it's a SINGLE chunk,
  and stripe offset is also 0.

to new layout:

0 1M 4M 5M
|<----------- temp chunk -------------->|
  And still keeps the 1:1 mapping.

However this also affects btrfs_min_dev_size() which still assume
temporary chunks starts at device offset 0.

The problem can only be exposed by "-m single" or "-M" where we reuse the
temporary chunk.

With other meta profiles, system and meta chunks are allocated by later
btrfs_alloc_chunk() call, and old SINGLE chunks are removed, so it will
be no such problem for other meta profiles.

Reported-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Tested-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
[ folded fix for the minimal device size calculation ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: 029-super-recovery: cleanup the test
David Sterba [Tue, 23 Jan 2018 15:25:11 +0000 (16:25 +0100)]
btrfs-progs: tests: 029-super-recovery: cleanup the test

Transform the test to the common helpers and don't manage the loop
devices here. The test category changes from check to misc.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: Add test for super block recovery
Nikolay Borisov [Tue, 5 Dec 2017 08:39:48 +0000 (10:39 +0200)]
btrfs-progs: tests: Add test for super block recovery

This functionality regressed some time ago and it was never caught. Seems no
one complained of that, but to be sure add a regression test to prevent future
regressions.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: super-recover: fix the broken sb detection
Nikolay Borisov [Tue, 5 Dec 2017 08:39:49 +0000 (10:39 +0200)]
btrfs-progs: super-recover: fix the broken sb detection

Commit 3296d058b7ce ("btrfs-progs: super-recover: Reuse
 btrfs_read_dev_super function") changed the logic when a superblock
is added to the bad block list to depend on -EIO. However currently
btrfs_read_dev_super doesn't return -EIO when the fist super block
is broken. Instead it returns -1. This causes the super-recovery
logic to miss the fact that the first super block is completely broken.

Fix this by considering any error code from btrfs_read_dev_super other
than -ENOENT to mean that the super block is corrupted. -ENOENT
means that the superblock copy is not part of the fs i.e. it's smaller
than the offset of the block. This can only occur for the 2nd copy at
256gb mark.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Document logic of btrfs_read_dev_super
Nikolay Borisov [Tue, 5 Dec 2017 08:39:47 +0000 (10:39 +0200)]
btrfs-progs: Document logic of btrfs_read_dev_super

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Replace usage of list_for_each with list_for_each_entry
Nikolay Borisov [Thu, 7 Dec 2017 09:10:05 +0000 (11:10 +0200)]
btrfs-progs: Replace usage of list_for_each with list_for_each_entry

There are a couple of places where instead of the more succinct
list_for_each_entry the code uses list_for_each. This results in
slightly more code with no additional benefit as well as no
coherent pattern. This patch makes the code uniform. No functional
changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ remove unused variable in uuid_search ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Remove recover_get_good_super
Nikolay Borisov [Tue, 5 Dec 2017 08:39:45 +0000 (10:39 +0200)]
btrfs-progs: Remove recover_get_good_super

Currently getting the good super really consists of just getting the
first entry on the linked list, since it's the one with the highest
transid. So remove the function and just use list_first_entry directly.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Factor out common print_device_info
Nikolay Borisov [Tue, 5 Dec 2017 08:39:44 +0000 (10:39 +0200)]
btrfs-progs: Factor out common print_device_info

This function has been copied twice in chunk-recover and super-recover. Factor
it out into utils.c/h and use it. No functional changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: Explictly state test.sh must be executable
Nikolay Borisov [Tue, 5 Dec 2017 08:39:43 +0000 (10:39 +0200)]
btrfs-progs: tests: Explictly state test.sh must be executable

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: build: simplify version tracking
David Sterba [Tue, 23 Jan 2018 13:38:30 +0000 (14:38 +0100)]
btrfs-progs: build: simplify version tracking

There will be a plain file tracking the last released version.

The rest will be simplified to print it where needed. The version
augmented by the current git status was not working anyway since we've
switched to autoconf. The result of version.h with the potential git
status was generated at configure time, which does not mean it's
accurate regarding the git status.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: bump zstd version in CI to 1.3.3
David Sterba [Tue, 23 Jan 2018 13:16:45 +0000 (14:16 +0100)]
btrfs-progs: tests: bump zstd version in CI to 1.3.3

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Print error on invalid extent item format during check
Nikolay Borisov [Fri, 29 Dec 2017 09:01:44 +0000 (11:01 +0200)]
btrfs-progs: Print error on invalid extent item format during check

While performing normal mode check if the code comes across an invalid
extent format it will just BUG() and exit without printing any useful
information for debugging. Improve the situation by outputting the
key/leaf bytenr/slot which will enable to quickly inspect the tree and
see what the corruption is.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: report more specific info about invalid location
Su Yue [Wed, 22 Nov 2017 02:17:16 +0000 (10:17 +0800)]
btrfs-progs: check: report more specific info about invalid location

Previously, it was so useless to print message like
"invalid location %d".

Let it print objectid and offset of the dir_item too.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: fix typo in error message
David Sterba [Mon, 8 Jan 2018 18:48:51 +0000 (19:48 +0100)]
btrfs-progs: tests: fix typo in error message

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: build: Remove unused variable TESTS
Gu Jinxiang [Tue, 31 Oct 2017 09:23:04 +0000 (17:23 +0800)]
btrfs-progs: build: Remove unused variable TESTS

Variable is never used.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Remove unused parameter trans
Gu Jinxiang [Tue, 31 Oct 2017 09:23:03 +0000 (17:23 +0800)]
btrfs-progs: Remove unused parameter trans

Some parameter of trans is not used indeed.
Let's remove them.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: qgroup: cleanup __qgroup_search
Lu Fengqi [Mon, 13 Nov 2017 05:33:16 +0000 (13:33 +0800)]
btrfs-progs: qgroup: cleanup __qgroup_search

Replace the if statement with the switch statement, and return the
appropriate value for the future use rather than directly exit.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: qgroup: move btrfs_show_qgroups's error handler to __qgroup_search
Lu Fengqi [Mon, 13 Nov 2017 05:33:15 +0000 (13:33 +0800)]
btrfs-progs: qgroup: move btrfs_show_qgroups's error handler to __qgroup_search

We have to process the return value of BTRFS_IOC_TREE_SEARCH ioctl in
advance, so that we can distinguish between the two case where quota
is not enabled (ioctl return -ENOENT) and either parent qgroup or child
qgroup does not exist (update_qgroup_relation return -ENOENT). Besides
this, any error in this routine has been reported, so we don't need to
report again in cmd_qgroup_show.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Fix build of btrfs-calc-size
Hans van Kranenburg [Sat, 23 Dec 2017 20:52:38 +0000 (21:52 +0100)]
btrfs-progs: Fix build of btrfs-calc-size

Build would fail because it couldn't find the usage function.

Signed-off-by: Hans van Kranenburg <hans@knorrie.org>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Fix progs_extra build dependencies
Hans van Kranenburg [Sat, 23 Dec 2017 20:52:37 +0000 (21:52 +0100)]
btrfs-progs: Fix progs_extra build dependencies

The Makefile does not have a dependency path that builds dependencies
for tools listed in progs_extra.

E.g. doing make btrfs-show-super in a clean build environment results in:
    gcc: error: cmds-inspect-dump-super.o: No such file or directory
    Makefile:389: recipe for target 'btrfs-show-super' failed

Signed-off-by: Hans van Kranenburg <hans@knorrie.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: update manual for mkfs --shrink
David Sterba [Thu, 7 Dec 2017 18:56:34 +0000 (19:56 +0100)]
btrfs-progs: docs: update manual for mkfs --shrink

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests/mkfs: verify that mkfs.btrfs rootdir+shrink behaves correctly
Qu Wenruo [Wed, 29 Nov 2017 08:58:43 +0000 (16:58 +0800)]
btrfs-progs: tests/mkfs: verify that mkfs.btrfs rootdir+shrink behaves correctly

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Use the whole file or block device to mkfs for rootdir
Qu Wenruo [Wed, 29 Nov 2017 08:42:05 +0000 (16:42 +0800)]
btrfs-progs: mkfs: Use the whole file or block device to mkfs for rootdir

For --rootdir, even for large existing file or block device, it will
always shrink the resulting filesystem.

The problem is, mkfs.btrfs will try to calculate the dir size, and use
it as @block_count to mkfs, which makes the filesystem shrunk.

Fix it by trying to get the original block device or file size as
@block_count, so mkfs.btrfs can use the full file/block device for
--rootdir option.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests/mkfs: Introduce test case to check if mkfs rootdir can create...
Qu Wenruo [Wed, 29 Nov 2017 08:26:02 +0000 (16:26 +0800)]
btrfs-progs: tests/mkfs: Introduce test case to check if mkfs rootdir can create a new file

To test regression 460e93f25754 ("btrfs-progs: mkfs: check the status of
file at mkfs").

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update test to create a out of /tmp ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: fix regression preventing --rootdir to create file
Qu Wenruo [Wed, 29 Nov 2017 08:07:34 +0000 (16:07 +0800)]
btrfs-progs: mkfs: fix regression preventing --rootdir to create file

Commit 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
will try to check the file state before creating fs on it.

The check is mostly fine for normal mkfs case, while for --rootdir
option, it's allowed to create a new file if the destination file
doesn't exist.

Fix it by allowing non-existent file if --rootdir is specified.

Fixes: 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Separate shrink from rootdir
Qu Wenruo [Thu, 19 Oct 2017 09:13:55 +0000 (17:13 +0800)]
btrfs-progs: mkfs: Separate shrink from rootdir

Make --shrink a separate option for --rootdir, and change the default to
off.

The shrinking behaviour is not a commonly used feature but can be useful
for creating minimal pre-filled images, in one step, without requiring
to mount.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update changelog and error messages ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs/rootdir: Shrink fs for rootdir option
Qu Wenruo [Thu, 19 Oct 2017 07:12:58 +0000 (15:12 +0800)]
btrfs-progs: mkfs/rootdir: Shrink fs for rootdir option

Use the new dev extent based shrink method for rootdir option. This
restores the original behaviour when --rootdir will create a minimal
filesystem size.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier
Qu Wenruo [Thu, 19 Oct 2017 02:11:07 +0000 (10:11 +0800)]
btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier

Use an easier method to calculate the estimate device size for
mkfs.btrfs --rootdir.

The new method will over-estimate, but should ensure we won't encounter
ENOSPC.

It relies on the following data:
1) number of inodes -- for metadata chunk size
2) rounded up data size of each regular inode -- for data chunk size

Total meta chunk size = round_up(nr_inode * (PATH_MAX * 3 + sectorsize),
min_chunk_size) * profile_multiplier

PATH_MAX is the maximum size possible for INODE_REF/DIR_INDEX/DIR_ITEM.
Sectorsize is the maximum size possible for inline extent.
min_chunk_size is 8M for SINGLE, and 32M for DUP, get from
btrfs_alloc_chunk().
profile_multiplier is 1 for Single, 2 for DUP.

Total data chunk size is much easier.
Total data chunk size = round_up(total_data_usage, min_chunk_size) *
profile_multiplier

Total_data_usage is the sum of *rounded up* size of each regular inode
use.
min_chunk_size is 8M for SINGLE, 64M for DUP, get from btrfS_alloc_chunk().
Same profile_multiplier for meta.

This over-estimate calculate is, of course inacurrate, but since we will
later shrink the fs to its real usage, it doesn't matter much now.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update comments ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Don't use custom chunk allocator for rootdir
Qu Wenruo [Thu, 19 Oct 2017 07:36:57 +0000 (15:36 +0800)]
btrfs-progs: mkfs: Don't use custom chunk allocator for rootdir

Remove the custom chunk allocator for mkfs. It is buggy in connection to
the --rootdir option and puts file data to the reerved 1M area. The
feature of the custom allocator was to reserve only minimal amount of
blockgroup space. This will temporarily stop working and will need an
explicit request by option, added by following patches.

Use the generic chunk allocator.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Cleanup temporary chunks before filling rootdir
Qu Wenruo [Wed, 29 Nov 2017 06:31:39 +0000 (14:31 +0800)]
btrfs-progs: mkfs: Cleanup temporary chunks before filling rootdir

Cleanup of temporary chunks should be done as soon as possible, and it
should be especially before doing large tree operations, like filling
the filesystem when using --rootdir.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Update allocation info before verbose output
Qu Wenruo [Fri, 20 Oct 2017 01:59:06 +0000 (09:59 +0800)]
btrfs-progs: mkfs: Update allocation info before verbose output

Since new --rootdir can allocate chunk, it will modify the chunk
allocation result.

This patch will update allocation info before verbose output to reflect
such info.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs/rootdir: Introduce function to get end position of last device...
Qu Wenruo [Fri, 20 Oct 2017 01:59:04 +0000 (09:59 +0800)]
btrfs-progs: mkfs/rootdir: Introduce function to get end position of last device extent

Useful for later 'mkfs.btrfs --rootdir' shrink support.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test/mkfs: Test if the minimal device size is valid
Qu Wenruo [Thu, 12 Oct 2017 07:11:33 +0000 (15:11 +0800)]
btrfs-progs: test/mkfs: Test if the minimal device size is valid

New test case to test if the minimal device size given by "mkfs.btrfs"
failure case is valid.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ renamed script ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: move source dir size calculation to its own files
Qu Wenruo [Thu, 19 Oct 2017 05:41:38 +0000 (13:41 +0800)]
btrfs-progs: mkfs: move source dir size calculation to its own files

Also rename the function from size_sourcedir() to mkfs_size_dir().

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: move image creation of rootdir to its own files
Qu Wenruo [Thu, 19 Oct 2017 05:41:37 +0000 (13:41 +0800)]
btrfs-progs: mkfs: move image creation of rootdir to its own files

In fact, --rootdir option is getting more and more independent from
normal mkfs code.

So move image creation function, make_image() and its related code to
mkfs/rootdir.[ch], and rename the function to btrfs_mkfs_fill_dir().

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agoBtrfs progs v4.14.1
David Sterba [Fri, 5 Jan 2018 18:01:39 +0000 (19:01 +0100)]
Btrfs progs v4.14.1

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: update CHANGES for v4.14.1
David Sterba [Tue, 14 Nov 2017 14:52:26 +0000 (15:52 +0100)]
btrfs-progs: update CHANGES for v4.14.1

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: annual typo, clarity, & grammar review & fixups
Nicholas D Steeves [Thu, 7 Dec 2017 20:26:09 +0000 (21:26 +0100)]
btrfs-progs: docs: annual typo, clarity, & grammar review & fixups

Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests/convert: ensure btrfs-convert won't rollback the filesystem after...
Qu Wenruo [Wed, 29 Nov 2017 13:48:06 +0000 (21:48 +0800)]
btrfs-progs: tests/convert: ensure btrfs-convert won't rollback the filesystem after balance

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ add shell quotes, rename test ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: convert: Fix a bug in rollback check which overwrite return value
Qu Wenruo [Wed, 29 Nov 2017 13:48:05 +0000 (21:48 +0800)]
btrfs-progs: convert: Fix a bug in rollback check which overwrite return value

Commit 1170ac307900 ("btrfs-progs: convert: Introduce function to check if
convert image is able to be rolled back") reworked rollback check
condition, by checking 1:1 mapping of each file extent.

The idea itself has nothing wrong, but error handler is not implemented
correctly, which over writes the return value and always try to rollback
the fs even it fails to pass the check.

Fix it by correctly return the error before rollback the fs.

Fixes: 1170ac307900 ("btrfs-progs: convert: Introduce function to check if convert image is able to be rolled back")
Reported-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: fix typo in btrfs-man5
Faalagorn [Wed, 29 Nov 2017 01:14:49 +0000 (02:14 +0100)]
btrfs-progs: docs: fix typo in btrfs-man5

Pull-request: #81
Author: Faalagorn <faalagorn@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: make option -A of mkfs less visible
David Sterba [Thu, 7 Dec 2017 18:42:56 +0000 (19:42 +0100)]
btrfs-progs: docs: make option -A of mkfs less visible

The option will be removed in the future, move it to the end of the
list.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: build: specify minimal library version for reiserfs support
David Sterba [Mon, 4 Dec 2017 12:14:00 +0000 (13:14 +0100)]
btrfs-progs: build: specify minimal library version for reiserfs support

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: fi defrag: clean up duplicate code if find errors
Su Yue [Tue, 28 Nov 2017 09:14:48 +0000 (17:14 +0800)]
btrfs-progs: fi defrag: clean up duplicate code if find errors

In function cmd_filesystem_defrag(), lines of code for error handling
are duplicate and hard to expand in further.

Create a jump label for errors.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Only zero out the first 1M for rootdir
Qu Wenruo [Thu, 19 Oct 2017 06:16:17 +0000 (14:16 +0800)]
btrfs-progs: mkfs: Only zero out the first 1M for rootdir

It's a waste of IO to fill the whole image before creating btrfs on it,
just wiping the first 1M, and then write 1 byte to the last position to
create a sparse file.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs failure on...
Qu Wenruo [Thu, 12 Oct 2017 06:24:34 +0000 (14:24 +0800)]
btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs failure on small file

Since commit c11e36a29e84 ("Btrfs-progs: Do not force mixed block group
creation unless '-M' option is specified"), mkfs no longer use mixed
block group unless specified manually.

This breaks the minimal device size calculation, which only considered
mixed block group use case.

This patch enhances minimal device size calculation for mkfs, by using
different minimal stripe length (calculated from code) for different
profiles, and use them to calculate minimal device size.

Reported-by: Wesley Aptekar-Cassels <W.Aptekar@gmail.com>
Fixes: c11e36a29e84 ("Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
[ updated comments ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test/common: Enhance prepare_test_dev to reset device size
Qu Wenruo [Wed, 1 Nov 2017 01:30:42 +0000 (09:30 +0800)]
btrfs-progs: test/common: Enhance prepare_test_dev to reset device size

So prepare_test_dev() can be called several times in one test case, to
test different device sizes.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ switch to [ ] ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test/common: Introduce run_mustfail_stdout
Qu Wenruo [Wed, 1 Nov 2017 01:30:41 +0000 (09:30 +0800)]
btrfs-progs: test/common: Introduce run_mustfail_stdout

For later test case which needs info from stderr.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: fix typos in test names
David Sterba [Mon, 27 Nov 2017 22:58:23 +0000 (23:58 +0100)]
btrfs-progs: tests: fix typos in test names

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: check the status of file at mkfs
Misono, Tomohiro [Fri, 24 Nov 2017 05:21:15 +0000 (14:21 +0900)]
btrfs-progs: mkfs: check the status of file at mkfs

Currently, only the status of block devices is checked at mkfs,
but we should also check for regular files whether they are already
formatted or mounted to prevent overwrite accidentally.

Device status is checked by test_dev_for_mkfs().
The part which is not related to block device is split from this
and used for both block device and regular file.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: mkfs/008 mkfs with force
David Sterba [Mon, 27 Nov 2017 22:50:45 +0000 (23:50 +0100)]
btrfs-progs: tests: mkfs/008 mkfs with force

With extended tests in the following patch a file based filesystem image
also needs -f, otherwise it will fail.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test/fsck/021: Cleanup custom check by overriding check_image
Qu Wenruo [Fri, 10 Nov 2017 01:34:19 +0000 (09:34 +0800)]
btrfs-progs: test/fsck/021: Cleanup custom check by overriding check_image

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update comment ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test/fsck/020: Cleanup custom check function by overriding check_image...
Qu Wenruo [Fri, 10 Nov 2017 01:34:18 +0000 (09:34 +0800)]
btrfs-progs: test/fsck/020: Cleanup custom check function by overriding check_image function

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test/fsck: Introduce test images containing tree reloc tree
Qu Wenruo [Fri, 10 Nov 2017 01:34:17 +0000 (09:34 +0800)]
btrfs-progs: test/fsck: Introduce test images containing tree reloc tree

Reloc tree is a special tree with very short life span.  It acts as a
special snapshot for any tree, with related nodes/leaves or EXTENT_DATA
modified to point to new position.

Considering the short life span and its special purpose, it should be
quite reasonable to keep them as both corner case for fsck and
educational dump for anyone interested in relocation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: lowmem check: Reword an unclear error message about file extent gap
Lu Fengqi [Fri, 10 Nov 2017 09:47:10 +0000 (17:47 +0800)]
btrfs-progs: lowmem check: Reword an unclear error message about file extent gap

This error occurs when no_holes is not set, but there is a gap
before the file extent.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: update btrfs-subvolume manual page
Howard [Sun, 26 Nov 2017 05:51:43 +0000 (19:51 -1000)]
btrfs-progs: docs: update btrfs-subvolume manual page

To simplify, I suggest moving the 'writable/readonly' issue only to the
-r line, instead of having it introduced in two places.

Pull-request: #80
Author: Howard <hwj@BridgeportContractor.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: dump_tree: remove superfluous _TREE
Hans van Kranenburg [Fri, 24 Nov 2017 20:26:08 +0000 (21:26 +0100)]
btrfs-progs: dump_tree: remove superfluous _TREE

-# btrfs inspect-internal dump-tree -t fs /dev/block/device
ERROR: unrecognized tree id: fs

Without this fix I can't dump-tree fs, but I can dump-tree fs_tree and
also fs_tree_tree, which is a bit silly.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Hans van Kranenburg <hans@knorrie.org>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: enable check lowmem in travis CI
David Sterba [Fri, 24 Nov 2017 14:32:13 +0000 (15:32 +0100)]
btrfs-progs: tests: enable check lowmem in travis CI

We missed some regressions because the lowmem mode was not run in the CI
tests. This is partially due to the incomplete implementation but we
have exceptions for the --repair mode in the tests.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: fsck-tests: Introduce test case with keyed data backref with shared...
Qu Wenruo [Wed, 22 Nov 2017 09:03:25 +0000 (17:03 +0800)]
btrfs-progs: fsck-tests: Introduce test case with keyed data backref with shared tree blocks

For snapshot shared tree blocks with source subvolume, the keyed backref
counter only counts the exclusive owned references.

In the following case, 258 is a snapshot of 257, which inherits all the
reference to this data extent.
------
        item 4 key (12582912 EXTENT_ITEM 524288) itemoff 3741 itemsize 140
                refs 179 gen 9 flags DATA
                extent data backref root 257 objectid 258 offset 0 count 49
                extent data backref root 257 objectid 257 offset 0 count 1
                extent data backref root 256 objectid 258 offset 0 count 128
                extent data backref root 256 objectid 257 offset 0 count 1
------

However lowmem mode used to iterate the whole inode to find all
references, and doesn't care if a reference is already counted by the
shared tree block.

Add the test case to check it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: lowmem check: Fix false alerts of referencer count mismatch for snapshot
Qu Wenruo [Wed, 22 Nov 2017 09:03:24 +0000 (17:03 +0800)]
btrfs-progs: lowmem check: Fix false alerts of referencer count mismatch for snapshot

Btrfs lowmem check reports such false alerts:
------
ERROR: extent[366498091008134217728] referencer count mismatch (root: 827, owner: 73782, offset: 134217728) wanted: 4, have: 26
ERROR: extent[366498091008134217728] referencer count mismatch (root: 818, owner: 73782, offset: 134217728) wanted: 4, have: 26
ERROR: extent[366498091008134217728] referencer count mismatch (root: 870, owner: 73782, offset: 134217728) wanted: 4, have: 26
------

While in extent tree, the extent has:
------
        item 81 key (366498091008 EXTENT_ITEM 134217728) itemoff 9008 itemsize 169
                refs 39 gen 224 flags DATA
                extent data backref root 827 objectid 73782 offset 134217728 count 4
                extent data backref root 818 objectid 73782 offset 134217728 count 4
                extent data backref root 259 objectid 73482 offset 134217728 count 1
                extent data backref root 644 objectid 73782 offset 134217728 count 26
                extent data backref root 870 objectid 73782 offset 134217728 count 4
------

And in root 827, there is one leaf with 4 references to that extent
which is owned by 827:
------
leaf 714964992 items 68 free space 10019 generation 641 owner 827
leaf 714964992 flags 0x1(WRITTEN) backref revision 1
......
        item 64 key (73782 EXTENT_DATA 134217728) itemoff 11878 itemsize 53
                generation 224 type 1 (regular)
                extent data disk byte 366498091008 nr 134217728
                extent data offset 0 nr 6410240 ram 134217728
                extent compression 0 (none)
        item 65 key (73782 EXTENT_DATA 140627968) itemoff 11825 itemsize 53
                generation 224 type 1 (regular)
                extent data disk byte 366498091008 nr 134217728
                extent data offset 6410240 nr 5120000 ram 134217728
                extent compression 0 (none)
        item 66 key (73782 EXTENT_DATA 145747968) itemoff 11772 itemsize 53
                generation 224 type 1 (regular)
                extent data disk byte 366498091008 nr 134217728
                extent data offset 11530240 nr 7675904 ram 134217728
                extent compression 0 (none)
        item 67 key (73782 EXTENT_DATA 153423872) itemoff 11719 itemsize 53
                generation 224 type 1 (regular)
                extent data disk byte 366498091008 nr 134217728
                extent data offset 19206144 nr 6397952 ram 134217728
                extent compression 0 (none)
------

And starts from next leaf, there are 22 references to the data extent:
------
leaf 894861312 items 208 free space 59 generation 261 owner 644
leaf 894861312 flags 0x1(WRITTEN) backref revision 1
        item 0 key (73782 EXTENT_DATA 159821824) itemoff 16230 itemsize 53
                generation 224 type 1 (regular)
                extent data disk byte 366498091008 nr 134217728
                extent data offset 25604096 nr 8192 ram 134217728
                extent compression 0 (none)
        item 1 key (73782 EXTENT_DATA 159830016) itemoff 16177 itemsize 53
                generation 224 type 1 (regular)
                extent data disk byte 366498091008 nr 134217728
                extent data offset 25612288 nr 7675904 ram 134217728
                extent compression 0 (none)
......
------

However the next leaf is owned by other subvolume, normally owned by
(part of) the snapshot source.

Fix it by also checking the leaf's owner before increasing the reference
counter.

Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: fsck-test: Add new image with shared block ref only metadata backref
Qu Wenruo [Wed, 22 Nov 2017 09:03:23 +0000 (17:03 +0800)]
btrfs-progs: fsck-test: Add new image with shared block ref only metadata backref

The image is dumped by modifying kernel to sleep long enough before
merging relocation trees, so we can just copy the whole image to other
place before kernel begins to merge reloc trees.

And the base image is created by the following script to bump metadata
size:
------
dev=~/test.img
mnt=/mnt/btrfs

umount $mnt &> /dev/null
fallocate -l 128M $dev

mkfs.btrfs -f -n 4k -m single -d single $dev
mount $dev $mnt -o nospace_cache,max_inline=2048

btrfs subvolume create $mnt/src
for i in $(seq -w 0 128); do
xfs_io -f -c "pwrite 0 2k" $mnt/src/file_$i > /dev/null
done
for i in $(seq -w 0 64); do
btrfs subvolume snapshot $mnt/src/ $mnt/snapshot_$i
touch $mnt/snapshot_$i/new
done
sync
------

The image triggers several corner cases that the old lowmem mode didn't
consider.

Like metadata backref with FULL_BACKREF flag and only SHARED_BLOCK_REF
backrefs for metadata.  And several tree reloc trees with shared
leaves/nodes to confuse old lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: lowmem check: Fix false alerts for image with shared block ref only...
Qu Wenruo [Wed, 22 Nov 2017 09:03:22 +0000 (17:03 +0800)]
btrfs-progs: lowmem check: Fix false alerts for image with shared block ref only backref

[BUG]
For image with shared block ref only metadata item like:
------
        item 66 key (21573632 METADATA_ITEM 0) itemoff 3971 itemsize 24
                refs 66 gen 9 flags TREE_BLOCK|FULL_BACKREF
                tree block skinny level 0
        item 0 key (21573632 SHARED_BLOCK_REF 21676032) itemoff 3995 itemsize 0
                shared block backref
        item 1 key (21573632 SHARED_BLOCK_REF 21921792) itemoff 3995 itemsize 0
                shared block backref
        item 2 key (21573632 SHARED_BLOCK_REF 21995520) itemoff 3995 itemsize 0
                shared block backref
        item 3 key (21573632 SHARED_BLOCK_REF 22077440) itemoff 3995 itemsize 0
                shared block backref
...
------

Lowmem mode check will report false alerts like:
------
ERROR: extent[21573632 4096] backref lost (owner: 256, level: 0)
------

[CAUSE]
In fact, the false alerts are not even from extent tree verfication,  but
a fs tree helper which is designed to make sure there is some tree block
referring to the fs tree block.

The idea is to find inlined tree backref then keyed TREE_BLOCK_REF_KEY.
However it missed SHARED_BLOCK_REF_KEY, and caused such false alert.

[FIX]
Add SHARED_BLOCK_REF_KEY to make the warning shut up.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: lowmem check: Fix function call stack overflow caused by wrong tree...
Qu Wenruo [Wed, 22 Nov 2017 09:03:21 +0000 (17:03 +0800)]
btrfs-progs: lowmem check: Fix function call stack overflow caused by wrong tree reloc tree detection

For reloc tree root, its backref points to itself.  So for such case,
we should finish the lookup.

Previous end condition is to ensure it's reloc tree *and* needs its root
bytenr to match the bytenr passed in.

However the @root passed can be another tree, e.g. other tree reloc root
which shares the node/leaf.  This makes any check based on @root passed
in invalid.

The patch removes the unreliable root objectid detection, and only uses
root->bytenr check.
For the possibility of invalid self-pointing backref, extent tree
checker should have already handled it, so we don't need to bother in
fs tree checker.

Fixes: 54c8f9152fd9 ("btrfs-progs: check: Fix lowmem mode stack overflow caused by fsck/023")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: backref: Allow backref walk to handle direct parent ref
Qu Wenruo [Wed, 22 Nov 2017 09:03:20 +0000 (17:03 +0800)]
btrfs-progs: backref: Allow backref walk to handle direct parent ref

[BUG]
Btrfs lowmem mode fails with the following ASSERT() on certain valid
image.
------
backref.c:466: __add_missing_keys: Assertion `ref->root_id` failed, value 0
------

[REASON]
Lowmem mode uses btrfs_find_all_roots() when walking down fs trees.

However if a tree block with only shared parent backref like below,
backref code from btrfs-progs doesn't handle it correct.
------
        item 72 key (604653731840 METADATA_ITEM 0) itemoff 13379 itemsize 60
                refs 4 gen 7198 flags TREE_BLOCK|FULL_BACKREF
                tree block skinny level 0
                shared block backref parent 604498477056
                shared block backref parent 604498460672
                shared block backref parent 604498444288
                shared block backref parent 604498411520
------

Such shared block ref is *direct* ref, which means we don't need to
solve its key, nor its rootid.

As the objective of backref walk is to find all direct parents until it
reaches tree root.
So for such direct ref, it should be pended to pref_stat->pending, other
than pending it to pref_stat->pending_missing_key.

[FIX]
For direct ref, pending it to pref_state->pending directly to solve the
problem.

Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>