linux-stable/fs/btrfs
Stefan Behrens 07b30a49da Btrfs: introduce a tree for items that map UUIDs to something
Mapping UUIDs to subvolume IDs is an operation with a high effort
today. Today, the algorithm even has quadratic effort (based on the
number of existing subvolumes), which means, that it takes minutes
to send/receive a single subvolume if 10,000 subvolumes exist. But
even linear effort would be too much since it is a waste. And these
data structures to allow mapping UUIDs to subvolume IDs are created
every time a btrfs send/receive instance is started.

It is much more efficient to maintain a searchable persistent data
structure in the filesystem, one that is updated whenever a
subvolume/snapshot is created and deleted, and when the received
subvolume UUID is set by the btrfs-receive tool.

Therefore kernel code is added with this commit that is able to
maintain data structures in the filesystem that allow to quickly
search for a given UUID and to retrieve data that is assigned to
this UUID, like which subvolume ID is related to this UUID.

This commit adds a new tree to hold UUID-to-data mapping items. The
key of the items is the full UUID plus the key type BTRFS_UUID_KEY.
Multiple data blocks can be stored for a given UUID, a type/length/
value scheme is used.

Now follows the lengthy justification, why a new tree was added
instead of using the existing root tree:

The first approach was to not create another tree that holds UUID
items. Instead, the items should just go into the top root tree.
Unfortunately this confused the algorithm to assign the objectid
of subvolumes and snapshots. The reason is that
btrfs_find_free_objectid() calls btrfs_find_highest_objectid() for
the first created subvol or snapshot after mounting a filesystem,
and this function simply searches for the largest used objectid in
the root tree keys to pick the next objectid to assign. Of course,
the UUID keys have always been the ones with the highest offset
value, and the next assigned subvol ID was wastefully huge.

