1 // SPDX-License-Identifier: GPL-2.0
4 #include "tree-mod-log.h"
8 #include "tree-checker.h"
10 struct tree_mod_root {
15 struct tree_mod_elem {
19 enum btrfs_mod_log_op op;
22 * This is used for BTRFS_MOD_LOG_KEY_* and BTRFS_MOD_LOG_MOVE_KEYS
27 /* This is used for BTRFS_MOD_LOG_KEY* and BTRFS_MOD_LOG_ROOT_REPLACE. */
30 /* Those are used for op == BTRFS_MOD_LOG_KEY_{REPLACE,REMOVE}. */
31 struct btrfs_disk_key key;
34 /* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */
40 /* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */
41 struct tree_mod_root old_root;
45 * Pull a new tree mod seq number for our operation.
47 static inline u64 btrfs_inc_tree_mod_seq(struct btrfs_fs_info *fs_info)
49 return atomic64_inc_return(&fs_info->tree_mod_seq);
53 * This adds a new blocker to the tree mod log's blocker list if the @elem
54 * passed does not already have a sequence number set. So when a caller expects
55 * to record tree modifications, it should ensure to set elem->seq to zero
56 * before calling btrfs_get_tree_mod_seq.
57 * Returns a fresh, unused tree log modification sequence number, even if no new
60 u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
61 struct btrfs_seq_list *elem)
63 write_lock(&fs_info->tree_mod_log_lock);
65 elem->seq = btrfs_inc_tree_mod_seq(fs_info);
66 list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
67 set_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags);
69 write_unlock(&fs_info->tree_mod_log_lock);
74 void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
75 struct btrfs_seq_list *elem)
77 struct rb_root *tm_root;
80 struct tree_mod_elem *tm;
81 u64 min_seq = BTRFS_SEQ_LAST;
82 u64 seq_putting = elem->seq;
87 write_lock(&fs_info->tree_mod_log_lock);
88 list_del(&elem->list);
91 if (list_empty(&fs_info->tree_mod_seq_list)) {
92 clear_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags);
94 struct btrfs_seq_list *first;
96 first = list_first_entry(&fs_info->tree_mod_seq_list,
97 struct btrfs_seq_list, list);
98 if (seq_putting > first->seq) {
100 * Blocker with lower sequence number exists, we cannot
101 * remove anything from the log.
103 write_unlock(&fs_info->tree_mod_log_lock);
106 min_seq = first->seq;
110 * Anything that's lower than the lowest existing (read: blocked)
111 * sequence number can be removed from the tree.
113 tm_root = &fs_info->tree_mod_log;
114 for (node = rb_first(tm_root); node; node = next) {
115 next = rb_next(node);
116 tm = rb_entry(node, struct tree_mod_elem, node);
117 if (tm->seq >= min_seq)
119 rb_erase(node, tm_root);
122 write_unlock(&fs_info->tree_mod_log_lock);
126 * Key order of the log:
127 * node/leaf start address -> sequence
129 * The 'start address' is the logical address of the *new* root node for root
130 * replace operations, or the logical address of the affected block for all
133 static noinline int tree_mod_log_insert(struct btrfs_fs_info *fs_info,
134 struct tree_mod_elem *tm)
136 struct rb_root *tm_root;
137 struct rb_node **new;
138 struct rb_node *parent = NULL;
139 struct tree_mod_elem *cur;
141 lockdep_assert_held_write(&fs_info->tree_mod_log_lock);
143 tm->seq = btrfs_inc_tree_mod_seq(fs_info);
145 tm_root = &fs_info->tree_mod_log;
146 new = &tm_root->rb_node;
148 cur = rb_entry(*new, struct tree_mod_elem, node);
150 if (cur->logical < tm->logical)
151 new = &((*new)->rb_left);
152 else if (cur->logical > tm->logical)
153 new = &((*new)->rb_right);
154 else if (cur->seq < tm->seq)
155 new = &((*new)->rb_left);
156 else if (cur->seq > tm->seq)
157 new = &((*new)->rb_right);
162 rb_link_node(&tm->node, parent, new);
163 rb_insert_color(&tm->node, tm_root);
168 * Determines if logging can be omitted. Returns true if it can. Otherwise, it
169 * returns false with the tree_mod_log_lock acquired. The caller must hold
170 * this until all tree mod log insertions are recorded in the rb tree and then
171 * write unlock fs_info::tree_mod_log_lock.
173 static inline bool tree_mod_dont_log(struct btrfs_fs_info *fs_info,
174 struct extent_buffer *eb)
176 if (!test_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags))
178 if (eb && btrfs_header_level(eb) == 0)
181 write_lock(&fs_info->tree_mod_log_lock);
182 if (list_empty(&(fs_info)->tree_mod_seq_list)) {
183 write_unlock(&fs_info->tree_mod_log_lock);
190 /* Similar to tree_mod_dont_log, but doesn't acquire any locks. */
191 static inline bool tree_mod_need_log(const struct btrfs_fs_info *fs_info,
192 struct extent_buffer *eb)
194 if (!test_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags))
196 if (eb && btrfs_header_level(eb) == 0)
202 static struct tree_mod_elem *alloc_tree_mod_elem(struct extent_buffer *eb,
204 enum btrfs_mod_log_op op)
206 struct tree_mod_elem *tm;
208 tm = kzalloc(sizeof(*tm), GFP_NOFS);
212 tm->logical = eb->start;
213 if (op != BTRFS_MOD_LOG_KEY_ADD) {
214 btrfs_node_key(eb, &tm->key, slot);
215 tm->blockptr = btrfs_node_blockptr(eb, slot);
219 tm->generation = btrfs_node_ptr_generation(eb, slot);
220 RB_CLEAR_NODE(&tm->node);
225 int btrfs_tree_mod_log_insert_key(struct extent_buffer *eb, int slot,
226 enum btrfs_mod_log_op op)
228 struct tree_mod_elem *tm;
231 if (!tree_mod_need_log(eb->fs_info, eb))
234 tm = alloc_tree_mod_elem(eb, slot, op);
238 if (tree_mod_dont_log(eb->fs_info, eb)) {
243 ret = tree_mod_log_insert(eb->fs_info, tm);
244 write_unlock(&eb->fs_info->tree_mod_log_lock);
251 int btrfs_tree_mod_log_insert_move(struct extent_buffer *eb,
252 int dst_slot, int src_slot,
255 struct tree_mod_elem *tm = NULL;
256 struct tree_mod_elem **tm_list = NULL;
261 if (!tree_mod_need_log(eb->fs_info, eb))
264 tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), GFP_NOFS);
268 tm = kzalloc(sizeof(*tm), GFP_NOFS);
274 tm->logical = eb->start;
276 tm->move.dst_slot = dst_slot;
277 tm->move.nr_items = nr_items;
278 tm->op = BTRFS_MOD_LOG_MOVE_KEYS;
280 for (i = 0; i + dst_slot < src_slot && i < nr_items; i++) {
281 tm_list[i] = alloc_tree_mod_elem(eb, i + dst_slot,
282 BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING);
289 if (tree_mod_dont_log(eb->fs_info, eb))
294 * When we override something during the move, we log these removals.
295 * This can only happen when we move towards the beginning of the
296 * buffer, i.e. dst_slot < src_slot.
298 for (i = 0; i + dst_slot < src_slot && i < nr_items; i++) {
299 ret = tree_mod_log_insert(eb->fs_info, tm_list[i]);
304 ret = tree_mod_log_insert(eb->fs_info, tm);
307 write_unlock(&eb->fs_info->tree_mod_log_lock);
313 for (i = 0; i < nr_items; i++) {
314 if (tm_list[i] && !RB_EMPTY_NODE(&tm_list[i]->node))
315 rb_erase(&tm_list[i]->node, &eb->fs_info->tree_mod_log);
319 write_unlock(&eb->fs_info->tree_mod_log_lock);
326 static inline int tree_mod_log_free_eb(struct btrfs_fs_info *fs_info,
327 struct tree_mod_elem **tm_list,
333 for (i = nritems - 1; i >= 0; i--) {
334 ret = tree_mod_log_insert(fs_info, tm_list[i]);
336 for (j = nritems - 1; j > i; j--)
337 rb_erase(&tm_list[j]->node,
338 &fs_info->tree_mod_log);
346 int btrfs_tree_mod_log_insert_root(struct extent_buffer *old_root,
347 struct extent_buffer *new_root,
350 struct btrfs_fs_info *fs_info = old_root->fs_info;
351 struct tree_mod_elem *tm = NULL;
352 struct tree_mod_elem **tm_list = NULL;
357 if (!tree_mod_need_log(fs_info, NULL))
360 if (log_removal && btrfs_header_level(old_root) > 0) {
361 nritems = btrfs_header_nritems(old_root);
362 tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *),
368 for (i = 0; i < nritems; i++) {
369 tm_list[i] = alloc_tree_mod_elem(old_root, i,
370 BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING);
378 tm = kzalloc(sizeof(*tm), GFP_NOFS);
384 tm->logical = new_root->start;
385 tm->old_root.logical = old_root->start;
386 tm->old_root.level = btrfs_header_level(old_root);
387 tm->generation = btrfs_header_generation(old_root);
388 tm->op = BTRFS_MOD_LOG_ROOT_REPLACE;
390 if (tree_mod_dont_log(fs_info, NULL))
394 ret = tree_mod_log_free_eb(fs_info, tm_list, nritems);
396 ret = tree_mod_log_insert(fs_info, tm);
398 write_unlock(&fs_info->tree_mod_log_lock);
407 for (i = 0; i < nritems; i++)
416 static struct tree_mod_elem *__tree_mod_log_search(struct btrfs_fs_info *fs_info,
417 u64 start, u64 min_seq,
420 struct rb_root *tm_root;
421 struct rb_node *node;
422 struct tree_mod_elem *cur = NULL;
423 struct tree_mod_elem *found = NULL;
425 read_lock(&fs_info->tree_mod_log_lock);
426 tm_root = &fs_info->tree_mod_log;
427 node = tm_root->rb_node;
429 cur = rb_entry(node, struct tree_mod_elem, node);
430 if (cur->logical < start) {
431 node = node->rb_left;
432 } else if (cur->logical > start) {
433 node = node->rb_right;
434 } else if (cur->seq < min_seq) {
435 node = node->rb_left;
436 } else if (!smallest) {
437 /* We want the node with the highest seq */
439 BUG_ON(found->seq > cur->seq);
441 node = node->rb_left;
442 } else if (cur->seq > min_seq) {
443 /* We want the node with the smallest seq */
445 BUG_ON(found->seq < cur->seq);
447 node = node->rb_right;
453 read_unlock(&fs_info->tree_mod_log_lock);
459 * This returns the element from the log with the smallest time sequence
460 * value that's in the log (the oldest log item). Any element with a time
461 * sequence lower than min_seq will be ignored.
463 static struct tree_mod_elem *tree_mod_log_search_oldest(struct btrfs_fs_info *fs_info,
464 u64 start, u64 min_seq)
466 return __tree_mod_log_search(fs_info, start, min_seq, true);
470 * This returns the element from the log with the largest time sequence
471 * value that's in the log (the most recent log item). Any element with
472 * a time sequence lower than min_seq will be ignored.
474 static struct tree_mod_elem *tree_mod_log_search(struct btrfs_fs_info *fs_info,
475 u64 start, u64 min_seq)
477 return __tree_mod_log_search(fs_info, start, min_seq, false);
480 int btrfs_tree_mod_log_eb_copy(struct extent_buffer *dst,
481 struct extent_buffer *src,
482 unsigned long dst_offset,
483 unsigned long src_offset,
486 struct btrfs_fs_info *fs_info = dst->fs_info;
488 struct tree_mod_elem **tm_list = NULL;
489 struct tree_mod_elem **tm_list_add, **tm_list_rem;
493 if (!tree_mod_need_log(fs_info, NULL))
496 if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0)
499 tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *),
504 tm_list_add = tm_list;
505 tm_list_rem = tm_list + nr_items;
506 for (i = 0; i < nr_items; i++) {
507 tm_list_rem[i] = alloc_tree_mod_elem(src, i + src_offset,
508 BTRFS_MOD_LOG_KEY_REMOVE);
509 if (!tm_list_rem[i]) {
514 tm_list_add[i] = alloc_tree_mod_elem(dst, i + dst_offset,
515 BTRFS_MOD_LOG_KEY_ADD);
516 if (!tm_list_add[i]) {
522 if (tree_mod_dont_log(fs_info, NULL))
526 for (i = 0; i < nr_items; i++) {
527 ret = tree_mod_log_insert(fs_info, tm_list_rem[i]);
530 ret = tree_mod_log_insert(fs_info, tm_list_add[i]);
535 write_unlock(&fs_info->tree_mod_log_lock);
541 for (i = 0; i < nr_items * 2; i++) {
542 if (tm_list[i] && !RB_EMPTY_NODE(&tm_list[i]->node))
543 rb_erase(&tm_list[i]->node, &fs_info->tree_mod_log);
547 write_unlock(&fs_info->tree_mod_log_lock);
553 int btrfs_tree_mod_log_free_eb(struct extent_buffer *eb)
555 struct tree_mod_elem **tm_list = NULL;
560 if (!tree_mod_need_log(eb->fs_info, eb))
563 nritems = btrfs_header_nritems(eb);
564 tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS);
568 for (i = 0; i < nritems; i++) {
569 tm_list[i] = alloc_tree_mod_elem(eb, i,
570 BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING);
577 if (tree_mod_dont_log(eb->fs_info, eb))
580 ret = tree_mod_log_free_eb(eb->fs_info, tm_list, nritems);
581 write_unlock(&eb->fs_info->tree_mod_log_lock);
589 for (i = 0; i < nritems; i++)
597 * Returns the logical address of the oldest predecessor of the given root.
598 * Entries older than time_seq are ignored.
600 static struct tree_mod_elem *tree_mod_log_oldest_root(struct extent_buffer *eb_root,
603 struct tree_mod_elem *tm;
604 struct tree_mod_elem *found = NULL;
605 u64 root_logical = eb_root->start;
612 * The very last operation that's logged for a root is the replacement
613 * operation (if it is replaced at all). This has the logical address
614 * of the *new* root, making it the very first operation that's logged
618 tm = tree_mod_log_search_oldest(eb_root->fs_info, root_logical,
623 * If there are no tree operation for the oldest root, we simply
624 * return it. This should only happen if that (old) root is at
631 * If there's an operation that's not a root replacement, we
632 * found the oldest version of our root. Normally, we'll find a
633 * BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING operation here.
635 if (tm->op != BTRFS_MOD_LOG_ROOT_REPLACE)
639 root_logical = tm->old_root.logical;
643 /* If there's no old root to return, return what we found instead */
652 * tm is a pointer to the first operation to rewind within eb. Then, all
653 * previous operations will be rewound (until we reach something older than
656 static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
657 struct extent_buffer *eb,
659 struct tree_mod_elem *first_tm)
662 struct rb_node *next;
663 struct tree_mod_elem *tm = first_tm;
666 unsigned long p_size = sizeof(struct btrfs_key_ptr);
668 n = btrfs_header_nritems(eb);
669 read_lock(&fs_info->tree_mod_log_lock);
670 while (tm && tm->seq >= time_seq) {
672 * All the operations are recorded with the operator used for
673 * the modification. As we're going backwards, we do the
674 * opposite of each operation here.
677 case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING:
678 BUG_ON(tm->slot < n);
680 case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING:
681 case BTRFS_MOD_LOG_KEY_REMOVE:
682 btrfs_set_node_key(eb, &tm->key, tm->slot);
683 btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
684 btrfs_set_node_ptr_generation(eb, tm->slot,
688 case BTRFS_MOD_LOG_KEY_REPLACE:
689 BUG_ON(tm->slot >= n);
690 btrfs_set_node_key(eb, &tm->key, tm->slot);
691 btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
692 btrfs_set_node_ptr_generation(eb, tm->slot,
695 case BTRFS_MOD_LOG_KEY_ADD:
696 /* if a move operation is needed it's in the log */
699 case BTRFS_MOD_LOG_MOVE_KEYS:
700 o_dst = btrfs_node_key_ptr_offset(eb, tm->slot);
701 o_src = btrfs_node_key_ptr_offset(eb, tm->move.dst_slot);
702 memmove_extent_buffer(eb, o_dst, o_src,
703 tm->move.nr_items * p_size);
705 case BTRFS_MOD_LOG_ROOT_REPLACE:
707 * This operation is special. For roots, this must be
708 * handled explicitly before rewinding.
709 * For non-roots, this operation may exist if the node
710 * was a root: root A -> child B; then A gets empty and
711 * B is promoted to the new root. In the mod log, we'll
712 * have a root-replace operation for B, a tree block
713 * that is no root. We simply ignore that operation.
717 next = rb_next(&tm->node);
720 tm = rb_entry(next, struct tree_mod_elem, node);
721 if (tm->logical != first_tm->logical)
724 read_unlock(&fs_info->tree_mod_log_lock);
725 btrfs_set_header_nritems(eb, n);
729 * Called with eb read locked. If the buffer cannot be rewound, the same buffer
730 * is returned. If rewind operations happen, a fresh buffer is returned. The
731 * returned buffer is always read-locked. If the returned buffer is not the
732 * input buffer, the lock on the input buffer is released and the input buffer
733 * is freed (its refcount is decremented).
735 struct extent_buffer *btrfs_tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
736 struct btrfs_path *path,
737 struct extent_buffer *eb,
740 struct extent_buffer *eb_rewin;
741 struct tree_mod_elem *tm;
746 if (btrfs_header_level(eb) == 0)
749 tm = tree_mod_log_search(fs_info, eb->start, time_seq);
753 if (tm->op == BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
754 BUG_ON(tm->slot != 0);
755 eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start);
757 btrfs_tree_read_unlock(eb);
758 free_extent_buffer(eb);
761 btrfs_set_header_bytenr(eb_rewin, eb->start);
762 btrfs_set_header_backref_rev(eb_rewin,
763 btrfs_header_backref_rev(eb));
764 btrfs_set_header_owner(eb_rewin, btrfs_header_owner(eb));
765 btrfs_set_header_level(eb_rewin, btrfs_header_level(eb));
767 eb_rewin = btrfs_clone_extent_buffer(eb);
769 btrfs_tree_read_unlock(eb);
770 free_extent_buffer(eb);
775 btrfs_tree_read_unlock(eb);
776 free_extent_buffer(eb);
778 btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb_rewin),
779 eb_rewin, btrfs_header_level(eb_rewin));
780 btrfs_tree_read_lock(eb_rewin);
781 tree_mod_log_rewind(fs_info, eb_rewin, time_seq, tm);
782 WARN_ON(btrfs_header_nritems(eb_rewin) >
783 BTRFS_NODEPTRS_PER_BLOCK(fs_info));
789 * Rewind the state of @root's root node to the given @time_seq value.
790 * If there are no changes, the current root->root_node is returned. If anything
791 * changed in between, there's a fresh buffer allocated on which the rewind
792 * operations are done. In any case, the returned buffer is read locked.
793 * Returns NULL on error (with no locks held).
795 struct extent_buffer *btrfs_get_old_root(struct btrfs_root *root, u64 time_seq)
797 struct btrfs_fs_info *fs_info = root->fs_info;
798 struct tree_mod_elem *tm;
799 struct extent_buffer *eb = NULL;
800 struct extent_buffer *eb_root;
801 u64 eb_root_owner = 0;
802 struct extent_buffer *old;
803 struct tree_mod_root *old_root = NULL;
804 u64 old_generation = 0;
808 eb_root = btrfs_read_lock_root_node(root);
809 tm = tree_mod_log_oldest_root(eb_root, time_seq);
813 if (tm->op == BTRFS_MOD_LOG_ROOT_REPLACE) {
814 old_root = &tm->old_root;
815 old_generation = tm->generation;
816 logical = old_root->logical;
817 level = old_root->level;
819 logical = eb_root->start;
820 level = btrfs_header_level(eb_root);
823 tm = tree_mod_log_search(fs_info, logical, time_seq);
824 if (old_root && tm && tm->op != BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
825 struct btrfs_tree_parent_check check = { 0 };
827 btrfs_tree_read_unlock(eb_root);
828 free_extent_buffer(eb_root);
831 check.owner_root = root->root_key.objectid;
833 old = read_tree_block(fs_info, logical, &check);
834 if (WARN_ON(IS_ERR(old) || !extent_buffer_uptodate(old))) {
836 free_extent_buffer(old);
838 "failed to read tree block %llu from get_old_root",
841 struct tree_mod_elem *tm2;
843 btrfs_tree_read_lock(old);
844 eb = btrfs_clone_extent_buffer(old);
846 * After the lookup for the most recent tree mod operation
847 * above and before we locked and cloned the extent buffer
848 * 'old', a new tree mod log operation may have been added.
849 * So lookup for a more recent one to make sure the number
850 * of mod log operations we replay is consistent with the
851 * number of items we have in the cloned extent buffer,
852 * otherwise we can hit a BUG_ON when rewinding the extent
855 tm2 = tree_mod_log_search(fs_info, logical, time_seq);
856 btrfs_tree_read_unlock(old);
857 free_extent_buffer(old);
859 ASSERT(tm2 == tm || tm2->seq > tm->seq);
860 if (!tm2 || tm2->seq < tm->seq) {
861 free_extent_buffer(eb);
866 } else if (old_root) {
867 eb_root_owner = btrfs_header_owner(eb_root);
868 btrfs_tree_read_unlock(eb_root);
869 free_extent_buffer(eb_root);
870 eb = alloc_dummy_extent_buffer(fs_info, logical);
872 eb = btrfs_clone_extent_buffer(eb_root);
873 btrfs_tree_read_unlock(eb_root);
874 free_extent_buffer(eb_root);
880 btrfs_set_header_bytenr(eb, eb->start);
881 btrfs_set_header_backref_rev(eb, BTRFS_MIXED_BACKREF_REV);
882 btrfs_set_header_owner(eb, eb_root_owner);
883 btrfs_set_header_level(eb, old_root->level);
884 btrfs_set_header_generation(eb, old_generation);
886 btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), eb,
887 btrfs_header_level(eb));
888 btrfs_tree_read_lock(eb);
890 tree_mod_log_rewind(fs_info, eb, time_seq, tm);
892 WARN_ON(btrfs_header_level(eb) != 0);
893 WARN_ON(btrfs_header_nritems(eb) > BTRFS_NODEPTRS_PER_BLOCK(fs_info));
898 int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq)
900 struct tree_mod_elem *tm;
902 struct extent_buffer *eb_root = btrfs_root_node(root);
904 tm = tree_mod_log_oldest_root(eb_root, time_seq);
905 if (tm && tm->op == BTRFS_MOD_LOG_ROOT_REPLACE)
906 level = tm->old_root.level;
908 level = btrfs_header_level(eb_root);
910 free_extent_buffer(eb_root);
916 * Return the lowest sequence number in the tree modification log.
918 * Return the sequence number of the oldest tree modification log user, which
919 * corresponds to the lowest sequence number of all existing users. If there are
920 * no users it returns 0.
922 u64 btrfs_tree_mod_log_lowest_seq(struct btrfs_fs_info *fs_info)
926 read_lock(&fs_info->tree_mod_log_lock);
927 if (!list_empty(&fs_info->tree_mod_seq_list)) {
928 struct btrfs_seq_list *elem;
930 elem = list_first_entry(&fs_info->tree_mod_seq_list,
931 struct btrfs_seq_list, list);
934 read_unlock(&fs_info->tree_mod_log_lock);