backref.c (4e4488d4efd56951e6c1c0f60f1fc8e0f93b7964) backref.c (e2fd83064a9bae368ce1c88a0cb9aee64ad4e124)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2011 STRATO. All rights reserved.
4 */
5
6#include <linux/mm.h>
7#include <linux/rbtree.h>
8#include <trace/events/btrfs.h>

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

1867 .inum = btrfs_ino(inode),
1868 .data_bytenr = bytenr,
1869 .data_extent_gen = extent_gen,
1870 .share_count = 0,
1871 .self_ref_count = 0,
1872 .have_delayed_delete_refs = false,
1873 };
1874 int level;
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2011 STRATO. All rights reserved.
4 */
5
6#include <linux/mm.h>
7#include <linux/rbtree.h>
8#include <trace/events/btrfs.h>

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

1867 .inum = btrfs_ino(inode),
1868 .data_bytenr = bytenr,
1869 .data_extent_gen = extent_gen,
1870 .share_count = 0,
1871 .self_ref_count = 0,
1872 .have_delayed_delete_refs = false,
1873 };
1874 int level;
1875 bool leaf_cached;
1876 bool leaf_is_shared;
1875
1876 for (int i = 0; i < BTRFS_BACKREF_CTX_PREV_EXTENTS_SIZE; i++) {
1877 if (ctx->prev_extents_cache[i].bytenr == bytenr)
1878 return ctx->prev_extents_cache[i].is_shared;
1879 }
1880
1881 ulist_init(&ctx->refs);
1882

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

1888 }
1889 trans = NULL;
1890 down_read(&fs_info->commit_root_sem);
1891 } else {
1892 btrfs_get_tree_mod_seq(fs_info, &elem);
1893 walk_ctx.time_seq = elem.seq;
1894 }
1895
1877
1878 for (int i = 0; i < BTRFS_BACKREF_CTX_PREV_EXTENTS_SIZE; i++) {
1879 if (ctx->prev_extents_cache[i].bytenr == bytenr)
1880 return ctx->prev_extents_cache[i].is_shared;
1881 }
1882
1883 ulist_init(&ctx->refs);
1884

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

1890 }
1891 trans = NULL;
1892 down_read(&fs_info->commit_root_sem);
1893 } else {
1894 btrfs_get_tree_mod_seq(fs_info, &elem);
1895 walk_ctx.time_seq = elem.seq;
1896 }
1897
1898 ctx->use_path_cache = true;
1899
1900 /*
1901 * We may have previously determined that the current leaf is shared.
1902 * If it is, then we have a data extent that is shared due to a shared
1903 * subtree (caused by snapshotting) and we don't need to check for data
1904 * backrefs. If the leaf is not shared, then we must do backref walking
1905 * to determine if the data extent is shared through reflinks.
1906 */
1907 leaf_cached = lookup_backref_shared_cache(ctx, root,
1908 ctx->curr_leaf_bytenr, 0,
1909 &leaf_is_shared);
1910 if (leaf_cached && leaf_is_shared) {
1911 ret = 1;
1912 goto out_trans;
1913 }
1914
1896 walk_ctx.ignore_extent_item_pos = true;
1897 walk_ctx.trans = trans;
1898 walk_ctx.fs_info = fs_info;
1899 walk_ctx.refs = &ctx->refs;
1900
1901 /* -1 means we are in the bytenr of the data extent. */
1902 level = -1;
1903 ULIST_ITER_INIT(&uiter);
1915 walk_ctx.ignore_extent_item_pos = true;
1916 walk_ctx.trans = trans;
1917 walk_ctx.fs_info = fs_info;
1918 walk_ctx.refs = &ctx->refs;
1919
1920 /* -1 means we are in the bytenr of the data extent. */
1921 level = -1;
1922 ULIST_ITER_INIT(&uiter);
1904 ctx->use_path_cache = true;
1905 while (1) {
1906 bool is_shared;
1907 bool cached;
1908
1909 walk_ctx.bytenr = bytenr;
1910 ret = find_parent_nodes(&walk_ctx, &shared);
1911 if (ret == BACKREF_FOUND_SHARED ||
1912 ret == BACKREF_FOUND_NOT_SHARED) {

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

1967
1968 ctx->prev_extents_cache[slot].bytenr = shared.data_bytenr;
1969 ctx->prev_extents_cache[slot].is_shared = (ret == 1);
1970
1971 slot = (slot + 1) % BTRFS_BACKREF_CTX_PREV_EXTENTS_SIZE;
1972 ctx->prev_extents_cache_slot = slot;
1973 }
1974
1923 while (1) {
1924 bool is_shared;
1925 bool cached;
1926
1927 walk_ctx.bytenr = bytenr;
1928 ret = find_parent_nodes(&walk_ctx, &shared);
1929 if (ret == BACKREF_FOUND_SHARED ||
1930 ret == BACKREF_FOUND_NOT_SHARED) {

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

1985
1986 ctx->prev_extents_cache[slot].bytenr = shared.data_bytenr;
1987 ctx->prev_extents_cache[slot].is_shared = (ret == 1);
1988
1989 slot = (slot + 1) % BTRFS_BACKREF_CTX_PREV_EXTENTS_SIZE;
1990 ctx->prev_extents_cache_slot = slot;
1991 }
1992
1993out_trans:
1975 if (trans) {
1976 btrfs_put_tree_mod_seq(fs_info, &elem);
1977 btrfs_end_transaction(trans);
1978 } else {
1979 up_read(&fs_info->commit_root_sem);
1980 }
1981out:
1982 ulist_release(&ctx->refs);

--- 1606 unchanged lines hidden ---
1994 if (trans) {
1995 btrfs_put_tree_mod_seq(fs_info, &elem);
1996 btrfs_end_transaction(trans);
1997 } else {
1998 up_read(&fs_info->commit_root_sem);
1999 }
2000out:
2001 ulist_release(&ctx->refs);

--- 1606 unchanged lines hidden ---