diff options
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 1123 |
1 files changed, 70 insertions, 1053 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 84a6a5b3384a..ddcc58f03c79 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <asm/kmap_types.h> | 33 | #include <asm/kmap_types.h> |
34 | #include <linux/pagemap.h> | 34 | #include <linux/pagemap.h> |
35 | #include <linux/btrfs.h> | 35 | #include <linux/btrfs.h> |
36 | #include <linux/btrfs_tree.h> | ||
36 | #include <linux/workqueue.h> | 37 | #include <linux/workqueue.h> |
37 | #include <linux/security.h> | 38 | #include <linux/security.h> |
38 | #include <linux/sizes.h> | 39 | #include <linux/sizes.h> |
@@ -64,98 +65,6 @@ struct btrfs_ordered_sum; | |||
64 | 65 | ||
65 | #define BTRFS_COMPAT_EXTENT_TREE_V0 | 66 | #define BTRFS_COMPAT_EXTENT_TREE_V0 |
66 | 67 | ||
67 | /* holds pointers to all of the tree roots */ | ||
68 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL | ||
69 | |||
70 | /* stores information about which extents are in use, and reference counts */ | ||
71 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL | ||
72 | |||
73 | /* | ||
74 | * chunk tree stores translations from logical -> physical block numbering | ||
75 | * the super block points to the chunk tree | ||
76 | */ | ||
77 | #define BTRFS_CHUNK_TREE_OBJECTID 3ULL | ||
78 | |||
79 | /* | ||
80 | * stores information about which areas of a given device are in use. | ||
81 | * one per device. The tree of tree roots points to the device tree | ||
82 | */ | ||
83 | #define BTRFS_DEV_TREE_OBJECTID 4ULL | ||
84 | |||
85 | /* one per subvolume, storing files and directories */ | ||
86 | #define BTRFS_FS_TREE_OBJECTID 5ULL | ||
87 | |||
88 | /* directory objectid inside the root tree */ | ||
89 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL | ||
90 | |||
91 | /* holds checksums of all the data extents */ | ||
92 | #define BTRFS_CSUM_TREE_OBJECTID 7ULL | ||
93 | |||
94 | /* holds quota configuration and tracking */ | ||
95 | #define BTRFS_QUOTA_TREE_OBJECTID 8ULL | ||
96 | |||
97 | /* for storing items that use the BTRFS_UUID_KEY* types */ | ||
98 | #define BTRFS_UUID_TREE_OBJECTID 9ULL | ||
99 | |||
100 | /* tracks free space in block groups. */ | ||
101 | #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL | ||
102 | |||
103 | /* device stats in the device tree */ | ||
104 | #define BTRFS_DEV_STATS_OBJECTID 0ULL | ||
105 | |||
106 | /* for storing balance parameters in the root tree */ | ||
107 | #define BTRFS_BALANCE_OBJECTID -4ULL | ||
108 | |||
109 | /* orhpan objectid for tracking unlinked/truncated files */ | ||
110 | #define BTRFS_ORPHAN_OBJECTID -5ULL | ||
111 | |||
112 | /* does write ahead logging to speed up fsyncs */ | ||
113 | #define BTRFS_TREE_LOG_OBJECTID -6ULL | ||
114 | #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL | ||
115 | |||
116 | /* for space balancing */ | ||
117 | #define BTRFS_TREE_RELOC_OBJECTID -8ULL | ||
118 | #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL | ||
119 | |||
120 | /* | ||
121 | * extent checksums all have this objectid | ||
122 | * this allows them to share the logging tree | ||
123 | * for fsyncs | ||
124 | */ | ||
125 | #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL | ||
126 | |||
127 | /* For storing free space cache */ | ||
128 | #define BTRFS_FREE_SPACE_OBJECTID -11ULL | ||
129 | |||
130 | /* | ||
131 | * The inode number assigned to the special inode for storing | ||
132 | * free ino cache | ||
133 | */ | ||
134 | #define BTRFS_FREE_INO_OBJECTID -12ULL | ||
135 | |||
136 | /* dummy objectid represents multiple objectids */ | ||
137 | #define BTRFS_MULTIPLE_OBJECTIDS -255ULL | ||
138 | |||
139 | /* | ||
140 | * All files have objectids in this range. | ||
141 | */ | ||
142 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL | ||
143 | #define BTRFS_LAST_FREE_OBJECTID -256ULL | ||
144 | #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL | ||
145 | |||
146 | |||
147 | /* | ||
148 | * the device items go into the chunk tree. The key is in the form | ||
149 | * [ 1 BTRFS_DEV_ITEM_KEY device_id ] | ||
150 | */ | ||
151 | #define BTRFS_DEV_ITEMS_OBJECTID 1ULL | ||
152 | |||
153 | #define BTRFS_BTREE_INODE_OBJECTID 1 | ||
154 | |||
155 | #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2 | ||
156 | |||
157 | #define BTRFS_DEV_REPLACE_DEVID 0ULL | ||
158 | |||
159 | /* | 68 | /* |
160 | * the max metadata block size. This limit is somewhat artificial, | 69 | * the max metadata block size. This limit is somewhat artificial, |
161 | * but the memmove costs go through the roof for larger blocks. | 70 | * but the memmove costs go through the roof for larger blocks. |
@@ -175,12 +84,6 @@ struct btrfs_ordered_sum; | |||
175 | */ | 84 | */ |
176 | #define BTRFS_LINK_MAX 65535U | 85 | #define BTRFS_LINK_MAX 65535U |
177 | 86 | ||
178 | /* 32 bytes in various csum fields */ | ||
179 | #define BTRFS_CSUM_SIZE 32 | ||
180 | |||
181 | /* csum types */ | ||
182 | #define BTRFS_CSUM_TYPE_CRC32 0 | ||
183 | |||
184 | static const int btrfs_csum_sizes[] = { 4 }; | 87 | static const int btrfs_csum_sizes[] = { 4 }; |
185 | 88 | ||
186 | /* four bytes for CRC32 */ | 89 | /* four bytes for CRC32 */ |
@@ -189,17 +92,6 @@ static const int btrfs_csum_sizes[] = { 4 }; | |||
189 | /* spefic to btrfs_map_block(), therefore not in include/linux/blk_types.h */ | 92 | /* spefic to btrfs_map_block(), therefore not in include/linux/blk_types.h */ |
190 | #define REQ_GET_READ_MIRRORS (1 << 30) | 93 | #define REQ_GET_READ_MIRRORS (1 << 30) |
191 | 94 | ||
192 | #define BTRFS_FT_UNKNOWN 0 | ||
193 | #define BTRFS_FT_REG_FILE 1 | ||
194 | #define BTRFS_FT_DIR 2 | ||
195 | #define BTRFS_FT_CHRDEV 3 | ||
196 | #define BTRFS_FT_BLKDEV 4 | ||
197 | #define BTRFS_FT_FIFO 5 | ||
198 | #define BTRFS_FT_SOCK 6 | ||
199 | #define BTRFS_FT_SYMLINK 7 | ||
200 | #define BTRFS_FT_XATTR 8 | ||
201 | #define BTRFS_FT_MAX 9 | ||
202 | |||
203 | /* ioprio of readahead is set to idle */ | 95 | /* ioprio of readahead is set to idle */ |
204 | #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) | 96 | #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) |
205 | 97 | ||
@@ -207,138 +99,10 @@ static const int btrfs_csum_sizes[] = { 4 }; | |||
207 | 99 | ||
208 | #define BTRFS_MAX_EXTENT_SIZE SZ_128M | 100 | #define BTRFS_MAX_EXTENT_SIZE SZ_128M |
209 | 101 | ||
210 | /* | ||
211 | * The key defines the order in the tree, and so it also defines (optimal) | ||
212 | * block layout. | ||
213 | * | ||
214 | * objectid corresponds to the inode number. | ||
215 | * | ||
216 | * type tells us things about the object, and is a kind of stream selector. | ||
217 | * so for a given inode, keys with type of 1 might refer to the inode data, | ||
218 | * type of 2 may point to file data in the btree and type == 3 may point to | ||
219 | * extents. | ||
220 | * | ||
221 | * offset is the starting byte offset for this key in the stream. | ||
222 | * | ||
223 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always | ||
224 | * in cpu native order. Otherwise they are identical and their sizes | ||
225 | * should be the same (ie both packed) | ||
226 | */ | ||
227 | struct btrfs_disk_key { | ||
228 | __le64 objectid; | ||
229 | u8 type; | ||
230 | __le64 offset; | ||
231 | } __attribute__ ((__packed__)); | ||
232 | |||
233 | struct btrfs_key { | ||
234 | u64 objectid; | ||
235 | u8 type; | ||
236 | u64 offset; | ||
237 | } __attribute__ ((__packed__)); | ||
238 | |||
239 | struct btrfs_mapping_tree { | 102 | struct btrfs_mapping_tree { |
240 | struct extent_map_tree map_tree; | 103 | struct extent_map_tree map_tree; |
241 | }; | 104 | }; |
242 | 105 | ||
243 | struct btrfs_dev_item { | ||
244 | /* the internal btrfs device id */ | ||
245 | __le64 devid; | ||
246 | |||
247 | /* size of the device */ | ||
248 | __le64 total_bytes; | ||
249 | |||
250 | /* bytes used */ | ||
251 | __le64 bytes_used; | ||
252 | |||
253 | /* optimal io alignment for this device */ | ||
254 | __le32 io_align; | ||
255 | |||
256 | /* optimal io width for this device */ | ||
257 | __le32 io_width; | ||
258 | |||
259 | /* minimal io size for this device */ | ||
260 | __le32 sector_size; | ||
261 | |||
262 | /* type and info about this device */ | ||
263 | __le64 type; | ||
264 | |||
265 | /* expected generation for this device */ | ||
266 | __le64 generation; | ||
267 | |||
268 | /* | ||
269 | * starting byte of this partition on the device, | ||
270 | * to allow for stripe alignment in the future | ||
271 | */ | ||
272 | __le64 start_offset; | ||
273 | |||
274 | /* grouping information for allocation decisions */ | ||
275 | __le32 dev_group; | ||
276 | |||
277 | /* seek speed 0-100 where 100 is fastest */ | ||
278 | u8 seek_speed; | ||
279 | |||
280 | /* bandwidth 0-100 where 100 is fastest */ | ||
281 | u8 bandwidth; | ||
282 | |||
283 | /* btrfs generated uuid for this device */ | ||
284 | u8 uuid[BTRFS_UUID_SIZE]; | ||
285 | |||
286 | /* uuid of FS who owns this device */ | ||
287 | u8 fsid[BTRFS_UUID_SIZE]; | ||
288 | } __attribute__ ((__packed__)); | ||
289 | |||
290 | struct btrfs_stripe { | ||
291 | __le64 devid; | ||
292 | __le64 offset; | ||
293 | u8 dev_uuid[BTRFS_UUID_SIZE]; | ||
294 | } __attribute__ ((__packed__)); | ||
295 | |||
296 | struct btrfs_chunk { | ||
297 | /* size of this chunk in bytes */ | ||
298 | __le64 length; | ||
299 | |||
300 | /* objectid of the root referencing this chunk */ | ||
301 | __le64 owner; | ||
302 | |||
303 | __le64 stripe_len; | ||
304 | __le64 type; | ||
305 | |||
306 | /* optimal io alignment for this chunk */ | ||
307 | __le32 io_align; | ||
308 | |||
309 | /* optimal io width for this chunk */ | ||
310 | __le32 io_width; | ||
311 | |||
312 | /* minimal io size for this chunk */ | ||
313 | __le32 sector_size; | ||
314 | |||
315 | /* 2^16 stripes is quite a lot, a second limit is the size of a single | ||
316 | * item in the btree | ||
317 | */ | ||
318 | __le16 num_stripes; | ||
319 | |||
320 | /* sub stripes only matter for raid10 */ | ||
321 | __le16 sub_stripes; | ||
322 | struct btrfs_stripe stripe; | ||
323 | /* additional stripes go here */ | ||
324 | } __attribute__ ((__packed__)); | ||
325 | |||
326 | #define BTRFS_FREE_SPACE_EXTENT 1 | ||
327 | #define BTRFS_FREE_SPACE_BITMAP 2 | ||
328 | |||
329 | struct btrfs_free_space_entry { | ||
330 | __le64 offset; | ||
331 | __le64 bytes; | ||
332 | u8 type; | ||
333 | } __attribute__ ((__packed__)); | ||
334 | |||
335 | struct btrfs_free_space_header { | ||
336 | struct btrfs_disk_key location; | ||
337 | __le64 generation; | ||
338 | __le64 num_entries; | ||
339 | __le64 num_bitmaps; | ||
340 | } __attribute__ ((__packed__)); | ||
341 | |||
342 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) | 106 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) |
343 | { | 107 | { |
344 | BUG_ON(num_stripes == 0); | 108 | BUG_ON(num_stripes == 0); |
@@ -346,9 +110,6 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes) | |||
346 | sizeof(struct btrfs_stripe) * (num_stripes - 1); | 110 | sizeof(struct btrfs_stripe) * (num_stripes - 1); |
347 | } | 111 | } |
348 | 112 | ||
349 | #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) | ||
350 | #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) | ||
351 | |||
352 | /* | 113 | /* |
353 | * File system states | 114 | * File system states |
354 | */ | 115 | */ |
@@ -357,13 +118,6 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes) | |||
357 | #define BTRFS_FS_STATE_TRANS_ABORTED 2 | 118 | #define BTRFS_FS_STATE_TRANS_ABORTED 2 |
358 | #define BTRFS_FS_STATE_DEV_REPLACING 3 | 119 | #define BTRFS_FS_STATE_DEV_REPLACING 3 |
359 | 120 | ||
360 | /* Super block flags */ | ||
361 | /* Errors detected */ | ||
362 | #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2) | ||
363 | |||
364 | #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32) | ||
365 | #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33) | ||
366 | |||
367 | #define BTRFS_BACKREF_REV_MAX 256 | 121 | #define BTRFS_BACKREF_REV_MAX 256 |
368 | #define BTRFS_BACKREF_REV_SHIFT 56 | 122 | #define BTRFS_BACKREF_REV_SHIFT 56 |
369 | #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ | 123 | #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ |
@@ -410,7 +164,6 @@ struct btrfs_header { | |||
410 | * room to translate 14 chunks with 3 stripes each. | 164 | * room to translate 14 chunks with 3 stripes each. |
411 | */ | 165 | */ |
412 | #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 | 166 | #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 |
413 | #define BTRFS_LABEL_SIZE 256 | ||
414 | 167 | ||
415 | /* | 168 | /* |
416 | * just in case we somehow lose the roots and are not able to mount, | 169 | * just in case we somehow lose the roots and are not able to mount, |
@@ -507,31 +260,6 @@ struct btrfs_super_block { | |||
507 | * Compat flags that we support. If any incompat flags are set other than the | 260 | * Compat flags that we support. If any incompat flags are set other than the |
508 | * ones specified below then we will fail to mount | 261 | * ones specified below then we will fail to mount |
509 | */ | 262 | */ |
510 | #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0) | ||
511 | |||
512 | #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) | ||
513 | #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1) | ||
514 | #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2) | ||
515 | #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3) | ||
516 | /* | ||
517 | * some patches floated around with a second compression method | ||
518 | * lets save that incompat here for when they do get in | ||
519 | * Note we don't actually support it, we're just reserving the | ||
520 | * number | ||
521 | */ | ||
522 | #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4) | ||
523 | |||
524 | /* | ||
525 | * older kernels tried to do bigger metadata blocks, but the | ||
526 | * code was pretty buggy. Lets not let them try anymore. | ||
527 | */ | ||
528 | #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5) | ||
529 | |||
530 | #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6) | ||
531 | #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7) | ||
532 | #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8) | ||
533 | #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9) | ||
534 | |||
535 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL | 263 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL |
536 | #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL | 264 | #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL |
537 | #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL | 265 | #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL |
@@ -624,357 +352,8 @@ struct btrfs_path { | |||
624 | unsigned int need_commit_sem:1; | 352 | unsigned int need_commit_sem:1; |
625 | unsigned int skip_release_on_error:1; | 353 | unsigned int skip_release_on_error:1; |
626 | }; | 354 | }; |
627 | |||
628 | /* | ||
629 | * items in the extent btree are used to record the objectid of the | ||
630 | * owner of the block and the number of references | ||
631 | */ | ||
632 | |||
633 | struct btrfs_extent_item { | ||
634 | __le64 refs; | ||
635 | __le64 generation; | ||
636 | __le64 flags; | ||
637 | } __attribute__ ((__packed__)); | ||
638 | |||
639 | struct btrfs_extent_item_v0 { | ||
640 | __le32 refs; | ||
641 | } __attribute__ ((__packed__)); | ||
642 | |||
643 | #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \ | 355 | #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \ |
644 | sizeof(struct btrfs_item)) | 356 | sizeof(struct btrfs_item)) |
645 | |||
646 | #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0) | ||
647 | #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1) | ||
648 | |||
649 | /* following flags only apply to tree blocks */ | ||
650 | |||
651 | /* use full backrefs for extent pointers in the block */ | ||
652 | #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8) | ||
653 | |||
654 | /* | ||
655 | * this flag is only used internally by scrub and may be changed at any time | ||
656 | * it is only declared here to avoid collisions | ||
657 | */ | ||
658 | #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48) | ||
659 | |||
660 | struct btrfs_tree_block_info { | ||
661 | struct btrfs_disk_key key; | ||
662 | u8 level; | ||
663 | } __attribute__ ((__packed__)); | ||
664 | |||
665 | struct btrfs_extent_data_ref { | ||
666 | __le64 root; | ||
667 | __le64 objectid; | ||
668 | __le64 offset; | ||
669 | __le32 count; | ||
670 | } __attribute__ ((__packed__)); | ||
671 | |||
672 | struct btrfs_shared_data_ref { | ||
673 | __le32 count; | ||
674 | } __attribute__ ((__packed__)); | ||
675 | |||
676 | struct btrfs_extent_inline_ref { | ||
677 | u8 type; | ||
678 | __le64 offset; | ||
679 | } __attribute__ ((__packed__)); | ||
680 | |||
681 | /* old style backrefs item */ | ||
682 | struct btrfs_extent_ref_v0 { | ||
683 | __le64 root; | ||
684 | __le64 generation; | ||
685 | __le64 objectid; | ||
686 | __le32 count; | ||
687 | } __attribute__ ((__packed__)); | ||
688 | |||
689 | |||
690 | /* dev extents record free space on individual devices. The owner | ||
691 | * field points back to the chunk allocation mapping tree that allocated | ||
692 | * the extent. The chunk tree uuid field is a way to double check the owner | ||
693 | */ | ||
694 | struct btrfs_dev_extent { | ||
695 | __le64 chunk_tree; | ||
696 | __le64 chunk_objectid; | ||
697 | __le64 chunk_offset; | ||
698 | __le64 length; | ||
699 | u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; | ||
700 | } __attribute__ ((__packed__)); | ||
701 | |||
702 | struct btrfs_inode_ref { | ||
703 | __le64 index; | ||
704 | __le16 name_len; | ||
705 | /* name goes here */ | ||
706 | } __attribute__ ((__packed__)); | ||
707 | |||
708 | struct btrfs_inode_extref { | ||
709 | __le64 parent_objectid; | ||
710 | __le64 index; | ||
711 | __le16 name_len; | ||
712 | __u8 name[0]; | ||
713 | /* name goes here */ | ||
714 | } __attribute__ ((__packed__)); | ||
715 | |||
716 | struct btrfs_timespec { | ||
717 | __le64 sec; | ||
718 | __le32 nsec; | ||
719 | } __attribute__ ((__packed__)); | ||
720 | |||
721 | struct btrfs_inode_item { | ||
722 | /* nfs style generation number */ | ||
723 | __le64 generation; | ||
724 | /* transid that last touched this inode */ | ||
725 | __le64 transid; | ||
726 | __le64 size; | ||
727 | __le64 nbytes; | ||
728 | __le64 block_group; | ||
729 | __le32 nlink; | ||
730 | __le32 uid; | ||
731 | __le32 gid; | ||
732 | __le32 mode; | ||
733 | __le64 rdev; | ||
734 | __le64 flags; | ||
735 | |||
736 | /* modification sequence number for NFS */ | ||
737 | __le64 sequence; | ||
738 | |||
739 | /* | ||
740 | * a little future expansion, for more than this we can | ||
741 | * just grow the inode item and version it | ||
742 | */ | ||
743 | __le64 reserved[4]; | ||
744 | struct btrfs_timespec atime; | ||
745 | struct btrfs_timespec ctime; | ||
746 | struct btrfs_timespec mtime; | ||
747 | struct btrfs_timespec otime; | ||
748 | } __attribute__ ((__packed__)); | ||
749 | |||
750 | struct btrfs_dir_log_item { | ||
751 | __le64 end; | ||
752 | } __attribute__ ((__packed__)); | ||
753 | |||
754 | struct btrfs_dir_item { | ||
755 | struct btrfs_disk_key location; | ||
756 | __le64 transid; | ||
757 | __le16 data_len; | ||
758 | __le16 name_len; | ||
759 | u8 type; | ||
760 | } __attribute__ ((__packed__)); | ||
761 | |||
762 | #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0) | ||
763 | |||
764 | /* | ||
765 | * Internal in-memory flag that a subvolume has been marked for deletion but | ||
766 | * still visible as a directory | ||
767 | */ | ||
768 | #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48) | ||
769 | |||
770 | struct btrfs_root_item { | ||
771 | struct btrfs_inode_item inode; | ||
772 | __le64 generation; | ||
773 | __le64 root_dirid; | ||
774 | __le64 bytenr; | ||
775 | __le64 byte_limit; | ||
776 | __le64 bytes_used; | ||
777 | __le64 last_snapshot; | ||
778 | __le64 flags; | ||
779 | __le32 refs; | ||
780 | struct btrfs_disk_key drop_progress; | ||
781 | u8 drop_level; | ||
782 | u8 level; | ||
783 | |||
784 | /* | ||
785 | * The following fields appear after subvol_uuids+subvol_times | ||
786 | * were introduced. | ||
787 | */ | ||
788 | |||
789 | /* | ||
790 | * This generation number is used to test if the new fields are valid | ||
791 | * and up to date while reading the root item. Every time the root item | ||
792 | * is written out, the "generation" field is copied into this field. If | ||
793 | * anyone ever mounted the fs with an older kernel, we will have | ||
794 | * mismatching generation values here and thus must invalidate the | ||
795 | * new fields. See btrfs_update_root and btrfs_find_last_root for | ||
796 | * details. | ||
797 | * the offset of generation_v2 is also used as the start for the memset | ||
798 | * when invalidating the fields. | ||
799 | */ | ||
800 | __le64 generation_v2; | ||
801 | u8 uuid[BTRFS_UUID_SIZE]; | ||
802 | u8 parent_uuid[BTRFS_UUID_SIZE]; | ||
803 | u8 received_uuid[BTRFS_UUID_SIZE]; | ||
804 | __le64 ctransid; /* updated when an inode changes */ | ||
805 | __le64 otransid; /* trans when created */ | ||
806 | __le64 stransid; /* trans when sent. non-zero for received subvol */ | ||
807 | __le64 rtransid; /* trans when received. non-zero for received subvol */ | ||
808 | struct btrfs_timespec ctime; | ||
809 | struct btrfs_timespec otime; | ||
810 | struct btrfs_timespec stime; | ||
811 | struct btrfs_timespec rtime; | ||
812 | __le64 reserved[8]; /* for future */ | ||
813 | } __attribute__ ((__packed__)); | ||
814 | |||
815 | /* | ||
816 | * this is used for both forward and backward root refs | ||
817 | */ | ||
818 | struct btrfs_root_ref { | ||
819 | __le64 dirid; | ||
820 | __le64 sequence; | ||
821 | __le16 name_len; | ||
822 | } __attribute__ ((__packed__)); | ||
823 | |||
824 | struct btrfs_disk_balance_args { | ||
825 | /* | ||
826 | * profiles to operate on, single is denoted by | ||
827 | * BTRFS_AVAIL_ALLOC_BIT_SINGLE | ||
828 | */ | ||
829 | __le64 profiles; | ||
830 | |||
831 | /* | ||
832 | * usage filter | ||
833 | * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' | ||
834 | * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max | ||
835 | */ | ||
836 | union { | ||
837 | __le64 usage; | ||
838 | struct { | ||
839 | __le32 usage_min; | ||
840 | __le32 usage_max; | ||
841 | }; | ||
842 | }; | ||
843 | |||
844 | /* devid filter */ | ||
845 | __le64 devid; | ||
846 | |||
847 | /* devid subset filter [pstart..pend) */ | ||
848 | __le64 pstart; | ||
849 | __le64 pend; | ||
850 | |||
851 | /* btrfs virtual address space subset filter [vstart..vend) */ | ||
852 | __le64 vstart; | ||
853 | __le64 vend; | ||
854 | |||
855 | /* | ||
856 | * profile to convert to, single is denoted by | ||
857 | * BTRFS_AVAIL_ALLOC_BIT_SINGLE | ||
858 | */ | ||
859 | __le64 target; | ||
860 | |||
861 | /* BTRFS_BALANCE_ARGS_* */ | ||
862 | __le64 flags; | ||
863 | |||
864 | /* | ||
865 | * BTRFS_BALANCE_ARGS_LIMIT with value 'limit' | ||
866 | * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum | ||
867 | * and maximum | ||
868 | */ | ||
869 | union { | ||
870 | __le64 limit; | ||
871 | struct { | ||
872 | __le32 limit_min; | ||
873 | __le32 limit_max; | ||
874 | }; | ||
875 | }; | ||
876 | |||
877 | /* | ||
878 | * Process chunks that cross stripes_min..stripes_max devices, | ||
879 | * BTRFS_BALANCE_ARGS_STRIPES_RANGE | ||
880 | */ | ||
881 | __le32 stripes_min; | ||
882 | __le32 stripes_max; | ||
883 | |||
884 | __le64 unused[6]; | ||
885 | } __attribute__ ((__packed__)); | ||
886 | |||
887 | /* | ||
888 | * store balance parameters to disk so that balance can be properly | ||
889 | * resumed after crash or unmount | ||
890 | */ | ||
891 | struct btrfs_balance_item { | ||
892 | /* BTRFS_BALANCE_* */ | ||
893 | __le64 flags; | ||
894 | |||
895 | struct btrfs_disk_balance_args data; | ||
896 | struct btrfs_disk_balance_args meta; | ||
897 | struct btrfs_disk_balance_args sys; | ||
898 | |||
899 | __le64 unused[4]; | ||
900 | } __attribute__ ((__packed__)); | ||
901 | |||
902 | #define BTRFS_FILE_EXTENT_INLINE 0 | ||
903 | #define BTRFS_FILE_EXTENT_REG 1 | ||
904 | #define BTRFS_FILE_EXTENT_PREALLOC 2 | ||
905 | |||
906 | struct btrfs_file_extent_item { | ||
907 | /* | ||
908 | * transaction id that created this extent | ||
909 | */ | ||
910 | __le64 generation; | ||
911 | /* | ||
912 | * max number of bytes to hold this extent in ram | ||
913 | * when we split a compressed extent we can't know how big | ||
914 | * each of the resulting pieces will be. So, this is | ||
915 | * an upper limit on the size of the extent in ram instead of | ||
916 | * an exact limit. | ||
917 | */ | ||
918 | __le64 ram_bytes; | ||
919 | |||
920 | /* | ||
921 | * 32 bits for the various ways we might encode the data, | ||
922 | * including compression and encryption. If any of these | ||
923 | * are set to something a given disk format doesn't understand | ||
924 | * it is treated like an incompat flag for reading and writing, | ||
925 | * but not for stat. | ||
926 | */ | ||
927 | u8 compression; | ||
928 | u8 encryption; | ||
929 | __le16 other_encoding; /* spare for later use */ | ||
930 | |||
931 | /* are we inline data or a real extent? */ | ||
932 | u8 type; | ||
933 | |||
934 | /* | ||
935 | * disk space consumed by the extent, checksum blocks are included | ||
936 | * in these numbers | ||
937 | * | ||
938 | * At this offset in the structure, the inline extent data start. | ||
939 | */ | ||
940 | __le64 disk_bytenr; | ||
941 | __le64 disk_num_bytes; | ||
942 | /* | ||
943 | * the logical offset in file blocks (no csums) | ||
944 | * this extent record is for. This allows a file extent to point | ||
945 | * into the middle of an existing extent on disk, sharing it | ||
946 | * between two snapshots (useful if some bytes in the middle of the | ||
947 | * extent have changed | ||
948 | */ | ||
949 | __le64 offset; | ||
950 | /* | ||
951 | * the logical number of file blocks (no csums included). This | ||
952 | * always reflects the size uncompressed and without encoding. | ||
953 | */ | ||
954 | __le64 num_bytes; | ||
955 | |||
956 | } __attribute__ ((__packed__)); | ||
957 | |||
958 | struct btrfs_csum_item { | ||
959 | u8 csum; | ||
960 | } __attribute__ ((__packed__)); | ||
961 | |||
962 | struct btrfs_dev_stats_item { | ||
963 | /* | ||
964 | * grow this item struct at the end for future enhancements and keep | ||
965 | * the existing values unchanged | ||
966 | */ | ||
967 | __le64 values[BTRFS_DEV_STAT_VALUES_MAX]; | ||
968 | } __attribute__ ((__packed__)); | ||
969 | |||
970 | #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0 | ||
971 | #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1 | ||
972 | #define BTRFS_DEV_REPLACE_ITEM_STATE_NEVER_STARTED 0 | ||
973 | #define BTRFS_DEV_REPLACE_ITEM_STATE_STARTED 1 | ||
974 | #define BTRFS_DEV_REPLACE_ITEM_STATE_SUSPENDED 2 | ||
975 | #define BTRFS_DEV_REPLACE_ITEM_STATE_FINISHED 3 | ||
976 | #define BTRFS_DEV_REPLACE_ITEM_STATE_CANCELED 4 | ||
977 | |||
978 | struct btrfs_dev_replace { | 357 | struct btrfs_dev_replace { |
979 | u64 replace_state; /* see #define above */ | 358 | u64 replace_state; /* see #define above */ |
980 | u64 time_started; /* seconds since 1-Jan-1970 */ | 359 | u64 time_started; /* seconds since 1-Jan-1970 */ |
@@ -1005,175 +384,6 @@ struct btrfs_dev_replace { | |||
1005 | struct btrfs_scrub_progress scrub_progress; | 384 | struct btrfs_scrub_progress scrub_progress; |
1006 | }; | 385 | }; |
1007 | 386 | ||
1008 | struct btrfs_dev_replace_item { | ||
1009 | /* | ||
1010 | * grow this item struct at the end for future enhancements and keep | ||
1011 | * the existing values unchanged | ||
1012 | */ | ||
1013 | __le64 src_devid; | ||
1014 | __le64 cursor_left; | ||
1015 | __le64 cursor_right; | ||
1016 | __le64 cont_reading_from_srcdev_mode; | ||
1017 | |||
1018 | __le64 replace_state; | ||
1019 | __le64 time_started; | ||
1020 | __le64 time_stopped; | ||
1021 | __le64 num_write_errors; | ||
1022 | __le64 num_uncorrectable_read_errors; | ||
1023 | } __attribute__ ((__packed__)); | ||
1024 | |||
1025 | /* different types of block groups (and chunks) */ | ||
1026 | #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0) | ||
1027 | #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1) | ||
1028 | #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2) | ||
1029 | #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3) | ||
1030 | #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4) | ||
1031 | #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5) | ||
1032 | #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6) | ||
1033 | #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7) | ||
1034 | #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8) | ||
1035 | #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \ | ||
1036 | BTRFS_SPACE_INFO_GLOBAL_RSV) | ||
1037 | |||
1038 | enum btrfs_raid_types { | ||
1039 | BTRFS_RAID_RAID10, | ||
1040 | BTRFS_RAID_RAID1, | ||
1041 | BTRFS_RAID_DUP, | ||
1042 | BTRFS_RAID_RAID0, | ||
1043 | BTRFS_RAID_SINGLE, | ||
1044 | BTRFS_RAID_RAID5, | ||
1045 | BTRFS_RAID_RAID6, | ||
1046 | BTRFS_NR_RAID_TYPES | ||
1047 | }; | ||
1048 | |||
1049 | #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \ | ||
1050 | BTRFS_BLOCK_GROUP_SYSTEM | \ | ||
1051 | BTRFS_BLOCK_GROUP_METADATA) | ||
1052 | |||
1053 | #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ | ||
1054 | BTRFS_BLOCK_GROUP_RAID1 | \ | ||
1055 | BTRFS_BLOCK_GROUP_RAID5 | \ | ||
1056 | BTRFS_BLOCK_GROUP_RAID6 | \ | ||
1057 | BTRFS_BLOCK_GROUP_DUP | \ | ||
1058 | BTRFS_BLOCK_GROUP_RAID10) | ||
1059 | #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \ | ||
1060 | BTRFS_BLOCK_GROUP_RAID6) | ||
1061 | |||
1062 | /* | ||
1063 | * We need a bit for restriper to be able to tell when chunks of type | ||
1064 | * SINGLE are available. This "extended" profile format is used in | ||
1065 | * fs_info->avail_*_alloc_bits (in-memory) and balance item fields | ||
1066 | * (on-disk). The corresponding on-disk bit in chunk.type is reserved | ||
1067 | * to avoid remappings between two formats in future. | ||
1068 | */ | ||
1069 | #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48) | ||
1070 | |||
1071 | /* | ||
1072 | * A fake block group type that is used to communicate global block reserve | ||
1073 | * size to userspace via the SPACE_INFO ioctl. | ||
1074 | */ | ||
1075 | #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49) | ||
1076 | |||
1077 | #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \ | ||
1078 | BTRFS_AVAIL_ALLOC_BIT_SINGLE) | ||
1079 | |||
1080 | static inline u64 chunk_to_extended(u64 flags) | ||
1081 | { | ||
1082 | if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0) | ||
1083 | flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE; | ||
1084 | |||
1085 | return flags; | ||
1086 | } | ||
1087 | static inline u64 extended_to_chunk(u64 flags) | ||
1088 | { | ||
1089 | return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE; | ||
1090 | } | ||
1091 | |||
1092 | struct btrfs_block_group_item { | ||
1093 | __le64 used; | ||
1094 | __le64 chunk_objectid; | ||
1095 | __le64 flags; | ||
1096 | } __attribute__ ((__packed__)); | ||
1097 | |||
1098 | struct btrfs_free_space_info { | ||
1099 | __le32 extent_count; | ||
1100 | __le32 flags; | ||
1101 | } __attribute__ ((__packed__)); | ||
1102 | |||
1103 | #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0) | ||
1104 | |||
1105 | #define BTRFS_QGROUP_LEVEL_SHIFT 48 | ||
1106 | static inline u64 btrfs_qgroup_level(u64 qgroupid) | ||
1107 | { | ||
1108 | return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT; | ||
1109 | } | ||
1110 | |||
1111 | /* | ||
1112 | * is subvolume quota turned on? | ||
1113 | */ | ||
1114 | #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) | ||
1115 | /* | ||
1116 | * RESCAN is set during the initialization phase | ||
1117 | */ | ||
1118 | #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1) | ||
1119 | /* | ||
1120 | * Some qgroup entries are known to be out of date, | ||
1121 | * either because the configuration has changed in a way that | ||
1122 | * makes a rescan necessary, or because the fs has been mounted | ||
1123 | * with a non-qgroup-aware version. | ||
1124 | * Turning qouta off and on again makes it inconsistent, too. | ||
1125 | */ | ||
1126 | #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) | ||
1127 | |||
1128 | #define BTRFS_QGROUP_STATUS_VERSION 1 | ||
1129 | |||
1130 | struct btrfs_qgroup_status_item { | ||
1131 | __le64 version; | ||
1132 | /* | ||
1133 | * the generation is updated during every commit. As older | ||
1134 | * versions of btrfs are not aware of qgroups, it will be | ||
1135 | * possible to detect inconsistencies by checking the | ||
1136 | * generation on mount time | ||
1137 | */ | ||
1138 | __le64 generation; | ||
1139 | |||
1140 | /* flag definitions see above */ | ||
1141 | __le64 flags; | ||
1142 | |||
1143 | /* | ||
1144 | * only used during scanning to record the progress | ||
1145 | * of the scan. It contains a logical address | ||
1146 | */ | ||
1147 | __le64 rescan; | ||
1148 | } __attribute__ ((__packed__)); | ||
1149 | |||
1150 | struct btrfs_qgroup_info_item { | ||
1151 | __le64 generation; | ||
1152 | __le64 rfer; | ||
1153 | __le64 rfer_cmpr; | ||
1154 | __le64 excl; | ||
1155 | __le64 excl_cmpr; | ||
1156 | } __attribute__ ((__packed__)); | ||
1157 | |||
1158 | /* flags definition for qgroup limits */ | ||
1159 | #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0) | ||
1160 | #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1) | ||
1161 | #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2) | ||
1162 | #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3) | ||
1163 | #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4) | ||
1164 | #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5) | ||
1165 | |||
1166 | struct btrfs_qgroup_limit_item { | ||
1167 | /* | ||
1168 | * only updated when any of the other values change | ||
1169 | */ | ||
1170 | __le64 flags; | ||
1171 | __le64 max_rfer; | ||
1172 | __le64 max_excl; | ||
1173 | __le64 rsv_rfer; | ||
1174 | __le64 rsv_excl; | ||
1175 | } __attribute__ ((__packed__)); | ||
1176 | |||
1177 | /* For raid type sysfs entries */ | 387 | /* For raid type sysfs entries */ |
1178 | struct raid_kobject { | 388 | struct raid_kobject { |
1179 | int raid_type; | 389 | int raid_type; |
@@ -1408,6 +618,27 @@ struct btrfs_block_group_cache { | |||
1408 | 618 | ||
1409 | struct btrfs_io_ctl io_ctl; | 619 | struct btrfs_io_ctl io_ctl; |
1410 | 620 | ||
621 | /* | ||
622 | * Incremented when doing extent allocations and holding a read lock | ||
623 | * on the space_info's groups_sem semaphore. | ||
624 | * Decremented when an ordered extent that represents an IO against this | ||
625 | * block group's range is created (after it's added to its inode's | ||
626 | * root's list of ordered extents) or immediately after the allocation | ||
627 | * if it's a metadata extent or fallocate extent (for these cases we | ||
628 | * don't create ordered extents). | ||
629 | */ | ||
630 | atomic_t reservations; | ||
631 | |||
632 | /* | ||
633 | * Incremented while holding the spinlock *lock* by a task checking if | ||
634 | * it can perform a nocow write (incremented if the value for the *ro* | ||
635 | * field is 0). Decremented by such tasks once they create an ordered | ||
636 | * extent or before that if some error happens before reaching that step. | ||
637 | * This is to prevent races between block group relocation and nocow | ||
638 | * writes through direct IO. | ||
639 | */ | ||
640 | atomic_t nocow_writers; | ||
641 | |||
1411 | /* Lock for free space tree operations. */ | 642 | /* Lock for free space tree operations. */ |
1412 | struct mutex free_space_lock; | 643 | struct mutex free_space_lock; |
1413 | 644 | ||
@@ -2026,228 +1257,6 @@ struct btrfs_root { | |||
2026 | atomic_t qgroup_meta_rsv; | 1257 | atomic_t qgroup_meta_rsv; |
2027 | }; | 1258 | }; |
2028 | 1259 | ||
2029 | struct btrfs_ioctl_defrag_range_args { | ||
2030 | /* start of the defrag operation */ | ||
2031 | __u64 start; | ||
2032 | |||
2033 | /* number of bytes to defrag, use (u64)-1 to say all */ | ||
2034 | __u64 len; | ||
2035 | |||
2036 | /* | ||
2037 | * flags for the operation, which can include turning | ||
2038 | * on compression for this one defrag | ||
2039 | */ | ||
2040 | __u64 flags; | ||
2041 | |||
2042 | /* | ||
2043 | * any extent bigger than this will be considered | ||
2044 | * already defragged. Use 0 to take the kernel default | ||
2045 | * Use 1 to say every single extent must be rewritten | ||
2046 | */ | ||
2047 | __u32 extent_thresh; | ||
2048 | |||
2049 | /* | ||
2050 | * which compression method to use if turning on compression | ||
2051 | * for this defrag operation. If unspecified, zlib will | ||
2052 | * be used | ||
2053 | */ | ||
2054 | __u32 compress_type; | ||
2055 | |||
2056 | /* spare for later */ | ||
2057 | __u32 unused[4]; | ||
2058 | }; | ||
2059 | |||
2060 | |||
2061 | /* | ||
2062 | * inode items have the data typically returned from stat and store other | ||
2063 | * info about object characteristics. There is one for every file and dir in | ||
2064 | * the FS | ||
2065 | */ | ||
2066 | #define BTRFS_INODE_ITEM_KEY 1 | ||
2067 | #define BTRFS_INODE_REF_KEY 12 | ||
2068 | #define BTRFS_INODE_EXTREF_KEY 13 | ||
2069 | #define BTRFS_XATTR_ITEM_KEY 24 | ||
2070 | #define BTRFS_ORPHAN_ITEM_KEY 48 | ||
2071 | /* reserve 2-15 close to the inode for later flexibility */ | ||
2072 | |||
2073 | /* | ||
2074 | * dir items are the name -> inode pointers in a directory. There is one | ||
2075 | * for every name in a directory. | ||
2076 | */ | ||
2077 | #define BTRFS_DIR_LOG_ITEM_KEY 60 | ||
2078 | #define BTRFS_DIR_LOG_INDEX_KEY 72 | ||
2079 | #define BTRFS_DIR_ITEM_KEY 84 | ||
2080 | #define BTRFS_DIR_INDEX_KEY 96 | ||
2081 | /* | ||
2082 | * extent data is for file data | ||
2083 | */ | ||
2084 | #define BTRFS_EXTENT_DATA_KEY 108 | ||
2085 | |||
2086 | /* | ||
2087 | * extent csums are stored in a separate tree and hold csums for | ||
2088 | * an entire extent on disk. | ||
2089 | */ | ||
2090 | #define BTRFS_EXTENT_CSUM_KEY 128 | ||
2091 | |||
2092 | /* | ||
2093 | * root items point to tree roots. They are typically in the root | ||
2094 | * tree used by the super block to find all the other trees | ||
2095 | */ | ||
2096 | #define BTRFS_ROOT_ITEM_KEY 132 | ||
2097 | |||
2098 | /* | ||
2099 | * root backrefs tie subvols and snapshots to the directory entries that | ||
2100 | * reference them | ||
2101 | */ | ||
2102 | #define BTRFS_ROOT_BACKREF_KEY 144 | ||
2103 | |||
2104 | /* | ||
2105 | * root refs make a fast index for listing all of the snapshots and | ||
2106 | * subvolumes referenced by a given root. They point directly to the | ||
2107 | * directory item in the root that references the subvol | ||
2108 | */ | ||
2109 | #define BTRFS_ROOT_REF_KEY 156 | ||
2110 | |||
2111 | /* | ||
2112 | * extent items are in the extent map tree. These record which blocks | ||
2113 | * are used, and how many references there are to each block | ||
2114 | */ | ||
2115 | #define BTRFS_EXTENT_ITEM_KEY 168 | ||
2116 | |||
2117 | /* | ||
2118 | * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know | ||
2119 | * the length, so we save the level in key->offset instead of the length. | ||
2120 | */ | ||
2121 | #define BTRFS_METADATA_ITEM_KEY 169 | ||
2122 | |||
2123 | #define BTRFS_TREE_BLOCK_REF_KEY 176 | ||
2124 | |||
2125 | #define BTRFS_EXTENT_DATA_REF_KEY 178 | ||
2126 | |||
2127 | #define BTRFS_EXTENT_REF_V0_KEY 180 | ||
2128 | |||
2129 | #define BTRFS_SHARED_BLOCK_REF_KEY 182 | ||
2130 | |||
2131 | #define BTRFS_SHARED_DATA_REF_KEY 184 | ||
2132 | |||
2133 | /* | ||
2134 | * block groups give us hints into the extent allocation trees. Which | ||
2135 | * blocks are free etc etc | ||
2136 | */ | ||
2137 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 192 | ||
2138 | |||
2139 | /* | ||
2140 | * Every block group is represented in the free space tree by a free space info | ||
2141 | * item, which stores some accounting information. It is keyed on | ||
2142 | * (block_group_start, FREE_SPACE_INFO, block_group_length). | ||
2143 | */ | ||
2144 | #define BTRFS_FREE_SPACE_INFO_KEY 198 | ||
2145 | |||
2146 | /* | ||
2147 | * A free space extent tracks an extent of space that is free in a block group. | ||
2148 | * It is keyed on (start, FREE_SPACE_EXTENT, length). | ||
2149 | */ | ||
2150 | #define BTRFS_FREE_SPACE_EXTENT_KEY 199 | ||
2151 | |||
2152 | /* | ||
2153 | * When a block group becomes very fragmented, we convert it to use bitmaps | ||
2154 | * instead of extents. A free space bitmap is keyed on | ||
2155 | * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with | ||
2156 | * (length / sectorsize) bits. | ||
2157 | */ | ||
2158 | #define BTRFS_FREE_SPACE_BITMAP_KEY 200 | ||
2159 | |||
2160 | #define BTRFS_DEV_EXTENT_KEY 204 | ||
2161 | #define BTRFS_DEV_ITEM_KEY 216 | ||
2162 | #define BTRFS_CHUNK_ITEM_KEY 228 | ||
2163 | |||
2164 | /* | ||
2165 | * Records the overall state of the qgroups. | ||
2166 | * There's only one instance of this key present, | ||
2167 | * (0, BTRFS_QGROUP_STATUS_KEY, 0) | ||
2168 | */ | ||
2169 | #define BTRFS_QGROUP_STATUS_KEY 240 | ||
2170 | /* | ||
2171 | * Records the currently used space of the qgroup. | ||
2172 | * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). | ||
2173 | */ | ||
2174 | #define BTRFS_QGROUP_INFO_KEY 242 | ||
2175 | /* | ||
2176 | * Contains the user configured limits for the qgroup. | ||
2177 | * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). | ||
2178 | */ | ||
2179 | #define BTRFS_QGROUP_LIMIT_KEY 244 | ||
2180 | /* | ||
2181 | * Records the child-parent relationship of qgroups. For | ||
2182 | * each relation, 2 keys are present: | ||
2183 | * (childid, BTRFS_QGROUP_RELATION_KEY, parentid) | ||
2184 | * (parentid, BTRFS_QGROUP_RELATION_KEY, childid) | ||
2185 | */ | ||
2186 | #define BTRFS_QGROUP_RELATION_KEY 246 | ||
2187 | |||
2188 | /* | ||
2189 | * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. | ||
2190 | */ | ||
2191 | #define BTRFS_BALANCE_ITEM_KEY 248 | ||
2192 | |||
2193 | /* | ||
2194 | * The key type for tree items that are stored persistently, but do not need to | ||
2195 | * exist for extended period of time. The items can exist in any tree. | ||
2196 | * | ||
2197 | * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data] | ||
2198 | * | ||
2199 | * Existing items: | ||
2200 | * | ||
2201 | * - balance status item | ||
2202 | * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0) | ||
2203 | */ | ||
2204 | #define BTRFS_TEMPORARY_ITEM_KEY 248 | ||
2205 | |||
2206 | /* | ||
2207 | * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY | ||
2208 | */ | ||
2209 | #define BTRFS_DEV_STATS_KEY 249 | ||
2210 | |||
2211 | /* | ||
2212 | * The key type for tree items that are stored persistently and usually exist | ||
2213 | * for a long period, eg. filesystem lifetime. The item kinds can be status | ||
2214 | * information, stats or preference values. The item can exist in any tree. | ||
2215 | * | ||
2216 | * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data] | ||
2217 | * | ||
2218 | * Existing items: | ||
2219 | * | ||
2220 | * - device statistics, store IO stats in the device tree, one key for all | ||
2221 | * stats | ||
2222 | * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0) | ||
2223 | */ | ||
2224 | #define BTRFS_PERSISTENT_ITEM_KEY 249 | ||
2225 | |||
2226 | /* | ||
2227 | * Persistantly stores the device replace state in the device tree. | ||
2228 | * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0). | ||
2229 | */ | ||
2230 | #define BTRFS_DEV_REPLACE_KEY 250 | ||
2231 | |||
2232 | /* | ||
2233 | * Stores items that allow to quickly map UUIDs to something else. | ||
2234 | * These items are part of the filesystem UUID tree. | ||
2235 | * The key is built like this: | ||
2236 | * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits). | ||
2237 | */ | ||
2238 | #if BTRFS_UUID_SIZE != 16 | ||
2239 | #error "UUID items require BTRFS_UUID_SIZE == 16!" | ||
2240 | #endif | ||
2241 | #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */ | ||
2242 | #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to | ||
2243 | * received subvols */ | ||
2244 | |||
2245 | /* | ||
2246 | * string items are for debugging. They just store a short string of | ||
2247 | * data in the FS | ||
2248 | */ | ||
2249 | #define BTRFS_STRING_ITEM_KEY 253 | ||
2250 | |||
2251 | /* | 1260 | /* |
2252 | * Flags for mount options. | 1261 | * Flags for mount options. |
2253 | * | 1262 | * |
@@ -3499,6 +2508,12 @@ int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, | |||
3499 | struct btrfs_root *root); | 2508 | struct btrfs_root *root); |
3500 | int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, | 2509 | int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, |
3501 | struct btrfs_root *root); | 2510 | struct btrfs_root *root); |
2511 | void btrfs_dec_block_group_reservations(struct btrfs_fs_info *fs_info, | ||
2512 | const u64 start); | ||
2513 | void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg); | ||
2514 | bool btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr); | ||
2515 | void btrfs_dec_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr); | ||
2516 | void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg); | ||
3502 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache); | 2517 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache); |
3503 | int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, | 2518 | int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, |
3504 | struct btrfs_root *root, unsigned long count); | 2519 | struct btrfs_root *root, unsigned long count); |
@@ -4122,6 +3137,7 @@ void btrfs_test_inode_set_ops(struct inode *inode); | |||
4122 | 3137 | ||
4123 | /* ioctl.c */ | 3138 | /* ioctl.c */ |
4124 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 3139 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
3140 | long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | ||
4125 | int btrfs_ioctl_get_supported_features(void __user *arg); | 3141 | int btrfs_ioctl_get_supported_features(void __user *arg); |
4126 | void btrfs_update_iflags(struct inode *inode); | 3142 | void btrfs_update_iflags(struct inode *inode); |
4127 | void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); | 3143 | void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); |
@@ -4326,10 +3342,9 @@ static inline void assfail(char *expr, char *file, int line) | |||
4326 | #define ASSERT(expr) ((void)0) | 3342 | #define ASSERT(expr) ((void)0) |
4327 | #endif | 3343 | #endif |
4328 | 3344 | ||
4329 | #define btrfs_assert() | ||
4330 | __printf(5, 6) | 3345 | __printf(5, 6) |
4331 | __cold | 3346 | __cold |
4332 | void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function, | 3347 | void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function, |
4333 | unsigned int line, int errno, const char *fmt, ...); | 3348 | unsigned int line, int errno, const char *fmt, ...); |
4334 | 3349 | ||
4335 | const char *btrfs_decode_error(int errno); | 3350 | const char *btrfs_decode_error(int errno); |
@@ -4339,6 +3354,46 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, | |||
4339 | struct btrfs_root *root, const char *function, | 3354 | struct btrfs_root *root, const char *function, |
4340 | unsigned int line, int errno); | 3355 | unsigned int line, int errno); |
4341 | 3356 | ||
3357 | /* | ||
3358 | * Call btrfs_abort_transaction as early as possible when an error condition is | ||
3359 | * detected, that way the exact line number is reported. | ||
3360 | */ | ||
3361 | #define btrfs_abort_transaction(trans, root, errno) \ | ||
3362 | do { \ | ||
3363 | /* Report first abort since mount */ \ | ||
3364 | if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ | ||
3365 | &((root)->fs_info->fs_state))) { \ | ||
3366 | WARN(1, KERN_DEBUG \ | ||
3367 | "BTRFS: Transaction aborted (error %d)\n", \ | ||
3368 | (errno)); \ | ||
3369 | } \ | ||
3370 | __btrfs_abort_transaction((trans), (root), __func__, \ | ||
3371 | __LINE__, (errno)); \ | ||
3372 | } while (0) | ||
3373 | |||
3374 | #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \ | ||
3375 | do { \ | ||
3376 | __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \ | ||
3377 | (errno), fmt, ##args); \ | ||
3378 | } while (0) | ||
3379 | |||
3380 | __printf(5, 6) | ||
3381 | __cold | ||
3382 | void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, | ||
3383 | unsigned int line, int errno, const char *fmt, ...); | ||
3384 | /* | ||
3385 | * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic | ||
3386 | * will panic(). Otherwise we BUG() here. | ||
3387 | */ | ||
3388 | #define btrfs_panic(fs_info, errno, fmt, args...) \ | ||
3389 | do { \ | ||
3390 | __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \ | ||
3391 | BUG(); \ | ||
3392 | } while (0) | ||
3393 | |||
3394 | |||
3395 | /* compatibility and incompatibility defines */ | ||
3396 | |||
4342 | #define btrfs_set_fs_incompat(__fs_info, opt) \ | 3397 | #define btrfs_set_fs_incompat(__fs_info, opt) \ |
4343 | __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) | 3398 | __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) |
4344 | 3399 | ||
@@ -4455,44 +3510,6 @@ static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag) | |||
4455 | return !!(btrfs_super_compat_ro_flags(disk_super) & flag); | 3510 | return !!(btrfs_super_compat_ro_flags(disk_super) & flag); |
4456 | } | 3511 | } |
4457 | 3512 | ||
4458 | /* | ||
4459 | * Call btrfs_abort_transaction as early as possible when an error condition is | ||
4460 | * detected, that way the exact line number is reported. | ||
4461 | */ | ||
4462 | #define btrfs_abort_transaction(trans, root, errno) \ | ||
4463 | do { \ | ||
4464 | /* Report first abort since mount */ \ | ||
4465 | if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ | ||
4466 | &((root)->fs_info->fs_state))) { \ | ||
4467 | WARN(1, KERN_DEBUG \ | ||
4468 | "BTRFS: Transaction aborted (error %d)\n", \ | ||
4469 | (errno)); \ | ||
4470 | } \ | ||
4471 | __btrfs_abort_transaction((trans), (root), __func__, \ | ||
4472 | __LINE__, (errno)); \ | ||
4473 | } while (0) | ||
4474 | |||
4475 | #define btrfs_std_error(fs_info, errno, fmt, args...) \ | ||
4476 | do { \ | ||
4477 | __btrfs_std_error((fs_info), __func__, __LINE__, \ | ||
4478 | (errno), fmt, ##args); \ | ||
4479 | } while (0) | ||
4480 | |||
4481 | __printf(5, 6) | ||
4482 | __cold | ||
4483 | void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, | ||
4484 | unsigned int line, int errno, const char *fmt, ...); | ||
4485 | |||
4486 | /* | ||
4487 | * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic | ||
4488 | * will panic(). Otherwise we BUG() here. | ||
4489 | */ | ||
4490 | #define btrfs_panic(fs_info, errno, fmt, args...) \ | ||
4491 | do { \ | ||
4492 | __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \ | ||
4493 | BUG(); \ | ||
4494 | } while (0) | ||
4495 | |||
4496 | /* acl.c */ | 3513 | /* acl.c */ |
4497 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL | 3514 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
4498 | struct posix_acl *btrfs_get_acl(struct inode *inode, int type); | 3515 | struct posix_acl *btrfs_get_acl(struct inode *inode, int type); |