summaryrefslogtreecommitdiff
path: root/kerncompat.h
Commit message (Collapse)AuthorAge
* btrfs-progs: kerncompat: rename swap to __swapDavid Sterba2018-11-13
| | | | | | | | | | | 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>
* btrfs-progs: Pull free space tree related code from kernelNikolay Borisov2018-10-25
| | | | | | | | | | | | 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>
* btrfs-progs: Add delayed refs infrastructureNikolay Borisov2018-10-23
| | | | | | | | | | | | | | | | | 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>
* btrfs-progs: kerncompat: Fix re-definition of __bitwiseQu Wenruo2017-03-16
| | | | | | | | | | | | 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>
* btrfs-progs: kerncompat: print trace from ASSERT, if enabledDavid Sterba2017-03-08
| | | | | | | | Commit bc2d4ccc46e2807964c74ce805fb6405ca2bc842 "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>
* btrfs-progs: kerncompat: simplify warning_traceDavid Sterba2017-01-25
| | | | | | The value of assertion is always set. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: kerncompat: disconnect assert and warning messagesDavid Sterba2017-01-25
| | | | | | | | 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>
* btrfs-progs: kerncompat: pass exact condition value from ASSERTDavid Sterba2017-01-25
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: kerncompat: add separate trace print for BUG_ONDavid Sterba2017-01-25
| | | | | | | 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>
* btrfs-progs: Fix disable backtrace assert errorQu Wenruo2017-01-25
| | | | | | | | | | | | | | | | | | | | | | | 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>
* btrfs-progs: Fix NULL pointer when receive clone operationQu Wenruo2016-12-21
| | | | | | | | | | | | | | | | Regression introduced by a2f7af94abe4a3491ca1280a2ae1d63edc0d62ab "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>
* btrfs-progs: Remove duplicate printfs in warning_trace()/assert_trace()Goldwyn Rodrigues2016-12-14
| | | | | | | | | 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>
* btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ONGoldwyn Rodrigues2016-12-14
| | | | | | | | | | | | | | | 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>
* btrfs-progs: ioctl: make build-time structure size checks optionalDavid Sterba2016-10-10
| | | | | | | | | 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>
* btrfs-progs: Fix warning_trace compile error if backtrace is disabledQu Wenruo2016-10-10
| | | | | | | | | | | 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>
* btrfs-progs: kerncompat: add build-time assertion supportDavid Sterba2016-10-05
| | | | | | | Macro to verify compile-time conditions, like sie of structures or types. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: kerncompat: call abort at the end of assert_traceDavid Sterba2016-10-05
| | | | | | | The assert* helpers should not exit normally, mimick the behaviour of the std library assert. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: kerncompat: make WARN_ON more verboseDavid Sterba2016-10-05
| | | | | | | 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>
* btrfs-progs: print value when assertion failsDavid Sterba2016-10-05
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: kerncompat: introduce put_unaligned_x helpersDavid Sterba2016-07-28
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix btrfsck of space_cache=v2 bitmaps on big-endianOmar Sandoval2016-07-26
| | | | | | | | 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>
* btrfs-progs: fix type mismatch in backtrace dumping functionsDavid Sterba2016-06-01
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: kerncompat: introduce get_unaligned helpersDavid Sterba2016-05-11
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: libbtrfs: remove max/min macros from APIOndrej Kozina2016-03-14
| | | | | | | | | 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>
* btrfs-progs: Enhance chunk validation checkQu Wenruo2016-01-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* btrfs-progs: compilation errors when using musl libcBrendan Heading2015-08-31
| | | | | | | | | | | | | - 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>
* btrfs-progs: unify header file inclusion protectionsDavid Sterba2015-01-21
| | | | | | There are missing ifdefs or defines with very generic names. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore backtrace functionality on glibcMerlijn Wajer2015-01-14
| | | | | | | | | | | | | Originally broke in commit c2691f807ddd2c6b261c5707f6838a45d9275390 __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>
* btrfs-progs: disable backtrace and define __always_inlineMerlijn Wajer2014-12-18
| | | | | | | | | 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>
* btrfs-progs: fix typedefKarel Zak2014-12-17
| | | | | Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: update rbtree libsJosef Bacik2014-10-14
| | | | | | | | | | 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>
* Btrfs-progs: pull back backref.c and fix it upJosef Bacik2014-10-14
| | | | | | | | | This patch pulls back backref.c, adds a couple of helpers everywhere that it needs, and cleans up backref.c to fit in btrfs-progs. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> [removed free_some_buffers after "do not reclaim extent buffer"] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add option to disable backtrace usageGustavo Zacarias2014-10-10
| | | | | | | | | | | | This commit adds the support for a make variable named "DISABLE_BACKTRACE" which allows to disable the support for backtrace() usage on ASSERT(), BUG() and BUG_ON() calls. This is useful because some alternative C libraries like uClibc have optional support for backtrace() which is rarely built when debugging isn't taking place. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: make BUG*() be more verboseJosef Bacik2014-10-01
| | | | | | | | | | | | Currently these macros just tie to assert(), which gives us line number and such but no backtrace so no actual context. This patch adds support for spitting out a backtrace so we can see how we got to the given assert. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> [backtrace_symbols_fd] Signed-off-by: Naohiro Aota <naota@elisp.net> [minor fixups] Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fix some build warnings on 32bit platformWang Shilong2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fix following build warnings on 32bit platform: ... utils.c:1708:3: warning: left shift count >= width of type [enabled by default] if (x << i & (1UL << 63)) ^ qgroup-verify.c:393:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] return (struct tree_block *)unode->aux; ^ qgroup-verify.c:407:38: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] if (ulist_add(tree_blocks, bytenr, (unsigned long long)block, 0) >= 0) ^ cmds-restore.c:120:4: warning: format %lu expects argument of type long unsigned int, but argument 3 has type size_t [-Wformat=] fprintf(stderr, "bad compress length %lu\n", in_len); ... BTW, this patch also switches other castings with new helpers. Signed-off-by: Wang Shilong <wangshilong1991@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: import ulistMark Fasheh2014-08-22
| | | | | | | qgroup-verify.c wants this for walking root refs. Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Change BUG() to use assert.Mitch Harder2014-03-21
| | | | | | | | | Change the definition of BUG() to use assert instead of abort to provide information about the location of the issue. Signed-off-by: Mitch Harder <mitch.harder@sabayonlinux.org> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: get C=1 sparse checking working againZach Brown2013-09-03
| | | | | | | | | | | | | | | | | | | | | | | | | | There were a few problems that were breaking sparse checking: - We were defining CHECK_ENDIAN late in the environment, after linux/fs.h has been included which defines __force and __bitwise in confusing ways that conflict with ours. Define it up with __CHECKER__ so that linux/fs.h and our copy are acting on the same input. - We had manually set a few of gcc's internal defines to give to sparse. It's easier to just ask gcc for all the defines it sets and hand those to sparse. - We weren't passing the same *FLAGS to sparse as we were to CC. - glibc has so many errors with FORTIFY turned on that sparse gives up and doesn't show us any errors from our code. It's a questionable hack to always turn on FORTIFY ourselves, so we'll just not do that when building with sparse. And add a nice '[SP]' quiet output line for sparse checks. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix unaligned compat endian warningsZach Brown2013-09-03
| | | | | | | | | | | | | | The _una_ struct's entire job is to pass an argument to le*_to_cpu. So it's a little embarassing that it uses a native cpu types and generates endian warnings. ctree.h:1616:1: warning: incorrect type in assignment (different base types) ctree.h:1616:1: expected unsigned long long [unsigned] [usertype] x ctree.h:1616:1: got restricted __le64 [usertype] <noident> Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix duplicate __[su]* typedefs on ppc64Michal Marek2013-08-09
| | | | | | | | | | | | | | | | | The <ext2fs/ext2_types.h> header does attempt to avoid conflicts with <linux/types.h>, but on ppc64, <asm-generic/int-ll64.h> gets somehow included by other headers. Include <linux/types.h> explicitly, so that <ext2fs/ext2_types.h> notices it. The proper fix would be to fix <ext2fs/ext2_types.h> to not use its own typedefs. Originally observed in btrfs-convert, put the include into kerncompat.h to avoid future problems. Signed-off-by: Michal Marek <mmarek@suse.cz> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: kerncompat.h: remove offsetof redefinitionCristian Rodríguez2013-08-09
| | | | | | | | Must use the version provided by the compiler in stddef.h header Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Merge branch 'cov-fixes-v1-integration-20130201' of ↵Chris Mason2013-02-06
|\ | | | | | | http://git.zabbo.net/cgit/btrfs-progs into merged
| * btrfs-progs: use ftw() unstead of system("du")Zach Brown2013-02-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | size_sourcedir() uses shockingly bad code to try and estimate the size of the files and directories in a subtree. - Its use of snprintf(), strcat(), and sscanf() with arbitrarily small on-stack buffers manages to overflow the stack a few times when given long file names. $ BIG=$(perl -e 'print "a" x 200') $ mkdir -p /tmp/$BIG/$BIG/$BIG/$BIG/$BIG $ mkfs.btrfs /tmp/img -r /tmp/$BIG/$BIG/$BIG/$BIG/$BIG *** stack smashing detected ***: mkfs.btrfs terminated - It passes raw paths to system() allowing interpreting file names as shell control characters. $ mkfs.btrfs /tmp/img -r /tmp/spacey\ dir/ du: cannot access `/tmp/spacey': No such file or directory du: cannot access `dir/': No such file or directory - It redirects du output to "temp_file" in the current directory, allowing overwriting of files through symlinks. $ echo hi > target $ ln -s target temp_file $ mkfs.btrfs /tmp/img -r /tmp/somedir/ $ cat target 3 /tmp/somedir/ This fixes the worst problems while maintaining -r functionality by tearing out the system() code and using ftw() to walk the source tree and sum up st.st_size. Signed-off-by: Zach Brown <zab@redhat.com>
* | Merge branch 'for-chris' of git://repo.or.cz/btrfs-progs-unstable/devel into ↵Chris Mason2013-02-06
|\| | | | | | | | | | | | | | | | | raid56 Conflicts: ctree.h Signed-off-by: Chris Mason <chris.mason@fusionio.com>
| * btrfs-progs: fix unaligned accesses v2Ben Peddell2013-01-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gcc optimizes out the memcpy calls at -O2 and -Os. Replacing memcpy with memmove does't work - gcc treats memmove the same way it treats memcpy. This patch brings in {get|put}_unaligned_le{16|32|64} (using the packed struct method), and uses them in the failing get/set calls. On architectures where unaligned accesses are cheap, these unaligned macros should be optimized out by the compiler. Signed-off-by: Ben Peddell <klightspeed@killerwolves.net>
* | btrfs-progs: include kerncompat.h in raid6.c, define __attribute_const__Eric Sandeen2013-02-03
|/ | | | | | | | | | | | | | | raid6.c was failing to build for Goffredo and me due to __attribute_const__ being undefined. Define it in kerncompat.h and include that; this also makes sure BITS_PER_LONG is defined for raid6.c, prior to this it was not defined, at least in my build. Finally, redefine BITS_PER_LONG in a way that it can be tested in the preprocessor macro. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: Fix compiler warnings on PPC64Wade Cline2013-01-17
| | | | | | | | | | | | | | | | The kernel uses unsigned long long for u64, but PPC64 uses unsigned long by default. This results in compilation warnings such as: print-tree.c:333: warning: format '%llu' expects type 'long long unsigned int', but argument 4 has type 'u64' To fix this, the macro __KERNEL__ needs to be defined before including the file <asm/types.h>. This can be done by defining the macro in "kerncompat.h" and making it the first included file in the relevant header files; this fixes the compiler warnings on PPC64. Reviewed-by: David Sterba <dsterba@suse.cz> Signed-off-by: Wade Cline <clinew@linux.vnet.ibm.com>
* multidevice support for check_mountedAndi Drebes2010-09-23
| | | | | | | | | | | | | | Check_mount() should also work with multi device filesystems. This patch adds checks that allow to detect if a file is a device file used by a mounted single or multi device btrfs or if it is a regular file used by a loopback device that is part of a mounted single or multi device btrfs. The single device checks also work for non-btrfs filesystems. This might be helpful to prevent users from running btrfs programs (e.g. mkfs.btrfs) accidentally on a filesystem used somewhere else. Signed-off-by: Andi Drebes <lists-receive@programmierforen.de>
* Mixed back reference (FORWARD ROLLING FORMAT CHANGE)Chris Mason2009-06-08
| | | | | | | | | | | | | | | | | This commit introduces a new kind of back reference for btrfs metadata. Once a filesystem has been mounted with this commit, IT WILL NO LONGER BE MOUNTABLE BY OLDER KERNELS. The new back ref provides information about pointer's key, level and in which tree the pointer lives. This information allow us to find the pointer by searching the tree. The shortcoming of the new back ref is that it only works for pointers in tree blocks referenced by their owner trees. This is mostly a problem for snapshots, where resolving one of these fuzzy back references would be O(number_of_snapshots) and quite slow. The solution used here is to use the fuzzy back references in the common case where a given tree block is only referenced by one root, and use the full back references when multiple roots have a reference
* Update BUG_ON and WARN_ONShen Feng2009-01-07
| | | | | | | Define BUG_ON and WARN_ON as assert for easy debugging. Signed-off-by: Shen Feng <shen@cn.fujitsu.com>