btrfs: add forward declarations and headers, part 1
[linux-2.6-block.git] / fs / btrfs / ordered-data.h
CommitLineData
9888c340 1/* SPDX-License-Identifier: GPL-2.0 */
dc17ff8f
CM
2/*
3 * Copyright (C) 2007 Oracle. All rights reserved.
dc17ff8f
CM
4 */
5
9888c340
DS
6#ifndef BTRFS_ORDERED_DATA_H
7#define BTRFS_ORDERED_DATA_H
dc17ff8f 8
22b46bdc
DS
9#include "async-thread.h"
10
e6dcd2dc 11struct btrfs_ordered_sum {
3edf7d33 12 /*
5cfe76f8
CH
13 * Logical start address and length for of the blocks covered by
14 * the sums array.
3edf7d33 15 */
5cfe76f8 16 u64 logical;
6e4b2479 17 u32 len;
5cfe76f8 18
e6dcd2dc 19 struct list_head list;
f51a4a18 20 /* last field is a variable length array of csums */
1e25a2e3 21 u8 sums[];
e6dcd2dc
CM
22};
23
eb84ae03 24/*
3c198fe0 25 * Bits for btrfs_ordered_extent::flags.
eb84ae03
CM
26 *
27 * BTRFS_ORDERED_IO_DONE is set when all of the blocks are written.
28 * It is used to make sure metadata is inserted into the tree only once
29 * per extent.
30 *
31 * BTRFS_ORDERED_COMPLETE is set when the extent is removed from the
32 * rbtree, just before waking any waiters. It is used to indicate the
33 * IO is done and any metadata is inserted into the tree.
34 */
5b840301 35enum {
3c198fe0 36 /*
0b3dcd13
QW
37 * Different types for ordered extents, one and only one of the 4 types
38 * need to be set when creating ordered extent.
3c198fe0
QW
39 *
40 * REGULAR: For regular non-compressed COW write
41 * NOCOW: For NOCOW write into existing non-hole extent
42 * PREALLOC: For NOCOW write into preallocated extent
43 * COMPRESSED: For compressed COW write
44 */
45 BTRFS_ORDERED_REGULAR,
46 BTRFS_ORDERED_NOCOW,
47 BTRFS_ORDERED_PREALLOC,
48 BTRFS_ORDERED_COMPRESSED,
49
50 /*
51 * Extra bit for direct io, can only be set for
52 * REGULAR/NOCOW/PREALLOC. No direct io for compressed extent.
53 */
54 BTRFS_ORDERED_DIRECT,
55
56 /* Extra status bits for ordered extents */
57
5b840301
DS
58 /* set when all the pages are written */
59 BTRFS_ORDERED_IO_DONE,
60 /* set when removed from the tree */
61 BTRFS_ORDERED_COMPLETE,
5b840301
DS
62 /* We had an io error when writing this out */
63 BTRFS_ORDERED_IOERR,
5b840301
DS
64 /* Set when we have to truncate an extent */
65 BTRFS_ORDERED_TRUNCATED,
48778179
FM
66 /* Used during fsync to track already logged extents */
67 BTRFS_ORDERED_LOGGED,
68 /* We have already logged all the csums of the ordered extent */
69 BTRFS_ORDERED_LOGGED_CSUM,
70 /* We wait for this extent to complete in the current transaction */
71 BTRFS_ORDERED_PENDING,
7c0c7269
OS
72 /* BTRFS_IOC_ENCODED_WRITE */
73 BTRFS_ORDERED_ENCODED,
5b840301 74};
1af4a0aa 75
cb36a9bb
OS
76/* BTRFS_ORDERED_* flags that specify the type of the extent. */
77#define BTRFS_ORDERED_TYPE_FLAGS ((1UL << BTRFS_ORDERED_REGULAR) | \
78 (1UL << BTRFS_ORDERED_NOCOW) | \
79 (1UL << BTRFS_ORDERED_PREALLOC) | \
80 (1UL << BTRFS_ORDERED_COMPRESSED) | \
7c0c7269
OS
81 (1UL << BTRFS_ORDERED_DIRECT) | \
82 (1UL << BTRFS_ORDERED_ENCODED))
cb36a9bb 83
e6dcd2dc 84struct btrfs_ordered_extent {
eb84ae03 85 /* logical offset in the file */
e6dcd2dc 86 u64 file_offset;
eb84ae03 87
bffe633e
OS
88 /*
89 * These fields directly correspond to the same fields in
90 * btrfs_file_extent_item.
91 */
bffe633e 92 u64 num_bytes;
cb36a9bb
OS
93 u64 ram_bytes;
94 u64 disk_bytenr;
bffe633e 95 u64 disk_num_bytes;
cb36a9bb 96 u64 offset;
c8b97818 97
8b62b72b
CM
98 /* number of bytes that still need writing */
99 u64 bytes_left;
100
77cef2ec
JB
101 /*
102 * If we get truncated we need to adjust the file extent we enter for
103 * this ordered extent so that we do not expose stale data.
104 */
105 u64 truncated_len;
106
eb84ae03 107 /* flags (described above) */
e6dcd2dc 108 unsigned long flags;
eb84ae03 109
261507a0
LZ
110 /* compression algorithm */
111 int compress_type;
112
7dbeaad0
QW
113 /* Qgroup reserved space */
114 int qgroup_rsv;
115
eb84ae03 116 /* reference count */
e76edab7 117 refcount_t refs;
eb84ae03 118
3eaa2885
CM
119 /* the inode we belong to */
120 struct inode *inode;
121
eb84ae03 122 /* list of checksums for insertion when the extent io is done */
e6dcd2dc 123 struct list_head list;
eb84ae03 124
48778179
FM
125 /* used for fast fsyncs */
126 struct list_head log_list;
127
eb84ae03 128 /* used to wait for the BTRFS_ORDERED_COMPLETE bit */
e6dcd2dc 129 wait_queue_head_t wait;
eb84ae03
CM
130
131 /* our friendly rbtree entry */
e6dcd2dc 132 struct rb_node rb_node;
3eaa2885
CM
133
134 /* a per root list of all the pending ordered extents */
135 struct list_head root_extent_list;
5fd02043 136
d458b054 137 struct btrfs_work work;
e6dcd2dc 138
9afab882 139 struct completion completion;
d458b054 140 struct btrfs_work flush_work;
9afab882 141 struct list_head work_list;
02c372e1
JT
142
143 struct list_head bioc_list;
9afab882 144};
e6dcd2dc 145
71df088c 146int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent);
711f447b
CH
147int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
148
143bede5 149void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
71fe0a55 150void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode,
e6dcd2dc 151 struct btrfs_ordered_extent *entry);
122e9ede
CH
152bool btrfs_finish_ordered_extent(struct btrfs_ordered_extent *ordered,
153 struct page *page, u64 file_offset, u64 len,
154 bool uptodate);
e65f152e
QW
155void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode,
156 struct page *page, u64 file_offset,
711f447b 157 u64 num_bytes, bool uptodate);
58f74b22
QW
158bool btrfs_dec_test_ordered_pending(struct btrfs_inode *inode,
159 struct btrfs_ordered_extent **cached,
f41b6ba9 160 u64 file_offset, u64 io_size);
cf6d1aa4
BB
161struct btrfs_ordered_extent *btrfs_alloc_ordered_extent(
162 struct btrfs_inode *inode, u64 file_offset,
163 u64 num_bytes, u64 ram_bytes, u64 disk_bytenr,
164 u64 disk_num_bytes, u64 offset, unsigned long flags,
165 int compress_type);
f9756261 166void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry,
143bede5 167 struct btrfs_ordered_sum *sum);
c3504372 168struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *inode,
e6dcd2dc 169 u64 file_offset);
36d45567 170void btrfs_start_ordered_extent(struct btrfs_ordered_extent *entry);
0ef8b726 171int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
e6dcd2dc 172struct btrfs_ordered_extent *
6d072c8e 173btrfs_lookup_first_ordered_extent(struct btrfs_inode *inode, u64 file_offset);
c095f333
QW
174struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range(
175 struct btrfs_inode *inode, u64 file_offset, u64 len);
a776c6fa
NB
176struct btrfs_ordered_extent *btrfs_lookup_ordered_range(
177 struct btrfs_inode *inode,
178 u64 file_offset,
179 u64 len);
48778179
FM
180void btrfs_get_ordered_extents_for_logging(struct btrfs_inode *inode,
181 struct list_head *list);
6374e57a 182u64 btrfs_wait_ordered_extents(struct btrfs_root *root, u64 nr,
578def7c 183 const u64 range_start, const u64 range_len);
042528f8 184void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, u64 nr,
578def7c 185 const u64 range_start, const u64 range_len);
b272ae22 186void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
ffa87214
NB
187 u64 end,
188 struct extent_state **cached_state);
632ddfa2
JB
189bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
190 struct extent_state **cached_state);
b0307e28
CH
191struct btrfs_ordered_extent *btrfs_split_ordered_extent(
192 struct btrfs_ordered_extent *ordered, u64 len);
6352b91d 193int __init ordered_data_init(void);
e67c718b 194void __cold ordered_data_exit(void);
9888c340 195
dc17ff8f 196#endif