Commit Graph

232 Commits (de34a33a8204af9e675e5247c88eb727955beae1)

Author SHA1 Message Date
Nikolay Borisov de34a33a82 btrfs-progs: Remove btrfs-debug-tree command
There is already a replacement in the face of btrfs inspect-internal
dump-tree. And this command is just a simple wrapper around it. Just
remove it and adjust the show-blocks script to call the main btrfs
binary to achieve the same effect.

Informally deprecated since 4.4.

Issue: #97
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-24 13:00:10 +02:00
Peter Kjellerstedt 6cedd68811 btrfs-progs: build: Do not use cp -a to install library links
Using cp -a to install files will preserve the ownership of the original
files (if possible), which is typically not wanted. E.g. if the files
were built by a normal user, but are being installed by root, then the
installed files would maintain the UIDs/GIDs of the user that built the
files rather than be owned by root.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-06 15:06:50 +02:00
Omar Sandoval 7cdd58b2e9 libbtrfsutil: always build libbtrfsutil.so.$MAJOR
Otherwise, make test-libbtrfsutil from a fresh checkout fails.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:54:51 +02:00
Omar Sandoval 660adc0e1c libbtrfsutil: use local mkfs.btrfs for tests if it exists
The system might not have mkfs installed at all.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:54:41 +02:00
Lu Fengqi 3fd6a955f9 btrfs-progs: build: modify cscope/ctags rules to include directories such as check
Modify cscope/ctags rule to include directories such as check/
libbtrfsutil/kernel-lib/kernel-shared.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba e0d173c6c4 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>
2018-03-06 11:28:37 +01:00
Omar Sandoval 92d4035074 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>
2018-03-06 11:28:36 +01:00
Omar Sandoval 9615c23d15 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>
2018-02-24 01:37:17 +01:00
Omar Sandoval bad4208da3 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>
2018-02-24 01:37:17 +01:00
Omar Sandoval 23c01b3c1b 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>
2018-02-24 01:37:17 +01:00
Omar Sandoval 502e2a3510 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>
2018-02-24 01:37:16 +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
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 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 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 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 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
David Sterba 2e1932e6a3 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>
2018-01-31 15:14:01 +01:00
Gu Jinxiang 60fa9e945f 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>
2018-01-08 19:25:05 +01:00
Hans van Kranenburg 9303f1dd1b 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>
2018-01-08 18:18:29 +01:00
Qu Wenruo 075580471e 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>
2018-01-08 18:11:24 +01:00
David Sterba ea085932dc btrfs-progs: image: move sanitization to new file
Signed-off-by: David Sterba <dsterba@suse.com>
2017-11-14 15:59:00 +01:00
David Sterba af524c9539 btrfs-progs: build: use variables for btrfs-image images
More separate sources will be created for btrfs-image.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-11-14 15:59:00 +01:00
Naohiro Aota 0792c17028 btrfs-progs: build: set include path relatively
Currently, gcc is passed the include directory with full path. As a result,
dependency files (*.o.d) also record the full path at the build time. Such
full path dependency is annoying for sharing the source between multiple
machines, containers, or anything the path differ.

And this is the same way what other program using autotools e.g. e2fsprogs
is doing:

$ grep top_builddir Makefile
top_builddir = .
CPPFLAGS = -I. -I$(top_builddir)/lib -I$(top_srcdir)/lib
BUILD_CFLAGS = -g -O2  -I. -I$(top_builddir)/lib -I$(top_srcdir)/lib -DHAVE_CONFIG_H
<snip>

