ctree.c (8632987380765dee716d460640aa58d58d52998e) ctree.c (7a1636089acfee7562fe79aff7d1b4c57869896d)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2007,2008 Oracle. All rights reserved.
4 */
5
6#include <linux/sched.h>
7#include <linux/slab.h>
8#include <linux/rbtree.h>
9#include <linux/mm.h>
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2007,2008 Oracle. All rights reserved.
4 */
5
6#include <linux/sched.h>
7#include <linux/slab.h>
8#include <linux/rbtree.h>
9#include <linux/mm.h>
10#include <linux/error-injection.h>
11#include "ctree.h"
12#include "disk-io.h"
13#include "transaction.h"
14#include "print-tree.h"
15#include "locking.h"
16#include "volumes.h"
17#include "qgroup.h"
18#include "tree-mod-log.h"

--- 439 unchanged lines hidden (view full) ---

458 btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV)
459 parent_start = buf->start;
460
461 atomic_inc(&cow->refs);
462 ret = btrfs_tree_mod_log_insert_root(root->node, cow, true);
463 BUG_ON(ret < 0);
464 rcu_assign_pointer(root->node, cow);
465
10#include "ctree.h"
11#include "disk-io.h"
12#include "transaction.h"
13#include "print-tree.h"
14#include "locking.h"
15#include "volumes.h"
16#include "qgroup.h"
17#include "tree-mod-log.h"

--- 439 unchanged lines hidden (view full) ---

457 btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV)
458 parent_start = buf->start;
459
460 atomic_inc(&cow->refs);
461 ret = btrfs_tree_mod_log_insert_root(root->node, cow, true);
462 BUG_ON(ret < 0);
463 rcu_assign_pointer(root->node, cow);
464
466 btrfs_free_tree_block(trans, root, buf, parent_start,
467 last_ref);
465 btrfs_free_tree_block(trans, btrfs_root_id(root), buf,
466 parent_start, last_ref);
468 free_extent_buffer(buf);
469 add_root_to_dirty_list(root);
470 } else {
471 WARN_ON(trans->transid != btrfs_header_generation(parent));
472 btrfs_tree_mod_log_insert_key(parent, parent_slot,
473 BTRFS_MOD_LOG_KEY_REPLACE, GFP_NOFS);
474 btrfs_set_node_blockptr(parent, parent_slot,
475 cow->start);

--- 4 unchanged lines hidden (view full) ---

480 ret = btrfs_tree_mod_log_free_eb(buf);
481 if (ret) {
482 btrfs_tree_unlock(cow);
483 free_extent_buffer(cow);
484 btrfs_abort_transaction(trans, ret);
485 return ret;
486 }
487 }
467 free_extent_buffer(buf);
468 add_root_to_dirty_list(root);
469 } else {
470 WARN_ON(trans->transid != btrfs_header_generation(parent));
471 btrfs_tree_mod_log_insert_key(parent, parent_slot,
472 BTRFS_MOD_LOG_KEY_REPLACE, GFP_NOFS);
473 btrfs_set_node_blockptr(parent, parent_slot,
474 cow->start);

--- 4 unchanged lines hidden (view full) ---

479 ret = btrfs_tree_mod_log_free_eb(buf);
480 if (ret) {
481 btrfs_tree_unlock(cow);
482 free_extent_buffer(cow);
483 btrfs_abort_transaction(trans, ret);
484 return ret;
485 }
486 }
488 btrfs_free_tree_block(trans, root, buf, parent_start,
489 last_ref);
487 btrfs_free_tree_block(trans, btrfs_root_id(root), buf,
488 parent_start, last_ref);
490 }
491 if (unlock_orig)
492 btrfs_tree_unlock(buf);
493 free_extent_buffer_stale(buf);
494 btrfs_mark_buffer_dirty(cow);
495 *cow_ret = cow;
496 return 0;
497}

--- 424 unchanged lines hidden (view full) ---

922 path->locks[level] = 0;
923 path->nodes[level] = NULL;
924 btrfs_clean_tree_block(mid);
925 btrfs_tree_unlock(mid);
926 /* once for the path */
927 free_extent_buffer(mid);
928
929 root_sub_used(root, mid->len);
489 }
490 if (unlock_orig)
491 btrfs_tree_unlock(buf);
492 free_extent_buffer_stale(buf);
493 btrfs_mark_buffer_dirty(cow);
494 *cow_ret = cow;
495 return 0;
496}

--- 424 unchanged lines hidden (view full) ---

921 path->locks[level] = 0;
922 path->nodes[level] = NULL;
923 btrfs_clean_tree_block(mid);
924 btrfs_tree_unlock(mid);
925 /* once for the path */
926 free_extent_buffer(mid);
927
928 root_sub_used(root, mid->len);
930 btrfs_free_tree_block(trans, root, mid, 0, 1);
929 btrfs_free_tree_block(trans, btrfs_root_id(root), mid, 0, 1);
931 /* once for the root ptr */
932 free_extent_buffer_stale(mid);
933 return 0;
934 }
935 if (btrfs_header_nritems(mid) >
936 BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)
937 return 0;
938

--- 42 unchanged lines hidden (view full) ---

