backref.c (12a824dc67a61ec02ad2960f1856654febcd5d9d) backref.c (b8f164e3e67f224f1751b708e66ccebcce1864c4)
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>

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

1608 entry->gen = gen;
1609 }
1610 }
1611}
1612
1613/*
1614 * Check if a data extent is shared or not.
1615 *
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>

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

1608 entry->gen = gen;
1609 }
1610 }
1611}
1612
1613/*
1614 * Check if a data extent is shared or not.
1615 *
1616 * @root: root inode belongs to
1617 * @inum: inode number of the inode whose extent we are checking
1618 * @bytenr: logical bytenr of the extent we are checking
1619 * @roots: list of roots this extent is shared among
1620 * @tmp: temporary list used for iteration
1621 * @cache: a backref lookup result cache
1616 * @root: The root the inode belongs to.
1617 * @inum: Number of the inode whose extent we are checking.
1618 * @bytenr: Logical bytenr of the extent we are checking.
1619 * @extent_gen: Generation of the extent (file extent item) or 0 if it is
1620 * not known.
1621 * @roots: List of roots this extent is shared among.
1622 * @tmp: Temporary list used for iteration.
1623 * @cache: A backref lookup result cache.
1622 *
1623 * btrfs_is_data_extent_shared uses the backref walking code but will short
1624 * circuit as soon as it finds a root or inode that doesn't match the
1625 * one passed in. This provides a significant performance benefit for
1626 * callers (such as fiemap) which want to know whether the extent is
1627 * shared but do not need a ref count.
1628 *
1629 * This attempts to attach to the running transaction in order to account for
1630 * delayed refs, but continues on even when no running transaction exists.
1631 *
1632 * Return: 0 if extent is not shared, 1 if it is shared, < 0 on error.
1633 */
1634int btrfs_is_data_extent_shared(struct btrfs_root *root, u64 inum, u64 bytenr,
1624 *
1625 * btrfs_is_data_extent_shared uses the backref walking code but will short
1626 * circuit as soon as it finds a root or inode that doesn't match the
1627 * one passed in. This provides a significant performance benefit for
1628 * callers (such as fiemap) which want to know whether the extent is
1629 * shared but do not need a ref count.
1630 *
1631 * This attempts to attach to the running transaction in order to account for
1632 * delayed refs, but continues on even when no running transaction exists.
1633 *
1634 * Return: 0 if extent is not shared, 1 if it is shared, < 0 on error.
1635 */
1636int btrfs_is_data_extent_shared(struct btrfs_root *root, u64 inum, u64 bytenr,
1637 u64 extent_gen,
1635 struct ulist *roots, struct ulist *tmp,
1636 struct btrfs_backref_shared_cache *cache)
1637{
1638 struct btrfs_fs_info *fs_info = root->fs_info;
1639 struct btrfs_trans_handle *trans;
1640 struct ulist_iterator uiter;
1641 struct ulist_node *node;
1642 struct btrfs_seq_list elem = BTRFS_SEQ_LIST_INIT(elem);

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

1678 if (level >= 0)
1679 store_backref_shared_cache(cache, root, bytenr,
1680 level, true);
1681 break;
1682 }
1683 if (ret < 0 && ret != -ENOENT)
1684 break;
1685 ret = 0;
1638 struct ulist *roots, struct ulist *tmp,
1639 struct btrfs_backref_shared_cache *cache)
1640{
1641 struct btrfs_fs_info *fs_info = root->fs_info;
1642 struct btrfs_trans_handle *trans;
1643 struct ulist_iterator uiter;
1644 struct ulist_node *node;
1645 struct btrfs_seq_list elem = BTRFS_SEQ_LIST_INIT(elem);

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

1681 if (level >= 0)
1682 store_backref_shared_cache(cache, root, bytenr,
1683 level, true);
1684 break;
1685 }
1686 if (ret < 0 && ret != -ENOENT)
1687 break;
1688 ret = 0;
1689 /*
1690 * If our data extent is not shared through reflinks and it was
1691 * created in a generation after the last one used to create a
1692 * snapshot of the inode's root, then it can not be shared
1693 * indirectly through subtrees, as that can only happen with
1694 * snapshots. In this case bail out, no need to check for the
1695 * sharedness of extent buffers.
1696 */
1697 if (level == -1 &&
1698 extent_gen > btrfs_root_last_snapshot(&root->root_item))
1699 break;
1700
1686 if (level >= 0)
1687 store_backref_shared_cache(cache, root, bytenr,
1688 level, false);
1689 node = ulist_next(tmp, &uiter);
1690 if (!node)
1691 break;
1692 bytenr = node->val;
1693 level++;

--- 1575 unchanged lines hidden ---
1701 if (level >= 0)
1702 store_backref_shared_cache(cache, root, bytenr,
1703 level, false);
1704 node = ulist_next(tmp, &uiter);
1705 if (!node)
1706 break;
1707 bytenr = node->val;
1708 level++;

--- 1575 unchanged lines hidden ---