Commit Graph

164 Commits (master)

Author SHA1 Message Date
David Sterba 2047b6de3d btrfs-progs: add blake2b support
Add definition, crypto wrappers and support to mkfs for blake2 for
checksumming. There are 2 aliases either blake2 or blake2b.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:06 +01:00
Johannes Thumshirn ae9f8bff30 btrfs-progs: add sha256 as supported checksumming algorithm
Add the definition to the checksum types and let mkfs accept it.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:40 +01:00
David Sterba cc8b28226c btrfs-progs: constify and reduce csum definition table
The table won't change at runtime and the string name can be in a buffer
avoiding the pointer indirection. Make one entry aligned to 16 bytes,
plenty of space to store reasonably long csum names.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:02 +01:00
Johannes Thumshirn f070ece2e9 btrfs-progs: add xxhash64 to mkfs
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:00 +01: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
Johannes Thumshirn e4a8e1916d btrfs-progs: add table for checksum type and name
Adding this table will make extending btrfs-progs with new checksum types
easier.

Also add accessor functions to access the table fields.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:29:05 +02:00
Josef Bacik 42a1aaeec4 btrfs-progs: deal with drop_progress properly in fsck
While testing snapshot deletion with dm-log-writes I saw that I was
failing the fsck sometimes when the fs was actually in the correct
state.  This is because we only skip blocks on the same level of
root_item->drop_level.  If the drop_level < the root level then we could
very well walk into nodes that we wouldn't actually walk into on fs
mount, because the drop_progress is further ahead in the slot of the
root.  Instead only process the slots of the nodes that are above the
drop_progress key.  With this patch in place we no longer improperly
fail to check fs'es that have a drop_progress set with a drop_level <
root level.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:42 +02:00
David Sterba 94fced6353 btrfs-progs: build: drop kernel-lib from -I and update paths
Include the files by full path to avoid any confusion in case of
potentially duplicate names.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba d1efe50d0a btrfs-progs: move messages.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba f63f29e9e9 btrfs-progs: move internal.h to common/
Create directory for all sources that can be used by anything that's not
rellated to a relevant kernel part, all common functions, helpers,
utilities that do not fit any other specific category.

The traditional location would be probably lib/ with all things that are
statically linked to the main binaries, but we have libbtrfs and
libbtrfsutil so this would be confusing.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 1d4796978c btrfs-progs: pass whole key to btrfs_uuid_to_key
Switch the function to take a key instead of objectid and offset
separately, gcc 9 complains with enabled -Waddress-of-packed-member:

    [CC]     ctree.o
ctree.c: In function ‘btrfs_uuid_tree_lookup’:
ctree.c:3133:26: error: taking address of packed member of ‘struct btrfs_key’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
 3133 |  btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);

Signed-off-by: David Sterba <dsterba@suse.com>
2019-06-13 20:25:26 +02:00
Qu Wenruo 085445e793 btrfs-progs: Cleanup BTRFS_COMPAT_EXTENT_TREE_V0
BTRFS_COMPAT_EXTENT_TREE_V0 is introduced for a short time in kernel,
and it's over 10 years ago.

Nowadays there should be no user for that feature, and kernel has remove
this support in Jun, 2018. There is no need for btrfs-progs to support
it.

