btrfs-progs/kernel-shared
Qu Wenruo e79f18a4a7 btrfs-progs: introduce a basic metadata free space reservation check
Unlike kernel, in btrfs-progs btrfs_start_transaction() never checks if
there is enough metadata space.

This can lead to very dangerous situation where there is no metadata
space left at all, deadlocking future tree operations.

This patch introduces a very basic version of metadata/system free space
check by:

- Check if there is enough metadata/system space left
  If there is enough, go as usual.

- If there is not enough space left, try allocating a new chunk

- Recheck if the new space can meet our demand
  If not, return ERR_PTR(-ENOSPC).
  Otherwise, allocate a new trans handle to the caller.

This is possible thanks to the simplified transaction model in
btrfs-progs:

- We don't allow joining a transaction
  This means we don't need to handle complex cases like data ordered
  extents, which need to reserve space first, then join the current
  transaction and use the reserved blocks.

- We don't allow multiple transaction handles for one transaction
  Since btrfs-progs is single threaded, we always start a transaction
  and then commit it.

However there is a feature that must be an exception for the new
metadata/system free space check:

- btrfs check --init-extent-tree
  As all the meta/system free space check is based on the space info,
  which is loaded from block group items.
  Thus when rebuilding extent tree, we can no longer have an accurate
  view, thus we have to disable the feature for the whole execution if
  we're rebuilding the extent tree.

For now, there is no regression exposed during the self tests, but I
really hope this can be an extra safety net to prevent causing ENOSPC
deadlock in btrfs-progs.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-17 19:33:59 +02:00
..
uapi btrfs-progs: remove stride length from on-disk format 2023-10-06 17:26:56 +02:00
accessors.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
accessors.h btrfs-progs: remove stride length from on-disk format 2023-10-06 17:26:56 +02:00
async-thread.c btrfs-progs: pull in the full max/min/clamp implementation from kernel 2023-10-10 19:16:29 +02:00
async-thread.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
backref.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
backref.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
compression.h btrfs-progs: minor source sync with kernel 6.4 2023-06-27 16:15:35 +02:00
ctree.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
ctree.h btrfs-progs: introduce a basic metadata free space reservation check 2023-10-17 19:33:59 +02:00
delayed-ref.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
delayed-ref.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
dir-item.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
disk-io.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
disk-io.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent_io.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent_io.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent-io-tree.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent-io-tree.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent-tree.c btrfs-progs: introduce a basic metadata free space reservation check 2023-10-17 19:33:59 +02:00
file-item.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
file-item.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
file.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
free-space-cache.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
free-space-cache.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
free-space-tree.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
free-space-tree.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
inode-item.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
inode.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
locking.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
locking.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
messages.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
messages.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
misc.h btrfs-progs: sync extent-io-tree.[ch] and misc.h from the kernel 2023-05-26 18:02:29 +02:00
print-tree.c btrfs-progs: remove stride length from tree dump 2023-10-06 17:26:54 +02:00
print-tree.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
README.md btrfs-progs: add README to kernel-shared tracking the progress 2023-05-26 18:02:32 +02:00
root-tree.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
send.h btrfs-progs: sync send.h from kernel 2023-05-26 18:02:32 +02:00
transaction.c btrfs-progs: introduce a basic metadata free space reservation check 2023-10-17 19:33:59 +02:00
transaction.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
tree-checker.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
tree-checker.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
tree-mod-log.h btrfs-progs: sync and stub-out tree-mod-log.h 2023-05-26 18:02:29 +02:00
ulist.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
ulist.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
uuid-tree.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
volumes.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
volumes.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
zoned.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
zoned.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00

Shared sources with kernel

Status and progress of kernel/userspace synchronization.

  • accessors.c - done, local changes
  • accessors.h - done, local changes
  • async-thread.c - done
  • async-thread.h - done
  • backref.c - todo
  • backref.h - todo
  • compression.h - done
  • ctree.c - partial
  • ctree.h - partial
  • delayed-ref.c - partial
  • delayed-ref.h - partial
  • dir-item.c - partial
  • disk-io.c - todo
  • disk-io.h - todo
  • extent_io.c
  • extent_io.h
  • extent-io-tree.c - done, local changes
  • extent-io-tree.h - done, local changes
  • extent-tree.c - todo
  • file.c - todo
  • file-item.c - todo
  • file-item.h - partial
  • free-space-cache.c - not needed
  • free-space-cache.h - not needed
  • free-space-tree.c - partial
  • free-space-tree.h - partial
  • inode.c - todo
  • inode-item.c - partial
  • locking.c - done, local changes
  • locking.h - done, local changes
  • messages.c - done, local changes
  • messages.h - done, local changes
  • misc.h - done
  • print-tree.c - partial, sync to kernel
  • print-tree.h - partial
  • root-tree.c - partial
  • root-tree.h - done
  • send.h - done
  • transaction.c - todo
  • transaction.h - partial, local changes
  • tree-checker.c - partial, local changes
  • tree-checker.h - partial, local changes
  • tree-mod-log.h - done, local changes
  • ulist.c - done
  • ulist.h - done
  • uuid-tree.c - partial
  • volumes.c - todo, local changes
  • volumes.h - todo, local changes
  • zoned.c - todo
  • zoned.h - todo