platform/upstream/btrfs-progs.git
6 years agobtrfs-progs: test/convert: Add test case for invalid large inline data extent
Qu Wenruo [Tue, 20 Mar 2018 06:42:28 +0000 (14:42 +0800)]
btrfs-progs: test/convert: Add test case for invalid large inline data extent

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check/lowmem mode: Check inline extent size
Qu Wenruo [Tue, 20 Mar 2018 06:42:27 +0000 (14:42 +0800)]
btrfs-progs: check/lowmem mode: Check inline extent size

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: original mode: Check inline extent size
Qu Wenruo [Tue, 20 Mar 2018 06:42:26 +0000 (14:42 +0800)]
btrfs-progs: check: original mode: Check inline extent size

For inline compressed file extent, kernel doesn't allow inline extent
ram size larger than sector size and on-disk inline extent size should
not exceed BTRFS_MAX_INLINE_DATA_SIZE().

For inline uncompressed file extent, kernel doesn't allow inline extent
ram and on-disk size larger than either BTRFS_MAX_INLINE_DATA_SIZE() or
sector size.

Check it in original mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs/rootdir: Fix inline extent creation check
Qu Wenruo [Tue, 20 Mar 2018 06:42:25 +0000 (14:42 +0800)]
btrfs-progs: mkfs/rootdir: Fix inline extent creation check

Just like convert, we need extra check against sector size for creating
inline extent.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: convert: Fix inline file extent creation condition
Qu Wenruo [Tue, 20 Mar 2018 06:42:24 +0000 (14:42 +0800)]
btrfs-progs: convert: Fix inline file extent creation condition

[Bug]
On btrfs converted from ext*, one user reported the following kernel
warning:
 ------------[ cut here ]------------
 BTRFS: Transaction aborted (error -95)
 WARNING: CPU: 0 PID: 324 at fs/btrfs/inode.c:3042 btrfs_finish_ordered_io+0x7ab/0x850 [btrfs]
 Workqueue: btrfs-endio-write btrfs_endio_write_helper [btrfs]
 RIP: 0010:btrfs_finish_ordered_io+0x7ab/0x850 [btrfs]
 ...
 Call Trace:
  normal_work_helper+0x39/0x370 [btrfs]
  process_one_work+0x1ce/0x410
  worker_thread+0x2b/0x3d0
  ? process_one_work+0x410/0x410
  kthread+0x113/0x130
  ? kthread_create_on_node+0x70/0x70
  ? do_syscall_64+0x74/0x190
  ? SyS_exit_group+0x10/0x10
  ret_from_fork+0x35/0x40
 ---[ end trace c8ed62ff6a525901 ]---
 BTRFS: error (device dm-2) in
btrfs_finish_ordered_io:3042: errno=-95 unknown
 BTRFS info (device dm-2): forced readonly
 BTRFS error (device dm-2): pending csums is 6447104

[Cause]
The call trace and the unique return value points to
__btrfs_drop_extents(), when we tries to drop pages of an inline extent,
we will trigger such -EOPNOTSUPP.

However kernel has limitation on the size of inline file extent
(sector size for ram size and sector size - 1 for on-disk size),
btrfs-convert doesn't have the same limitation, resulting much larger
file extent.

The lack of correct inline extent size check dates back to 2008 when
btrfs-convert is added into btrfs-progs.

[Fix]
Fix the inline extent creation condition, not only using
BTRFS_MAX_INLINE_DATA_SIZE(), which is only the maximum size of inline
data according to nodesize, but also limit it against sector size.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: dump-tree: add option to print children nodes of a given block
Qu Wenruo [Wed, 14 Mar 2018 01:05:38 +0000 (09:05 +0800)]
btrfs-progs: dump-tree: add option to print children nodes of a given block

When debuging with "btrfs inspect dump-tree", it's not that handy if we
want to iterate all child tree blocks starting from a specified block.

-b can only print a single block, while without -b "btrfs inspect dump-tree"
will need extra tree roots fulfilled to continue, which is not possible
for a damaged filesystem.

Add a new option --follow to iterate a sub-tree starting from block
specified by --block.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ remove the short option for now ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: print-tree: Enhance warning on tree block level mismatch and error handling
Qu Wenruo [Thu, 15 Mar 2018 04:48:15 +0000 (12:48 +0800)]
btrfs-progs: print-tree: Enhance warning on tree block level mismatch and error handling

This patch enhances the tree block level mismatch by the following
methods:

1) Merge same warning branches into one
   We had two branches showing the same message, and their condition
   is also the same. Merge them

2) Only skip bad slot
   The old code skipped all the remaining slots, here we just skip one
   slot to output as many correct tree blocks as possible.

3) Enhance warning message
   Output the parent bytenr and expected and wrong level, so we don't
   need to refer to stdout to get which tree block is corrupted.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Fix typos in docs and user-facing strings
Nicholas D Steeves [Fri, 16 Mar 2018 00:39:09 +0000 (20:39 -0400)]
btrfs-progs: Fix typos in docs and user-facing strings

Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: print-tree: Do correct offset output for ROOT_ITEM
Qu Wenruo [Mon, 19 Mar 2018 10:28:10 +0000 (18:28 +0800)]
btrfs-progs: print-tree: Do correct offset output for ROOT_ITEM