This patch will remove EXTENT_TREE_V0 related code and replace those
BUG_ON() to a more graceful error message.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-06-05 18:00:07 +02:00
Qu Wenruo db51d8d8f6 btrfs-progs: Use @fs_info to replace @root for btrfs_check_leaf/node()
Signed-off-by: Qu Wenruo <wqu@suse.com>
2019-04-16 09:04:25 +08:00
David Sterba f6f518a081 btrfs-progs: build: fix libbtrfs build
Commit 75b5eabb61 ("btrfs-progs: uuid: Port
btrfs_uuid_tree_add() function") brings code from kernel and introduces
an unsatisfied build dependency for libbtrfs. This fails build for
external library users like snapper.

As a hotfix, shuffle the new UUID functions so the build works. Simply
adding uuid-tree.o to libbtrfs_objects does not work due to other
missing symbols.

    [CC]     uuid-tree.o
    [LD]     libbtrfs.so.0.1
    [LN]     libbtrfs.so
    [TEST PREP]  library-test
	ld: .../libbtrfs.so: undefined reference to `btrfs_alloc_path'
	ld: .../libbtrfs.so: undefined reference to `btrfs_extend_item'
	ld: .../libbtrfs.so: undefined reference to `btrfs_insert_empty_items'
	ld: .../libbtrfs.so: undefined reference to `btrfs_free_path'
	ld: .../libbtrfs.so: undefined reference to `read_extent_buffer'
	ld: .../libbtrfs.so: undefined reference to `btrfs_mark_buffer_dirty'
	ld: .../libbtrfs.so: undefined reference to `write_extent_buffer'
	ld: .../libbtrfs.so: undefined reference to `btrfs_search_slot'

LinK: https://bugs.gentoo.org/675974
Link: https://github.com/openSUSE/snapper/issues/473
Fixes: 75b5eabb61 ("btrfs-progs: uuid: Port btrfs_uuid_tree_add() function")
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-23 13:53:55 +01:00
Qu Wenruo bda00a4021 btrfs-progs: Fix -Wmaybe-uninitialized warning
GCC 8.2.1 will report the following warning with "make W=1":

  ctree.c: In function 'btrfs_next_sibling_tree_block':
  ctree.c:2990:21: warning: 'slot' may be used uninitialized in this function [-Wmaybe-uninitialized]
    path->slots[level] = slot;
    ~~~~~~~~~~~~~~~~~~~^~~~~~

The culprit is the following code:

	int slot;		<< Not initialized
	int level = path->lowest_level + 1;
 	BUG_ON(path->lowest_level + 1 >= BTRFS_MAX_LEVEL);
 	while(level < BTRFS_MAX_LEVEL) {
		slot = path->slots[level] + 1;
		^^^^^^ but we initialize @slot here.
		...
	}
	path->slots[level] = slot;

It's possible that compiler doesn't get enough hint for BUG_ON() on
lowest_level + 1 >= BTRFS_MAX_LEVEL case.

Fix it by using a do {} while() loop other than while() {} loop, to
ensure we will run the loop for at least once.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 18:42:12 +01:00
Nikolay Borisov f7717d8cdb btrfs-progs: Remove fsid/metdata_uuid fields from fs_info
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 16:20:09 +01:00
Nikolay Borisov c4aadd9af2 btrfs-progs: Add support for metadata_uuid field
Add support for a new metadata_uuid field. This is just a preparatory
commit which switches all users of the fsid field for metdata comparison
purposes to utilize the new field. This more or less mirrors the
kernel patch, additionally:

 * Update 'btrfs inspect-internal dump-super' to account for the new
 field. This involes introducing the 'metadata_uuid' line to the
 output and updating the logic for comparing the fs uuid to the
 dev_item uuid.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-12-06 12:51:36 +01:00
Josh Soref b1d39a42a4 btrfs-progs: fix typos in comments
Generated by https://github.com/jsoref/spelling

Issue: #154
Author: Josh Soref <jsoref@users.noreply.github.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-11-26 18:24:48 +01:00
Qu Wenruo cdd00958e4 btrfs-progs: Introduce function to find next sibling tree block
Introduce a new function, btrfs_next_sibling_tree_block(), which could
find any sibling tree blocks at path->lowest_level, unlike level 0
limited btrfs_next_leaf().

Since this function is more generic than btrfs_next_leaf(), also make
btrfs_next_leaf() a wrapper of btrfs_next_sibling_tree_block(), to keep
the interface the same as kernel.

This would provide the basis for later breadth-first search print-tree.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-31 18:24:14 +01:00
Qu Wenruo 65c3665811 btrfs-progs: Replace root parameter using fs_info for reada_for_search()
As the @root parameter is only used to get @fs_info, use fs_info
directly instead.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-31 18:24:14 +01:00
Su Yanjun 22e4767950 btrfs-progs: consitfy keys passed to serch functions
When using gcc8 to compile btrfs-progs, it complains as below:

ctree.c: In function 'btrfs_search_slot_for_read':
    ctree.c:1249:45: warning: passing argument 3 of 'btrfs_search_slot'
    discards 'const' qualifier from pointer target type
    [-Wdiscarded-qualifiers]
             ret = btrfs_search_slot(NULL, root, key, p, 0, 0);

Change btrfs_search_slot prototype with 'const' qualifier for argument 3.
Also fix similar problems as above change.

Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11:40 +02: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 f23d10d9c0 btrfs-progs: Always pass 0 for offset when calling btrfs_free_extent for btree blocks.
Currently some instances of btrfs_free_extent are called with the
last parameter ("offset") being set to 1. This makes no sense, since
offset is used for data extents. I suspect this is a left-over from
95d3f20b51 ("Mixed back reference  (FORWARD ROLLING FORMAT CHANGE)")
since this commit changed the signature of the function from :

-int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
-                     *root, u64 bytenr, u64 num_bytes, u64 parent,
-                     u64 root_objectid, u64 ref_generation,
-                     u64 owner_objectid, int pin);

to

+int btrfs_free_extent(struct btrfs_trans_handle *trans,
+                     struct btrfs_root *root,
+                     u64 bytenr, u64 num_bytes, u64 parent,
+                     u64 root_objectid, u64 owner, u64 offset);

