xref: /kernel/linux/linux-5.10/fs/btrfs/disk-io.h (revision 8c2ecf20)
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_DISK_IO_H
78c2ecf20Sopenharmony_ci#define BTRFS_DISK_IO_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define BTRFS_SUPER_INFO_OFFSET SZ_64K
108c2ecf20Sopenharmony_ci#define BTRFS_SUPER_INFO_SIZE 4096
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define BTRFS_SUPER_MIRROR_MAX	 3
138c2ecf20Sopenharmony_ci#define BTRFS_SUPER_MIRROR_SHIFT 12
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ci * Fixed blocksize for all devices, applies to specific ways of reading
178c2ecf20Sopenharmony_ci * metadata like superblock. Must meet the set_blocksize requirements.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * Do not change.
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci#define BTRFS_BDEV_BLOCKSIZE	(4096)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cienum btrfs_wq_endio_type {
248c2ecf20Sopenharmony_ci	BTRFS_WQ_ENDIO_DATA,
258c2ecf20Sopenharmony_ci	BTRFS_WQ_ENDIO_METADATA,
268c2ecf20Sopenharmony_ci	BTRFS_WQ_ENDIO_FREE_SPACE,
278c2ecf20Sopenharmony_ci	BTRFS_WQ_ENDIO_RAID56,
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic inline u64 btrfs_sb_offset(int mirror)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	u64 start = SZ_16K;
338c2ecf20Sopenharmony_ci	if (mirror)
348c2ecf20Sopenharmony_ci		return start << (BTRFS_SUPER_MIRROR_SHIFT * mirror);
358c2ecf20Sopenharmony_ci	return BTRFS_SUPER_INFO_OFFSET;
368c2ecf20Sopenharmony_ci}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct btrfs_device;
398c2ecf20Sopenharmony_cistruct btrfs_fs_devices;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_civoid btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
428c2ecf20Sopenharmony_civoid btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
438c2ecf20Sopenharmony_ciint btrfs_verify_level_key(struct extent_buffer *eb, int level,
448c2ecf20Sopenharmony_ci			   struct btrfs_key *first_key, u64 parent_transid);
458c2ecf20Sopenharmony_cistruct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
468c2ecf20Sopenharmony_ci				      u64 parent_transid, int level,
478c2ecf20Sopenharmony_ci				      struct btrfs_key *first_key);
488c2ecf20Sopenharmony_civoid readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr);
498c2ecf20Sopenharmony_cistruct extent_buffer *btrfs_find_create_tree_block(
508c2ecf20Sopenharmony_ci						struct btrfs_fs_info *fs_info,
518c2ecf20Sopenharmony_ci						u64 bytenr);
528c2ecf20Sopenharmony_civoid btrfs_clean_tree_block(struct extent_buffer *buf);
538c2ecf20Sopenharmony_ciint __cold open_ctree(struct super_block *sb,
548c2ecf20Sopenharmony_ci	       struct btrfs_fs_devices *fs_devices,
558c2ecf20Sopenharmony_ci	       char *options);
568c2ecf20Sopenharmony_civoid __cold close_ctree(struct btrfs_fs_info *fs_info);
578c2ecf20Sopenharmony_ciint write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
588c2ecf20Sopenharmony_cistruct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
598c2ecf20Sopenharmony_cistruct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
608c2ecf20Sopenharmony_ci						   int copy_num);
618c2ecf20Sopenharmony_ciint btrfs_commit_super(struct btrfs_fs_info *fs_info);
628c2ecf20Sopenharmony_cistruct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
638c2ecf20Sopenharmony_ci					struct btrfs_key *key);
648c2ecf20Sopenharmony_ciint btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
658c2ecf20Sopenharmony_ci			 struct btrfs_root *root);
668c2ecf20Sopenharmony_civoid btrfs_free_fs_roots(struct btrfs_fs_info *fs_info);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
698c2ecf20Sopenharmony_ci				     u64 objectid, bool check_ref);
708c2ecf20Sopenharmony_cistruct btrfs_root *btrfs_get_new_fs_root(struct btrfs_fs_info *fs_info,
718c2ecf20Sopenharmony_ci					 u64 objectid, dev_t anon_dev);
728c2ecf20Sopenharmony_cistruct btrfs_root *btrfs_get_fs_root_commit_root(struct btrfs_fs_info *fs_info,
738c2ecf20Sopenharmony_ci						 struct btrfs_path *path,
748c2ecf20Sopenharmony_ci						 u64 objectid);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_civoid btrfs_free_fs_info(struct btrfs_fs_info *fs_info);
778c2ecf20Sopenharmony_ciint btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info);
788c2ecf20Sopenharmony_civoid btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info);
798c2ecf20Sopenharmony_civoid btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info);
808c2ecf20Sopenharmony_civoid btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
818c2ecf20Sopenharmony_ci				 struct btrfs_root *root);
828c2ecf20Sopenharmony_ciint btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio, u64 phy_offset,
838c2ecf20Sopenharmony_ci				   struct page *page, u64 start, u64 end,
848c2ecf20Sopenharmony_ci				   int mirror);
858c2ecf20Sopenharmony_ciblk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio,
868c2ecf20Sopenharmony_ci				       int mirror_num, unsigned long bio_flags);
878c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
888c2ecf20Sopenharmony_cistruct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
898c2ecf20Sopenharmony_ci#endif
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/*
928c2ecf20Sopenharmony_ci * This function is used to grab the root, and avoid it is freed when we
938c2ecf20Sopenharmony_ci * access it. But it doesn't ensure that the tree is not dropped.
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci * If you want to ensure the whole tree is safe, you should use
968c2ecf20Sopenharmony_ci * 	fs_info->subvol_srcu
978c2ecf20Sopenharmony_ci */
988c2ecf20Sopenharmony_cistatic inline struct btrfs_root *btrfs_grab_root(struct btrfs_root *root)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	if (!root)
1018c2ecf20Sopenharmony_ci		return NULL;
1028c2ecf20Sopenharmony_ci	if (refcount_inc_not_zero(&root->refs))
1038c2ecf20Sopenharmony_ci		return root;
1048c2ecf20Sopenharmony_ci	return NULL;
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_civoid btrfs_put_root(struct btrfs_root *root);
1088c2ecf20Sopenharmony_civoid btrfs_mark_buffer_dirty(struct extent_buffer *buf);
1098c2ecf20Sopenharmony_ciint btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
1108c2ecf20Sopenharmony_ci			  int atomic);
1118c2ecf20Sopenharmony_ciint btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid, int level,
1128c2ecf20Sopenharmony_ci		      struct btrfs_key *first_key);
1138c2ecf20Sopenharmony_ciblk_status_t btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
1148c2ecf20Sopenharmony_ci			enum btrfs_wq_endio_type metadata);
1158c2ecf20Sopenharmony_ciblk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
1168c2ecf20Sopenharmony_ci			int mirror_num, unsigned long bio_flags,
1178c2ecf20Sopenharmony_ci			u64 bio_offset, void *private_data,
1188c2ecf20Sopenharmony_ci			extent_submit_bio_start_t *submit_bio_start);
1198c2ecf20Sopenharmony_ciblk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio,
1208c2ecf20Sopenharmony_ci			  int mirror_num);
1218c2ecf20Sopenharmony_ciint btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
1228c2ecf20Sopenharmony_ci			     struct btrfs_fs_info *fs_info);
1238c2ecf20Sopenharmony_ciint btrfs_add_log_tree(struct btrfs_trans_handle *trans,
1248c2ecf20Sopenharmony_ci		       struct btrfs_root *root);
1258c2ecf20Sopenharmony_civoid btrfs_cleanup_dirty_bgs(struct btrfs_transaction *trans,
1268c2ecf20Sopenharmony_ci			     struct btrfs_fs_info *fs_info);
1278c2ecf20Sopenharmony_civoid btrfs_cleanup_one_transaction(struct btrfs_transaction *trans,
1288c2ecf20Sopenharmony_ci				  struct btrfs_fs_info *fs_info);
1298c2ecf20Sopenharmony_cistruct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
1308c2ecf20Sopenharmony_ci				     u64 objectid);
1318c2ecf20Sopenharmony_ciint btree_lock_page_hook(struct page *page, void *data,
1328c2ecf20Sopenharmony_ci				void (*flush_fn)(void *));
1338c2ecf20Sopenharmony_ciint btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
1348c2ecf20Sopenharmony_ciint btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
1358c2ecf20Sopenharmony_ciint btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid);
1368c2ecf20Sopenharmony_ciint __init btrfs_end_io_wq_init(void);
1378c2ecf20Sopenharmony_civoid __cold btrfs_end_io_wq_exit(void);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_LOCK_ALLOC
1408c2ecf20Sopenharmony_civoid btrfs_init_lockdep(void);
1418c2ecf20Sopenharmony_civoid btrfs_set_buffer_lockdep_class(u64 objectid,
1428c2ecf20Sopenharmony_ci			            struct extent_buffer *eb, int level);
1438c2ecf20Sopenharmony_ci#else
1448c2ecf20Sopenharmony_cistatic inline void btrfs_init_lockdep(void)
1458c2ecf20Sopenharmony_ci{ }
1468c2ecf20Sopenharmony_cistatic inline void btrfs_set_buffer_lockdep_class(u64 objectid,
1478c2ecf20Sopenharmony_ci					struct extent_buffer *eb, int level)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci#endif
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#endif
153