18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2007 Oracle.  All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef BTRFS_CTREE_H
78c2ecf20Sopenharmony_ci#define BTRFS_CTREE_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/mm.h>
108c2ecf20Sopenharmony_ci#include <linux/sched/signal.h>
118c2ecf20Sopenharmony_ci#include <linux/highmem.h>
128c2ecf20Sopenharmony_ci#include <linux/fs.h>
138c2ecf20Sopenharmony_ci#include <linux/rwsem.h>
148c2ecf20Sopenharmony_ci#include <linux/semaphore.h>
158c2ecf20Sopenharmony_ci#include <linux/completion.h>
168c2ecf20Sopenharmony_ci#include <linux/backing-dev.h>
178c2ecf20Sopenharmony_ci#include <linux/wait.h>
188c2ecf20Sopenharmony_ci#include <linux/slab.h>
198c2ecf20Sopenharmony_ci#include <trace/events/btrfs.h>
208c2ecf20Sopenharmony_ci#include <asm/kmap_types.h>
218c2ecf20Sopenharmony_ci#include <asm/unaligned.h>
228c2ecf20Sopenharmony_ci#include <linux/pagemap.h>
238c2ecf20Sopenharmony_ci#include <linux/btrfs.h>
248c2ecf20Sopenharmony_ci#include <linux/btrfs_tree.h>
258c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
268c2ecf20Sopenharmony_ci#include <linux/security.h>
278c2ecf20Sopenharmony_ci#include <linux/sizes.h>
288c2ecf20Sopenharmony_ci#include <linux/dynamic_debug.h>
298c2ecf20Sopenharmony_ci#include <linux/refcount.h>
308c2ecf20Sopenharmony_ci#include <linux/crc32c.h>
318c2ecf20Sopenharmony_ci#include "extent-io-tree.h"
328c2ecf20Sopenharmony_ci#include "extent_io.h"
338c2ecf20Sopenharmony_ci#include "extent_map.h"
348c2ecf20Sopenharmony_ci#include "async-thread.h"
358c2ecf20Sopenharmony_ci#include "block-rsv.h"
368c2ecf20Sopenharmony_ci#include "locking.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct btrfs_trans_handle;
398c2ecf20Sopenharmony_cistruct btrfs_transaction;
408c2ecf20Sopenharmony_cistruct btrfs_pending_snapshot;
418c2ecf20Sopenharmony_cistruct btrfs_delayed_ref_root;
428c2ecf20Sopenharmony_cistruct btrfs_space_info;
438c2ecf20Sopenharmony_cistruct btrfs_block_group;
448c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_trans_handle_cachep;
458c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_bit_radix_cachep;
468c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_path_cachep;
478c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_free_space_cachep;
488c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_free_space_bitmap_cachep;
498c2ecf20Sopenharmony_cistruct btrfs_ordered_sum;
508c2ecf20Sopenharmony_cistruct btrfs_ref;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/*
558c2ecf20Sopenharmony_ci * Maximum number of mirrors that can be available for all profiles counting
568c2ecf20Sopenharmony_ci * the target device of dev-replace as one. During an active device replace
578c2ecf20Sopenharmony_ci * procedure, the target device of the copy operation is a mirror for the
588c2ecf20Sopenharmony_ci * filesystem data as well that can be used to read data in order to repair
598c2ecf20Sopenharmony_ci * read errors on other disks.
608c2ecf20Sopenharmony_ci *
618c2ecf20Sopenharmony_ci * Current value is derived from RAID1C4 with 4 copies.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ci#define BTRFS_MAX_MIRRORS (4 + 1)
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define BTRFS_MAX_LEVEL 8
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define BTRFS_OLDEST_GENERATION	0ULL
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/*
708c2ecf20Sopenharmony_ci * the max metadata block size.  This limit is somewhat artificial,
718c2ecf20Sopenharmony_ci * but the memmove costs go through the roof for larger blocks.
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_ci#define BTRFS_MAX_METADATA_BLOCKSIZE 65536
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/*
768c2ecf20Sopenharmony_ci * we can actually store much bigger names, but lets not confuse the rest
778c2ecf20Sopenharmony_ci * of linux
788c2ecf20Sopenharmony_ci */
798c2ecf20Sopenharmony_ci#define BTRFS_NAME_LEN 255
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * Theoretical limit is larger, but we keep this down to a sane
838c2ecf20Sopenharmony_ci * value. That should limit greatly the possibility of collisions on
848c2ecf20Sopenharmony_ci * inode ref items.
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_ci#define BTRFS_LINK_MAX 65535U
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define BTRFS_EMPTY_DIR_SIZE 0
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* ioprio of readahead is set to idle */
918c2ecf20Sopenharmony_ci#define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0))
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define BTRFS_DIRTY_METADATA_THRESH	SZ_32M
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/*
968c2ecf20Sopenharmony_ci * Use large batch size to reduce overhead of metadata updates.  On the reader
978c2ecf20Sopenharmony_ci * side, we only read it when we are close to ENOSPC and the read overhead is
988c2ecf20Sopenharmony_ci * mostly related to the number of CPUs, so it is OK to use arbitrary large
998c2ecf20Sopenharmony_ci * value here.
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_ci#define BTRFS_TOTAL_BYTES_PINNED_BATCH	SZ_128M
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define BTRFS_MAX_EXTENT_SIZE SZ_128M
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/*
1068c2ecf20Sopenharmony_ci * Deltas are an effective way to populate global statistics.  Give macro names
1078c2ecf20Sopenharmony_ci * to make it clear what we're doing.  An example is discard_extents in
1088c2ecf20Sopenharmony_ci * btrfs_free_space_ctl.
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ci#define BTRFS_STAT_NR_ENTRIES	2
1118c2ecf20Sopenharmony_ci#define BTRFS_STAT_CURR		0
1128c2ecf20Sopenharmony_ci#define BTRFS_STAT_PREV		1
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci/*
1158c2ecf20Sopenharmony_ci * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistatic inline u32 count_max_extents(u64 size)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
1208c2ecf20Sopenharmony_ci}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic inline unsigned long btrfs_chunk_item_size(int num_stripes)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	BUG_ON(num_stripes == 0);
1258c2ecf20Sopenharmony_ci	return sizeof(struct btrfs_chunk) +
1268c2ecf20Sopenharmony_ci		sizeof(struct btrfs_stripe) * (num_stripes - 1);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/*
1308c2ecf20Sopenharmony_ci * Runtime (in-memory) states of filesystem
1318c2ecf20Sopenharmony_ci */
1328c2ecf20Sopenharmony_cienum {
1338c2ecf20Sopenharmony_ci	/* Global indicator of serious filesystem errors */
1348c2ecf20Sopenharmony_ci	BTRFS_FS_STATE_ERROR,
1358c2ecf20Sopenharmony_ci	/*
1368c2ecf20Sopenharmony_ci	 * Filesystem is being remounted, allow to skip some operations, like
1378c2ecf20Sopenharmony_ci	 * defrag
1388c2ecf20Sopenharmony_ci	 */
1398c2ecf20Sopenharmony_ci	BTRFS_FS_STATE_REMOUNTING,
1408c2ecf20Sopenharmony_ci	/* Track if a transaction abort has been reported on this filesystem */
1418c2ecf20Sopenharmony_ci	BTRFS_FS_STATE_TRANS_ABORTED,
1428c2ecf20Sopenharmony_ci	/*
1438c2ecf20Sopenharmony_ci	 * Bio operations should be blocked on this filesystem because a source
1448c2ecf20Sopenharmony_ci	 * or target device is being destroyed as part of a device replace
1458c2ecf20Sopenharmony_ci	 */
1468c2ecf20Sopenharmony_ci	BTRFS_FS_STATE_DEV_REPLACING,
1478c2ecf20Sopenharmony_ci	/* The btrfs_fs_info created for self-tests */
1488c2ecf20Sopenharmony_ci	BTRFS_FS_STATE_DUMMY_FS_INFO,
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#define BTRFS_BACKREF_REV_MAX		256
1528c2ecf20Sopenharmony_ci#define BTRFS_BACKREF_REV_SHIFT		56
1538c2ecf20Sopenharmony_ci#define BTRFS_BACKREF_REV_MASK		(((u64)BTRFS_BACKREF_REV_MAX - 1) << \
1548c2ecf20Sopenharmony_ci					 BTRFS_BACKREF_REV_SHIFT)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#define BTRFS_OLD_BACKREF_REV		0
1578c2ecf20Sopenharmony_ci#define BTRFS_MIXED_BACKREF_REV		1
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci/*
1608c2ecf20Sopenharmony_ci * every tree block (leaf or node) starts with this header.
1618c2ecf20Sopenharmony_ci */
1628c2ecf20Sopenharmony_cistruct btrfs_header {
1638c2ecf20Sopenharmony_ci	/* these first four must match the super block */
1648c2ecf20Sopenharmony_ci	u8 csum[BTRFS_CSUM_SIZE];
1658c2ecf20Sopenharmony_ci	u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
1668c2ecf20Sopenharmony_ci	__le64 bytenr; /* which block this node is supposed to live in */
1678c2ecf20Sopenharmony_ci	__le64 flags;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	/* allowed to be different from the super from here on down */
1708c2ecf20Sopenharmony_ci	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
1718c2ecf20Sopenharmony_ci	__le64 generation;
1728c2ecf20Sopenharmony_ci	__le64 owner;
1738c2ecf20Sopenharmony_ci	__le32 nritems;
1748c2ecf20Sopenharmony_ci	u8 level;
1758c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci/*
1788c2ecf20Sopenharmony_ci * this is a very generous portion of the super block, giving us
1798c2ecf20Sopenharmony_ci * room to translate 14 chunks with 3 stripes each.
1808c2ecf20Sopenharmony_ci */
1818c2ecf20Sopenharmony_ci#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/*
1848c2ecf20Sopenharmony_ci * just in case we somehow lose the roots and are not able to mount,
1858c2ecf20Sopenharmony_ci * we store an array of the roots from previous transactions
1868c2ecf20Sopenharmony_ci * in the super.
1878c2ecf20Sopenharmony_ci */
1888c2ecf20Sopenharmony_ci#define BTRFS_NUM_BACKUP_ROOTS 4
1898c2ecf20Sopenharmony_cistruct btrfs_root_backup {
1908c2ecf20Sopenharmony_ci	__le64 tree_root;
1918c2ecf20Sopenharmony_ci	__le64 tree_root_gen;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	__le64 chunk_root;
1948c2ecf20Sopenharmony_ci	__le64 chunk_root_gen;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	__le64 extent_root;
1978c2ecf20Sopenharmony_ci	__le64 extent_root_gen;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	__le64 fs_root;
2008c2ecf20Sopenharmony_ci	__le64 fs_root_gen;
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	__le64 dev_root;
2038c2ecf20Sopenharmony_ci	__le64 dev_root_gen;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	__le64 csum_root;
2068c2ecf20Sopenharmony_ci	__le64 csum_root_gen;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	__le64 total_bytes;
2098c2ecf20Sopenharmony_ci	__le64 bytes_used;
2108c2ecf20Sopenharmony_ci	__le64 num_devices;
2118c2ecf20Sopenharmony_ci	/* future */
2128c2ecf20Sopenharmony_ci	__le64 unused_64[4];
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	u8 tree_root_level;
2158c2ecf20Sopenharmony_ci	u8 chunk_root_level;
2168c2ecf20Sopenharmony_ci	u8 extent_root_level;
2178c2ecf20Sopenharmony_ci	u8 fs_root_level;
2188c2ecf20Sopenharmony_ci	u8 dev_root_level;
2198c2ecf20Sopenharmony_ci	u8 csum_root_level;
2208c2ecf20Sopenharmony_ci	/* future and to align */
2218c2ecf20Sopenharmony_ci	u8 unused_8[10];
2228c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci/*
2258c2ecf20Sopenharmony_ci * the super block basically lists the main trees of the FS
2268c2ecf20Sopenharmony_ci * it currently lacks any block count etc etc
2278c2ecf20Sopenharmony_ci */
2288c2ecf20Sopenharmony_cistruct btrfs_super_block {
2298c2ecf20Sopenharmony_ci	/* the first 4 fields must match struct btrfs_header */
2308c2ecf20Sopenharmony_ci	u8 csum[BTRFS_CSUM_SIZE];
2318c2ecf20Sopenharmony_ci	/* FS specific UUID, visible to user */
2328c2ecf20Sopenharmony_ci	u8 fsid[BTRFS_FSID_SIZE];
2338c2ecf20Sopenharmony_ci	__le64 bytenr; /* this block number */
2348c2ecf20Sopenharmony_ci	__le64 flags;
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	/* allowed to be different from the btrfs_header from here own down */
2378c2ecf20Sopenharmony_ci	__le64 magic;
2388c2ecf20Sopenharmony_ci	__le64 generation;
2398c2ecf20Sopenharmony_ci	__le64 root;
2408c2ecf20Sopenharmony_ci	__le64 chunk_root;
2418c2ecf20Sopenharmony_ci	__le64 log_root;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	/* this will help find the new super based on the log root */
2448c2ecf20Sopenharmony_ci	__le64 log_root_transid;
2458c2ecf20Sopenharmony_ci	__le64 total_bytes;
2468c2ecf20Sopenharmony_ci	__le64 bytes_used;
2478c2ecf20Sopenharmony_ci	__le64 root_dir_objectid;
2488c2ecf20Sopenharmony_ci	__le64 num_devices;
2498c2ecf20Sopenharmony_ci	__le32 sectorsize;
2508c2ecf20Sopenharmony_ci	__le32 nodesize;
2518c2ecf20Sopenharmony_ci	__le32 __unused_leafsize;
2528c2ecf20Sopenharmony_ci	__le32 stripesize;
2538c2ecf20Sopenharmony_ci	__le32 sys_chunk_array_size;
2548c2ecf20Sopenharmony_ci	__le64 chunk_root_generation;
2558c2ecf20Sopenharmony_ci	__le64 compat_flags;
2568c2ecf20Sopenharmony_ci	__le64 compat_ro_flags;
2578c2ecf20Sopenharmony_ci	__le64 incompat_flags;
2588c2ecf20Sopenharmony_ci	__le16 csum_type;
2598c2ecf20Sopenharmony_ci	u8 root_level;
2608c2ecf20Sopenharmony_ci	u8 chunk_root_level;
2618c2ecf20Sopenharmony_ci	u8 log_root_level;
2628c2ecf20Sopenharmony_ci	struct btrfs_dev_item dev_item;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	char label[BTRFS_LABEL_SIZE];
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	__le64 cache_generation;
2678c2ecf20Sopenharmony_ci	__le64 uuid_tree_generation;
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	/* the UUID written into btree blocks */
2708c2ecf20Sopenharmony_ci	u8 metadata_uuid[BTRFS_FSID_SIZE];
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	/* future expansion */
2738c2ecf20Sopenharmony_ci	__le64 reserved[28];
2748c2ecf20Sopenharmony_ci	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
2758c2ecf20Sopenharmony_ci	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
2768c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci/*
2798c2ecf20Sopenharmony_ci * Compat flags that we support.  If any incompat flags are set other than the
2808c2ecf20Sopenharmony_ci * ones specified below then we will fail to mount
2818c2ecf20Sopenharmony_ci */
2828c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_COMPAT_SUPP		0ULL
2838c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_COMPAT_SAFE_SET		0ULL
2848c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR		0ULL
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_COMPAT_RO_SUPP			\
2878c2ecf20Sopenharmony_ci	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
2888c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET	0ULL
2918c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR	0ULL
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_INCOMPAT_SUPP			\
2948c2ecf20Sopenharmony_ci	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
2958c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
2968c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
2978c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_BIG_METADATA |		\
2988c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
2998c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD |		\
3008c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_RAID56 |		\
3018c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |		\
3028c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |	\
3038c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_NO_HOLES	|	\
3048c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID	|	\
3058c2ecf20Sopenharmony_ci	 BTRFS_FEATURE_INCOMPAT_RAID1C34)
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_INCOMPAT_SAFE_SET			\
3088c2ecf20Sopenharmony_ci	(BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
3098c2ecf20Sopenharmony_ci#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR		0ULL
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci/*
3128c2ecf20Sopenharmony_ci * A leaf is full of items. offset and size tell us where to find
3138c2ecf20Sopenharmony_ci * the item in the leaf (relative to the start of the data area)
3148c2ecf20Sopenharmony_ci */
3158c2ecf20Sopenharmony_cistruct btrfs_item {
3168c2ecf20Sopenharmony_ci	struct btrfs_disk_key key;
3178c2ecf20Sopenharmony_ci	__le32 offset;
3188c2ecf20Sopenharmony_ci	__le32 size;
3198c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci/*
3228c2ecf20Sopenharmony_ci * leaves have an item area and a data area:
3238c2ecf20Sopenharmony_ci * [item0, item1....itemN] [free space] [dataN...data1, data0]
3248c2ecf20Sopenharmony_ci *
3258c2ecf20Sopenharmony_ci * The data is separate from the items to get the keys closer together
3268c2ecf20Sopenharmony_ci * during searches.
3278c2ecf20Sopenharmony_ci */
3288c2ecf20Sopenharmony_cistruct btrfs_leaf {
3298c2ecf20Sopenharmony_ci	struct btrfs_header header;
3308c2ecf20Sopenharmony_ci	struct btrfs_item items[];
3318c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/*
3348c2ecf20Sopenharmony_ci * all non-leaf blocks are nodes, they hold only keys and pointers to
3358c2ecf20Sopenharmony_ci * other blocks
3368c2ecf20Sopenharmony_ci */
3378c2ecf20Sopenharmony_cistruct btrfs_key_ptr {
3388c2ecf20Sopenharmony_ci	struct btrfs_disk_key key;
3398c2ecf20Sopenharmony_ci	__le64 blockptr;
3408c2ecf20Sopenharmony_ci	__le64 generation;
3418c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistruct btrfs_node {
3448c2ecf20Sopenharmony_ci	struct btrfs_header header;
3458c2ecf20Sopenharmony_ci	struct btrfs_key_ptr ptrs[];
3468c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci/*
3498c2ecf20Sopenharmony_ci * btrfs_paths remember the path taken from the root down to the leaf.
3508c2ecf20Sopenharmony_ci * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
3518c2ecf20Sopenharmony_ci * to any other levels that are present.
3528c2ecf20Sopenharmony_ci *
3538c2ecf20Sopenharmony_ci * The slots array records the index of the item or block pointer
3548c2ecf20Sopenharmony_ci * used while walking the tree.
3558c2ecf20Sopenharmony_ci */
3568c2ecf20Sopenharmony_cienum { READA_NONE, READA_BACK, READA_FORWARD };
3578c2ecf20Sopenharmony_cistruct btrfs_path {
3588c2ecf20Sopenharmony_ci	struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
3598c2ecf20Sopenharmony_ci	int slots[BTRFS_MAX_LEVEL];
3608c2ecf20Sopenharmony_ci	/* if there is real range locking, this locks field will change */
3618c2ecf20Sopenharmony_ci	u8 locks[BTRFS_MAX_LEVEL];
3628c2ecf20Sopenharmony_ci	u8 reada;
3638c2ecf20Sopenharmony_ci	/* keep some upper locks as we walk down */
3648c2ecf20Sopenharmony_ci	u8 lowest_level;
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	/*
3678c2ecf20Sopenharmony_ci	 * set by btrfs_split_item, tells search_slot to keep all locks
3688c2ecf20Sopenharmony_ci	 * and to force calls to keep space in the nodes
3698c2ecf20Sopenharmony_ci	 */
3708c2ecf20Sopenharmony_ci	unsigned int search_for_split:1;
3718c2ecf20Sopenharmony_ci	unsigned int keep_locks:1;
3728c2ecf20Sopenharmony_ci	unsigned int skip_locking:1;
3738c2ecf20Sopenharmony_ci	unsigned int leave_spinning:1;
3748c2ecf20Sopenharmony_ci	unsigned int search_commit_root:1;
3758c2ecf20Sopenharmony_ci	unsigned int need_commit_sem:1;
3768c2ecf20Sopenharmony_ci	unsigned int skip_release_on_error:1;
3778c2ecf20Sopenharmony_ci	unsigned int recurse:1;
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci#define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \
3808c2ecf20Sopenharmony_ci					sizeof(struct btrfs_item))
3818c2ecf20Sopenharmony_cistruct btrfs_dev_replace {
3828c2ecf20Sopenharmony_ci	u64 replace_state;	/* see #define above */
3838c2ecf20Sopenharmony_ci	time64_t time_started;	/* seconds since 1-Jan-1970 */
3848c2ecf20Sopenharmony_ci	time64_t time_stopped;	/* seconds since 1-Jan-1970 */
3858c2ecf20Sopenharmony_ci	atomic64_t num_write_errors;
3868c2ecf20Sopenharmony_ci	atomic64_t num_uncorrectable_read_errors;
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	u64 cursor_left;
3898c2ecf20Sopenharmony_ci	u64 committed_cursor_left;
3908c2ecf20Sopenharmony_ci	u64 cursor_left_last_write_of_item;
3918c2ecf20Sopenharmony_ci	u64 cursor_right;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	u64 cont_reading_from_srcdev_mode;	/* see #define above */
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	int is_valid;
3968c2ecf20Sopenharmony_ci	int item_needs_writeback;
3978c2ecf20Sopenharmony_ci	struct btrfs_device *srcdev;
3988c2ecf20Sopenharmony_ci	struct btrfs_device *tgtdev;
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	struct mutex lock_finishing_cancel_unmount;
4018c2ecf20Sopenharmony_ci	struct rw_semaphore rwsem;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	struct btrfs_scrub_progress scrub_progress;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	struct percpu_counter bio_counter;
4068c2ecf20Sopenharmony_ci	wait_queue_head_t replace_wait;
4078c2ecf20Sopenharmony_ci};
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci/*
4108c2ecf20Sopenharmony_ci * free clusters are used to claim free space in relatively large chunks,
4118c2ecf20Sopenharmony_ci * allowing us to do less seeky writes. They are used for all metadata
4128c2ecf20Sopenharmony_ci * allocations. In ssd_spread mode they are also used for data allocations.
4138c2ecf20Sopenharmony_ci */
4148c2ecf20Sopenharmony_cistruct btrfs_free_cluster {
4158c2ecf20Sopenharmony_ci	spinlock_t lock;
4168c2ecf20Sopenharmony_ci	spinlock_t refill_lock;
4178c2ecf20Sopenharmony_ci	struct rb_root root;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	/* largest extent in this cluster */
4208c2ecf20Sopenharmony_ci	u64 max_size;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	/* first extent starting offset */
4238c2ecf20Sopenharmony_ci	u64 window_start;
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	/* We did a full search and couldn't create a cluster */
4268c2ecf20Sopenharmony_ci	bool fragmented;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	struct btrfs_block_group *block_group;
4298c2ecf20Sopenharmony_ci	/*
4308c2ecf20Sopenharmony_ci	 * when a cluster is allocated from a block group, we put the
4318c2ecf20Sopenharmony_ci	 * cluster onto a list in the block group so that it can
4328c2ecf20Sopenharmony_ci	 * be freed before the block group is freed.
4338c2ecf20Sopenharmony_ci	 */
4348c2ecf20Sopenharmony_ci	struct list_head block_group_list;
4358c2ecf20Sopenharmony_ci};
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cienum btrfs_caching_type {
4388c2ecf20Sopenharmony_ci	BTRFS_CACHE_NO,
4398c2ecf20Sopenharmony_ci	BTRFS_CACHE_STARTED,
4408c2ecf20Sopenharmony_ci	BTRFS_CACHE_FAST,
4418c2ecf20Sopenharmony_ci	BTRFS_CACHE_FINISHED,
4428c2ecf20Sopenharmony_ci	BTRFS_CACHE_ERROR,
4438c2ecf20Sopenharmony_ci};
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci/*
4468c2ecf20Sopenharmony_ci * Tree to record all locked full stripes of a RAID5/6 block group
4478c2ecf20Sopenharmony_ci */
4488c2ecf20Sopenharmony_cistruct btrfs_full_stripe_locks_tree {
4498c2ecf20Sopenharmony_ci	struct rb_root root;
4508c2ecf20Sopenharmony_ci	struct mutex lock;
4518c2ecf20Sopenharmony_ci};
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/* Discard control. */
4548c2ecf20Sopenharmony_ci/*
4558c2ecf20Sopenharmony_ci * Async discard uses multiple lists to differentiate the discard filter
4568c2ecf20Sopenharmony_ci * parameters.  Index 0 is for completely free block groups where we need to
4578c2ecf20Sopenharmony_ci * ensure the entire block group is trimmed without being lossy.  Indices
4588c2ecf20Sopenharmony_ci * afterwards represent monotonically decreasing discard filter sizes to
4598c2ecf20Sopenharmony_ci * prioritize what should be discarded next.
4608c2ecf20Sopenharmony_ci */
4618c2ecf20Sopenharmony_ci#define BTRFS_NR_DISCARD_LISTS		3
4628c2ecf20Sopenharmony_ci#define BTRFS_DISCARD_INDEX_UNUSED	0
4638c2ecf20Sopenharmony_ci#define BTRFS_DISCARD_INDEX_START	1
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistruct btrfs_discard_ctl {
4668c2ecf20Sopenharmony_ci	struct workqueue_struct *discard_workers;
4678c2ecf20Sopenharmony_ci	struct delayed_work work;
4688c2ecf20Sopenharmony_ci	spinlock_t lock;
4698c2ecf20Sopenharmony_ci	struct btrfs_block_group *block_group;
4708c2ecf20Sopenharmony_ci	struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
4718c2ecf20Sopenharmony_ci	u64 prev_discard;
4728c2ecf20Sopenharmony_ci	atomic_t discardable_extents;
4738c2ecf20Sopenharmony_ci	atomic64_t discardable_bytes;
4748c2ecf20Sopenharmony_ci	u64 max_discard_size;
4758c2ecf20Sopenharmony_ci	unsigned long delay;
4768c2ecf20Sopenharmony_ci	u32 iops_limit;
4778c2ecf20Sopenharmony_ci	u32 kbps_limit;
4788c2ecf20Sopenharmony_ci	u64 discard_extent_bytes;
4798c2ecf20Sopenharmony_ci	u64 discard_bitmap_bytes;
4808c2ecf20Sopenharmony_ci	atomic64_t discard_bytes_saved;
4818c2ecf20Sopenharmony_ci};
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci/* delayed seq elem */
4848c2ecf20Sopenharmony_cistruct seq_list {
4858c2ecf20Sopenharmony_ci	struct list_head list;
4868c2ecf20Sopenharmony_ci	u64 seq;
4878c2ecf20Sopenharmony_ci};
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci#define SEQ_LIST_INIT(name)	{ .list = LIST_HEAD_INIT((name).list), .seq = 0 }
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci#define SEQ_LAST	((u64)-1)
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_cienum btrfs_orphan_cleanup_state {
4948c2ecf20Sopenharmony_ci	ORPHAN_CLEANUP_STARTED	= 1,
4958c2ecf20Sopenharmony_ci	ORPHAN_CLEANUP_DONE	= 2,
4968c2ecf20Sopenharmony_ci};
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_civoid btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci/* fs_info */
5018c2ecf20Sopenharmony_cistruct reloc_control;
5028c2ecf20Sopenharmony_cistruct btrfs_device;
5038c2ecf20Sopenharmony_cistruct btrfs_fs_devices;
5048c2ecf20Sopenharmony_cistruct btrfs_balance_control;
5058c2ecf20Sopenharmony_cistruct btrfs_delayed_root;
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci/*
5088c2ecf20Sopenharmony_ci * Block group or device which contains an active swapfile. Used for preventing
5098c2ecf20Sopenharmony_ci * unsafe operations while a swapfile is active.
5108c2ecf20Sopenharmony_ci *
5118c2ecf20Sopenharmony_ci * These are sorted on (ptr, inode) (note that a block group or device can
5128c2ecf20Sopenharmony_ci * contain more than one swapfile). We compare the pointer values because we
5138c2ecf20Sopenharmony_ci * don't actually care what the object is, we just need a quick check whether
5148c2ecf20Sopenharmony_ci * the object exists in the rbtree.
5158c2ecf20Sopenharmony_ci */
5168c2ecf20Sopenharmony_cistruct btrfs_swapfile_pin {
5178c2ecf20Sopenharmony_ci	struct rb_node node;
5188c2ecf20Sopenharmony_ci	void *ptr;
5198c2ecf20Sopenharmony_ci	struct inode *inode;
5208c2ecf20Sopenharmony_ci	/*
5218c2ecf20Sopenharmony_ci	 * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr
5228c2ecf20Sopenharmony_ci	 * points to a struct btrfs_device.
5238c2ecf20Sopenharmony_ci	 */
5248c2ecf20Sopenharmony_ci	bool is_block_group;
5258c2ecf20Sopenharmony_ci	/*
5268c2ecf20Sopenharmony_ci	 * Only used when 'is_block_group' is true and it is the number of
5278c2ecf20Sopenharmony_ci	 * extents used by a swapfile for this block group ('ptr' field).
5288c2ecf20Sopenharmony_ci	 */
5298c2ecf20Sopenharmony_ci	int bg_extent_count;
5308c2ecf20Sopenharmony_ci};
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_cienum {
5338c2ecf20Sopenharmony_ci	BTRFS_FS_BARRIER,
5348c2ecf20Sopenharmony_ci	BTRFS_FS_CLOSING_START,
5358c2ecf20Sopenharmony_ci	BTRFS_FS_CLOSING_DONE,
5368c2ecf20Sopenharmony_ci	BTRFS_FS_LOG_RECOVERING,
5378c2ecf20Sopenharmony_ci	BTRFS_FS_OPEN,
5388c2ecf20Sopenharmony_ci	BTRFS_FS_QUOTA_ENABLED,
5398c2ecf20Sopenharmony_ci	BTRFS_FS_UPDATE_UUID_TREE_GEN,
5408c2ecf20Sopenharmony_ci	BTRFS_FS_CREATING_FREE_SPACE_TREE,
5418c2ecf20Sopenharmony_ci	BTRFS_FS_BTREE_ERR,
5428c2ecf20Sopenharmony_ci	BTRFS_FS_LOG1_ERR,
5438c2ecf20Sopenharmony_ci	BTRFS_FS_LOG2_ERR,
5448c2ecf20Sopenharmony_ci	BTRFS_FS_QUOTA_OVERRIDE,
5458c2ecf20Sopenharmony_ci	/* Used to record internally whether fs has been frozen */
5468c2ecf20Sopenharmony_ci	BTRFS_FS_FROZEN,
5478c2ecf20Sopenharmony_ci	/*
5488c2ecf20Sopenharmony_ci	 * Indicate that balance has been set up from the ioctl and is in the
5498c2ecf20Sopenharmony_ci	 * main phase. The fs_info::balance_ctl is initialized.
5508c2ecf20Sopenharmony_ci	 * Set and cleared while holding fs_info::balance_mutex.
5518c2ecf20Sopenharmony_ci	 */
5528c2ecf20Sopenharmony_ci	BTRFS_FS_BALANCE_RUNNING,
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	/* Indicate that the cleaner thread is awake and doing something. */
5558c2ecf20Sopenharmony_ci	BTRFS_FS_CLEANER_RUNNING,
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	/*
5588c2ecf20Sopenharmony_ci	 * The checksumming has an optimized version and is considered fast,
5598c2ecf20Sopenharmony_ci	 * so we don't need to offload checksums to workqueues.
5608c2ecf20Sopenharmony_ci	 */
5618c2ecf20Sopenharmony_ci	BTRFS_FS_CSUM_IMPL_FAST,
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	/* Indicate that the discard workqueue can service discards. */
5648c2ecf20Sopenharmony_ci	BTRFS_FS_DISCARD_RUNNING,
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	/* Indicate that we can't trust the free space tree for caching yet */
5678c2ecf20Sopenharmony_ci	BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
5688c2ecf20Sopenharmony_ci};
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci/*
5718c2ecf20Sopenharmony_ci * Exclusive operations (device replace, resize, device add/remove, balance)
5728c2ecf20Sopenharmony_ci */
5738c2ecf20Sopenharmony_cienum btrfs_exclusive_operation {
5748c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_NONE,
5758c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_BALANCE,
5768c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_DEV_ADD,
5778c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_DEV_REMOVE,
5788c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_DEV_REPLACE,
5798c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_RESIZE,
5808c2ecf20Sopenharmony_ci	BTRFS_EXCLOP_SWAP_ACTIVATE,
5818c2ecf20Sopenharmony_ci};
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_cistruct btrfs_fs_info {
5848c2ecf20Sopenharmony_ci	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
5858c2ecf20Sopenharmony_ci	unsigned long flags;
5868c2ecf20Sopenharmony_ci	struct btrfs_root *extent_root;
5878c2ecf20Sopenharmony_ci	struct btrfs_root *tree_root;
5888c2ecf20Sopenharmony_ci	struct btrfs_root *chunk_root;
5898c2ecf20Sopenharmony_ci	struct btrfs_root *dev_root;
5908c2ecf20Sopenharmony_ci	struct btrfs_root *fs_root;
5918c2ecf20Sopenharmony_ci	struct btrfs_root *csum_root;
5928c2ecf20Sopenharmony_ci	struct btrfs_root *quota_root;
5938c2ecf20Sopenharmony_ci	struct btrfs_root *uuid_root;
5948c2ecf20Sopenharmony_ci	struct btrfs_root *free_space_root;
5958c2ecf20Sopenharmony_ci	struct btrfs_root *data_reloc_root;
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	/* the log root tree is a directory of all the other log roots */
5988c2ecf20Sopenharmony_ci	struct btrfs_root *log_root_tree;
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	spinlock_t fs_roots_radix_lock;
6018c2ecf20Sopenharmony_ci	struct radix_tree_root fs_roots_radix;
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	/* block group cache stuff */
6048c2ecf20Sopenharmony_ci	spinlock_t block_group_cache_lock;
6058c2ecf20Sopenharmony_ci	u64 first_logical_byte;
6068c2ecf20Sopenharmony_ci	struct rb_root block_group_cache_tree;
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci	/* keep track of unallocated space */
6098c2ecf20Sopenharmony_ci	atomic64_t free_chunk_space;
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	/* Track ranges which are used by log trees blocks/logged data extents */
6128c2ecf20Sopenharmony_ci	struct extent_io_tree excluded_extents;
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	/* logical->physical extent mapping */
6158c2ecf20Sopenharmony_ci	struct extent_map_tree mapping_tree;
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	/*
6188c2ecf20Sopenharmony_ci	 * block reservation for extent, checksum, root tree and
6198c2ecf20Sopenharmony_ci	 * delayed dir index item
6208c2ecf20Sopenharmony_ci	 */
6218c2ecf20Sopenharmony_ci	struct btrfs_block_rsv global_block_rsv;
6228c2ecf20Sopenharmony_ci	/* block reservation for metadata operations */
6238c2ecf20Sopenharmony_ci	struct btrfs_block_rsv trans_block_rsv;
6248c2ecf20Sopenharmony_ci	/* block reservation for chunk tree */
6258c2ecf20Sopenharmony_ci	struct btrfs_block_rsv chunk_block_rsv;
6268c2ecf20Sopenharmony_ci	/* block reservation for delayed operations */
6278c2ecf20Sopenharmony_ci	struct btrfs_block_rsv delayed_block_rsv;
6288c2ecf20Sopenharmony_ci	/* block reservation for delayed refs */
6298c2ecf20Sopenharmony_ci	struct btrfs_block_rsv delayed_refs_rsv;
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	struct btrfs_block_rsv empty_block_rsv;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	u64 generation;
6348c2ecf20Sopenharmony_ci	u64 last_trans_committed;
6358c2ecf20Sopenharmony_ci	u64 avg_delayed_ref_runtime;
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci	/*
6388c2ecf20Sopenharmony_ci	 * this is updated to the current trans every time a full commit
6398c2ecf20Sopenharmony_ci	 * is required instead of the faster short fsync log commits
6408c2ecf20Sopenharmony_ci	 */
6418c2ecf20Sopenharmony_ci	u64 last_trans_log_full_commit;
6428c2ecf20Sopenharmony_ci	unsigned long mount_opt;
6438c2ecf20Sopenharmony_ci	/*
6448c2ecf20Sopenharmony_ci	 * Track requests for actions that need to be done during transaction
6458c2ecf20Sopenharmony_ci	 * commit (like for some mount options).
6468c2ecf20Sopenharmony_ci	 */
6478c2ecf20Sopenharmony_ci	unsigned long pending_changes;
6488c2ecf20Sopenharmony_ci	unsigned long compress_type:4;
6498c2ecf20Sopenharmony_ci	unsigned int compress_level;
6508c2ecf20Sopenharmony_ci	u32 commit_interval;
6518c2ecf20Sopenharmony_ci	/*
6528c2ecf20Sopenharmony_ci	 * It is a suggestive number, the read side is safe even it gets a
6538c2ecf20Sopenharmony_ci	 * wrong number because we will write out the data into a regular
6548c2ecf20Sopenharmony_ci	 * extent. The write side(mount/remount) is under ->s_umount lock,
6558c2ecf20Sopenharmony_ci	 * so it is also safe.
6568c2ecf20Sopenharmony_ci	 */
6578c2ecf20Sopenharmony_ci	u64 max_inline;
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci	struct btrfs_transaction *running_transaction;
6608c2ecf20Sopenharmony_ci	wait_queue_head_t transaction_throttle;
6618c2ecf20Sopenharmony_ci	wait_queue_head_t transaction_wait;
6628c2ecf20Sopenharmony_ci	wait_queue_head_t transaction_blocked_wait;
6638c2ecf20Sopenharmony_ci	wait_queue_head_t async_submit_wait;
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_ci	/*
6668c2ecf20Sopenharmony_ci	 * Used to protect the incompat_flags, compat_flags, compat_ro_flags
6678c2ecf20Sopenharmony_ci	 * when they are updated.
6688c2ecf20Sopenharmony_ci	 *
6698c2ecf20Sopenharmony_ci	 * Because we do not clear the flags for ever, so we needn't use
6708c2ecf20Sopenharmony_ci	 * the lock on the read side.
6718c2ecf20Sopenharmony_ci	 *
6728c2ecf20Sopenharmony_ci	 * We also needn't use the lock when we mount the fs, because
6738c2ecf20Sopenharmony_ci	 * there is no other task which will update the flag.
6748c2ecf20Sopenharmony_ci	 */
6758c2ecf20Sopenharmony_ci	spinlock_t super_lock;
6768c2ecf20Sopenharmony_ci	struct btrfs_super_block *super_copy;
6778c2ecf20Sopenharmony_ci	struct btrfs_super_block *super_for_commit;
6788c2ecf20Sopenharmony_ci	struct super_block *sb;
6798c2ecf20Sopenharmony_ci	struct inode *btree_inode;
6808c2ecf20Sopenharmony_ci	struct mutex tree_log_mutex;
6818c2ecf20Sopenharmony_ci	struct mutex transaction_kthread_mutex;
6828c2ecf20Sopenharmony_ci	struct mutex cleaner_mutex;
6838c2ecf20Sopenharmony_ci	struct mutex chunk_mutex;
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci	/*
6868c2ecf20Sopenharmony_ci	 * this is taken to make sure we don't set block groups ro after
6878c2ecf20Sopenharmony_ci	 * the free space cache has been allocated on them
6888c2ecf20Sopenharmony_ci	 */
6898c2ecf20Sopenharmony_ci	struct mutex ro_block_group_mutex;
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	/* this is used during read/modify/write to make sure
6928c2ecf20Sopenharmony_ci	 * no two ios are trying to mod the same stripe at the same
6938c2ecf20Sopenharmony_ci	 * time
6948c2ecf20Sopenharmony_ci	 */
6958c2ecf20Sopenharmony_ci	struct btrfs_stripe_hash_table *stripe_hash_table;
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci	/*
6988c2ecf20Sopenharmony_ci	 * this protects the ordered operations list only while we are
6998c2ecf20Sopenharmony_ci	 * processing all of the entries on it.  This way we make
7008c2ecf20Sopenharmony_ci	 * sure the commit code doesn't find the list temporarily empty
7018c2ecf20Sopenharmony_ci	 * because another function happens to be doing non-waiting preflush
7028c2ecf20Sopenharmony_ci	 * before jumping into the main commit.
7038c2ecf20Sopenharmony_ci	 */
7048c2ecf20Sopenharmony_ci	struct mutex ordered_operations_mutex;
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	struct rw_semaphore commit_root_sem;
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	struct rw_semaphore cleanup_work_sem;
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	struct rw_semaphore subvol_sem;
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	spinlock_t trans_lock;
7138c2ecf20Sopenharmony_ci	/*
7148c2ecf20Sopenharmony_ci	 * the reloc mutex goes with the trans lock, it is taken
7158c2ecf20Sopenharmony_ci	 * during commit to protect us from the relocation code
7168c2ecf20Sopenharmony_ci	 */
7178c2ecf20Sopenharmony_ci	struct mutex reloc_mutex;
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci	struct list_head trans_list;
7208c2ecf20Sopenharmony_ci	struct list_head dead_roots;
7218c2ecf20Sopenharmony_ci	struct list_head caching_block_groups;
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	spinlock_t delayed_iput_lock;
7248c2ecf20Sopenharmony_ci	struct list_head delayed_iputs;
7258c2ecf20Sopenharmony_ci	atomic_t nr_delayed_iputs;
7268c2ecf20Sopenharmony_ci	wait_queue_head_t delayed_iputs_wait;
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci	atomic64_t tree_mod_seq;
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci	/* this protects tree_mod_log and tree_mod_seq_list */
7318c2ecf20Sopenharmony_ci	rwlock_t tree_mod_log_lock;
7328c2ecf20Sopenharmony_ci	struct rb_root tree_mod_log;
7338c2ecf20Sopenharmony_ci	struct list_head tree_mod_seq_list;
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci	atomic_t async_delalloc_pages;
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	/*
7388c2ecf20Sopenharmony_ci	 * this is used to protect the following list -- ordered_roots.
7398c2ecf20Sopenharmony_ci	 */
7408c2ecf20Sopenharmony_ci	spinlock_t ordered_root_lock;
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci	/*
7438c2ecf20Sopenharmony_ci	 * all fs/file tree roots in which there are data=ordered extents
7448c2ecf20Sopenharmony_ci	 * pending writeback are added into this list.
7458c2ecf20Sopenharmony_ci	 *
7468c2ecf20Sopenharmony_ci	 * these can span multiple transactions and basically include
7478c2ecf20Sopenharmony_ci	 * every dirty data page that isn't from nodatacow
7488c2ecf20Sopenharmony_ci	 */
7498c2ecf20Sopenharmony_ci	struct list_head ordered_roots;
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci	struct mutex delalloc_root_mutex;
7528c2ecf20Sopenharmony_ci	spinlock_t delalloc_root_lock;
7538c2ecf20Sopenharmony_ci	/* all fs/file tree roots that have delalloc inodes. */
7548c2ecf20Sopenharmony_ci	struct list_head delalloc_roots;
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci	/*
7578c2ecf20Sopenharmony_ci	 * there is a pool of worker threads for checksumming during writes
7588c2ecf20Sopenharmony_ci	 * and a pool for checksumming after reads.  This is because readers
7598c2ecf20Sopenharmony_ci	 * can run with FS locks held, and the writers may be waiting for
7608c2ecf20Sopenharmony_ci	 * those locks.  We don't want ordering in the pending list to cause
7618c2ecf20Sopenharmony_ci	 * deadlocks, and so the two are serviced separately.
7628c2ecf20Sopenharmony_ci	 *
7638c2ecf20Sopenharmony_ci	 * A third pool does submit_bio to avoid deadlocking with the other
7648c2ecf20Sopenharmony_ci	 * two
7658c2ecf20Sopenharmony_ci	 */
7668c2ecf20Sopenharmony_ci	struct btrfs_workqueue *workers;
7678c2ecf20Sopenharmony_ci	struct btrfs_workqueue *delalloc_workers;
7688c2ecf20Sopenharmony_ci	struct btrfs_workqueue *flush_workers;
7698c2ecf20Sopenharmony_ci	struct btrfs_workqueue *endio_workers;
7708c2ecf20Sopenharmony_ci	struct btrfs_workqueue *endio_meta_workers;
7718c2ecf20Sopenharmony_ci	struct btrfs_workqueue *endio_raid56_workers;
7728c2ecf20Sopenharmony_ci	struct btrfs_workqueue *rmw_workers;
7738c2ecf20Sopenharmony_ci	struct btrfs_workqueue *endio_meta_write_workers;
7748c2ecf20Sopenharmony_ci	struct btrfs_workqueue *endio_write_workers;
7758c2ecf20Sopenharmony_ci	struct btrfs_workqueue *endio_freespace_worker;
7768c2ecf20Sopenharmony_ci	struct btrfs_workqueue *caching_workers;
7778c2ecf20Sopenharmony_ci	struct btrfs_workqueue *readahead_workers;
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_ci	/*
7808c2ecf20Sopenharmony_ci	 * fixup workers take dirty pages that didn't properly go through
7818c2ecf20Sopenharmony_ci	 * the cow mechanism and make them safe to write.  It happens
7828c2ecf20Sopenharmony_ci	 * for the sys_munmap function call path
7838c2ecf20Sopenharmony_ci	 */
7848c2ecf20Sopenharmony_ci	struct btrfs_workqueue *fixup_workers;
7858c2ecf20Sopenharmony_ci	struct btrfs_workqueue *delayed_workers;
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci	struct task_struct *transaction_kthread;
7888c2ecf20Sopenharmony_ci	struct task_struct *cleaner_kthread;
7898c2ecf20Sopenharmony_ci	u32 thread_pool_size;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	struct kobject *space_info_kobj;
7928c2ecf20Sopenharmony_ci	struct kobject *qgroups_kobj;
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	u64 total_pinned;
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci	/* used to keep from writing metadata until there is a nice batch */
7978c2ecf20Sopenharmony_ci	struct percpu_counter dirty_metadata_bytes;
7988c2ecf20Sopenharmony_ci	struct percpu_counter delalloc_bytes;
7998c2ecf20Sopenharmony_ci	struct percpu_counter dio_bytes;
8008c2ecf20Sopenharmony_ci	s32 dirty_metadata_batch;
8018c2ecf20Sopenharmony_ci	s32 delalloc_batch;
8028c2ecf20Sopenharmony_ci
8038c2ecf20Sopenharmony_ci	struct list_head dirty_cowonly_roots;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	struct btrfs_fs_devices *fs_devices;
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci	/*
8088c2ecf20Sopenharmony_ci	 * The space_info list is effectively read only after initial
8098c2ecf20Sopenharmony_ci	 * setup.  It is populated at mount time and cleaned up after
8108c2ecf20Sopenharmony_ci	 * all block groups are removed.  RCU is used to protect it.
8118c2ecf20Sopenharmony_ci	 */
8128c2ecf20Sopenharmony_ci	struct list_head space_info;
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	struct btrfs_space_info *data_sinfo;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	struct reloc_control *reloc_ctl;
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci	/* data_alloc_cluster is only used in ssd_spread mode */
8198c2ecf20Sopenharmony_ci	struct btrfs_free_cluster data_alloc_cluster;
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	/* all metadata allocations go through this cluster */
8228c2ecf20Sopenharmony_ci	struct btrfs_free_cluster meta_alloc_cluster;
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci	/* auto defrag inodes go here */
8258c2ecf20Sopenharmony_ci	spinlock_t defrag_inodes_lock;
8268c2ecf20Sopenharmony_ci	struct rb_root defrag_inodes;
8278c2ecf20Sopenharmony_ci	atomic_t defrag_running;
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	/* Used to protect avail_{data, metadata, system}_alloc_bits */
8308c2ecf20Sopenharmony_ci	seqlock_t profiles_lock;
8318c2ecf20Sopenharmony_ci	/*
8328c2ecf20Sopenharmony_ci	 * these three are in extended format (availability of single
8338c2ecf20Sopenharmony_ci	 * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other
8348c2ecf20Sopenharmony_ci	 * types are denoted by corresponding BTRFS_BLOCK_GROUP_* bits)
8358c2ecf20Sopenharmony_ci	 */
8368c2ecf20Sopenharmony_ci	u64 avail_data_alloc_bits;
8378c2ecf20Sopenharmony_ci	u64 avail_metadata_alloc_bits;
8388c2ecf20Sopenharmony_ci	u64 avail_system_alloc_bits;
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_ci	/* restriper state */
8418c2ecf20Sopenharmony_ci	spinlock_t balance_lock;
8428c2ecf20Sopenharmony_ci	struct mutex balance_mutex;
8438c2ecf20Sopenharmony_ci	atomic_t balance_pause_req;
8448c2ecf20Sopenharmony_ci	atomic_t balance_cancel_req;
8458c2ecf20Sopenharmony_ci	struct btrfs_balance_control *balance_ctl;
8468c2ecf20Sopenharmony_ci	wait_queue_head_t balance_wait_q;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci	u32 data_chunk_allocations;
8498c2ecf20Sopenharmony_ci	u32 metadata_ratio;
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci	void *bdev_holder;
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ci	/* private scrub information */
8548c2ecf20Sopenharmony_ci	struct mutex scrub_lock;
8558c2ecf20Sopenharmony_ci	atomic_t scrubs_running;
8568c2ecf20Sopenharmony_ci	atomic_t scrub_pause_req;
8578c2ecf20Sopenharmony_ci	atomic_t scrubs_paused;
8588c2ecf20Sopenharmony_ci	atomic_t scrub_cancel_req;
8598c2ecf20Sopenharmony_ci	wait_queue_head_t scrub_pause_wait;
8608c2ecf20Sopenharmony_ci	/*
8618c2ecf20Sopenharmony_ci	 * The worker pointers are NULL iff the refcount is 0, ie. scrub is not
8628c2ecf20Sopenharmony_ci	 * running.
8638c2ecf20Sopenharmony_ci	 */
8648c2ecf20Sopenharmony_ci	refcount_t scrub_workers_refcnt;
8658c2ecf20Sopenharmony_ci	struct btrfs_workqueue *scrub_workers;
8668c2ecf20Sopenharmony_ci	struct btrfs_workqueue *scrub_wr_completion_workers;
8678c2ecf20Sopenharmony_ci	struct btrfs_workqueue *scrub_parity_workers;
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci	struct btrfs_discard_ctl discard_ctl;
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
8728c2ecf20Sopenharmony_ci	u32 check_integrity_print_mask;
8738c2ecf20Sopenharmony_ci#endif
8748c2ecf20Sopenharmony_ci	/* is qgroup tracking in a consistent state? */
8758c2ecf20Sopenharmony_ci	u64 qgroup_flags;
8768c2ecf20Sopenharmony_ci
8778c2ecf20Sopenharmony_ci	/* holds configuration and tracking. Protected by qgroup_lock */
8788c2ecf20Sopenharmony_ci	struct rb_root qgroup_tree;
8798c2ecf20Sopenharmony_ci	spinlock_t qgroup_lock;
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	/*
8828c2ecf20Sopenharmony_ci	 * used to avoid frequently calling ulist_alloc()/ulist_free()
8838c2ecf20Sopenharmony_ci	 * when doing qgroup accounting, it must be protected by qgroup_lock.
8848c2ecf20Sopenharmony_ci	 */
8858c2ecf20Sopenharmony_ci	struct ulist *qgroup_ulist;
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_ci	/*
8888c2ecf20Sopenharmony_ci	 * Protect user change for quota operations. If a transaction is needed,
8898c2ecf20Sopenharmony_ci	 * it must be started before locking this lock.
8908c2ecf20Sopenharmony_ci	 */
8918c2ecf20Sopenharmony_ci	struct mutex qgroup_ioctl_lock;
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_ci	/* list of dirty qgroups to be written at next commit */
8948c2ecf20Sopenharmony_ci	struct list_head dirty_qgroups;
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_ci	/* used by qgroup for an efficient tree traversal */
8978c2ecf20Sopenharmony_ci	u64 qgroup_seq;
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	/* qgroup rescan items */
9008c2ecf20Sopenharmony_ci	struct mutex qgroup_rescan_lock; /* protects the progress item */
9018c2ecf20Sopenharmony_ci	struct btrfs_key qgroup_rescan_progress;
9028c2ecf20Sopenharmony_ci	struct btrfs_workqueue *qgroup_rescan_workers;
9038c2ecf20Sopenharmony_ci	struct completion qgroup_rescan_completion;
9048c2ecf20Sopenharmony_ci	struct btrfs_work qgroup_rescan_work;
9058c2ecf20Sopenharmony_ci	bool qgroup_rescan_running;	/* protected by qgroup_rescan_lock */
9068c2ecf20Sopenharmony_ci
9078c2ecf20Sopenharmony_ci	/* filesystem state */
9088c2ecf20Sopenharmony_ci	unsigned long fs_state;
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	struct btrfs_delayed_root *delayed_root;
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci	/* readahead tree */
9138c2ecf20Sopenharmony_ci	spinlock_t reada_lock;
9148c2ecf20Sopenharmony_ci	struct radix_tree_root reada_tree;
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci	/* readahead works cnt */
9178c2ecf20Sopenharmony_ci	atomic_t reada_works_cnt;
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci	/* Extent buffer radix tree */
9208c2ecf20Sopenharmony_ci	spinlock_t buffer_lock;
9218c2ecf20Sopenharmony_ci	struct radix_tree_root buffer_radix;
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_ci	/* next backup root to be overwritten */
9248c2ecf20Sopenharmony_ci	int backup_root_index;
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	/* device replace state */
9278c2ecf20Sopenharmony_ci	struct btrfs_dev_replace dev_replace;
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci	struct semaphore uuid_tree_rescan_sem;
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci	/* Used to reclaim the metadata space in the background. */
9328c2ecf20Sopenharmony_ci	struct work_struct async_reclaim_work;
9338c2ecf20Sopenharmony_ci	struct work_struct async_data_reclaim_work;
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_ci	spinlock_t unused_bgs_lock;
9368c2ecf20Sopenharmony_ci	struct list_head unused_bgs;
9378c2ecf20Sopenharmony_ci	struct mutex unused_bg_unpin_mutex;
9388c2ecf20Sopenharmony_ci	struct mutex delete_unused_bgs_mutex;
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_ci	/* Cached block sizes */
9418c2ecf20Sopenharmony_ci	u32 nodesize;
9428c2ecf20Sopenharmony_ci	u32 sectorsize;
9438c2ecf20Sopenharmony_ci	u32 stripesize;
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci	/* Block groups and devices containing active swapfiles. */
9468c2ecf20Sopenharmony_ci	spinlock_t swapfile_pins_lock;
9478c2ecf20Sopenharmony_ci	struct rb_root swapfile_pins;
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	struct crypto_shash *csum_shash;
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	/*
9528c2ecf20Sopenharmony_ci	 * Number of send operations in progress.
9538c2ecf20Sopenharmony_ci	 * Updated while holding fs_info::balance_mutex.
9548c2ecf20Sopenharmony_ci	 */
9558c2ecf20Sopenharmony_ci	int send_in_progress;
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	/* Type of exclusive operation running */
9588c2ecf20Sopenharmony_ci	unsigned long exclusive_operation;
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_REF_VERIFY
9618c2ecf20Sopenharmony_ci	spinlock_t ref_verify_lock;
9628c2ecf20Sopenharmony_ci	struct rb_root block_tree;
9638c2ecf20Sopenharmony_ci#endif
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_DEBUG
9668c2ecf20Sopenharmony_ci	struct kobject *debug_kobj;
9678c2ecf20Sopenharmony_ci	struct kobject *discard_debug_kobj;
9688c2ecf20Sopenharmony_ci	struct list_head allocated_roots;
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci	spinlock_t eb_leak_lock;
9718c2ecf20Sopenharmony_ci	struct list_head allocated_ebs;
9728c2ecf20Sopenharmony_ci#endif
9738c2ecf20Sopenharmony_ci};
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_cistatic inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
9768c2ecf20Sopenharmony_ci{
9778c2ecf20Sopenharmony_ci	return sb->s_fs_info;
9788c2ecf20Sopenharmony_ci}
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci/*
9818c2ecf20Sopenharmony_ci * The state of btrfs root
9828c2ecf20Sopenharmony_ci */
9838c2ecf20Sopenharmony_cienum {
9848c2ecf20Sopenharmony_ci	/*
9858c2ecf20Sopenharmony_ci	 * btrfs_record_root_in_trans is a multi-step process, and it can race
9868c2ecf20Sopenharmony_ci	 * with the balancing code.   But the race is very small, and only the
9878c2ecf20Sopenharmony_ci	 * first time the root is added to each transaction.  So IN_TRANS_SETUP
9888c2ecf20Sopenharmony_ci	 * is used to tell us when more checks are required
9898c2ecf20Sopenharmony_ci	 */
9908c2ecf20Sopenharmony_ci	BTRFS_ROOT_IN_TRANS_SETUP,
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_ci	/*
9938c2ecf20Sopenharmony_ci	 * Set if tree blocks of this root can be shared by other roots.
9948c2ecf20Sopenharmony_ci	 * Only subvolume trees and their reloc trees have this bit set.
9958c2ecf20Sopenharmony_ci	 * Conflicts with TRACK_DIRTY bit.
9968c2ecf20Sopenharmony_ci	 *
9978c2ecf20Sopenharmony_ci	 * This affects two things:
9988c2ecf20Sopenharmony_ci	 *
9998c2ecf20Sopenharmony_ci	 * - How balance works
10008c2ecf20Sopenharmony_ci	 *   For shareable roots, we need to use reloc tree and do path
10018c2ecf20Sopenharmony_ci	 *   replacement for balance, and need various pre/post hooks for
10028c2ecf20Sopenharmony_ci	 *   snapshot creation to handle them.
10038c2ecf20Sopenharmony_ci	 *
10048c2ecf20Sopenharmony_ci	 *   While for non-shareable trees, we just simply do a tree search
10058c2ecf20Sopenharmony_ci	 *   with COW.
10068c2ecf20Sopenharmony_ci	 *
10078c2ecf20Sopenharmony_ci	 * - How dirty roots are tracked
10088c2ecf20Sopenharmony_ci	 *   For shareable roots, btrfs_record_root_in_trans() is needed to
10098c2ecf20Sopenharmony_ci	 *   track them, while non-subvolume roots have TRACK_DIRTY bit, they
10108c2ecf20Sopenharmony_ci	 *   don't need to set this manually.
10118c2ecf20Sopenharmony_ci	 */
10128c2ecf20Sopenharmony_ci	BTRFS_ROOT_SHAREABLE,
10138c2ecf20Sopenharmony_ci	BTRFS_ROOT_TRACK_DIRTY,
10148c2ecf20Sopenharmony_ci	BTRFS_ROOT_IN_RADIX,
10158c2ecf20Sopenharmony_ci	BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
10168c2ecf20Sopenharmony_ci	BTRFS_ROOT_DEFRAG_RUNNING,
10178c2ecf20Sopenharmony_ci	BTRFS_ROOT_FORCE_COW,
10188c2ecf20Sopenharmony_ci	BTRFS_ROOT_MULTI_LOG_TASKS,
10198c2ecf20Sopenharmony_ci	BTRFS_ROOT_DIRTY,
10208c2ecf20Sopenharmony_ci	BTRFS_ROOT_DELETING,
10218c2ecf20Sopenharmony_ci
10228c2ecf20Sopenharmony_ci	/*
10238c2ecf20Sopenharmony_ci	 * Reloc tree is orphan, only kept here for qgroup delayed subtree scan
10248c2ecf20Sopenharmony_ci	 *
10258c2ecf20Sopenharmony_ci	 * Set for the subvolume tree owning the reloc tree.
10268c2ecf20Sopenharmony_ci	 */
10278c2ecf20Sopenharmony_ci	BTRFS_ROOT_DEAD_RELOC_TREE,
10288c2ecf20Sopenharmony_ci	/* Mark dead root stored on device whose cleanup needs to be resumed */
10298c2ecf20Sopenharmony_ci	BTRFS_ROOT_DEAD_TREE,
10308c2ecf20Sopenharmony_ci	/* The root has a log tree. Used only for subvolume roots. */
10318c2ecf20Sopenharmony_ci	BTRFS_ROOT_HAS_LOG_TREE,
10328c2ecf20Sopenharmony_ci	/* Qgroup flushing is in progress */
10338c2ecf20Sopenharmony_ci	BTRFS_ROOT_QGROUP_FLUSHING,
10348c2ecf20Sopenharmony_ci};
10358c2ecf20Sopenharmony_ci
10368c2ecf20Sopenharmony_ci/*
10378c2ecf20Sopenharmony_ci * Record swapped tree blocks of a subvolume tree for delayed subtree trace
10388c2ecf20Sopenharmony_ci * code. For detail check comment in fs/btrfs/qgroup.c.
10398c2ecf20Sopenharmony_ci */
10408c2ecf20Sopenharmony_cistruct btrfs_qgroup_swapped_blocks {
10418c2ecf20Sopenharmony_ci	spinlock_t lock;
10428c2ecf20Sopenharmony_ci	/* RM_EMPTY_ROOT() of above blocks[] */
10438c2ecf20Sopenharmony_ci	bool swapped;
10448c2ecf20Sopenharmony_ci	struct rb_root blocks[BTRFS_MAX_LEVEL];
10458c2ecf20Sopenharmony_ci};
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci/*
10488c2ecf20Sopenharmony_ci * in ram representation of the tree.  extent_root is used for all allocations
10498c2ecf20Sopenharmony_ci * and for the extent tree extent_root root.
10508c2ecf20Sopenharmony_ci */
10518c2ecf20Sopenharmony_cistruct btrfs_root {
10528c2ecf20Sopenharmony_ci	struct extent_buffer *node;
10538c2ecf20Sopenharmony_ci
10548c2ecf20Sopenharmony_ci	struct extent_buffer *commit_root;
10558c2ecf20Sopenharmony_ci	struct btrfs_root *log_root;
10568c2ecf20Sopenharmony_ci	struct btrfs_root *reloc_root;
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci	unsigned long state;
10598c2ecf20Sopenharmony_ci	struct btrfs_root_item root_item;
10608c2ecf20Sopenharmony_ci	struct btrfs_key root_key;
10618c2ecf20Sopenharmony_ci	struct btrfs_fs_info *fs_info;
10628c2ecf20Sopenharmony_ci	struct extent_io_tree dirty_log_pages;
10638c2ecf20Sopenharmony_ci
10648c2ecf20Sopenharmony_ci	struct mutex objectid_mutex;
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci	spinlock_t accounting_lock;
10678c2ecf20Sopenharmony_ci	struct btrfs_block_rsv *block_rsv;
10688c2ecf20Sopenharmony_ci
10698c2ecf20Sopenharmony_ci	/* free ino cache stuff */
10708c2ecf20Sopenharmony_ci	struct btrfs_free_space_ctl *free_ino_ctl;
10718c2ecf20Sopenharmony_ci	enum btrfs_caching_type ino_cache_state;
10728c2ecf20Sopenharmony_ci	spinlock_t ino_cache_lock;
10738c2ecf20Sopenharmony_ci	wait_queue_head_t ino_cache_wait;
10748c2ecf20Sopenharmony_ci	struct btrfs_free_space_ctl *free_ino_pinned;
10758c2ecf20Sopenharmony_ci	u64 ino_cache_progress;
10768c2ecf20Sopenharmony_ci	struct inode *ino_cache_inode;
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ci	struct mutex log_mutex;
10798c2ecf20Sopenharmony_ci	wait_queue_head_t log_writer_wait;
10808c2ecf20Sopenharmony_ci	wait_queue_head_t log_commit_wait[2];
10818c2ecf20Sopenharmony_ci	struct list_head log_ctxs[2];
10828c2ecf20Sopenharmony_ci	/* Used only for log trees of subvolumes, not for the log root tree */
10838c2ecf20Sopenharmony_ci	atomic_t log_writers;
10848c2ecf20Sopenharmony_ci	atomic_t log_commit[2];
10858c2ecf20Sopenharmony_ci	/* Used only for log trees of subvolumes, not for the log root tree */
10868c2ecf20Sopenharmony_ci	atomic_t log_batch;
10878c2ecf20Sopenharmony_ci	int log_transid;
10888c2ecf20Sopenharmony_ci	/* No matter the commit succeeds or not*/
10898c2ecf20Sopenharmony_ci	int log_transid_committed;
10908c2ecf20Sopenharmony_ci	/* Just be updated when the commit succeeds. */
10918c2ecf20Sopenharmony_ci	int last_log_commit;
10928c2ecf20Sopenharmony_ci	pid_t log_start_pid;
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci	u64 last_trans;
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_ci	u32 type;
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ci	u64 highest_objectid;
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_ci	struct btrfs_key defrag_progress;
11018c2ecf20Sopenharmony_ci	struct btrfs_key defrag_max;
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	/* The dirty list is only used by non-shareable roots */
11048c2ecf20Sopenharmony_ci	struct list_head dirty_list;
11058c2ecf20Sopenharmony_ci
11068c2ecf20Sopenharmony_ci	struct list_head root_list;
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_ci	spinlock_t log_extents_lock[2];
11098c2ecf20Sopenharmony_ci	struct list_head logged_list[2];
11108c2ecf20Sopenharmony_ci
11118c2ecf20Sopenharmony_ci	int orphan_cleanup_state;
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_ci	spinlock_t inode_lock;
11148c2ecf20Sopenharmony_ci	/* red-black tree that keeps track of in-memory inodes */
11158c2ecf20Sopenharmony_ci	struct rb_root inode_tree;
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_ci	/*
11188c2ecf20Sopenharmony_ci	 * radix tree that keeps track of delayed nodes of every inode,
11198c2ecf20Sopenharmony_ci	 * protected by inode_lock
11208c2ecf20Sopenharmony_ci	 */
11218c2ecf20Sopenharmony_ci	struct radix_tree_root delayed_nodes_tree;
11228c2ecf20Sopenharmony_ci	/*
11238c2ecf20Sopenharmony_ci	 * right now this just gets used so that a root has its own devid
11248c2ecf20Sopenharmony_ci	 * for stat.  It may be used for more later
11258c2ecf20Sopenharmony_ci	 */
11268c2ecf20Sopenharmony_ci	dev_t anon_dev;
11278c2ecf20Sopenharmony_ci
11288c2ecf20Sopenharmony_ci	spinlock_t root_item_lock;
11298c2ecf20Sopenharmony_ci	refcount_t refs;
11308c2ecf20Sopenharmony_ci
11318c2ecf20Sopenharmony_ci	struct mutex delalloc_mutex;
11328c2ecf20Sopenharmony_ci	spinlock_t delalloc_lock;
11338c2ecf20Sopenharmony_ci	/*
11348c2ecf20Sopenharmony_ci	 * all of the inodes that have delalloc bytes.  It is possible for
11358c2ecf20Sopenharmony_ci	 * this list to be empty even when there is still dirty data=ordered
11368c2ecf20Sopenharmony_ci	 * extents waiting to finish IO.
11378c2ecf20Sopenharmony_ci	 */
11388c2ecf20Sopenharmony_ci	struct list_head delalloc_inodes;
11398c2ecf20Sopenharmony_ci	struct list_head delalloc_root;
11408c2ecf20Sopenharmony_ci	u64 nr_delalloc_inodes;
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci	struct mutex ordered_extent_mutex;
11438c2ecf20Sopenharmony_ci	/*
11448c2ecf20Sopenharmony_ci	 * this is used by the balancing code to wait for all the pending
11458c2ecf20Sopenharmony_ci	 * ordered extents
11468c2ecf20Sopenharmony_ci	 */
11478c2ecf20Sopenharmony_ci	spinlock_t ordered_extent_lock;
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_ci	/*
11508c2ecf20Sopenharmony_ci	 * all of the data=ordered extents pending writeback
11518c2ecf20Sopenharmony_ci	 * these can span multiple transactions and basically include
11528c2ecf20Sopenharmony_ci	 * every dirty data page that isn't from nodatacow
11538c2ecf20Sopenharmony_ci	 */
11548c2ecf20Sopenharmony_ci	struct list_head ordered_extents;
11558c2ecf20Sopenharmony_ci	struct list_head ordered_root;
11568c2ecf20Sopenharmony_ci	u64 nr_ordered_extents;
11578c2ecf20Sopenharmony_ci
11588c2ecf20Sopenharmony_ci	/*
11598c2ecf20Sopenharmony_ci	 * Not empty if this subvolume root has gone through tree block swap
11608c2ecf20Sopenharmony_ci	 * (relocation)
11618c2ecf20Sopenharmony_ci	 *
11628c2ecf20Sopenharmony_ci	 * Will be used by reloc_control::dirty_subvol_roots.
11638c2ecf20Sopenharmony_ci	 */
11648c2ecf20Sopenharmony_ci	struct list_head reloc_dirty_list;
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_ci	/*
11678c2ecf20Sopenharmony_ci	 * Number of currently running SEND ioctls to prevent
11688c2ecf20Sopenharmony_ci	 * manipulation with the read-only status via SUBVOL_SETFLAGS
11698c2ecf20Sopenharmony_ci	 */
11708c2ecf20Sopenharmony_ci	int send_in_progress;
11718c2ecf20Sopenharmony_ci	/*
11728c2ecf20Sopenharmony_ci	 * Number of currently running deduplication operations that have a
11738c2ecf20Sopenharmony_ci	 * destination inode belonging to this root. Protected by the lock
11748c2ecf20Sopenharmony_ci	 * root_item_lock.
11758c2ecf20Sopenharmony_ci	 */
11768c2ecf20Sopenharmony_ci	int dedupe_in_progress;
11778c2ecf20Sopenharmony_ci	/* For exclusion of snapshot creation and nocow writes */
11788c2ecf20Sopenharmony_ci	struct btrfs_drew_lock snapshot_lock;
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci	atomic_t snapshot_force_cow;
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci	/* For qgroup metadata reserved space */
11838c2ecf20Sopenharmony_ci	spinlock_t qgroup_meta_rsv_lock;
11848c2ecf20Sopenharmony_ci	u64 qgroup_meta_rsv_pertrans;
11858c2ecf20Sopenharmony_ci	u64 qgroup_meta_rsv_prealloc;
11868c2ecf20Sopenharmony_ci	wait_queue_head_t qgroup_flush_wait;
11878c2ecf20Sopenharmony_ci
11888c2ecf20Sopenharmony_ci	/* Number of active swapfiles */
11898c2ecf20Sopenharmony_ci	atomic_t nr_swapfiles;
11908c2ecf20Sopenharmony_ci
11918c2ecf20Sopenharmony_ci	/* Record pairs of swapped blocks for qgroup */
11928c2ecf20Sopenharmony_ci	struct btrfs_qgroup_swapped_blocks swapped_blocks;
11938c2ecf20Sopenharmony_ci
11948c2ecf20Sopenharmony_ci	/* Used only by log trees, when logging csum items */
11958c2ecf20Sopenharmony_ci	struct extent_io_tree log_csum_range;
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
11988c2ecf20Sopenharmony_ci	u64 alloc_bytenr;
11998c2ecf20Sopenharmony_ci#endif
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_DEBUG
12028c2ecf20Sopenharmony_ci	struct list_head leak_list;
12038c2ecf20Sopenharmony_ci#endif
12048c2ecf20Sopenharmony_ci};
12058c2ecf20Sopenharmony_ci
12068c2ecf20Sopenharmony_ci/*
12078c2ecf20Sopenharmony_ci * Structure that conveys information about an extent that is going to replace
12088c2ecf20Sopenharmony_ci * all the extents in a file range.
12098c2ecf20Sopenharmony_ci */
12108c2ecf20Sopenharmony_cistruct btrfs_replace_extent_info {
12118c2ecf20Sopenharmony_ci	u64 disk_offset;
12128c2ecf20Sopenharmony_ci	u64 disk_len;
12138c2ecf20Sopenharmony_ci	u64 data_offset;
12148c2ecf20Sopenharmony_ci	u64 data_len;
12158c2ecf20Sopenharmony_ci	u64 file_offset;
12168c2ecf20Sopenharmony_ci	/* Pointer to a file extent item of type regular or prealloc. */
12178c2ecf20Sopenharmony_ci	char *extent_buf;
12188c2ecf20Sopenharmony_ci	/*
12198c2ecf20Sopenharmony_ci	 * Set to true when attempting to replace a file range with a new extent
12208c2ecf20Sopenharmony_ci	 * described by this structure, set to false when attempting to clone an
12218c2ecf20Sopenharmony_ci	 * existing extent into a file range.
12228c2ecf20Sopenharmony_ci	 */
12238c2ecf20Sopenharmony_ci	bool is_new_extent;
12248c2ecf20Sopenharmony_ci	/* Meaningful only if is_new_extent is true. */
12258c2ecf20Sopenharmony_ci	int qgroup_reserved;
12268c2ecf20Sopenharmony_ci	/*
12278c2ecf20Sopenharmony_ci	 * Meaningful only if is_new_extent is true.
12288c2ecf20Sopenharmony_ci	 * Used to track how many extent items we have already inserted in a
12298c2ecf20Sopenharmony_ci	 * subvolume tree that refer to the extent described by this structure,
12308c2ecf20Sopenharmony_ci	 * so that we know when to create a new delayed ref or update an existing
12318c2ecf20Sopenharmony_ci	 * one.
12328c2ecf20Sopenharmony_ci	 */
12338c2ecf20Sopenharmony_ci	int insertions;
12348c2ecf20Sopenharmony_ci};
12358c2ecf20Sopenharmony_ci
12368c2ecf20Sopenharmony_cistruct btrfs_file_private {
12378c2ecf20Sopenharmony_ci	void *filldir_buf;
12388c2ecf20Sopenharmony_ci};
12398c2ecf20Sopenharmony_ci
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_cistatic inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
12428c2ecf20Sopenharmony_ci{
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci	return info->nodesize - sizeof(struct btrfs_header);
12458c2ecf20Sopenharmony_ci}
12468c2ecf20Sopenharmony_ci
12478c2ecf20Sopenharmony_ci#define BTRFS_LEAF_DATA_OFFSET		offsetof(struct btrfs_leaf, items)
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_cistatic inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info)
12508c2ecf20Sopenharmony_ci{
12518c2ecf20Sopenharmony_ci	return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item);
12528c2ecf20Sopenharmony_ci}
12538c2ecf20Sopenharmony_ci
12548c2ecf20Sopenharmony_cistatic inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info)
12558c2ecf20Sopenharmony_ci{
12568c2ecf20Sopenharmony_ci	return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr);
12578c2ecf20Sopenharmony_ci}
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci#define BTRFS_FILE_EXTENT_INLINE_DATA_START		\
12608c2ecf20Sopenharmony_ci		(offsetof(struct btrfs_file_extent_item, disk_bytenr))
12618c2ecf20Sopenharmony_cistatic inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
12628c2ecf20Sopenharmony_ci{
12638c2ecf20Sopenharmony_ci	return BTRFS_MAX_ITEM_SIZE(info) -
12648c2ecf20Sopenharmony_ci	       BTRFS_FILE_EXTENT_INLINE_DATA_START;
12658c2ecf20Sopenharmony_ci}
12668c2ecf20Sopenharmony_ci
12678c2ecf20Sopenharmony_cistatic inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
12688c2ecf20Sopenharmony_ci{
12698c2ecf20Sopenharmony_ci	return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
12708c2ecf20Sopenharmony_ci}
12718c2ecf20Sopenharmony_ci
12728c2ecf20Sopenharmony_ci/*
12738c2ecf20Sopenharmony_ci * Flags for mount options.
12748c2ecf20Sopenharmony_ci *
12758c2ecf20Sopenharmony_ci * Note: don't forget to add new options to btrfs_show_options()
12768c2ecf20Sopenharmony_ci */
12778c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_NODATASUM		(1 << 0)
12788c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_NODATACOW		(1 << 1)
12798c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_NOBARRIER		(1 << 2)
12808c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_SSD			(1 << 3)
12818c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_DEGRADED		(1 << 4)
12828c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_COMPRESS		(1 << 5)
12838c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_NOTREELOG           (1 << 6)
12848c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_FLUSHONCOMMIT       (1 << 7)
12858c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_SSD_SPREAD		(1 << 8)
12868c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_NOSSD		(1 << 9)
12878c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_DISCARD_SYNC	(1 << 10)
12888c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
12898c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_SPACE_CACHE		(1 << 12)
12908c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_CLEAR_CACHE		(1 << 13)
12918c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
12928c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_ENOSPC_DEBUG	 (1 << 15)
12938c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_AUTO_DEFRAG		(1 << 16)
12948c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_INODE_MAP_CACHE	(1 << 17)
12958c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_USEBACKUPROOT	(1 << 18)
12968c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_SKIP_BALANCE	(1 << 19)
12978c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_CHECK_INTEGRITY	(1 << 20)
12988c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
12998c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR	(1 << 22)
13008c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_RESCAN_UUID_TREE	(1 << 23)
13018c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_FRAGMENT_DATA	(1 << 24)
13028c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_FRAGMENT_METADATA	(1 << 25)
13038c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_FREE_SPACE_TREE	(1 << 26)
13048c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_NOLOGREPLAY		(1 << 27)
13058c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_REF_VERIFY		(1 << 28)
13068c2ecf20Sopenharmony_ci#define BTRFS_MOUNT_DISCARD_ASYNC	(1 << 29)
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci#define BTRFS_DEFAULT_COMMIT_INTERVAL	(30)
13098c2ecf20Sopenharmony_ci#define BTRFS_DEFAULT_MAX_INLINE	(2048)
13108c2ecf20Sopenharmony_ci
13118c2ecf20Sopenharmony_ci#define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
13128c2ecf20Sopenharmony_ci#define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
13138c2ecf20Sopenharmony_ci#define btrfs_raw_test_opt(o, opt)	((o) & BTRFS_MOUNT_##opt)
13148c2ecf20Sopenharmony_ci#define btrfs_test_opt(fs_info, opt)	((fs_info)->mount_opt & \
13158c2ecf20Sopenharmony_ci					 BTRFS_MOUNT_##opt)
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci#define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
13188c2ecf20Sopenharmony_cido {									\
13198c2ecf20Sopenharmony_ci	if (!btrfs_test_opt(fs_info, opt))				\
13208c2ecf20Sopenharmony_ci		btrfs_info(fs_info, fmt, ##args);			\
13218c2ecf20Sopenharmony_ci	btrfs_set_opt(fs_info->mount_opt, opt);				\
13228c2ecf20Sopenharmony_ci} while (0)
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci#define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
13258c2ecf20Sopenharmony_cido {									\
13268c2ecf20Sopenharmony_ci	if (btrfs_test_opt(fs_info, opt))				\
13278c2ecf20Sopenharmony_ci		btrfs_info(fs_info, fmt, ##args);			\
13288c2ecf20Sopenharmony_ci	btrfs_clear_opt(fs_info->mount_opt, opt);			\
13298c2ecf20Sopenharmony_ci} while (0)
13308c2ecf20Sopenharmony_ci
13318c2ecf20Sopenharmony_ci/*
13328c2ecf20Sopenharmony_ci * Requests for changes that need to be done during transaction commit.
13338c2ecf20Sopenharmony_ci *
13348c2ecf20Sopenharmony_ci * Internal mount options that are used for special handling of the real
13358c2ecf20Sopenharmony_ci * mount options (eg. cannot be set during remount and have to be set during
13368c2ecf20Sopenharmony_ci * transaction commit)
13378c2ecf20Sopenharmony_ci */
13388c2ecf20Sopenharmony_ci
13398c2ecf20Sopenharmony_ci#define BTRFS_PENDING_SET_INODE_MAP_CACHE	(0)
13408c2ecf20Sopenharmony_ci#define BTRFS_PENDING_CLEAR_INODE_MAP_CACHE	(1)
13418c2ecf20Sopenharmony_ci#define BTRFS_PENDING_COMMIT			(2)
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci#define btrfs_test_pending(info, opt)	\
13448c2ecf20Sopenharmony_ci	test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
13458c2ecf20Sopenharmony_ci#define btrfs_set_pending(info, opt)	\
13468c2ecf20Sopenharmony_ci	set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
13478c2ecf20Sopenharmony_ci#define btrfs_clear_pending(info, opt)	\
13488c2ecf20Sopenharmony_ci	clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
13498c2ecf20Sopenharmony_ci
13508c2ecf20Sopenharmony_ci/*
13518c2ecf20Sopenharmony_ci * Helpers for setting pending mount option changes.
13528c2ecf20Sopenharmony_ci *
13538c2ecf20Sopenharmony_ci * Expects corresponding macros
13548c2ecf20Sopenharmony_ci * BTRFS_PENDING_SET_ and CLEAR_ + short mount option name
13558c2ecf20Sopenharmony_ci */
13568c2ecf20Sopenharmony_ci#define btrfs_set_pending_and_info(info, opt, fmt, args...)            \
13578c2ecf20Sopenharmony_cido {                                                                   \
13588c2ecf20Sopenharmony_ci       if (!btrfs_raw_test_opt((info)->mount_opt, opt)) {              \
13598c2ecf20Sopenharmony_ci               btrfs_info((info), fmt, ##args);                        \
13608c2ecf20Sopenharmony_ci               btrfs_set_pending((info), SET_##opt);                   \
13618c2ecf20Sopenharmony_ci               btrfs_clear_pending((info), CLEAR_##opt);               \
13628c2ecf20Sopenharmony_ci       }                                                               \
13638c2ecf20Sopenharmony_ci} while(0)
13648c2ecf20Sopenharmony_ci
13658c2ecf20Sopenharmony_ci#define btrfs_clear_pending_and_info(info, opt, fmt, args...)          \
13668c2ecf20Sopenharmony_cido {                                                                   \
13678c2ecf20Sopenharmony_ci       if (btrfs_raw_test_opt((info)->mount_opt, opt)) {               \
13688c2ecf20Sopenharmony_ci               btrfs_info((info), fmt, ##args);                        \
13698c2ecf20Sopenharmony_ci               btrfs_set_pending((info), CLEAR_##opt);                 \
13708c2ecf20Sopenharmony_ci               btrfs_clear_pending((info), SET_##opt);                 \
13718c2ecf20Sopenharmony_ci       }                                                               \
13728c2ecf20Sopenharmony_ci} while(0)
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci/*
13758c2ecf20Sopenharmony_ci * Inode flags
13768c2ecf20Sopenharmony_ci */
13778c2ecf20Sopenharmony_ci#define BTRFS_INODE_NODATASUM		(1 << 0)
13788c2ecf20Sopenharmony_ci#define BTRFS_INODE_NODATACOW		(1 << 1)
13798c2ecf20Sopenharmony_ci#define BTRFS_INODE_READONLY		(1 << 2)
13808c2ecf20Sopenharmony_ci#define BTRFS_INODE_NOCOMPRESS		(1 << 3)
13818c2ecf20Sopenharmony_ci#define BTRFS_INODE_PREALLOC		(1 << 4)
13828c2ecf20Sopenharmony_ci#define BTRFS_INODE_SYNC		(1 << 5)
13838c2ecf20Sopenharmony_ci#define BTRFS_INODE_IMMUTABLE		(1 << 6)
13848c2ecf20Sopenharmony_ci#define BTRFS_INODE_APPEND		(1 << 7)
13858c2ecf20Sopenharmony_ci#define BTRFS_INODE_NODUMP		(1 << 8)
13868c2ecf20Sopenharmony_ci#define BTRFS_INODE_NOATIME		(1 << 9)
13878c2ecf20Sopenharmony_ci#define BTRFS_INODE_DIRSYNC		(1 << 10)
13888c2ecf20Sopenharmony_ci#define BTRFS_INODE_COMPRESS		(1 << 11)
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci#define BTRFS_INODE_ROOT_ITEM_INIT	(1 << 31)
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_ci#define BTRFS_INODE_FLAG_MASK						\
13938c2ecf20Sopenharmony_ci	(BTRFS_INODE_NODATASUM |					\
13948c2ecf20Sopenharmony_ci	 BTRFS_INODE_NODATACOW |					\
13958c2ecf20Sopenharmony_ci	 BTRFS_INODE_READONLY |						\
13968c2ecf20Sopenharmony_ci	 BTRFS_INODE_NOCOMPRESS |					\
13978c2ecf20Sopenharmony_ci	 BTRFS_INODE_PREALLOC |						\
13988c2ecf20Sopenharmony_ci	 BTRFS_INODE_SYNC |						\
13998c2ecf20Sopenharmony_ci	 BTRFS_INODE_IMMUTABLE |					\
14008c2ecf20Sopenharmony_ci	 BTRFS_INODE_APPEND |						\
14018c2ecf20Sopenharmony_ci	 BTRFS_INODE_NODUMP |						\
14028c2ecf20Sopenharmony_ci	 BTRFS_INODE_NOATIME |						\
14038c2ecf20Sopenharmony_ci	 BTRFS_INODE_DIRSYNC |						\
14048c2ecf20Sopenharmony_ci	 BTRFS_INODE_COMPRESS |						\
14058c2ecf20Sopenharmony_ci	 BTRFS_INODE_ROOT_ITEM_INIT)
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_cistruct btrfs_map_token {
14088c2ecf20Sopenharmony_ci	struct extent_buffer *eb;
14098c2ecf20Sopenharmony_ci	char *kaddr;
14108c2ecf20Sopenharmony_ci	unsigned long offset;
14118c2ecf20Sopenharmony_ci};
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci#define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
14148c2ecf20Sopenharmony_ci				((bytes) >> (fs_info)->sb->s_blocksize_bits)
14158c2ecf20Sopenharmony_ci
14168c2ecf20Sopenharmony_cistatic inline void btrfs_init_map_token(struct btrfs_map_token *token,
14178c2ecf20Sopenharmony_ci					struct extent_buffer *eb)
14188c2ecf20Sopenharmony_ci{
14198c2ecf20Sopenharmony_ci	token->eb = eb;
14208c2ecf20Sopenharmony_ci	token->kaddr = page_address(eb->pages[0]);
14218c2ecf20Sopenharmony_ci	token->offset = 0;
14228c2ecf20Sopenharmony_ci}
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci/* some macros to generate set/get functions for the struct fields.  This
14258c2ecf20Sopenharmony_ci * assumes there is a lefoo_to_cpu for every type, so lets make a simple
14268c2ecf20Sopenharmony_ci * one for u8:
14278c2ecf20Sopenharmony_ci */
14288c2ecf20Sopenharmony_ci#define le8_to_cpu(v) (v)
14298c2ecf20Sopenharmony_ci#define cpu_to_le8(v) (v)
14308c2ecf20Sopenharmony_ci#define __le8 u8
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_cistatic inline u8 get_unaligned_le8(const void *p)
14338c2ecf20Sopenharmony_ci{
14348c2ecf20Sopenharmony_ci       return *(u8 *)p;
14358c2ecf20Sopenharmony_ci}
14368c2ecf20Sopenharmony_ci
14378c2ecf20Sopenharmony_cistatic inline void put_unaligned_le8(u8 val, void *p)
14388c2ecf20Sopenharmony_ci{
14398c2ecf20Sopenharmony_ci       *(u8 *)p = val;
14408c2ecf20Sopenharmony_ci}
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci#define read_eb_member(eb, ptr, type, member, result) (\
14438c2ecf20Sopenharmony_ci	read_extent_buffer(eb, (char *)(result),			\
14448c2ecf20Sopenharmony_ci			   ((unsigned long)(ptr)) +			\
14458c2ecf20Sopenharmony_ci			    offsetof(type, member),			\
14468c2ecf20Sopenharmony_ci			   sizeof(((type *)0)->member)))
14478c2ecf20Sopenharmony_ci
14488c2ecf20Sopenharmony_ci#define write_eb_member(eb, ptr, type, member, result) (\
14498c2ecf20Sopenharmony_ci	write_extent_buffer(eb, (char *)(result),			\
14508c2ecf20Sopenharmony_ci			   ((unsigned long)(ptr)) +			\
14518c2ecf20Sopenharmony_ci			    offsetof(type, member),			\
14528c2ecf20Sopenharmony_ci			   sizeof(((type *)0)->member)))
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_ci#define DECLARE_BTRFS_SETGET_BITS(bits)					\
14558c2ecf20Sopenharmony_ciu##bits btrfs_get_token_##bits(struct btrfs_map_token *token,		\
14568c2ecf20Sopenharmony_ci			       const void *ptr, unsigned long off);	\
14578c2ecf20Sopenharmony_civoid btrfs_set_token_##bits(struct btrfs_map_token *token,		\
14588c2ecf20Sopenharmony_ci			    const void *ptr, unsigned long off,		\
14598c2ecf20Sopenharmony_ci			    u##bits val);				\
14608c2ecf20Sopenharmony_ciu##bits btrfs_get_##bits(const struct extent_buffer *eb,		\
14618c2ecf20Sopenharmony_ci			 const void *ptr, unsigned long off);		\
14628c2ecf20Sopenharmony_civoid btrfs_set_##bits(const struct extent_buffer *eb, void *ptr,	\
14638c2ecf20Sopenharmony_ci		      unsigned long off, u##bits val);
14648c2ecf20Sopenharmony_ci
14658c2ecf20Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(8)
14668c2ecf20Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(16)
14678c2ecf20Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(32)
14688c2ecf20Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(64)
14698c2ecf20Sopenharmony_ci
14708c2ecf20Sopenharmony_ci#define BTRFS_SETGET_FUNCS(name, type, member, bits)			\
14718c2ecf20Sopenharmony_cistatic inline u##bits btrfs_##name(const struct extent_buffer *eb,	\
14728c2ecf20Sopenharmony_ci				   const type *s)			\
14738c2ecf20Sopenharmony_ci{									\
14748c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member);	\
14758c2ecf20Sopenharmony_ci	return btrfs_get_##bits(eb, s, offsetof(type, member));		\
14768c2ecf20Sopenharmony_ci}									\
14778c2ecf20Sopenharmony_cistatic inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
14788c2ecf20Sopenharmony_ci				    u##bits val)			\
14798c2ecf20Sopenharmony_ci{									\
14808c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member);	\
14818c2ecf20Sopenharmony_ci	btrfs_set_##bits(eb, s, offsetof(type, member), val);		\
14828c2ecf20Sopenharmony_ci}									\
14838c2ecf20Sopenharmony_cistatic inline u##bits btrfs_token_##name(struct btrfs_map_token *token,	\
14848c2ecf20Sopenharmony_ci					 const type *s)			\
14858c2ecf20Sopenharmony_ci{									\
14868c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member);	\
14878c2ecf20Sopenharmony_ci	return btrfs_get_token_##bits(token, s, offsetof(type, member));\
14888c2ecf20Sopenharmony_ci}									\
14898c2ecf20Sopenharmony_cistatic inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
14908c2ecf20Sopenharmony_ci					  type *s, u##bits val)		\
14918c2ecf20Sopenharmony_ci{									\
14928c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member);	\
14938c2ecf20Sopenharmony_ci	btrfs_set_token_##bits(token, s, offsetof(type, member), val);	\
14948c2ecf20Sopenharmony_ci}
14958c2ecf20Sopenharmony_ci
14968c2ecf20Sopenharmony_ci#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits)		\
14978c2ecf20Sopenharmony_cistatic inline u##bits btrfs_##name(const struct extent_buffer *eb)	\
14988c2ecf20Sopenharmony_ci{									\
14998c2ecf20Sopenharmony_ci	const type *p = page_address(eb->pages[0]);			\
15008c2ecf20Sopenharmony_ci	return get_unaligned_le##bits(&p->member);			\
15018c2ecf20Sopenharmony_ci}									\
15028c2ecf20Sopenharmony_cistatic inline void btrfs_set_##name(const struct extent_buffer *eb,	\
15038c2ecf20Sopenharmony_ci				    u##bits val)			\
15048c2ecf20Sopenharmony_ci{									\
15058c2ecf20Sopenharmony_ci	type *p = page_address(eb->pages[0]);				\
15068c2ecf20Sopenharmony_ci	put_unaligned_le##bits(val, &p->member);			\
15078c2ecf20Sopenharmony_ci}
15088c2ecf20Sopenharmony_ci
15098c2ecf20Sopenharmony_ci#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits)		\
15108c2ecf20Sopenharmony_cistatic inline u##bits btrfs_##name(const type *s)			\
15118c2ecf20Sopenharmony_ci{									\
15128c2ecf20Sopenharmony_ci	return get_unaligned_le##bits(&s->member);			\
15138c2ecf20Sopenharmony_ci}									\
15148c2ecf20Sopenharmony_cistatic inline void btrfs_set_##name(type *s, u##bits val)		\
15158c2ecf20Sopenharmony_ci{									\
15168c2ecf20Sopenharmony_ci	put_unaligned_le##bits(val, &s->member);			\
15178c2ecf20Sopenharmony_ci}
15188c2ecf20Sopenharmony_ci
15198c2ecf20Sopenharmony_cistatic inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
15208c2ecf20Sopenharmony_ci					   struct btrfs_dev_item *s)
15218c2ecf20Sopenharmony_ci{
15228c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(u64) !=
15238c2ecf20Sopenharmony_ci		     sizeof(((struct btrfs_dev_item *)0))->total_bytes);
15248c2ecf20Sopenharmony_ci	return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
15258c2ecf20Sopenharmony_ci					    total_bytes));
15268c2ecf20Sopenharmony_ci}
15278c2ecf20Sopenharmony_cistatic inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
15288c2ecf20Sopenharmony_ci						struct btrfs_dev_item *s,
15298c2ecf20Sopenharmony_ci						u64 val)
15308c2ecf20Sopenharmony_ci{
15318c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(u64) !=
15328c2ecf20Sopenharmony_ci		     sizeof(((struct btrfs_dev_item *)0))->total_bytes);
15338c2ecf20Sopenharmony_ci	WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize));
15348c2ecf20Sopenharmony_ci	btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
15358c2ecf20Sopenharmony_ci}
15368c2ecf20Sopenharmony_ci
15378c2ecf20Sopenharmony_ci
15388c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
15398c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
15408c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
15418c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
15428c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
15438c2ecf20Sopenharmony_ci		   start_offset, 64);
15448c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
15458c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
15468c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
15478c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
15488c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
15498c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
15508c2ecf20Sopenharmony_ci
15518c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
15528c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
15538c2ecf20Sopenharmony_ci			 total_bytes, 64);
15548c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
15558c2ecf20Sopenharmony_ci			 bytes_used, 64);
15568c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
15578c2ecf20Sopenharmony_ci			 io_align, 32);
15588c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
15598c2ecf20Sopenharmony_ci			 io_width, 32);
15608c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
15618c2ecf20Sopenharmony_ci			 sector_size, 32);
15628c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
15638c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
15648c2ecf20Sopenharmony_ci			 dev_group, 32);
15658c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
15668c2ecf20Sopenharmony_ci			 seek_speed, 8);
15678c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
15688c2ecf20Sopenharmony_ci			 bandwidth, 8);
15698c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
15708c2ecf20Sopenharmony_ci			 generation, 64);
15718c2ecf20Sopenharmony_ci
15728c2ecf20Sopenharmony_cistatic inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d)
15738c2ecf20Sopenharmony_ci{
15748c2ecf20Sopenharmony_ci	return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid);
15758c2ecf20Sopenharmony_ci}
15768c2ecf20Sopenharmony_ci
15778c2ecf20Sopenharmony_cistatic inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d)
15788c2ecf20Sopenharmony_ci{
15798c2ecf20Sopenharmony_ci	return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid);
15808c2ecf20Sopenharmony_ci}
15818c2ecf20Sopenharmony_ci
15828c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
15838c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
15848c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
15858c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
15868c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
15878c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
15888c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
15898c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
15908c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
15918c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
15928c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
15938c2ecf20Sopenharmony_ci
15948c2ecf20Sopenharmony_cistatic inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
15958c2ecf20Sopenharmony_ci{
15968c2ecf20Sopenharmony_ci	return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
15978c2ecf20Sopenharmony_ci}
15988c2ecf20Sopenharmony_ci
15998c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
16008c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
16018c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
16028c2ecf20Sopenharmony_ci			 stripe_len, 64);
16038c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
16048c2ecf20Sopenharmony_ci			 io_align, 32);
16058c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
16068c2ecf20Sopenharmony_ci			 io_width, 32);
16078c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
16088c2ecf20Sopenharmony_ci			 sector_size, 32);
16098c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
16108c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
16118c2ecf20Sopenharmony_ci			 num_stripes, 16);
16128c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
16138c2ecf20Sopenharmony_ci			 sub_stripes, 16);
16148c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
16158c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
16168c2ecf20Sopenharmony_ci
16178c2ecf20Sopenharmony_cistatic inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
16188c2ecf20Sopenharmony_ci						   int nr)
16198c2ecf20Sopenharmony_ci{
16208c2ecf20Sopenharmony_ci	unsigned long offset = (unsigned long)c;
16218c2ecf20Sopenharmony_ci	offset += offsetof(struct btrfs_chunk, stripe);
16228c2ecf20Sopenharmony_ci	offset += nr * sizeof(struct btrfs_stripe);
16238c2ecf20Sopenharmony_ci	return (struct btrfs_stripe *)offset;
16248c2ecf20Sopenharmony_ci}
16258c2ecf20Sopenharmony_ci
16268c2ecf20Sopenharmony_cistatic inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
16278c2ecf20Sopenharmony_ci{
16288c2ecf20Sopenharmony_ci	return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
16298c2ecf20Sopenharmony_ci}
16308c2ecf20Sopenharmony_ci
16318c2ecf20Sopenharmony_cistatic inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,
16328c2ecf20Sopenharmony_ci					 struct btrfs_chunk *c, int nr)
16338c2ecf20Sopenharmony_ci{
16348c2ecf20Sopenharmony_ci	return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
16358c2ecf20Sopenharmony_ci}
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_cistatic inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb,
16388c2ecf20Sopenharmony_ci					 struct btrfs_chunk *c, int nr)
16398c2ecf20Sopenharmony_ci{
16408c2ecf20Sopenharmony_ci	return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
16418c2ecf20Sopenharmony_ci}
16428c2ecf20Sopenharmony_ci
16438c2ecf20Sopenharmony_ci/* struct btrfs_block_group_item */
16448c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item,
16458c2ecf20Sopenharmony_ci			 used, 64);
16468c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item,
16478c2ecf20Sopenharmony_ci			 used, 64);
16488c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid,
16498c2ecf20Sopenharmony_ci			struct btrfs_block_group_item, chunk_objectid, 64);
16508c2ecf20Sopenharmony_ci
16518c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(block_group_chunk_objectid,
16528c2ecf20Sopenharmony_ci		   struct btrfs_block_group_item, chunk_objectid, 64);
16538c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(block_group_flags,
16548c2ecf20Sopenharmony_ci		   struct btrfs_block_group_item, flags, 64);
16558c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_block_group_flags,
16568c2ecf20Sopenharmony_ci			struct btrfs_block_group_item, flags, 64);
16578c2ecf20Sopenharmony_ci
16588c2ecf20Sopenharmony_ci/* struct btrfs_free_space_info */
16598c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info,
16608c2ecf20Sopenharmony_ci		   extent_count, 32);
16618c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32);
16628c2ecf20Sopenharmony_ci
16638c2ecf20Sopenharmony_ci/* struct btrfs_inode_ref */
16648c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
16658c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
16668c2ecf20Sopenharmony_ci
16678c2ecf20Sopenharmony_ci/* struct btrfs_inode_extref */
16688c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref,
16698c2ecf20Sopenharmony_ci		   parent_objectid, 64);
16708c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref,
16718c2ecf20Sopenharmony_ci		   name_len, 16);
16728c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64);
16738c2ecf20Sopenharmony_ci
16748c2ecf20Sopenharmony_ci/* struct btrfs_inode_item */
16758c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
16768c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
16778c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
16788c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
16798c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
16808c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
16818c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
16828c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
16838c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
16848c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
16858c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
16868c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
16878c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item,
16888c2ecf20Sopenharmony_ci			 generation, 64);
16898c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item,
16908c2ecf20Sopenharmony_ci			 sequence, 64);
16918c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item,
16928c2ecf20Sopenharmony_ci			 transid, 64);
16938c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64);
16948c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item,
16958c2ecf20Sopenharmony_ci			 nbytes, 64);
16968c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item,
16978c2ecf20Sopenharmony_ci			 block_group, 64);
16988c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32);
16998c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32);
17008c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32);
17018c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32);
17028c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64);
17038c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64);
17048c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
17058c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
17068c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64);
17078c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32);
17088c2ecf20Sopenharmony_ci
17098c2ecf20Sopenharmony_ci/* struct btrfs_dev_extent */
17108c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
17118c2ecf20Sopenharmony_ci		   chunk_tree, 64);
17128c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
17138c2ecf20Sopenharmony_ci		   chunk_objectid, 64);
17148c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
17158c2ecf20Sopenharmony_ci		   chunk_offset, 64);
17168c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
17178c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
17188c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
17198c2ecf20Sopenharmony_ci		   generation, 64);
17208c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
17218c2ecf20Sopenharmony_ci
17228c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
17238c2ecf20Sopenharmony_ci
17248c2ecf20Sopenharmony_cistatic inline void btrfs_tree_block_key(const struct extent_buffer *eb,
17258c2ecf20Sopenharmony_ci					struct btrfs_tree_block_info *item,
17268c2ecf20Sopenharmony_ci					struct btrfs_disk_key *key)
17278c2ecf20Sopenharmony_ci{
17288c2ecf20Sopenharmony_ci	read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
17298c2ecf20Sopenharmony_ci}
17308c2ecf20Sopenharmony_ci
17318c2ecf20Sopenharmony_cistatic inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
17328c2ecf20Sopenharmony_ci					    struct btrfs_tree_block_info *item,
17338c2ecf20Sopenharmony_ci					    struct btrfs_disk_key *key)
17348c2ecf20Sopenharmony_ci{
17358c2ecf20Sopenharmony_ci	write_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
17368c2ecf20Sopenharmony_ci}
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref,
17398c2ecf20Sopenharmony_ci		   root, 64);
17408c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref,
17418c2ecf20Sopenharmony_ci		   objectid, 64);
17428c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref,
17438c2ecf20Sopenharmony_ci		   offset, 64);
17448c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref,
17458c2ecf20Sopenharmony_ci		   count, 32);
17468c2ecf20Sopenharmony_ci
17478c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref,
17488c2ecf20Sopenharmony_ci		   count, 32);
17498c2ecf20Sopenharmony_ci
17508c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref,
17518c2ecf20Sopenharmony_ci		   type, 8);
17528c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref,
17538c2ecf20Sopenharmony_ci		   offset, 64);
17548c2ecf20Sopenharmony_ci
17558c2ecf20Sopenharmony_cistatic inline u32 btrfs_extent_inline_ref_size(int type)
17568c2ecf20Sopenharmony_ci{
17578c2ecf20Sopenharmony_ci	if (type == BTRFS_TREE_BLOCK_REF_KEY ||
17588c2ecf20Sopenharmony_ci	    type == BTRFS_SHARED_BLOCK_REF_KEY)
17598c2ecf20Sopenharmony_ci		return sizeof(struct btrfs_extent_inline_ref);
17608c2ecf20Sopenharmony_ci	if (type == BTRFS_SHARED_DATA_REF_KEY)
17618c2ecf20Sopenharmony_ci		return sizeof(struct btrfs_shared_data_ref) +
17628c2ecf20Sopenharmony_ci		       sizeof(struct btrfs_extent_inline_ref);
17638c2ecf20Sopenharmony_ci	if (type == BTRFS_EXTENT_DATA_REF_KEY)
17648c2ecf20Sopenharmony_ci		return sizeof(struct btrfs_extent_data_ref) +
17658c2ecf20Sopenharmony_ci		       offsetof(struct btrfs_extent_inline_ref, offset);
17668c2ecf20Sopenharmony_ci	return 0;
17678c2ecf20Sopenharmony_ci}
17688c2ecf20Sopenharmony_ci
17698c2ecf20Sopenharmony_ci/* struct btrfs_node */
17708c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
17718c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
17728c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr,
17738c2ecf20Sopenharmony_ci			 blockptr, 64);
17748c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
17758c2ecf20Sopenharmony_ci			 generation, 64);
17768c2ecf20Sopenharmony_ci
17778c2ecf20Sopenharmony_cistatic inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
17788c2ecf20Sopenharmony_ci{
17798c2ecf20Sopenharmony_ci	unsigned long ptr;
17808c2ecf20Sopenharmony_ci	ptr = offsetof(struct btrfs_node, ptrs) +
17818c2ecf20Sopenharmony_ci		sizeof(struct btrfs_key_ptr) * nr;
17828c2ecf20Sopenharmony_ci	return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
17838c2ecf20Sopenharmony_ci}
17848c2ecf20Sopenharmony_ci
17858c2ecf20Sopenharmony_cistatic inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
17868c2ecf20Sopenharmony_ci					   int nr, u64 val)
17878c2ecf20Sopenharmony_ci{
17888c2ecf20Sopenharmony_ci	unsigned long ptr;
17898c2ecf20Sopenharmony_ci	ptr = offsetof(struct btrfs_node, ptrs) +
17908c2ecf20Sopenharmony_ci		sizeof(struct btrfs_key_ptr) * nr;
17918c2ecf20Sopenharmony_ci	btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
17928c2ecf20Sopenharmony_ci}
17938c2ecf20Sopenharmony_ci
17948c2ecf20Sopenharmony_cistatic inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
17958c2ecf20Sopenharmony_ci{
17968c2ecf20Sopenharmony_ci	unsigned long ptr;
17978c2ecf20Sopenharmony_ci	ptr = offsetof(struct btrfs_node, ptrs) +
17988c2ecf20Sopenharmony_ci		sizeof(struct btrfs_key_ptr) * nr;
17998c2ecf20Sopenharmony_ci	return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
18008c2ecf20Sopenharmony_ci}
18018c2ecf20Sopenharmony_ci
18028c2ecf20Sopenharmony_cistatic inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
18038c2ecf20Sopenharmony_ci						 int nr, u64 val)
18048c2ecf20Sopenharmony_ci{
18058c2ecf20Sopenharmony_ci	unsigned long ptr;
18068c2ecf20Sopenharmony_ci	ptr = offsetof(struct btrfs_node, ptrs) +
18078c2ecf20Sopenharmony_ci		sizeof(struct btrfs_key_ptr) * nr;
18088c2ecf20Sopenharmony_ci	btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
18098c2ecf20Sopenharmony_ci}
18108c2ecf20Sopenharmony_ci
18118c2ecf20Sopenharmony_cistatic inline unsigned long btrfs_node_key_ptr_offset(int nr)
18128c2ecf20Sopenharmony_ci{
18138c2ecf20Sopenharmony_ci	return offsetof(struct btrfs_node, ptrs) +
18148c2ecf20Sopenharmony_ci		sizeof(struct btrfs_key_ptr) * nr;
18158c2ecf20Sopenharmony_ci}
18168c2ecf20Sopenharmony_ci
18178c2ecf20Sopenharmony_civoid btrfs_node_key(const struct extent_buffer *eb,
18188c2ecf20Sopenharmony_ci		    struct btrfs_disk_key *disk_key, int nr);
18198c2ecf20Sopenharmony_ci
18208c2ecf20Sopenharmony_cistatic inline void btrfs_set_node_key(const struct extent_buffer *eb,
18218c2ecf20Sopenharmony_ci				      struct btrfs_disk_key *disk_key, int nr)
18228c2ecf20Sopenharmony_ci{
18238c2ecf20Sopenharmony_ci	unsigned long ptr;
18248c2ecf20Sopenharmony_ci	ptr = btrfs_node_key_ptr_offset(nr);
18258c2ecf20Sopenharmony_ci	write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
18268c2ecf20Sopenharmony_ci		       struct btrfs_key_ptr, key, disk_key);
18278c2ecf20Sopenharmony_ci}
18288c2ecf20Sopenharmony_ci
18298c2ecf20Sopenharmony_ci/* struct btrfs_item */
18308c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
18318c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
18328c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32);
18338c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32);
18348c2ecf20Sopenharmony_ci
18358c2ecf20Sopenharmony_cistatic inline unsigned long btrfs_item_nr_offset(int nr)
18368c2ecf20Sopenharmony_ci{
18378c2ecf20Sopenharmony_ci	return offsetof(struct btrfs_leaf, items) +
18388c2ecf20Sopenharmony_ci		sizeof(struct btrfs_item) * nr;
18398c2ecf20Sopenharmony_ci}
18408c2ecf20Sopenharmony_ci
18418c2ecf20Sopenharmony_cistatic inline struct btrfs_item *btrfs_item_nr(int nr)
18428c2ecf20Sopenharmony_ci{
18438c2ecf20Sopenharmony_ci	return (struct btrfs_item *)btrfs_item_nr_offset(nr);
18448c2ecf20Sopenharmony_ci}
18458c2ecf20Sopenharmony_ci
18468c2ecf20Sopenharmony_cistatic inline u32 btrfs_item_end(const struct extent_buffer *eb,
18478c2ecf20Sopenharmony_ci				 struct btrfs_item *item)
18488c2ecf20Sopenharmony_ci{
18498c2ecf20Sopenharmony_ci	return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
18508c2ecf20Sopenharmony_ci}
18518c2ecf20Sopenharmony_ci
18528c2ecf20Sopenharmony_cistatic inline u32 btrfs_item_end_nr(const struct extent_buffer *eb, int nr)
18538c2ecf20Sopenharmony_ci{
18548c2ecf20Sopenharmony_ci	return btrfs_item_end(eb, btrfs_item_nr(nr));
18558c2ecf20Sopenharmony_ci}
18568c2ecf20Sopenharmony_ci
18578c2ecf20Sopenharmony_cistatic inline u32 btrfs_item_offset_nr(const struct extent_buffer *eb, int nr)
18588c2ecf20Sopenharmony_ci{
18598c2ecf20Sopenharmony_ci	return btrfs_item_offset(eb, btrfs_item_nr(nr));
18608c2ecf20Sopenharmony_ci}
18618c2ecf20Sopenharmony_ci
18628c2ecf20Sopenharmony_cistatic inline u32 btrfs_item_size_nr(const struct extent_buffer *eb, int nr)
18638c2ecf20Sopenharmony_ci{
18648c2ecf20Sopenharmony_ci	return btrfs_item_size(eb, btrfs_item_nr(nr));
18658c2ecf20Sopenharmony_ci}
18668c2ecf20Sopenharmony_ci
18678c2ecf20Sopenharmony_cistatic inline void btrfs_item_key(const struct extent_buffer *eb,
18688c2ecf20Sopenharmony_ci			   struct btrfs_disk_key *disk_key, int nr)
18698c2ecf20Sopenharmony_ci{
18708c2ecf20Sopenharmony_ci	struct btrfs_item *item = btrfs_item_nr(nr);
18718c2ecf20Sopenharmony_ci	read_eb_member(eb, item, struct btrfs_item, key, disk_key);
18728c2ecf20Sopenharmony_ci}
18738c2ecf20Sopenharmony_ci
18748c2ecf20Sopenharmony_cistatic inline void btrfs_set_item_key(struct extent_buffer *eb,
18758c2ecf20Sopenharmony_ci			       struct btrfs_disk_key *disk_key, int nr)
18768c2ecf20Sopenharmony_ci{
18778c2ecf20Sopenharmony_ci	struct btrfs_item *item = btrfs_item_nr(nr);
18788c2ecf20Sopenharmony_ci	write_eb_member(eb, item, struct btrfs_item, key, disk_key);
18798c2ecf20Sopenharmony_ci}
18808c2ecf20Sopenharmony_ci
18818c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_ci/*
18848c2ecf20Sopenharmony_ci * struct btrfs_root_ref
18858c2ecf20Sopenharmony_ci */
18868c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
18878c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
18888c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
18898c2ecf20Sopenharmony_ci
18908c2ecf20Sopenharmony_ci/* struct btrfs_dir_item */
18918c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
18928c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
18938c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
18948c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
18958c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8);
18968c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item,
18978c2ecf20Sopenharmony_ci			 data_len, 16);
18988c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item,
18998c2ecf20Sopenharmony_ci			 name_len, 16);
19008c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item,
19018c2ecf20Sopenharmony_ci			 transid, 64);
19028c2ecf20Sopenharmony_ci
19038c2ecf20Sopenharmony_cistatic inline void btrfs_dir_item_key(const struct extent_buffer *eb,
19048c2ecf20Sopenharmony_ci				      const struct btrfs_dir_item *item,
19058c2ecf20Sopenharmony_ci				      struct btrfs_disk_key *key)
19068c2ecf20Sopenharmony_ci{
19078c2ecf20Sopenharmony_ci	read_eb_member(eb, item, struct btrfs_dir_item, location, key);
19088c2ecf20Sopenharmony_ci}
19098c2ecf20Sopenharmony_ci
19108c2ecf20Sopenharmony_cistatic inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
19118c2ecf20Sopenharmony_ci					  struct btrfs_dir_item *item,
19128c2ecf20Sopenharmony_ci					  const struct btrfs_disk_key *key)
19138c2ecf20Sopenharmony_ci{
19148c2ecf20Sopenharmony_ci	write_eb_member(eb, item, struct btrfs_dir_item, location, key);
19158c2ecf20Sopenharmony_ci}
19168c2ecf20Sopenharmony_ci
19178c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header,
19188c2ecf20Sopenharmony_ci		   num_entries, 64);
19198c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header,
19208c2ecf20Sopenharmony_ci		   num_bitmaps, 64);
19218c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header,
19228c2ecf20Sopenharmony_ci		   generation, 64);
19238c2ecf20Sopenharmony_ci
19248c2ecf20Sopenharmony_cistatic inline void btrfs_free_space_key(const struct extent_buffer *eb,
19258c2ecf20Sopenharmony_ci					const struct btrfs_free_space_header *h,
19268c2ecf20Sopenharmony_ci					struct btrfs_disk_key *key)
19278c2ecf20Sopenharmony_ci{
19288c2ecf20Sopenharmony_ci	read_eb_member(eb, h, struct btrfs_free_space_header, location, key);
19298c2ecf20Sopenharmony_ci}
19308c2ecf20Sopenharmony_ci
19318c2ecf20Sopenharmony_cistatic inline void btrfs_set_free_space_key(struct extent_buffer *eb,
19328c2ecf20Sopenharmony_ci					    struct btrfs_free_space_header *h,
19338c2ecf20Sopenharmony_ci					    const struct btrfs_disk_key *key)
19348c2ecf20Sopenharmony_ci{
19358c2ecf20Sopenharmony_ci	write_eb_member(eb, h, struct btrfs_free_space_header, location, key);
19368c2ecf20Sopenharmony_ci}
19378c2ecf20Sopenharmony_ci
19388c2ecf20Sopenharmony_ci/* struct btrfs_disk_key */
19398c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
19408c2ecf20Sopenharmony_ci			 objectid, 64);
19418c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
19428c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
19438c2ecf20Sopenharmony_ci
19448c2ecf20Sopenharmony_ci#ifdef __LITTLE_ENDIAN
19458c2ecf20Sopenharmony_ci
19468c2ecf20Sopenharmony_ci/*
19478c2ecf20Sopenharmony_ci * Optimized helpers for little-endian architectures where CPU and on-disk
19488c2ecf20Sopenharmony_ci * structures have the same endianness and we can skip conversions.
19498c2ecf20Sopenharmony_ci */
19508c2ecf20Sopenharmony_ci
19518c2ecf20Sopenharmony_cistatic inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key,
19528c2ecf20Sopenharmony_ci					 const struct btrfs_disk_key *disk_key)
19538c2ecf20Sopenharmony_ci{
19548c2ecf20Sopenharmony_ci	memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));
19558c2ecf20Sopenharmony_ci}
19568c2ecf20Sopenharmony_ci
19578c2ecf20Sopenharmony_cistatic inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key,
19588c2ecf20Sopenharmony_ci					 const struct btrfs_key *cpu_key)
19598c2ecf20Sopenharmony_ci{
19608c2ecf20Sopenharmony_ci	memcpy(disk_key, cpu_key, sizeof(struct btrfs_key));
19618c2ecf20Sopenharmony_ci}
19628c2ecf20Sopenharmony_ci
19638c2ecf20Sopenharmony_cistatic inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
19648c2ecf20Sopenharmony_ci					 struct btrfs_key *cpu_key, int nr)
19658c2ecf20Sopenharmony_ci{
19668c2ecf20Sopenharmony_ci	struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
19678c2ecf20Sopenharmony_ci
19688c2ecf20Sopenharmony_ci	btrfs_node_key(eb, disk_key, nr);
19698c2ecf20Sopenharmony_ci}
19708c2ecf20Sopenharmony_ci
19718c2ecf20Sopenharmony_cistatic inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
19728c2ecf20Sopenharmony_ci					 struct btrfs_key *cpu_key, int nr)
19738c2ecf20Sopenharmony_ci{
19748c2ecf20Sopenharmony_ci	struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
19758c2ecf20Sopenharmony_ci
19768c2ecf20Sopenharmony_ci	btrfs_item_key(eb, disk_key, nr);
19778c2ecf20Sopenharmony_ci}
19788c2ecf20Sopenharmony_ci
19798c2ecf20Sopenharmony_cistatic inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
19808c2ecf20Sopenharmony_ci					     const struct btrfs_dir_item *item,
19818c2ecf20Sopenharmony_ci					     struct btrfs_key *cpu_key)
19828c2ecf20Sopenharmony_ci{
19838c2ecf20Sopenharmony_ci	struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
19848c2ecf20Sopenharmony_ci
19858c2ecf20Sopenharmony_ci	btrfs_dir_item_key(eb, item, disk_key);
19868c2ecf20Sopenharmony_ci}
19878c2ecf20Sopenharmony_ci
19888c2ecf20Sopenharmony_ci#else
19898c2ecf20Sopenharmony_ci
19908c2ecf20Sopenharmony_cistatic inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
19918c2ecf20Sopenharmony_ci					 const struct btrfs_disk_key *disk)
19928c2ecf20Sopenharmony_ci{
19938c2ecf20Sopenharmony_ci	cpu->offset = le64_to_cpu(disk->offset);
19948c2ecf20Sopenharmony_ci	cpu->type = disk->type;
19958c2ecf20Sopenharmony_ci	cpu->objectid = le64_to_cpu(disk->objectid);
19968c2ecf20Sopenharmony_ci}
19978c2ecf20Sopenharmony_ci
19988c2ecf20Sopenharmony_cistatic inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
19998c2ecf20Sopenharmony_ci					 const struct btrfs_key *cpu)
20008c2ecf20Sopenharmony_ci{
20018c2ecf20Sopenharmony_ci	disk->offset = cpu_to_le64(cpu->offset);
20028c2ecf20Sopenharmony_ci	disk->type = cpu->type;
20038c2ecf20Sopenharmony_ci	disk->objectid = cpu_to_le64(cpu->objectid);
20048c2ecf20Sopenharmony_ci}
20058c2ecf20Sopenharmony_ci
20068c2ecf20Sopenharmony_cistatic inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
20078c2ecf20Sopenharmony_ci					 struct btrfs_key *key, int nr)
20088c2ecf20Sopenharmony_ci{
20098c2ecf20Sopenharmony_ci	struct btrfs_disk_key disk_key;
20108c2ecf20Sopenharmony_ci	btrfs_node_key(eb, &disk_key, nr);
20118c2ecf20Sopenharmony_ci	btrfs_disk_key_to_cpu(key, &disk_key);
20128c2ecf20Sopenharmony_ci}
20138c2ecf20Sopenharmony_ci
20148c2ecf20Sopenharmony_cistatic inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
20158c2ecf20Sopenharmony_ci					 struct btrfs_key *key, int nr)
20168c2ecf20Sopenharmony_ci{
20178c2ecf20Sopenharmony_ci	struct btrfs_disk_key disk_key;
20188c2ecf20Sopenharmony_ci	btrfs_item_key(eb, &disk_key, nr);
20198c2ecf20Sopenharmony_ci	btrfs_disk_key_to_cpu(key, &disk_key);
20208c2ecf20Sopenharmony_ci}
20218c2ecf20Sopenharmony_ci
20228c2ecf20Sopenharmony_cistatic inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
20238c2ecf20Sopenharmony_ci					     const struct btrfs_dir_item *item,
20248c2ecf20Sopenharmony_ci					     struct btrfs_key *key)
20258c2ecf20Sopenharmony_ci{
20268c2ecf20Sopenharmony_ci	struct btrfs_disk_key disk_key;
20278c2ecf20Sopenharmony_ci	btrfs_dir_item_key(eb, item, &disk_key);
20288c2ecf20Sopenharmony_ci	btrfs_disk_key_to_cpu(key, &disk_key);
20298c2ecf20Sopenharmony_ci}
20308c2ecf20Sopenharmony_ci
20318c2ecf20Sopenharmony_ci#endif
20328c2ecf20Sopenharmony_ci
20338c2ecf20Sopenharmony_ci/* struct btrfs_header */
20348c2ecf20Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
20358c2ecf20Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
20368c2ecf20Sopenharmony_ci			  generation, 64);
20378c2ecf20Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
20388c2ecf20Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
20398c2ecf20Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
20408c2ecf20Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
20418c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
20428c2ecf20Sopenharmony_ci			 generation, 64);
20438c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
20448c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header,
20458c2ecf20Sopenharmony_ci			 nritems, 32);
20468c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
20478c2ecf20Sopenharmony_ci
20488c2ecf20Sopenharmony_cistatic inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
20498c2ecf20Sopenharmony_ci{
20508c2ecf20Sopenharmony_ci	return (btrfs_header_flags(eb) & flag) == flag;
20518c2ecf20Sopenharmony_ci}
20528c2ecf20Sopenharmony_ci
20538c2ecf20Sopenharmony_cistatic inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
20548c2ecf20Sopenharmony_ci{
20558c2ecf20Sopenharmony_ci	u64 flags = btrfs_header_flags(eb);
20568c2ecf20Sopenharmony_ci	btrfs_set_header_flags(eb, flags | flag);
20578c2ecf20Sopenharmony_ci}
20588c2ecf20Sopenharmony_ci
20598c2ecf20Sopenharmony_cistatic inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
20608c2ecf20Sopenharmony_ci{
20618c2ecf20Sopenharmony_ci	u64 flags = btrfs_header_flags(eb);
20628c2ecf20Sopenharmony_ci	btrfs_set_header_flags(eb, flags & ~flag);
20638c2ecf20Sopenharmony_ci}
20648c2ecf20Sopenharmony_ci
20658c2ecf20Sopenharmony_cistatic inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
20668c2ecf20Sopenharmony_ci{
20678c2ecf20Sopenharmony_ci	u64 flags = btrfs_header_flags(eb);
20688c2ecf20Sopenharmony_ci	return flags >> BTRFS_BACKREF_REV_SHIFT;
20698c2ecf20Sopenharmony_ci}
20708c2ecf20Sopenharmony_ci
20718c2ecf20Sopenharmony_cistatic inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
20728c2ecf20Sopenharmony_ci						int rev)
20738c2ecf20Sopenharmony_ci{
20748c2ecf20Sopenharmony_ci	u64 flags = btrfs_header_flags(eb);
20758c2ecf20Sopenharmony_ci	flags &= ~BTRFS_BACKREF_REV_MASK;
20768c2ecf20Sopenharmony_ci	flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
20778c2ecf20Sopenharmony_ci	btrfs_set_header_flags(eb, flags);
20788c2ecf20Sopenharmony_ci}
20798c2ecf20Sopenharmony_ci
20808c2ecf20Sopenharmony_cistatic inline int btrfs_is_leaf(const struct extent_buffer *eb)
20818c2ecf20Sopenharmony_ci{
20828c2ecf20Sopenharmony_ci	return btrfs_header_level(eb) == 0;
20838c2ecf20Sopenharmony_ci}
20848c2ecf20Sopenharmony_ci
20858c2ecf20Sopenharmony_ci/* struct btrfs_root_item */
20868c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
20878c2ecf20Sopenharmony_ci		   generation, 64);
20888c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
20898c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
20908c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
20918c2ecf20Sopenharmony_ci
20928c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
20938c2ecf20Sopenharmony_ci			 generation, 64);
20948c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
20958c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
20968c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
20978c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
20988c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
20998c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
21008c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
21018c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
21028c2ecf20Sopenharmony_ci			 last_snapshot, 64);
21038c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item,
21048c2ecf20Sopenharmony_ci			 generation_v2, 64);
21058c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item,
21068c2ecf20Sopenharmony_ci			 ctransid, 64);
21078c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item,
21088c2ecf20Sopenharmony_ci			 otransid, 64);
21098c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item,
21108c2ecf20Sopenharmony_ci			 stransid, 64);
21118c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item,
21128c2ecf20Sopenharmony_ci			 rtransid, 64);
21138c2ecf20Sopenharmony_ci
21148c2ecf20Sopenharmony_cistatic inline bool btrfs_root_readonly(const struct btrfs_root *root)
21158c2ecf20Sopenharmony_ci{
21168c2ecf20Sopenharmony_ci	return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0;
21178c2ecf20Sopenharmony_ci}
21188c2ecf20Sopenharmony_ci
21198c2ecf20Sopenharmony_cistatic inline bool btrfs_root_dead(const struct btrfs_root *root)
21208c2ecf20Sopenharmony_ci{
21218c2ecf20Sopenharmony_ci	return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_DEAD)) != 0;
21228c2ecf20Sopenharmony_ci}
21238c2ecf20Sopenharmony_ci
21248c2ecf20Sopenharmony_ci/* struct btrfs_root_backup */
21258c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
21268c2ecf20Sopenharmony_ci		   tree_root, 64);
21278c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup,
21288c2ecf20Sopenharmony_ci		   tree_root_gen, 64);
21298c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup,
21308c2ecf20Sopenharmony_ci		   tree_root_level, 8);
21318c2ecf20Sopenharmony_ci
21328c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup,
21338c2ecf20Sopenharmony_ci		   chunk_root, 64);
21348c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup,
21358c2ecf20Sopenharmony_ci		   chunk_root_gen, 64);
21368c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup,
21378c2ecf20Sopenharmony_ci		   chunk_root_level, 8);
21388c2ecf20Sopenharmony_ci
21398c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup,
21408c2ecf20Sopenharmony_ci		   extent_root, 64);
21418c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup,
21428c2ecf20Sopenharmony_ci		   extent_root_gen, 64);
21438c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup,
21448c2ecf20Sopenharmony_ci		   extent_root_level, 8);
21458c2ecf20Sopenharmony_ci
21468c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup,
21478c2ecf20Sopenharmony_ci		   fs_root, 64);
21488c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup,
21498c2ecf20Sopenharmony_ci		   fs_root_gen, 64);
21508c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup,
21518c2ecf20Sopenharmony_ci		   fs_root_level, 8);
21528c2ecf20Sopenharmony_ci
21538c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup,
21548c2ecf20Sopenharmony_ci		   dev_root, 64);
21558c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup,
21568c2ecf20Sopenharmony_ci		   dev_root_gen, 64);
21578c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup,
21588c2ecf20Sopenharmony_ci		   dev_root_level, 8);
21598c2ecf20Sopenharmony_ci
21608c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup,
21618c2ecf20Sopenharmony_ci		   csum_root, 64);
21628c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup,
21638c2ecf20Sopenharmony_ci		   csum_root_gen, 64);
21648c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup,
21658c2ecf20Sopenharmony_ci		   csum_root_level, 8);
21668c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup,
21678c2ecf20Sopenharmony_ci		   total_bytes, 64);
21688c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
21698c2ecf20Sopenharmony_ci		   bytes_used, 64);
21708c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
21718c2ecf20Sopenharmony_ci		   num_devices, 64);
21728c2ecf20Sopenharmony_ci
21738c2ecf20Sopenharmony_ci/* struct btrfs_balance_item */
21748c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64);
21758c2ecf20Sopenharmony_ci
21768c2ecf20Sopenharmony_cistatic inline void btrfs_balance_data(const struct extent_buffer *eb,
21778c2ecf20Sopenharmony_ci				      const struct btrfs_balance_item *bi,
21788c2ecf20Sopenharmony_ci				      struct btrfs_disk_balance_args *ba)
21798c2ecf20Sopenharmony_ci{
21808c2ecf20Sopenharmony_ci	read_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
21818c2ecf20Sopenharmony_ci}
21828c2ecf20Sopenharmony_ci
21838c2ecf20Sopenharmony_cistatic inline void btrfs_set_balance_data(struct extent_buffer *eb,
21848c2ecf20Sopenharmony_ci				  struct btrfs_balance_item *bi,
21858c2ecf20Sopenharmony_ci				  const struct btrfs_disk_balance_args *ba)
21868c2ecf20Sopenharmony_ci{
21878c2ecf20Sopenharmony_ci	write_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
21888c2ecf20Sopenharmony_ci}
21898c2ecf20Sopenharmony_ci
21908c2ecf20Sopenharmony_cistatic inline void btrfs_balance_meta(const struct extent_buffer *eb,
21918c2ecf20Sopenharmony_ci				      const struct btrfs_balance_item *bi,
21928c2ecf20Sopenharmony_ci				      struct btrfs_disk_balance_args *ba)
21938c2ecf20Sopenharmony_ci{
21948c2ecf20Sopenharmony_ci	read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
21958c2ecf20Sopenharmony_ci}
21968c2ecf20Sopenharmony_ci
21978c2ecf20Sopenharmony_cistatic inline void btrfs_set_balance_meta(struct extent_buffer *eb,
21988c2ecf20Sopenharmony_ci				  struct btrfs_balance_item *bi,
21998c2ecf20Sopenharmony_ci				  const struct btrfs_disk_balance_args *ba)
22008c2ecf20Sopenharmony_ci{
22018c2ecf20Sopenharmony_ci	write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
22028c2ecf20Sopenharmony_ci}
22038c2ecf20Sopenharmony_ci
22048c2ecf20Sopenharmony_cistatic inline void btrfs_balance_sys(const struct extent_buffer *eb,
22058c2ecf20Sopenharmony_ci				     const struct btrfs_balance_item *bi,
22068c2ecf20Sopenharmony_ci				     struct btrfs_disk_balance_args *ba)
22078c2ecf20Sopenharmony_ci{
22088c2ecf20Sopenharmony_ci	read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
22098c2ecf20Sopenharmony_ci}
22108c2ecf20Sopenharmony_ci
22118c2ecf20Sopenharmony_cistatic inline void btrfs_set_balance_sys(struct extent_buffer *eb,
22128c2ecf20Sopenharmony_ci				 struct btrfs_balance_item *bi,
22138c2ecf20Sopenharmony_ci				 const struct btrfs_disk_balance_args *ba)
22148c2ecf20Sopenharmony_ci{
22158c2ecf20Sopenharmony_ci	write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
22168c2ecf20Sopenharmony_ci}
22178c2ecf20Sopenharmony_ci
22188c2ecf20Sopenharmony_cistatic inline void
22198c2ecf20Sopenharmony_cibtrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu,
22208c2ecf20Sopenharmony_ci			       const struct btrfs_disk_balance_args *disk)
22218c2ecf20Sopenharmony_ci{
22228c2ecf20Sopenharmony_ci	memset(cpu, 0, sizeof(*cpu));
22238c2ecf20Sopenharmony_ci
22248c2ecf20Sopenharmony_ci	cpu->profiles = le64_to_cpu(disk->profiles);
22258c2ecf20Sopenharmony_ci	cpu->usage = le64_to_cpu(disk->usage);
22268c2ecf20Sopenharmony_ci	cpu->devid = le64_to_cpu(disk->devid);
22278c2ecf20Sopenharmony_ci	cpu->pstart = le64_to_cpu(disk->pstart);
22288c2ecf20Sopenharmony_ci	cpu->pend = le64_to_cpu(disk->pend);
22298c2ecf20Sopenharmony_ci	cpu->vstart = le64_to_cpu(disk->vstart);
22308c2ecf20Sopenharmony_ci	cpu->vend = le64_to_cpu(disk->vend);
22318c2ecf20Sopenharmony_ci	cpu->target = le64_to_cpu(disk->target);
22328c2ecf20Sopenharmony_ci	cpu->flags = le64_to_cpu(disk->flags);
22338c2ecf20Sopenharmony_ci	cpu->limit = le64_to_cpu(disk->limit);
22348c2ecf20Sopenharmony_ci	cpu->stripes_min = le32_to_cpu(disk->stripes_min);
22358c2ecf20Sopenharmony_ci	cpu->stripes_max = le32_to_cpu(disk->stripes_max);
22368c2ecf20Sopenharmony_ci}
22378c2ecf20Sopenharmony_ci
22388c2ecf20Sopenharmony_cistatic inline void
22398c2ecf20Sopenharmony_cibtrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
22408c2ecf20Sopenharmony_ci			       const struct btrfs_balance_args *cpu)
22418c2ecf20Sopenharmony_ci{
22428c2ecf20Sopenharmony_ci	memset(disk, 0, sizeof(*disk));
22438c2ecf20Sopenharmony_ci
22448c2ecf20Sopenharmony_ci	disk->profiles = cpu_to_le64(cpu->profiles);
22458c2ecf20Sopenharmony_ci	disk->usage = cpu_to_le64(cpu->usage);
22468c2ecf20Sopenharmony_ci	disk->devid = cpu_to_le64(cpu->devid);
22478c2ecf20Sopenharmony_ci	disk->pstart = cpu_to_le64(cpu->pstart);
22488c2ecf20Sopenharmony_ci	disk->pend = cpu_to_le64(cpu->pend);
22498c2ecf20Sopenharmony_ci	disk->vstart = cpu_to_le64(cpu->vstart);
22508c2ecf20Sopenharmony_ci	disk->vend = cpu_to_le64(cpu->vend);
22518c2ecf20Sopenharmony_ci	disk->target = cpu_to_le64(cpu->target);
22528c2ecf20Sopenharmony_ci	disk->flags = cpu_to_le64(cpu->flags);
22538c2ecf20Sopenharmony_ci	disk->limit = cpu_to_le64(cpu->limit);
22548c2ecf20Sopenharmony_ci	disk->stripes_min = cpu_to_le32(cpu->stripes_min);
22558c2ecf20Sopenharmony_ci	disk->stripes_max = cpu_to_le32(cpu->stripes_max);
22568c2ecf20Sopenharmony_ci}
22578c2ecf20Sopenharmony_ci
22588c2ecf20Sopenharmony_ci/* struct btrfs_super_block */
22598c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
22608c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
22618c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
22628c2ecf20Sopenharmony_ci			 generation, 64);
22638c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
22648c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
22658c2ecf20Sopenharmony_ci			 struct btrfs_super_block, sys_chunk_array_size, 32);
22668c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
22678c2ecf20Sopenharmony_ci			 struct btrfs_super_block, chunk_root_generation, 64);
22688c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
22698c2ecf20Sopenharmony_ci			 root_level, 8);
22708c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
22718c2ecf20Sopenharmony_ci			 chunk_root, 64);
22728c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
22738c2ecf20Sopenharmony_ci			 chunk_root_level, 8);
22748c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
22758c2ecf20Sopenharmony_ci			 log_root, 64);
22768c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
22778c2ecf20Sopenharmony_ci			 log_root_transid, 64);
22788c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
22798c2ecf20Sopenharmony_ci			 log_root_level, 8);
22808c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
22818c2ecf20Sopenharmony_ci			 total_bytes, 64);
22828c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
22838c2ecf20Sopenharmony_ci			 bytes_used, 64);
22848c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
22858c2ecf20Sopenharmony_ci			 sectorsize, 32);
22868c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
22878c2ecf20Sopenharmony_ci			 nodesize, 32);
22888c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
22898c2ecf20Sopenharmony_ci			 stripesize, 32);
22908c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
22918c2ecf20Sopenharmony_ci			 root_dir_objectid, 64);
22928c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
22938c2ecf20Sopenharmony_ci			 num_devices, 64);
22948c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
22958c2ecf20Sopenharmony_ci			 compat_flags, 64);
22968c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
22978c2ecf20Sopenharmony_ci			 compat_ro_flags, 64);
22988c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
22998c2ecf20Sopenharmony_ci			 incompat_flags, 64);
23008c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
23018c2ecf20Sopenharmony_ci			 csum_type, 16);
23028c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
23038c2ecf20Sopenharmony_ci			 cache_generation, 64);
23048c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
23058c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
23068c2ecf20Sopenharmony_ci			 uuid_tree_generation, 64);
23078c2ecf20Sopenharmony_ci
23088c2ecf20Sopenharmony_ciint btrfs_super_csum_size(const struct btrfs_super_block *s);
23098c2ecf20Sopenharmony_ciconst char *btrfs_super_csum_name(u16 csum_type);
23108c2ecf20Sopenharmony_ciconst char *btrfs_super_csum_driver(u16 csum_type);
23118c2ecf20Sopenharmony_cisize_t __attribute_const__ btrfs_get_num_csums(void);
23128c2ecf20Sopenharmony_ci
23138c2ecf20Sopenharmony_ci
23148c2ecf20Sopenharmony_ci/*
23158c2ecf20Sopenharmony_ci * The leaf data grows from end-to-front in the node.
23168c2ecf20Sopenharmony_ci * this returns the address of the start of the last item,
23178c2ecf20Sopenharmony_ci * which is the stop of the leaf data stack
23188c2ecf20Sopenharmony_ci */
23198c2ecf20Sopenharmony_cistatic inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
23208c2ecf20Sopenharmony_ci{
23218c2ecf20Sopenharmony_ci	u32 nr = btrfs_header_nritems(leaf);
23228c2ecf20Sopenharmony_ci
23238c2ecf20Sopenharmony_ci	if (nr == 0)
23248c2ecf20Sopenharmony_ci		return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
23258c2ecf20Sopenharmony_ci	return btrfs_item_offset_nr(leaf, nr - 1);
23268c2ecf20Sopenharmony_ci}
23278c2ecf20Sopenharmony_ci
23288c2ecf20Sopenharmony_ci/* struct btrfs_file_extent_item */
23298c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
23308c2ecf20Sopenharmony_ci			 type, 8);
23318c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
23328c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, disk_bytenr, 64);
23338c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
23348c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, offset, 64);
23358c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation,
23368c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, generation, 64);
23378c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
23388c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, num_bytes, 64);
23398c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes,
23408c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, ram_bytes, 64);
23418c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,
23428c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, disk_num_bytes, 64);
23438c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
23448c2ecf20Sopenharmony_ci			 struct btrfs_file_extent_item, compression, 8);
23458c2ecf20Sopenharmony_ci
23468c2ecf20Sopenharmony_cistatic inline unsigned long
23478c2ecf20Sopenharmony_cibtrfs_file_extent_inline_start(const struct btrfs_file_extent_item *e)
23488c2ecf20Sopenharmony_ci{
23498c2ecf20Sopenharmony_ci	return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START;
23508c2ecf20Sopenharmony_ci}
23518c2ecf20Sopenharmony_ci
23528c2ecf20Sopenharmony_cistatic inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
23538c2ecf20Sopenharmony_ci{
23548c2ecf20Sopenharmony_ci	return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
23558c2ecf20Sopenharmony_ci}
23568c2ecf20Sopenharmony_ci
23578c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
23588c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
23598c2ecf20Sopenharmony_ci		   disk_bytenr, 64);
23608c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
23618c2ecf20Sopenharmony_ci		   generation, 64);
23628c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
23638c2ecf20Sopenharmony_ci		   disk_num_bytes, 64);
23648c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
23658c2ecf20Sopenharmony_ci		  offset, 64);
23668c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
23678c2ecf20Sopenharmony_ci		   num_bytes, 64);
23688c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
23698c2ecf20Sopenharmony_ci		   ram_bytes, 64);
23708c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
23718c2ecf20Sopenharmony_ci		   compression, 8);
23728c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
23738c2ecf20Sopenharmony_ci		   encryption, 8);
23748c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
23758c2ecf20Sopenharmony_ci		   other_encoding, 16);
23768c2ecf20Sopenharmony_ci
23778c2ecf20Sopenharmony_ci/*
23788c2ecf20Sopenharmony_ci * this returns the number of bytes used by the item on disk, minus the
23798c2ecf20Sopenharmony_ci * size of any extent headers.  If a file is compressed on disk, this is
23808c2ecf20Sopenharmony_ci * the compressed size
23818c2ecf20Sopenharmony_ci */
23828c2ecf20Sopenharmony_cistatic inline u32 btrfs_file_extent_inline_item_len(
23838c2ecf20Sopenharmony_ci						const struct extent_buffer *eb,
23848c2ecf20Sopenharmony_ci						struct btrfs_item *e)
23858c2ecf20Sopenharmony_ci{
23868c2ecf20Sopenharmony_ci	return btrfs_item_size(eb, e) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
23878c2ecf20Sopenharmony_ci}
23888c2ecf20Sopenharmony_ci
23898c2ecf20Sopenharmony_ci/* btrfs_qgroup_status_item */
23908c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item,
23918c2ecf20Sopenharmony_ci		   generation, 64);
23928c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item,
23938c2ecf20Sopenharmony_ci		   version, 64);
23948c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
23958c2ecf20Sopenharmony_ci		   flags, 64);
23968c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item,
23978c2ecf20Sopenharmony_ci		   rescan, 64);
23988c2ecf20Sopenharmony_ci
23998c2ecf20Sopenharmony_ci/* btrfs_qgroup_info_item */
24008c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
24018c2ecf20Sopenharmony_ci		   generation, 64);
24028c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64);
24038c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item,
24048c2ecf20Sopenharmony_ci		   rfer_cmpr, 64);
24058c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64);
24068c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item,
24078c2ecf20Sopenharmony_ci		   excl_cmpr, 64);
24088c2ecf20Sopenharmony_ci
24098c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation,
24108c2ecf20Sopenharmony_ci			 struct btrfs_qgroup_info_item, generation, 64);
24118c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item,
24128c2ecf20Sopenharmony_ci			 rfer, 64);
24138c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr,
24148c2ecf20Sopenharmony_ci			 struct btrfs_qgroup_info_item, rfer_cmpr, 64);
24158c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item,
24168c2ecf20Sopenharmony_ci			 excl, 64);
24178c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr,
24188c2ecf20Sopenharmony_ci			 struct btrfs_qgroup_info_item, excl_cmpr, 64);
24198c2ecf20Sopenharmony_ci
24208c2ecf20Sopenharmony_ci/* btrfs_qgroup_limit_item */
24218c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item,
24228c2ecf20Sopenharmony_ci		   flags, 64);
24238c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item,
24248c2ecf20Sopenharmony_ci		   max_rfer, 64);
24258c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item,
24268c2ecf20Sopenharmony_ci		   max_excl, 64);
24278c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item,
24288c2ecf20Sopenharmony_ci		   rsv_rfer, 64);
24298c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item,
24308c2ecf20Sopenharmony_ci		   rsv_excl, 64);
24318c2ecf20Sopenharmony_ci
24328c2ecf20Sopenharmony_ci/* btrfs_dev_replace_item */
24338c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_src_devid,
24348c2ecf20Sopenharmony_ci		   struct btrfs_dev_replace_item, src_devid, 64);
24358c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode,
24368c2ecf20Sopenharmony_ci		   struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode,
24378c2ecf20Sopenharmony_ci		   64);
24388c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item,
24398c2ecf20Sopenharmony_ci		   replace_state, 64);
24408c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item,
24418c2ecf20Sopenharmony_ci		   time_started, 64);
24428c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item,
24438c2ecf20Sopenharmony_ci		   time_stopped, 64);
24448c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item,
24458c2ecf20Sopenharmony_ci		   num_write_errors, 64);
24468c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors,
24478c2ecf20Sopenharmony_ci		   struct btrfs_dev_replace_item, num_uncorrectable_read_errors,
24488c2ecf20Sopenharmony_ci		   64);
24498c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item,
24508c2ecf20Sopenharmony_ci		   cursor_left, 64);
24518c2ecf20Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item,
24528c2ecf20Sopenharmony_ci		   cursor_right, 64);
24538c2ecf20Sopenharmony_ci
24548c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid,
24558c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, src_devid, 64);
24568c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode,
24578c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item,
24588c2ecf20Sopenharmony_ci			 cont_reading_from_srcdev_mode, 64);
24598c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state,
24608c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, replace_state, 64);
24618c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started,
24628c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, time_started, 64);
24638c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped,
24648c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, time_stopped, 64);
24658c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors,
24668c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, num_write_errors, 64);
24678c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors,
24688c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item,
24698c2ecf20Sopenharmony_ci			 num_uncorrectable_read_errors, 64);
24708c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left,
24718c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, cursor_left, 64);
24728c2ecf20Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right,
24738c2ecf20Sopenharmony_ci			 struct btrfs_dev_replace_item, cursor_right, 64);
24748c2ecf20Sopenharmony_ci
24758c2ecf20Sopenharmony_ci/* helper function to cast into the data area of the leaf. */
24768c2ecf20Sopenharmony_ci#define btrfs_item_ptr(leaf, slot, type) \
24778c2ecf20Sopenharmony_ci	((type *)(BTRFS_LEAF_DATA_OFFSET + \
24788c2ecf20Sopenharmony_ci	btrfs_item_offset_nr(leaf, slot)))
24798c2ecf20Sopenharmony_ci
24808c2ecf20Sopenharmony_ci#define btrfs_item_ptr_offset(leaf, slot) \
24818c2ecf20Sopenharmony_ci	((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \
24828c2ecf20Sopenharmony_ci	btrfs_item_offset_nr(leaf, slot)))
24838c2ecf20Sopenharmony_ci
24848c2ecf20Sopenharmony_cistatic inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length)
24858c2ecf20Sopenharmony_ci{
24868c2ecf20Sopenharmony_ci	return crc32c(crc, address, length);
24878c2ecf20Sopenharmony_ci}
24888c2ecf20Sopenharmony_ci
24898c2ecf20Sopenharmony_cistatic inline void btrfs_crc32c_final(u32 crc, u8 *result)
24908c2ecf20Sopenharmony_ci{
24918c2ecf20Sopenharmony_ci	put_unaligned_le32(~crc, result);
24928c2ecf20Sopenharmony_ci}
24938c2ecf20Sopenharmony_ci
24948c2ecf20Sopenharmony_cistatic inline u64 btrfs_name_hash(const char *name, int len)
24958c2ecf20Sopenharmony_ci{
24968c2ecf20Sopenharmony_ci       return crc32c((u32)~1, name, len);
24978c2ecf20Sopenharmony_ci}
24988c2ecf20Sopenharmony_ci
24998c2ecf20Sopenharmony_ci/*
25008c2ecf20Sopenharmony_ci * Figure the key offset of an extended inode ref
25018c2ecf20Sopenharmony_ci */
25028c2ecf20Sopenharmony_cistatic inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name,
25038c2ecf20Sopenharmony_ci                                   int len)
25048c2ecf20Sopenharmony_ci{
25058c2ecf20Sopenharmony_ci       return (u64) crc32c(parent_objectid, name, len);
25068c2ecf20Sopenharmony_ci}
25078c2ecf20Sopenharmony_ci
25088c2ecf20Sopenharmony_cistatic inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
25098c2ecf20Sopenharmony_ci{
25108c2ecf20Sopenharmony_ci	return mapping_gfp_constraint(mapping, ~__GFP_FS);
25118c2ecf20Sopenharmony_ci}
25128c2ecf20Sopenharmony_ci
25138c2ecf20Sopenharmony_ci/* extent-tree.c */
25148c2ecf20Sopenharmony_ci
25158c2ecf20Sopenharmony_cienum btrfs_inline_ref_type {
25168c2ecf20Sopenharmony_ci	BTRFS_REF_TYPE_INVALID,
25178c2ecf20Sopenharmony_ci	BTRFS_REF_TYPE_BLOCK,
25188c2ecf20Sopenharmony_ci	BTRFS_REF_TYPE_DATA,
25198c2ecf20Sopenharmony_ci	BTRFS_REF_TYPE_ANY,
25208c2ecf20Sopenharmony_ci};
25218c2ecf20Sopenharmony_ci
25228c2ecf20Sopenharmony_ciint btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
25238c2ecf20Sopenharmony_ci				     struct btrfs_extent_inline_ref *iref,
25248c2ecf20Sopenharmony_ci				     enum btrfs_inline_ref_type is_data);
25258c2ecf20Sopenharmony_ciu64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
25268c2ecf20Sopenharmony_ci
25278c2ecf20Sopenharmony_ciu64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes);
25288c2ecf20Sopenharmony_ci
25298c2ecf20Sopenharmony_ci/*
25308c2ecf20Sopenharmony_ci * Use this if we would be adding new items, as we could split nodes as we cow
25318c2ecf20Sopenharmony_ci * down the tree.
25328c2ecf20Sopenharmony_ci */
25338c2ecf20Sopenharmony_cistatic inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info,
25348c2ecf20Sopenharmony_ci						  unsigned num_items)
25358c2ecf20Sopenharmony_ci{
25368c2ecf20Sopenharmony_ci	return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
25378c2ecf20Sopenharmony_ci}
25388c2ecf20Sopenharmony_ci
25398c2ecf20Sopenharmony_ci/*
25408c2ecf20Sopenharmony_ci * Doing a truncate or a modification won't result in new nodes or leaves, just
25418c2ecf20Sopenharmony_ci * what we need for COW.
25428c2ecf20Sopenharmony_ci */
25438c2ecf20Sopenharmony_cistatic inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info,
25448c2ecf20Sopenharmony_ci						 unsigned num_items)
25458c2ecf20Sopenharmony_ci{
25468c2ecf20Sopenharmony_ci	return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
25478c2ecf20Sopenharmony_ci}
25488c2ecf20Sopenharmony_ci
25498c2ecf20Sopenharmony_ciint btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info,
25508c2ecf20Sopenharmony_ci			      u64 start, u64 num_bytes);
25518c2ecf20Sopenharmony_civoid btrfs_free_excluded_extents(struct btrfs_block_group *cache);
25528c2ecf20Sopenharmony_ciint btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
25538c2ecf20Sopenharmony_ci			   unsigned long count);
25548c2ecf20Sopenharmony_civoid btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
25558c2ecf20Sopenharmony_ci				  struct btrfs_delayed_ref_root *delayed_refs,
25568c2ecf20Sopenharmony_ci				  struct btrfs_delayed_ref_head *head);
25578c2ecf20Sopenharmony_ciint btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len);
25588c2ecf20Sopenharmony_ciint btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
25598c2ecf20Sopenharmony_ci			     struct btrfs_fs_info *fs_info, u64 bytenr,
25608c2ecf20Sopenharmony_ci			     u64 offset, int metadata, u64 *refs, u64 *flags);
25618c2ecf20Sopenharmony_ciint btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
25628c2ecf20Sopenharmony_ci		     int reserved);
25638c2ecf20Sopenharmony_ciint btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
25648c2ecf20Sopenharmony_ci				    u64 bytenr, u64 num_bytes);
25658c2ecf20Sopenharmony_ciint btrfs_exclude_logged_extents(struct extent_buffer *eb);
25668c2ecf20Sopenharmony_ciint btrfs_cross_ref_exist(struct btrfs_root *root,
25678c2ecf20Sopenharmony_ci			  u64 objectid, u64 offset, u64 bytenr, bool strict);
25688c2ecf20Sopenharmony_cistruct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
25698c2ecf20Sopenharmony_ci					     struct btrfs_root *root,
25708c2ecf20Sopenharmony_ci					     u64 parent, u64 root_objectid,
25718c2ecf20Sopenharmony_ci					     const struct btrfs_disk_key *key,
25728c2ecf20Sopenharmony_ci					     int level, u64 hint,
25738c2ecf20Sopenharmony_ci					     u64 empty_size,
25748c2ecf20Sopenharmony_ci					     enum btrfs_lock_nesting nest);
25758c2ecf20Sopenharmony_civoid btrfs_free_tree_block(struct btrfs_trans_handle *trans,
25768c2ecf20Sopenharmony_ci			   struct btrfs_root *root,
25778c2ecf20Sopenharmony_ci			   struct extent_buffer *buf,
25788c2ecf20Sopenharmony_ci			   u64 parent, int last_ref);
25798c2ecf20Sopenharmony_ciint btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
25808c2ecf20Sopenharmony_ci				     struct btrfs_root *root, u64 owner,
25818c2ecf20Sopenharmony_ci				     u64 offset, u64 ram_bytes,
25828c2ecf20Sopenharmony_ci				     struct btrfs_key *ins);
25838c2ecf20Sopenharmony_ciint btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
25848c2ecf20Sopenharmony_ci				   u64 root_objectid, u64 owner, u64 offset,
25858c2ecf20Sopenharmony_ci				   struct btrfs_key *ins);
25868c2ecf20Sopenharmony_ciint btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes,
25878c2ecf20Sopenharmony_ci			 u64 min_alloc_size, u64 empty_size, u64 hint_byte,
25888c2ecf20Sopenharmony_ci			 struct btrfs_key *ins, int is_data, int delalloc);
25898c2ecf20Sopenharmony_ciint btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
25908c2ecf20Sopenharmony_ci		  struct extent_buffer *buf, int full_backref);
25918c2ecf20Sopenharmony_ciint btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
25928c2ecf20Sopenharmony_ci		  struct extent_buffer *buf, int full_backref);
25938c2ecf20Sopenharmony_ciint btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
25948c2ecf20Sopenharmony_ci				struct extent_buffer *eb, u64 flags,
25958c2ecf20Sopenharmony_ci				int level, int is_data);
25968c2ecf20Sopenharmony_ciint btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
25978c2ecf20Sopenharmony_ci
25988c2ecf20Sopenharmony_ciint btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
25998c2ecf20Sopenharmony_ci			       u64 start, u64 len, int delalloc);
26008c2ecf20Sopenharmony_ciint btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start,
26018c2ecf20Sopenharmony_ci			      u64 len);
26028c2ecf20Sopenharmony_ciint btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
26038c2ecf20Sopenharmony_ciint btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
26048c2ecf20Sopenharmony_ci			 struct btrfs_ref *generic_ref);
26058c2ecf20Sopenharmony_ci
26068c2ecf20Sopenharmony_ciint btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr);
26078c2ecf20Sopenharmony_civoid btrfs_clear_space_info_full(struct btrfs_fs_info *info);
26088c2ecf20Sopenharmony_ci
26098c2ecf20Sopenharmony_ci/*
26108c2ecf20Sopenharmony_ci * Different levels for to flush space when doing space reservations.
26118c2ecf20Sopenharmony_ci *
26128c2ecf20Sopenharmony_ci * The higher the level, the more methods we try to reclaim space.
26138c2ecf20Sopenharmony_ci */
26148c2ecf20Sopenharmony_cienum btrfs_reserve_flush_enum {
26158c2ecf20Sopenharmony_ci	/* If we are in the transaction, we can't flush anything.*/
26168c2ecf20Sopenharmony_ci	BTRFS_RESERVE_NO_FLUSH,
26178c2ecf20Sopenharmony_ci
26188c2ecf20Sopenharmony_ci	/*
26198c2ecf20Sopenharmony_ci	 * Flush space by:
26208c2ecf20Sopenharmony_ci	 * - Running delayed inode items
26218c2ecf20Sopenharmony_ci	 * - Allocating a new chunk
26228c2ecf20Sopenharmony_ci	 */
26238c2ecf20Sopenharmony_ci	BTRFS_RESERVE_FLUSH_LIMIT,
26248c2ecf20Sopenharmony_ci
26258c2ecf20Sopenharmony_ci	/*
26268c2ecf20Sopenharmony_ci	 * Flush space by:
26278c2ecf20Sopenharmony_ci	 * - Running delayed inode items
26288c2ecf20Sopenharmony_ci	 * - Running delayed refs
26298c2ecf20Sopenharmony_ci	 * - Running delalloc and waiting for ordered extents
26308c2ecf20Sopenharmony_ci	 * - Allocating a new chunk
26318c2ecf20Sopenharmony_ci	 */
26328c2ecf20Sopenharmony_ci	BTRFS_RESERVE_FLUSH_EVICT,
26338c2ecf20Sopenharmony_ci
26348c2ecf20Sopenharmony_ci	/*
26358c2ecf20Sopenharmony_ci	 * Flush space by above mentioned methods and by:
26368c2ecf20Sopenharmony_ci	 * - Running delayed iputs
26378c2ecf20Sopenharmony_ci	 * - Commiting transaction
26388c2ecf20Sopenharmony_ci	 *
26398c2ecf20Sopenharmony_ci	 * Can be interruped by fatal signal.
26408c2ecf20Sopenharmony_ci	 */
26418c2ecf20Sopenharmony_ci	BTRFS_RESERVE_FLUSH_DATA,
26428c2ecf20Sopenharmony_ci	BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE,
26438c2ecf20Sopenharmony_ci	BTRFS_RESERVE_FLUSH_ALL,
26448c2ecf20Sopenharmony_ci
26458c2ecf20Sopenharmony_ci	/*
26468c2ecf20Sopenharmony_ci	 * Pretty much the same as FLUSH_ALL, but can also steal space from
26478c2ecf20Sopenharmony_ci	 * global rsv.
26488c2ecf20Sopenharmony_ci	 *
26498c2ecf20Sopenharmony_ci	 * Can be interruped by fatal signal.
26508c2ecf20Sopenharmony_ci	 */
26518c2ecf20Sopenharmony_ci	BTRFS_RESERVE_FLUSH_ALL_STEAL,
26528c2ecf20Sopenharmony_ci};
26538c2ecf20Sopenharmony_ci
26548c2ecf20Sopenharmony_cienum btrfs_flush_state {
26558c2ecf20Sopenharmony_ci	FLUSH_DELAYED_ITEMS_NR	=	1,
26568c2ecf20Sopenharmony_ci	FLUSH_DELAYED_ITEMS	=	2,
26578c2ecf20Sopenharmony_ci	FLUSH_DELAYED_REFS_NR	=	3,
26588c2ecf20Sopenharmony_ci	FLUSH_DELAYED_REFS	=	4,
26598c2ecf20Sopenharmony_ci	FLUSH_DELALLOC		=	5,
26608c2ecf20Sopenharmony_ci	FLUSH_DELALLOC_WAIT	=	6,
26618c2ecf20Sopenharmony_ci	ALLOC_CHUNK		=	7,
26628c2ecf20Sopenharmony_ci	ALLOC_CHUNK_FORCE	=	8,
26638c2ecf20Sopenharmony_ci	RUN_DELAYED_IPUTS	=	9,
26648c2ecf20Sopenharmony_ci	COMMIT_TRANS		=	10,
26658c2ecf20Sopenharmony_ci};
26668c2ecf20Sopenharmony_ci
26678c2ecf20Sopenharmony_ciint btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
26688c2ecf20Sopenharmony_ci				     struct btrfs_block_rsv *rsv,
26698c2ecf20Sopenharmony_ci				     int nitems, bool use_global_rsv);
26708c2ecf20Sopenharmony_civoid btrfs_subvolume_release_metadata(struct btrfs_root *root,
26718c2ecf20Sopenharmony_ci				      struct btrfs_block_rsv *rsv);
26728c2ecf20Sopenharmony_civoid btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
26738c2ecf20Sopenharmony_ci
26748c2ecf20Sopenharmony_ciint btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes);
26758c2ecf20Sopenharmony_ciu64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
26768c2ecf20Sopenharmony_ciint btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
26778c2ecf20Sopenharmony_ci				   u64 start, u64 end);
26788c2ecf20Sopenharmony_ciint btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
26798c2ecf20Sopenharmony_ci			 u64 num_bytes, u64 *actual_bytes);
26808c2ecf20Sopenharmony_ciint btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);
26818c2ecf20Sopenharmony_ci
26828c2ecf20Sopenharmony_ciint btrfs_init_space_info(struct btrfs_fs_info *fs_info);
26838c2ecf20Sopenharmony_ciint btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans,
26848c2ecf20Sopenharmony_ci					 struct btrfs_fs_info *fs_info);
26858c2ecf20Sopenharmony_ciint btrfs_start_write_no_snapshotting(struct btrfs_root *root);
26868c2ecf20Sopenharmony_civoid btrfs_end_write_no_snapshotting(struct btrfs_root *root);
26878c2ecf20Sopenharmony_civoid btrfs_wait_for_snapshot_creation(struct btrfs_root *root);
26888c2ecf20Sopenharmony_ci
26898c2ecf20Sopenharmony_ci/* ctree.c */
26908c2ecf20Sopenharmony_ciint btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
26918c2ecf20Sopenharmony_ci		     int *slot);
26928c2ecf20Sopenharmony_ciint __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
26938c2ecf20Sopenharmony_ciint btrfs_previous_item(struct btrfs_root *root,
26948c2ecf20Sopenharmony_ci			struct btrfs_path *path, u64 min_objectid,
26958c2ecf20Sopenharmony_ci			int type);
26968c2ecf20Sopenharmony_ciint btrfs_previous_extent_item(struct btrfs_root *root,
26978c2ecf20Sopenharmony_ci			struct btrfs_path *path, u64 min_objectid);
26988c2ecf20Sopenharmony_civoid btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
26998c2ecf20Sopenharmony_ci			     struct btrfs_path *path,
27008c2ecf20Sopenharmony_ci			     const struct btrfs_key *new_key);
27018c2ecf20Sopenharmony_cistruct extent_buffer *btrfs_root_node(struct btrfs_root *root);
27028c2ecf20Sopenharmony_ciint btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
27038c2ecf20Sopenharmony_ci			struct btrfs_key *key, int lowest_level,
27048c2ecf20Sopenharmony_ci			u64 min_trans);
27058c2ecf20Sopenharmony_ciint btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
27068c2ecf20Sopenharmony_ci			 struct btrfs_path *path,
27078c2ecf20Sopenharmony_ci			 u64 min_trans);
27088c2ecf20Sopenharmony_cistruct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
27098c2ecf20Sopenharmony_ci					   int slot);
27108c2ecf20Sopenharmony_ci
27118c2ecf20Sopenharmony_ciint btrfs_cow_block(struct btrfs_trans_handle *trans,
27128c2ecf20Sopenharmony_ci		    struct btrfs_root *root, struct extent_buffer *buf,
27138c2ecf20Sopenharmony_ci		    struct extent_buffer *parent, int parent_slot,
27148c2ecf20Sopenharmony_ci		    struct extent_buffer **cow_ret,
27158c2ecf20Sopenharmony_ci		    enum btrfs_lock_nesting nest);
27168c2ecf20Sopenharmony_ciint btrfs_copy_root(struct btrfs_trans_handle *trans,
27178c2ecf20Sopenharmony_ci		      struct btrfs_root *root,
27188c2ecf20Sopenharmony_ci		      struct extent_buffer *buf,
27198c2ecf20Sopenharmony_ci		      struct extent_buffer **cow_ret, u64 new_root_objectid);
27208c2ecf20Sopenharmony_ciint btrfs_block_can_be_shared(struct btrfs_root *root,
27218c2ecf20Sopenharmony_ci			      struct extent_buffer *buf);
27228c2ecf20Sopenharmony_civoid btrfs_extend_item(struct btrfs_path *path, u32 data_size);
27238c2ecf20Sopenharmony_civoid btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end);
27248c2ecf20Sopenharmony_ciint btrfs_split_item(struct btrfs_trans_handle *trans,
27258c2ecf20Sopenharmony_ci		     struct btrfs_root *root,
27268c2ecf20Sopenharmony_ci		     struct btrfs_path *path,
27278c2ecf20Sopenharmony_ci		     const struct btrfs_key *new_key,
27288c2ecf20Sopenharmony_ci		     unsigned long split_offset);
27298c2ecf20Sopenharmony_ciint btrfs_duplicate_item(struct btrfs_trans_handle *trans,
27308c2ecf20Sopenharmony_ci			 struct btrfs_root *root,
27318c2ecf20Sopenharmony_ci			 struct btrfs_path *path,
27328c2ecf20Sopenharmony_ci			 const struct btrfs_key *new_key);
27338c2ecf20Sopenharmony_ciint btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
27348c2ecf20Sopenharmony_ci		u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key);
27358c2ecf20Sopenharmony_ciint btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
27368c2ecf20Sopenharmony_ci		      const struct btrfs_key *key, struct btrfs_path *p,
27378c2ecf20Sopenharmony_ci		      int ins_len, int cow);
27388c2ecf20Sopenharmony_ciint btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
27398c2ecf20Sopenharmony_ci			  struct btrfs_path *p, u64 time_seq);
27408c2ecf20Sopenharmony_ciint btrfs_search_slot_for_read(struct btrfs_root *root,
27418c2ecf20Sopenharmony_ci			       const struct btrfs_key *key,
27428c2ecf20Sopenharmony_ci			       struct btrfs_path *p, int find_higher,
27438c2ecf20Sopenharmony_ci			       int return_any);
27448c2ecf20Sopenharmony_ciint btrfs_realloc_node(struct btrfs_trans_handle *trans,
27458c2ecf20Sopenharmony_ci		       struct btrfs_root *root, struct extent_buffer *parent,
27468c2ecf20Sopenharmony_ci		       int start_slot, u64 *last_ret,
27478c2ecf20Sopenharmony_ci		       struct btrfs_key *progress);
27488c2ecf20Sopenharmony_civoid btrfs_release_path(struct btrfs_path *p);
27498c2ecf20Sopenharmony_cistruct btrfs_path *btrfs_alloc_path(void);
27508c2ecf20Sopenharmony_civoid btrfs_free_path(struct btrfs_path *p);
27518c2ecf20Sopenharmony_ci
27528c2ecf20Sopenharmony_ciint btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
27538c2ecf20Sopenharmony_ci		   struct btrfs_path *path, int slot, int nr);
27548c2ecf20Sopenharmony_cistatic inline int btrfs_del_item(struct btrfs_trans_handle *trans,
27558c2ecf20Sopenharmony_ci				 struct btrfs_root *root,
27568c2ecf20Sopenharmony_ci				 struct btrfs_path *path)
27578c2ecf20Sopenharmony_ci{
27588c2ecf20Sopenharmony_ci	return btrfs_del_items(trans, root, path, path->slots[0], 1);
27598c2ecf20Sopenharmony_ci}
27608c2ecf20Sopenharmony_ci
27618c2ecf20Sopenharmony_civoid setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
27628c2ecf20Sopenharmony_ci			    const struct btrfs_key *cpu_key, u32 *data_size,
27638c2ecf20Sopenharmony_ci			    int nr);
27648c2ecf20Sopenharmony_ciint btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
27658c2ecf20Sopenharmony_ci		      const struct btrfs_key *key, void *data, u32 data_size);
27668c2ecf20Sopenharmony_ciint btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
27678c2ecf20Sopenharmony_ci			     struct btrfs_root *root,
27688c2ecf20Sopenharmony_ci			     struct btrfs_path *path,
27698c2ecf20Sopenharmony_ci			     const struct btrfs_key *cpu_key, u32 *data_size,
27708c2ecf20Sopenharmony_ci			     int nr);
27718c2ecf20Sopenharmony_ci
27728c2ecf20Sopenharmony_cistatic inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
27738c2ecf20Sopenharmony_ci					  struct btrfs_root *root,
27748c2ecf20Sopenharmony_ci					  struct btrfs_path *path,
27758c2ecf20Sopenharmony_ci					  const struct btrfs_key *key,
27768c2ecf20Sopenharmony_ci					  u32 data_size)
27778c2ecf20Sopenharmony_ci{
27788c2ecf20Sopenharmony_ci	return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
27798c2ecf20Sopenharmony_ci}
27808c2ecf20Sopenharmony_ci
27818c2ecf20Sopenharmony_ciint btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
27828c2ecf20Sopenharmony_ciint btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
27838c2ecf20Sopenharmony_ciint btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
27848c2ecf20Sopenharmony_ci			u64 time_seq);
27858c2ecf20Sopenharmony_cistatic inline int btrfs_next_old_item(struct btrfs_root *root,
27868c2ecf20Sopenharmony_ci				      struct btrfs_path *p, u64 time_seq)
27878c2ecf20Sopenharmony_ci{
27888c2ecf20Sopenharmony_ci	++p->slots[0];
27898c2ecf20Sopenharmony_ci	if (p->slots[0] >= btrfs_header_nritems(p->nodes[0]))
27908c2ecf20Sopenharmony_ci		return btrfs_next_old_leaf(root, p, time_seq);
27918c2ecf20Sopenharmony_ci	return 0;
27928c2ecf20Sopenharmony_ci}
27938c2ecf20Sopenharmony_cistatic inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p)
27948c2ecf20Sopenharmony_ci{
27958c2ecf20Sopenharmony_ci	return btrfs_next_old_item(root, p, 0);
27968c2ecf20Sopenharmony_ci}
27978c2ecf20Sopenharmony_ciint btrfs_leaf_free_space(struct extent_buffer *leaf);
27988c2ecf20Sopenharmony_ciint __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref,
27998c2ecf20Sopenharmony_ci				     int for_reloc);
28008c2ecf20Sopenharmony_ciint btrfs_drop_subtree(struct btrfs_trans_handle *trans,
28018c2ecf20Sopenharmony_ci			struct btrfs_root *root,
28028c2ecf20Sopenharmony_ci			struct extent_buffer *node,
28038c2ecf20Sopenharmony_ci			struct extent_buffer *parent);
28048c2ecf20Sopenharmony_cistatic inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
28058c2ecf20Sopenharmony_ci{
28068c2ecf20Sopenharmony_ci	/*
28078c2ecf20Sopenharmony_ci	 * Do it this way so we only ever do one test_bit in the normal case.
28088c2ecf20Sopenharmony_ci	 */
28098c2ecf20Sopenharmony_ci	if (test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags)) {
28108c2ecf20Sopenharmony_ci		if (test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags))
28118c2ecf20Sopenharmony_ci			return 2;
28128c2ecf20Sopenharmony_ci		return 1;
28138c2ecf20Sopenharmony_ci	}
28148c2ecf20Sopenharmony_ci	return 0;
28158c2ecf20Sopenharmony_ci}
28168c2ecf20Sopenharmony_ci
28178c2ecf20Sopenharmony_ci/*
28188c2ecf20Sopenharmony_ci * If we remount the fs to be R/O or umount the fs, the cleaner needn't do
28198c2ecf20Sopenharmony_ci * anything except sleeping. This function is used to check the status of
28208c2ecf20Sopenharmony_ci * the fs.
28218c2ecf20Sopenharmony_ci */
28228c2ecf20Sopenharmony_cistatic inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
28238c2ecf20Sopenharmony_ci{
28248c2ecf20Sopenharmony_ci	return fs_info->sb->s_flags & SB_RDONLY || btrfs_fs_closing(fs_info);
28258c2ecf20Sopenharmony_ci}
28268c2ecf20Sopenharmony_ci
28278c2ecf20Sopenharmony_ci/* tree mod log functions from ctree.c */
28288c2ecf20Sopenharmony_ciu64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
28298c2ecf20Sopenharmony_ci			   struct seq_list *elem);
28308c2ecf20Sopenharmony_civoid btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
28318c2ecf20Sopenharmony_ci			    struct seq_list *elem);
28328c2ecf20Sopenharmony_ciint btrfs_old_root_level(struct btrfs_root *root, u64 time_seq);
28338c2ecf20Sopenharmony_ci
28348c2ecf20Sopenharmony_ci/* root-item.c */
28358c2ecf20Sopenharmony_ciint btrfs_add_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
28368c2ecf20Sopenharmony_ci		       u64 ref_id, u64 dirid, u64 sequence, const char *name,
28378c2ecf20Sopenharmony_ci		       int name_len);
28388c2ecf20Sopenharmony_ciint btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
28398c2ecf20Sopenharmony_ci		       u64 ref_id, u64 dirid, u64 *sequence, const char *name,
28408c2ecf20Sopenharmony_ci		       int name_len);
28418c2ecf20Sopenharmony_ciint btrfs_del_root(struct btrfs_trans_handle *trans,
28428c2ecf20Sopenharmony_ci		   const struct btrfs_key *key);
28438c2ecf20Sopenharmony_ciint btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
28448c2ecf20Sopenharmony_ci		      const struct btrfs_key *key,
28458c2ecf20Sopenharmony_ci		      struct btrfs_root_item *item);
28468c2ecf20Sopenharmony_ciint __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
28478c2ecf20Sopenharmony_ci				   struct btrfs_root *root,
28488c2ecf20Sopenharmony_ci				   struct btrfs_key *key,
28498c2ecf20Sopenharmony_ci				   struct btrfs_root_item *item);
28508c2ecf20Sopenharmony_ciint btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
28518c2ecf20Sopenharmony_ci		    struct btrfs_path *path, struct btrfs_root_item *root_item,
28528c2ecf20Sopenharmony_ci		    struct btrfs_key *root_key);
28538c2ecf20Sopenharmony_ciint btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
28548c2ecf20Sopenharmony_civoid btrfs_set_root_node(struct btrfs_root_item *item,
28558c2ecf20Sopenharmony_ci			 struct extent_buffer *node);
28568c2ecf20Sopenharmony_civoid btrfs_check_and_init_root_item(struct btrfs_root_item *item);
28578c2ecf20Sopenharmony_civoid btrfs_update_root_times(struct btrfs_trans_handle *trans,
28588c2ecf20Sopenharmony_ci			     struct btrfs_root *root);
28598c2ecf20Sopenharmony_ci
28608c2ecf20Sopenharmony_ci/* uuid-tree.c */
28618c2ecf20Sopenharmony_ciint btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
28628c2ecf20Sopenharmony_ci			u64 subid);
28638c2ecf20Sopenharmony_ciint btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
28648c2ecf20Sopenharmony_ci			u64 subid);
28658c2ecf20Sopenharmony_ciint btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);
28668c2ecf20Sopenharmony_ci
28678c2ecf20Sopenharmony_ci/* dir-item.c */
28688c2ecf20Sopenharmony_ciint btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
28698c2ecf20Sopenharmony_ci			  const char *name, int name_len);
28708c2ecf20Sopenharmony_ciint btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
28718c2ecf20Sopenharmony_ci			  int name_len, struct btrfs_inode *dir,
28728c2ecf20Sopenharmony_ci			  struct btrfs_key *location, u8 type, u64 index);
28738c2ecf20Sopenharmony_cistruct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
28748c2ecf20Sopenharmony_ci					     struct btrfs_root *root,
28758c2ecf20Sopenharmony_ci					     struct btrfs_path *path, u64 dir,
28768c2ecf20Sopenharmony_ci					     const char *name, int name_len,
28778c2ecf20Sopenharmony_ci					     int mod);
28788c2ecf20Sopenharmony_cistruct btrfs_dir_item *
28798c2ecf20Sopenharmony_cibtrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
28808c2ecf20Sopenharmony_ci			    struct btrfs_root *root,
28818c2ecf20Sopenharmony_ci			    struct btrfs_path *path, u64 dir,
28828c2ecf20Sopenharmony_ci			    u64 objectid, const char *name, int name_len,
28838c2ecf20Sopenharmony_ci			    int mod);
28848c2ecf20Sopenharmony_cistruct btrfs_dir_item *
28858c2ecf20Sopenharmony_cibtrfs_search_dir_index_item(struct btrfs_root *root,
28868c2ecf20Sopenharmony_ci			    struct btrfs_path *path, u64 dirid,
28878c2ecf20Sopenharmony_ci			    const char *name, int name_len);
28888c2ecf20Sopenharmony_ciint btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
28898c2ecf20Sopenharmony_ci			      struct btrfs_root *root,
28908c2ecf20Sopenharmony_ci			      struct btrfs_path *path,
28918c2ecf20Sopenharmony_ci			      struct btrfs_dir_item *di);
28928c2ecf20Sopenharmony_ciint btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
28938c2ecf20Sopenharmony_ci			    struct btrfs_root *root,
28948c2ecf20Sopenharmony_ci			    struct btrfs_path *path, u64 objectid,
28958c2ecf20Sopenharmony_ci			    const char *name, u16 name_len,
28968c2ecf20Sopenharmony_ci			    const void *data, u16 data_len);
28978c2ecf20Sopenharmony_cistruct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
28988c2ecf20Sopenharmony_ci					  struct btrfs_root *root,
28998c2ecf20Sopenharmony_ci					  struct btrfs_path *path, u64 dir,
29008c2ecf20Sopenharmony_ci					  const char *name, u16 name_len,
29018c2ecf20Sopenharmony_ci					  int mod);
29028c2ecf20Sopenharmony_cistruct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info,
29038c2ecf20Sopenharmony_ci						 struct btrfs_path *path,
29048c2ecf20Sopenharmony_ci						 const char *name,
29058c2ecf20Sopenharmony_ci						 int name_len);
29068c2ecf20Sopenharmony_ci
29078c2ecf20Sopenharmony_ci/* orphan.c */
29088c2ecf20Sopenharmony_ciint btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
29098c2ecf20Sopenharmony_ci			     struct btrfs_root *root, u64 offset);
29108c2ecf20Sopenharmony_ciint btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
29118c2ecf20Sopenharmony_ci			  struct btrfs_root *root, u64 offset);
29128c2ecf20Sopenharmony_ciint btrfs_find_orphan_item(struct btrfs_root *root, u64 offset);
29138c2ecf20Sopenharmony_ci
29148c2ecf20Sopenharmony_ci/* inode-item.c */
29158c2ecf20Sopenharmony_ciint btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
29168c2ecf20Sopenharmony_ci			   struct btrfs_root *root,
29178c2ecf20Sopenharmony_ci			   const char *name, int name_len,
29188c2ecf20Sopenharmony_ci			   u64 inode_objectid, u64 ref_objectid, u64 index);
29198c2ecf20Sopenharmony_ciint btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
29208c2ecf20Sopenharmony_ci			   struct btrfs_root *root,
29218c2ecf20Sopenharmony_ci			   const char *name, int name_len,
29228c2ecf20Sopenharmony_ci			   u64 inode_objectid, u64 ref_objectid, u64 *index);
29238c2ecf20Sopenharmony_ciint btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
29248c2ecf20Sopenharmony_ci			     struct btrfs_root *root,
29258c2ecf20Sopenharmony_ci			     struct btrfs_path *path, u64 objectid);
29268c2ecf20Sopenharmony_ciint btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
29278c2ecf20Sopenharmony_ci		       *root, struct btrfs_path *path,
29288c2ecf20Sopenharmony_ci		       struct btrfs_key *location, int mod);
29298c2ecf20Sopenharmony_ci
29308c2ecf20Sopenharmony_cistruct btrfs_inode_extref *
29318c2ecf20Sopenharmony_cibtrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
29328c2ecf20Sopenharmony_ci			  struct btrfs_root *root,
29338c2ecf20Sopenharmony_ci			  struct btrfs_path *path,
29348c2ecf20Sopenharmony_ci			  const char *name, int name_len,
29358c2ecf20Sopenharmony_ci			  u64 inode_objectid, u64 ref_objectid, int ins_len,
29368c2ecf20Sopenharmony_ci			  int cow);
29378c2ecf20Sopenharmony_ci
29388c2ecf20Sopenharmony_cistruct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
29398c2ecf20Sopenharmony_ci						   int slot, const char *name,
29408c2ecf20Sopenharmony_ci						   int name_len);
29418c2ecf20Sopenharmony_cistruct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
29428c2ecf20Sopenharmony_ci		struct extent_buffer *leaf, int slot, u64 ref_objectid,
29438c2ecf20Sopenharmony_ci		const char *name, int name_len);
29448c2ecf20Sopenharmony_ci/* file-item.c */
29458c2ecf20Sopenharmony_cistruct btrfs_dio_private;
29468c2ecf20Sopenharmony_ciint btrfs_del_csums(struct btrfs_trans_handle *trans,
29478c2ecf20Sopenharmony_ci		    struct btrfs_root *root, u64 bytenr, u64 len);
29488c2ecf20Sopenharmony_ciblk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
29498c2ecf20Sopenharmony_ci				   u64 offset, u8 *dst);
29508c2ecf20Sopenharmony_ciint btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
29518c2ecf20Sopenharmony_ci			     struct btrfs_root *root,
29528c2ecf20Sopenharmony_ci			     u64 objectid, u64 pos,
29538c2ecf20Sopenharmony_ci			     u64 disk_offset, u64 disk_num_bytes,
29548c2ecf20Sopenharmony_ci			     u64 num_bytes, u64 offset, u64 ram_bytes,
29558c2ecf20Sopenharmony_ci			     u8 compression, u8 encryption, u16 other_encoding);
29568c2ecf20Sopenharmony_ciint btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
29578c2ecf20Sopenharmony_ci			     struct btrfs_root *root,
29588c2ecf20Sopenharmony_ci			     struct btrfs_path *path, u64 objectid,
29598c2ecf20Sopenharmony_ci			     u64 bytenr, int mod);
29608c2ecf20Sopenharmony_ciint btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
29618c2ecf20Sopenharmony_ci			   struct btrfs_root *root,
29628c2ecf20Sopenharmony_ci			   struct btrfs_ordered_sum *sums);
29638c2ecf20Sopenharmony_ciblk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
29648c2ecf20Sopenharmony_ci				u64 file_start, int contig);
29658c2ecf20Sopenharmony_ciint btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
29668c2ecf20Sopenharmony_ci			     struct list_head *list, int search_commit);
29678c2ecf20Sopenharmony_civoid btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
29688c2ecf20Sopenharmony_ci				     const struct btrfs_path *path,
29698c2ecf20Sopenharmony_ci				     struct btrfs_file_extent_item *fi,
29708c2ecf20Sopenharmony_ci				     const bool new_inline,
29718c2ecf20Sopenharmony_ci				     struct extent_map *em);
29728c2ecf20Sopenharmony_ciint btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
29738c2ecf20Sopenharmony_ci					u64 len);
29748c2ecf20Sopenharmony_ciint btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start,
29758c2ecf20Sopenharmony_ci				      u64 len);
29768c2ecf20Sopenharmony_civoid btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_i_size);
29778c2ecf20Sopenharmony_ciu64 btrfs_file_extent_end(const struct btrfs_path *path);
29788c2ecf20Sopenharmony_ci
29798c2ecf20Sopenharmony_ci/* inode.c */
29808c2ecf20Sopenharmony_ciblk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
29818c2ecf20Sopenharmony_ci				   int mirror_num, unsigned long bio_flags);
29828c2ecf20Sopenharmony_ciint btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
29838c2ecf20Sopenharmony_ci			   struct page *page, u64 start, u64 end, int mirror);
29848c2ecf20Sopenharmony_cistruct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
29858c2ecf20Sopenharmony_ci					   u64 start, u64 len);
29868c2ecf20Sopenharmony_cinoinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
29878c2ecf20Sopenharmony_ci			      u64 *orig_start, u64 *orig_block_len,
29888c2ecf20Sopenharmony_ci			      u64 *ram_bytes, bool strict);
29898c2ecf20Sopenharmony_ci
29908c2ecf20Sopenharmony_civoid __btrfs_del_delalloc_inode(struct btrfs_root *root,
29918c2ecf20Sopenharmony_ci				struct btrfs_inode *inode);
29928c2ecf20Sopenharmony_cistruct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
29938c2ecf20Sopenharmony_ciint btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index);
29948c2ecf20Sopenharmony_ciint btrfs_unlink_inode(struct btrfs_trans_handle *trans,
29958c2ecf20Sopenharmony_ci		       struct btrfs_root *root,
29968c2ecf20Sopenharmony_ci		       struct btrfs_inode *dir, struct btrfs_inode *inode,
29978c2ecf20Sopenharmony_ci		       const char *name, int name_len);
29988c2ecf20Sopenharmony_ciint btrfs_add_link(struct btrfs_trans_handle *trans,
29998c2ecf20Sopenharmony_ci		   struct btrfs_inode *parent_inode, struct btrfs_inode *inode,
30008c2ecf20Sopenharmony_ci		   const char *name, int name_len, int add_backref, u64 index);
30018c2ecf20Sopenharmony_ciint btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry);
30028c2ecf20Sopenharmony_ciint btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,
30038c2ecf20Sopenharmony_ci			int front);
30048c2ecf20Sopenharmony_ciint btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
30058c2ecf20Sopenharmony_ci			       struct btrfs_root *root,
30068c2ecf20Sopenharmony_ci			       struct inode *inode, u64 new_size,
30078c2ecf20Sopenharmony_ci			       u32 min_type);
30088c2ecf20Sopenharmony_ci
30098c2ecf20Sopenharmony_ciint btrfs_start_delalloc_snapshot(struct btrfs_root *root);
30108c2ecf20Sopenharmony_ciint btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr,
30118c2ecf20Sopenharmony_ci			       bool in_reclaim_context);
30128c2ecf20Sopenharmony_ciint btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
30138c2ecf20Sopenharmony_ci			      unsigned int extra_bits,
30148c2ecf20Sopenharmony_ci			      struct extent_state **cached_state);
30158c2ecf20Sopenharmony_ciint btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
30168c2ecf20Sopenharmony_ci			     struct btrfs_root *new_root,
30178c2ecf20Sopenharmony_ci			     struct btrfs_root *parent_root,
30188c2ecf20Sopenharmony_ci			     u64 new_dirid);
30198c2ecf20Sopenharmony_ci void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
30208c2ecf20Sopenharmony_ci			       unsigned *bits);
30218c2ecf20Sopenharmony_civoid btrfs_clear_delalloc_extent(struct inode *inode,
30228c2ecf20Sopenharmony_ci				 struct extent_state *state, unsigned *bits);
30238c2ecf20Sopenharmony_civoid btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
30248c2ecf20Sopenharmony_ci				 struct extent_state *other);
30258c2ecf20Sopenharmony_civoid btrfs_split_delalloc_extent(struct inode *inode,
30268c2ecf20Sopenharmony_ci				 struct extent_state *orig, u64 split);
30278c2ecf20Sopenharmony_ciint btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
30288c2ecf20Sopenharmony_ci			     unsigned long bio_flags);
30298c2ecf20Sopenharmony_civoid btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
30308c2ecf20Sopenharmony_civm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
30318c2ecf20Sopenharmony_ciint btrfs_readpage(struct file *file, struct page *page);
30328c2ecf20Sopenharmony_civoid btrfs_evict_inode(struct inode *inode);
30338c2ecf20Sopenharmony_ciint btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
30348c2ecf20Sopenharmony_cistruct inode *btrfs_alloc_inode(struct super_block *sb);
30358c2ecf20Sopenharmony_civoid btrfs_destroy_inode(struct inode *inode);
30368c2ecf20Sopenharmony_civoid btrfs_free_inode(struct inode *inode);
30378c2ecf20Sopenharmony_ciint btrfs_drop_inode(struct inode *inode);
30388c2ecf20Sopenharmony_ciint __init btrfs_init_cachep(void);
30398c2ecf20Sopenharmony_civoid __cold btrfs_destroy_cachep(void);
30408c2ecf20Sopenharmony_cistruct inode *btrfs_iget_path(struct super_block *s, u64 ino,
30418c2ecf20Sopenharmony_ci			      struct btrfs_root *root, struct btrfs_path *path);
30428c2ecf20Sopenharmony_cistruct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root);
30438c2ecf20Sopenharmony_cistruct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
30448c2ecf20Sopenharmony_ci				    struct page *page, size_t pg_offset,
30458c2ecf20Sopenharmony_ci				    u64 start, u64 end);
30468c2ecf20Sopenharmony_ciint btrfs_update_inode(struct btrfs_trans_handle *trans,
30478c2ecf20Sopenharmony_ci			      struct btrfs_root *root,
30488c2ecf20Sopenharmony_ci			      struct inode *inode);
30498c2ecf20Sopenharmony_ciint btrfs_update_inode_fallback(struct btrfs_trans_handle *trans,
30508c2ecf20Sopenharmony_ci				struct btrfs_root *root, struct inode *inode);
30518c2ecf20Sopenharmony_ciint btrfs_orphan_add(struct btrfs_trans_handle *trans,
30528c2ecf20Sopenharmony_ci		struct btrfs_inode *inode);
30538c2ecf20Sopenharmony_ciint btrfs_orphan_cleanup(struct btrfs_root *root);
30548c2ecf20Sopenharmony_ciint btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size);
30558c2ecf20Sopenharmony_civoid btrfs_add_delayed_iput(struct inode *inode);
30568c2ecf20Sopenharmony_civoid btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info);
30578c2ecf20Sopenharmony_ciint btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
30588c2ecf20Sopenharmony_ciint btrfs_prealloc_file_range(struct inode *inode, int mode,
30598c2ecf20Sopenharmony_ci			      u64 start, u64 num_bytes, u64 min_size,
30608c2ecf20Sopenharmony_ci			      loff_t actual_len, u64 *alloc_hint);
30618c2ecf20Sopenharmony_ciint btrfs_prealloc_file_range_trans(struct inode *inode,
30628c2ecf20Sopenharmony_ci				    struct btrfs_trans_handle *trans, int mode,
30638c2ecf20Sopenharmony_ci				    u64 start, u64 num_bytes, u64 min_size,
30648c2ecf20Sopenharmony_ci				    loff_t actual_len, u64 *alloc_hint);
30658c2ecf20Sopenharmony_ciint btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page,
30668c2ecf20Sopenharmony_ci		u64 start, u64 end, int *page_started, unsigned long *nr_written,
30678c2ecf20Sopenharmony_ci		struct writeback_control *wbc);
30688c2ecf20Sopenharmony_ciint btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
30698c2ecf20Sopenharmony_civoid btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
30708c2ecf20Sopenharmony_ci					  u64 end, int uptodate);
30718c2ecf20Sopenharmony_ciextern const struct dentry_operations btrfs_dentry_operations;
30728c2ecf20Sopenharmony_cissize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
30738c2ecf20Sopenharmony_ci
30748c2ecf20Sopenharmony_ci/* ioctl.c */
30758c2ecf20Sopenharmony_cilong btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
30768c2ecf20Sopenharmony_cilong btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
30778c2ecf20Sopenharmony_ciint btrfs_ioctl_get_supported_features(void __user *arg);
30788c2ecf20Sopenharmony_civoid btrfs_sync_inode_flags_to_i_flags(struct inode *inode);
30798c2ecf20Sopenharmony_ciint __pure btrfs_is_empty_uuid(u8 *uuid);
30808c2ecf20Sopenharmony_ciint btrfs_defrag_file(struct inode *inode, struct file *file,
30818c2ecf20Sopenharmony_ci		      struct btrfs_ioctl_defrag_range_args *range,
30828c2ecf20Sopenharmony_ci		      u64 newer_than, unsigned long max_pages);
30838c2ecf20Sopenharmony_civoid btrfs_get_block_group_info(struct list_head *groups_list,
30848c2ecf20Sopenharmony_ci				struct btrfs_ioctl_space_info *space);
30858c2ecf20Sopenharmony_civoid btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
30868c2ecf20Sopenharmony_ci			       struct btrfs_ioctl_balance_args *bargs);
30878c2ecf20Sopenharmony_cibool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
30888c2ecf20Sopenharmony_ci			enum btrfs_exclusive_operation type);
30898c2ecf20Sopenharmony_civoid btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
30908c2ecf20Sopenharmony_ci
30918c2ecf20Sopenharmony_ci/* file.c */
30928c2ecf20Sopenharmony_ciint __init btrfs_auto_defrag_init(void);
30938c2ecf20Sopenharmony_civoid __cold btrfs_auto_defrag_exit(void);
30948c2ecf20Sopenharmony_ciint btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
30958c2ecf20Sopenharmony_ci			   struct btrfs_inode *inode);
30968c2ecf20Sopenharmony_ciint btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
30978c2ecf20Sopenharmony_civoid btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info);
30988c2ecf20Sopenharmony_ciint btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
30998c2ecf20Sopenharmony_civoid btrfs_drop_extent_cache(struct btrfs_inode *inode, u64 start, u64 end,
31008c2ecf20Sopenharmony_ci			     int skip_pinned);
31018c2ecf20Sopenharmony_ciextern const struct file_operations btrfs_file_operations;
31028c2ecf20Sopenharmony_ciint __btrfs_drop_extents(struct btrfs_trans_handle *trans,
31038c2ecf20Sopenharmony_ci			 struct btrfs_root *root, struct btrfs_inode *inode,
31048c2ecf20Sopenharmony_ci			 struct btrfs_path *path, u64 start, u64 end,
31058c2ecf20Sopenharmony_ci			 u64 *drop_end, int drop_cache,
31068c2ecf20Sopenharmony_ci			 int replace_extent,
31078c2ecf20Sopenharmony_ci			 u32 extent_item_size,
31088c2ecf20Sopenharmony_ci			 int *key_inserted);
31098c2ecf20Sopenharmony_ciint btrfs_drop_extents(struct btrfs_trans_handle *trans,
31108c2ecf20Sopenharmony_ci		       struct btrfs_root *root, struct inode *inode, u64 start,
31118c2ecf20Sopenharmony_ci		       u64 end, int drop_cache);
31128c2ecf20Sopenharmony_ciint btrfs_replace_file_extents(struct inode *inode, struct btrfs_path *path,
31138c2ecf20Sopenharmony_ci			   const u64 start, const u64 end,
31148c2ecf20Sopenharmony_ci			   struct btrfs_replace_extent_info *extent_info,
31158c2ecf20Sopenharmony_ci			   struct btrfs_trans_handle **trans_out);
31168c2ecf20Sopenharmony_ciint btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
31178c2ecf20Sopenharmony_ci			      struct btrfs_inode *inode, u64 start, u64 end);
31188c2ecf20Sopenharmony_ciint btrfs_release_file(struct inode *inode, struct file *file);
31198c2ecf20Sopenharmony_ciint btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
31208c2ecf20Sopenharmony_ci		      size_t num_pages, loff_t pos, size_t write_bytes,
31218c2ecf20Sopenharmony_ci		      struct extent_state **cached);
31228c2ecf20Sopenharmony_ciint btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
31238c2ecf20Sopenharmony_ciint btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
31248c2ecf20Sopenharmony_ci			   size_t *write_bytes);
31258c2ecf20Sopenharmony_civoid btrfs_check_nocow_unlock(struct btrfs_inode *inode);
31268c2ecf20Sopenharmony_ci
31278c2ecf20Sopenharmony_ci/* tree-defrag.c */
31288c2ecf20Sopenharmony_ciint btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
31298c2ecf20Sopenharmony_ci			struct btrfs_root *root);
31308c2ecf20Sopenharmony_ci
31318c2ecf20Sopenharmony_ci/* super.c */
31328c2ecf20Sopenharmony_ciint btrfs_parse_options(struct btrfs_fs_info *info, char *options,
31338c2ecf20Sopenharmony_ci			unsigned long new_flags);
31348c2ecf20Sopenharmony_ciint btrfs_sync_fs(struct super_block *sb, int wait);
31358c2ecf20Sopenharmony_cichar *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
31368c2ecf20Sopenharmony_ci					  u64 subvol_objectid);
31378c2ecf20Sopenharmony_ci
31388c2ecf20Sopenharmony_cistatic inline __printf(2, 3) __cold
31398c2ecf20Sopenharmony_civoid btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
31408c2ecf20Sopenharmony_ci{
31418c2ecf20Sopenharmony_ci}
31428c2ecf20Sopenharmony_ci
31438c2ecf20Sopenharmony_ci#ifdef CONFIG_PRINTK
31448c2ecf20Sopenharmony_ci__printf(2, 3)
31458c2ecf20Sopenharmony_ci__cold
31468c2ecf20Sopenharmony_civoid btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
31478c2ecf20Sopenharmony_ci#else
31488c2ecf20Sopenharmony_ci#define btrfs_printk(fs_info, fmt, args...) \
31498c2ecf20Sopenharmony_ci	btrfs_no_printk(fs_info, fmt, ##args)
31508c2ecf20Sopenharmony_ci#endif
31518c2ecf20Sopenharmony_ci
31528c2ecf20Sopenharmony_ci#define btrfs_emerg(fs_info, fmt, args...) \
31538c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
31548c2ecf20Sopenharmony_ci#define btrfs_alert(fs_info, fmt, args...) \
31558c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
31568c2ecf20Sopenharmony_ci#define btrfs_crit(fs_info, fmt, args...) \
31578c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
31588c2ecf20Sopenharmony_ci#define btrfs_err(fs_info, fmt, args...) \
31598c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_ERR fmt, ##args)
31608c2ecf20Sopenharmony_ci#define btrfs_warn(fs_info, fmt, args...) \
31618c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
31628c2ecf20Sopenharmony_ci#define btrfs_notice(fs_info, fmt, args...) \
31638c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
31648c2ecf20Sopenharmony_ci#define btrfs_info(fs_info, fmt, args...) \
31658c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_INFO fmt, ##args)
31668c2ecf20Sopenharmony_ci
31678c2ecf20Sopenharmony_ci/*
31688c2ecf20Sopenharmony_ci * Wrappers that use printk_in_rcu
31698c2ecf20Sopenharmony_ci */
31708c2ecf20Sopenharmony_ci#define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
31718c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
31728c2ecf20Sopenharmony_ci#define btrfs_alert_in_rcu(fs_info, fmt, args...) \
31738c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
31748c2ecf20Sopenharmony_ci#define btrfs_crit_in_rcu(fs_info, fmt, args...) \
31758c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
31768c2ecf20Sopenharmony_ci#define btrfs_err_in_rcu(fs_info, fmt, args...) \
31778c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
31788c2ecf20Sopenharmony_ci#define btrfs_warn_in_rcu(fs_info, fmt, args...) \
31798c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
31808c2ecf20Sopenharmony_ci#define btrfs_notice_in_rcu(fs_info, fmt, args...) \
31818c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
31828c2ecf20Sopenharmony_ci#define btrfs_info_in_rcu(fs_info, fmt, args...) \
31838c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
31848c2ecf20Sopenharmony_ci
31858c2ecf20Sopenharmony_ci/*
31868c2ecf20Sopenharmony_ci * Wrappers that use a ratelimited printk_in_rcu
31878c2ecf20Sopenharmony_ci */
31888c2ecf20Sopenharmony_ci#define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
31898c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
31908c2ecf20Sopenharmony_ci#define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
31918c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
31928c2ecf20Sopenharmony_ci#define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
31938c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
31948c2ecf20Sopenharmony_ci#define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
31958c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
31968c2ecf20Sopenharmony_ci#define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
31978c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
31988c2ecf20Sopenharmony_ci#define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
31998c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
32008c2ecf20Sopenharmony_ci#define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
32018c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
32028c2ecf20Sopenharmony_ci
32038c2ecf20Sopenharmony_ci/*
32048c2ecf20Sopenharmony_ci * Wrappers that use a ratelimited printk
32058c2ecf20Sopenharmony_ci */
32068c2ecf20Sopenharmony_ci#define btrfs_emerg_rl(fs_info, fmt, args...) \
32078c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
32088c2ecf20Sopenharmony_ci#define btrfs_alert_rl(fs_info, fmt, args...) \
32098c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
32108c2ecf20Sopenharmony_ci#define btrfs_crit_rl(fs_info, fmt, args...) \
32118c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
32128c2ecf20Sopenharmony_ci#define btrfs_err_rl(fs_info, fmt, args...) \
32138c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
32148c2ecf20Sopenharmony_ci#define btrfs_warn_rl(fs_info, fmt, args...) \
32158c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
32168c2ecf20Sopenharmony_ci#define btrfs_notice_rl(fs_info, fmt, args...) \
32178c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
32188c2ecf20Sopenharmony_ci#define btrfs_info_rl(fs_info, fmt, args...) \
32198c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
32208c2ecf20Sopenharmony_ci
32218c2ecf20Sopenharmony_ci#if defined(CONFIG_DYNAMIC_DEBUG)
32228c2ecf20Sopenharmony_ci#define btrfs_debug(fs_info, fmt, args...)				\
32238c2ecf20Sopenharmony_ci	_dynamic_func_call_no_desc(fmt, btrfs_printk,			\
32248c2ecf20Sopenharmony_ci				   fs_info, KERN_DEBUG fmt, ##args)
32258c2ecf20Sopenharmony_ci#define btrfs_debug_in_rcu(fs_info, fmt, args...)			\
32268c2ecf20Sopenharmony_ci	_dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu,		\
32278c2ecf20Sopenharmony_ci				   fs_info, KERN_DEBUG fmt, ##args)
32288c2ecf20Sopenharmony_ci#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...)			\
32298c2ecf20Sopenharmony_ci	_dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu,		\
32308c2ecf20Sopenharmony_ci				   fs_info, KERN_DEBUG fmt, ##args)
32318c2ecf20Sopenharmony_ci#define btrfs_debug_rl(fs_info, fmt, args...)				\
32328c2ecf20Sopenharmony_ci	_dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited,	\
32338c2ecf20Sopenharmony_ci				   fs_info, KERN_DEBUG fmt, ##args)
32348c2ecf20Sopenharmony_ci#elif defined(DEBUG)
32358c2ecf20Sopenharmony_ci#define btrfs_debug(fs_info, fmt, args...) \
32368c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
32378c2ecf20Sopenharmony_ci#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
32388c2ecf20Sopenharmony_ci	btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
32398c2ecf20Sopenharmony_ci#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
32408c2ecf20Sopenharmony_ci	btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
32418c2ecf20Sopenharmony_ci#define btrfs_debug_rl(fs_info, fmt, args...) \
32428c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
32438c2ecf20Sopenharmony_ci#else
32448c2ecf20Sopenharmony_ci#define btrfs_debug(fs_info, fmt, args...) \
32458c2ecf20Sopenharmony_ci	btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
32468c2ecf20Sopenharmony_ci#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
32478c2ecf20Sopenharmony_ci	btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
32488c2ecf20Sopenharmony_ci#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
32498c2ecf20Sopenharmony_ci	btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
32508c2ecf20Sopenharmony_ci#define btrfs_debug_rl(fs_info, fmt, args...) \
32518c2ecf20Sopenharmony_ci	btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
32528c2ecf20Sopenharmony_ci#endif
32538c2ecf20Sopenharmony_ci
32548c2ecf20Sopenharmony_ci#define btrfs_printk_in_rcu(fs_info, fmt, args...)	\
32558c2ecf20Sopenharmony_cido {							\
32568c2ecf20Sopenharmony_ci	rcu_read_lock();				\
32578c2ecf20Sopenharmony_ci	btrfs_printk(fs_info, fmt, ##args);		\
32588c2ecf20Sopenharmony_ci	rcu_read_unlock();				\
32598c2ecf20Sopenharmony_ci} while (0)
32608c2ecf20Sopenharmony_ci
32618c2ecf20Sopenharmony_ci#define btrfs_no_printk_in_rcu(fs_info, fmt, args...)	\
32628c2ecf20Sopenharmony_cido {							\
32638c2ecf20Sopenharmony_ci	rcu_read_lock();				\
32648c2ecf20Sopenharmony_ci	btrfs_no_printk(fs_info, fmt, ##args);		\
32658c2ecf20Sopenharmony_ci	rcu_read_unlock();				\
32668c2ecf20Sopenharmony_ci} while (0)
32678c2ecf20Sopenharmony_ci
32688c2ecf20Sopenharmony_ci#define btrfs_printk_ratelimited(fs_info, fmt, args...)		\
32698c2ecf20Sopenharmony_cido {								\
32708c2ecf20Sopenharmony_ci	static DEFINE_RATELIMIT_STATE(_rs,			\
32718c2ecf20Sopenharmony_ci		DEFAULT_RATELIMIT_INTERVAL,			\
32728c2ecf20Sopenharmony_ci		DEFAULT_RATELIMIT_BURST);       		\
32738c2ecf20Sopenharmony_ci	if (__ratelimit(&_rs))					\
32748c2ecf20Sopenharmony_ci		btrfs_printk(fs_info, fmt, ##args);		\
32758c2ecf20Sopenharmony_ci} while (0)
32768c2ecf20Sopenharmony_ci
32778c2ecf20Sopenharmony_ci#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...)		\
32788c2ecf20Sopenharmony_cido {								\
32798c2ecf20Sopenharmony_ci	rcu_read_lock();					\
32808c2ecf20Sopenharmony_ci	btrfs_printk_ratelimited(fs_info, fmt, ##args);		\
32818c2ecf20Sopenharmony_ci	rcu_read_unlock();					\
32828c2ecf20Sopenharmony_ci} while (0)
32838c2ecf20Sopenharmony_ci
32848c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_ASSERT
32858c2ecf20Sopenharmony_ci__cold __noreturn
32868c2ecf20Sopenharmony_cistatic inline void assertfail(const char *expr, const char *file, int line)
32878c2ecf20Sopenharmony_ci{
32888c2ecf20Sopenharmony_ci	pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
32898c2ecf20Sopenharmony_ci	BUG();
32908c2ecf20Sopenharmony_ci}
32918c2ecf20Sopenharmony_ci
32928c2ecf20Sopenharmony_ci#define ASSERT(expr)						\
32938c2ecf20Sopenharmony_ci	(likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
32948c2ecf20Sopenharmony_ci
32958c2ecf20Sopenharmony_ci#else
32968c2ecf20Sopenharmony_cistatic inline void assertfail(const char *expr, const char* file, int line) { }
32978c2ecf20Sopenharmony_ci#define ASSERT(expr)	(void)(expr)
32988c2ecf20Sopenharmony_ci#endif
32998c2ecf20Sopenharmony_ci
33008c2ecf20Sopenharmony_ci/*
33018c2ecf20Sopenharmony_ci * Use that for functions that are conditionally exported for sanity tests but
33028c2ecf20Sopenharmony_ci * otherwise static
33038c2ecf20Sopenharmony_ci */
33048c2ecf20Sopenharmony_ci#ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
33058c2ecf20Sopenharmony_ci#define EXPORT_FOR_TESTS static
33068c2ecf20Sopenharmony_ci#else
33078c2ecf20Sopenharmony_ci#define EXPORT_FOR_TESTS
33088c2ecf20Sopenharmony_ci#endif
33098c2ecf20Sopenharmony_ci
33108c2ecf20Sopenharmony_ci__cold
33118c2ecf20Sopenharmony_cistatic inline void btrfs_print_v0_err(struct btrfs_fs_info *fs_info)
33128c2ecf20Sopenharmony_ci{
33138c2ecf20Sopenharmony_ci	btrfs_err(fs_info,
33148c2ecf20Sopenharmony_ci"Unsupported V0 extent filesystem detected. Aborting. Please re-create your filesystem with a newer kernel");
33158c2ecf20Sopenharmony_ci}
33168c2ecf20Sopenharmony_ci
33178c2ecf20Sopenharmony_ci__printf(5, 6)
33188c2ecf20Sopenharmony_ci__cold
33198c2ecf20Sopenharmony_civoid __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
33208c2ecf20Sopenharmony_ci		     unsigned int line, int errno, const char *fmt, ...);
33218c2ecf20Sopenharmony_ci
33228c2ecf20Sopenharmony_ciconst char * __attribute_const__ btrfs_decode_error(int errno);
33238c2ecf20Sopenharmony_ci
33248c2ecf20Sopenharmony_ci__cold
33258c2ecf20Sopenharmony_civoid __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
33268c2ecf20Sopenharmony_ci			       const char *function,
33278c2ecf20Sopenharmony_ci			       unsigned int line, int errno);
33288c2ecf20Sopenharmony_ci
33298c2ecf20Sopenharmony_ci/*
33308c2ecf20Sopenharmony_ci * Call btrfs_abort_transaction as early as possible when an error condition is
33318c2ecf20Sopenharmony_ci * detected, that way the exact line number is reported.
33328c2ecf20Sopenharmony_ci */
33338c2ecf20Sopenharmony_ci#define btrfs_abort_transaction(trans, errno)		\
33348c2ecf20Sopenharmony_cido {								\
33358c2ecf20Sopenharmony_ci	/* Report first abort since mount */			\
33368c2ecf20Sopenharmony_ci	if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,	\
33378c2ecf20Sopenharmony_ci			&((trans)->fs_info->fs_state))) {	\
33388c2ecf20Sopenharmony_ci		if ((errno) != -EIO && (errno) != -EROFS) {		\
33398c2ecf20Sopenharmony_ci			WARN(1, KERN_DEBUG				\
33408c2ecf20Sopenharmony_ci			"BTRFS: Transaction aborted (error %d)\n",	\
33418c2ecf20Sopenharmony_ci			(errno));					\
33428c2ecf20Sopenharmony_ci		} else {						\
33438c2ecf20Sopenharmony_ci			btrfs_debug((trans)->fs_info,			\
33448c2ecf20Sopenharmony_ci				    "Transaction aborted (error %d)", \
33458c2ecf20Sopenharmony_ci				  (errno));			\
33468c2ecf20Sopenharmony_ci		}						\
33478c2ecf20Sopenharmony_ci	}							\
33488c2ecf20Sopenharmony_ci	__btrfs_abort_transaction((trans), __func__,		\
33498c2ecf20Sopenharmony_ci				  __LINE__, (errno));		\
33508c2ecf20Sopenharmony_ci} while (0)
33518c2ecf20Sopenharmony_ci
33528c2ecf20Sopenharmony_ci#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)		\
33538c2ecf20Sopenharmony_cido {								\
33548c2ecf20Sopenharmony_ci	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,	\
33558c2ecf20Sopenharmony_ci			  (errno), fmt, ##args);		\
33568c2ecf20Sopenharmony_ci} while (0)
33578c2ecf20Sopenharmony_ci
33588c2ecf20Sopenharmony_ci__printf(5, 6)
33598c2ecf20Sopenharmony_ci__cold
33608c2ecf20Sopenharmony_civoid __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
33618c2ecf20Sopenharmony_ci		   unsigned int line, int errno, const char *fmt, ...);
33628c2ecf20Sopenharmony_ci/*
33638c2ecf20Sopenharmony_ci * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
33648c2ecf20Sopenharmony_ci * will panic().  Otherwise we BUG() here.
33658c2ecf20Sopenharmony_ci */
33668c2ecf20Sopenharmony_ci#define btrfs_panic(fs_info, errno, fmt, args...)			\
33678c2ecf20Sopenharmony_cido {									\
33688c2ecf20Sopenharmony_ci	__btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args);	\
33698c2ecf20Sopenharmony_ci	BUG();								\
33708c2ecf20Sopenharmony_ci} while (0)
33718c2ecf20Sopenharmony_ci
33728c2ecf20Sopenharmony_ci
33738c2ecf20Sopenharmony_ci/* compatibility and incompatibility defines */
33748c2ecf20Sopenharmony_ci
33758c2ecf20Sopenharmony_ci#define btrfs_set_fs_incompat(__fs_info, opt) \
33768c2ecf20Sopenharmony_ci	__btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
33778c2ecf20Sopenharmony_ci				#opt)
33788c2ecf20Sopenharmony_ci
33798c2ecf20Sopenharmony_cistatic inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info,
33808c2ecf20Sopenharmony_ci					   u64 flag, const char* name)
33818c2ecf20Sopenharmony_ci{
33828c2ecf20Sopenharmony_ci	struct btrfs_super_block *disk_super;
33838c2ecf20Sopenharmony_ci	u64 features;
33848c2ecf20Sopenharmony_ci
33858c2ecf20Sopenharmony_ci	disk_super = fs_info->super_copy;
33868c2ecf20Sopenharmony_ci	features = btrfs_super_incompat_flags(disk_super);
33878c2ecf20Sopenharmony_ci	if (!(features & flag)) {
33888c2ecf20Sopenharmony_ci		spin_lock(&fs_info->super_lock);
33898c2ecf20Sopenharmony_ci		features = btrfs_super_incompat_flags(disk_super);
33908c2ecf20Sopenharmony_ci		if (!(features & flag)) {
33918c2ecf20Sopenharmony_ci			features |= flag;
33928c2ecf20Sopenharmony_ci			btrfs_set_super_incompat_flags(disk_super, features);
33938c2ecf20Sopenharmony_ci			btrfs_info(fs_info,
33948c2ecf20Sopenharmony_ci				"setting incompat feature flag for %s (0x%llx)",
33958c2ecf20Sopenharmony_ci				name, flag);
33968c2ecf20Sopenharmony_ci		}
33978c2ecf20Sopenharmony_ci		spin_unlock(&fs_info->super_lock);
33988c2ecf20Sopenharmony_ci	}
33998c2ecf20Sopenharmony_ci}
34008c2ecf20Sopenharmony_ci
34018c2ecf20Sopenharmony_ci#define btrfs_clear_fs_incompat(__fs_info, opt) \
34028c2ecf20Sopenharmony_ci	__btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
34038c2ecf20Sopenharmony_ci				  #opt)
34048c2ecf20Sopenharmony_ci
34058c2ecf20Sopenharmony_cistatic inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info,
34068c2ecf20Sopenharmony_ci					     u64 flag, const char* name)
34078c2ecf20Sopenharmony_ci{
34088c2ecf20Sopenharmony_ci	struct btrfs_super_block *disk_super;
34098c2ecf20Sopenharmony_ci	u64 features;
34108c2ecf20Sopenharmony_ci
34118c2ecf20Sopenharmony_ci	disk_super = fs_info->super_copy;
34128c2ecf20Sopenharmony_ci	features = btrfs_super_incompat_flags(disk_super);
34138c2ecf20Sopenharmony_ci	if (features & flag) {
34148c2ecf20Sopenharmony_ci		spin_lock(&fs_info->super_lock);
34158c2ecf20Sopenharmony_ci		features = btrfs_super_incompat_flags(disk_super);
34168c2ecf20Sopenharmony_ci		if (features & flag) {
34178c2ecf20Sopenharmony_ci			features &= ~flag;
34188c2ecf20Sopenharmony_ci			btrfs_set_super_incompat_flags(disk_super, features);
34198c2ecf20Sopenharmony_ci			btrfs_info(fs_info,
34208c2ecf20Sopenharmony_ci				"clearing incompat feature flag for %s (0x%llx)",
34218c2ecf20Sopenharmony_ci				name, flag);
34228c2ecf20Sopenharmony_ci		}
34238c2ecf20Sopenharmony_ci		spin_unlock(&fs_info->super_lock);
34248c2ecf20Sopenharmony_ci	}
34258c2ecf20Sopenharmony_ci}
34268c2ecf20Sopenharmony_ci
34278c2ecf20Sopenharmony_ci#define btrfs_fs_incompat(fs_info, opt) \
34288c2ecf20Sopenharmony_ci	__btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
34298c2ecf20Sopenharmony_ci
34308c2ecf20Sopenharmony_cistatic inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
34318c2ecf20Sopenharmony_ci{
34328c2ecf20Sopenharmony_ci	struct btrfs_super_block *disk_super;
34338c2ecf20Sopenharmony_ci	disk_super = fs_info->super_copy;
34348c2ecf20Sopenharmony_ci	return !!(btrfs_super_incompat_flags(disk_super) & flag);
34358c2ecf20Sopenharmony_ci}
34368c2ecf20Sopenharmony_ci
34378c2ecf20Sopenharmony_ci#define btrfs_set_fs_compat_ro(__fs_info, opt) \
34388c2ecf20Sopenharmony_ci	__btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
34398c2ecf20Sopenharmony_ci				 #opt)
34408c2ecf20Sopenharmony_ci
34418c2ecf20Sopenharmony_cistatic inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info,
34428c2ecf20Sopenharmony_ci					    u64 flag, const char *name)
34438c2ecf20Sopenharmony_ci{
34448c2ecf20Sopenharmony_ci	struct btrfs_super_block *disk_super;
34458c2ecf20Sopenharmony_ci	u64 features;
34468c2ecf20Sopenharmony_ci
34478c2ecf20Sopenharmony_ci	disk_super = fs_info->super_copy;
34488c2ecf20Sopenharmony_ci	features = btrfs_super_compat_ro_flags(disk_super);
34498c2ecf20Sopenharmony_ci	if (!(features & flag)) {
34508c2ecf20Sopenharmony_ci		spin_lock(&fs_info->super_lock);
34518c2ecf20Sopenharmony_ci		features = btrfs_super_compat_ro_flags(disk_super);
34528c2ecf20Sopenharmony_ci		if (!(features & flag)) {
34538c2ecf20Sopenharmony_ci			features |= flag;
34548c2ecf20Sopenharmony_ci			btrfs_set_super_compat_ro_flags(disk_super, features);
34558c2ecf20Sopenharmony_ci			btrfs_info(fs_info,
34568c2ecf20Sopenharmony_ci				"setting compat-ro feature flag for %s (0x%llx)",
34578c2ecf20Sopenharmony_ci				name, flag);
34588c2ecf20Sopenharmony_ci		}
34598c2ecf20Sopenharmony_ci		spin_unlock(&fs_info->super_lock);
34608c2ecf20Sopenharmony_ci	}
34618c2ecf20Sopenharmony_ci}
34628c2ecf20Sopenharmony_ci
34638c2ecf20Sopenharmony_ci#define btrfs_clear_fs_compat_ro(__fs_info, opt) \
34648c2ecf20Sopenharmony_ci	__btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
34658c2ecf20Sopenharmony_ci				   #opt)
34668c2ecf20Sopenharmony_ci
34678c2ecf20Sopenharmony_cistatic inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info,
34688c2ecf20Sopenharmony_ci					      u64 flag, const char *name)
34698c2ecf20Sopenharmony_ci{
34708c2ecf20Sopenharmony_ci	struct btrfs_super_block *disk_super;
34718c2ecf20Sopenharmony_ci	u64 features;
34728c2ecf20Sopenharmony_ci
34738c2ecf20Sopenharmony_ci	disk_super = fs_info->super_copy;
34748c2ecf20Sopenharmony_ci	features = btrfs_super_compat_ro_flags(disk_super);
34758c2ecf20Sopenharmony_ci	if (features & flag) {
34768c2ecf20Sopenharmony_ci		spin_lock(&fs_info->super_lock);
34778c2ecf20Sopenharmony_ci		features = btrfs_super_compat_ro_flags(disk_super);
34788c2ecf20Sopenharmony_ci		if (features & flag) {
34798c2ecf20Sopenharmony_ci			features &= ~flag;
34808c2ecf20Sopenharmony_ci			btrfs_set_super_compat_ro_flags(disk_super, features);
34818c2ecf20Sopenharmony_ci			btrfs_info(fs_info,
34828c2ecf20Sopenharmony_ci				"clearing compat-ro feature flag for %s (0x%llx)",
34838c2ecf20Sopenharmony_ci				name, flag);
34848c2ecf20Sopenharmony_ci		}
34858c2ecf20Sopenharmony_ci		spin_unlock(&fs_info->super_lock);
34868c2ecf20Sopenharmony_ci	}
34878c2ecf20Sopenharmony_ci}
34888c2ecf20Sopenharmony_ci
34898c2ecf20Sopenharmony_ci#define btrfs_fs_compat_ro(fs_info, opt) \
34908c2ecf20Sopenharmony_ci	__btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
34918c2ecf20Sopenharmony_ci
34928c2ecf20Sopenharmony_cistatic inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
34938c2ecf20Sopenharmony_ci{
34948c2ecf20Sopenharmony_ci	struct btrfs_super_block *disk_super;
34958c2ecf20Sopenharmony_ci	disk_super = fs_info->super_copy;
34968c2ecf20Sopenharmony_ci	return !!(btrfs_super_compat_ro_flags(disk_super) & flag);
34978c2ecf20Sopenharmony_ci}
34988c2ecf20Sopenharmony_ci
34998c2ecf20Sopenharmony_ci/* acl.c */
35008c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_POSIX_ACL
35018c2ecf20Sopenharmony_cistruct posix_acl *btrfs_get_acl(struct inode *inode, int type);
35028c2ecf20Sopenharmony_ciint btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
35038c2ecf20Sopenharmony_ciint btrfs_init_acl(struct btrfs_trans_handle *trans,
35048c2ecf20Sopenharmony_ci		   struct inode *inode, struct inode *dir);
35058c2ecf20Sopenharmony_ci#else
35068c2ecf20Sopenharmony_ci#define btrfs_get_acl NULL
35078c2ecf20Sopenharmony_ci#define btrfs_set_acl NULL
35088c2ecf20Sopenharmony_cistatic inline int btrfs_init_acl(struct btrfs_trans_handle *trans,
35098c2ecf20Sopenharmony_ci				 struct inode *inode, struct inode *dir)
35108c2ecf20Sopenharmony_ci{
35118c2ecf20Sopenharmony_ci	return 0;
35128c2ecf20Sopenharmony_ci}
35138c2ecf20Sopenharmony_ci#endif
35148c2ecf20Sopenharmony_ci
35158c2ecf20Sopenharmony_ci/* relocation.c */
35168c2ecf20Sopenharmony_ciint btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start);
35178c2ecf20Sopenharmony_ciint btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
35188c2ecf20Sopenharmony_ci			  struct btrfs_root *root);
35198c2ecf20Sopenharmony_ciint btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
35208c2ecf20Sopenharmony_ci			    struct btrfs_root *root);
35218c2ecf20Sopenharmony_ciint btrfs_recover_relocation(struct btrfs_root *root);
35228c2ecf20Sopenharmony_ciint btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len);
35238c2ecf20Sopenharmony_ciint btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
35248c2ecf20Sopenharmony_ci			  struct btrfs_root *root, struct extent_buffer *buf,
35258c2ecf20Sopenharmony_ci			  struct extent_buffer *cow);
35268c2ecf20Sopenharmony_civoid btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending,
35278c2ecf20Sopenharmony_ci			      u64 *bytes_to_reserve);
35288c2ecf20Sopenharmony_ciint btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
35298c2ecf20Sopenharmony_ci			      struct btrfs_pending_snapshot *pending);
35308c2ecf20Sopenharmony_ciint btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info);
35318c2ecf20Sopenharmony_cistruct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info,
35328c2ecf20Sopenharmony_ci				   u64 bytenr);
35338c2ecf20Sopenharmony_ciint btrfs_should_ignore_reloc_root(struct btrfs_root *root);
35348c2ecf20Sopenharmony_ci
35358c2ecf20Sopenharmony_ci/* scrub.c */
35368c2ecf20Sopenharmony_ciint btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
35378c2ecf20Sopenharmony_ci		    u64 end, struct btrfs_scrub_progress *progress,
35388c2ecf20Sopenharmony_ci		    int readonly, int is_dev_replace);
35398c2ecf20Sopenharmony_civoid btrfs_scrub_pause(struct btrfs_fs_info *fs_info);
35408c2ecf20Sopenharmony_civoid btrfs_scrub_continue(struct btrfs_fs_info *fs_info);
35418c2ecf20Sopenharmony_ciint btrfs_scrub_cancel(struct btrfs_fs_info *info);
35428c2ecf20Sopenharmony_ciint btrfs_scrub_cancel_dev(struct btrfs_device *dev);
35438c2ecf20Sopenharmony_ciint btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
35448c2ecf20Sopenharmony_ci			 struct btrfs_scrub_progress *progress);
35458c2ecf20Sopenharmony_cistatic inline void btrfs_init_full_stripe_locks_tree(
35468c2ecf20Sopenharmony_ci			struct btrfs_full_stripe_locks_tree *locks_root)
35478c2ecf20Sopenharmony_ci{
35488c2ecf20Sopenharmony_ci	locks_root->root = RB_ROOT;
35498c2ecf20Sopenharmony_ci	mutex_init(&locks_root->lock);
35508c2ecf20Sopenharmony_ci}
35518c2ecf20Sopenharmony_ci
35528c2ecf20Sopenharmony_ci/* dev-replace.c */
35538c2ecf20Sopenharmony_civoid btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info);
35548c2ecf20Sopenharmony_civoid btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info);
35558c2ecf20Sopenharmony_civoid btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount);
35568c2ecf20Sopenharmony_ci
35578c2ecf20Sopenharmony_cistatic inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info)
35588c2ecf20Sopenharmony_ci{
35598c2ecf20Sopenharmony_ci	btrfs_bio_counter_sub(fs_info, 1);
35608c2ecf20Sopenharmony_ci}
35618c2ecf20Sopenharmony_ci
35628c2ecf20Sopenharmony_ci/* reada.c */
35638c2ecf20Sopenharmony_cistruct reada_control {
35648c2ecf20Sopenharmony_ci	struct btrfs_fs_info	*fs_info;		/* tree to prefetch */
35658c2ecf20Sopenharmony_ci	struct btrfs_key	key_start;
35668c2ecf20Sopenharmony_ci	struct btrfs_key	key_end;	/* exclusive */
35678c2ecf20Sopenharmony_ci	atomic_t		elems;
35688c2ecf20Sopenharmony_ci	struct kref		refcnt;
35698c2ecf20Sopenharmony_ci	wait_queue_head_t	wait;
35708c2ecf20Sopenharmony_ci};
35718c2ecf20Sopenharmony_cistruct reada_control *btrfs_reada_add(struct btrfs_root *root,
35728c2ecf20Sopenharmony_ci			      struct btrfs_key *start, struct btrfs_key *end);
35738c2ecf20Sopenharmony_ciint btrfs_reada_wait(void *handle);
35748c2ecf20Sopenharmony_civoid btrfs_reada_detach(void *handle);
35758c2ecf20Sopenharmony_ciint btree_readahead_hook(struct extent_buffer *eb, int err);
35768c2ecf20Sopenharmony_civoid btrfs_reada_remove_dev(struct btrfs_device *dev);
35778c2ecf20Sopenharmony_civoid btrfs_reada_undo_remove_dev(struct btrfs_device *dev);
35788c2ecf20Sopenharmony_ci
35798c2ecf20Sopenharmony_cistatic inline int is_fstree(u64 rootid)
35808c2ecf20Sopenharmony_ci{
35818c2ecf20Sopenharmony_ci	if (rootid == BTRFS_FS_TREE_OBJECTID ||
35828c2ecf20Sopenharmony_ci	    ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID &&
35838c2ecf20Sopenharmony_ci	      !btrfs_qgroup_level(rootid)))
35848c2ecf20Sopenharmony_ci		return 1;
35858c2ecf20Sopenharmony_ci	return 0;
35868c2ecf20Sopenharmony_ci}
35878c2ecf20Sopenharmony_ci
35888c2ecf20Sopenharmony_cistatic inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
35898c2ecf20Sopenharmony_ci{
35908c2ecf20Sopenharmony_ci	return signal_pending(current);
35918c2ecf20Sopenharmony_ci}
35928c2ecf20Sopenharmony_ci
35938c2ecf20Sopenharmony_ci#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
35948c2ecf20Sopenharmony_ci
35958c2ecf20Sopenharmony_ci/* Sanity test specific functions */
35968c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
35978c2ecf20Sopenharmony_civoid btrfs_test_destroy_inode(struct inode *inode);
35988c2ecf20Sopenharmony_cistatic inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
35998c2ecf20Sopenharmony_ci{
36008c2ecf20Sopenharmony_ci	return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
36018c2ecf20Sopenharmony_ci}
36028c2ecf20Sopenharmony_ci#else
36038c2ecf20Sopenharmony_cistatic inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
36048c2ecf20Sopenharmony_ci{
36058c2ecf20Sopenharmony_ci	return 0;
36068c2ecf20Sopenharmony_ci}
36078c2ecf20Sopenharmony_ci#endif
36088c2ecf20Sopenharmony_ci
36098c2ecf20Sopenharmony_ci#endif
3610