I.e the last parameter was "pin" and not offset. So these are just
leftovers with no semantic meaning. Fix this by passing 0.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:02:04 +02:00
Nikolay Borisov 3a0cf26bee btrfs-progs: Refactor the root used bytes are updated
Instead of updating this during update_block_group, move the updating
code at the places where we free/allocate a block. This resembles the
current state of the kernel code. This is in prep for delayed refs.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:01:51 +02:00
Nikolay Borisov 4d918a7299 btrfs-progs: Add functions to modify the used space by a root
Pull the necessary function, excluding locking. Required to enable
integration of delayed refs.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:01:48 +02:00
Nikolay Borisov 2d99e810d9 btrfs-progs: Remove root argument from btrfs_set_block_flags
It's used only to get a reference to fs_info, which can be obtained from
the transaction handle.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:37 +02:00
Nikolay Borisov a22b593587 btrfs-progs: Change btrfs_root to btrfs_fs_info argument in btrfs_lookup_extent_info
That function really wants an fs_info and not a root. Accidentally,
this also makes the kernel/user space signatures to be coherent.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:37 +02:00
Nikolay Borisov a93d51ede7 btrfs-progs: Remove unused argument from clean_tree_block
This function actually uses only the extent_buffer arg but takes 3
arguments. Furthermore, it's current interface doesn't even mirror
the kernel counterpart. Just remove the extra arguments.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:37 +02:00
Qu Wenruo 41750fe660 btrfs-progs: Remove fs_info parameter from btrfs_leaf_free_space()
For btrfs_leaf_free_space(), to get leaf data size, we have two way to
get it:

1) leaf->fs_info->nodesize
2) leaf->len

Anyway, we could get rid of @fs_info parameter for
btrfs_leaf_free_space().
And here we choose method 2), as it provides extra benefit to get leaf
free space without initializing a real fs_info.

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>
2018-06-07 16:37:35 +02:00
Qu Wenruo 26c1dafbf6 btrfs-progs: print-tree: Remove btrfs_root parameter
Just like kernel cleanup made by David, btrfs_print_leaf() and
btrfs_print_tree() doesn't need btrfs_root parameter at all.