981 wret = push_node_left(trans, mid, right, 1);
982 if (wret < 0 && wret != -ENOSPC)
983 ret = wret;
984 if (btrfs_header_nritems(right) == 0) {
985 btrfs_clean_tree_block(right);
986 btrfs_tree_unlock(right);
987 del_ptr(root, path, level + 1, pslot + 1);
988 root_sub_used(root, right->len);
930 /* once for the root ptr */
931 free_extent_buffer_stale(mid);
932 return 0;
933 }
934 if (btrfs_header_nritems(mid) >
935 BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)
936 return 0;
937

--- 42 unchanged lines hidden (view full) ---

980 wret = push_node_left(trans, mid, right, 1);
981 if (wret < 0 && wret != -ENOSPC)
982 ret = wret;
983 if (btrfs_header_nritems(right) == 0) {
984 btrfs_clean_tree_block(right);
985 btrfs_tree_unlock(right);
986 del_ptr(root, path, level + 1, pslot + 1);
987 root_sub_used(root, right->len);
989 btrfs_free_tree_block(trans, root, right, 0, 1);
988 btrfs_free_tree_block(trans, btrfs_root_id(root), right,
989 0, 1);
990 free_extent_buffer_stale(right);
991 right = NULL;
992 } else {
993 struct btrfs_disk_key right_key;
994 btrfs_node_key(right, &right_key, 0);
995 ret = btrfs_tree_mod_log_insert_key(parent, pslot + 1,
996 BTRFS_MOD_LOG_KEY_REPLACE, GFP_NOFS);
997 BUG_ON(ret < 0);

--- 28 unchanged lines hidden (view full) ---

1026 }
1027 BUG_ON(wret == 1);
1028 }
1029 if (btrfs_header_nritems(mid) == 0) {
1030 btrfs_clean_tree_block(mid);
1031 btrfs_tree_unlock(mid);
1032 del_ptr(root, path, level + 1, pslot);
1033 root_sub_used(root, mid->len);
990 free_extent_buffer_stale(right);
991 right = NULL;
992 } else {
993 struct btrfs_disk_key right_key;
994 btrfs_node_key(right, &right_key, 0);
995 ret = btrfs_tree_mod_log_insert_key(parent, pslot + 1,
996 BTRFS_MOD_LOG_KEY_REPLACE, GFP_NOFS);
997 BUG_ON(ret < 0);

--- 28 unchanged lines hidden (view full) ---

1026 }
1027 BUG_ON(wret == 1);
1028 }
1029 if (btrfs_header_nritems(mid) == 0) {
1030 btrfs_clean_tree_block(mid);
1031 btrfs_tree_unlock(mid);
1032 del_ptr(root, path, level + 1, pslot);
1033 root_sub_used(root, mid->len);
1034 btrfs_free_tree_block(trans, root, mid, 0, 1);
1034 btrfs_free_tree_block(trans, btrfs_root_id(root), mid, 0, 1);
1035 free_extent_buffer_stale(mid);
1036 mid = NULL;
1037 } else {
1038 /* update the parent key to reflect our changes */
1039 struct btrfs_disk_key mid_key;
1040 btrfs_node_key(mid, &mid_key, 0);
1041 ret = btrfs_tree_mod_log_insert_key(parent, pslot,
1042 BTRFS_MOD_LOG_KEY_REPLACE, GFP_NOFS);

--- 2984 unchanged lines hidden (view full) ---

4027 * btrfs_free_extent is expensive, we want to make sure we
4028 * aren't holding any locks when we call it
4029 */
4030 btrfs_unlock_up_safe(path, 0);
4031
4032 root_sub_used(root, leaf->len);
4033
4034 atomic_inc(&leaf->refs);
1035 free_extent_buffer_stale(mid);
1036 mid = NULL;
1037 } else {
1038 /* update the parent key to reflect our changes */
1039 struct btrfs_disk_key mid_key;
1040 btrfs_node_key(mid, &mid_key, 0);
1041 ret = btrfs_tree_mod_log_insert_key(parent, pslot,
1042 BTRFS_MOD_LOG_KEY_REPLACE, GFP_NOFS);

--- 2984 unchanged lines hidden (view full) ---

4027 * btrfs_free_extent is expensive, we want to make sure we
4028 * aren't holding any locks when we call it
4029 */
4030 btrfs_unlock_up_safe(path, 0);
4031
4032 root_sub_used(root, leaf->len);
4033
4034 atomic_inc(&leaf->refs);
4035 btrfs_free_tree_block(trans, root, leaf, 0, 1);
4035 btrfs_free_tree_block(trans, btrfs_root_id(root), leaf, 0, 1);
4036 free_extent_buffer_stale(leaf);
4037}
4038/*
4039 * delete the item at the leaf level in path. If that empties
4040 * the leaf, remove it from the tree
4041 */
4042int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
4043 struct btrfs_path *path, int slot, int nr)

--- 595 unchanged lines hidden ---
4036 free_extent_buffer_stale(leaf);
4037}
4038/*
4039 * delete the item at the leaf level in path. If that empties
4040 * the leaf, remove it from the tree
4041 */
4042int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
4043 struct btrfs_path *path, int slot, int nr)

--- 595 unchanged lines hidden ---