Commit Graph

85 Commits

Author SHA1 Message Date
David Sterba
73efc566d5 btrfs-progs: kerncompat: hide definition of __init
As kerncompat.h is included from all libbtrfs headers we must be careful
about generic names like __init, in this case it breaks build of
snapper.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-01-03 17:24:36 +01:00
Josef Bacik
788a71c16a btrfs-progs: sync compression.h from the kernel
This patch copies in compression.h from the kernel.  This is relatively
straightforward, we just have to drop the compression types definition
from ctree.h, and update the image to use BTRFS_NR_COMPRESS_TYPES
instead of BTRFS_COMPRESS_LAST, and add a few things to kerncompat.h to
make everything build smoothly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-30 19:14:29 +01:00
Jeff Mahoney
8d1c854094 btrfs-progs: qgroup: add path to show output
The 'btrfs qgroup show' command currently only prints qgroup IDs,
forcing the user to resolve which subvolume each corresponds to.

Adds subvolume path resolution to 'qgroup show' so that when
the -P option is used, the last column contains the pathname of
the root of the subvolume it describes.  In the case of nested
qgroups, it will show the number of member qgroups or the paths
of the members if the -v option is used.

Path can also be used as a sort parameter.

Sample output:

qgroupid         rfer         excl       path
--------         ----         ----       ----
0/5          16.00KiB     16.00KiB   <FS_ROOT>
0/256        16.00KiB     16.00KiB   <FS_ROOT>/subv1
0/257        16.00KiB     16.00KiB   <missing>
0/258        16.00KiB     16.00KiB   <FS_ROOT>/subv3
0/259        16.00KiB     16.00KiB   <FS_ROOT>/snap1

Pull-request: #139
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:12:24 +02:00
Wang Yugui
588429caf9 btrfs-progs: kerncompat: avoid redefined __bitwise__ warning
Compile warning:

    ./kerncompat.h:142: warning: "__bitwise__" redefined
    #define __bitwise__

    In file included from ./kerncompat.h:35,
                    from check/qgroup-verify.c:24:
    /usr/include/linux/types.h:25: note: this is the location of the previous definition
    #define __bitwise__ __bitwise

Because  __bitwise__ is already defined in newer kernel-headers
(/usr/include/linux/types.h), so add #ifndef to avoid this warning.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:12 +02:00
David Sterba
63e0f3b39c btrfs-progs: kernel-lib: make headers C++ compatible
The snapper build fails due to updates to kernel-lib files, the type
casts do not work the same way in C++. Simplify READ_ONCE/WRITE_ONCE
even more, drop use of 'new' as identifier.

Issue: https://github.com/openSUSE/snapper/issues/725
Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:47:53 +02:00
David Sterba
2b603d9819 btrfs-progs: kernel-lib: add simplified READ_ONCE and WRITE_ONCE
For easier source synchronization with kernel, add the _ONCE wrappers,
but only the simplified version as we don't do any lock-less
algorithms or use the semantics in userspace.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-05-12 12:43:27 +02:00
Rosen Penev
56760e8dca btrfs-progs: fix 64-bit mips and powerpc types
The kernel uses 'unsigned long' for u64 specifically for ppc64 and
mips64.

Remove asm/types.h include as it will get included properly later.

Fixe -Wformat warnings.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-16 22:44:58 +01:00
David Sterba
9ed0aadb63 btrfs-progs: kerncompat: add local definition for alignment macros
There's still problem left with compilation on musl and kernel < 5.11,
because __ALIGN_KERNEL is not defined anymore:

../bin/ld: kernel-shared/volumes.o: in function `create_chunk':
volumes.c:(.text+0x17f8): undefined reference to `__ALIGN_KERNEL'

Due to the entangled includes and unconditional definition of
__ALIGN_KERNEL, we can't use #ifdef in kerncompat.h to define it
eventually (as kerncompat.h is the first include). Instead add local
definitions of the macros and rename them to avoid name clashes.

Pull-request: #433
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:40:51 +01:00
Fabrice Fontaine
a2511aaa85 btrfs-progs: include sys/sysinfo.h conditionally on musl
Make inclusion of sys/sysinfo.h conditional to avoid the following build
failure on musl:

In file included from .../i586-buildroot-linux-musl/sysroot/usr/include/linux/kernel.h:4,
                 from ./kerncompat.h:31,
                 from common/utils.c:42:
