blob: 1d3b749c405a891ec5da46708e5864d8e4855062 [file] [log] [blame]
David Sterba9888c342018-04-03 19:16:55 +02001/* SPDX-License-Identifier: GPL-2.0 */
Chris Mason6cbd5572007-06-12 09:07:21 -04002/*
3 * Copyright (C) 2007 Oracle. All rights reserved.
Chris Mason6cbd5572007-06-12 09:07:21 -04004 */
5
David Sterba9888c342018-04-03 19:16:55 +02006#ifndef BTRFS_DISK_IO_H
7#define BTRFS_DISK_IO_H
Chris Masoneb60cea2007-02-02 09:18:22 -05008
Byongho Leeee221842015-12-15 01:42:10 +09009#define BTRFS_SUPER_INFO_OFFSET SZ_64K
Chris Masonf2984462008-04-10 16:19:33 -040010#define BTRFS_SUPER_INFO_SIZE 4096
Yan Zhenga512bbf2008-12-08 16:46:26 -050011
12#define BTRFS_SUPER_MIRROR_MAX 3
13#define BTRFS_SUPER_MIRROR_SHIFT 12
14
David Sterba9f6d2512017-06-16 01:48:05 +020015/*
16 * Fixed blocksize for all devices, applies to specific ways of reading
17 * metadata like superblock. Must meet the set_blocksize requirements.
18 *
19 * Do not change.
20 */
21#define BTRFS_BDEV_BLOCKSIZE (4096)
22
David Sterbabfebd8b2014-07-30 00:25:45 +020023enum btrfs_wq_endio_type {
David Sterbabbe339c2018-11-27 15:25:13 +010024 BTRFS_WQ_ENDIO_DATA,
25 BTRFS_WQ_ENDIO_METADATA,
26 BTRFS_WQ_ENDIO_FREE_SPACE,
27 BTRFS_WQ_ENDIO_RAID56,
David Woodhouse53b381b2013-01-29 18:40:14 -050028};
29
Yan Zhenga512bbf2008-12-08 16:46:26 -050030static inline u64 btrfs_sb_offset(int mirror)
31{
Byongho Leeee221842015-12-15 01:42:10 +090032 u64 start = SZ_16K;
Yan Zhenga512bbf2008-12-08 16:46:26 -050033 if (mirror)
34 return start << (BTRFS_SUPER_MIRROR_SHIFT * mirror);
35 return BTRFS_SUPER_INFO_OFFSET;
36}
37
Chris Mason0b86a832008-03-24 15:01:56 -040038struct btrfs_device;
Chris Mason8a4b83c2008-03-24 15:02:07 -040039struct btrfs_fs_devices;
Chris Masoneb60cea2007-02-02 09:18:22 -050040
Josef Bacikbd647ce2020-01-24 09:33:00 -050041void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
Josef Bacik8260edba2020-01-24 09:32:59 -050042void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
David Sterbae064d5e2019-03-20 14:58:13 +010043int btrfs_verify_level_key(struct extent_buffer *eb, int level,
Qu Wenruo448de472019-03-12 17:10:40 +080044 struct btrfs_key *first_key, u64 parent_transid);
Qu Wenruo581c1762018-03-29 09:08:11 +080045struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
Josef Bacik1b7ec852020-11-05 10:45:18 -050046 u64 owner_root, u64 parent_transid,
47 int level, struct btrfs_key *first_key);
Jeff Mahoney2ff7e612016-06-22 18:54:24 -040048struct extent_buffer *btrfs_find_create_tree_block(
49 struct btrfs_fs_info *fs_info,
Josef Bacik3fbaf252020-11-05 10:45:20 -050050 u64 bytenr, u64 owner_root,
51 int level);
David Sterba6a884d7d2019-03-20 14:30:02 +010052void btrfs_clean_tree_block(struct extent_buffer *buf);
Boris Burkov8cd29082020-11-18 15:06:20 -080053void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info);
Boris Burkov44c0ca22020-11-18 15:06:16 -080054int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info);
David Sterbab105e922019-10-01 19:57:35 +020055int __cold open_ctree(struct super_block *sb,
Al Viroad2b2c82011-11-17 01:10:02 -050056 struct btrfs_fs_devices *fs_devices,
57 char *options);
David Sterbab105e922019-10-01 19:57:35 +020058void __cold close_ctree(struct btrfs_fs_info *fs_info);
David Sterbaeece6a92017-02-10 19:04:32 +010059int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
Johannes Thumshirn8f323802020-02-14 00:24:32 +090060struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
61struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
62 int copy_num);
Jeff Mahoney6bccf3a2016-06-21 21:16:51 -040063int btrfs_commit_super(struct btrfs_fs_info *fs_info);
Josef Bacik62a2c732020-01-24 09:32:21 -050064struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
65 struct btrfs_key *key);
Miao Xiecb517ea2013-05-15 07:48:19 +000066int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
67 struct btrfs_root *root);
Josef Bacikfaa2dbf2014-05-07 17:06:09 -040068void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info);
Miao Xiec00869f2013-09-25 21:47:44 +080069
70struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
David Sterba56e93572020-05-15 19:35:55 +020071 u64 objectid, bool check_ref);
Qu Wenruo2dfb1e42020-06-16 10:17:36 +080072struct btrfs_root *btrfs_get_new_fs_root(struct btrfs_fs_info *fs_info,
73 u64 objectid, dev_t anon_dev);
Josef Bacik49d11be2020-10-19 16:02:31 -040074struct btrfs_root *btrfs_get_fs_root_commit_root(struct btrfs_fs_info *fs_info,
75 struct btrfs_path *path,
76 u64 objectid);
Miao Xiec00869f2013-09-25 21:47:44 +080077
Josef Bacik0d4b0462020-01-24 09:32:53 -050078void btrfs_free_fs_info(struct btrfs_fs_info *fs_info);
Yan Zhengc146afa2008-11-12 14:34:12 -050079int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info);
Jeff Mahoney2ff7e612016-06-22 18:54:24 -040080void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info);
81void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info);
Miao Xiecb517ea2013-05-15 07:48:19 +000082void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
83 struct btrfs_root *root);
Qu Wenruoc3a3b192021-09-15 15:17:18 +080084int btrfs_validate_metadata_buffer(struct btrfs_bio *bbio,
Nikolay Borisov9a446d62020-09-18 16:34:33 +030085 struct page *page, u64 start, u64 end,
86 int mirror);
Nikolay Borisov1b362942020-09-18 16:34:38 +030087blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio,
88 int mirror_num, unsigned long bio_flags);
Josef Bacik06ea65a2013-09-19 16:07:01 -040089#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
Jeff Mahoneyda170662016-06-15 09:22:56 -040090struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
Josef Bacik06ea65a2013-09-19 16:07:01 -040091#endif
92
Miao Xieb0feb9d2013-05-15 07:48:20 +000093/*
94 * This function is used to grab the root, and avoid it is freed when we
95 * access it. But it doesn't ensure that the tree is not dropped.
96 *
97 * If you want to ensure the whole tree is safe, you should use
98 * fs_info->subvol_srcu
99 */
Josef Bacik00246522020-01-24 09:33:01 -0500100static inline struct btrfs_root *btrfs_grab_root(struct btrfs_root *root)
Miao Xieb0feb9d2013-05-15 07:48:20 +0000101{
Josef Bacik4cdfd932020-01-24 09:32:26 -0500102 if (!root)
103 return NULL;
Elena Reshetova0700cea2017-03-03 10:55:18 +0200104 if (refcount_inc_not_zero(&root->refs))
Miao Xieb0feb9d2013-05-15 07:48:20 +0000105 return root;
106 return NULL;
107}
108
Josef Bacik8c389382020-02-14 16:11:42 -0500109void btrfs_put_root(struct btrfs_root *root);
Chris Mason5f39d392007-10-15 16:14:19 -0400110void btrfs_mark_buffer_dirty(struct extent_buffer *buf);
Chris Masonb9fab912012-05-06 07:23:47 -0400111int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
112 int atomic);
Qu Wenruo581c1762018-03-29 09:08:11 +0800113int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid, int level,
114 struct btrfs_key *first_key);
Christoph Hellwig4e4cbee2017-06-03 09:38:06 +0200115blk_status_t btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
David Sterbabfebd8b2014-07-30 00:25:45 +0200116 enum btrfs_wq_endio_type metadata);
Qu Wenruo8896a082020-10-21 14:24:53 +0800117blk_status_t btrfs_wq_submit_bio(struct inode *inode, struct bio *bio,
118 int mirror_num, unsigned long bio_flags,
Qu Wenruo1941b642020-12-02 14:47:57 +0800119 u64 dio_file_offset,
Qu Wenruo8896a082020-10-21 14:24:53 +0800120 extent_submit_bio_start_t *submit_bio_start);
David Sterbae288c082018-07-18 17:36:24 +0200121blk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio,
122 int mirror_num);
Naohiro Aota6ab6ebb2021-02-04 19:22:17 +0900123int btrfs_alloc_log_tree_node(struct btrfs_trans_handle *trans,
124 struct btrfs_root *root);
Chris Masone02119d2008-09-05 16:13:11 -0400125int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
126 struct btrfs_fs_info *fs_info);
Yan Zheng7237f182009-01-21 12:54:03 -0500127int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
128 struct btrfs_root *root);
Liu Boc79a1752016-07-20 17:44:12 -0700129void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *trans,
Jeff Mahoney2ff7e612016-06-22 18:54:24 -0400130 struct btrfs_fs_info *fs_info);
Jeff Mahoney49b25e02012-03-01 17:24:58 +0100131void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans,
Jeff Mahoney2ff7e612016-06-22 18:54:24 -0400132 struct btrfs_fs_info *fs_info);
Arne Jansen20897f52011-09-13 12:44:20 +0200133struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
Arne Jansen20897f52011-09-13 12:44:20 +0200134 u64 objectid);
135int btree_lock_page_hook(struct page *page, void *data,
136 void (*flush_fn)(void *));
Zhao Lei943c6e92015-08-19 15:54:15 +0800137int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
Nikolay Borisov543068a2020-12-07 17:32:33 +0200138int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid);
Nikolay Borisov453e4872020-12-07 17:32:32 +0200139int btrfs_init_root_free_objectid(struct btrfs_root *root);
David Sterba97eb6b62014-07-30 00:55:42 +0200140int __init btrfs_end_io_wq_init(void);
David Sterbae67c7182018-02-19 17:24:18 +0100141void __cold btrfs_end_io_wq_exit(void);
Chris Mason4008c042009-02-12 14:09:45 -0500142
143#ifdef CONFIG_DEBUG_LOCK_ALLOC
Chris Mason85d4e462011-07-26 16:11:19 -0400144void btrfs_set_buffer_lockdep_class(u64 objectid,
145 struct extent_buffer *eb, int level);
Chris Mason4008c042009-02-12 14:09:45 -0500146#else
Chris Mason85d4e462011-07-26 16:11:19 -0400147static inline void btrfs_set_buffer_lockdep_class(u64 objectid,
148 struct extent_buffer *eb, int level)
Chris Mason4008c042009-02-12 14:09:45 -0500149{
150}
151#endif
David Sterba9888c342018-04-03 19:16:55 +0200152
Chris Masoneb60cea2007-02-02 09:18:22 -0500153#endif