Commit Graph

4042 Commits (78c5a90ebf22989b07770de6324cc14a70d72a17)
 

Author SHA1 Message Date
Qu Wenruo 78c5a90ebf 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>
2018-02-14 16:31:19 +01:00
Qu Wenruo 54246115ba 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>
2018-02-14 16:20:30 +01:00
David Sterba e6477462d3 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>
2018-02-13 16:22:55 +01:00
Anand Jain 9fe78033cb 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>
2018-02-13 16:22:55 +01:00
David Sterba 9aa0c422b8 btrfs-progs: tests: document exported testsuite
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 16:22:55 +01:00
David Sterba dbb8c9d19e btrfs-progs: test: update clean-test.sh after the TEST_TOP update
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 16:22:55 +01:00
David Sterba e44f595dd7 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>
2018-02-13 16:19:48 +01:00
David Sterba dd11901dae btrfs-progs: tests: update README.md
Irregular proofreading with adjustments and enhancements.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
Gu Jinxiang cebf3b3722 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>
2018-02-13 15:41:32 +01:00
David Sterba 04cd2c0bca 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>
2018-02-13 15:41:32 +01:00
Gu Jinxiang eb2fe7d1c4 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>
2018-02-13 15:41:32 +01:00
Gu Jinxiang d5238ad711 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>
2018-02-13 15:41:32 +01:00
Gu Jinxiang 64a938ff70 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>
2018-02-13 15:41:32 +01:00
Gu Jinxiang 837c850415 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>
2018-02-13 15:41:32 +01:00
David Sterba 5432a68997 btrfs-progs: ci: replace inline shell commands with scripts
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
David Sterba ba067ed4ee 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>
2018-02-13 15:41:32 +01:00
David Sterba ddfe4d7c30 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>
2018-02-13 15:41:32 +01:00
David Sterba 3cfe67998a 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>
2018-02-08 01:26:55 +01:00
David Sterba 47cbdeb836 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>
2018-02-08 01:24:25 +01:00
David Sterba 5720b3ae9a 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>
2018-02-08 01:00:12 +01:00
Su Yue 03401ccd7c 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>
2018-02-07 15:32:08 +01:00
Qu Wenruo c38425344e 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>
2018-02-06 14:33:20 +01:00
David Sterba 3aa1bbdd89 btrfs-progs: mkfs: fix build on musl
Another build failure on musl.

Issue: #90
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-03 01:15:42 +01:00
David Sterba de60d6f047 btrfs-progs: convert: fix build on musl
Voidlinux has a patch to fix build on musl.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-03 01:06:21 +01:00
David Sterba 652544f4c0 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>
2018-02-02 21:02:13 +01:00
David Sterba 4523dc2776 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>
2018-02-02 21:02:13 +01:00
David Sterba 6d3fea8f46 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>
2018-02-02 16:01:59 +01:00
Qu Wenruo 3876f9f1d5 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>
2018-02-02 16:01:59 +01:00
Qu Wenruo 3a939bc7f3 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>
2018-02-02 16:01:59 +01:00
Qu Wenruo b8d706e58e 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>
2018-02-02 16:01:59 +01:00
Qu Wenruo 5dade4b951 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>
2018-02-02 16:01:59 +01:00
Qu Wenruo 3d3ce73d90 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo fa37a13f73 btrfs-progs: check: move reada_walk_down to check/common.c
Both original and lowmem modes share this function to do readahead.

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>
2018-02-02 16:01:58 +01:00
Qu Wenruo d0b191b880 btrfs-progs: check: Move check_dev_size_alignment 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo 4e84c8251a btrfs-progs: check: Move link_inode_to_lostfound function to 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo a20557599e 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo b695ef1ddc 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo d1b55330c2 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo 58a19f1ea7 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo 96c6e1f0aa 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo 5c9ac8dc48 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>
2018-02-02 16:01:58 +01:00
Qu Wenruo 16e58a4003 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>
2018-02-02 16:01:57 +01:00
Qu Wenruo c10efe7c1c 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>
2018-02-02 16:01:57 +01:00
Qu Wenruo c772db30e9 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>
2018-02-02 16:01:57 +01:00
Qu Wenruo 53b8ae1436 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>
2018-02-02 16:01:57 +01:00
Gu Jinxiang 4665484f5f 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>
2018-02-02 16:01:57 +01:00
Gu Jinxiang f1bc621846 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>
2018-02-02 16:01:57 +01:00
Gu Jinxiang 0de16cc4a0 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>
2018-02-02 16:01:57 +01:00
Gu Jinxiang 8bcac688be 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>
2018-02-02 16:01:57 +01:00
Gu Jinxiang c958110785 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>
2018-02-02 16:01:57 +01:00