.../i586-buildroot-linux-musl/sysroot/usr/include/linux/sysinfo.h:7:8: error: redefinition of 'struct sysinfo'
    7 | struct sysinfo {
      |        ^~~~~~~
In file included from common/utils.c:27:
.../i586-buildroot-linux-musl/sysroot/usr/include/sys/sysinfo.h:10:8: note: originally defined here
   10 | struct sysinfo {
      |        ^~~~~~~

Fixes:
 - http://autobuild.buildroot.org/results/16f44fb9dea72a7079e8e5517e760dd79d2724cc

The 'struct sysinfo' is defined in linux/sysinfo.h and sys/sysinfo.h,
while both must not be included at the same time. Stop including
linux/kernel.h that sometimes unconditionally includes sys/sysinfo.h and
causes the double definition for some reason. As we now include
linux/const.h directly, there's no other effective change.

Pull-request: #433
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-01-10 19:35:28 +01:00
Bruce Ashfield
b28f7bd9bb btrfs-progs: include linux/const.h to fix build with 5.12+ headers
btrfs-tools compile fails with mips, musl and 5.12+ headers.

The definition of __ALIGN_KERNEL has moved in 5.12+ kernels, so we
add an explicit include of const.h to pickup the macro:

  | make: *** [Makefile:595: mkfs.btrfs] Error 1
  | make: *** Waiting for unfinished jobs....
  | libbtrfs.a(volumes.o): in function `dev_extent_search_start':
  | /usr/src/debug/btrfs-tools/5.12.1-r0/git/kernel-shared/volumes.c:464: undefined reference to `__ALIGN_KERNEL'
  | collect2: error: ld returned 1 exit status

This is safe for older kernel's as well, since the header still
exists, and is valid to include.

Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
[remove invalid OE Upstream-status]
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-01-04 16:56:33 +01:00
David Sterba
38254c4934 btrfs-progs: kerncompat: add const_ilog2
The newly added zoned mode constants can utilize the const ilog2
version. Copy it from kernel include/linux/log2.h.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:46 +02:00
Naohiro Aota
b031fe84fd btrfs-progs: zoned: implement zoned chunk allocator
Implement a zoned chunk and device extent allocator. One device zone
becomes a device extent so that a zone reset affects only this device
extent and does not change the state of blocks in the neighbor device
extents.

To implement the allocator, we need to extend the following functions for
a zoned filesystem:

  - init_alloc_chunk_ctl
  - dev_extent_search_start
  - dev_extent_hole_check
  - decide_stripe_size

Here, dev_extent_hole_check() is newly introduced to check the validity of
a hole found.

init_alloc_chunk_ctl_zoned() is mostly the same as regular one. It always
set the stripe_size to the zone size and aligns the parameters to the zone
size.

dev_extent_search_start() only aligns the start offset to zone boundaries.
We don't care about the first 1MB like in regular filesystem because we
anyway reserve the first two zones for superblock logging.

dev_extent_hole_check_zoned() checks if zones in given hole are either
conventional or empty sequential zones. Also, it skips zones reserved for
superblock logging.

With the change to the hole, the new hole may now contain pending extents.
So, in this case, loop again to check that.

Finally, decide_stripe_size_zoned() should shrink the number of devices
instead of stripe size because we need to honor stripe_size == zone_size.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:45 +02:00
Naohiro Aota
8ef9313cf2 btrfs-progs: zoned: implement log-structured superblock
Superblock (and its copies) is the only data structure in btrfs which has a
fixed location on a device. Since we cannot overwrite in a sequential write
required zone, we cannot place superblock in the zone.  One easy solution
is limiting superblock and copies to be placed only in conventional zones.

However, this method has two downsides: one is reduced number of superblock
copies. The location of the second copy of superblock is 256GB, which is in
a sequential write required zone on typical devices in the market today.
So, the number of superblock and copies is limited to be two.  Second
downside is that we cannot support devices which have no conventional zones
at all.

To solve these two problems, we employ superblock log writing. It uses two
adjacent zones as a circular buffer to write updated superblocks.  Once the
first zone is filled up, start writing into the second one.  Then, when
both zones are filled up and before starting to write to the first zone
again, reset the first zone.

We can determine the position of the latest superblock by reading write
pointer information from a device. One corner case is when both zones are
full. For this situation, we read out the last superblock of each zone, and
compare them to determine which zone is older.

The following zones are reserved as the circular buffer on ZONED btrfs.

- primary superblock: offset   0B (and the following zone)
- first copy:         offset 512G (and the following zone)
- Second copy:        offset   4T (4096G, and the following zone)

If these reserved zones are conventional, superblock is written fixed at
the start of the zone without logging.

Currently, superblock reading/writing is done by pread/pwrite. This
commit replace the call sites with sbread/sbwrite to wrap the functions.
For zoned btrfs, btrfs_sb_io which is called from sbread/sbwrite
reverses the IO position back to a mirror number, maps the mirror number
into the superblock logging position, and do the IO.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:45 +02:00
Naohiro Aota
49d5ce4d0f btrfs-progs: zoned: allow zoned filesystems on non-zoned block devices
Run a zoned filesystem on non-zoned devices. This is done by "slicing
up" the block device into fixed-sized chunks and emulate a conventional
zone on each of them. The emulated zone size is determined from the size
of device extent.

This is mainly aimed at testing of zoned filesystems, i.e. the zoned
chunk allocator, on regular block devices.

Currently, we always use EMULATED_ZONE_SIZE (256MiB) for the emulated
zone size. In the future, this will be customized by mkfs option.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:45 +02:00
Naohiro Aota
384840b9c0 btrfs-progs: zoned: get zone information of zoned block devices
Get the zone information (number of zones and zone size) from all the
devices, if the volume contains a zoned block device. To avoid costly
run-time zone report commands to test the device zones type during block
allocation, it also records all the zone status (zone type, write
pointer position, etc.).

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:45 +02:00
Naohiro Aota
c6b585034f btrfs-progs: mark BUG() as unreachable
Marking BUG() unreachable helps us silence unnecessary warnings e.g.
"warning: control reaches end of non-void function [-Wreturn-type]" like
the code below.

   int foo()
   {
   ...
   	if (XXX)
   		return 0;
	else if (YYY)
		return 1;
   	else
   		BUG();
   }

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-04-16 19:34:07 +02:00
Rosen Penev
5d72055066 btrfs-progs: Fix printf formats
Discovered with cppcheck. Fix signed/unsigned int mismatches, sizeof and
long formats.

Pull-request: #197
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:31:05 +02:00
Fabrice Fontaine
4b3e22e988 btrfs-progs: kerncompat: define BTRFS_DISABLE_BACKTRACE when building with uClibc
uClibc does not provide backtrace() nor <execinfo.h>. When building
btrfs-progs, passing --disable-backtrace is enough to make it build with
uClibc. But once btrfs-progs is installed and another program/library
includes kerncompat.h, it fails to build with uClibc, because
BTRFS_DISABLE_BACKTRACE is not defined.

The most correct fix for this would be to have kerncompat.h generated
from kerncompat.h.in during the btrfs-progs build process, and tuned
depending on autoconf/automake variables. But as a quick fix that
follows the current strategy, we simply tweak the existing __GLIBC__
conditional. Indeed, uClibc pretends to be glibc and defines __GLIBC__,
but it does not replace it completely, hence the need to define
BTRFS_DISABLE_BACKTRACE when __GLIBC__ is not defined *or* when
__UCLIBC__ is defined.

Pull-request: #206
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
[Retrieved from: https://git.buildroot.net/buildroot/tree/package/btrfs-progs/0002-kerncompat.h-define-BTRFS_DISABLE_BACKTRACE-when-bui.patch]
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:29:41 +02:00
David Sterba
0a688a4454 btrfs-progs: kerncompat: define __always_inline conditionally
The CI build prints a lot of warnings

      [CC]     btrfs.o
  In file included from volumes.h:22,
		   from btrfs.c:22:
  kerncompat.h:39: warning: "__always_inline" redefined
   #define __always_inline __inline __attribute__ ((__always_inline__))

so define the macro conditionally.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba
d96671ae54 btrfs-progs: kerncompat: rename swap to __swap
The 'swap' is too generic and clashes with some userspace tools that
compile against btrfs, eg. snapper when including
boost::smart_ptr::scoped_array after kerncompat.h:

  /usr/include/boost/smart_ptr/scoped_array.hpp:127:13: error: macro "swap" requires 2 arguments, but only 1 given
  a.swap(b);

Signed-off-by: David Sterba <dsterba@suse.com>
2018-11-13 13:33:15 +01:00
Nikolay Borisov
8c028efe4a btrfs-progs: Pull free space tree related code from kernel
To help implement free space tree checker in user space some kernel
function are necessary, namely iterating/deleting/adding freespace
items, some internal search functions. Functions to populate a block
group based on the extent tree. The code is largely copy/paste from
the kernel with locking eliminated (i.e free_space_lock). It supports
reading/writing of both bitmap and extent based FST trees.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11:39 +02:00
Nikolay Borisov
c6039704c5 btrfs-progs: Add delayed refs infrastructure
This commit pulls those portions of the kernel implementation of
delayed refs which are necessary to have them working in user-space.
I've done the following modifications:

1. Replaced all kmem_cache_alloc calls to kmalloc.

2. Removed all locking-related code, since we are single threaded in
   userspace.

3. Removed code which deals with data refs - delayed refs in user space
   are going to be used only for cowonly trees.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-23 14:48:41 +02:00
Qu Wenruo
1d1e2ef6bf btrfs-progs: kerncompat: Fix re-definition of __bitwise
In latest linux api headers, __bitwise is already defined in
/usr/include/linux/types.h.

So kerncompat.h will re-define __bitwise, and cause gcc warning.

Fix it by checking if __bitwise is already define.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-16 17:40:35 +01:00
David Sterba
df32b5fa22 btrfs-progs: kerncompat: print trace from ASSERT, if enabled
Commit bc2d4ccc46 "btrfs-progs:
kerncompat: disconnect assert and warning messages" forgot to add the
print_trace call to assert_trace.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
David Sterba
6b62b76470 btrfs-progs: kerncompat: simplify warning_trace
The value of assertion is always set.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:48:25 +01:00
David Sterba
bc2d4ccc46 btrfs-progs: kerncompat: disconnect assert and warning messages
The assertion and warn/bug have reversed condition checks, using the
same helpers drops the exact value, so we'll print the message directly
without the helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:48:23 +01:00
David Sterba
eb6e3d6518 btrfs-progs: kerncompat: pass exact condition value from ASSERT
Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:48:17 +01:00
David Sterba
be5e0b230c btrfs-progs: kerncompat: add separate trace print for BUG_ON
We want to pass unmodified condition down to the handlers so we can't
use assert_trace for that purpose.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:48:15 +01:00
Qu Wenruo
5826f1e9ff btrfs-progs: Fix disable backtrace assert error
Due to commit 00e769d04c2c83029d6c71(btrfs-progs: Correct value printed
by assertions/BUG_ON/WARN_ON), which changed the assert_trace()
parameter, the condition passed to assert/WARN_ON/BUG_ON are logical
notted for backtrace enabled and disabled case.

Such behavior makes us easier to pass value wrong, and in fact it did
cause us to pass wrong condition for ASSERT().

Instead of passing different conditions for ASSERT/WARN_ON/BUG_ON()
manually, this patch will use ASSERT() to implement the resting
ASSERT/WARN_ON/BUG() for disable backtrace case, and use assert_trace()
to implement ASSERT() and BUG_ON(), to allow them to print correct
value.

Also, move WARN_ON() out of the ifdef branch, as it's completely the
same for both branches.

Cc: Goldwyn Rodrigues <rgoldwyn@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:48:13 +01:00
Qu Wenruo
e0485281ed btrfs-progs: Fix NULL pointer when receive clone operation
Regression introduced by a2f7af94ab
"btrfs-progs: subvol_uuid_search: return error encoded pointer"
IS_ERR() will only check if it's an error code, won't check if it's
NULL.  And for all the caller the commit modifies, it can return NULL
and makes cause segfault.

Fix it by introducing new IS_ERR_OR_NULL() macro, and for NULL pointer
and needs to return int case, convert NULL pointer to -ENOENT.

Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-21 16:29:06 +01:00
Goldwyn Rodrigues
4927705d6f btrfs-progs: Remove duplicate printfs in warning_trace()/assert_trace()
Code reduction. Call warning_trace from assert_trace in order to
reduce the printf's used. Also, trace variable in warning_trace()
is not required because it is already handled by BTRFS_DISABLE_BACKTRACE.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:35 +01:00
Goldwyn Rodrigues
dd2c2a4c67 btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON
The values passed to BUG_ON/WARN_ON are negated(!) and printed, which
results in printing the value zero for each bug/warning. For example:
volumes.c:988: btrfs_alloc_chunk: Assertion `ret` failed, value 0

This is not useful. Instead changed to print the value of the parameter
passed to BUG_ON()/WARN_ON(). The value needed to be changed to long
to accomodate pointers being passed.

Also, consolidated assert() and BUG() into ifndef.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:35 +01:00
David Sterba
5aade6f9c3 btrfs-progs: ioctl: make build-time structure size checks optional
Temporarily make the build checks optional. The structure sizes could
change on arches due to alignment requirements or padding inserted into
the structures. We need more extensive tests to make sure we'd not break
ioctls.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-10 10:11:31 +02:00
Qu Wenruo
bb5bcb8a4a btrfs-progs: Fix warning_trace compile error if backtrace is disabled
If we disable backtrace, btrfs-progs can't be compiled since we don't
have warning_trace defined.

Fix by move it out of #ifndef BTRFS_DISABLE_BACKTRACE block.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ move warning_trace to the right place ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-10 09:46:42 +02:00
David Sterba
c8d9f05cec btrfs-progs: kerncompat: add build-time assertion support
Macro to verify compile-time conditions, like sie of structures or
types.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
David Sterba
dabfc65124 btrfs-progs: kerncompat: call abort at the end of assert_trace
The assert* helpers should not exit normally, mimick the behaviour of
the std library assert.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
David Sterba
26619538da btrfs-progs: kerncompat: make WARN_ON more verbose
Curretnly WARN_ON would crash but that's not it's purpose. Add helper
that prints the warning, optionally with trace.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
David Sterba
9adce1abe4 btrfs-progs: print value when assertion fails
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
David Sterba
1c47e5b039 btrfs-progs: kerncompat: introduce put_unaligned_x helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
Omar Sandoval
1d6c7cb725 btrfs-progs: fix btrfsck of space_cache=v2 bitmaps on big-endian
Copy le_test_bit() from the kernel and use that for the free space tree
bitmaps.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-26 18:35:05 +02:00
David Sterba
5e975516b9 btrfs-progs: fix type mismatch in backtrace dumping functions
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba
a6ffadee7b btrfs-progs: kerncompat: introduce get_unaligned helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-11 15:53:16 +02:00
Ondrej Kozina
5d23b6a7b0 btrfs-progs: libbtrfs: remove max/min macros from API
kerncompat.h header file is part of libbtrfs API. min/max macros cause
conflict while building projects dependant on libbtrfs. Moving those
macros to btrfs-progs internal header file fixes the conflict.

Signed-off-by: Ondrej Kozina <okozina@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
Qu Wenruo
61d6ed4fe7 btrfs-progs: Enhance chunk validation check
Enhance chunk validation:
1) Num_stripes
   We already have such check but it's only in super block sys chunk
   array.
   Now check all on-disk chunks.

2) Chunk logical
   It should be aligned to sector size.
   This behavior should be *DOUBLE CHECKED* for 64K sector size like
   PPC64 or AArch64.
   Maybe we can found some hidden bugs.

3) Chunk length
   Same as chunk logical, should be aligned to sector size.