Commit Fixes: 8c36786c8198 ("btrfs-progs: print-tree: Print offset as
tree objectid for ROOT_ITEM") changes how we translate offset of
ROOT_ITEM.

However the fact is, even for ROOT_ITEM, we have different meaning of
offset.

For tree reloc tree, it's indeed subvolume id.  But for other trees,
it's the transid of when it's created.

Reported-by: Nikolay Borisov <nborisov@suse.com>
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: convert/ext2: Remove check for ext2_ext_attr_entry->e_value_block
Qu Wenruo [Wed, 14 Mar 2018 00:56:57 +0000 (08:56 +0800)]
btrfs-progs: convert/ext2: Remove check for ext2_ext_attr_entry->e_value_block

In latest e2fsprogs (1.44.0) definition of ext2_ext_attr_entry has
removed member e_value_block, as currently ext* doesn't support it set
anyway.

So remove such check so that we can pass compile.

Issue: #110
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199071
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agoBtrfs-progs: add fsck test for filesystem with shared prealloc extents
Filipe Manana [Wed, 14 Mar 2018 20:11:18 +0000 (20:11 +0000)]
Btrfs-progs: add fsck test for filesystem with shared prealloc extents

Verify that a filesystem check operation (fsck) does not report the
following scenario as an error:

An extent is shared between two inodes, as a result of clone/reflink
operation, and for one of the inodes, lets call it inode A, the extent is
referenced through a file extent item as a prealloc extent, while for the
other inode, call it inode B, the extent is referenced through a regular
file extent item, that is, it was written to. The goal of this test is to
make sure a filesystem check operation will not report "odd csum items"
errors for the prealloc extent at inode A, because this scenario is valid
since the extent was written through inode B and therefore it is expected
to have checksum items in the filesystem's checksum btree for that shared
extent.

Such scenario can be created with the following steps for example:

 mkfs.btrfs -f /dev/sdb
 mount /dev/sdb /mnt

 touch /mnt/foo
 xfs_io -c "falloc 0 256K" /mnt/foo
 sync

 xfs_io -c "pwrite -S 0xab 0 256K" /mnt/foo
 touch /mnt/bar
 xfs_io -c "reflink /mnt/foo 0 0 256K" /mnt/bar
 xfs_io -c "fsync" /mnt/bar

 <power fail>
 mount /dev/sdb /mnt
 umount /mnt

This scenario is fixed by the following patch for the filesystem checker:

 "Btrfs-progs: check, fix false error reports for shared prealloc extents"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agoBtrfs-progs: check, fix false error reports for shared prealloc extents
Filipe Manana [Wed, 14 Mar 2018 20:11:09 +0000 (20:11 +0000)]
Btrfs-progs: check, fix false error reports for shared prealloc extents

Under some cases the filesystem checker reports an error when it finds
checksum items for an extent that is referenced by an inode as a prealloc
extent. Such cases are not an error when the extent is actually shared
(was cloned/reflinked) with other inodes and was written through one of
those other inodes.

Example:

  $ mkfs.btrfs -f /dev/sdb
  $ mount /dev/sdb /mnt

  $ touch /mnt/foo
  $ xfs_io -c "falloc 0 256K" /mnt/foo
  $ sync

  $ xfs_io -c "pwrite -S 0xab 0 256K" /mnt/foo
  $ touch /mnt/bar
  $ xfs_io -c "reflink /mnt/foo 0 0 256K" /mnt/bar
  $ xfs_io -c "fsync" /mnt/bar

  <power fail>
  $ mount /dev/sdb /mnt
  $ umount /mnt

  $ btrfs check /dev/sdc
  Checking filesystem on /dev/sdb
  UUID: 52d3006e-ee3b-40eb-aa21-e56253a03d39
  checking extents
  checking free space cache
  checking fs roots
  root 5 inode 257 errors 800, odd csum item
  ERROR: errors found in fs roots
  found 688128 bytes used, error(s) found
  total csum bytes: 256
  total tree bytes: 163840
  total fs tree bytes: 65536
  total extent tree bytes: 16384
  btree space waste bytes: 138819
  file data blocks allocated: 10747904
   referenced 10747904
  $ echo $?
  1

So teach check to not report such cases as errors by checking if the
extent is shared with other inodes and if so, consider it an error the
existence of checksum items only if all those other inodes are referencing
the extent as a prealloc extent.
This case can be hit often when running the generic/475 testcase from
fstests.

A test case will follow in a separate patch.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ctree: Add extra level check for read_node_slot()
Qu Wenruo [Thu, 8 Feb 2018 00:59:40 +0000 (08:59 +0800)]
btrfs-progs: ctree: Add extra level check for read_node_slot()

Strangely, we have level check in btrfs_print_tree() while we don't have
the same check in read_node_slot().

That's to say, for the following corruption, btrfs_search_slot() or
btrfs_next_leaf() can return invalid leaf:

Parent eb:
  node XXXXXX level 1
              ^^^^^^^
              Child should be leaf (level 0)
  ...
  key (XXX XXX XXX) block YYYYYY

Child eb:
  leaf YYYYYY level 1
              ^^^^^^^
              Something went wrong now

And for the corrupted leaf returned, later caller can be screwed up
easily.

Reported-by: Ralph Gauges <ralphgauges@googlemail.com>
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: fix source path for testsuite
David Sterba [Mon, 12 Mar 2018 18:17:49 +0000 (19:17 +0100)]
btrfs-progs: tests: fix source path for testsuite

The commit cebf3b37228cbde730a5 ("btrfs-progs: introduce TEST_TOP and
INTERNAL_BIN for tests") did not convert all test paths. This would
break the exported testsutie.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: Add test case with valid orphan inode
Qu Wenruo [Mon, 5 Feb 2018 06:47:12 +0000 (14:47 +0800)]
btrfs-progs: tests: Add test case with valid orphan inode

Regression test for false alerts in lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update test ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: lowmem: Fix false alert about orphan inode
Qu Wenruo [Mon, 5 Feb 2018 06:47:11 +0000 (14:47 +0800)]
btrfs-progs: check: lowmem: Fix false alert about orphan inode

Btrfs can delay inode deletion and in that case btrfs will unlink the
victim inode from its parent dir, and insert a marker to info btrfs to
delete it later.

In that case, such victim inode will have nlinks == 0, but is still
completely valid.
Original mode won't report such problem, but lowmem mode doesn't check
the ORPHAN_ITEM key for such inode, and can report false alert like:
------
ERROR: root 257 INODE[28891726] is orphan item
------

Fix such false alert by checking orphan item for inode whose nlink is 0.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: gitignore: Ignore patches
Qu Wenruo [Mon, 5 Feb 2018 06:47:14 +0000 (14:47 +0800)]
btrfs-progs: gitignore: Ignore patches

Although it's not a good practice to format all patches under project
directory, sometimes lazy bones like me just like to put patches under
project directory.

Just ignore such patches.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: gitignore: Ignore *.restored test image
Qu Wenruo [Mon, 5 Feb 2018 06:47:13 +0000 (14:47 +0800)]
btrfs-progs: gitignore: Ignore *.restored test image

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: fsck-tests: Introduce test case with keyed data backref with the extent...
Lu Fengqi [Wed, 28 Feb 2018 10:13:23 +0000 (18:13 +0800)]
btrfs-progs: fsck-tests: Introduce test case with keyed data backref with the extent offset

Add the testcase for false alert of data extent backref lost with the
extent offset.

The image can be reproduced by the following commands:
------
dev=~/test.img
mnt=/mnt/btrfs

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

mkfs.btrfs $dev
mount $dev $mnt

for i in `seq 1 10`; do
xfs_io -f -c "pwrite 0 2K" $mnt/file$i
done

xfs_io -f -c "falloc 0 64K" $mnt/file11

for i in `seq 1 32`; do
xfs_io -f -c "reflink $mnt/file11 0 $(($i * 64))K 64K" $mnt/file11
done

xfs_io -f -c "reflink $mnt/file11 32K $((33 * 64))K 32K" $mnt/file11

btrfs subvolume snapshot $mnt $mnt/snap1

umount $mnt
btrfs-image -c9 $dev extent_data_ref.img
------

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check/lowmem: Fix false alert of data extent backref lost for snapshot
Lu Fengqi [Wed, 28 Feb 2018 10:13:22 +0000 (18:13 +0800)]
btrfs-progs: check/lowmem: Fix false alert of data extent backref lost for snapshot

Btrfs lowmem check reports the following false alert:
------
ERROR: file extent[267 2162688] root 256 owner 5 backref lost
------

The file extent is in the leaf which is shared by file tree 256 and fs
tree.
------
leaf 30605312 items 46 free space 4353 generation 7 owner 5
......
        item 45 key (267 EXTENT_DATA 2162688) itemoff 5503 itemsize 53
                generation 7 type 2 (prealloc)
                prealloc data disk byte 13631488 nr 65536
                prealloc data offset 32768 nr 32768
------

And there is the corresponding extent_data_ref item in the extent tree.
------
        item 1 key (13631488 EXTENT_DATA_REF 1007496934287921081) itemoff 15274 itemsize 28
                extent data backref root 5 objectid 267 offset 2129920 count 1
------

The offset of EXTENT_DATA_REF which is the hash of the owner root objectid,
the inode number and the calculated offset (file offset - extent offset).

What caused the false alert is the code mix up the owner root objectid and
the file tree objectid.

Fixes: b0d360b541f0 ("btrfs-progs: check: introduce function to check data backref in extent tree")
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check/lowmem: Fix the incorrect error message of check_extent_data_item
Lu Fengqi [Wed, 28 Feb 2018 10:13:21 +0000 (18:13 +0800)]
btrfs-progs: check/lowmem: Fix the incorrect error message of check_extent_data_item

Instead of the disk_bytenr and disk_num_bytes of the extent_item which the
file extent references, we should output the objectid and offset of the
file extent. And the leaf may be shared by the file trees, we should print
the objectid of the root and the owner of the leaf.

Fixes: b0d360b541f0 ("btrfs-progs: check: introduce function to check data backref in extent tree")
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: dump-super: Don't verify csum if csum type or size is unknown
Qu Wenruo [Tue, 6 Mar 2018 02:16:51 +0000 (10:16 +0800)]
btrfs-progs: dump-super: Don't verify csum if csum type or size is unknown

Reported-by: Ken Swenson <flat@imo.uto.moe>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: free-space-cache: Enhance free space cache free space check
Qu Wenruo [Thu, 8 Mar 2018 07:02:31 +0000 (15:02 +0800)]
btrfs-progs: free-space-cache: Enhance free space cache free space check

When we found free space difference between free space cache and block
group item, we just discard this free space cache.

Normally such difference is caused by btrfs_reserve_extent() called by
delalloc which is out of a transaction.
And since all btrfs_release_extent() is called with a transaction, under
heavy race free space cache can have less free space than block group
item.

Normally kernel will detect such difference and just discard that cache.

However we must be more careful if free space cache has more free space
cache, and if that happens, paried with above race one invalid free
space cache can be loaded into kernel.

So if we find any free space cache who has more free space then block
group item, we report it as an error other than ignoring it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: add section about filesystem limits to btrfs(5)
David Sterba [Tue, 6 Mar 2018 13:22:14 +0000 (14:22 +0100)]
btrfs-progs: docs: add section about filesystem limits to btrfs(5)

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: free-space-cache: Use DIV_ROUND_UP() to replace open code
Qu Wenruo [Mon, 5 Mar 2018 08:09:12 +0000 (16:09 +0800)]
btrfs-progs: free-space-cache: Use DIV_ROUND_UP() to replace open code

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: use pkg-config detection for the right Python version
Omar Sandoval [Tue, 27 Feb 2018 20:42:38 +0000 (12:42 -0800)]
libbtrfsutil: use pkg-config detection for the right Python version

The user may have specified a different version of Python than the
python3 from their $PATH (e.g., with PYTHON=/usr/bin/python3.6).

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: enable clang and python for musl build test
David Sterba [Tue, 27 Feb 2018 16:08:30 +0000 (17:08 +0100)]
btrfs-progs: ci: enable clang and python for musl build test

The updated image now provides clang, so the variable is exported from
the base environment to docker. And we have python too.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: update test image packages - add clang and python
David Sterba [Tue, 27 Feb 2018 16:07:22 +0000 (17:07 +0100)]
btrfs-progs: ci: update test image packages - add clang and python

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutils: add python-devel detection
David Sterba [Tue, 27 Feb 2018 15:19:51 +0000 (16:19 +0100)]
libbtrfsutils: add python-devel detection

Use pkg-config to detect python devel.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: cache built dependencies
David Sterba [Sat, 24 Feb 2018 00:57:42 +0000 (01:57 +0100)]
btrfs-progs: ci: cache built dependencies

For a slight speed up of the build, cache reiserfs and zstd. A quick
cache validity is done, or it can be cleared manually on travis web UI.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()
Omar Sandoval [Sun, 21 Jan 2018 08:24:50 +0000 (00:24 -0800)]
btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()

This gets the remaining occurrences that weren't covered by previous
conversions.

Signed-off-by: Omar Sandoval <osandov@fb.com>
[ fixup test_issubvolume due to removed dependency patch ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for subvol sync
Omar Sandoval [Wed, 24 Jan 2018 23:54:14 +0000 (15:54 -0800)]
btrfs-progs: use libbtrfsutil for subvol sync

btrfs_util_f_deleted_subvolumes() replaces enumerate_dead_subvols() and
btrfs_util_f_subvolume_info() replaces is_subvolume_cleaned().

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for subvol show
Omar Sandoval [Wed, 20 Dec 2017 20:37:08 +0000 (12:37 -0800)]
btrfs-progs: use libbtrfsutil for subvol show

Now implemented with btrfs_util_subvolume_path(),
btrfs_util_subvolume_info(), and subvolume iterators.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for subvol delete
Omar Sandoval [Sat, 20 Jan 2018 21:04:48 +0000 (13:04 -0800)]
btrfs-progs: use libbtrfsutil for subvol delete

Most of the interesting part of this command is the commit mode, so this
only saves a little bit of code.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for get-default
Omar Sandoval [Fri, 19 Jan 2018 22:52:11 +0000 (14:52 -0800)]
btrfs-progs: use libbtrfsutil for get-default

The only thing of note here is the "top level" column. This used to mean
something else, but for a long time it has been equal to the parent ID.
I preserved this for backwards compatability.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for set-default
Omar Sandoval [Wed, 20 Dec 2017 17:43:52 +0000 (09:43 -0800)]
btrfs-progs: use libbtrfsutil for set-default

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for sync ioctls
Omar Sandoval [Thu, 25 Jan 2018 09:35:27 +0000 (01:35 -0800)]
btrfs-progs: use libbtrfsutil for sync ioctls

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: use libbtrfsutil for read-only property
Omar Sandoval [Sat, 20 Jan 2018 00:49:29 +0000 (16:49 -0800)]
btrfs-progs: use libbtrfsutil for read-only property

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_deleted_subvolumes()
Omar Sandoval [Wed, 24 Jan 2018 20:48:59 +0000 (12:48 -0800)]
libbtrfsutil: add btrfs_util_deleted_subvolumes()

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_delete_subvolume()
Omar Sandoval [Thu, 18 Jan 2018 22:26:35 +0000 (14:26 -0800)]
libbtrfsutil: add btrfs_util_delete_subvolume()

We also support recursive deletion using a subvolume iterator.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_create_snapshot()
Omar Sandoval [Thu, 18 Jan 2018 22:23:23 +0000 (14:23 -0800)]
libbtrfsutil: add btrfs_util_create_snapshot()

Thanks to subvolume iterators, we can also implement recursive snapshot
fairly easily.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add subvolume iterator helpers
Omar Sandoval [Thu, 18 Jan 2018 22:05:12 +0000 (14:05 -0800)]
libbtrfsutil: add subvolume iterator helpers

This is how we can implement stuff like `btrfs subvol list`. Rather than
producing the entire list upfront, the iterator approach uses less
memory in the common case where the whole list is not stored (O(max
subvolume path length)). It supports both pre-order traversal (useful
for, e.g, recursive snapshot) and post-order traversal (useful for
recursive delete).

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add stub for reallocarray
David Sterba [Thu, 22 Feb 2018 11:45:14 +0000 (12:45 +0100)]
libbtrfsutil: add stub for reallocarray

This function is new in glibc 2.26 and breaks build in CI and possibly
other environments.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_[gs]et_default_subvolume()
Omar Sandoval [Thu, 18 Jan 2018 21:51:16 +0000 (13:51 -0800)]
libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()

set_default_subvolume() is a trivial ioctl(), but there's no ioctl() for
get_default_subvolume(), so we need to search the root tree.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_[gs]et_read_only()
Omar Sandoval [Thu, 18 Jan 2018 21:39:57 +0000 (13:39 -0800)]
libbtrfsutil: add btrfs_util_[gs]et_read_only()

In the future, btrfs_util_[gs]et_subvolume_flags() might be useful, but
since these are the only subvolume flags we've defined in all this time,
this will do for now.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_subvolume_info()
Omar Sandoval [Thu, 18 Jan 2018 21:33:02 +0000 (13:33 -0800)]
libbtrfsutil: add btrfs_util_subvolume_info()

This gets the the information in `btrfs subvolume show` from the root
item.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_subvolume_path()
Omar Sandoval [Thu, 15 Feb 2018 06:16:33 +0000 (22:16 -0800)]
libbtrfsutil: add btrfs_util_subvolume_path()

We can just walk up root backrefs with BTRFS_IOC_TREE_SEARCH and inode
paths with BTRFS_IOC_INO_LOOKUP.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_create_subvolume()
Omar Sandoval [Thu, 18 Jan 2018 21:15:32 +0000 (13:15 -0800)]
libbtrfsutil: add btrfs_util_create_subvolume()

Doing the ioctl() directly isn't too bad, but passing in a full path is
more convenient than opening the parent and passing the path component.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id()
Omar Sandoval [Thu, 18 Jan 2018 20:49:55 +0000 (12:49 -0800)]
libbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id()

These are the most trivial helpers in the library and will be used to
implement several of the more involved functions.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: copy in Btrfs UAPI headers
Omar Sandoval [Wed, 21 Feb 2018 19:55:11 +0000 (11:55 -0800)]
libbtrfsutil: copy in Btrfs UAPI headers

Systems with older kernels won't have these available, and the copies in
btrfs-progs aren't quite compatible, so for now, let's just copy these
in. We can potentially deduplicate some of this in the future.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: fix Python tests
Omar Sandoval [Wed, 21 Feb 2018 20:15:54 +0000 (12:15 -0800)]
libbtrfsutil: fix Python tests

These were broken when the patch series got shuffled around.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Move chunk stripe size calculation function to volumes.h
Qu Wenruo [Fri, 9 Feb 2018 07:44:26 +0000 (15:44 +0800)]
btrfs-progs: Move chunk stripe size calculation function to volumes.h

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: volumes: Allow find_free_dev_extent() to return maximum hole size
Qu Wenruo [Fri, 9 Feb 2018 07:44:23 +0000 (15:44 +0800)]
btrfs-progs: volumes: Allow find_free_dev_extent() to return maximum hole size

Just as kernel find_free_dev_extent(), allow it to return maximum hole
size for us to build device list for later chunk allocator rework.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Introduce btrfs_raid_array and related infrastructures
Qu Wenruo [Fri, 9 Feb 2018 07:44:22 +0000 (15:44 +0800)]
btrfs-progs: Introduce btrfs_raid_array and related infrastructures

As part of the effort to unify code and behavior between btrfs-progs and
kernel, copy the btrfs_raid_array from kernel to btrfs-progs.

So later we can use the btrfs_raid_array[] to get needed raid info other
than manually do if-else branches.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Refactor parameter of BTRFS_MAX_DEVS() from root to fs_info
Qu Wenruo [Fri, 9 Feb 2018 07:44:19 +0000 (15:44 +0800)]
btrfs-progs: Refactor parameter of BTRFS_MAX_DEVS() from root to fs_info

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add filesystem sync helpers
Omar Sandoval [Thu, 25 Jan 2018 09:18:20 +0000 (01:18 -0800)]
libbtrfsutil: add filesystem sync helpers

Namely, sync, start_sync, and wait_sync.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add qgroup inheritance helpers
Omar Sandoval [Thu, 18 Jan 2018 21:09:32 +0000 (13:09 -0800)]
libbtrfsutil: add qgroup inheritance helpers

We want to hide struct btrfs_qgroup_inherit from the user because that
comes from the Btrfs UAPI headers. Instead, wrap it in a struct
btrfs_util_qgroup_inherit and provide helpers to manipulate it. This
will be used for subvolume and snapshot creation.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agolibbtrfsutil: add Python bindings
Omar Sandoval [Mon, 18 Dec 2017 08:31:25 +0000 (00:31 -0800)]
libbtrfsutil: add Python bindings

The C libbtrfsutil library isn't very useful for scripting, so we also
want bindings for Python. Writing unit tests in Python is also much
easier than doing so in C. Only Python 3 is supported; if someone really
wants Python 2 support, they can write their own bindings. This commit
is just the scaffolding.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: add python dependencies for libbtrfsutil
David Sterba [Wed, 21 Feb 2018 00:10:16 +0000 (01:10 +0100)]
btrfs-progs: ci: add python dependencies for libbtrfsutil

Install the setuptools. Python is not yet in the musl image, so the
build is disabled there.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agoAdd libbtrfsutil
Omar Sandoval [Thu, 15 Feb 2018 19:04:47 +0000 (11:04 -0800)]
Add libbtrfsutil

Currently, users wishing to manage Btrfs filesystems programatically
have to shell out to btrfs-progs and parse the output. This isn't ideal.
The goal of libbtrfsutil is to provide a library version of as many of
the operations of btrfs-progs as possible and to migrate btrfs-progs to
use it.

Rather than simply refactoring the existing btrfs-progs code, the code
has to be written from scratch for a couple of reasons:

* A lot of the btrfs-progs code was not designed with a nice library API
  in mind in terms of reusability, naming, and error reporting.
* libbtrfsutil is licensed under the LGPL, whereas btrfs-progs is under
  the GPL, which makes it dubious to directly copy or move the code.

Eventually, most of the low-level btrfs-progs code should either live in
libbtrfsutil or the shared kernel/userspace filesystem code, and
btrfs-progs will just be the CLI wrapper.

This first commit just includes the build system changes, license,
README, and error reporting helper.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: add helper to log pipe stdout
David Sterba [Mon, 19 Feb 2018 18:24:07 +0000 (19:24 +0100)]
btrfs-progs: tests: add helper to log pipe stdout

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: add test for send -p on 2 mont points
David Sterba [Mon, 19 Feb 2018 18:07:32 +0000 (19:07 +0100)]
btrfs-progs: tests: add test for send -p on 2 mont points

Add testcase from issue, use reproducer from Axel Burri.

Issue: #96
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: prevent incorrect use of subvol_strip_mountpoint
Axel Burri [Sat, 17 Feb 2018 15:05:34 +0000 (16:05 +0100)]
btrfs-progs: prevent incorrect use of subvol_strip_mountpoint

Add additional bound checks to prevent memory corruption on incorrect
usage of subvol_strip_mountpoint. Assert sane return value by properly
comparing the mount point to the full_path before stripping it off.

Mitigates issue: "btrfs send -p" fails if source and parent subvolumes
are on different mountpoints (memory corruption):

    https://github.com/kdave/btrfs-progs/issues/96

Note that this does not properly fix this bug, but prevents a possible
security issue by unexpected usage of "btrfs send -p".

Issue: #96
Pull-request: #98
Signed-off-by: Axel Burri <axel@tty0.ch>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: build: configure.ac hard-codes the pkg-config command
David Sterba [Mon, 19 Feb 2018 17:13:46 +0000 (18:13 +0100)]
btrfs-progs: build: configure.ac hard-codes the pkg-config command

Right now the pkg-config command is hard-coded in configure.ac, which may
result in build errors on system and cross environments that have prefixed
toolchains, e.g. /usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-pkg-config.

Please see the attached patch, it has been written a while ago but it seems it
hasn't been submitted for upstream inclusion.
0001-configure.ac-Consistently-use-PKG_CONFIG.txt

Submitted by Timo Gurr.

Author: Wulf C. Krueger <philantrop@exherbo.org>
Issue: #101
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agoBtrfs progs v4.15.1
David Sterba [Fri, 16 Feb 2018 16:01:17 +0000 (17:01 +0100)]
Btrfs progs v4.15.1

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

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: let callers of btrfs_show_qgroups free the buffers
David Sterba [Thu, 15 Feb 2018 17:13:35 +0000 (18:13 +0100)]
btrfs-progs: let callers of btrfs_show_qgroups free the buffers

btrfs_show_qgroups frees the filter and comparer in case it succeeds.
This makes the caller slightly more complicated so move the freeing up
one level.

Issue: #20
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: convert/ext2: Fix memory leak caused by handled ext2_filsys
Qu Wenruo [Wed, 14 Feb 2018 08:09:56 +0000 (16:09 +0800)]
btrfs-progs: convert/ext2: Fix memory leak caused by handled ext2_filsys

Exposed by convert-test with D=asan.

Unlike btrfs, ext2fs_close() still leaves its ext2_filsys parameter
filled with allocated pointers.

It needs ext2fs_free() to free those pointers.

Issue: #92
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs/rootdir: Fix memory leak in traverse_directory()
Qu Wenruo [Wed, 14 Feb 2018 07:50:06 +0000 (15:50 +0800)]
btrfs-progs: mkfs/rootdir: Fix memory leak in traverse_directory()

The bug is exposed by mkfs test case 009, with D=asan.

We are leaking memory of parent_dir_entry->path() which ,except the
rootdir, is allocated by strdup().

Before fixing it, unifiy the allocation of parent_dir_entry() to heap
allocation.

Then fix it by adding "free(parent_dir_entry->path);" in
traverse_directory() and error handler.

Issue: #92
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: btrfs-progs: Fix read beyond boundary bug in build_roots_info_cache()
Qu Wenruo [Wed, 14 Feb 2018 15:15:46 +0000 (16:15 +0100)]
btrfs-progs: btrfs-progs: Fix read beyond boundary bug in build_roots_info_cache()

This bug is exposed by fsck-test with D=asan, hit by test case 020, with
the following error report:

=================================================================
==10740==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000061580 at pc 0x56051f0db6cd bp 0x7ffe170f3e20 sp 0x7ffe170f3e10
READ of size 1 at 0x621000061580 thread T0
    #0 0x56051f0db6cc in btrfs_extent_inline_ref_type /home/adam/btrfs/btrfs-progs/ctree.h:1727
    #1 0x56051f13b669 in build_roots_info_cache /home/adam/btrfs/btrfs-progs/cmds-check.c:14306
    #2 0x56051f13c86a in repair_root_items /home/adam/btrfs/btrfs-progs/cmds-check.c:14450
    #3 0x56051f13ea89 in cmd_check /home/adam/btrfs/btrfs-progs/cmds-check.c:14965
    #4 0x56051efe75bb in main /home/adam/btrfs/btrfs-progs/btrfs.c:302
    #5 0x7f04ddbb0f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
    #6 0x56051efe68c9 in _start (/home/adam/btrfs/btrfs-progs/btrfs+0x5b8c9)

0x621000061580 is located 0 bytes to the right of 4224-byte region [0x621000060500,0x621000061580)
allocated by thread T0 here:
    #0 0x7f04ded50ce1 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:70
    #1 0x56051f04685e in __alloc_extent_buffer /home/adam/btrfs/btrfs-progs/extent_io.c:553
    #2 0x56051f047563 in alloc_extent_buffer /home/adam/btrfs/btrfs-progs/extent_io.c:687
    #3 0x56051efff1d1 in btrfs_find_create_tree_block /home/adam/btrfs/btrfs-progs/disk-io.c:187
    #4 0x56051f000133 in read_tree_block /home/adam/btrfs/btrfs-progs/disk-io.c:327
    #5 0x56051efeddb8 in read_node_slot /home/adam/btrfs/btrfs-progs/ctree.c:652
    #6 0x56051effb0d9 in btrfs_next_leaf /home/adam/btrfs/btrfs-progs/ctree.c:2853
    #7 0x56051f13b343 in build_roots_info_cache /home/adam/btrfs/btrfs-progs/cmds-check.c:14267
    #8 0x56051f13c86a in repair_root_items /home/adam/btrfs/btrfs-progs/cmds-check.c:14450
    #9 0x56051f13ea89 in cmd_check /home/adam/btrfs/btrfs-progs/cmds-check.c:14965
    #10 0x56051efe75bb in main /home/adam/btrfs/btrfs-progs/btrfs.c:302
    #11 0x7f04ddbb0f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)

It's completely possible that one extent/metadata item has no inline
reference, while build_roots_info_cache() doesn't have such check.

Fix it by checking @iref against item end to avoid such problem.

Issue: #92
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: reorder tests in make target
David Sterba [Tue, 13 Feb 2018 14:32:03 +0000 (15:32 +0100)]
btrfs-progs: reorder tests in make target

Run the shorter tests first, convert can take very long, we're more
interested in the misc test.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: print-tree: fix INODE_ITEM sequence and flags
Anand Jain [Mon, 12 Feb 2018 15:21:26 +0000 (23:21 +0800)]
btrfs-progs: print-tree: fix INODE_ITEM sequence and flags

dump-tree prints wrong sequence number and the flags numbers,
as we misplaced the printf args. This patch fixes it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: document exported testsuite
David Sterba [Thu, 8 Feb 2018 17:44:41 +0000 (18:44 +0100)]
btrfs-progs: tests: document exported testsuite

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: test: update clean-test.sh after the TEST_TOP update
David Sterba [Tue, 13 Feb 2018 15:21:20 +0000 (16:21 +0100)]
btrfs-progs: test: update clean-test.sh after the TEST_TOP update

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: unify test drivers, make ready for extenral testsuite
David Sterba [Thu, 8 Feb 2018 17:34:40 +0000 (18:34 +0100)]
btrfs-progs: tests: unify test drivers, make ready for extenral testsuite

Make the TOP variable more configurable, allow to set it to any path
where to find binaries when the testsuite is exported, or fallback to
system binaries.

There's now more code duplication, the logic is now more complex so it's
left open coded for clarity. Further cleanups are possible.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests: update README.md
David Sterba [Thu, 8 Feb 2018 16:40:34 +0000 (17:40 +0100)]
btrfs-progs: tests: update README.md

Irregular proofreading with adjustments and enhancements.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
Gu Jinxiang [Thu, 8 Feb 2018 06:34:19 +0000 (14:34 +0800)]
btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests

Use TEST_TOP as base for tests to reference any files, this will be used
for git and external testsuite.

INTERNAL_BIN is needed for referencing binaries that could reside in
different paths in git vs external testsuite.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
[ add quotes around sourced files, update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: rework testsuite export
David Sterba [Thu, 8 Feb 2018 14:34:04 +0000 (15:34 +0100)]
btrfs-progs: rework testsuite export

Move the testsuite to tests/ and make the tarball generation more
deterministic. As there could be many random temporary files left in the
test directories, we can't just copy them. Use 'git ls-tree' to
filter just what we want, this needs a slight extension of the file list
specification.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: Add make testsuite command for export tests
Gu Jinxiang [Thu, 8 Feb 2018 06:34:18 +0000 (14:34 +0800)]
btrfs-progs: Add make testsuite command for export tests

Export the testsuite files to a separate tar.  Since fsck tests depend
on btrfs-corrupt-block, and misc tests depends on both
btrfs-corrupt-block and fssum, so set it as prerequisites for package
commad.

Because, althougth fssum can be generated by source that are all in
tests directory, and has no rely on the btrfs's structure.  But
btrfs-corrupt-block deeply relys on btrfs's structure.  For consistency,
at the present stage, generete the two when create test tar.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
[ applied without changes, the generated tarball will be different from
  the one after the follow up commits ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: add prerequisite btrfs-convert for test-misc
Gu Jinxiang [Thu, 8 Feb 2018 05:08:58 +0000 (13:08 +0800)]
btrfs-progs: add prerequisite btrfs-convert for test-misc

Since tests/misc-tests/005-convert-progress-thread-crash/test.sh need
the btrfs-convert for prerequisite.  So add the dependency in Makefile.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: add prerequisite btrfs-image for test-fuzz
Gu Jinxiang [Thu, 8 Feb 2018 05:08:57 +0000 (13:08 +0800)]
btrfs-progs: add prerequisite btrfs-image for test-fuzz

Since tests/fuzz-tests/002-simple-image/test.sh need the btrfs-image for
prerequisite.  So add the dependency in Makefile.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: add prerequisite mkfs.btrfs for test-cli
Gu Jinxiang [Thu, 8 Feb 2018 05:08:56 +0000 (13:08 +0800)]
btrfs-progs: add prerequisite mkfs.btrfs for test-cli

Since tests/cli-tests/002-balance-full-no-filters/test.sh need
the mkfs.btrfs for prerequisite.
So add the dependency in Makefile.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: replace inline shell commands with scripts
David Sterba [Thu, 8 Feb 2018 00:49:11 +0000 (01:49 +0100)]
btrfs-progs: ci: replace inline shell commands with scripts

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: use helper script for default build commands
David Sterba [Thu, 8 Feb 2018 00:41:40 +0000 (01:41 +0100)]
btrfs-progs: ci: use helper script for default build commands

There's a script for the make command combo, let's use it.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: enable musl build tests in docker
David Sterba [Thu, 8 Feb 2018 00:36:50 +0000 (01:36 +0100)]
btrfs-progs: ci: enable musl build tests in docker

Enable docker in travis and start build test(s) before our testsuite.
Now for musl libc, so we don't accidentally break the build anymore.

Issue: #29
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: add dockerfile for a musl build test
David Sterba [Thu, 8 Feb 2018 00:26:55 +0000 (01:26 +0100)]
btrfs-progs: ci: add dockerfile for a musl build test

Build environment with musl as the libc, based on Alpine Linux.

To build the docker image:
- cd travis/images
- cp test-build $dir
- cd $dir
- docker build -t $tag .
- docker push $tag

We're going to have more images that will share the prep script so it
has to be copied to the directory before making the image. No other way
around that.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: add support scripts for docker build
David Sterba [Thu, 8 Feb 2018 00:24:25 +0000 (01:24 +0100)]
btrfs-progs: ci: add support scripts for docker build

The test-build resides inside the docker image and is supposed to be
called from outside, downloads the branch and calls build-default.
Buid-default will run up to make.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: ci: change clone depth to 1
David Sterba [Thu, 8 Feb 2018 00:00:12 +0000 (01:00 +0100)]
btrfs-progs: ci: change clone depth to 1

Check only the top commit of a given branch.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: tests common: remove meaningless colon in extract_image()
Su Yue [Wed, 7 Feb 2018 09:57:43 +0000 (17:57 +0800)]
btrfs-progs: tests common: remove meaningless colon in extract_image()

The colon is meaningless so remove it.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: fsck-tests: Cleanup the restored image for 028
Qu Wenruo [Tue, 6 Feb 2018 07:31:42 +0000 (15:31 +0800)]
btrfs-progs: fsck-tests: Cleanup the restored image for 028

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: mkfs: fix build on musl
David Sterba [Sat, 3 Feb 2018 00:15:42 +0000 (01:15 +0100)]
btrfs-progs: mkfs: fix build on musl

Another build failure on musl.

Issue: #90
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: convert: fix build on musl
David Sterba [Sat, 3 Feb 2018 00:06:21 +0000 (01:06 +0100)]
btrfs-progs: convert: fix build on musl

Voidlinux has a patch to fix build on musl.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: build: add support for asciidoctor doc generator
David Sterba [Fri, 2 Feb 2018 19:51:25 +0000 (20:51 +0100)]
btrfs-progs: build: add support for asciidoctor doc generator

We've been using asciidoc that's written in python2, which is going to
be phased out and deprecated next year. There's a replacement,
asciidoctor. Add a configure-time detection which tool is available,
update Documentation/Makefile.in.

The original asciidoc tool is still preferred as it produces slightly
better output. The file asciidoc.conf does not have a direct equivalten
in asciidoct and would need to be replaced by extension written in ruby.

The differences:

- the <literal> are not automatically underlined and are less visible in
  the generated manual page, but it's still acceptable
- the inline CSS for the html output looks subjectively worse, is less
  compact and colourful

Issue: #89
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: docs: fix manual page title format
David Sterba [Fri, 2 Feb 2018 19:49:00 +0000 (20:49 +0100)]
btrfs-progs: docs: fix manual page title format

Asciidoctor is more strict about the formatting for the manual pages and
needs exact number of =.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: rename files after moving code
David Sterba [Thu, 1 Feb 2018 16:14:42 +0000 (17:14 +0100)]
btrfs-progs: check: rename files after moving code

Add prefixes to the files so it's clear they belong to the mode group.

Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Cleanup all checkpatch error and warning
Qu Wenruo [Thu, 1 Feb 2018 06:34:42 +0000 (14:34 +0800)]
btrfs-progs: check: Cleanup all checkpatch error and warning

Since we're moving tons of code, it's a good idea to fix all errors and
warnings from checkpatch.

Note: we don't rely on checkpatch, take its warnings and errors as a
      hint and do not blindly fix anything that gets reported. The code
      follows some style that should be kept and is not in 100% with
      what checkpatch finds. Always apply your common sense and decide
      if the change makes sense or if it is really making the code
      better.

Additional fixes from dsterba:

- %Lu -> %llu
- lowercase first word or messages

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ added note ]
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffixes
Qu Wenruo [Fri, 19 Jan 2018 05:26:49 +0000 (13:26 +0800)]
btrfs-progs: check/lowmem: Cleanup unnecessary _v2 suffixes

There used to be some functions with _v2 suffix to distinguish them from
original mode that had similar functions.

However now when the lowmem mode is moved to own check/lowmem.[ch],
cleanup the _v2 suffixes, and for functions that really need to be
distinguished from original mode (exported functions), change the _v2
suffix to _lowmem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move lowmem check code to its own check/lowmem.[ch]
Qu Wenruo [Thu, 1 Feb 2018 05:37:31 +0000 (13:37 +0800)]
btrfs-progs: check: Move lowmem check code to its own check/lowmem.[ch]

Since lowmem mode code is highly internally connected, it's pretty hard to
move them piece by piece.
In theory it's possible to move part of the functions and temporarily
export them, but it will just cause extra temporarily modifications.

So this patch moves the whole lowmem check part into its own
check/lowmem.[ch].

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
6 years agobtrfs-progs: check: Move reset_cached_block_groups to check/common.c
Qu Wenruo [Thu, 18 Jan 2018 08:38:23 +0000 (16:38 +0800)]
btrfs-progs: check: Move reset_cached_block_groups to check/common.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: check: Move check_child_node to check/common.c
Qu Wenruo [Thu, 18 Jan 2018 08:30:10 +0000 (16:30 +0800)]
btrfs-progs: check: Move check_child_node to check/common.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>