Signed-off-by: Naohiro Aota <naota@elisp.net>
[ set TOPDIR=. instead of -I as discussed, does not harm linker ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-13 20:16:01 +02:00
David Sterba aafb4593fe btrfs-progs: build: add absolute path for topdir
We'll need TOPDIR to be ./ but library-test is intentionally built
outside of the git repository so we need to make them separate.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-13 20:15:58 +02:00
David Sterba 15beadeaa2 btrfs-progs: build: add more sparse warning checks
- declarations after statements (style issue)
- bitfields without defined signedness

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:18:44 +02:00
David Sterba 5d57bdeb23 btrfs-progs: build: use -std=gnu89 for sparse
Sparse does not seem to support gnu90 that we'd like to keep for the
regular build. Use gnu89 for C=1 build.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:18:40 +02:00
David Sterba 4498f53707 btrfs-progs: build: add missing defines for the C=1 build
Sparse complains that BTRFSCONVERT_EXT2 and _RESIERFS are not defined.
The per-target options are missing from the default CFLAGS and only
added in the specific rule.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:18:37 +02:00
Naohiro Aota 3efd322db2 btrfs-progs: build: omit unnecessary -MD flag
According to gcc(1), "-MD is equivalent to -M -MF file, except that -E is not
implied." Since the rule in the Makefile is just generating dependency file
and not building object file, it is no use to have "-MD" here. Also, it's
overridden and conflicting with the following "-MM" flag. I guess we can drop
it.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:17:45 +02:00
Naohiro Aota fd8c78a47c btrfs-progs: build: generate all dependency files
We're missing several dependency files like:

$ diff -u <(find -name '*.o'|cut -d. -f2|sort) <(find -name '*.o.d'|cut -d. -f2|sort)
@@ -3,7 +3,6 @@
 /btrfs-corrupt-block
 /btrfs-debug-tree
 /btrfs-find-root
-/btrfs-list
 /btrfs-map-logical
 /btrfs-select-super
 /btrfstune
@@ -29,11 +28,6 @@
 /cmds-scrub
 /cmds-send
 /cmds-subvolume
-/convert/common
-/convert/main
-/convert/source-ext2
-/convert/source-fs
-/convert/source-reiserfs
 /ctree
 /dir-item
 /disk-io
<snip>

This is due to moving things out of objects and cmds_objects variables. Such
missing dependency files cause mis-building of some source files (try touch
utils.h; make mkfs/main.o).

This patch introduce a new variable "all_objects" to keep all the objects and
use the variable to generate proper dependency file building rules.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:17:42 +02:00
David Sterba bcaadc2e49 btrfs-progs: build: whitespace adjustment of [LD] fssum
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:17:35 +02:00
Nick Terrell 717a8b1e5d btrfs-progs: Add zstd support
Adds zstd support to the btrfs program. An optional dependency on libzstd
>= 1.0.0 is added. Autoconf accepts `--enable-zstd' or `--disable-zstd' and
defaults to detecting if libzstd is present using `pkg-config'.

The patch is also available in my fork of btrfs-progs [1], which passes
Travis-CI with the new tests. The prebuilt binary is available there.

I haven't updated Android.mk.

[1] https://github.com/terrelln/btrfs-progs/tree/devel

Signed-off-by: Nick Terrell <terrelln@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:17:13 +02:00
David Sterba 37c271b216 btrfs-progs: move transaction implementation out of header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba a31458b966 btrfs-progs: build: fix asan and ubsan build
Probably with a new gcc (7.1.1) I started to see asan/ubsan link failures.
Fixed by explicitly linking the libraries.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 2e5617c9a6 btrfs-progs: build: fix building libbtrfs.so with tsan
Except libbtrfs.so object, all other tools compile fine. The error is:

ld: send-stream.o: relocation R_X86_64_PC32 against symbol
`stderr@@GLIBC_2.2.5' can not be used when making a shared object;
recompile with -fPIC

Compiling with -fPIC fixes the problem.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba b8c9c457c1 btrfs-progs: build: properly pass the LDFLAGS during tsan build
The variable LD_FLAGS does not exist and the flags are not used, we need
to use the newly added internal debugging linker flags.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 339019c934 btrfs-progs: build: add internal LDFLAGS for the D= features
We might want to pass additional linker flags for various sanitization
features.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 5d8b645f6f btrfs-progs: build: fix PIE build
Patch from Marcus Meissner <meissner@suse.com>. The CFLAGS are passed to
the linker and mix up the compilation and linker flags for PIE support.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Jeff Mahoney 99340c2ef7 btrfs-progs: convert: add support for converting reiserfs
This patch adds support to convert reiserfs file systems in-place to btrfs.

It will convert extended attribute files to btrfs extended attributes,
translate ACLs, coalesce tails that consist of multiple items into one item,
and convert tails that are too big into indirect files.

This requires that libreiserfscore 3.6.27 be available.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Qu Wenruo cd30857ceb btrfs-progs: Specify C standard to gnu90 explicitly
Different C compilers have different default language standard.
This sometimes causes problem on different system.

For distribution like CentOS/RHEL7, its gcc is still 4.8 and will report
error for c90 style declaration, while most developers are using newer
gcc which will just ignore it.
This makes us hard to detect such language standard problem.

This patch will specify standard to gnu90 explicitly to avoid such problem.
Gnu90 is a good mix of c90 while provide a lot of useful gnu extension,
and is supported by all modern gcc and clang.

Reported-by: Marco Lorenzo Crociani <marcoc@prismatelecomtesting.com>
Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-08-24 19:06:33 +02:00
David Sterba f929b62ae8 btrfs-progs: build: do not regenerate kernel-lib/tables.c
As reported in
https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg66765.html
cross-compilation does not work very well with current tables.c. We can
simpy keep the pergenerated file in the repository and update if needed.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-08-24 19:06:12 +02:00
Adam Buchbinder 18aed6a623 btrfs-progs: build: Enable ThreadSanitizer, using D=tsan
Tested with clang-3.9. We have to enable PIE,
(https://clang.llvm.org/docs/ThreadSanitizer.html)

Signed-off-by: Adam Buchbinder <abuchbinder@google.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-20 17:43:43 +02:00
Adam Buchbinder 50d037b459 btrfs-progs: tests: Fix missing internal deps in check and misc tests
Doing a straight 'make test' would fail because some misc and fsck
tests require particular tools to already be built. Add dependencies
at the Makefile and shell-script level.

Signed-off-by: Adam Buchbinder <abuchbinder@google.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-20 17:43:43 +02:00
Qu Wenruo 9604ce49d6 btrfs-progs: raid56: Allow raid6 to recover 2 data stripes
Copied from kernel lib/raid6/recov.c raid6_2data_recov_intx1() function.
With the following modification:
- Rename to raid6_recov_data2() for shorter name
- s/kfree/free/g modification

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 084d152407 btrfs-progs: raid56: Introduce tables for RAID6 recovery
Use kernel RAID6 galois tables for later RAID6 recovery.

Galois tables file, kernel-lib/tables.c is generated by user space
program, mktable.

Galois field tables declaration, in kernel-lib/raid56.h, is completely
copied from kernel.

The mktables.c is copied from kernel with minor header/macro
modification, to ensure the generated tables.c works well in
btrfs-progs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 5e2a2acc9a btrfs-progs: raid56: Introduce raid56 header for later recovery usage
Introduce a new header, kernel-lib/raid56.h, for later raid56 works.

It contains 2 functions, from original btrfs-progs code:
void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs);
int raid5_gen_result(int nr_devs, size_t stripe_len, int dest, void **data);

Will be expanded later and some part of it(RAID6 recover part) may keep
sync with kernel later.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ unify gpl header, rename header macro ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00