4) Stripe length
   It should be power of 2.

5) Chunk type
   Any bit out of TYPE_MAS | PROFILE_MASK is invalid.

With all these much restrict rules, several fuzzed image reported in
mail list should no longer cause btrfsck error.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:04 +01:00
Brendan Heading
38c5382e3f btrfs-progs: compilation errors when using musl libc
- limits.h must be included to pick up PATH_MAX.
- remove double declaration of BTRFS_DISABLE_BACKTRACE

kerncompat.h assumed that if __GLIBC__ was not defined,
it could safely define BTRFS_DISABLE_BACKTRACE, however this can be
defined by the configure script. Added a check to ensure it is not
defined first.

Signed-off-by: Brendan Heading <brendanheading@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:11 +02:00
David Sterba
07ce7005fc btrfs-progs: unify header file inclusion protections
There are missing ifdefs or defines with very generic names.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-21 17:49:26 +01:00
Merlijn Wajer
54498f9a14 btrfs-progs: restore backtrace functionality on glibc
Originally broke in commit c2691f807d

__glibc__ should have been __GLIBC__

We also include features.h ; although most includes (at least stdlib.h)
typically already include it -- at least on glibc, where it matters.

Signed-off-by: Merlijn Wajer <merlijn@wizzup.org>
Reported-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-14 15:12:05 +01:00
Merlijn Wajer
c2691f807d btrfs-progs: disable backtrace and define __always_inline
Disable backtrace and define __always_inline when glibc is not used as
libc. This, together with some header changes allows btrfs-progs to
compile with musl-libc.

Signed-off-by: Merlijn Wajer <merlijn@wizzup.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-18 18:28:34 +01:00
Karel Zak
7a9fcccfd2 btrfs-progs: fix typedef
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-17 15:13:47 +01:00
Josef Bacik
2ba12173d5 Btrfs-progs: update rbtree libs
While debugging a broken fs we were seeing hangs in the rb_erase loops.  The
rbtree was simple and wasn't corrupted so it appeared to be a bug in our rbtree
library.  Updating to the kernels latest rbtree code made the infinite loop go
away, so pull it back.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-10-14 10:39:40 +02:00