blob: bf43245406c4d98b813e4015a6040bc1bbfa7307 [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,
46 u64 parent_transid, int level,
47 struct btrfs_key *first_key);
Jeff Mahoney2ff7e612016-06-22 18:54:24 -040048void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr);
Jeff Mahoney2ff7e612016-06-22 18:54:24 -040049struct extent_buffer *btrfs_find_create_tree_block(
50 struct btrfs_fs_info *fs_info,
51 u64 bytenr);
David Sterba6a884d7d2019-03-20 14:30:02 +010052void btrfs_clean_tree_block(struct extent_buffer *buf);
David Sterbab105e922019-10-01 19:57:35 +020053int __cold open_ctree(struct super_block *sb,
Al Viroad2b2c82011-11-17 01:10:02 -050054 struct btrfs_fs_devices *fs_devices,
55 char *options);
David Sterbab105e922019-10-01 19:57:35 +020056void __cold close_ctree(struct btrfs_fs_info *fs_info);
David Sterbaeece6a92017-02-10 19:04:32 +010057int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
Johannes Thumshirn8f323802020-02-14 00:24:32 +090058struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
59struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
60 int copy_num);
Jeff Mahoney6bccf3a2016-06-21 21:16:51 -040061int btrfs_commit_super(struct btrfs_fs_info *fs_info);
Josef Bacik62a2c732020-01-24 09:32:21 -050062struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
63 struct btrfs_key *key);
Miao Xiecb517ea2013-05-15 07:48:19 +000064int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
65 struct btrfs_root *root);
Josef Bacikfaa2dbf2014-05-07 17:06:09 -040066void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info);
Miao Xiec00869f2013-09-25 21:47:44 +080067
68struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
David Sterba56e93572020-05-15 19:35:55 +020069 u64 objectid, bool check_ref);
Miao Xiec00869f2013-09-25 21:47:44 +080070
Josef Bacik0d4b0462020-01-24 09:32:53 -050071void btrfs_free_fs_info(struct btrfs_fs_info *fs_info);
Yan Zhengc146afa2008-11-12 14:34:12 -050072int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info);
Jeff Mahoney2ff7e612016-06-22 18:54:24 -040073void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info);
74void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info);
Miao Xiecb517ea2013-05-15 07:48:19 +000075void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
76 struct btrfs_root *root);
Miao Xieb0feb9d2013-05-15 07:48:20 +000077
Josef Bacik06ea65a2013-09-19 16:07:01 -040078#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
Jeff Mahoneyda170662016-06-15 09:22:56 -040079struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
Josef Bacik06ea65a2013-09-19 16:07:01 -040080#endif
81
Miao Xieb0feb9d2013-05-15 07:48:20 +000082/*
83 * This function is used to grab the root, and avoid it is freed when we
84 * access it. But it doesn't ensure that the tree is not dropped.
85 *
86 * If you want to ensure the whole tree is safe, you should use
87 * fs_info->subvol_srcu
88 */
Josef Bacik00246522020-01-24 09:33:01 -050089static inline struct btrfs_root *btrfs_grab_root(struct btrfs_root *root)
Miao Xieb0feb9d2013-05-15 07:48:20 +000090{
Josef Bacik4cdfd932020-01-24 09:32:26 -050091 if (!root)
92 return NULL;
Elena Reshetova0700cea2017-03-03 10:55:18 +020093 if (refcount_inc_not_zero(&root->refs))
Miao Xieb0feb9d2013-05-15 07:48:20 +000094 return root;
95 return NULL;
96}
97
Josef Bacik8c389382020-02-14 16:11:42 -050098void btrfs_put_root(struct btrfs_root *root);
Chris Mason5f39d392007-10-15 16:14:19 -040099void btrfs_mark_buffer_dirty(struct extent_buffer *buf);
Chris Masonb9fab912012-05-06 07:23:47 -0400100int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
101 int atomic);
Qu Wenruo581c1762018-03-29 09:08:11 +0800102int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid, int level,
103 struct btrfs_key *first_key);
Christoph Hellwig4e4cbee2017-06-03 09:38:06 +0200104blk_status_t btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
David Sterbabfebd8b2014-07-30 00:25:45 +0200105 enum btrfs_wq_endio_type metadata);
Linus Torvalds8c27cb32017-07-05 16:41:23 -0700106blk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
Josef Bacikc6100a42017-05-05 11:57:13 -0400107 int mirror_num, unsigned long bio_flags,
108 u64 bio_offset, void *private_data,
David Sterbae288c082018-07-18 17:36:24 +0200109 extent_submit_bio_start_t *submit_bio_start);
110blk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio,
111 int mirror_num);
Chris Masone02119d2008-09-05 16:13:11 -0400112int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
113 struct btrfs_fs_info *fs_info);
Yan Zheng7237f182009-01-21 12:54:03 -0500114int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
115 struct btrfs_root *root);
Liu Boc79a1752016-07-20 17:44:12 -0700116void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *trans,
Jeff Mahoney2ff7e612016-06-22 18:54:24 -0400117 struct btrfs_fs_info *fs_info);
Jeff Mahoney49b25e02012-03-01 17:24:58 +0100118void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans,
Jeff Mahoney2ff7e612016-06-22 18:54:24 -0400119 struct btrfs_fs_info *fs_info);
Arne Jansen20897f52011-09-13 12:44:20 +0200120struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
Arne Jansen20897f52011-09-13 12:44:20 +0200121 u64 objectid);
122int btree_lock_page_hook(struct page *page, void *data,
123 void (*flush_fn)(void *));
David Sterba6af49db2017-06-23 04:09:57 +0200124struct extent_map *btree_get_extent(struct btrfs_inode *inode,
Omar Sandoval39b07b52019-12-02 17:34:23 -0800125 struct page *page, size_t pg_offset,
126 u64 start, u64 len);
Zhao Lei943c6e92015-08-19 15:54:15 +0800127int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
David Sterba97eb6b62014-07-30 00:55:42 +0200128int __init btrfs_end_io_wq_init(void);
David Sterbae67c7182018-02-19 17:24:18 +0100129void __cold btrfs_end_io_wq_exit(void);
Chris Mason4008c042009-02-12 14:09:45 -0500130
131#ifdef CONFIG_DEBUG_LOCK_ALLOC
Chris Mason85d4e462011-07-26 16:11:19 -0400132void btrfs_init_lockdep(void);
133void btrfs_set_buffer_lockdep_class(u64 objectid,
134 struct extent_buffer *eb, int level);
Chris Mason4008c042009-02-12 14:09:45 -0500135#else
Chris Mason85d4e462011-07-26 16:11:19 -0400136static inline void btrfs_init_lockdep(void)
137{ }
138static inline void btrfs_set_buffer_lockdep_class(u64 objectid,
139 struct extent_buffer *eb, int level)
Chris Mason4008c042009-02-12 14:09:45 -0500140{
141}
142#endif
David Sterba9888c342018-04-03 19:16:55 +0200143
Chris Masoneb60cea2007-02-02 09:18:22 -0500144#endif