To use any other existing tree did not look proper. To apply a
workaround such as setting the objectid to zero in the UUID item
key and to implement collision handling would either add
limitations (in case of a btrfs_extend_item() approach to handle
the collisions) or a lot of complexity and source code (in case a
key would be looked up that is free of collisions). Adding new code
that introduces limitations is not good, and adding code that is
complex and lengthy for no good reason is also not good. That's the
justification why a completely new tree was introduced.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-09-01 08:15:52 -04:00
..
tests Btrfs: separate out tests into their own directory 2013-09-01 08:15:38 -04:00
acl.c Btrfs: skip adding an acl attribute if we don't have to 2012-12-16 20:46:15 -05:00
async-thread.c
async-thread.h
backref.c Btrfs: get rid of sparse warnings 2013-09-01 08:15:50 -04:00
backref.h Btrfs: cleanup backref search commit root flag stuff 2013-07-01 08:52:29 -04:00
btrfs_inode.h Btrfs: don't cache the csum value into the extent state tree 2013-09-01 08:04:33 -04:00
check-integrity.c Btrfs: get rid of sparse warnings 2013-09-01 08:15:50 -04:00
check-integrity.h
compat.h
compression.c btrfs: Introduce extent_read_full_page_nolock() 2013-09-01 08:04:59 -04:00
compression.h btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
ctree.c Btrfs: get rid of sparse warnings 2013-09-01 08:15:50 -04:00
ctree.h Btrfs: introduce a tree for items that map UUIDs to something 2013-09-01 08:15:52 -04:00
delayed-inode.c btrfs: Cleanup for using BTRFS_SETGET_STACK instead of raw convert 2013-09-01 07:57:37 -04:00
delayed-inode.h [readdir] convert btrfs 2013-06-29 12:57:00 +04:00
delayed-ref.c Btrfs: get rid of sparse warnings 2013-09-01 08:15:50 -04:00
delayed-ref.h Btrfs: handle running extent ops with skinny metadata 2013-05-17 21:40:15 -04:00
dev-replace.c Btrfs: introduce per-subvolume ordered extent list 2013-06-14 11:29:41 -04:00
dev-replace.h Btrfs: add new sources for device replace code 2012-12-12 17:15:41 -05:00
dir-item.c btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
disk-io.c btrfs: mark some local function as 'static' 2013-09-01 08:15:51 -04:00
disk-io.h Btrfs: introduce grab/put functions for the root of the fs/file tree 2013-06-14 11:29:38 -04:00
export.c Btrfs: cleanup: don't check the same thing twice 2013-06-14 11:29:30 -04:00
export.h
extent-tree.c Btrfs: avoid starting a transaction in the write path 2013-09-01 08:05:05 -04:00
extent_io.c btrfs: mark some local function as 'static' 2013-09-01 08:15:51 -04:00
extent_io.h btrfs: mark some local function as 'static' 2013-09-01 08:15:51 -04:00
extent_map.c btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
extent_map.h Btrfs: fix bad extent logging 2013-05-06 15:54:34 -04:00
file-item.c Btrfs: don't cache the csum value into the extent state tree 2013-09-01 08:04:33 -04:00
file.c Btrfs: avoid starting a transaction in the write path 2013-09-01 08:05:05 -04:00
free-space-cache.c Btrfs: separate out tests into their own directory 2013-09-01 08:15:38 -04:00
free-space-cache.h Btrfs: separate out tests into their own directory 2013-09-01 08:15:38 -04:00
hash.h
inode-item.c btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
inode-map.c Btrfs: don't use global block reservation for inode cache truncation 2013-05-17 21:40:22 -04:00
inode-map.h
inode.c Btrfs: avoid starting a transaction in the write path 2013-09-01 08:05:05 -04:00
ioctl.c Btrfs: don't miss inode ref items in BTRFS_IOC_INO_LOOKUP 2013-09-01 08:15:49 -04:00
Kconfig btrfs: move leak debug code to functions 2013-05-06 15:55:16 -04:00
locking.c btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
locking.h Btrfs: remove btrfs_try_spin_lock 2013-03-14 14:57:10 -04:00
lzo.c Btrfs: return -1 when lzo compression makes data bigger 2013-09-01 07:57:19 -04:00
Makefile Btrfs: introduce a tree for items that map UUIDs to something 2013-09-01 08:15:52 -04:00
math.h
ordered-data.c Btrfs: fix heavy delalloc related deadlock 2013-09-01 08:05:04 -04:00
ordered-data.h Btrfs: remove btrfs_sector_sum structure 2013-07-02 11:50:47 -04:00
orphan.c
print-tree.c Btrfs: Print key type in decimal everywhere 2013-09-01 07:57:40 -04:00
print-tree.h btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
qgroup.c Btrfs: remove reduplicate check when disabling quota 2013-09-01 08:15:47 -04:00
raid56.c Btrfs, raid56: fix memory leak when allocating pages for p/q stripes failed 2013-09-01 08:04:27 -04:00
raid56.h Btrfs: RAID5 and RAID6 2013-02-01 14:24:23 -05:00
rcu-string.h
reada.c Btrfs: fix reada debug code compilation 2013-05-06 15:54:55 -04:00
relocation.c Btrfs: change how we queue blocks for backref checking 2013-09-01 08:04:41 -04:00
root-tree.c btrfs: mark some local function as 'static' 2013-09-01 08:15:51 -04:00
scrub.c btrfs: Cleanup for using BTRFS_SETGET_STACK instead of raw convert 2013-09-01 07:57:37 -04:00
send.c Btrfs: get rid of sparse warnings 2013-09-01 08:15:50 -04:00
send.h btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
struct-funcs.c
super.c Btrfs: separate out tests into their own directory 2013-09-01 08:15:38 -04:00
sysfs.c btrfs: fixup/remove module.h usage as required 2013-03-01 15:01:01 -05:00
transaction.c btrfs: mark some local function as 'static' 2013-09-01 08:15:51 -04:00
transaction.h btrfs: mark some local function as 'static' 2013-09-01 08:15:51 -04:00
tree-defrag.c btrfs: remove cache only arguments from defrag path 2013-02-20 12:59:36 -05:00
tree-log.c Btrfs: don't ignore errors from btrfs_run_delayed_items 2013-09-01 08:04:54 -04:00
tree-log.h btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
ulist.c Btrfs: fix crash regarding to ulist_add_merge 2013-07-02 11:50:59 -04:00
ulist.h Btrfs: add a rb_tree to improve performance of ulist search 2013-05-06 15:54:44 -04:00
uuid-tree.c Btrfs: introduce a tree for items that map UUIDs to something 2013-09-01 08:15:52 -04:00
volumes.c Btrfs: get rid of sparse warnings 2013-09-01 08:15:50 -04:00
volumes.h Btrfs: don't cache the csum value into the extent state tree 2013-09-01 08:04:33 -04:00
xattr.c btrfs: make static code static & remove dead code 2013-05-06 15:55:23 -04:00
xattr.h
zlib.c