| /* SPDX-License-Identifier: GPL-2.0 */ |
| /* |
| * Copyright (C) 2007 Oracle. All rights reserved. |
| */ |
| |
| #ifndef BTRFS_CTREE_H |
| #define BTRFS_CTREE_H |
| |
| #include <linux/mm.h> |
| #include <linux/sched/signal.h> |
| #include <linux/highmem.h> |
| #include <linux/fs.h> |
| #include <linux/rwsem.h> |
| #include <linux/semaphore.h> |
| #include <linux/completion.h> |
| #include <linux/backing-dev.h> |
| #include <linux/wait.h> |
| #include <linux/slab.h> |
| #include <trace/events/btrfs.h> |
| #include <asm/unaligned.h> |
| #include <linux/pagemap.h> |
| #include <linux/btrfs.h> |
| #include <linux/btrfs_tree.h> |
| #include <linux/workqueue.h> |
| #include <linux/security.h> |
| #include <linux/sizes.h> |
| #include <linux/dynamic_debug.h> |
| #include <linux/refcount.h> |
| #include <linux/crc32c.h> |
| #include <linux/iomap.h> |
| #include <linux/fscrypt.h> |
| #include "extent-io-tree.h" |
| #include "extent_io.h" |
| #include "extent_map.h" |
| #include "async-thread.h" |
| #include "block-rsv.h" |
| #include "locking.h" |
| #include "misc.h" |
| |
| struct btrfs_trans_handle; |
| struct btrfs_transaction; |
| struct btrfs_pending_snapshot; |
| struct btrfs_delayed_ref_root; |
| struct btrfs_space_info; |
| struct btrfs_block_group; |
| struct btrfs_ordered_sum; |
| struct btrfs_ref; |
| struct btrfs_bio; |
| struct btrfs_ioctl_encoded_io_args; |
| struct btrfs_device; |
| struct btrfs_fs_devices; |
| struct btrfs_balance_control; |
| struct btrfs_delayed_root; |
| struct reloc_control; |
| |
| #define BTRFS_OLDEST_GENERATION 0ULL |
| |
| #define BTRFS_EMPTY_DIR_SIZE 0 |
| |
| #define BTRFS_DIRTY_METADATA_THRESH SZ_32M |
| |
| #define BTRFS_MAX_EXTENT_SIZE SZ_128M |
| |
| static inline unsigned long btrfs_chunk_item_size(int num_stripes) |
| { |
| BUG_ON(num_stripes == 0); |
| return sizeof(struct btrfs_chunk) + |
| sizeof(struct btrfs_stripe) * (num_stripes - 1); |
| } |
| |
| #define BTRFS_SUPER_INFO_OFFSET SZ_64K |
| #define BTRFS_SUPER_INFO_SIZE 4096 |
| static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); |
| |
| /* |
| * The reserved space at the beginning of each device. |
| * It covers the primary super block and leaves space for potential use by other |
| * tools like bootloaders or to lower potential damage of accidental overwrite. |
| */ |
| #define BTRFS_DEVICE_RANGE_RESERVED (SZ_1M) |
| |
| /* Read ahead values for struct btrfs_path.reada */ |
| enum { |
| READA_NONE, |
| READA_BACK, |
| READA_FORWARD, |
| /* |
| * Similar to READA_FORWARD but unlike it: |
| * |
| * 1) It will trigger readahead even for leaves that are not close to |
| * each other on disk; |
| * 2) It also triggers readahead for nodes; |
| * 3) During a search, even when a node or leaf is already in memory, it |
| * will still trigger readahead for other nodes and leaves that follow |
| * it. |
| * |
| * This is meant to be used only when we know we are iterating over the |
| * entire tree or a very large part of it. |
| */ |
| READA_FORWARD_ALWAYS, |
| }; |
| |
| /* |
| * btrfs_paths remember the path taken from the root down to the leaf. |
| * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point |
| * to any other levels that are present. |
| * |
| * The slots array records the index of the item or block pointer |
| * used while walking the tree. |
| */ |
| struct btrfs_path { |
| struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
| int slots[BTRFS_MAX_LEVEL]; |
| /* if there is real range locking, this locks field will change */ |
| u8 locks[BTRFS_MAX_LEVEL]; |
| u8 reada; |
| /* keep some upper locks as we walk down */ |
| u8 lowest_level; |
| |
| /* |
| * set by btrfs_split_item, tells search_slot to keep all locks |
| * and to force calls to keep space in the nodes |
| */ |
| unsigned int search_for_split:1; |
| unsigned int keep_locks:1; |
| unsigned int skip_locking:1; |
| unsigned int search_commit_root:1; |
| unsigned int need_commit_sem:1; |
| unsigned int skip_release_on_error:1; |
| /* |
| * Indicate that new item (btrfs_search_slot) is extending already |
| * existing item and ins_len contains only the data size and not item |
| * header (ie. sizeof(struct btrfs_item) is not included). |
| */ |
| unsigned int search_for_extension:1; |
| /* Stop search if any locks need to be taken (for read) */ |
| unsigned int nowait:1; |
| }; |
| |
| struct btrfs_dev_replace { |
| u64 replace_state; /* see #define above */ |
| time64_t time_started; /* seconds since 1-Jan-1970 */ |
| time64_t time_stopped; /* seconds since 1-Jan-1970 */ |
| atomic64_t num_write_errors; |
| atomic64_t num_uncorrectable_read_errors; |
| |
| u64 cursor_left; |
| u64 committed_cursor_left; |
| u64 cursor_left_last_write_of_item; |
| u64 cursor_right; |
| |
| u64 cont_reading_from_srcdev_mode; /* see #define above */ |
| |
| int is_valid; |
| int item_needs_writeback; |
| struct btrfs_device *srcdev; |
| struct btrfs_device *tgtdev; |
| |
| struct mutex lock_finishing_cancel_unmount; |
| struct rw_semaphore rwsem; |
| |
| struct btrfs_scrub_progress scrub_progress; |
| |
| struct percpu_counter bio_counter; |
| wait_queue_head_t replace_wait; |
| }; |
| |
| /* |
| * free clusters are used to claim free space in relatively large chunks, |
| * allowing us to do less seeky writes. They are used for all metadata |
| * allocations. In ssd_spread mode they are also used for data allocations. |
| */ |
| struct btrfs_free_cluster { |
| spinlock_t lock; |
| spinlock_t refill_lock; |
| struct rb_root root; |
| |
| /* largest extent in this cluster */ |
| u64 max_size; |
| |
| /* first extent starting offset */ |
| u64 window_start; |
| |
| /* We did a full search and couldn't create a cluster */ |
| bool fragmented; |
| |
| struct btrfs_block_group *block_group; |
| /* |
| * when a cluster is allocated from a block group, we put the |
| * cluster onto a list in the block group so that it can |
| * be freed before the block group is freed. |
| */ |
| struct list_head block_group_list; |
| }; |
| |
| /* Discard control. */ |
| /* |
| * Async discard uses multiple lists to differentiate the discard filter |
| * parameters. Index 0 is for completely free block groups where we need to |
| * ensure the entire block group is trimmed without being lossy. Indices |
| * afterwards represent monotonically decreasing discard filter sizes to |
| * prioritize what should be discarded next. |
| */ |
| #define BTRFS_NR_DISCARD_LISTS 3 |
| #define BTRFS_DISCARD_INDEX_UNUSED 0 |
| #define BTRFS_DISCARD_INDEX_START 1 |
| |
| struct btrfs_discard_ctl { |
| struct workqueue_struct *discard_workers; |
| struct delayed_work work; |
| spinlock_t lock; |
| struct btrfs_block_group *block_group; |
| struct list_head discard_list[BTRFS_NR_DISCARD_LISTS]; |
| u64 prev_discard; |
| u64 prev_discard_time; |
| atomic_t discardable_extents; |
| atomic64_t discardable_bytes; |
| u64 max_discard_size; |
| u64 delay_ms; |
| u32 iops_limit; |
| u32 kbps_limit; |
| u64 discard_extent_bytes; |
| u64 discard_bitmap_bytes; |
| atomic64_t discard_bytes_saved; |
| }; |
| |
| /* |
| * Exclusive operations (device replace, resize, device add/remove, balance) |
| */ |
| enum btrfs_exclusive_operation { |
| BTRFS_EXCLOP_NONE, |
| BTRFS_EXCLOP_BALANCE_PAUSED, |
| BTRFS_EXCLOP_BALANCE, |
| BTRFS_EXCLOP_DEV_ADD, |
| BTRFS_EXCLOP_DEV_REMOVE, |
| BTRFS_EXCLOP_DEV_REPLACE, |
| BTRFS_EXCLOP_RESIZE, |
| BTRFS_EXCLOP_SWAP_ACTIVATE, |
| }; |
| |
| /* Store data about transaction commits, exported via sysfs. */ |
| struct btrfs_commit_stats { |
| /* Total number of commits */ |
| u64 commit_count; |
| /* The maximum commit duration so far in ns */ |
| u64 max_commit_dur; |
| /* The last commit duration in ns */ |
| u64 last_commit_dur; |
| /* The total commit duration in ns */ |
| u64 total_commit_dur; |
| }; |
| |
| struct btrfs_fs_info { |
| u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; |
| unsigned long flags; |
| struct btrfs_root *tree_root; |
| struct btrfs_root *chunk_root; |
| struct btrfs_root *dev_root; |
| struct btrfs_root *fs_root; |
| struct btrfs_root *quota_root; |
| struct btrfs_root *uuid_root; |
| struct btrfs_root *data_reloc_root; |
| struct btrfs_root *block_group_root; |
| |
| /* the log root tree is a directory of all the other log roots */ |
| struct btrfs_root *log_root_tree; |
| |
| /* The tree that holds the global roots (csum, extent, etc) */ |
| rwlock_t global_root_lock; |
| struct rb_root global_root_tree; |
| |
| spinlock_t fs_roots_radix_lock; |
| struct radix_tree_root fs_roots_radix; |
| |
| /* block group cache stuff */ |
| rwlock_t block_group_cache_lock; |
| struct rb_root_cached block_group_cache_tree; |
| |
| /* keep track of unallocated space */ |
| atomic64_t free_chunk_space; |
| |
| /* Track ranges which are used by log trees blocks/logged data extents */ |
| struct extent_io_tree excluded_extents; |
| |
| /* logical->physical extent mapping */ |
| struct extent_map_tree mapping_tree; |
| |
| /* |
| * block reservation for extent, checksum, root tree and |
| * delayed dir index item |
| */ |
| struct btrfs_block_rsv global_block_rsv; |
| /* block reservation for metadata operations */ |
| struct btrfs_block_rsv trans_block_rsv; |
| /* block reservation for chunk tree */ |
| struct btrfs_block_rsv chunk_block_rsv; |
| /* block reservation for delayed operations */ |
| struct btrfs_block_rsv delayed_block_rsv; |
| /* block reservation for delayed refs */ |
| struct btrfs_block_rsv delayed_refs_rsv; |
| |
| struct btrfs_block_rsv empty_block_rsv; |
| |
| u64 generation; |
| u64 last_trans_committed; |
| /* |
| * Generation of the last transaction used for block group relocation |
| * since the filesystem was last mounted (or 0 if none happened yet). |
| * Must be written and read while holding btrfs_fs_info::commit_root_sem. |
| */ |
| u64 last_reloc_trans; |
| u64 avg_delayed_ref_runtime; |
| |
| /* |
| * this is updated to the current trans every time a full commit |
| * is required instead of the faster short fsync log commits |
| */ |
| u64 last_trans_log_full_commit; |
| unsigned long mount_opt; |
| |
| unsigned long compress_type:4; |
| unsigned int compress_level; |
| u32 commit_interval; |
| /* |
| * It is a suggestive number, the read side is safe even it gets a |
| * wrong number because we will write out the data into a regular |
| * extent. The write side(mount/remount) is under ->s_umount lock, |
| * so it is also safe. |
| */ |
| u64 max_inline; |
| |
| struct btrfs_transaction *running_transaction; |
| wait_queue_head_t transaction_throttle; |
| wait_queue_head_t transaction_wait; |
| wait_queue_head_t transaction_blocked_wait; |
| wait_queue_head_t async_submit_wait; |
| |
| /* |
| * Used to protect the incompat_flags, compat_flags, compat_ro_flags |
| * when they are updated. |
| * |
| * Because we do not clear the flags for ever, so we needn't use |
| * the lock on the read side. |
| * |
| * We also needn't use the lock when we mount the fs, because |
| * there is no other task which will update the flag. |
| */ |
| spinlock_t super_lock; |
| struct btrfs_super_block *super_copy; |
| struct btrfs_super_block *super_for_commit; |
| struct super_block *sb; |
| struct inode *btree_inode; |
| struct mutex tree_log_mutex; |
| struct mutex transaction_kthread_mutex; |
| struct mutex cleaner_mutex; |
| struct mutex chunk_mutex; |
| |
| /* |
| * this is taken to make sure we don't set block groups ro after |
| * the free space cache has been allocated on them |
| */ |
| struct mutex ro_block_group_mutex; |
| |
| /* this is used during read/modify/write to make sure |
| * no two ios are trying to mod the same stripe at the same |
| * time |
| */ |
| struct btrfs_stripe_hash_table *stripe_hash_table; |
| |
| /* |
| * this protects the ordered operations list only while we are |
| * processing all of the entries on it. This way we make |
| * sure the commit code doesn't find the list temporarily empty |
| * because another function happens to be doing non-waiting preflush |
| * before jumping into the main commit. |
| */ |
| struct mutex ordered_operations_mutex; |
| |
| struct rw_semaphore commit_root_sem; |
| |
| struct rw_semaphore cleanup_work_sem; |
| |
| struct rw_semaphore subvol_sem; |
| |
| spinlock_t trans_lock; |
| /* |
| * the reloc mutex goes with the trans lock, it is taken |
| * during commit to protect us from the relocation code |
| */ |
| struct mutex reloc_mutex; |
| |
| struct list_head trans_list; |
| struct list_head dead_roots; |
| struct list_head caching_block_groups; |
| |
| spinlock_t delayed_iput_lock; |
| struct list_head delayed_iputs; |
| atomic_t nr_delayed_iputs; |
| wait_queue_head_t delayed_iputs_wait; |
| |
| atomic64_t tree_mod_seq; |
| |
| /* this protects tree_mod_log and tree_mod_seq_list */ |
| rwlock_t tree_mod_log_lock; |
| struct rb_root tree_mod_log; |
| struct list_head tree_mod_seq_list; |
| |
| atomic_t async_delalloc_pages; |
| |
| /* |
| * this is used to protect the following list -- ordered_roots. |
| */ |
| spinlock_t ordered_root_lock; |
| |
| /* |
| * all fs/file tree roots in which there are data=ordered extents |
| * pending writeback are added into this list. |
| * |
| * these can span multiple transactions and basically include |
| * every dirty data page that isn't from nodatacow |
| */ |
| struct list_head ordered_roots; |
| |
| struct mutex delalloc_root_mutex; |
| spinlock_t delalloc_root_lock; |
| /* all fs/file tree roots that have delalloc inodes. */ |
| struct list_head delalloc_roots; |
| |
| /* |
| * there is a pool of worker threads for checksumming during writes |
| * and a pool for checksumming after reads. This is because readers |
| * can run with FS locks held, and the writers may be waiting for |
| * those locks. We don't want ordering in the pending list to cause |
| * deadlocks, and so the two are serviced separately. |
| * |
| * A third pool does submit_bio to avoid deadlocking with the other |
| * two |
| */ |
| struct btrfs_workqueue *workers; |
| struct btrfs_workqueue *hipri_workers; |
| struct btrfs_workqueue *delalloc_workers; |
| struct btrfs_workqueue *flush_workers; |
| struct workqueue_struct *endio_workers; |
| struct workqueue_struct *endio_meta_workers; |
| struct workqueue_struct *endio_raid56_workers; |
| struct workqueue_struct *rmw_workers; |
| struct workqueue_struct *compressed_write_workers; |
| struct btrfs_workqueue *endio_write_workers; |
| struct btrfs_workqueue *endio_freespace_worker; |
| struct btrfs_workqueue *caching_workers; |
| |
| /* |
| * fixup workers take dirty pages that didn't properly go through |
| * the cow mechanism and make them safe to write. It happens |
| * for the sys_munmap function call path |
| */ |
| struct btrfs_workqueue *fixup_workers; |
| struct btrfs_workqueue *delayed_workers; |
| |
| struct task_struct *transaction_kthread; |
| struct task_struct *cleaner_kthread; |
| u32 thread_pool_size; |
| |
| struct kobject *space_info_kobj; |
| struct kobject *qgroups_kobj; |
| struct kobject *discard_kobj; |
| |
| /* used to keep from writing metadata until there is a nice batch */ |
| struct percpu_counter dirty_metadata_bytes; |
| struct percpu_counter delalloc_bytes; |
| struct percpu_counter ordered_bytes; |
| s32 dirty_metadata_batch; |
| s32 delalloc_batch; |
| |
| struct list_head dirty_cowonly_roots; |
| |
| struct btrfs_fs_devices *fs_devices; |
| |
| /* |
| * The space_info list is effectively read only after initial |
| * setup. It is populated at mount time and cleaned up after |
| * all block groups are removed. RCU is used to protect it. |
| */ |
| struct list_head space_info; |
| |
| struct btrfs_space_info *data_sinfo; |
| |
| struct reloc_control *reloc_ctl; |
| |
| /* data_alloc_cluster is only used in ssd_spread mode */ |
| struct btrfs_free_cluster data_alloc_cluster; |
| |
| /* all metadata allocations go through this cluster */ |
| struct btrfs_free_cluster meta_alloc_cluster; |
| |
| /* auto defrag inodes go here */ |
| spinlock_t defrag_inodes_lock; |
| struct rb_root defrag_inodes; |
| atomic_t defrag_running; |
| |
| /* Used to protect avail_{data, metadata, system}_alloc_bits */ |
| seqlock_t profiles_lock; |
| /* |
| * these three are in extended format (availability of single |
| * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other |
| * types are denoted by corresponding BTRFS_BLOCK_GROUP_* bits) |
| */ |
| u64 avail_data_alloc_bits; |
| u64 avail_metadata_alloc_bits; |
| u64 avail_system_alloc_bits; |
| |
| /* restriper state */ |
| spinlock_t balance_lock; |
| struct mutex balance_mutex; |
| atomic_t balance_pause_req; |
| atomic_t balance_cancel_req; |
| struct btrfs_balance_control *balance_ctl; |
| wait_queue_head_t balance_wait_q; |
| |
| /* Cancellation requests for chunk relocation */ |
| atomic_t reloc_cancel_req; |
| |
| u32 data_chunk_allocations; |
| u32 metadata_ratio; |
| |
| void *bdev_holder; |
| |
| /* private scrub information */ |
| struct mutex scrub_lock; |
| atomic_t scrubs_running; |
| atomic_t scrub_pause_req; |
| atomic_t scrubs_paused; |
| atomic_t scrub_cancel_req; |
| wait_queue_head_t scrub_pause_wait; |
| /* |
| * The worker pointers are NULL iff the refcount is 0, ie. scrub is not |
| * running. |
| */ |
| refcount_t scrub_workers_refcnt; |
| struct workqueue_struct *scrub_workers; |
| struct workqueue_struct *scrub_wr_completion_workers; |
| struct workqueue_struct *scrub_parity_workers; |
| struct btrfs_subpage_info *subpage_info; |
| |
| struct btrfs_discard_ctl discard_ctl; |
| |
| #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
| u32 check_integrity_print_mask; |
| #endif |
| /* is qgroup tracking in a consistent state? */ |
| u64 qgroup_flags; |
| |
| /* holds configuration and tracking. Protected by qgroup_lock */ |
| struct rb_root qgroup_tree; |
| spinlock_t qgroup_lock; |
| |
| /* |
| * used to avoid frequently calling ulist_alloc()/ulist_free() |
| * when doing qgroup accounting, it must be protected by qgroup_lock. |
| */ |
| struct ulist *qgroup_ulist; |
| |
| /* |
| * Protect user change for quota operations. If a transaction is needed, |
| * it must be started before locking this lock. |
| */ |
| struct mutex qgroup_ioctl_lock; |
| |
| /* list of dirty qgroups to be written at next commit */ |
| struct list_head dirty_qgroups; |
| |
| /* used by qgroup for an efficient tree traversal */ |
| u64 qgroup_seq; |
| |
| /* qgroup rescan items */ |
| struct mutex qgroup_rescan_lock; /* protects the progress item */ |
| struct btrfs_key qgroup_rescan_progress; |
| struct btrfs_workqueue *qgroup_rescan_workers; |
| struct completion qgroup_rescan_completion; |
| struct btrfs_work qgroup_rescan_work; |
| bool qgroup_rescan_running; /* protected by qgroup_rescan_lock */ |
| u8 qgroup_drop_subtree_thres; |
| |
| /* filesystem state */ |
| unsigned long fs_state; |
| |
| struct btrfs_delayed_root *delayed_root; |
| |
| /* Extent buffer radix tree */ |
| spinlock_t buffer_lock; |
| /* Entries are eb->start / sectorsize */ |
| struct radix_tree_root buffer_radix; |
| |
| /* next backup root to be overwritten */ |
| int backup_root_index; |
| |
| /* device replace state */ |
| struct btrfs_dev_replace dev_replace; |
| |
| struct semaphore uuid_tree_rescan_sem; |
| |
| /* Used to reclaim the metadata space in the background. */ |
| struct work_struct async_reclaim_work; |
| struct work_struct async_data_reclaim_work; |
| struct work_struct preempt_reclaim_work; |
| |
| /* Reclaim partially filled block groups in the background */ |
| struct work_struct reclaim_bgs_work; |
| struct list_head reclaim_bgs; |
| int bg_reclaim_threshold; |
| |
| spinlock_t unused_bgs_lock; |
| struct list_head unused_bgs; |
| struct mutex unused_bg_unpin_mutex; |
| /* Protect block groups that are going to be deleted */ |
| struct mutex reclaim_bgs_lock; |
| |
| /* Cached block sizes */ |
| u32 nodesize; |
| u32 sectorsize; |
| /* ilog2 of sectorsize, use to avoid 64bit division */ |
| u32 sectorsize_bits; |
| u32 csum_size; |
| u32 csums_per_leaf; |
| u32 stripesize; |
| |
| /* |
| * Maximum size of an extent. BTRFS_MAX_EXTENT_SIZE on regular |
| * filesystem, on zoned it depends on the device constraints. |
| */ |
| u64 max_extent_size; |
| |
| /* Block groups and devices containing active swapfiles. */ |
| spinlock_t swapfile_pins_lock; |
| struct rb_root swapfile_pins; |
| |
| struct crypto_shash *csum_shash; |
| |
| /* Type of exclusive operation running, protected by super_lock */ |
| enum btrfs_exclusive_operation exclusive_operation; |
| |
| /* |
| * Zone size > 0 when in ZONED mode, otherwise it's used for a check |
| * if the mode is enabled |
| */ |
| u64 zone_size; |
| |
| /* Max size to emit ZONE_APPEND write command */ |
| u64 max_zone_append_size; |
| struct mutex zoned_meta_io_lock; |
| spinlock_t treelog_bg_lock; |
| u64 treelog_bg; |
| |
| /* |
| * Start of the dedicated data relocation block group, protected by |
| * relocation_bg_lock. |
| */ |
| spinlock_t relocation_bg_lock; |
| u64 data_reloc_bg; |
| struct mutex zoned_data_reloc_io_lock; |
| |
| u64 nr_global_roots; |
| |
| spinlock_t zone_active_bgs_lock; |
| struct list_head zone_active_bgs; |
| |
| /* Updates are not protected by any lock */ |
| struct btrfs_commit_stats commit_stats; |
| |
| /* |
| * Last generation where we dropped a non-relocation root. |
| * Use btrfs_set_last_root_drop_gen() and btrfs_get_last_root_drop_gen() |
| * to change it and to read it, respectively. |
| */ |
| u64 last_root_drop_gen; |
| |
| /* |
| * Annotations for transaction events (structures are empty when |
| * compiled without lockdep). |
| */ |
| struct lockdep_map btrfs_trans_num_writers_map; |
| struct lockdep_map btrfs_trans_num_extwriters_map; |
| struct lockdep_map btrfs_state_change_map[4]; |
| struct lockdep_map btrfs_trans_pending_ordered_map; |
| struct lockdep_map btrfs_ordered_extent_map; |
| |
| #ifdef CONFIG_BTRFS_FS_REF_VERIFY |
| spinlock_t ref_verify_lock; |
| struct rb_root block_tree; |
| #endif |
| |
| #ifdef CONFIG_BTRFS_DEBUG |
| struct kobject *debug_kobj; |
| struct list_head allocated_roots; |
| |
| spinlock_t eb_leak_lock; |
| struct list_head allocated_ebs; |
| #endif |
| }; |
| |
| static inline void btrfs_set_last_root_drop_gen(struct btrfs_fs_info *fs_info, |
| u64 gen) |
| { |
| WRITE_ONCE(fs_info->last_root_drop_gen, gen); |
| } |
| |
| static inline u64 btrfs_get_last_root_drop_gen(const struct btrfs_fs_info *fs_info) |
| { |
| return READ_ONCE(fs_info->last_root_drop_gen); |
| } |
| |
| static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) |
| { |
| return sb->s_fs_info; |
| } |
| |
| /* |
| * Take the number of bytes to be checksummed and figure out how many leaves |
| * it would require to store the csums for that many bytes. |
| */ |
| static inline u64 btrfs_csum_bytes_to_leaves( |
| const struct btrfs_fs_info *fs_info, u64 csum_bytes) |
| { |
| const u64 num_csums = csum_bytes >> fs_info->sectorsize_bits; |
| |
| return DIV_ROUND_UP_ULL(num_csums, fs_info->csums_per_leaf); |
| } |
| |
| /* |
| * Use this if we would be adding new items, as we could split nodes as we cow |
| * down the tree. |
| */ |
| static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info, |
| unsigned num_items) |
| { |
| return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items; |
| } |
| |
| /* |
| * Doing a truncate or a modification won't result in new nodes or leaves, just |
| * what we need for COW. |
| */ |
| static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info, |
| unsigned num_items) |
| { |
| return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items; |
| } |
| |
| #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \ |
| sizeof(struct btrfs_item)) |
| |
| static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info) |
| { |
| return fs_info->zone_size > 0; |
| } |
| |
| /* |
| * Count how many fs_info->max_extent_size cover the @size |
| */ |
| static inline u32 count_max_extents(struct btrfs_fs_info *fs_info, u64 size) |
| { |
| #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
| if (!fs_info) |
| return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); |
| #endif |
| |
| return div_u64(size + fs_info->max_extent_size - 1, fs_info->max_extent_size); |
| } |
| |
| bool btrfs_exclop_start(struct btrfs_fs_info *fs_info, |
| enum btrfs_exclusive_operation type); |
| bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info, |
| enum btrfs_exclusive_operation type); |
| void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info); |
| void btrfs_exclop_finish(struct btrfs_fs_info *fs_info); |
| void btrfs_exclop_balance(struct btrfs_fs_info *fs_info, |
| enum btrfs_exclusive_operation op); |
| |
| /* |
| * The state of btrfs root |
| */ |
| enum { |
| /* |
| * btrfs_record_root_in_trans is a multi-step process, and it can race |
| * with the balancing code. But the race is very small, and only the |
| * first time the root is added to each transaction. So IN_TRANS_SETUP |
| * is used to tell us when more checks are required |
| */ |
| BTRFS_ROOT_IN_TRANS_SETUP, |
| |
| /* |
| * Set if tree blocks of this root can be shared by other roots. |
| * Only subvolume trees and their reloc trees have this bit set. |
| * Conflicts with TRACK_DIRTY bit. |
| * |
| * This affects two things: |
| * |
| * - How balance works |
| * For shareable roots, we need to use reloc tree and do path |
| * replacement for balance, and need various pre/post hooks for |
| * snapshot creation to handle them. |
| * |
| * While for non-shareable trees, we just simply do a tree search |
| * with COW. |
| * |
| * - How dirty roots are tracked |
| * For shareable roots, btrfs_record_root_in_trans() is needed to |
| * track them, while non-subvolume roots have TRACK_DIRTY bit, they |
| * don't need to set this manually. |
| */ |
| BTRFS_ROOT_SHAREABLE, |
| BTRFS_ROOT_TRACK_DIRTY, |
| BTRFS_ROOT_IN_RADIX, |
| BTRFS_ROOT_ORPHAN_ITEM_INSERTED, |
| BTRFS_ROOT_DEFRAG_RUNNING, |
| BTRFS_ROOT_FORCE_COW, |
| BTRFS_ROOT_MULTI_LOG_TASKS, |
| BTRFS_ROOT_DIRTY, |
| BTRFS_ROOT_DELETING, |
| |
| /* |
| * Reloc tree is orphan, only kept here for qgroup delayed subtree scan |
| * |
| * Set for the subvolume tree owning the reloc tree. |
| */ |
| BTRFS_ROOT_DEAD_RELOC_TREE, |
| /* Mark dead root stored on device whose cleanup needs to be resumed */ |
| BTRFS_ROOT_DEAD_TREE, |
| /* The root has a log tree. Used for subvolume roots and the tree root. */ |
| BTRFS_ROOT_HAS_LOG_TREE, |
| /* Qgroup flushing is in progress */ |
| BTRFS_ROOT_QGROUP_FLUSHING, |
| /* We started the orphan cleanup for this root. */ |
| BTRFS_ROOT_ORPHAN_CLEANUP, |
| /* This root has a drop operation that was started previously. */ |
| BTRFS_ROOT_UNFINISHED_DROP, |
| /* This reloc root needs to have its buffers lockdep class reset. */ |
| BTRFS_ROOT_RESET_LOCKDEP_CLASS, |
| }; |
| |
| enum btrfs_lockdep_trans_states { |
| BTRFS_LOCKDEP_TRANS_COMMIT_START, |
| BTRFS_LOCKDEP_TRANS_UNBLOCKED, |
| BTRFS_LOCKDEP_TRANS_SUPER_COMMITTED, |
| BTRFS_LOCKDEP_TRANS_COMPLETED, |
| }; |
| |
| /* |
| * Lockdep annotation for wait events. |
| * |
| * @owner: The struct where the lockdep map is defined |
| * @lock: The lockdep map corresponding to a wait event |
| * |
| * This macro is used to annotate a wait event. In this case a thread acquires |
| * the lockdep map as writer (exclusive lock) because it has to block until all |
| * the threads that hold the lock as readers signal the condition for the wait |
| * event and release their locks. |
| */ |
| #define btrfs_might_wait_for_event(owner, lock) \ |
| do { \ |
| rwsem_acquire(&owner->lock##_map, 0, 0, _THIS_IP_); \ |
| rwsem_release(&owner->lock##_map, _THIS_IP_); \ |
| } while (0) |
| |
| /* |
| * Protection for the resource/condition of a wait event. |
| * |
| * @owner: The struct where the lockdep map is defined |
| * @lock: The lockdep map corresponding to a wait event |
| * |
| * Many threads can modify the condition for the wait event at the same time |
| * and signal the threads that block on the wait event. The threads that modify |
| * the condition and do the signaling acquire the lock as readers (shared |
| * lock). |
| */ |
| #define btrfs_lockdep_acquire(owner, lock) \ |
| rwsem_acquire_read(&owner->lock##_map, 0, 0, _THIS_IP_) |
| |
| /* |
| * Used after signaling the condition for a wait event to release the lockdep |
| * map held by a reader thread. |
| */ |
| #define btrfs_lockdep_release(owner, lock) \ |
| rwsem_release(&owner->lock##_map, _THIS_IP_) |
| |
| /* |
| * Macros for the transaction states wait events, similar to the generic wait |
| * event macros. |
| */ |
| #define btrfs_might_wait_for_state(owner, i) \ |
| do { \ |
| rwsem_acquire(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_); \ |
| rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_); \ |
| } while (0) |
| |
| #define btrfs_trans_state_lockdep_acquire(owner, i) \ |
| rwsem_acquire_read(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_) |
| |
| #define btrfs_trans_state_lockdep_release(owner, i) \ |
| rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_) |
| |
| /* Initialization of the lockdep map */ |
| #define btrfs_lockdep_init_map(owner, lock) \ |
| do { \ |
| static struct lock_class_key lock##_key; \ |
| lockdep_init_map(&owner->lock##_map, #lock, &lock##_key, 0); \ |
| } while (0) |
| |
| /* Initialization of the transaction states lockdep maps. */ |
| #define btrfs_state_lockdep_init_map(owner, lock, state) \ |
| do { \ |
| static struct lock_class_key lock##_key; \ |
| lockdep_init_map(&owner->btrfs_state_change_map[state], #lock, \ |
| &lock##_key, 0); \ |
| } while (0) |
| |
| /* |
| * Record swapped tree blocks of a subvolume tree for delayed subtree trace |
| * code. For detail check comment in fs/btrfs/qgroup.c. |
| */ |
| struct btrfs_qgroup_swapped_blocks { |
| spinlock_t lock; |
| /* RM_EMPTY_ROOT() of above blocks[] */ |
| bool swapped; |
| struct rb_root blocks[BTRFS_MAX_LEVEL]; |
| }; |
| |
| /* |
| * in ram representation of the tree. extent_root is used for all allocations |
| * and for the extent tree extent_root root. |
| */ |
| struct btrfs_root { |
| struct rb_node rb_node; |
| |
| struct extent_buffer *node; |
| |
| struct extent_buffer *commit_root; |
| struct btrfs_root *log_root; |
| struct btrfs_root *reloc_root; |
| |
| unsigned long state; |
| struct btrfs_root_item root_item; |
| struct btrfs_key root_key; |
| struct btrfs_fs_info *fs_info; |
| struct extent_io_tree dirty_log_pages; |
| |
| struct mutex objectid_mutex; |
| |
| spinlock_t accounting_lock; |
| struct btrfs_block_rsv *block_rsv; |
| |
| struct mutex log_mutex; |
| wait_queue_head_t log_writer_wait; |
| wait_queue_head_t log_commit_wait[2]; |
| struct list_head log_ctxs[2]; |
| /* Used only for log trees of subvolumes, not for the log root tree */ |
| atomic_t log_writers; |
| atomic_t log_commit[2]; |
| /* Used only for log trees of subvolumes, not for the log root tree */ |
| atomic_t log_batch; |
| int log_transid; |
| /* No matter the commit succeeds or not*/ |
| int log_transid_committed; |
| /* Just be updated when the commit succeeds. */ |
| int last_log_commit; |
| pid_t log_start_pid; |
| |
| u64 last_trans; |
| |
| u32 type; |
| |
| u64 free_objectid; |
| |
| struct btrfs_key defrag_progress; |
| struct btrfs_key defrag_max; |
| |
| /* The dirty list is only used by non-shareable roots */ |
| struct list_head dirty_list; |
| |
| struct list_head root_list; |
| |
| spinlock_t log_extents_lock[2]; |
| struct list_head logged_list[2]; |
| |
| spinlock_t inode_lock; |
| /* red-black tree that keeps track of in-memory inodes */ |
| struct rb_root inode_tree; |
| |
| /* |
| * radix tree that keeps track of delayed nodes of every inode, |
| * protected by inode_lock |
| */ |
| struct radix_tree_root delayed_nodes_tree; |
| /* |
| * right now this just gets used so that a root has its own devid |
| * for stat. It may be used for more later |
| */ |
| dev_t anon_dev; |
| |
| spinlock_t root_item_lock; |
| refcount_t refs; |
| |
| struct mutex delalloc_mutex; |
| spinlock_t delalloc_lock; |
| /* |
| * all of the inodes that have delalloc bytes. It is possible for |
| * this list to be empty even when there is still dirty data=ordered |
| * extents waiting to finish IO. |
| */ |
| struct list_head delalloc_inodes; |
| struct list_head delalloc_root; |
| u64 nr_delalloc_inodes; |
| |
| struct mutex ordered_extent_mutex; |
| /* |
| * this is used by the balancing code to wait for all the pending |
| * ordered extents |
| */ |
| spinlock_t ordered_extent_lock; |
| |
| /* |
| * all of the data=ordered extents pending writeback |
| * these can span multiple transactions and basically include |
| * every dirty data page that isn't from nodatacow |
| */ |
| struct list_head ordered_extents; |
| struct list_head ordered_root; |
| u64 nr_ordered_extents; |
| |
| /* |
| * Not empty if this subvolume root has gone through tree block swap |
| * (relocation) |
| * |
| * Will be used by reloc_control::dirty_subvol_roots. |
| */ |
| struct list_head reloc_dirty_list; |
| |
| /* |
| * Number of currently running SEND ioctls to prevent |
| * manipulation with the read-only status via SUBVOL_SETFLAGS |
| */ |
| int send_in_progress; |
| /* |
| * Number of currently running deduplication operations that have a |
| * destination inode belonging to this root. Protected by the lock |
| * root_item_lock. |
| */ |
| int dedupe_in_progress; |
| /* For exclusion of snapshot creation and nocow writes */ |
| struct btrfs_drew_lock snapshot_lock; |
| |
| atomic_t snapshot_force_cow; |
| |
| /* For qgroup metadata reserved space */ |
| spinlock_t qgroup_meta_rsv_lock; |
| u64 qgroup_meta_rsv_pertrans; |
| u64 qgroup_meta_rsv_prealloc; |
| wait_queue_head_t qgroup_flush_wait; |
| |
| /* Number of active swapfiles */ |
| atomic_t nr_swapfiles; |
| |
| /* Record pairs of swapped blocks for qgroup */ |
| struct btrfs_qgroup_swapped_blocks swapped_blocks; |
| |
| /* Used only by log trees, when logging csum items */ |
| struct extent_io_tree log_csum_range; |
| |
| #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
| u64 alloc_bytenr; |
| #endif |
| |
| #ifdef CONFIG_BTRFS_DEBUG |
| struct list_head leak_list; |
| #endif |
| }; |
| |
| /* |
| * Structure that conveys information about an extent that is going to replace |
| * all the extents in a file range. |
| */ |
| struct btrfs_replace_extent_info { |
| u64 disk_offset; |
| u64 disk_len; |
| u64 data_offset; |
| u64 data_len; |
| u64 file_offset; |
| /* Pointer to a file extent item of type regular or prealloc. */ |
| char *extent_buf; |
| /* |
| * Set to true when attempting to replace a file range with a new extent |
| * described by this structure, set to false when attempting to clone an |
| * existing extent into a file range. |
| */ |
| bool is_new_extent; |
| /* Indicate if we should update the inode's mtime and ctime. */ |
| bool update_times; |
| /* Meaningful only if is_new_extent is true. */ |
| int qgroup_reserved; |
| /* |
| * Meaningful only if is_new_extent is true. |
| * Used to track how many extent items we have already inserted in a |
| * subvolume tree that refer to the extent described by this structure, |
| * so that we know when to create a new delayed ref or update an existing |
| * one. |
| */ |
| int insertions; |
| }; |
| |
| /* Arguments for btrfs_drop_extents() */ |
| struct btrfs_drop_extents_args { |
| /* Input parameters */ |
| |
| /* |
| * If NULL, btrfs_drop_extents() will allocate and free its own path. |
| * If 'replace_extent' is true, this must not be NULL. Also the path |
| * is always released except if 'replace_extent' is true and |
| * btrfs_drop_extents() sets 'extent_inserted' to true, in which case |
| * the path is kept locked. |
| */ |
| struct btrfs_path *path; |
| /* Start offset of the range to drop extents from */ |
| u64 start; |
| /* End (exclusive, last byte + 1) of the range to drop extents from */ |
| u64 end; |
| /* If true drop all the extent maps in the range */ |
| bool drop_cache; |
| /* |
| * If true it means we want to insert a new extent after dropping all |
| * the extents in the range. If this is true, the 'extent_item_size' |
| * parameter must be set as well and the 'extent_inserted' field will |
| * be set to true by btrfs_drop_extents() if it could insert the new |
| * extent. |
| * Note: when this is set to true the path must not be NULL. |
| */ |
| bool replace_extent; |
| /* |
| * Used if 'replace_extent' is true. Size of the file extent item to |
| * insert after dropping all existing extents in the range |
| */ |
| u32 extent_item_size; |
| |
| /* Output parameters */ |
| |
| /* |
| * Set to the minimum between the input parameter 'end' and the end |
| * (exclusive, last byte + 1) of the last dropped extent. This is always |
| * set even if btrfs_drop_extents() returns an error. |
| */ |
| u64 drop_end; |
| /* |
| * The number of allocated bytes found in the range. This can be smaller |
| * than the range's length when there are holes in the range. |
| */ |
| u64 bytes_found; |
| /* |
| * Only set if 'replace_extent' is true. Set to true if we were able |
| * to insert a replacement extent after dropping all extents in the |
| * range, otherwise set to false by btrfs_drop_extents(). |
| * Also, if btrfs_drop_extents() has set this to true it means it |
| * returned with the path locked, otherwise if it has set this to |
| * false it has returned with the path released. |
| */ |
| bool extent_inserted; |
| }; |
| |
| struct btrfs_file_private { |
| void *filldir_buf; |
| }; |
| |
| |
| static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info) |
| { |
| |
| return info->nodesize - sizeof(struct btrfs_header); |
| } |
| |
| static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info) |
| { |
| return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item); |
| } |
| |
| static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info) |
| { |
| return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr); |
| } |
| |
| #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ |
| (offsetof(struct btrfs_file_extent_item, disk_bytenr)) |
| static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info) |
| { |
| return BTRFS_MAX_ITEM_SIZE(info) - |
| BTRFS_FILE_EXTENT_INLINE_DATA_START; |
| } |
| |
| static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) |
| { |
| return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); |
| } |
| |
| #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ |
| ((bytes) >> (fs_info)->sectorsize_bits) |
| |
| static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length) |
| { |
| return crc32c(crc, address, length); |
| } |
| |
| static inline void btrfs_crc32c_final(u32 crc, u8 *result) |
| { |
| put_unaligned_le32(~crc, result); |
| } |
| |
| static inline u64 btrfs_name_hash(const char *name, int len) |
| { |
| return crc32c((u32)~1, name, len); |
| } |
| |
| /* |
| * Figure the key offset of an extended inode ref |
| */ |
| static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name, |
| int len) |
| { |
| return (u64) crc32c(parent_objectid, name, len); |
| } |
| |
| static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) |
| { |
| return mapping_gfp_constraint(mapping, ~__GFP_FS); |
| } |
| |
| /* extent-tree.c */ |
| |
| enum btrfs_inline_ref_type { |
| BTRFS_REF_TYPE_INVALID, |
| BTRFS_REF_TYPE_BLOCK, |
| BTRFS_REF_TYPE_DATA, |
| BTRFS_REF_TYPE_ANY, |
| }; |
| |
| int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb, |
| struct btrfs_extent_inline_ref *iref, |
| enum btrfs_inline_ref_type is_data); |
| u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset); |
| |
| |
| int btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info, |
| u64 start, u64 num_bytes); |
| void btrfs_free_excluded_extents(struct btrfs_block_group *cache); |
| int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, |
| unsigned long count); |
| void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, |
| struct btrfs_delayed_ref_root *delayed_refs, |
| struct btrfs_delayed_ref_head *head); |
| int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len); |
| int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, |
| struct btrfs_fs_info *fs_info, u64 bytenr, |
| u64 offset, int metadata, u64 *refs, u64 *flags); |
| int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num, |
| int reserved); |
| int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans, |
| u64 bytenr, u64 num_bytes); |
| int btrfs_exclude_logged_extents(struct extent_buffer *eb); |
| int btrfs_cross_ref_exist(struct btrfs_root *root, |
| u64 objectid, u64 offset, u64 bytenr, bool strict, |
| struct btrfs_path *path); |
| struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| u64 parent, u64 root_objectid, |
| const struct btrfs_disk_key *key, |
| int level, u64 hint, |
| u64 empty_size, |
| enum btrfs_lock_nesting nest); |
| void btrfs_free_tree_block(struct btrfs_trans_handle *trans, |
| u64 root_id, |
| struct extent_buffer *buf, |
| u64 parent, int last_ref); |
| int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, u64 owner, |
| u64 offset, u64 ram_bytes, |
| struct btrfs_key *ins); |
| int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, |
| u64 root_objectid, u64 owner, u64 offset, |
| struct btrfs_key *ins); |
| int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes, |
| u64 min_alloc_size, u64 empty_size, u64 hint_byte, |
| struct btrfs_key *ins, int is_data, int delalloc); |
| int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| struct extent_buffer *buf, int full_backref); |
| int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| struct extent_buffer *buf, int full_backref); |
| int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, |
| struct extent_buffer *eb, u64 flags, int level); |
| int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); |
| |
| int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, |
| u64 start, u64 len, int delalloc); |
| int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start, |
| u64 len); |
| int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); |
| int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
| struct btrfs_ref *generic_ref); |
| |
| void btrfs_clear_space_info_full(struct btrfs_fs_info *info); |
| |
| int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, |
| struct btrfs_block_rsv *rsv, |
| int nitems, bool use_global_rsv); |
| void btrfs_subvolume_release_metadata(struct btrfs_root *root, |
| struct btrfs_block_rsv *rsv); |
| void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes); |
| |
| int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes, |
| u64 disk_num_bytes, bool noflush); |
| u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); |
| int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, |
| u64 start, u64 end); |
| int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, |
| u64 num_bytes, u64 *actual_bytes); |
| int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); |
| |
| int btrfs_init_space_info(struct btrfs_fs_info *fs_info); |
| int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans, |
| struct btrfs_fs_info *fs_info); |
| int btrfs_start_write_no_snapshotting(struct btrfs_root *root); |
| void btrfs_end_write_no_snapshotting(struct btrfs_root *root); |
| void btrfs_wait_for_snapshot_creation(struct btrfs_root *root); |
| |
| /* ctree.c */ |
| int __init btrfs_ctree_init(void); |
| void __cold btrfs_ctree_exit(void); |
| int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, |
| int *slot); |
| int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); |
| int btrfs_previous_item(struct btrfs_root *root, |
| struct btrfs_path *path, u64 min_objectid, |
| int type); |
| int btrfs_previous_extent_item(struct btrfs_root *root, |
| struct btrfs_path *path, u64 min_objectid); |
| void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, |
| struct btrfs_path *path, |
| const struct btrfs_key *new_key); |
| struct extent_buffer *btrfs_root_node(struct btrfs_root *root); |
| int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, |
| struct btrfs_key *key, int lowest_level, |
| u64 min_trans); |
| int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, |
| struct btrfs_path *path, |
| u64 min_trans); |
| struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent, |
| int slot); |
| |
| int btrfs_cow_block(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, struct extent_buffer *buf, |
| struct extent_buffer *parent, int parent_slot, |
| struct extent_buffer **cow_ret, |
| enum btrfs_lock_nesting nest); |
| int btrfs_copy_root(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct extent_buffer *buf, |
| struct extent_buffer **cow_ret, u64 new_root_objectid); |
| int btrfs_block_can_be_shared(struct btrfs_root *root, |
| struct extent_buffer *buf); |
| void btrfs_extend_item(struct btrfs_path *path, u32 data_size); |
| void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end); |
| int btrfs_split_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, |
| const struct btrfs_key *new_key, |
| unsigned long split_offset); |
| int btrfs_duplicate_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, |
| const struct btrfs_key *new_key); |
| int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, |
| u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); |
| int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| const struct btrfs_key *key, struct btrfs_path *p, |
| int ins_len, int cow); |
| int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key, |
| struct btrfs_path *p, u64 time_seq); |
| int btrfs_search_slot_for_read(struct btrfs_root *root, |
| const struct btrfs_key *key, |
| struct btrfs_path *p, int find_higher, |
| int return_any); |
| int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, struct extent_buffer *parent, |
| int start_slot, u64 *last_ret, |
| struct btrfs_key *progress); |
| void btrfs_release_path(struct btrfs_path *p); |
| struct btrfs_path *btrfs_alloc_path(void); |
| void btrfs_free_path(struct btrfs_path *p); |
| |
| int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| struct btrfs_path *path, int slot, int nr); |
| static inline int btrfs_del_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path) |
| { |
| return btrfs_del_items(trans, root, path, path->slots[0], 1); |
| } |
| |
| /* |
| * Describes a batch of items to insert in a btree. This is used by |
| * btrfs_insert_empty_items(). |
| */ |
| struct btrfs_item_batch { |
| /* |
| * Pointer to an array containing the keys of the items to insert (in |
| * sorted order). |
| */ |
| const struct btrfs_key *keys; |
| /* Pointer to an array containing the data size for each item to insert. */ |
| const u32 *data_sizes; |
| /* |
| * The sum of data sizes for all items. The caller can compute this while |
| * setting up the data_sizes array, so it ends up being more efficient |
| * than having btrfs_insert_empty_items() or setup_item_for_insert() |
| * doing it, as it would avoid an extra loop over a potentially large |
| * array, and in the case of setup_item_for_insert(), we would be doing |
| * it while holding a write lock on a leaf and often on upper level nodes |
| * too, unnecessarily increasing the size of a critical section. |
| */ |
| u32 total_data_size; |
| /* Size of the keys and data_sizes arrays (number of items in the batch). */ |
| int nr; |
| }; |
| |
| void btrfs_setup_item_for_insert(struct btrfs_root *root, |
| struct btrfs_path *path, |
| const struct btrfs_key *key, |
| u32 data_size); |
| int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| const struct btrfs_key *key, void *data, u32 data_size); |
| int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, |
| const struct btrfs_item_batch *batch); |
| |
| static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, |
| const struct btrfs_key *key, |
| u32 data_size) |
| { |
| struct btrfs_item_batch batch; |
| |
| batch.keys = key; |
| batch.data_sizes = &data_size; |
| batch.total_data_size = data_size; |
| batch.nr = 1; |
| |
| return btrfs_insert_empty_items(trans, root, path, &batch); |
| } |
| |
| int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); |
| int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path, |
| u64 time_seq); |
| |
| int btrfs_search_backwards(struct btrfs_root *root, struct btrfs_key *key, |
| struct btrfs_path *path); |
| |
| int btrfs_get_next_valid_item(struct btrfs_root *root, struct btrfs_key *key, |
| struct btrfs_path *path); |
| |
| /* |
| * Search in @root for a given @key, and store the slot found in @found_key. |
| * |
| * @root: The root node of the tree. |
| * @key: The key we are looking for. |
| * @found_key: Will hold the found item. |
| * @path: Holds the current slot/leaf. |
| * @iter_ret: Contains the value returned from btrfs_search_slot or |
| * btrfs_get_next_valid_item, whichever was executed last. |
| * |
| * The @iter_ret is an output variable that will contain the return value of |
| * btrfs_search_slot, if it encountered an error, or the value returned from |
| * btrfs_get_next_valid_item otherwise. That return value can be 0, if a valid |
| * slot was found, 1 if there were no more leaves, and <0 if there was an error. |
| * |
| * It's recommended to use a separate variable for iter_ret and then use it to |
| * set the function return value so there's no confusion of the 0/1/errno |
| * values stemming from btrfs_search_slot. |
| */ |
| #define btrfs_for_each_slot(root, key, found_key, path, iter_ret) \ |
| for (iter_ret = btrfs_search_slot(NULL, (root), (key), (path), 0, 0); \ |
| (iter_ret) >= 0 && \ |
| (iter_ret = btrfs_get_next_valid_item((root), (found_key), (path))) == 0; \ |
| (path)->slots[0]++ \ |
| ) |
| |
| int btrfs_next_old_item(struct btrfs_root *root, struct btrfs_path *path, u64 time_seq); |
| |
| /* |
| * Search the tree again to find a leaf with greater keys. |
| * |
| * Returns 0 if it found something or 1 if there are no greater leaves. |
| * Returns < 0 on error. |
| */ |
| static inline int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path) |
| { |
| return btrfs_next_old_leaf(root, path, 0); |
| } |
| |
| static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) |
| { |
| return btrfs_next_old_item(root, p, 0); |
| } |
| int btrfs_leaf_free_space(struct extent_buffer *leaf); |
| int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, |
| int for_reloc); |
| int btrfs_drop_subtree(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct extent_buffer *node, |
| struct extent_buffer *parent); |
| |
| /* root-item.c */ |
| int btrfs_add_root_ref(struct btrfs_trans_handle *trans, u64 root_id, |
| u64 ref_id, u64 dirid, u64 sequence, |
| const struct qstr *name); |
| int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id, |
| u64 ref_id, u64 dirid, u64 *sequence, |
| const struct qstr *name); |
| int btrfs_del_root(struct btrfs_trans_handle *trans, |
| const struct btrfs_key *key); |
| int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| const struct btrfs_key *key, |
| struct btrfs_root_item *item); |
| int __must_check btrfs_update_root(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_key *key, |
| struct btrfs_root_item *item); |
| int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key, |
| struct btrfs_path *path, struct btrfs_root_item *root_item, |
| struct btrfs_key *root_key); |
| int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info); |
| void btrfs_set_root_node(struct btrfs_root_item *item, |
| struct extent_buffer *node); |
| void btrfs_check_and_init_root_item(struct btrfs_root_item *item); |
| void btrfs_update_root_times(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root); |
| |
| /* uuid-tree.c */ |
| int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, |
| u64 subid); |
| int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, |
| u64 subid); |
| int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info); |
| |
| /* dir-item.c */ |
| int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir, |
| const struct qstr *name); |
| int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, |
| const struct qstr *name, struct btrfs_inode *dir, |
| struct btrfs_key *location, u8 type, u64 index); |
| struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, u64 dir, |
| const struct qstr *name, int mod); |
| struct btrfs_dir_item * |
| btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, u64 dir, |
| u64 index, const struct qstr *name, int mod); |
| struct btrfs_dir_item * |
| btrfs_search_dir_index_item(struct btrfs_root *root, |
| struct btrfs_path *path, u64 dirid, |
| const struct qstr *name); |
| int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, |
| struct btrfs_dir_item *di); |
| int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, u64 objectid, |
| const char *name, u16 name_len, |
| const void *data, u16 data_len); |
| struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, u64 dir, |
| const char *name, u16 name_len, |
| int mod); |
| struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info, |
| struct btrfs_path *path, |
| const char *name, |
| int name_len); |
| |
| /* orphan.c */ |
| int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, u64 offset); |
| int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, u64 offset); |
| int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset); |
| |
| /* file-item.c */ |
| int btrfs_del_csums(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, u64 bytenr, u64 len); |
| blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst); |
| int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, u64 objectid, u64 pos, |
| u64 num_bytes); |
| int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_path *path, u64 objectid, |
| u64 bytenr, int mod); |
| int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, |
| struct btrfs_ordered_sum *sums); |
| blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio, |
| u64 offset, bool one_ordered); |
| int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, |
| struct list_head *list, int search_commit, |
| bool nowait); |
| void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, |
| const struct btrfs_path *path, |
| struct btrfs_file_extent_item *fi, |
| const bool new_inline, |
| struct extent_map *em); |
| int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, |
| u64 len); |
| int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, |
| u64 len); |
| void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_size); |
| u64 btrfs_file_extent_end(const struct btrfs_path *path); |
| |
| /* inode.c */ |
| void btrfs_submit_data_write_bio(struct inode *inode, struct bio *bio, int mirror_num); |
| void btrfs_submit_data_read_bio(struct inode *inode, struct bio *bio, |
| int mirror_num, enum btrfs_compression_type compress_type); |
| int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page, |
| u32 pgoff, u8 *csum, const u8 * const csum_expected); |
| int btrfs_check_data_csum(struct inode *inode, struct btrfs_bio *bbio, |
| u32 bio_offset, struct page *page, u32 pgoff); |
| unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio, |
| u32 bio_offset, struct page *page, |
| u64 start, u64 end); |
| int btrfs_check_data_csum(struct inode *inode, struct btrfs_bio *bbio, |
| u32 bio_offset, struct page *page, u32 pgoff); |
| noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, |
| u64 *orig_start, u64 *orig_block_len, |
| u64 *ram_bytes, bool nowait, bool strict); |
| |
| void __btrfs_del_delalloc_inode(struct btrfs_root *root, |
| struct btrfs_inode *inode); |
| struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); |
| int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index); |
| int btrfs_unlink_inode(struct btrfs_trans_handle *trans, |
| struct btrfs_inode *dir, struct btrfs_inode *inode, |
| const struct qstr *name); |
| int btrfs_add_link(struct btrfs_trans_handle *trans, |
| struct btrfs_inode *parent_inode, struct btrfs_inode *inode, |
| const struct qstr *name, int add_backref, u64 index); |
| int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry); |
| int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, |
| int front); |
| |
| int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context); |
| int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr, |
| bool in_reclaim_context); |
| int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end, |
| unsigned int extra_bits, |
| struct extent_state **cached_state); |
| struct btrfs_new_inode_args { |
| /* Input */ |
| struct inode *dir; |
| struct dentry *dentry; |
| struct inode *inode; |
| bool orphan; |
| bool subvol; |
| |
| /* |
| * Output from btrfs_new_inode_prepare(), input to |
| * btrfs_create_new_inode(). |
| */ |
| struct posix_acl *default_acl; |
| struct posix_acl *acl; |
| struct fscrypt_name fname; |
| struct qstr name; |
| }; |
| int btrfs_new_inode_prepare(struct btrfs_new_inode_args *args, |
| unsigned int *trans_num_items); |
| int btrfs_create_new_inode(struct btrfs_trans_handle *trans, |
| struct btrfs_new_inode_args *args); |
| void btrfs_new_inode_args_destroy(struct btrfs_new_inode_args *args); |
| struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns, |
| struct inode *dir); |
| void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state, |
| u32 bits); |
| void btrfs_clear_delalloc_extent(struct inode *inode, |
| struct extent_state *state, u32 bits); |
| void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new, |
| struct extent_state *other); |
| void btrfs_split_delalloc_extent(struct inode *inode, |
| struct extent_state *orig, u64 split); |
| void btrfs_set_range_writeback(struct btrfs_inode *inode, u64 start, u64 end); |
| vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf); |
| void btrfs_evict_inode(struct inode *inode); |
| struct inode *btrfs_alloc_inode(struct super_block *sb); |
| void btrfs_destroy_inode(struct inode *inode); |
| void btrfs_free_inode(struct inode *inode); |
| int btrfs_drop_inode(struct inode *inode); |
| int __init btrfs_init_cachep(void); |
| void __cold btrfs_destroy_cachep(void); |
| struct inode *btrfs_iget_path(struct super_block *s, u64 ino, |
| struct btrfs_root *root, struct btrfs_path *path); |
| struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root); |
| struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, |
| struct page *page, size_t pg_offset, |
| u64 start, u64 end); |
| int btrfs_update_inode(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, struct btrfs_inode *inode); |
| int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, struct btrfs_inode *inode); |
| int btrfs_orphan_add(struct btrfs_trans_handle *trans, |
| struct btrfs_inode *inode); |
| int btrfs_orphan_cleanup(struct btrfs_root *root); |
| int btrfs_cont_expand(struct btrfs_inode *inode, loff_t oldsize, loff_t size); |
| void btrfs_add_delayed_iput(struct inode *inode); |
| void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info); |
| int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info); |
| int btrfs_prealloc_file_range(struct inode *inode, int mode, |
| u64 start, u64 num_bytes, u64 min_size, |
| loff_t actual_len, u64 *alloc_hint); |
| int btrfs_prealloc_file_range_trans(struct inode *inode, |
| struct btrfs_trans_handle *trans, int mode, |
| u64 start, u64 num_bytes, u64 min_size, |
| loff_t actual_len, u64 *alloc_hint); |
| int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page, |
| u64 start, u64 end, int *page_started, unsigned long *nr_written, |
| struct writeback_control *wbc); |
| int btrfs_writepage_cow_fixup(struct page *page); |
| void btrfs_writepage_endio_finish_ordered(struct btrfs_inode *inode, |
| struct page *page, u64 start, |
| u64 end, bool uptodate); |
| int btrfs_encoded_io_compression_from_extent(struct btrfs_fs_info *fs_info, |
| int compress_type); |
| int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, |
| u64 file_offset, u64 disk_bytenr, |
| u64 disk_io_size, |
| struct page **pages); |
| ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, |
| struct btrfs_ioctl_encoded_io_args *encoded); |
| ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, |
| const struct btrfs_ioctl_encoded_io_args *encoded); |
| |
| ssize_t btrfs_dio_read(struct kiocb *iocb, struct iov_iter *iter, |
| size_t done_before); |
| struct iomap_dio *btrfs_dio_write(struct kiocb *iocb, struct iov_iter *iter, |
| size_t done_before); |
| |
| extern const struct dentry_operations btrfs_dentry_operations; |
| |
| /* Inode locking type flags, by default the exclusive lock is taken */ |
| enum btrfs_ilock_type { |
| ENUM_BIT(BTRFS_ILOCK_SHARED), |
| ENUM_BIT(BTRFS_ILOCK_TRY), |
| ENUM_BIT(BTRFS_ILOCK_MMAP), |
| }; |
| |
| int btrfs_inode_lock(struct inode *inode, unsigned int ilock_flags); |
| void btrfs_inode_unlock(struct inode *inode, unsigned int ilock_flags); |
| void btrfs_update_inode_bytes(struct btrfs_inode *inode, |
| const u64 add_bytes, |
| const u64 del_bytes); |
| void btrfs_assert_inode_range_clean(struct btrfs_inode *inode, u64 start, u64 end); |
| |
| /* ioctl.c */ |
| long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
| long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
| int btrfs_fileattr_get(struct dentry *dentry, struct fileattr *fa); |
| int btrfs_fileattr_set(struct user_namespace *mnt_userns, |
| struct dentry *dentry, struct fileattr *fa); |
| int btrfs_ioctl_get_supported_features(void __user *arg); |
| void btrfs_sync_inode_flags_to_i_flags(struct inode *inode); |
| int __pure btrfs_is_empty_uuid(u8 *uuid); |
| int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra, |
| struct btrfs_ioctl_defrag_range_args *range, |
| u64 newer_than, unsigned long max_to_defrag); |
| void btrfs_get_block_group_info(struct list_head *groups_list, |
| struct btrfs_ioctl_space_info *space); |
| void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info, |
| struct btrfs_ioctl_balance_args *bargs); |
| |
| /* file.c */ |
| int __init btrfs_auto_defrag_init(void); |
| void __cold btrfs_auto_defrag_exit(void); |
| int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, |
| struct btrfs_inode *inode, u32 extent_thresh); |
| int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info); |
| void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info); |
| int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); |
| extern const struct file_operations btrfs_file_operations; |
| int btrfs_drop_extents(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, struct btrfs_inode *inode, |
| struct btrfs_drop_extents_args *args); |
| int btrfs_replace_file_extents(struct btrfs_inode *inode, |
| struct btrfs_path *path, const u64 start, |
| const u64 end, |
| struct btrfs_replace_extent_info *extent_info, |
| struct btrfs_trans_handle **trans_out); |
| int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, |
| struct btrfs_inode *inode, u64 start, u64 end); |
| ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from, |
| const struct btrfs_ioctl_encoded_io_args *encoded); |
| int btrfs_release_file(struct inode *inode, struct file *file); |
| int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages, |
| size_t num_pages, loff_t pos, size_t write_bytes, |
| struct extent_state **cached, bool noreserve); |
| int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); |
| int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos, |
| size_t *write_bytes, bool nowait); |
| void btrfs_check_nocow_unlock(struct btrfs_inode *inode); |
| bool btrfs_find_delalloc_in_range(struct btrfs_inode *inode, u64 start, u64 end, |
| u64 *delalloc_start_ret, u64 *delalloc_end_ret); |
| |
| /* tree-defrag.c */ |
| int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root); |
| |
| /* super.c */ |
| int btrfs_parse_options(struct btrfs_fs_info *info, char *options, |
| unsigned long new_flags); |
| int btrfs_sync_fs(struct super_block *sb, int wait); |
| char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, |
| u64 subvol_objectid); |
| |
| #if BITS_PER_LONG == 32 |
| #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT) |
| /* |
| * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical |
| * addresses of extents. |
| * |
| * For 4K page size it's about 10T, for 64K it's 160T. |
| */ |
| #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8) |
| void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info); |
| void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info); |
| #endif |
| |
| /* |
| * Get the correct offset inside the page of extent buffer. |
| * |
| * @eb: target extent buffer |
| * @start: offset inside the extent buffer |
| * |
| * Will handle both sectorsize == PAGE_SIZE and sectorsize < PAGE_SIZE cases. |
| */ |
| static inline size_t get_eb_offset_in_page(const struct extent_buffer *eb, |
| unsigned long offset) |
| { |
| /* |
| * For sectorsize == PAGE_SIZE case, eb->start will always be aligned |
| * to PAGE_SIZE, thus adding it won't cause any difference. |
| * |
| * For sectorsize < PAGE_SIZE, we must only read the data that belongs |
| * to the eb, thus we have to take the eb->start into consideration. |
| */ |
| return offset_in_page(offset + eb->start); |
| } |
| |
| static inline unsigned long get_eb_page_index(unsigned long offset) |
| { |
| /* |
| * For sectorsize == PAGE_SIZE case, plain >> PAGE_SHIFT is enough. |
| * |
| * For sectorsize < PAGE_SIZE case, we only support 64K PAGE_SIZE, |
| * and have ensured that all tree blocks are contained in one page, |
| * thus we always get index == 0. |
| */ |
| return offset >> PAGE_SHIFT; |
| } |
| |
| /* |
| * Use that for functions that are conditionally exported for sanity tests but |
| * otherwise static |
| */ |
| #ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
| #define EXPORT_FOR_TESTS static |
| #else |
| #define EXPORT_FOR_TESTS |
| #endif |
| |
| /* acl.c */ |
| #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
| struct posix_acl *btrfs_get_acl(struct inode *inode, int type, bool rcu); |
| int btrfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode, |
| struct posix_acl *acl, int type); |
| int __btrfs_set_acl(struct btrfs_trans_handle *trans, struct inode *inode, |
| struct posix_acl *acl, int type); |
| #else |
| #define btrfs_get_acl NULL |
| #define btrfs_set_acl NULL |
| static inline int __btrfs_set_acl(struct btrfs_trans_handle *trans, |
| struct inode *inode, struct posix_acl *acl, |
| int type) |
| { |
| return -EOPNOTSUPP; |
| } |
| #endif |
| |
| /* relocation.c */ |
| int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start); |
| int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root); |
| int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root); |
| int btrfs_recover_relocation(struct btrfs_fs_info *fs_info); |
| int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len); |
| int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, |
| struct btrfs_root *root, struct extent_buffer *buf, |
| struct extent_buffer *cow); |
| void btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending, |
| u64 *bytes_to_reserve); |
| int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, |
| struct btrfs_pending_snapshot *pending); |
| int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info); |
| struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info, |
| u64 bytenr); |
| int btrfs_should_ignore_reloc_root(struct btrfs_root *root); |
| |
| /* scrub.c */ |
| int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, |
| u64 end, struct btrfs_scrub_progress *progress, |
| int readonly, int is_dev_replace); |
| void btrfs_scrub_pause(struct btrfs_fs_info *fs_info); |
| void btrfs_scrub_continue(struct btrfs_fs_info *fs_info); |
| int btrfs_scrub_cancel(struct btrfs_fs_info *info); |
| int btrfs_scrub_cancel_dev(struct btrfs_device *dev); |
| int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid, |
| struct btrfs_scrub_progress *progress); |
| |
| /* dev-replace.c */ |
| void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info); |
| void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount); |
| |
| static inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info) |
| { |
| btrfs_bio_counter_sub(fs_info, 1); |
| } |
| |
| static inline int is_fstree(u64 rootid) |
| { |
| if (rootid == BTRFS_FS_TREE_OBJECTID || |
| ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID && |
| !btrfs_qgroup_level(rootid))) |
| return 1; |
| return 0; |
| } |
| |
| static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) |
| { |
| return signal_pending(current); |
| } |
| |
| /* verity.c */ |
| #ifdef CONFIG_FS_VERITY |
| |
| extern const struct fsverity_operations btrfs_verityops; |
| int btrfs_drop_verity_items(struct btrfs_inode *inode); |
| int btrfs_get_verity_descriptor(struct inode *inode, void *buf, size_t buf_size); |
| |
| #else |
| |
| static inline int btrfs_drop_verity_items(struct btrfs_inode *inode) |
| { |
| return 0; |
| } |
| |
| static inline int btrfs_get_verity_descriptor(struct inode *inode, void *buf, |
| size_t buf_size) |
| { |
| return -EPERM; |
| } |
| |
| #endif |
| |
| /* Sanity test specific functions */ |
| #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
| void btrfs_test_destroy_inode(struct inode *inode); |
| #endif |
| |
| static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root) |
| { |
| return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID; |
| } |
| |
| /* |
| * We use page status Private2 to indicate there is an ordered extent with |
| * unfinished IO. |
| * |
| * Rename the Private2 accessors to Ordered, to improve readability. |
| */ |
| #define PageOrdered(page) PagePrivate2(page) |
| #define SetPageOrdered(page) SetPagePrivate2(page) |
| #define ClearPageOrdered(page) ClearPagePrivate2(page) |
| #define folio_test_ordered(folio) folio_test_private_2(folio) |
| #define folio_set_ordered(folio) folio_set_private_2(folio) |
| #define folio_clear_ordered(folio) folio_clear_private_2(folio) |
| |
| #endif |