With previous patches as preparation, now we can remove the btrfs_root
parameter.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-24 13:00:11 +02:00
Qu Wenruo 47c694b0f4 btrfs-progs: Unify btrfs_leaf_free_space() parameter with kernel
Instead of struct btrfs_root, use struct btrfs_fs_info, since nodesize
is now a per-fs setting, and with the need to pass a @root, caller don't
need to wonder which root should be passed.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-24 13:00:11 +02:00
Qu Wenruo 2615aca92c 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>
2018-03-30 22:15:54 +02: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 3809b36d85 btrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK
Do a cleanup. Also make it consistent with kernel.  Use fs_info instead
of root for BTRFS_NODEPTRS_PER_BLOCK, 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 26072f584d btrfs-progs: Use fs_info instead of root for BTRFS_LEAF_DATA_SIZE
Do a cleanup. Also make it consistent with kernel.  Use fs_info instead
of root for BTRFS_LEAF_DATA_SIZE, since maybe in some situation we do
not know root, but just know fs_info.

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:56 +01:00
David Sterba 145a5969bd btrfs-progs: drop blocksize argument from readahead_tree_block
Tree blocks are always nodesize. As readahead is only an optimization,
exact size is not required and is only advisory.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 98909c21d7 btrfs-progs: drop blocksize from read_tree_block
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
David Sterba 1fa9653dc8 btrfs-progs: drop local blocksize variables if they're nodesize
Prep work so we can drop the blocksize argument from several functions.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Qu Wenruo bb3ecd59f2 btrfs-progs: Refactor btrfs_readahead_tree_block to use btrfs_fs_info
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-12 17:53:21 +02:00
Qu Wenruo 6aaf1b10e7 btrfs-progs: Refactor btrfs_find_tree_block to use btrfs_fs_info
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-12 17:53:18 +02:00
Philipp Hahn 1618d8afb9 btrfs-progs: Fix slot >= nritems
Running "btrfsck --repair /dev/sdd2" crashed as it can happen in
(corrupted) file systems, that slot > nritems:
> (gdb) bt full
> #0  0x00007ffff7020e71 in __memmove_sse2_unaligned_erms () from /lib/x86_64-linux-gnu/libc.so.6
> #1  0x0000000000438764 in btrfs_del_ptr (trans=<optimized out>, root=0x6e4fe0, path=0x1d17880, level=0, slot=7)
>     at ctree.c:2611
>         parent = 0xcd96980
>         nritems = <optimized out>
>         __func__ = "btrfs_del_ptr"
> #2  0x0000000000421b15 in repair_btree (corrupt_blocks=<optimized out>, root=<optimized out>) at cmds-check.c:3539
>         key = {objectid = 77990592512, type = 168 '\250', offset = 16384}
>         trans = 0x8f48c0
>         path = 0x1d17880
>         level = 0
> #3  check_fs_root (wc=<optimized out>, root_cache=<optimized out>, root=<optimized out>) at cmds-check.c:3703
>         corrupt = 0x1d17880
>         corrupt_blocks = {root = {rb_node = 0x6e80c60}}
>         path = {nodes = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, slots = {0, 0, 0, 0, 0, 0, 0, 0}, locks = {0, 0,
>             0, 0, 0, 0, 0, 0}, reada = 0, lowest_level = 0, search_for_split = 0, skip_check_block = 0}
>         nrefs = {bytenr = {271663104, 271646720, 560021504, 0, 0, 0, 0, 0}, refs = {1, 1, 1, 0, 0, 0, 0, 0}}
>         wret = 215575372
>         root_node = {cache = {rb_node = {__rb_parent_color = 0, rb_right = 0x0, rb_left = 0x0}, objectid = 0,
>             start = 0, size = 0}, root_cache = {root = {rb_node = 0x0}}, inode_cache = {root = {
>               rb_node = 0x781c80}}, current = 0x819530, refs = 0}
>         status = 215575372
>         rec = 0x1
> #4  check_fs_roots (root_cache=0xcd96b6d, root=<optimized out>) at cmds-check.c:3809
>         path = {nodes = {0x6eed90, 0x6a2f40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, slots = {18, 2, 0, 0, 0, 0, 0, 0},
>           locks = {0, 0, 0, 0, 0, 0, 0, 0}, reada = 0, lowest_level = 0, search_for_split = 0,
>           skip_check_block = 0}
>         key = {objectid = 323, type = 132 '\204', offset = 18446744073709551615}
>         wc = {shared = {root = {rb_node = 0x0}}, nodes = {0x0, 0x0, 0x7fffffffe428, 0x0, 0x0, 0x0, 0x0, 0x0},
>           active_node = 2, root_level = 2}
>         leaf = 0x6e4fe0
>         tmp_root = 0x6e4fe0
> #5  0x00000000004287c3 in cmd_check (argc=215575372, argv=0x1d17880) at cmds-check.c:11521
>         root_cache = {root = {rb_node = 0x98c2940}}
>         info = 0x6927b0
>         bytenr = 6891440
>         tree_root_bytenr = 0
>         uuidbuf = "f65ff1a1-76ef-456e-beb5-c6c3841e7534"
>         num = 215575372
>         readonly = 218080104
>         qgroups_repaired = 0
> #6  0x000000000040a41f in main (argc=3, argv=0x7fffffffebe8) at btrfs.c:243
>         cmd = 0x689868
>         bname = <optimized out>
>         ret = <optimized out>

in that case the count of remaining items (nritems - slot - 1) gets
negative. That is then casted to (unsigned long len), which leads to the
observed crash.

Change the tests before the move to handle only the non-corrupted case,
were slow < nritems.

This does not fix the corruption, but allows btrfsck to finish without
crashing.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 9f6dec4dd5 btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root
parameter

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 8690c887d1 btrfs-progs: Refactor read_tree_block to get rid of btrfs_root
The only reasom read_tree_block() needs a btrfs_root parameter is to get
its node/sector size.

And long ago, I have already introduced a compactible interface,
read_tree_block_fs_info() to pass btrfs_fs_info instead of btrfs_root.

Since we have cleaned up all root->sector/node/stripesize users, we
should be OK to refactor read_tree_block() function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:11 +02:00
Qu Wenruo 34bd207932 btrfs-progs: Refactor block sizes users in ctree.c and ctree.h
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
David Sterba 16ce9d6069 btrfs-progs: remove unused function wait_on_tree_block_writeback
This used to be a kernel stub but has been removed from kernel long time
ago.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba 99063d88af btrfs-progs: drop unused argument from btrfs_del_ptr
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba c6eae415ee btrfs-progs: drop unused argument from btrfs_extend_item
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba 4069aa73d3 btrfs-progs: drop unused argument from btrfs_truncate_item
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
Qu Wenruo a2203246ae btrfs-progs: Introduce kernel sizes to cleanup large intermediate number
Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to
waste one second to convert to 1G.

Introduce kernel include/linux/sizes.h to replace any intermediate
number larger than 4096 (not including 4096) to SZ_*.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba 1ef93ea863 btrfs-progs: handle errors from btrfs_alloc_path
All functions already return an error condition, so the callers should
expect that.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 14:12:38 +02:00