Commit graph

31 commits

Author SHA1 Message Date
Marek Behún 08fb534eb7 btrfs-progs: do not fail when offset of a ROOT_ITEM is not -1
When the btrfs_read_fs_root() function is searching a ROOT_ITEM with
location key offset other than -1, it currently fails via BUG_ON.

The offset can have other value than -1, though. This can happen for
example if a subvolume is renamed:

  $ btrfs subvolume create X && sync
  Create subvolume './X'
  $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: X$
        location key (270 ROOT_ITEM 18446744073709551615) type DIR
        transid 283 data_len 0 name_len 1
        name: X
  $ mv X Y && sync
  $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: Y$
        location key (270 ROOT_ITEM 0) type DIR
        transid 285 data_len 0 name_len 1
        name: Y

As can be seen the offset changed from -1ULL to 0.

Do not fail in this case.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
CC: Qu Wenruo <wqu@suse.com>
CC: Tom Rini <trini@konsulko.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
Su Yue be6710f89d btrfs-progs: print bytenr of child eb if mismatched level found in read_node_slot
If btrfs check reported like

  ERROR: child eb corrupted: parent bytenr=178081 item=246 parent level=1 child level=2

It's hard to find which eb is corrupted without bytenr in dump tree
information:

  node 178081 level 1 items 424 free 69 generation 44495 owner EXTENT_TREE
  fs uuid 7d9dbe1b-dea6-4141-807b-026325123ad8
  chunk uuid 97a3e3aa-7105-4101-aaf7-50204a240e69
	  key (16613126144 EXTENT_ITEM 4096) block 177939087360 gen 44433
	  key (16632803328 EXTENT_ITEM 4096) block 177939120128 gen 44433
	  key (16654548992 EXTENT_ITEM 8192) block 177970380800 gen 44336
	  key (16697884672 EXTENT_ITEM 8192) block 177970397184 gen 44336
	  key (16714223616 EXTENT_ITEM 16384) block 177970413568 gen 44336
	  key (16721760256 EXTENT_ITEM 16384) block 177943855104 gen 44436
	  key (16857755648 EXTENT_ITEM 4096) block 177857544192 gen 44416
  ...

For easier lookup, print bytenr of child eb if its level is not equal
to parent's level - 1 in read_node_slot().

Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
Josef Bacik 9cc9c9ab32 btrfs-progs: print the eb flags for nodes as well
While debugging a corruption problem I realized we don't spit out the
flags for nodes, which is needed when debugging relocation problems so
we know which nodes are the RELOC root items and which are the actual fs
tree's items.  Fix this by unifying the header printing helper so both
leaf's and nodes get the same information printed out.

  node 41070940160 level 1 items 34 free space 87 generation 7709536 owner ROOT_TREE
  node 41070940160 flags 0x1(WRITTEN) backref revision 1

Same for leaves:

  leaf 41070944256 items 12 free space 515 generation 7709536 owner ROOT_TREE
  leaf 41070944256 flags 0x1(WRITTEN) backref revision 1

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Boris Burkov 92d92e99b7 btrfs-progs: mkfs: support free space tree as -R option
Add a runtime feature (-R) flag for the free space tree. A filesystem
that is mkfs'd with -R free-space-tree then mounted with no options has
the same contents as one mkfs'd without the option, then mounted with
'-o space_cache=v2'.

The only tricky thing is in exactly how to call the tree creation code.
Using btrfs_create_free_space_tree as is did not quite work, because an
extra reference to the eb (root->commit_root) is leaked, which mkfs
complains about with a warning. I opted to follow how the uuid tree is
created by adding it to the dirty roots list for cleanup by
commit_tree_roots in commit_transaction. As a result,
btrfs_create_free_space_tree no longer exactly matches the version in
the kernel sources.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-09-08 22:06:04 +02:00
Marcos Paulo de Souza c655b5e4b1 btrfs-progs: make btrfs_lookup_dir_index in parity with kernel code
This function exists in kernel side but using the _item suffix, and
objectid argument is placed before the name argument. Change the
function to reflect the kernel version.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:09:49 +02:00
David Sterba 0144bcb713 btrfs-progs: move volumes.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:06 +02:00
David Sterba 6069bc52a9 btrfs-progs: move transaction.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:06 +02:00
David Sterba 978f300c21 btrfs-progs: move inode.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba abb670f883 btrfs-progs: move ctree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba c03619b864 btrfs-progs: move file.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba 772f0da6df btrfs-progs: move disk-io.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba cf529f36ad btrfs-progs: move print-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba 7dd4abc3c5 btrfs-progs: move extent-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba 4e49bd703d btrfs-progs: move extent_io.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba da90f38ad9 btrfs-progs: move free-space-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba f7fe7de64c btrfs-progs: move uuid-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba a656166d11 btrfs-progs: move root-tree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba fdf058ac0f btrfs-progs: move inode-item.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba a067ecef0a btrfs-progs: move file-item.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:09 +02:00
David Sterba 925bf01f5d btrfs-progs: move dir-item.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:08 +02:00
Qu Wenruo ccad599701 btrfs-progs: rename btrfs_block_group_cache to btrfs_block_group
To keep the same naming across kernel and btrfs-progs.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:50:00 +02:00
Qu Wenruo 5bc44891c9 btrfs-progs: kill block_group_cache::key
This would sync the code between kernel and btrfs-progs, and save at
least 1 byte for each btrfs_block_group_cache.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-11 20:49:50 +02:00
David Sterba 8c85b34420 btrfs-progs: move backref.[ch] to kernel-shared/
The files are very close to kernel versions, for that keep them in the
shared directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:35 +02:00
David Sterba 58bcd4260f btrfs-progs: move free-space-tree.[ch] to kernel-shared/
The files are very close to kernel versions, for that keep them in the
shared directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:34 +02:00
David Sterba 019489a143 btrfs-progs: move delayed-ref.[ch] to kernel-shared/
The files are very close to kernel versions, for that keep them in the
shared directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:34 +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 440e8b9830 btrfs-progs: shared: rename ulist_fini to ulist_release
Sync the file with kernel version.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-16 21:16:14 +01:00
David Sterba 2fefed2601 btrfs-progs: shared: cleanup includes in ulist.c
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba 390db8a346 btrfs-progs: shared: remove debug code from ulist
Sync with kernel sources, we don't define CONFIG_BTRFS_DEBUG in
userspace anyway.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba 4049542d4f btrfs-progs: shared: copy ulist_del from kernel
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba 886a8565e0 btrfs-progs: move ulist.[ch] to kernel-shared
The implementation of ulist_* is same for kernel and userspace, without
dependencies, so we can keep it separately for code sync.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00