1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * Copyright (C) 2007 Oracle. All rights rese 3 * Copyright (C) 2007 Oracle. All rights reserved. 4 */ 4 */ 5 5 6 #ifndef BTRFS_CTREE_H 6 #ifndef BTRFS_CTREE_H 7 #define BTRFS_CTREE_H 7 #define BTRFS_CTREE_H 8 8 9 #include "linux/cleanup.h" !! 9 #include <linux/mm.h> 10 #include <linux/pagemap.h> !! 10 #include <linux/sched/signal.h> 11 #include <linux/spinlock.h> !! 11 #include <linux/highmem.h> 12 #include <linux/rbtree.h> !! 12 #include <linux/fs.h> 13 #include <linux/mutex.h> !! 13 #include <linux/rwsem.h> >> 14 #include <linux/semaphore.h> >> 15 #include <linux/completion.h> >> 16 #include <linux/backing-dev.h> 14 #include <linux/wait.h> 17 #include <linux/wait.h> 15 #include <linux/list.h> !! 18 #include <linux/slab.h> 16 #include <linux/atomic.h> !! 19 #include <linux/kobject.h> 17 #include <linux/xarray.h> !! 20 #include <trace/events/btrfs.h> >> 21 #include <asm/kmap_types.h> >> 22 #include <linux/pagemap.h> >> 23 #include <linux/btrfs.h> >> 24 #include <linux/btrfs_tree.h> >> 25 #include <linux/workqueue.h> >> 26 #include <linux/security.h> >> 27 #include <linux/sizes.h> >> 28 #include <linux/dynamic_debug.h> 18 #include <linux/refcount.h> 29 #include <linux/refcount.h> 19 #include <uapi/linux/btrfs_tree.h> !! 30 #include <linux/crc32c.h> 20 #include "locking.h" !! 31 #include "extent_io.h" 21 #include "fs.h" !! 32 #include "extent_map.h" 22 #include "accessors.h" !! 33 #include "async-thread.h" 23 #include "extent-io-tree.h" << 24 34 25 struct extent_buffer; << 26 struct btrfs_block_rsv; << 27 struct btrfs_trans_handle; 35 struct btrfs_trans_handle; 28 struct btrfs_block_group; !! 36 struct btrfs_transaction; >> 37 struct btrfs_pending_snapshot; >> 38 struct btrfs_delayed_ref_root; >> 39 extern struct kmem_cache *btrfs_trans_handle_cachep; >> 40 extern struct kmem_cache *btrfs_bit_radix_cachep; >> 41 extern struct kmem_cache *btrfs_path_cachep; >> 42 extern struct kmem_cache *btrfs_free_space_cachep; >> 43 extern struct kmem_cache *btrfs_free_space_bitmap_cachep; >> 44 struct btrfs_ordered_sum; >> 45 struct btrfs_ref; >> 46 >> 47 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */ >> 48 >> 49 #define BTRFS_MAX_MIRRORS 3 >> 50 >> 51 #define BTRFS_MAX_LEVEL 8 >> 52 >> 53 #define BTRFS_OLDEST_GENERATION 0ULL >> 54 >> 55 /* >> 56 * the max metadata block size. This limit is somewhat artificial, >> 57 * but the memmove costs go through the roof for larger blocks. >> 58 */ >> 59 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536 >> 60 >> 61 /* >> 62 * we can actually store much bigger names, but lets not confuse the rest >> 63 * of linux >> 64 */ >> 65 #define BTRFS_NAME_LEN 255 >> 66 >> 67 /* >> 68 * Theoretical limit is larger, but we keep this down to a sane >> 69 * value. That should limit greatly the possibility of collisions on >> 70 * inode ref items. >> 71 */ >> 72 #define BTRFS_LINK_MAX 65535U >> 73 >> 74 /* four bytes for CRC32 */ >> 75 static const int btrfs_csum_sizes[] = { 4 }; >> 76 >> 77 #define BTRFS_EMPTY_DIR_SIZE 0 >> 78 >> 79 /* ioprio of readahead is set to idle */ >> 80 #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) >> 81 >> 82 #define BTRFS_DIRTY_METADATA_THRESH SZ_32M 29 83 30 /* Read ahead values for struct btrfs_path.rea !! 84 /* >> 85 * Use large batch size to reduce overhead of metadata updates. On the reader >> 86 * side, we only read it when we are close to ENOSPC and the read overhead is >> 87 * mostly related to the number of CPUs, so it is OK to use arbitrary large >> 88 * value here. >> 89 */ >> 90 #define BTRFS_TOTAL_BYTES_PINNED_BATCH SZ_128M >> 91 >> 92 #define BTRFS_MAX_EXTENT_SIZE SZ_128M >> 93 >> 94 >> 95 /* >> 96 * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size >> 97 */ >> 98 static inline u32 count_max_extents(u64 size) >> 99 { >> 100 return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); >> 101 } >> 102 >> 103 struct btrfs_mapping_tree { >> 104 struct extent_map_tree map_tree; >> 105 }; >> 106 >> 107 static inline unsigned long btrfs_chunk_item_size(int num_stripes) >> 108 { >> 109 BUG_ON(num_stripes == 0); >> 110 return sizeof(struct btrfs_chunk) + >> 111 sizeof(struct btrfs_stripe) * (num_stripes - 1); >> 112 } >> 113 >> 114 /* >> 115 * Runtime (in-memory) states of filesystem >> 116 */ 31 enum { 117 enum { 32 READA_NONE, !! 118 /* Global indicator of serious filesystem errors */ 33 READA_BACK, !! 119 BTRFS_FS_STATE_ERROR, 34 READA_FORWARD, << 35 /* 120 /* 36 * Similar to READA_FORWARD but unlike !! 121 * Filesystem is being remounted, allow to skip some operations, like 37 * !! 122 * defrag 38 * 1) It will trigger readahead even f << 39 * each other on disk; << 40 * 2) It also triggers readahead for n << 41 * 3) During a search, even when a nod << 42 * will still trigger readahead for << 43 * it. << 44 * << 45 * This is meant to be used only when << 46 * entire tree or a very large part of << 47 */ 123 */ 48 READA_FORWARD_ALWAYS, !! 124 BTRFS_FS_STATE_REMOUNTING, >> 125 /* Track if a transaction abort has been reported on this filesystem */ >> 126 BTRFS_FS_STATE_TRANS_ABORTED, >> 127 /* >> 128 * Bio operations should be blocked on this filesystem because a source >> 129 * or target device is being destroyed as part of a device replace >> 130 */ >> 131 BTRFS_FS_STATE_DEV_REPLACING, >> 132 /* The btrfs_fs_info created for self-tests */ >> 133 BTRFS_FS_STATE_DUMMY_FS_INFO, 49 }; 134 }; 50 135 >> 136 #define BTRFS_BACKREF_REV_MAX 256 >> 137 #define BTRFS_BACKREF_REV_SHIFT 56 >> 138 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ >> 139 BTRFS_BACKREF_REV_SHIFT) >> 140 >> 141 #define BTRFS_OLD_BACKREF_REV 0 >> 142 #define BTRFS_MIXED_BACKREF_REV 1 >> 143 >> 144 /* >> 145 * every tree block (leaf or node) starts with this header. >> 146 */ >> 147 struct btrfs_header { >> 148 /* these first four must match the super block */ >> 149 u8 csum[BTRFS_CSUM_SIZE]; >> 150 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ >> 151 __le64 bytenr; /* which block this node is supposed to live in */ >> 152 __le64 flags; >> 153 >> 154 /* allowed to be different from the super from here on down */ >> 155 u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; >> 156 __le64 generation; >> 157 __le64 owner; >> 158 __le32 nritems; >> 159 u8 level; >> 160 } __attribute__ ((__packed__)); >> 161 >> 162 /* >> 163 * this is a very generous portion of the super block, giving us >> 164 * room to translate 14 chunks with 3 stripes each. >> 165 */ >> 166 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 >> 167 >> 168 /* >> 169 * just in case we somehow lose the roots and are not able to mount, >> 170 * we store an array of the roots from previous transactions >> 171 * in the super. >> 172 */ >> 173 #define BTRFS_NUM_BACKUP_ROOTS 4 >> 174 struct btrfs_root_backup { >> 175 __le64 tree_root; >> 176 __le64 tree_root_gen; >> 177 >> 178 __le64 chunk_root; >> 179 __le64 chunk_root_gen; >> 180 >> 181 __le64 extent_root; >> 182 __le64 extent_root_gen; >> 183 >> 184 __le64 fs_root; >> 185 __le64 fs_root_gen; >> 186 >> 187 __le64 dev_root; >> 188 __le64 dev_root_gen; >> 189 >> 190 __le64 csum_root; >> 191 __le64 csum_root_gen; >> 192 >> 193 __le64 total_bytes; >> 194 __le64 bytes_used; >> 195 __le64 num_devices; >> 196 /* future */ >> 197 __le64 unused_64[4]; >> 198 >> 199 u8 tree_root_level; >> 200 u8 chunk_root_level; >> 201 u8 extent_root_level; >> 202 u8 fs_root_level; >> 203 u8 dev_root_level; >> 204 u8 csum_root_level; >> 205 /* future and to align */ >> 206 u8 unused_8[10]; >> 207 } __attribute__ ((__packed__)); >> 208 >> 209 /* >> 210 * the super block basically lists the main trees of the FS >> 211 * it currently lacks any block count etc etc >> 212 */ >> 213 struct btrfs_super_block { >> 214 /* the first 4 fields must match struct btrfs_header */ >> 215 u8 csum[BTRFS_CSUM_SIZE]; >> 216 /* FS specific UUID, visible to user */ >> 217 u8 fsid[BTRFS_FSID_SIZE]; >> 218 __le64 bytenr; /* this block number */ >> 219 __le64 flags; >> 220 >> 221 /* allowed to be different from the btrfs_header from here own down */ >> 222 __le64 magic; >> 223 __le64 generation; >> 224 __le64 root; >> 225 __le64 chunk_root; >> 226 __le64 log_root; >> 227 >> 228 /* this will help find the new super based on the log root */ >> 229 __le64 log_root_transid; >> 230 __le64 total_bytes; >> 231 __le64 bytes_used; >> 232 __le64 root_dir_objectid; >> 233 __le64 num_devices; >> 234 __le32 sectorsize; >> 235 __le32 nodesize; >> 236 __le32 __unused_leafsize; >> 237 __le32 stripesize; >> 238 __le32 sys_chunk_array_size; >> 239 __le64 chunk_root_generation; >> 240 __le64 compat_flags; >> 241 __le64 compat_ro_flags; >> 242 __le64 incompat_flags; >> 243 __le16 csum_type; >> 244 u8 root_level; >> 245 u8 chunk_root_level; >> 246 u8 log_root_level; >> 247 struct btrfs_dev_item dev_item; >> 248 >> 249 char label[BTRFS_LABEL_SIZE]; >> 250 >> 251 __le64 cache_generation; >> 252 __le64 uuid_tree_generation; >> 253 >> 254 /* the UUID written into btree blocks */ >> 255 u8 metadata_uuid[BTRFS_FSID_SIZE]; >> 256 >> 257 /* future expansion */ >> 258 __le64 reserved[28]; >> 259 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; >> 260 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS]; >> 261 } __attribute__ ((__packed__)); >> 262 >> 263 /* >> 264 * Compat flags that we support. If any incompat flags are set other than the >> 265 * ones specified below then we will fail to mount >> 266 */ >> 267 #define BTRFS_FEATURE_COMPAT_SUPP 0ULL >> 268 #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL >> 269 #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL >> 270 >> 271 #define BTRFS_FEATURE_COMPAT_RO_SUPP \ >> 272 (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \ >> 273 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID) >> 274 >> 275 #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL >> 276 #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL >> 277 >> 278 #define BTRFS_FEATURE_INCOMPAT_SUPP \ >> 279 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ >> 280 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \ >> 281 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \ >> 282 BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \ >> 283 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \ >> 284 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \ >> 285 BTRFS_FEATURE_INCOMPAT_RAID56 | \ >> 286 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \ >> 287 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \ >> 288 BTRFS_FEATURE_INCOMPAT_NO_HOLES | \ >> 289 BTRFS_FEATURE_INCOMPAT_METADATA_UUID) >> 290 >> 291 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \ >> 292 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF) >> 293 #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL >> 294 >> 295 /* >> 296 * A leaf is full of items. offset and size tell us where to find >> 297 * the item in the leaf (relative to the start of the data area) >> 298 */ >> 299 struct btrfs_item { >> 300 struct btrfs_disk_key key; >> 301 __le32 offset; >> 302 __le32 size; >> 303 } __attribute__ ((__packed__)); >> 304 >> 305 /* >> 306 * leaves have an item area and a data area: >> 307 * [item0, item1....itemN] [free space] [dataN...data1, data0] >> 308 * >> 309 * The data is separate from the items to get the keys closer together >> 310 * during searches. >> 311 */ >> 312 struct btrfs_leaf { >> 313 struct btrfs_header header; >> 314 struct btrfs_item items[]; >> 315 } __attribute__ ((__packed__)); >> 316 >> 317 /* >> 318 * all non-leaf blocks are nodes, they hold only keys and pointers to >> 319 * other blocks >> 320 */ >> 321 struct btrfs_key_ptr { >> 322 struct btrfs_disk_key key; >> 323 __le64 blockptr; >> 324 __le64 generation; >> 325 } __attribute__ ((__packed__)); >> 326 >> 327 struct btrfs_node { >> 328 struct btrfs_header header; >> 329 struct btrfs_key_ptr ptrs[]; >> 330 } __attribute__ ((__packed__)); >> 331 51 /* 332 /* 52 * btrfs_paths remember the path taken from th 333 * btrfs_paths remember the path taken from the root down to the leaf. 53 * level 0 is always the leaf, and nodes[1...B 334 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point 54 * to any other levels that are present. 335 * to any other levels that are present. 55 * 336 * 56 * The slots array records the index of the it 337 * The slots array records the index of the item or block pointer 57 * used while walking the tree. 338 * used while walking the tree. 58 */ 339 */ >> 340 enum { READA_NONE, READA_BACK, READA_FORWARD }; 59 struct btrfs_path { 341 struct btrfs_path { 60 struct extent_buffer *nodes[BTRFS_MAX_ 342 struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; 61 int slots[BTRFS_MAX_LEVEL]; 343 int slots[BTRFS_MAX_LEVEL]; 62 /* if there is real range locking, thi 344 /* if there is real range locking, this locks field will change */ 63 u8 locks[BTRFS_MAX_LEVEL]; 345 u8 locks[BTRFS_MAX_LEVEL]; 64 u8 reada; 346 u8 reada; 65 /* keep some upper locks as we walk do 347 /* keep some upper locks as we walk down */ 66 u8 lowest_level; 348 u8 lowest_level; 67 349 68 /* 350 /* 69 * set by btrfs_split_item, tells sear 351 * set by btrfs_split_item, tells search_slot to keep all locks 70 * and to force calls to keep space in 352 * and to force calls to keep space in the nodes 71 */ 353 */ 72 unsigned int search_for_split:1; 354 unsigned int search_for_split:1; 73 unsigned int keep_locks:1; 355 unsigned int keep_locks:1; 74 unsigned int skip_locking:1; 356 unsigned int skip_locking:1; >> 357 unsigned int leave_spinning:1; 75 unsigned int search_commit_root:1; 358 unsigned int search_commit_root:1; 76 unsigned int need_commit_sem:1; 359 unsigned int need_commit_sem:1; 77 unsigned int skip_release_on_error:1; 360 unsigned int skip_release_on_error:1; >> 361 }; >> 362 #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \ >> 363 sizeof(struct btrfs_item)) >> 364 struct btrfs_dev_replace { >> 365 u64 replace_state; /* see #define above */ >> 366 time64_t time_started; /* seconds since 1-Jan-1970 */ >> 367 time64_t time_stopped; /* seconds since 1-Jan-1970 */ >> 368 atomic64_t num_write_errors; >> 369 atomic64_t num_uncorrectable_read_errors; >> 370 >> 371 u64 cursor_left; >> 372 u64 committed_cursor_left; >> 373 u64 cursor_left_last_write_of_item; >> 374 u64 cursor_right; >> 375 >> 376 u64 cont_reading_from_srcdev_mode; /* see #define above */ >> 377 >> 378 int is_valid; >> 379 int item_needs_writeback; >> 380 struct btrfs_device *srcdev; >> 381 struct btrfs_device *tgtdev; >> 382 >> 383 struct mutex lock_finishing_cancel_unmount; >> 384 struct rw_semaphore rwsem; >> 385 >> 386 struct btrfs_scrub_progress scrub_progress; >> 387 >> 388 struct percpu_counter bio_counter; >> 389 wait_queue_head_t replace_wait; >> 390 }; >> 391 >> 392 /* For raid type sysfs entries */ >> 393 struct raid_kobject { >> 394 u64 flags; >> 395 struct kobject kobj; >> 396 struct list_head list; >> 397 }; >> 398 >> 399 struct btrfs_space_info { >> 400 spinlock_t lock; >> 401 >> 402 u64 total_bytes; /* total bytes in the space, >> 403 this doesn't take mirrors into account */ >> 404 u64 bytes_used; /* total bytes used, >> 405 this doesn't take mirrors into account */ >> 406 u64 bytes_pinned; /* total bytes pinned, will be freed when the >> 407 transaction finishes */ >> 408 u64 bytes_reserved; /* total bytes the allocator has reserved for >> 409 current allocations */ >> 410 u64 bytes_may_use; /* number of bytes that may be used for >> 411 delalloc/allocations */ >> 412 u64 bytes_readonly; /* total bytes that are read only */ >> 413 >> 414 u64 max_extent_size; /* This will hold the maximum extent size of >> 415 the space info if we had an ENOSPC in the >> 416 allocator. */ >> 417 >> 418 unsigned int full:1; /* indicates that we cannot allocate any more >> 419 chunks for this space */ >> 420 unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ >> 421 >> 422 unsigned int flush:1; /* set if we are trying to make space */ >> 423 >> 424 unsigned int force_alloc; /* set if we need to force a chunk >> 425 alloc for this space */ >> 426 >> 427 u64 disk_used; /* total bytes used on disk */ >> 428 u64 disk_total; /* total bytes on disk, takes mirrors into >> 429 account */ >> 430 >> 431 u64 flags; >> 432 >> 433 /* >> 434 * bytes_pinned is kept in line with what is actually pinned, as in >> 435 * we've called update_block_group and dropped the bytes_used counter >> 436 * and increased the bytes_pinned counter. However this means that >> 437 * bytes_pinned does not reflect the bytes that will be pinned once the >> 438 * delayed refs are flushed, so this counter is inc'ed every time we >> 439 * call btrfs_free_extent so it is a realtime count of what will be >> 440 * freed once the transaction is committed. It will be zeroed every >> 441 * time the transaction commits. >> 442 */ >> 443 struct percpu_counter total_bytes_pinned; >> 444 >> 445 struct list_head list; >> 446 /* Protected by the spinlock 'lock'. */ >> 447 struct list_head ro_bgs; >> 448 struct list_head priority_tickets; >> 449 struct list_head tickets; >> 450 /* >> 451 * tickets_id just indicates the next ticket will be handled, so note >> 452 * it's not stored per ticket. >> 453 */ >> 454 u64 tickets_id; >> 455 >> 456 struct rw_semaphore groups_sem; >> 457 /* for block groups in our same type */ >> 458 struct list_head block_groups[BTRFS_NR_RAID_TYPES]; >> 459 wait_queue_head_t wait; >> 460 >> 461 struct kobject kobj; >> 462 struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES]; >> 463 }; >> 464 >> 465 /* >> 466 * Types of block reserves >> 467 */ >> 468 enum { >> 469 BTRFS_BLOCK_RSV_GLOBAL, >> 470 BTRFS_BLOCK_RSV_DELALLOC, >> 471 BTRFS_BLOCK_RSV_TRANS, >> 472 BTRFS_BLOCK_RSV_CHUNK, >> 473 BTRFS_BLOCK_RSV_DELOPS, >> 474 BTRFS_BLOCK_RSV_DELREFS, >> 475 BTRFS_BLOCK_RSV_EMPTY, >> 476 BTRFS_BLOCK_RSV_TEMP, >> 477 }; >> 478 >> 479 struct btrfs_block_rsv { >> 480 u64 size; >> 481 u64 reserved; >> 482 struct btrfs_space_info *space_info; >> 483 spinlock_t lock; >> 484 unsigned short full; >> 485 unsigned short type; >> 486 unsigned short failfast; >> 487 >> 488 /* >> 489 * Qgroup equivalent for @size @reserved >> 490 * >> 491 * Unlike normal @size/@reserved for inode rsv, qgroup doesn't care >> 492 * about things like csum size nor how many tree blocks it will need to >> 493 * reserve. >> 494 * >> 495 * Qgroup cares more about net change of the extent usage. >> 496 * >> 497 * So for one newly inserted file extent, in worst case it will cause >> 498 * leaf split and level increase, nodesize for each file extent is >> 499 * already too much. >> 500 * >> 501 * In short, qgroup_size/reserved is the upper limit of possible needed >> 502 * qgroup metadata reservation. >> 503 */ >> 504 u64 qgroup_rsv_size; >> 505 u64 qgroup_rsv_reserved; >> 506 }; >> 507 >> 508 /* >> 509 * free clusters are used to claim free space in relatively large chunks, >> 510 * allowing us to do less seeky writes. They are used for all metadata >> 511 * allocations. In ssd_spread mode they are also used for data allocations. >> 512 */ >> 513 struct btrfs_free_cluster { >> 514 spinlock_t lock; >> 515 spinlock_t refill_lock; >> 516 struct rb_root root; >> 517 >> 518 /* largest extent in this cluster */ >> 519 u64 max_size; >> 520 >> 521 /* first extent starting offset */ >> 522 u64 window_start; >> 523 >> 524 /* We did a full search and couldn't create a cluster */ >> 525 bool fragmented; >> 526 >> 527 struct btrfs_block_group_cache *block_group; 78 /* 528 /* 79 * Indicate that new item (btrfs_searc !! 529 * when a cluster is allocated from a block group, we put the 80 * existing item and ins_len contains !! 530 * cluster onto a list in the block group so that it can 81 * header (ie. sizeof(struct btrfs_ite !! 531 * be freed before the block group is freed. 82 */ 532 */ 83 unsigned int search_for_extension:1; !! 533 struct list_head block_group_list; 84 /* Stop search if any locks need to be << 85 unsigned int nowait:1; << 86 }; 534 }; 87 535 88 #define BTRFS_PATH_AUTO_FREE(path_name) !! 536 enum btrfs_caching_type { 89 struct btrfs_path *path_name __free(bt !! 537 BTRFS_CACHE_NO, >> 538 BTRFS_CACHE_STARTED, >> 539 BTRFS_CACHE_FAST, >> 540 BTRFS_CACHE_FINISHED, >> 541 BTRFS_CACHE_ERROR, >> 542 }; >> 543 >> 544 enum btrfs_disk_cache_state { >> 545 BTRFS_DC_WRITTEN, >> 546 BTRFS_DC_ERROR, >> 547 BTRFS_DC_CLEAR, >> 548 BTRFS_DC_SETUP, >> 549 }; >> 550 >> 551 struct btrfs_caching_control { >> 552 struct list_head list; >> 553 struct mutex mutex; >> 554 wait_queue_head_t wait; >> 555 struct btrfs_work work; >> 556 struct btrfs_block_group_cache *block_group; >> 557 u64 progress; >> 558 refcount_t count; >> 559 }; >> 560 >> 561 /* Once caching_thread() finds this much free space, it will wake up waiters. */ >> 562 #define CACHING_CTL_WAKE_UP SZ_2M >> 563 >> 564 struct btrfs_io_ctl { >> 565 void *cur, *orig; >> 566 struct page *page; >> 567 struct page **pages; >> 568 struct btrfs_fs_info *fs_info; >> 569 struct inode *inode; >> 570 unsigned long size; >> 571 int index; >> 572 int num_pages; >> 573 int entries; >> 574 int bitmaps; >> 575 unsigned check_crcs:1; >> 576 }; 90 577 91 /* 578 /* 92 * The state of btrfs root !! 579 * Tree to record all locked full stripes of a RAID5/6 block group >> 580 */ >> 581 struct btrfs_full_stripe_locks_tree { >> 582 struct rb_root root; >> 583 struct mutex lock; >> 584 }; >> 585 >> 586 struct btrfs_block_group_cache { >> 587 struct btrfs_key key; >> 588 struct btrfs_block_group_item item; >> 589 struct btrfs_fs_info *fs_info; >> 590 struct inode *inode; >> 591 spinlock_t lock; >> 592 u64 pinned; >> 593 u64 reserved; >> 594 u64 delalloc_bytes; >> 595 u64 bytes_super; >> 596 u64 flags; >> 597 u64 cache_generation; >> 598 >> 599 /* >> 600 * If the free space extent count exceeds this number, convert the block >> 601 * group to bitmaps. >> 602 */ >> 603 u32 bitmap_high_thresh; >> 604 >> 605 /* >> 606 * If the free space extent count drops below this number, convert the >> 607 * block group back to extents. >> 608 */ >> 609 u32 bitmap_low_thresh; >> 610 >> 611 /* >> 612 * It is just used for the delayed data space allocation because >> 613 * only the data space allocation and the relative metadata update >> 614 * can be done cross the transaction. >> 615 */ >> 616 struct rw_semaphore data_rwsem; >> 617 >> 618 /* for raid56, this is a full stripe, without parity */ >> 619 unsigned long full_stripe_len; >> 620 >> 621 unsigned int ro; >> 622 unsigned int iref:1; >> 623 unsigned int has_caching_ctl:1; >> 624 unsigned int removed:1; >> 625 >> 626 int disk_cache_state; >> 627 >> 628 /* cache tracking stuff */ >> 629 int cached; >> 630 struct btrfs_caching_control *caching_ctl; >> 631 u64 last_byte_to_unpin; >> 632 >> 633 struct btrfs_space_info *space_info; >> 634 >> 635 /* free space cache stuff */ >> 636 struct btrfs_free_space_ctl *free_space_ctl; >> 637 >> 638 /* block group cache stuff */ >> 639 struct rb_node cache_node; >> 640 >> 641 /* for block groups in the same raid type */ >> 642 struct list_head list; >> 643 >> 644 /* usage count */ >> 645 atomic_t count; >> 646 >> 647 /* List of struct btrfs_free_clusters for this block group. >> 648 * Today it will only have one thing on it, but that may change >> 649 */ >> 650 struct list_head cluster_list; >> 651 >> 652 /* For delayed block group creation or deletion of empty block groups */ >> 653 struct list_head bg_list; >> 654 >> 655 /* For read-only block groups */ >> 656 struct list_head ro_list; >> 657 >> 658 atomic_t trimming; >> 659 >> 660 /* For dirty block groups */ >> 661 struct list_head dirty_list; >> 662 struct list_head io_list; >> 663 >> 664 struct btrfs_io_ctl io_ctl; >> 665 >> 666 /* >> 667 * Incremented when doing extent allocations and holding a read lock >> 668 * on the space_info's groups_sem semaphore. >> 669 * Decremented when an ordered extent that represents an IO against this >> 670 * block group's range is created (after it's added to its inode's >> 671 * root's list of ordered extents) or immediately after the allocation >> 672 * if it's a metadata extent or fallocate extent (for these cases we >> 673 * don't create ordered extents). >> 674 */ >> 675 atomic_t reservations; >> 676 >> 677 /* >> 678 * Incremented while holding the spinlock *lock* by a task checking if >> 679 * it can perform a nocow write (incremented if the value for the *ro* >> 680 * field is 0). Decremented by such tasks once they create an ordered >> 681 * extent or before that if some error happens before reaching that step. >> 682 * This is to prevent races between block group relocation and nocow >> 683 * writes through direct IO. >> 684 */ >> 685 atomic_t nocow_writers; >> 686 >> 687 /* Lock for free space tree operations. */ >> 688 struct mutex free_space_lock; >> 689 >> 690 /* >> 691 * Does the block group need to be added to the free space tree? >> 692 * Protected by free_space_lock. >> 693 */ >> 694 int needs_free_space; >> 695 >> 696 /* Record locked full stripes for RAID5/6 block group */ >> 697 struct btrfs_full_stripe_locks_tree full_stripe_locks_root; >> 698 }; >> 699 >> 700 /* delayed seq elem */ >> 701 struct seq_list { >> 702 struct list_head list; >> 703 u64 seq; >> 704 }; >> 705 >> 706 #define SEQ_LIST_INIT(name) { .list = LIST_HEAD_INIT((name).list), .seq = 0 } >> 707 >> 708 #define SEQ_LAST ((u64)-1) >> 709 >> 710 enum btrfs_orphan_cleanup_state { >> 711 ORPHAN_CLEANUP_STARTED = 1, >> 712 ORPHAN_CLEANUP_DONE = 2, >> 713 }; >> 714 >> 715 /* used by the raid56 code to lock stripes for read/modify/write */ >> 716 struct btrfs_stripe_hash { >> 717 struct list_head hash_list; >> 718 spinlock_t lock; >> 719 }; >> 720 >> 721 /* used by the raid56 code to lock stripes for read/modify/write */ >> 722 struct btrfs_stripe_hash_table { >> 723 struct list_head stripe_cache; >> 724 spinlock_t cache_lock; >> 725 int cache_size; >> 726 struct btrfs_stripe_hash table[]; >> 727 }; >> 728 >> 729 #define BTRFS_STRIPE_HASH_TABLE_BITS 11 >> 730 >> 731 void btrfs_init_async_reclaim_work(struct work_struct *work); >> 732 >> 733 /* fs_info */ >> 734 struct reloc_control; >> 735 struct btrfs_device; >> 736 struct btrfs_fs_devices; >> 737 struct btrfs_balance_control; >> 738 struct btrfs_delayed_root; >> 739 >> 740 /* >> 741 * Block group or device which contains an active swapfile. Used for preventing >> 742 * unsafe operations while a swapfile is active. >> 743 * >> 744 * These are sorted on (ptr, inode) (note that a block group or device can >> 745 * contain more than one swapfile). We compare the pointer values because we >> 746 * don't actually care what the object is, we just need a quick check whether >> 747 * the object exists in the rbtree. 93 */ 748 */ >> 749 struct btrfs_swapfile_pin { >> 750 struct rb_node node; >> 751 void *ptr; >> 752 struct inode *inode; >> 753 /* >> 754 * If true, ptr points to a struct btrfs_block_group_cache. Otherwise, >> 755 * ptr points to a struct btrfs_device. >> 756 */ >> 757 bool is_block_group; >> 758 }; >> 759 >> 760 bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr); >> 761 94 enum { 762 enum { >> 763 BTRFS_FS_BARRIER, >> 764 BTRFS_FS_CLOSING_START, >> 765 BTRFS_FS_CLOSING_DONE, >> 766 BTRFS_FS_LOG_RECOVERING, >> 767 BTRFS_FS_OPEN, >> 768 BTRFS_FS_QUOTA_ENABLED, >> 769 BTRFS_FS_UPDATE_UUID_TREE_GEN, >> 770 BTRFS_FS_CREATING_FREE_SPACE_TREE, >> 771 BTRFS_FS_BTREE_ERR, >> 772 BTRFS_FS_LOG1_ERR, >> 773 BTRFS_FS_LOG2_ERR, >> 774 BTRFS_FS_QUOTA_OVERRIDE, >> 775 /* Used to record internally whether fs has been frozen */ >> 776 BTRFS_FS_FROZEN, >> 777 /* >> 778 * Indicate that a whole-filesystem exclusive operation is running >> 779 * (device replace, resize, device add/delete, balance) >> 780 */ >> 781 BTRFS_FS_EXCL_OP, >> 782 /* >> 783 * To info transaction_kthread we need an immediate commit so it >> 784 * doesn't need to wait for commit_interval >> 785 */ >> 786 BTRFS_FS_NEED_ASYNC_COMMIT, 95 /* 787 /* 96 * btrfs_record_root_in_trans is a mul !! 788 * Indicate that balance has been set up from the ioctl and is in the 97 * with the balancing code. But the !! 789 * main phase. The fs_info::balance_ctl is initialized. 98 * first time the root is added to eac << 99 * is used to tell us when more checks << 100 */ 790 */ 101 BTRFS_ROOT_IN_TRANS_SETUP, !! 791 BTRFS_FS_BALANCE_RUNNING, >> 792 >> 793 /* Indicate that the cleaner thread is awake and doing something. */ >> 794 BTRFS_FS_CLEANER_RUNNING, >> 795 }; >> 796 >> 797 struct btrfs_fs_info { >> 798 u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; >> 799 unsigned long flags; >> 800 struct btrfs_root *extent_root; >> 801 struct btrfs_root *tree_root; >> 802 struct btrfs_root *chunk_root; >> 803 struct btrfs_root *dev_root; >> 804 struct btrfs_root *fs_root; >> 805 struct btrfs_root *csum_root; >> 806 struct btrfs_root *quota_root; >> 807 struct btrfs_root *uuid_root; >> 808 struct btrfs_root *free_space_root; >> 809 >> 810 /* the log root tree is a directory of all the other log roots */ >> 811 struct btrfs_root *log_root_tree; >> 812 >> 813 spinlock_t fs_roots_radix_lock; >> 814 struct radix_tree_root fs_roots_radix; >> 815 >> 816 /* block group cache stuff */ >> 817 spinlock_t block_group_cache_lock; >> 818 u64 first_logical_byte; >> 819 struct rb_root block_group_cache_tree; >> 820 >> 821 /* keep track of unallocated space */ >> 822 atomic64_t free_chunk_space; >> 823 >> 824 struct extent_io_tree freed_extents[2]; >> 825 struct extent_io_tree *pinned_extents; >> 826 >> 827 /* logical->physical extent mapping */ >> 828 struct btrfs_mapping_tree mapping_tree; >> 829 >> 830 /* >> 831 * block reservation for extent, checksum, root tree and >> 832 * delayed dir index item >> 833 */ >> 834 struct btrfs_block_rsv global_block_rsv; >> 835 /* block reservation for metadata operations */ >> 836 struct btrfs_block_rsv trans_block_rsv; >> 837 /* block reservation for chunk tree */ >> 838 struct btrfs_block_rsv chunk_block_rsv; >> 839 /* block reservation for delayed operations */ >> 840 struct btrfs_block_rsv delayed_block_rsv; >> 841 /* block reservation for delayed refs */ >> 842 struct btrfs_block_rsv delayed_refs_rsv; >> 843 >> 844 struct btrfs_block_rsv empty_block_rsv; >> 845 >> 846 u64 generation; >> 847 u64 last_trans_committed; >> 848 u64 avg_delayed_ref_runtime; >> 849 >> 850 /* >> 851 * this is updated to the current trans every time a full commit >> 852 * is required instead of the faster short fsync log commits >> 853 */ >> 854 u64 last_trans_log_full_commit; >> 855 unsigned long mount_opt; >> 856 /* >> 857 * Track requests for actions that need to be done during transaction >> 858 * commit (like for some mount options). >> 859 */ >> 860 unsigned long pending_changes; >> 861 unsigned long compress_type:4; >> 862 unsigned int compress_level; >> 863 u32 commit_interval; >> 864 /* >> 865 * It is a suggestive number, the read side is safe even it gets a >> 866 * wrong number because we will write out the data into a regular >> 867 * extent. The write side(mount/remount) is under ->s_umount lock, >> 868 * so it is also safe. >> 869 */ >> 870 u64 max_inline; >> 871 >> 872 struct btrfs_transaction *running_transaction; >> 873 wait_queue_head_t transaction_throttle; >> 874 wait_queue_head_t transaction_wait; >> 875 wait_queue_head_t transaction_blocked_wait; >> 876 wait_queue_head_t async_submit_wait; 102 877 103 /* 878 /* 104 * Set if tree blocks of this root can !! 879 * Used to protect the incompat_flags, compat_flags, compat_ro_flags 105 * Only subvolume trees and their relo !! 880 * when they are updated. 106 * Conflicts with TRACK_DIRTY bit. << 107 * 881 * 108 * This affects two things: !! 882 * Because we do not clear the flags for ever, so we needn't use >> 883 * the lock on the read side. 109 * 884 * 110 * - How balance works !! 885 * We also needn't use the lock when we mount the fs, because 111 * For shareable roots, we need to u !! 886 * there is no other task which will update the flag. 112 * replacement for balance, and need !! 887 */ 113 * snapshot creation to handle them. !! 888 spinlock_t super_lock; >> 889 struct btrfs_super_block *super_copy; >> 890 struct btrfs_super_block *super_for_commit; >> 891 struct super_block *sb; >> 892 struct inode *btree_inode; >> 893 struct mutex tree_log_mutex; >> 894 struct mutex transaction_kthread_mutex; >> 895 struct mutex cleaner_mutex; >> 896 struct mutex chunk_mutex; >> 897 >> 898 /* >> 899 * this is taken to make sure we don't set block groups ro after >> 900 * the free space cache has been allocated on them >> 901 */ >> 902 struct mutex ro_block_group_mutex; >> 903 >> 904 /* this is used during read/modify/write to make sure >> 905 * no two ios are trying to mod the same stripe at the same >> 906 * time >> 907 */ >> 908 struct btrfs_stripe_hash_table *stripe_hash_table; >> 909 >> 910 /* >> 911 * this protects the ordered operations list only while we are >> 912 * processing all of the entries on it. This way we make >> 913 * sure the commit code doesn't find the list temporarily empty >> 914 * because another function happens to be doing non-waiting preflush >> 915 * before jumping into the main commit. >> 916 */ >> 917 struct mutex ordered_operations_mutex; >> 918 >> 919 struct rw_semaphore commit_root_sem; >> 920 >> 921 struct rw_semaphore cleanup_work_sem; >> 922 >> 923 struct rw_semaphore subvol_sem; >> 924 struct srcu_struct subvol_srcu; >> 925 >> 926 spinlock_t trans_lock; >> 927 /* >> 928 * the reloc mutex goes with the trans lock, it is taken >> 929 * during commit to protect us from the relocation code >> 930 */ >> 931 struct mutex reloc_mutex; >> 932 >> 933 struct list_head trans_list; >> 934 struct list_head dead_roots; >> 935 struct list_head caching_block_groups; >> 936 >> 937 spinlock_t delayed_iput_lock; >> 938 struct list_head delayed_iputs; >> 939 atomic_t nr_delayed_iputs; >> 940 wait_queue_head_t delayed_iputs_wait; >> 941 >> 942 /* this protects tree_mod_seq_list */ >> 943 spinlock_t tree_mod_seq_lock; >> 944 atomic64_t tree_mod_seq; >> 945 struct list_head tree_mod_seq_list; >> 946 >> 947 /* this protects tree_mod_log */ >> 948 rwlock_t tree_mod_log_lock; >> 949 struct rb_root tree_mod_log; >> 950 >> 951 atomic_t async_delalloc_pages; >> 952 >> 953 /* >> 954 * this is used to protect the following list -- ordered_roots. >> 955 */ >> 956 spinlock_t ordered_root_lock; >> 957 >> 958 /* >> 959 * all fs/file tree roots in which there are data=ordered extents >> 960 * pending writeback are added into this list. 114 * 961 * 115 * While for non-shareable trees, we !! 962 * these can span multiple transactions and basically include 116 * with COW. !! 963 * every dirty data page that isn't from nodatacow >> 964 */ >> 965 struct list_head ordered_roots; >> 966 >> 967 struct mutex delalloc_root_mutex; >> 968 spinlock_t delalloc_root_lock; >> 969 /* all fs/file tree roots that have delalloc inodes. */ >> 970 struct list_head delalloc_roots; >> 971 >> 972 /* >> 973 * there is a pool of worker threads for checksumming during writes >> 974 * and a pool for checksumming after reads. This is because readers >> 975 * can run with FS locks held, and the writers may be waiting for >> 976 * those locks. We don't want ordering in the pending list to cause >> 977 * deadlocks, and so the two are serviced separately. 117 * 978 * 118 * - How dirty roots are tracked !! 979 * A third pool does submit_bio to avoid deadlocking with the other 119 * For shareable roots, btrfs_record !! 980 * two 120 * track them, while non-subvolume r << 121 * don't need to set this manually. << 122 */ 981 */ 123 BTRFS_ROOT_SHAREABLE, !! 982 struct btrfs_workqueue *workers; >> 983 struct btrfs_workqueue *delalloc_workers; >> 984 struct btrfs_workqueue *flush_workers; >> 985 struct btrfs_workqueue *endio_workers; >> 986 struct btrfs_workqueue *endio_meta_workers; >> 987 struct btrfs_workqueue *endio_raid56_workers; >> 988 struct btrfs_workqueue *endio_repair_workers; >> 989 struct btrfs_workqueue *rmw_workers; >> 990 struct btrfs_workqueue *endio_meta_write_workers; >> 991 struct btrfs_workqueue *endio_write_workers; >> 992 struct btrfs_workqueue *endio_freespace_worker; >> 993 struct btrfs_workqueue *submit_workers; >> 994 struct btrfs_workqueue *caching_workers; >> 995 struct btrfs_workqueue *readahead_workers; >> 996 >> 997 /* >> 998 * fixup workers take dirty pages that didn't properly go through >> 999 * the cow mechanism and make them safe to write. It happens >> 1000 * for the sys_munmap function call path >> 1001 */ >> 1002 struct btrfs_workqueue *fixup_workers; >> 1003 struct btrfs_workqueue *delayed_workers; >> 1004 >> 1005 /* the extent workers do delayed refs on the extent allocation tree */ >> 1006 struct btrfs_workqueue *extent_workers; >> 1007 struct task_struct *transaction_kthread; >> 1008 struct task_struct *cleaner_kthread; >> 1009 u32 thread_pool_size; >> 1010 >> 1011 struct kobject *space_info_kobj; >> 1012 struct list_head pending_raid_kobjs; >> 1013 spinlock_t pending_raid_kobjs_lock; /* uncontended */ >> 1014 >> 1015 u64 total_pinned; >> 1016 >> 1017 /* used to keep from writing metadata until there is a nice batch */ >> 1018 struct percpu_counter dirty_metadata_bytes; >> 1019 struct percpu_counter delalloc_bytes; >> 1020 struct percpu_counter dio_bytes; >> 1021 s32 dirty_metadata_batch; >> 1022 s32 delalloc_batch; >> 1023 >> 1024 struct list_head dirty_cowonly_roots; >> 1025 >> 1026 struct btrfs_fs_devices *fs_devices; >> 1027 >> 1028 /* >> 1029 * The space_info list is effectively read only after initial >> 1030 * setup. It is populated at mount time and cleaned up after >> 1031 * all block groups are removed. RCU is used to protect it. >> 1032 */ >> 1033 struct list_head space_info; >> 1034 >> 1035 struct btrfs_space_info *data_sinfo; >> 1036 >> 1037 struct reloc_control *reloc_ctl; >> 1038 >> 1039 /* data_alloc_cluster is only used in ssd_spread mode */ >> 1040 struct btrfs_free_cluster data_alloc_cluster; >> 1041 >> 1042 /* all metadata allocations go through this cluster */ >> 1043 struct btrfs_free_cluster meta_alloc_cluster; >> 1044 >> 1045 /* auto defrag inodes go here */ >> 1046 spinlock_t defrag_inodes_lock; >> 1047 struct rb_root defrag_inodes; >> 1048 atomic_t defrag_running; >> 1049 >> 1050 /* Used to protect avail_{data, metadata, system}_alloc_bits */ >> 1051 seqlock_t profiles_lock; >> 1052 /* >> 1053 * these three are in extended format (availability of single >> 1054 * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other >> 1055 * types are denoted by corresponding BTRFS_BLOCK_GROUP_* bits) >> 1056 */ >> 1057 u64 avail_data_alloc_bits; >> 1058 u64 avail_metadata_alloc_bits; >> 1059 u64 avail_system_alloc_bits; >> 1060 >> 1061 /* restriper state */ >> 1062 spinlock_t balance_lock; >> 1063 struct mutex balance_mutex; >> 1064 atomic_t balance_pause_req; >> 1065 atomic_t balance_cancel_req; >> 1066 struct btrfs_balance_control *balance_ctl; >> 1067 wait_queue_head_t balance_wait_q; >> 1068 >> 1069 u32 data_chunk_allocations; >> 1070 u32 metadata_ratio; >> 1071 >> 1072 void *bdev_holder; >> 1073 >> 1074 /* private scrub information */ >> 1075 struct mutex scrub_lock; >> 1076 atomic_t scrubs_running; >> 1077 atomic_t scrub_pause_req; >> 1078 atomic_t scrubs_paused; >> 1079 atomic_t scrub_cancel_req; >> 1080 wait_queue_head_t scrub_pause_wait; >> 1081 /* >> 1082 * The worker pointers are NULL iff the refcount is 0, ie. scrub is not >> 1083 * running. >> 1084 */ >> 1085 refcount_t scrub_workers_refcnt; >> 1086 struct btrfs_workqueue *scrub_workers; >> 1087 struct btrfs_workqueue *scrub_wr_completion_workers; >> 1088 struct btrfs_workqueue *scrub_parity_workers; >> 1089 >> 1090 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY >> 1091 u32 check_integrity_print_mask; >> 1092 #endif >> 1093 /* is qgroup tracking in a consistent state? */ >> 1094 u64 qgroup_flags; >> 1095 >> 1096 /* holds configuration and tracking. Protected by qgroup_lock */ >> 1097 struct rb_root qgroup_tree; >> 1098 spinlock_t qgroup_lock; >> 1099 >> 1100 /* >> 1101 * used to avoid frequently calling ulist_alloc()/ulist_free() >> 1102 * when doing qgroup accounting, it must be protected by qgroup_lock. >> 1103 */ >> 1104 struct ulist *qgroup_ulist; >> 1105 >> 1106 /* protect user change for quota operations */ >> 1107 struct mutex qgroup_ioctl_lock; >> 1108 >> 1109 /* list of dirty qgroups to be written at next commit */ >> 1110 struct list_head dirty_qgroups; >> 1111 >> 1112 /* used by qgroup for an efficient tree traversal */ >> 1113 u64 qgroup_seq; >> 1114 >> 1115 /* qgroup rescan items */ >> 1116 struct mutex qgroup_rescan_lock; /* protects the progress item */ >> 1117 struct btrfs_key qgroup_rescan_progress; >> 1118 struct btrfs_workqueue *qgroup_rescan_workers; >> 1119 struct completion qgroup_rescan_completion; >> 1120 struct btrfs_work qgroup_rescan_work; >> 1121 bool qgroup_rescan_running; /* protected by qgroup_rescan_lock */ >> 1122 >> 1123 /* filesystem state */ >> 1124 unsigned long fs_state; >> 1125 >> 1126 struct btrfs_delayed_root *delayed_root; >> 1127 >> 1128 /* readahead tree */ >> 1129 spinlock_t reada_lock; >> 1130 struct radix_tree_root reada_tree; >> 1131 >> 1132 /* readahead works cnt */ >> 1133 atomic_t reada_works_cnt; >> 1134 >> 1135 /* Extent buffer radix tree */ >> 1136 spinlock_t buffer_lock; >> 1137 struct radix_tree_root buffer_radix; >> 1138 >> 1139 /* next backup root to be overwritten */ >> 1140 int backup_root_index; >> 1141 >> 1142 /* device replace state */ >> 1143 struct btrfs_dev_replace dev_replace; >> 1144 >> 1145 struct semaphore uuid_tree_rescan_sem; >> 1146 >> 1147 /* Used to reclaim the metadata space in the background. */ >> 1148 struct work_struct async_reclaim_work; >> 1149 >> 1150 spinlock_t unused_bgs_lock; >> 1151 struct list_head unused_bgs; >> 1152 struct mutex unused_bg_unpin_mutex; >> 1153 struct mutex delete_unused_bgs_mutex; >> 1154 >> 1155 /* Cached block sizes */ >> 1156 u32 nodesize; >> 1157 u32 sectorsize; >> 1158 u32 stripesize; >> 1159 >> 1160 /* Block groups and devices containing active swapfiles. */ >> 1161 spinlock_t swapfile_pins_lock; >> 1162 struct rb_root swapfile_pins; >> 1163 >> 1164 #ifdef CONFIG_BTRFS_FS_REF_VERIFY >> 1165 spinlock_t ref_verify_lock; >> 1166 struct rb_root block_tree; >> 1167 #endif >> 1168 }; >> 1169 >> 1170 static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) >> 1171 { >> 1172 return sb->s_fs_info; >> 1173 } >> 1174 >> 1175 struct btrfs_subvolume_writers { >> 1176 struct percpu_counter counter; >> 1177 wait_queue_head_t wait; >> 1178 }; >> 1179 >> 1180 /* >> 1181 * The state of btrfs root >> 1182 */ >> 1183 enum { >> 1184 /* >> 1185 * btrfs_record_root_in_trans is a multi-step process, and it can race >> 1186 * with the balancing code. But the race is very small, and only the >> 1187 * first time the root is added to each transaction. So IN_TRANS_SETUP >> 1188 * is used to tell us when more checks are required >> 1189 */ >> 1190 BTRFS_ROOT_IN_TRANS_SETUP, >> 1191 BTRFS_ROOT_REF_COWS, 124 BTRFS_ROOT_TRACK_DIRTY, 1192 BTRFS_ROOT_TRACK_DIRTY, 125 BTRFS_ROOT_IN_RADIX, 1193 BTRFS_ROOT_IN_RADIX, 126 BTRFS_ROOT_ORPHAN_ITEM_INSERTED, 1194 BTRFS_ROOT_ORPHAN_ITEM_INSERTED, 127 BTRFS_ROOT_DEFRAG_RUNNING, 1195 BTRFS_ROOT_DEFRAG_RUNNING, 128 BTRFS_ROOT_FORCE_COW, 1196 BTRFS_ROOT_FORCE_COW, 129 BTRFS_ROOT_MULTI_LOG_TASKS, 1197 BTRFS_ROOT_MULTI_LOG_TASKS, 130 BTRFS_ROOT_DIRTY, 1198 BTRFS_ROOT_DIRTY, 131 BTRFS_ROOT_DELETING, 1199 BTRFS_ROOT_DELETING, 132 1200 133 /* 1201 /* 134 * Reloc tree is orphan, only kept her 1202 * Reloc tree is orphan, only kept here for qgroup delayed subtree scan 135 * 1203 * 136 * Set for the subvolume tree owning t 1204 * Set for the subvolume tree owning the reloc tree. 137 */ 1205 */ 138 BTRFS_ROOT_DEAD_RELOC_TREE, 1206 BTRFS_ROOT_DEAD_RELOC_TREE, 139 /* Mark dead root stored on device who 1207 /* Mark dead root stored on device whose cleanup needs to be resumed */ 140 BTRFS_ROOT_DEAD_TREE, 1208 BTRFS_ROOT_DEAD_TREE, 141 /* The root has a log tree. Used for s << 142 BTRFS_ROOT_HAS_LOG_TREE, << 143 /* Qgroup flushing is in progress */ << 144 BTRFS_ROOT_QGROUP_FLUSHING, << 145 /* We started the orphan cleanup for t << 146 BTRFS_ROOT_ORPHAN_CLEANUP, << 147 /* This root has a drop operation that << 148 BTRFS_ROOT_UNFINISHED_DROP, << 149 /* This reloc root needs to have its b << 150 BTRFS_ROOT_RESET_LOCKDEP_CLASS, << 151 }; 1209 }; 152 1210 153 /* 1211 /* 154 * Record swapped tree blocks of a subvolume t 1212 * Record swapped tree blocks of a subvolume tree for delayed subtree trace 155 * code. For detail check comment in fs/btrfs/ 1213 * code. For detail check comment in fs/btrfs/qgroup.c. 156 */ 1214 */ 157 struct btrfs_qgroup_swapped_blocks { 1215 struct btrfs_qgroup_swapped_blocks { 158 spinlock_t lock; 1216 spinlock_t lock; 159 /* RM_EMPTY_ROOT() of above blocks[] * 1217 /* RM_EMPTY_ROOT() of above blocks[] */ 160 bool swapped; 1218 bool swapped; 161 struct rb_root blocks[BTRFS_MAX_LEVEL] 1219 struct rb_root blocks[BTRFS_MAX_LEVEL]; 162 }; 1220 }; 163 1221 164 /* 1222 /* 165 * in ram representation of the tree. extent_ 1223 * in ram representation of the tree. extent_root is used for all allocations 166 * and for the extent tree extent_root root. 1224 * and for the extent tree extent_root root. 167 */ 1225 */ 168 struct btrfs_root { 1226 struct btrfs_root { 169 struct rb_node rb_node; << 170 << 171 struct extent_buffer *node; 1227 struct extent_buffer *node; 172 1228 173 struct extent_buffer *commit_root; 1229 struct extent_buffer *commit_root; 174 struct btrfs_root *log_root; 1230 struct btrfs_root *log_root; 175 struct btrfs_root *reloc_root; 1231 struct btrfs_root *reloc_root; 176 1232 177 unsigned long state; 1233 unsigned long state; 178 struct btrfs_root_item root_item; 1234 struct btrfs_root_item root_item; 179 struct btrfs_key root_key; 1235 struct btrfs_key root_key; 180 struct btrfs_fs_info *fs_info; 1236 struct btrfs_fs_info *fs_info; 181 struct extent_io_tree dirty_log_pages; 1237 struct extent_io_tree dirty_log_pages; 182 1238 183 struct mutex objectid_mutex; 1239 struct mutex objectid_mutex; 184 1240 185 spinlock_t accounting_lock; 1241 spinlock_t accounting_lock; 186 struct btrfs_block_rsv *block_rsv; 1242 struct btrfs_block_rsv *block_rsv; 187 1243 >> 1244 /* free ino cache stuff */ >> 1245 struct btrfs_free_space_ctl *free_ino_ctl; >> 1246 enum btrfs_caching_type ino_cache_state; >> 1247 spinlock_t ino_cache_lock; >> 1248 wait_queue_head_t ino_cache_wait; >> 1249 struct btrfs_free_space_ctl *free_ino_pinned; >> 1250 u64 ino_cache_progress; >> 1251 struct inode *ino_cache_inode; >> 1252 188 struct mutex log_mutex; 1253 struct mutex log_mutex; 189 wait_queue_head_t log_writer_wait; 1254 wait_queue_head_t log_writer_wait; 190 wait_queue_head_t log_commit_wait[2]; 1255 wait_queue_head_t log_commit_wait[2]; 191 struct list_head log_ctxs[2]; 1256 struct list_head log_ctxs[2]; 192 /* Used only for log trees of subvolum << 193 atomic_t log_writers; 1257 atomic_t log_writers; 194 atomic_t log_commit[2]; 1258 atomic_t log_commit[2]; 195 /* Used only for log trees of subvolum << 196 atomic_t log_batch; 1259 atomic_t log_batch; 197 /* << 198 * Protected by the 'log_mutex' lock b << 199 * that lock to avoid unnecessary lock << 200 * should be read using btrfs_get_root << 201 * log tree in which case it can be di << 202 * field should always use btrfs_set_r << 203 * trees where the field can be update << 204 */ << 205 int log_transid; 1260 int log_transid; 206 /* No matter the commit succeeds or no 1261 /* No matter the commit succeeds or not*/ 207 int log_transid_committed; 1262 int log_transid_committed; 208 /* !! 1263 /* Just be updated when the commit succeeds. */ 209 * Just be updated when the commit suc << 210 * btrfs_get_root_last_log_commit() an << 211 * to access this field. << 212 */ << 213 int last_log_commit; 1264 int last_log_commit; 214 pid_t log_start_pid; 1265 pid_t log_start_pid; 215 1266 216 u64 last_trans; 1267 u64 last_trans; 217 1268 218 u64 free_objectid; !! 1269 u32 type; >> 1270 >> 1271 u64 highest_objectid; 219 1272 >> 1273 u64 defrag_trans_start; 220 struct btrfs_key defrag_progress; 1274 struct btrfs_key defrag_progress; 221 struct btrfs_key defrag_max; 1275 struct btrfs_key defrag_max; 222 1276 223 /* The dirty list is only used by non- !! 1277 /* the dirty list is only used by non-reference counted roots */ 224 struct list_head dirty_list; 1278 struct list_head dirty_list; 225 1279 226 struct list_head root_list; 1280 struct list_head root_list; 227 1281 228 /* !! 1282 spinlock_t log_extents_lock[2]; 229 * Xarray that keeps track of in-memor !! 1283 struct list_head logged_list[2]; 230 * @inode_lock. !! 1284 231 */ !! 1285 int orphan_cleanup_state; 232 struct xarray inodes; !! 1286 >> 1287 spinlock_t inode_lock; >> 1288 /* red-black tree that keeps track of in-memory inodes */ >> 1289 struct rb_root inode_tree; 233 1290 234 /* 1291 /* 235 * Xarray that keeps track of delayed !! 1292 * radix tree that keeps track of delayed nodes of every inode, 236 * by @inode_lock. !! 1293 * protected by inode_lock 237 */ 1294 */ 238 struct xarray delayed_nodes; !! 1295 struct radix_tree_root delayed_nodes_tree; 239 /* 1296 /* 240 * right now this just gets used so th 1297 * right now this just gets used so that a root has its own devid 241 * for stat. It may be used for more 1298 * for stat. It may be used for more later 242 */ 1299 */ 243 dev_t anon_dev; 1300 dev_t anon_dev; 244 1301 245 spinlock_t root_item_lock; 1302 spinlock_t root_item_lock; 246 refcount_t refs; 1303 refcount_t refs; 247 1304 248 struct mutex delalloc_mutex; 1305 struct mutex delalloc_mutex; 249 spinlock_t delalloc_lock; 1306 spinlock_t delalloc_lock; 250 /* 1307 /* 251 * all of the inodes that have delallo 1308 * all of the inodes that have delalloc bytes. It is possible for 252 * this list to be empty even when the 1309 * this list to be empty even when there is still dirty data=ordered 253 * extents waiting to finish IO. 1310 * extents waiting to finish IO. 254 */ 1311 */ 255 struct list_head delalloc_inodes; 1312 struct list_head delalloc_inodes; 256 struct list_head delalloc_root; 1313 struct list_head delalloc_root; 257 u64 nr_delalloc_inodes; 1314 u64 nr_delalloc_inodes; 258 1315 259 struct mutex ordered_extent_mutex; 1316 struct mutex ordered_extent_mutex; 260 /* 1317 /* 261 * this is used by the balancing code 1318 * this is used by the balancing code to wait for all the pending 262 * ordered extents 1319 * ordered extents 263 */ 1320 */ 264 spinlock_t ordered_extent_lock; 1321 spinlock_t ordered_extent_lock; 265 1322 266 /* 1323 /* 267 * all of the data=ordered extents pen 1324 * all of the data=ordered extents pending writeback 268 * these can span multiple transaction 1325 * these can span multiple transactions and basically include 269 * every dirty data page that isn't fr 1326 * every dirty data page that isn't from nodatacow 270 */ 1327 */ 271 struct list_head ordered_extents; 1328 struct list_head ordered_extents; 272 struct list_head ordered_root; 1329 struct list_head ordered_root; 273 u64 nr_ordered_extents; 1330 u64 nr_ordered_extents; 274 1331 275 /* 1332 /* 276 * Not empty if this subvolume root ha 1333 * Not empty if this subvolume root has gone through tree block swap 277 * (relocation) 1334 * (relocation) 278 * 1335 * 279 * Will be used by reloc_control::dirt 1336 * Will be used by reloc_control::dirty_subvol_roots. 280 */ 1337 */ 281 struct list_head reloc_dirty_list; 1338 struct list_head reloc_dirty_list; 282 1339 283 /* 1340 /* 284 * Number of currently running SEND io 1341 * Number of currently running SEND ioctls to prevent 285 * manipulation with the read-only sta 1342 * manipulation with the read-only status via SUBVOL_SETFLAGS 286 */ 1343 */ 287 int send_in_progress; 1344 int send_in_progress; 288 /* 1345 /* 289 * Number of currently running dedupli 1346 * Number of currently running deduplication operations that have a 290 * destination inode belonging to this 1347 * destination inode belonging to this root. Protected by the lock 291 * root_item_lock. 1348 * root_item_lock. 292 */ 1349 */ 293 int dedupe_in_progress; 1350 int dedupe_in_progress; 294 /* For exclusion of snapshot creation !! 1351 struct btrfs_subvolume_writers *subv_writers; 295 struct btrfs_drew_lock snapshot_lock; !! 1352 atomic_t will_be_snapshotted; 296 << 297 atomic_t snapshot_force_cow; 1353 atomic_t snapshot_force_cow; 298 1354 299 /* For qgroup metadata reserved space 1355 /* For qgroup metadata reserved space */ 300 spinlock_t qgroup_meta_rsv_lock; 1356 spinlock_t qgroup_meta_rsv_lock; 301 u64 qgroup_meta_rsv_pertrans; 1357 u64 qgroup_meta_rsv_pertrans; 302 u64 qgroup_meta_rsv_prealloc; 1358 u64 qgroup_meta_rsv_prealloc; 303 wait_queue_head_t qgroup_flush_wait; << 304 1359 305 /* Number of active swapfiles */ 1360 /* Number of active swapfiles */ 306 atomic_t nr_swapfiles; 1361 atomic_t nr_swapfiles; 307 1362 308 /* Record pairs of swapped blocks for 1363 /* Record pairs of swapped blocks for qgroup */ 309 struct btrfs_qgroup_swapped_blocks swa 1364 struct btrfs_qgroup_swapped_blocks swapped_blocks; 310 1365 311 /* Used only by log trees, when loggin << 312 struct extent_io_tree log_csum_range; << 313 << 314 /* Used in simple quotas, track root d << 315 u64 relocation_src_root; << 316 << 317 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 1366 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 318 u64 alloc_bytenr; 1367 u64 alloc_bytenr; 319 #endif 1368 #endif >> 1369 }; >> 1370 >> 1371 struct btrfs_file_private { >> 1372 void *filldir_buf; >> 1373 }; >> 1374 >> 1375 static inline u32 btrfs_inode_sectorsize(const struct inode *inode) >> 1376 { >> 1377 return btrfs_sb(inode->i_sb)->sectorsize; >> 1378 } >> 1379 >> 1380 static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info) >> 1381 { >> 1382 >> 1383 return info->nodesize - sizeof(struct btrfs_header); >> 1384 } >> 1385 >> 1386 #define BTRFS_LEAF_DATA_OFFSET offsetof(struct btrfs_leaf, items) >> 1387 >> 1388 static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info) >> 1389 { >> 1390 return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item); >> 1391 } >> 1392 >> 1393 static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info) >> 1394 { >> 1395 return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr); >> 1396 } >> 1397 >> 1398 #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ >> 1399 (offsetof(struct btrfs_file_extent_item, disk_bytenr)) >> 1400 static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info) >> 1401 { >> 1402 return BTRFS_MAX_ITEM_SIZE(info) - >> 1403 BTRFS_FILE_EXTENT_INLINE_DATA_START; >> 1404 } >> 1405 >> 1406 static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) >> 1407 { >> 1408 return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); >> 1409 } >> 1410 >> 1411 /* >> 1412 * Flags for mount options. >> 1413 * >> 1414 * Note: don't forget to add new options to btrfs_show_options() >> 1415 */ >> 1416 #define BTRFS_MOUNT_NODATASUM (1 << 0) >> 1417 #define BTRFS_MOUNT_NODATACOW (1 << 1) >> 1418 #define BTRFS_MOUNT_NOBARRIER (1 << 2) >> 1419 #define BTRFS_MOUNT_SSD (1 << 3) >> 1420 #define BTRFS_MOUNT_DEGRADED (1 << 4) >> 1421 #define BTRFS_MOUNT_COMPRESS (1 << 5) >> 1422 #define BTRFS_MOUNT_NOTREELOG (1 << 6) >> 1423 #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) >> 1424 #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) >> 1425 #define BTRFS_MOUNT_NOSSD (1 << 9) >> 1426 #define BTRFS_MOUNT_DISCARD (1 << 10) >> 1427 #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) >> 1428 #define BTRFS_MOUNT_SPACE_CACHE (1 << 12) >> 1429 #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13) >> 1430 #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14) >> 1431 #define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15) >> 1432 #define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16) >> 1433 #define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17) >> 1434 #define BTRFS_MOUNT_USEBACKUPROOT (1 << 18) >> 1435 #define BTRFS_MOUNT_SKIP_BALANCE (1 << 19) >> 1436 #define BTRFS_MOUNT_CHECK_INTEGRITY (1 << 20) >> 1437 #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21) >> 1438 #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22) >> 1439 #define BTRFS_MOUNT_RESCAN_UUID_TREE (1 << 23) >> 1440 #define BTRFS_MOUNT_FRAGMENT_DATA (1 << 24) >> 1441 #define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25) >> 1442 #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26) >> 1443 #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27) >> 1444 #define BTRFS_MOUNT_REF_VERIFY (1 << 28) >> 1445 >> 1446 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) >> 1447 #define BTRFS_DEFAULT_MAX_INLINE (2048) >> 1448 >> 1449 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) >> 1450 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) >> 1451 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt) >> 1452 #define btrfs_test_opt(fs_info, opt) ((fs_info)->mount_opt & \ >> 1453 BTRFS_MOUNT_##opt) >> 1454 >> 1455 #define btrfs_set_and_info(fs_info, opt, fmt, args...) \ >> 1456 { \ >> 1457 if (!btrfs_test_opt(fs_info, opt)) \ >> 1458 btrfs_info(fs_info, fmt, ##args); \ >> 1459 btrfs_set_opt(fs_info->mount_opt, opt); \ >> 1460 } >> 1461 >> 1462 #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \ >> 1463 { \ >> 1464 if (btrfs_test_opt(fs_info, opt)) \ >> 1465 btrfs_info(fs_info, fmt, ##args); \ >> 1466 btrfs_clear_opt(fs_info->mount_opt, opt); \ >> 1467 } 320 1468 321 #ifdef CONFIG_BTRFS_DEBUG 1469 #ifdef CONFIG_BTRFS_DEBUG 322 struct list_head leak_list; !! 1470 static inline int >> 1471 btrfs_should_fragment_free_space(struct btrfs_block_group_cache *block_group) >> 1472 { >> 1473 struct btrfs_fs_info *fs_info = block_group->fs_info; >> 1474 >> 1475 return (btrfs_test_opt(fs_info, FRAGMENT_METADATA) && >> 1476 block_group->flags & BTRFS_BLOCK_GROUP_METADATA) || >> 1477 (btrfs_test_opt(fs_info, FRAGMENT_DATA) && >> 1478 block_group->flags & BTRFS_BLOCK_GROUP_DATA); >> 1479 } 323 #endif 1480 #endif >> 1481 >> 1482 /* >> 1483 * Requests for changes that need to be done during transaction commit. >> 1484 * >> 1485 * Internal mount options that are used for special handling of the real >> 1486 * mount options (eg. cannot be set during remount and have to be set during >> 1487 * transaction commit) >> 1488 */ >> 1489 >> 1490 #define BTRFS_PENDING_SET_INODE_MAP_CACHE (0) >> 1491 #define BTRFS_PENDING_CLEAR_INODE_MAP_CACHE (1) >> 1492 #define BTRFS_PENDING_COMMIT (2) >> 1493 >> 1494 #define btrfs_test_pending(info, opt) \ >> 1495 test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes) >> 1496 #define btrfs_set_pending(info, opt) \ >> 1497 set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes) >> 1498 #define btrfs_clear_pending(info, opt) \ >> 1499 clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes) >> 1500 >> 1501 /* >> 1502 * Helpers for setting pending mount option changes. >> 1503 * >> 1504 * Expects corresponding macros >> 1505 * BTRFS_PENDING_SET_ and CLEAR_ + short mount option name >> 1506 */ >> 1507 #define btrfs_set_pending_and_info(info, opt, fmt, args...) \ >> 1508 do { \ >> 1509 if (!btrfs_raw_test_opt((info)->mount_opt, opt)) { \ >> 1510 btrfs_info((info), fmt, ##args); \ >> 1511 btrfs_set_pending((info), SET_##opt); \ >> 1512 btrfs_clear_pending((info), CLEAR_##opt); \ >> 1513 } \ >> 1514 } while(0) >> 1515 >> 1516 #define btrfs_clear_pending_and_info(info, opt, fmt, args...) \ >> 1517 do { \ >> 1518 if (btrfs_raw_test_opt((info)->mount_opt, opt)) { \ >> 1519 btrfs_info((info), fmt, ##args); \ >> 1520 btrfs_set_pending((info), CLEAR_##opt); \ >> 1521 btrfs_clear_pending((info), SET_##opt); \ >> 1522 } \ >> 1523 } while(0) >> 1524 >> 1525 /* >> 1526 * Inode flags >> 1527 */ >> 1528 #define BTRFS_INODE_NODATASUM (1 << 0) >> 1529 #define BTRFS_INODE_NODATACOW (1 << 1) >> 1530 #define BTRFS_INODE_READONLY (1 << 2) >> 1531 #define BTRFS_INODE_NOCOMPRESS (1 << 3) >> 1532 #define BTRFS_INODE_PREALLOC (1 << 4) >> 1533 #define BTRFS_INODE_SYNC (1 << 5) >> 1534 #define BTRFS_INODE_IMMUTABLE (1 << 6) >> 1535 #define BTRFS_INODE_APPEND (1 << 7) >> 1536 #define BTRFS_INODE_NODUMP (1 << 8) >> 1537 #define BTRFS_INODE_NOATIME (1 << 9) >> 1538 #define BTRFS_INODE_DIRSYNC (1 << 10) >> 1539 #define BTRFS_INODE_COMPRESS (1 << 11) >> 1540 >> 1541 #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31) >> 1542 >> 1543 #define BTRFS_INODE_FLAG_MASK \ >> 1544 (BTRFS_INODE_NODATASUM | \ >> 1545 BTRFS_INODE_NODATACOW | \ >> 1546 BTRFS_INODE_READONLY | \ >> 1547 BTRFS_INODE_NOCOMPRESS | \ >> 1548 BTRFS_INODE_PREALLOC | \ >> 1549 BTRFS_INODE_SYNC | \ >> 1550 BTRFS_INODE_IMMUTABLE | \ >> 1551 BTRFS_INODE_APPEND | \ >> 1552 BTRFS_INODE_NODUMP | \ >> 1553 BTRFS_INODE_NOATIME | \ >> 1554 BTRFS_INODE_DIRSYNC | \ >> 1555 BTRFS_INODE_COMPRESS | \ >> 1556 BTRFS_INODE_ROOT_ITEM_INIT) >> 1557 >> 1558 struct btrfs_map_token { >> 1559 const struct extent_buffer *eb; >> 1560 char *kaddr; >> 1561 unsigned long offset; 324 }; 1562 }; 325 1563 326 static inline bool btrfs_root_readonly(const s !! 1564 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ >> 1565 ((bytes) >> (fs_info)->sb->s_blocksize_bits) >> 1566 >> 1567 static inline void btrfs_init_map_token (struct btrfs_map_token *token) 327 { 1568 { 328 /* Byte-swap the constant at compile t !! 1569 token->kaddr = NULL; 329 return (root->root_item.flags & cpu_to << 330 } 1570 } 331 1571 332 static inline bool btrfs_root_dead(const struc !! 1572 /* some macros to generate set/get functions for the struct fields. This >> 1573 * assumes there is a lefoo_to_cpu for every type, so lets make a simple >> 1574 * one for u8: >> 1575 */ >> 1576 #define le8_to_cpu(v) (v) >> 1577 #define cpu_to_le8(v) (v) >> 1578 #define __le8 u8 >> 1579 >> 1580 #define read_eb_member(eb, ptr, type, member, result) (\ >> 1581 read_extent_buffer(eb, (char *)(result), \ >> 1582 ((unsigned long)(ptr)) + \ >> 1583 offsetof(type, member), \ >> 1584 sizeof(((type *)0)->member))) >> 1585 >> 1586 #define write_eb_member(eb, ptr, type, member, result) (\ >> 1587 write_extent_buffer(eb, (char *)(result), \ >> 1588 ((unsigned long)(ptr)) + \ >> 1589 offsetof(type, member), \ >> 1590 sizeof(((type *)0)->member))) >> 1591 >> 1592 #define DECLARE_BTRFS_SETGET_BITS(bits) \ >> 1593 u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \ >> 1594 const void *ptr, unsigned long off, \ >> 1595 struct btrfs_map_token *token); \ >> 1596 void btrfs_set_token_##bits(struct extent_buffer *eb, const void *ptr, \ >> 1597 unsigned long off, u##bits val, \ >> 1598 struct btrfs_map_token *token); \ >> 1599 static inline u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ >> 1600 const void *ptr, \ >> 1601 unsigned long off) \ >> 1602 { \ >> 1603 return btrfs_get_token_##bits(eb, ptr, off, NULL); \ >> 1604 } \ >> 1605 static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr,\ >> 1606 unsigned long off, u##bits val) \ >> 1607 { \ >> 1608 btrfs_set_token_##bits(eb, ptr, off, val, NULL); \ >> 1609 } >> 1610 >> 1611 DECLARE_BTRFS_SETGET_BITS(8) >> 1612 DECLARE_BTRFS_SETGET_BITS(16) >> 1613 DECLARE_BTRFS_SETGET_BITS(32) >> 1614 DECLARE_BTRFS_SETGET_BITS(64) >> 1615 >> 1616 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ >> 1617 static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ >> 1618 const type *s) \ >> 1619 { \ >> 1620 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ >> 1621 return btrfs_get_##bits(eb, s, offsetof(type, member)); \ >> 1622 } \ >> 1623 static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \ >> 1624 u##bits val) \ >> 1625 { \ >> 1626 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ >> 1627 btrfs_set_##bits(eb, s, offsetof(type, member), val); \ >> 1628 } \ >> 1629 static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\ >> 1630 const type *s, \ >> 1631 struct btrfs_map_token *token) \ >> 1632 { \ >> 1633 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ >> 1634 return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \ >> 1635 } \ >> 1636 static inline void btrfs_set_token_##name(struct extent_buffer *eb, \ >> 1637 type *s, u##bits val, \ >> 1638 struct btrfs_map_token *token) \ >> 1639 { \ >> 1640 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ >> 1641 btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \ >> 1642 } >> 1643 >> 1644 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ >> 1645 static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ >> 1646 { \ >> 1647 const type *p = page_address(eb->pages[0]); \ >> 1648 u##bits res = le##bits##_to_cpu(p->member); \ >> 1649 return res; \ >> 1650 } \ >> 1651 static inline void btrfs_set_##name(struct extent_buffer *eb, \ >> 1652 u##bits val) \ >> 1653 { \ >> 1654 type *p = page_address(eb->pages[0]); \ >> 1655 p->member = cpu_to_le##bits(val); \ >> 1656 } >> 1657 >> 1658 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ >> 1659 static inline u##bits btrfs_##name(const type *s) \ >> 1660 { \ >> 1661 return le##bits##_to_cpu(s->member); \ >> 1662 } \ >> 1663 static inline void btrfs_set_##name(type *s, u##bits val) \ >> 1664 { \ >> 1665 s->member = cpu_to_le##bits(val); \ >> 1666 } >> 1667 >> 1668 >> 1669 static inline u64 btrfs_device_total_bytes(struct extent_buffer *eb, >> 1670 struct btrfs_dev_item *s) >> 1671 { >> 1672 BUILD_BUG_ON(sizeof(u64) != >> 1673 sizeof(((struct btrfs_dev_item *)0))->total_bytes); >> 1674 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, >> 1675 total_bytes)); >> 1676 } >> 1677 static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb, >> 1678 struct btrfs_dev_item *s, >> 1679 u64 val) >> 1680 { >> 1681 BUILD_BUG_ON(sizeof(u64) != >> 1682 sizeof(((struct btrfs_dev_item *)0))->total_bytes); >> 1683 WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize)); >> 1684 btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val); >> 1685 } >> 1686 >> 1687 >> 1688 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); >> 1689 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); >> 1690 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); >> 1691 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); >> 1692 BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, >> 1693 start_offset, 64); >> 1694 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); >> 1695 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); >> 1696 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32); >> 1697 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); >> 1698 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); >> 1699 BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); >> 1700 >> 1701 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); >> 1702 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, >> 1703 total_bytes, 64); >> 1704 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, >> 1705 bytes_used, 64); >> 1706 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item, >> 1707 io_align, 32); >> 1708 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item, >> 1709 io_width, 32); >> 1710 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, >> 1711 sector_size, 32); >> 1712 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); >> 1713 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, >> 1714 dev_group, 32); >> 1715 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item, >> 1716 seek_speed, 8); >> 1717 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item, >> 1718 bandwidth, 8); >> 1719 BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, >> 1720 generation, 64); >> 1721 >> 1722 static inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d) >> 1723 { >> 1724 return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid); >> 1725 } >> 1726 >> 1727 static inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d) >> 1728 { >> 1729 return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid); >> 1730 } >> 1731 >> 1732 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); >> 1733 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); >> 1734 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); >> 1735 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); >> 1736 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32); >> 1737 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32); >> 1738 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64); >> 1739 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16); >> 1740 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16); >> 1741 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); >> 1742 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); >> 1743 >> 1744 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) >> 1745 { >> 1746 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); >> 1747 } >> 1748 >> 1749 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); >> 1750 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); >> 1751 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, >> 1752 stripe_len, 64); >> 1753 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, >> 1754 io_align, 32); >> 1755 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, >> 1756 io_width, 32); >> 1757 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk, >> 1758 sector_size, 32); >> 1759 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64); >> 1760 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk, >> 1761 num_stripes, 16); >> 1762 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk, >> 1763 sub_stripes, 16); >> 1764 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64); >> 1765 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); >> 1766 >> 1767 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, >> 1768 int nr) >> 1769 { >> 1770 unsigned long offset = (unsigned long)c; >> 1771 offset += offsetof(struct btrfs_chunk, stripe); >> 1772 offset += nr * sizeof(struct btrfs_stripe); >> 1773 return (struct btrfs_stripe *)offset; >> 1774 } >> 1775 >> 1776 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) >> 1777 { >> 1778 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr)); >> 1779 } >> 1780 >> 1781 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb, >> 1782 struct btrfs_chunk *c, int nr) >> 1783 { >> 1784 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); >> 1785 } >> 1786 >> 1787 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, >> 1788 struct btrfs_chunk *c, int nr) >> 1789 { >> 1790 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); >> 1791 } >> 1792 >> 1793 /* struct btrfs_block_group_item */ >> 1794 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, >> 1795 used, 64); >> 1796 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, >> 1797 used, 64); >> 1798 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid, >> 1799 struct btrfs_block_group_item, chunk_objectid, 64); >> 1800 >> 1801 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid, >> 1802 struct btrfs_block_group_item, chunk_objectid, 64); >> 1803 BTRFS_SETGET_FUNCS(disk_block_group_flags, >> 1804 struct btrfs_block_group_item, flags, 64); >> 1805 BTRFS_SETGET_STACK_FUNCS(block_group_flags, >> 1806 struct btrfs_block_group_item, flags, 64); >> 1807 >> 1808 /* struct btrfs_free_space_info */ >> 1809 BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info, >> 1810 extent_count, 32); >> 1811 BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32); >> 1812 >> 1813 /* struct btrfs_inode_ref */ >> 1814 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); >> 1815 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); >> 1816 >> 1817 /* struct btrfs_inode_extref */ >> 1818 BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref, >> 1819 parent_objectid, 64); >> 1820 BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref, >> 1821 name_len, 16); >> 1822 BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64); >> 1823 >> 1824 /* struct btrfs_inode_item */ >> 1825 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); >> 1826 BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64); >> 1827 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); >> 1828 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); >> 1829 BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); >> 1830 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); >> 1831 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); >> 1832 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); >> 1833 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); >> 1834 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); >> 1835 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64); >> 1836 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); >> 1837 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item, >> 1838 generation, 64); >> 1839 BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item, >> 1840 sequence, 64); >> 1841 BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item, >> 1842 transid, 64); >> 1843 BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64); >> 1844 BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item, >> 1845 nbytes, 64); >> 1846 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item, >> 1847 block_group, 64); >> 1848 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32); >> 1849 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32); >> 1850 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32); >> 1851 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32); >> 1852 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64); >> 1853 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64); >> 1854 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); >> 1855 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); >> 1856 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); >> 1857 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); >> 1858 >> 1859 /* struct btrfs_dev_extent */ >> 1860 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, >> 1861 chunk_tree, 64); >> 1862 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, >> 1863 chunk_objectid, 64); >> 1864 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, >> 1865 chunk_offset, 64); >> 1866 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); >> 1867 >> 1868 static inline unsigned long btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev) >> 1869 { >> 1870 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid); >> 1871 return (unsigned long)dev + ptr; >> 1872 } >> 1873 >> 1874 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); >> 1875 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, >> 1876 generation, 64); >> 1877 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); >> 1878 >> 1879 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32); >> 1880 >> 1881 >> 1882 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); >> 1883 >> 1884 static inline void btrfs_tree_block_key(struct extent_buffer *eb, >> 1885 struct btrfs_tree_block_info *item, >> 1886 struct btrfs_disk_key *key) >> 1887 { >> 1888 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); >> 1889 } >> 1890 >> 1891 static inline void btrfs_set_tree_block_key(struct extent_buffer *eb, >> 1892 struct btrfs_tree_block_info *item, >> 1893 struct btrfs_disk_key *key) >> 1894 { >> 1895 write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); >> 1896 } >> 1897 >> 1898 BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, >> 1899 root, 64); >> 1900 BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, >> 1901 objectid, 64); >> 1902 BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, >> 1903 offset, 64); >> 1904 BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, >> 1905 count, 32); >> 1906 >> 1907 BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, >> 1908 count, 32); >> 1909 >> 1910 BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, >> 1911 type, 8); >> 1912 BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, >> 1913 offset, 64); >> 1914 >> 1915 static inline u32 btrfs_extent_inline_ref_size(int type) >> 1916 { >> 1917 if (type == BTRFS_TREE_BLOCK_REF_KEY || >> 1918 type == BTRFS_SHARED_BLOCK_REF_KEY) >> 1919 return sizeof(struct btrfs_extent_inline_ref); >> 1920 if (type == BTRFS_SHARED_DATA_REF_KEY) >> 1921 return sizeof(struct btrfs_shared_data_ref) + >> 1922 sizeof(struct btrfs_extent_inline_ref); >> 1923 if (type == BTRFS_EXTENT_DATA_REF_KEY) >> 1924 return sizeof(struct btrfs_extent_data_ref) + >> 1925 offsetof(struct btrfs_extent_inline_ref, offset); >> 1926 return 0; >> 1927 } >> 1928 >> 1929 BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64); >> 1930 BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0, >> 1931 generation, 64); >> 1932 BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64); >> 1933 BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32); >> 1934 >> 1935 /* struct btrfs_node */ >> 1936 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); >> 1937 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); >> 1938 BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, >> 1939 blockptr, 64); >> 1940 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, >> 1941 generation, 64); >> 1942 >> 1943 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) 333 { 1944 { 334 /* Byte-swap the constant at compile t !! 1945 unsigned long ptr; 335 return (root->root_item.flags & cpu_to !! 1946 ptr = offsetof(struct btrfs_node, ptrs) + >> 1947 sizeof(struct btrfs_key_ptr) * nr; >> 1948 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); >> 1949 } >> 1950 >> 1951 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, >> 1952 int nr, u64 val) >> 1953 { >> 1954 unsigned long ptr; >> 1955 ptr = offsetof(struct btrfs_node, ptrs) + >> 1956 sizeof(struct btrfs_key_ptr) * nr; >> 1957 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); >> 1958 } >> 1959 >> 1960 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) >> 1961 { >> 1962 unsigned long ptr; >> 1963 ptr = offsetof(struct btrfs_node, ptrs) + >> 1964 sizeof(struct btrfs_key_ptr) * nr; >> 1965 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); >> 1966 } >> 1967 >> 1968 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, >> 1969 int nr, u64 val) >> 1970 { >> 1971 unsigned long ptr; >> 1972 ptr = offsetof(struct btrfs_node, ptrs) + >> 1973 sizeof(struct btrfs_key_ptr) * nr; >> 1974 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); >> 1975 } >> 1976 >> 1977 static inline unsigned long btrfs_node_key_ptr_offset(int nr) >> 1978 { >> 1979 return offsetof(struct btrfs_node, ptrs) + >> 1980 sizeof(struct btrfs_key_ptr) * nr; >> 1981 } >> 1982 >> 1983 void btrfs_node_key(const struct extent_buffer *eb, >> 1984 struct btrfs_disk_key *disk_key, int nr); >> 1985 >> 1986 static inline void btrfs_set_node_key(struct extent_buffer *eb, >> 1987 struct btrfs_disk_key *disk_key, int nr) >> 1988 { >> 1989 unsigned long ptr; >> 1990 ptr = btrfs_node_key_ptr_offset(nr); >> 1991 write_eb_member(eb, (struct btrfs_key_ptr *)ptr, >> 1992 struct btrfs_key_ptr, key, disk_key); >> 1993 } >> 1994 >> 1995 /* struct btrfs_item */ >> 1996 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32); >> 1997 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32); >> 1998 BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); >> 1999 BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); >> 2000 >> 2001 static inline unsigned long btrfs_item_nr_offset(int nr) >> 2002 { >> 2003 return offsetof(struct btrfs_leaf, items) + >> 2004 sizeof(struct btrfs_item) * nr; 336 } 2005 } 337 2006 338 static inline u64 btrfs_root_id(const struct b !! 2007 static inline struct btrfs_item *btrfs_item_nr(int nr) 339 { 2008 { 340 return root->root_key.objectid; !! 2009 return (struct btrfs_item *)btrfs_item_nr_offset(nr); 341 } 2010 } 342 2011 343 static inline int btrfs_get_root_log_transid(c !! 2012 static inline u32 btrfs_item_end(const struct extent_buffer *eb, >> 2013 struct btrfs_item *item) 344 { 2014 { 345 return READ_ONCE(root->log_transid); !! 2015 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item); 346 } 2016 } 347 2017 348 static inline void btrfs_set_root_log_transid( !! 2018 static inline u32 btrfs_item_end_nr(const struct extent_buffer *eb, int nr) 349 { 2019 { 350 WRITE_ONCE(root->log_transid, log_tran !! 2020 return btrfs_item_end(eb, btrfs_item_nr(nr)); 351 } 2021 } 352 2022 353 static inline int btrfs_get_root_last_log_comm !! 2023 static inline u32 btrfs_item_offset_nr(const struct extent_buffer *eb, int nr) 354 { 2024 { 355 return READ_ONCE(root->last_log_commit !! 2025 return btrfs_item_offset(eb, btrfs_item_nr(nr)); 356 } 2026 } 357 2027 358 static inline void btrfs_set_root_last_log_com !! 2028 static inline u32 btrfs_item_size_nr(const struct extent_buffer *eb, int nr) 359 { 2029 { 360 WRITE_ONCE(root->last_log_commit, comm !! 2030 return btrfs_item_size(eb, btrfs_item_nr(nr)); 361 } 2031 } 362 2032 363 static inline u64 btrfs_get_root_last_trans(co !! 2033 static inline void btrfs_item_key(const struct extent_buffer *eb, >> 2034 struct btrfs_disk_key *disk_key, int nr) 364 { 2035 { 365 return READ_ONCE(root->last_trans); !! 2036 struct btrfs_item *item = btrfs_item_nr(nr); >> 2037 read_eb_member(eb, item, struct btrfs_item, key, disk_key); 366 } 2038 } 367 2039 368 static inline void btrfs_set_root_last_trans(s !! 2040 static inline void btrfs_set_item_key(struct extent_buffer *eb, >> 2041 struct btrfs_disk_key *disk_key, int nr) 369 { 2042 { 370 WRITE_ONCE(root->last_trans, transid); !! 2043 struct btrfs_item *item = btrfs_item_nr(nr); >> 2044 write_eb_member(eb, item, struct btrfs_item, key, disk_key); 371 } 2045 } 372 2046 >> 2047 BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); >> 2048 373 /* 2049 /* 374 * Structure that conveys information about an !! 2050 * struct btrfs_root_ref 375 * all the extents in a file range. << 376 */ 2051 */ 377 struct btrfs_replace_extent_info { !! 2052 BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); 378 u64 disk_offset; !! 2053 BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); 379 u64 disk_len; !! 2054 BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); 380 u64 data_offset; << 381 u64 data_len; << 382 u64 file_offset; << 383 /* Pointer to a file extent item of ty << 384 char *extent_buf; << 385 /* << 386 * Set to true when attempting to repl << 387 * described by this structure, set to << 388 * existing extent into a file range. << 389 */ << 390 bool is_new_extent; << 391 /* Indicate if we should update the in << 392 bool update_times; << 393 /* Meaningful only if is_new_extent is << 394 int qgroup_reserved; << 395 /* << 396 * Meaningful only if is_new_extent is << 397 * Used to track how many extent items << 398 * subvolume tree that refer to the ex << 399 * so that we know when to create a ne << 400 * one. << 401 */ << 402 int insertions; << 403 }; << 404 2055 405 /* Arguments for btrfs_drop_extents() */ !! 2056 /* struct btrfs_dir_item */ 406 struct btrfs_drop_extents_args { !! 2057 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); 407 /* Input parameters */ !! 2058 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); >> 2059 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); >> 2060 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); >> 2061 BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8); >> 2062 BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, >> 2063 data_len, 16); >> 2064 BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, >> 2065 name_len, 16); >> 2066 BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, >> 2067 transid, 64); 408 2068 409 /* !! 2069 static inline void btrfs_dir_item_key(const struct extent_buffer *eb, 410 * If NULL, btrfs_drop_extents() will !! 2070 const struct btrfs_dir_item *item, 411 * If 'replace_extent' is true, this m !! 2071 struct btrfs_disk_key *key) 412 * is always released except if 'repla !! 2072 { 413 * btrfs_drop_extents() sets 'extent_i !! 2073 read_eb_member(eb, item, struct btrfs_dir_item, location, key); 414 * the path is kept locked. !! 2074 } 415 */ << 416 struct btrfs_path *path; << 417 /* Start offset of the range to drop e << 418 u64 start; << 419 /* End (exclusive, last byte + 1) of t << 420 u64 end; << 421 /* If true drop all the extent maps in << 422 bool drop_cache; << 423 /* << 424 * If true it means we want to insert << 425 * the extents in the range. If this i << 426 * parameter must be set as well and t << 427 * be set to true by btrfs_drop_extent << 428 * extent. << 429 * Note: when this is set to true the << 430 */ << 431 bool replace_extent; << 432 /* << 433 * Used if 'replace_extent' is true. S << 434 * insert after dropping all existing << 435 */ << 436 u32 extent_item_size; << 437 2075 438 /* Output parameters */ !! 2076 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, >> 2077 struct btrfs_dir_item *item, >> 2078 const struct btrfs_disk_key *key) >> 2079 { >> 2080 write_eb_member(eb, item, struct btrfs_dir_item, location, key); >> 2081 } 439 2082 440 /* !! 2083 BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, 441 * Set to the minimum between the inpu !! 2084 num_entries, 64); 442 * (exclusive, last byte + 1) of the l !! 2085 BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, 443 * set even if btrfs_drop_extents() re !! 2086 num_bitmaps, 64); 444 */ !! 2087 BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, 445 u64 drop_end; !! 2088 generation, 64); 446 /* << 447 * The number of allocated bytes found << 448 * than the range's length when there << 449 */ << 450 u64 bytes_found; << 451 /* << 452 * Only set if 'replace_extent' is tru << 453 * to insert a replacement extent afte << 454 * range, otherwise set to false by bt << 455 * Also, if btrfs_drop_extents() has s << 456 * returned with the path locked, othe << 457 * false it has returned with the path << 458 */ << 459 bool extent_inserted; << 460 }; << 461 2089 462 struct btrfs_file_private { !! 2090 static inline void btrfs_free_space_key(const struct extent_buffer *eb, 463 void *filldir_buf; !! 2091 const struct btrfs_free_space_header *h, 464 u64 last_index; !! 2092 struct btrfs_disk_key *key) 465 struct extent_state *llseek_cached_sta !! 2093 { 466 /* Task that allocated this structure. !! 2094 read_eb_member(eb, h, struct btrfs_free_space_header, location, key); 467 struct task_struct *owner_task; !! 2095 } 468 }; << 469 2096 470 static inline u32 BTRFS_LEAF_DATA_SIZE(const s !! 2097 static inline void btrfs_set_free_space_key(struct extent_buffer *eb, >> 2098 struct btrfs_free_space_header *h, >> 2099 const struct btrfs_disk_key *key) 471 { 2100 { 472 return info->nodesize - sizeof(struct !! 2101 write_eb_member(eb, h, struct btrfs_free_space_header, location, key); 473 } 2102 } 474 2103 475 static inline u32 BTRFS_MAX_ITEM_SIZE(const st !! 2104 /* struct btrfs_disk_key */ >> 2105 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, >> 2106 objectid, 64); >> 2107 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); >> 2108 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); >> 2109 >> 2110 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, >> 2111 const struct btrfs_disk_key *disk) 476 { 2112 { 477 return BTRFS_LEAF_DATA_SIZE(info) - si !! 2113 cpu->offset = le64_to_cpu(disk->offset); >> 2114 cpu->type = disk->type; >> 2115 cpu->objectid = le64_to_cpu(disk->objectid); 478 } 2116 } 479 2117 480 static inline u32 BTRFS_NODEPTRS_PER_BLOCK(con !! 2118 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, >> 2119 const struct btrfs_key *cpu) 481 { 2120 { 482 return BTRFS_LEAF_DATA_SIZE(info) / si !! 2121 disk->offset = cpu_to_le64(cpu->offset); >> 2122 disk->type = cpu->type; >> 2123 disk->objectid = cpu_to_le64(cpu->objectid); 483 } 2124 } 484 2125 485 static inline u32 BTRFS_MAX_XATTR_SIZE(const s !! 2126 static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, >> 2127 struct btrfs_key *key, int nr) 486 { 2128 { 487 return BTRFS_MAX_ITEM_SIZE(info) - siz !! 2129 struct btrfs_disk_key disk_key; >> 2130 btrfs_node_key(eb, &disk_key, nr); >> 2131 btrfs_disk_key_to_cpu(key, &disk_key); 488 } 2132 } 489 2133 490 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ !! 2134 static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 491 ((bytes) >> (f !! 2135 struct btrfs_key *key, int nr) >> 2136 { >> 2137 struct btrfs_disk_key disk_key; >> 2138 btrfs_item_key(eb, &disk_key, nr); >> 2139 btrfs_disk_key_to_cpu(key, &disk_key); >> 2140 } 492 2141 493 static inline gfp_t btrfs_alloc_write_mask(str !! 2142 static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, >> 2143 const struct btrfs_dir_item *item, >> 2144 struct btrfs_key *key) 494 { 2145 { 495 return mapping_gfp_constraint(mapping, !! 2146 struct btrfs_disk_key disk_key; >> 2147 btrfs_dir_item_key(eb, item, &disk_key); >> 2148 btrfs_disk_key_to_cpu(key, &disk_key); 496 } 2149 } 497 2150 498 void btrfs_error_unpin_extent_range(struct btr !! 2151 static inline u8 btrfs_key_type(const struct btrfs_key *key) 499 int btrfs_discard_extent(struct btrfs_fs_info !! 2152 { 500 u64 num_bytes, u64 *a !! 2153 return key->type; 501 int btrfs_trim_fs(struct btrfs_fs_info *fs_inf !! 2154 } 502 2155 503 /* ctree.c */ !! 2156 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val) 504 int __init btrfs_ctree_init(void); !! 2157 { 505 void __cold btrfs_ctree_exit(void); !! 2158 key->type = val; >> 2159 } >> 2160 >> 2161 /* struct btrfs_header */ >> 2162 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); >> 2163 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, >> 2164 generation, 64); >> 2165 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); >> 2166 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); >> 2167 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); >> 2168 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); >> 2169 BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, >> 2170 generation, 64); >> 2171 BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); >> 2172 BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, >> 2173 nritems, 32); >> 2174 BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); >> 2175 >> 2176 static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag) >> 2177 { >> 2178 return (btrfs_header_flags(eb) & flag) == flag; >> 2179 } >> 2180 >> 2181 static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) >> 2182 { >> 2183 u64 flags = btrfs_header_flags(eb); >> 2184 btrfs_set_header_flags(eb, flags | flag); >> 2185 } >> 2186 >> 2187 static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) >> 2188 { >> 2189 u64 flags = btrfs_header_flags(eb); >> 2190 btrfs_set_header_flags(eb, flags & ~flag); >> 2191 } >> 2192 >> 2193 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb) >> 2194 { >> 2195 u64 flags = btrfs_header_flags(eb); >> 2196 return flags >> BTRFS_BACKREF_REV_SHIFT; >> 2197 } >> 2198 >> 2199 static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, >> 2200 int rev) >> 2201 { >> 2202 u64 flags = btrfs_header_flags(eb); >> 2203 flags &= ~BTRFS_BACKREF_REV_MASK; >> 2204 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; >> 2205 btrfs_set_header_flags(eb, flags); >> 2206 } >> 2207 >> 2208 static inline unsigned long btrfs_header_fsid(void) >> 2209 { >> 2210 return offsetof(struct btrfs_header, fsid); >> 2211 } >> 2212 >> 2213 static inline unsigned long btrfs_header_chunk_tree_uuid(const struct extent_buffer *eb) >> 2214 { >> 2215 return offsetof(struct btrfs_header, chunk_tree_uuid); >> 2216 } 506 2217 507 int btrfs_bin_search(struct extent_buffer *eb, !! 2218 static inline int btrfs_is_leaf(const struct extent_buffer *eb) 508 const struct btrfs_key *k !! 2219 { >> 2220 return btrfs_header_level(eb) == 0; >> 2221 } 509 2222 510 int __pure btrfs_comp_cpu_keys(const struct bt !! 2223 /* struct btrfs_root_item */ >> 2224 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, >> 2225 generation, 64); >> 2226 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); >> 2227 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); >> 2228 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); >> 2229 >> 2230 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, >> 2231 generation, 64); >> 2232 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); >> 2233 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); >> 2234 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); >> 2235 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); >> 2236 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); >> 2237 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); >> 2238 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); >> 2239 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, >> 2240 last_snapshot, 64); >> 2241 BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, >> 2242 generation_v2, 64); >> 2243 BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, >> 2244 ctransid, 64); >> 2245 BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, >> 2246 otransid, 64); >> 2247 BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, >> 2248 stransid, 64); >> 2249 BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, >> 2250 rtransid, 64); >> 2251 >> 2252 static inline bool btrfs_root_readonly(const struct btrfs_root *root) >> 2253 { >> 2254 return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0; >> 2255 } >> 2256 >> 2257 static inline bool btrfs_root_dead(const struct btrfs_root *root) >> 2258 { >> 2259 return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_DEAD)) != 0; >> 2260 } >> 2261 >> 2262 /* struct btrfs_root_backup */ >> 2263 BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, >> 2264 tree_root, 64); >> 2265 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, >> 2266 tree_root_gen, 64); >> 2267 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, >> 2268 tree_root_level, 8); >> 2269 >> 2270 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, >> 2271 chunk_root, 64); >> 2272 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, >> 2273 chunk_root_gen, 64); >> 2274 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, >> 2275 chunk_root_level, 8); >> 2276 >> 2277 BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, >> 2278 extent_root, 64); >> 2279 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, >> 2280 extent_root_gen, 64); >> 2281 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, >> 2282 extent_root_level, 8); >> 2283 >> 2284 BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, >> 2285 fs_root, 64); >> 2286 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, >> 2287 fs_root_gen, 64); >> 2288 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, >> 2289 fs_root_level, 8); >> 2290 >> 2291 BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, >> 2292 dev_root, 64); >> 2293 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, >> 2294 dev_root_gen, 64); >> 2295 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, >> 2296 dev_root_level, 8); >> 2297 >> 2298 BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, >> 2299 csum_root, 64); >> 2300 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, >> 2301 csum_root_gen, 64); >> 2302 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, >> 2303 csum_root_level, 8); >> 2304 BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, >> 2305 total_bytes, 64); >> 2306 BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, >> 2307 bytes_used, 64); >> 2308 BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, >> 2309 num_devices, 64); >> 2310 >> 2311 /* struct btrfs_balance_item */ >> 2312 BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); >> 2313 >> 2314 static inline void btrfs_balance_data(const struct extent_buffer *eb, >> 2315 const struct btrfs_balance_item *bi, >> 2316 struct btrfs_disk_balance_args *ba) >> 2317 { >> 2318 read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); >> 2319 } >> 2320 >> 2321 static inline void btrfs_set_balance_data(struct extent_buffer *eb, >> 2322 struct btrfs_balance_item *bi, >> 2323 const struct btrfs_disk_balance_args *ba) >> 2324 { >> 2325 write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); >> 2326 } >> 2327 >> 2328 static inline void btrfs_balance_meta(const struct extent_buffer *eb, >> 2329 const struct btrfs_balance_item *bi, >> 2330 struct btrfs_disk_balance_args *ba) >> 2331 { >> 2332 read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); >> 2333 } >> 2334 >> 2335 static inline void btrfs_set_balance_meta(struct extent_buffer *eb, >> 2336 struct btrfs_balance_item *bi, >> 2337 const struct btrfs_disk_balance_args *ba) >> 2338 { >> 2339 write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); >> 2340 } >> 2341 >> 2342 static inline void btrfs_balance_sys(const struct extent_buffer *eb, >> 2343 const struct btrfs_balance_item *bi, >> 2344 struct btrfs_disk_balance_args *ba) >> 2345 { >> 2346 read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); >> 2347 } >> 2348 >> 2349 static inline void btrfs_set_balance_sys(struct extent_buffer *eb, >> 2350 struct btrfs_balance_item *bi, >> 2351 const struct btrfs_disk_balance_args *ba) >> 2352 { >> 2353 write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); >> 2354 } >> 2355 >> 2356 static inline void >> 2357 btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu, >> 2358 const struct btrfs_disk_balance_args *disk) >> 2359 { >> 2360 memset(cpu, 0, sizeof(*cpu)); >> 2361 >> 2362 cpu->profiles = le64_to_cpu(disk->profiles); >> 2363 cpu->usage = le64_to_cpu(disk->usage); >> 2364 cpu->devid = le64_to_cpu(disk->devid); >> 2365 cpu->pstart = le64_to_cpu(disk->pstart); >> 2366 cpu->pend = le64_to_cpu(disk->pend); >> 2367 cpu->vstart = le64_to_cpu(disk->vstart); >> 2368 cpu->vend = le64_to_cpu(disk->vend); >> 2369 cpu->target = le64_to_cpu(disk->target); >> 2370 cpu->flags = le64_to_cpu(disk->flags); >> 2371 cpu->limit = le64_to_cpu(disk->limit); >> 2372 cpu->stripes_min = le32_to_cpu(disk->stripes_min); >> 2373 cpu->stripes_max = le32_to_cpu(disk->stripes_max); >> 2374 } >> 2375 >> 2376 static inline void >> 2377 btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk, >> 2378 const struct btrfs_balance_args *cpu) >> 2379 { >> 2380 memset(disk, 0, sizeof(*disk)); >> 2381 >> 2382 disk->profiles = cpu_to_le64(cpu->profiles); >> 2383 disk->usage = cpu_to_le64(cpu->usage); >> 2384 disk->devid = cpu_to_le64(cpu->devid); >> 2385 disk->pstart = cpu_to_le64(cpu->pstart); >> 2386 disk->pend = cpu_to_le64(cpu->pend); >> 2387 disk->vstart = cpu_to_le64(cpu->vstart); >> 2388 disk->vend = cpu_to_le64(cpu->vend); >> 2389 disk->target = cpu_to_le64(cpu->target); >> 2390 disk->flags = cpu_to_le64(cpu->flags); >> 2391 disk->limit = cpu_to_le64(cpu->limit); >> 2392 disk->stripes_min = cpu_to_le32(cpu->stripes_min); >> 2393 disk->stripes_max = cpu_to_le32(cpu->stripes_max); >> 2394 } >> 2395 >> 2396 /* struct btrfs_super_block */ >> 2397 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); >> 2398 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); >> 2399 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, >> 2400 generation, 64); >> 2401 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); >> 2402 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size, >> 2403 struct btrfs_super_block, sys_chunk_array_size, 32); >> 2404 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, >> 2405 struct btrfs_super_block, chunk_root_generation, 64); >> 2406 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, >> 2407 root_level, 8); >> 2408 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, >> 2409 chunk_root, 64); >> 2410 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, >> 2411 chunk_root_level, 8); >> 2412 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, >> 2413 log_root, 64); >> 2414 BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block, >> 2415 log_root_transid, 64); >> 2416 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, >> 2417 log_root_level, 8); >> 2418 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, >> 2419 total_bytes, 64); >> 2420 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, >> 2421 bytes_used, 64); >> 2422 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, >> 2423 sectorsize, 32); >> 2424 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, >> 2425 nodesize, 32); >> 2426 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, >> 2427 stripesize, 32); >> 2428 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, >> 2429 root_dir_objectid, 64); >> 2430 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, >> 2431 num_devices, 64); >> 2432 BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, >> 2433 compat_flags, 64); >> 2434 BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, >> 2435 compat_ro_flags, 64); >> 2436 BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, >> 2437 incompat_flags, 64); >> 2438 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, >> 2439 csum_type, 16); >> 2440 BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, >> 2441 cache_generation, 64); >> 2442 BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); >> 2443 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, >> 2444 uuid_tree_generation, 64); >> 2445 >> 2446 static inline int btrfs_super_csum_size(const struct btrfs_super_block *s) >> 2447 { >> 2448 u16 t = btrfs_super_csum_type(s); >> 2449 /* >> 2450 * csum type is validated at mount time >> 2451 */ >> 2452 return btrfs_csum_sizes[t]; >> 2453 } 511 2454 512 #ifdef __LITTLE_ENDIAN << 513 2455 514 /* 2456 /* 515 * Compare two keys, on little-endian the disk !! 2457 * The leaf data grows from end-to-front in the node. 516 * we can avoid the conversion. !! 2458 * this returns the address of the start of the last item, >> 2459 * which is the stop of the leaf data stack 517 */ 2460 */ 518 static inline int btrfs_comp_keys(const struct !! 2461 static inline unsigned int leaf_data_end(const struct extent_buffer *leaf) 519 const struct << 520 { 2462 { 521 const struct btrfs_key *k1 = (const st !! 2463 u32 nr = btrfs_header_nritems(leaf); >> 2464 >> 2465 if (nr == 0) >> 2466 return BTRFS_LEAF_DATA_SIZE(leaf->fs_info); >> 2467 return btrfs_item_offset_nr(leaf, nr - 1); >> 2468 } >> 2469 >> 2470 /* struct btrfs_file_extent_item */ >> 2471 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); >> 2472 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, >> 2473 struct btrfs_file_extent_item, disk_bytenr, 64); >> 2474 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, >> 2475 struct btrfs_file_extent_item, offset, 64); >> 2476 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, >> 2477 struct btrfs_file_extent_item, generation, 64); >> 2478 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, >> 2479 struct btrfs_file_extent_item, num_bytes, 64); >> 2480 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, >> 2481 struct btrfs_file_extent_item, disk_num_bytes, 64); >> 2482 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, >> 2483 struct btrfs_file_extent_item, compression, 8); >> 2484 >> 2485 static inline unsigned long >> 2486 btrfs_file_extent_inline_start(const struct btrfs_file_extent_item *e) >> 2487 { >> 2488 return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START; >> 2489 } >> 2490 >> 2491 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) >> 2492 { >> 2493 return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; >> 2494 } >> 2495 >> 2496 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, >> 2497 disk_bytenr, 64); >> 2498 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, >> 2499 generation, 64); >> 2500 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, >> 2501 disk_num_bytes, 64); >> 2502 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, >> 2503 offset, 64); >> 2504 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, >> 2505 num_bytes, 64); >> 2506 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, >> 2507 ram_bytes, 64); >> 2508 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, >> 2509 compression, 8); >> 2510 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, >> 2511 encryption, 8); >> 2512 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, >> 2513 other_encoding, 16); 522 2514 523 return btrfs_comp_cpu_keys(k1, k2); !! 2515 /* >> 2516 * this returns the number of bytes used by the item on disk, minus the >> 2517 * size of any extent headers. If a file is compressed on disk, this is >> 2518 * the compressed size >> 2519 */ >> 2520 static inline u32 btrfs_file_extent_inline_item_len( >> 2521 const struct extent_buffer *eb, >> 2522 struct btrfs_item *e) >> 2523 { >> 2524 return btrfs_item_size(eb, e) - BTRFS_FILE_EXTENT_INLINE_DATA_START; >> 2525 } >> 2526 >> 2527 /* btrfs_dev_stats_item */ >> 2528 static inline u64 btrfs_dev_stats_value(const struct extent_buffer *eb, >> 2529 const struct btrfs_dev_stats_item *ptr, >> 2530 int index) >> 2531 { >> 2532 u64 val; >> 2533 >> 2534 read_extent_buffer(eb, &val, >> 2535 offsetof(struct btrfs_dev_stats_item, values) + >> 2536 ((unsigned long)ptr) + (index * sizeof(u64)), >> 2537 sizeof(val)); >> 2538 return val; >> 2539 } >> 2540 >> 2541 static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb, >> 2542 struct btrfs_dev_stats_item *ptr, >> 2543 int index, u64 val) >> 2544 { >> 2545 write_extent_buffer(eb, &val, >> 2546 offsetof(struct btrfs_dev_stats_item, values) + >> 2547 ((unsigned long)ptr) + (index * sizeof(u64)), >> 2548 sizeof(val)); >> 2549 } >> 2550 >> 2551 /* btrfs_qgroup_status_item */ >> 2552 BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, >> 2553 generation, 64); >> 2554 BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, >> 2555 version, 64); >> 2556 BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, >> 2557 flags, 64); >> 2558 BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, >> 2559 rescan, 64); >> 2560 >> 2561 /* btrfs_qgroup_info_item */ >> 2562 BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, >> 2563 generation, 64); >> 2564 BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); >> 2565 BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, >> 2566 rfer_cmpr, 64); >> 2567 BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); >> 2568 BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, >> 2569 excl_cmpr, 64); >> 2570 >> 2571 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, >> 2572 struct btrfs_qgroup_info_item, generation, 64); >> 2573 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, >> 2574 rfer, 64); >> 2575 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, >> 2576 struct btrfs_qgroup_info_item, rfer_cmpr, 64); >> 2577 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, >> 2578 excl, 64); >> 2579 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, >> 2580 struct btrfs_qgroup_info_item, excl_cmpr, 64); >> 2581 >> 2582 /* btrfs_qgroup_limit_item */ >> 2583 BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, >> 2584 flags, 64); >> 2585 BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, >> 2586 max_rfer, 64); >> 2587 BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, >> 2588 max_excl, 64); >> 2589 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, >> 2590 rsv_rfer, 64); >> 2591 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, >> 2592 rsv_excl, 64); >> 2593 >> 2594 /* btrfs_dev_replace_item */ >> 2595 BTRFS_SETGET_FUNCS(dev_replace_src_devid, >> 2596 struct btrfs_dev_replace_item, src_devid, 64); >> 2597 BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode, >> 2598 struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode, >> 2599 64); >> 2600 BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item, >> 2601 replace_state, 64); >> 2602 BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item, >> 2603 time_started, 64); >> 2604 BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item, >> 2605 time_stopped, 64); >> 2606 BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item, >> 2607 num_write_errors, 64); >> 2608 BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors, >> 2609 struct btrfs_dev_replace_item, num_uncorrectable_read_errors, >> 2610 64); >> 2611 BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item, >> 2612 cursor_left, 64); >> 2613 BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item, >> 2614 cursor_right, 64); >> 2615 >> 2616 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid, >> 2617 struct btrfs_dev_replace_item, src_devid, 64); >> 2618 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode, >> 2619 struct btrfs_dev_replace_item, >> 2620 cont_reading_from_srcdev_mode, 64); >> 2621 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state, >> 2622 struct btrfs_dev_replace_item, replace_state, 64); >> 2623 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started, >> 2624 struct btrfs_dev_replace_item, time_started, 64); >> 2625 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped, >> 2626 struct btrfs_dev_replace_item, time_stopped, 64); >> 2627 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors, >> 2628 struct btrfs_dev_replace_item, num_write_errors, 64); >> 2629 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors, >> 2630 struct btrfs_dev_replace_item, >> 2631 num_uncorrectable_read_errors, 64); >> 2632 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, >> 2633 struct btrfs_dev_replace_item, cursor_left, 64); >> 2634 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, >> 2635 struct btrfs_dev_replace_item, cursor_right, 64); >> 2636 >> 2637 /* helper function to cast into the data area of the leaf. */ >> 2638 #define btrfs_item_ptr(leaf, slot, type) \ >> 2639 ((type *)(BTRFS_LEAF_DATA_OFFSET + \ >> 2640 btrfs_item_offset_nr(leaf, slot))) >> 2641 >> 2642 #define btrfs_item_ptr_offset(leaf, slot) \ >> 2643 ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \ >> 2644 btrfs_item_offset_nr(leaf, slot))) >> 2645 >> 2646 static inline u64 btrfs_name_hash(const char *name, int len) >> 2647 { >> 2648 return crc32c((u32)~1, name, len); 524 } 2649 } 525 2650 526 #else !! 2651 /* >> 2652 * Figure the key offset of an extended inode ref >> 2653 */ >> 2654 static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name, >> 2655 int len) >> 2656 { >> 2657 return (u64) crc32c(parent_objectid, name, len); >> 2658 } 527 2659 528 /* Compare two keys in a memcmp fashion. */ !! 2660 static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info) 529 static inline int btrfs_comp_keys(const struct << 530 const struct << 531 { 2661 { 532 struct btrfs_key k1; !! 2662 return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) && >> 2663 (space_info->flags & BTRFS_BLOCK_GROUP_DATA)); >> 2664 } >> 2665 >> 2666 static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) >> 2667 { >> 2668 return mapping_gfp_constraint(mapping, ~__GFP_FS); >> 2669 } 533 2670 534 btrfs_disk_key_to_cpu(&k1, disk); !! 2671 /* extent-tree.c */ 535 2672 536 return btrfs_comp_cpu_keys(&k1, k2); !! 2673 enum btrfs_inline_ref_type { >> 2674 BTRFS_REF_TYPE_INVALID, >> 2675 BTRFS_REF_TYPE_BLOCK, >> 2676 BTRFS_REF_TYPE_DATA, >> 2677 BTRFS_REF_TYPE_ANY, >> 2678 }; >> 2679 >> 2680 int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb, >> 2681 struct btrfs_extent_inline_ref *iref, >> 2682 enum btrfs_inline_ref_type is_data); >> 2683 >> 2684 u64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes); >> 2685 >> 2686 static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_fs_info *fs_info, >> 2687 unsigned num_items) >> 2688 { >> 2689 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items; 537 } 2690 } 538 2691 539 #endif !! 2692 /* >> 2693 * Doing a truncate won't result in new nodes or leaves, just what we need for >> 2694 * COW. >> 2695 */ >> 2696 static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info, >> 2697 unsigned num_items) >> 2698 { >> 2699 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items; >> 2700 } >> 2701 >> 2702 int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans); >> 2703 bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); >> 2704 void btrfs_dec_block_group_reservations(struct btrfs_fs_info *fs_info, >> 2705 const u64 start); >> 2706 void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg); >> 2707 bool btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr); >> 2708 void btrfs_dec_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr); >> 2709 void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg); >> 2710 void btrfs_put_block_group(struct btrfs_block_group_cache *cache); >> 2711 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, >> 2712 unsigned long count); >> 2713 void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, >> 2714 struct btrfs_delayed_ref_root *delayed_refs, >> 2715 struct btrfs_delayed_ref_head *head); >> 2716 int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len); >> 2717 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, >> 2718 struct btrfs_fs_info *fs_info, u64 bytenr, >> 2719 u64 offset, int metadata, u64 *refs, u64 *flags); >> 2720 int btrfs_pin_extent(struct btrfs_fs_info *fs_info, >> 2721 u64 bytenr, u64 num, int reserved); >> 2722 int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info, >> 2723 u64 bytenr, u64 num_bytes); >> 2724 int btrfs_exclude_logged_extents(struct extent_buffer *eb); >> 2725 int btrfs_cross_ref_exist(struct btrfs_root *root, >> 2726 u64 objectid, u64 offset, u64 bytenr); >> 2727 struct btrfs_block_group_cache *btrfs_lookup_block_group( >> 2728 struct btrfs_fs_info *info, >> 2729 u64 bytenr); >> 2730 void btrfs_get_block_group(struct btrfs_block_group_cache *cache); >> 2731 void btrfs_put_block_group(struct btrfs_block_group_cache *cache); >> 2732 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, >> 2733 struct btrfs_root *root, >> 2734 u64 parent, u64 root_objectid, >> 2735 const struct btrfs_disk_key *key, >> 2736 int level, u64 hint, >> 2737 u64 empty_size); >> 2738 void btrfs_free_tree_block(struct btrfs_trans_handle *trans, >> 2739 struct btrfs_root *root, >> 2740 struct extent_buffer *buf, >> 2741 u64 parent, int last_ref); >> 2742 int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, >> 2743 struct btrfs_root *root, u64 owner, >> 2744 u64 offset, u64 ram_bytes, >> 2745 struct btrfs_key *ins); >> 2746 int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, >> 2747 u64 root_objectid, u64 owner, u64 offset, >> 2748 struct btrfs_key *ins); >> 2749 int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes, >> 2750 u64 min_alloc_size, u64 empty_size, u64 hint_byte, >> 2751 struct btrfs_key *ins, int is_data, int delalloc); >> 2752 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, >> 2753 struct extent_buffer *buf, int full_backref); >> 2754 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, >> 2755 struct extent_buffer *buf, int full_backref); >> 2756 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, >> 2757 u64 bytenr, u64 num_bytes, u64 flags, >> 2758 int level, int is_data); >> 2759 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); >> 2760 >> 2761 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, >> 2762 u64 start, u64 len, int delalloc); >> 2763 int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info, >> 2764 u64 start, u64 len); >> 2765 void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info); >> 2766 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); >> 2767 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, >> 2768 struct btrfs_ref *generic_ref); >> 2769 >> 2770 int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans); >> 2771 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans); >> 2772 int btrfs_setup_space_cache(struct btrfs_trans_handle *trans); >> 2773 int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr); >> 2774 int btrfs_free_block_groups(struct btrfs_fs_info *info); >> 2775 int btrfs_read_block_groups(struct btrfs_fs_info *info); >> 2776 int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr); >> 2777 int btrfs_make_block_group(struct btrfs_trans_handle *trans, >> 2778 u64 bytes_used, u64 type, u64 chunk_offset, >> 2779 u64 size); >> 2780 void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info); >> 2781 struct btrfs_trans_handle *btrfs_start_trans_remove_block_group( >> 2782 struct btrfs_fs_info *fs_info, >> 2783 const u64 chunk_offset); >> 2784 int btrfs_remove_block_group(struct btrfs_trans_handle *trans, >> 2785 u64 group_start, struct extent_map *em); >> 2786 void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info); >> 2787 void btrfs_get_block_group_trimming(struct btrfs_block_group_cache *cache); >> 2788 void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *cache); >> 2789 void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans); >> 2790 u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info); >> 2791 u64 btrfs_metadata_alloc_profile(struct btrfs_fs_info *fs_info); >> 2792 u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info); >> 2793 void btrfs_clear_space_info_full(struct btrfs_fs_info *info); >> 2794 >> 2795 enum btrfs_reserve_flush_enum { >> 2796 /* If we are in the transaction, we can't flush anything.*/ >> 2797 BTRFS_RESERVE_NO_FLUSH, >> 2798 /* >> 2799 * Flushing delalloc may cause deadlock somewhere, in this >> 2800 * case, use FLUSH LIMIT >> 2801 */ >> 2802 BTRFS_RESERVE_FLUSH_LIMIT, >> 2803 BTRFS_RESERVE_FLUSH_ALL, >> 2804 }; >> 2805 >> 2806 enum btrfs_flush_state { >> 2807 FLUSH_DELAYED_ITEMS_NR = 1, >> 2808 FLUSH_DELAYED_ITEMS = 2, >> 2809 FLUSH_DELAYED_REFS_NR = 3, >> 2810 FLUSH_DELAYED_REFS = 4, >> 2811 FLUSH_DELALLOC = 5, >> 2812 FLUSH_DELALLOC_WAIT = 6, >> 2813 ALLOC_CHUNK = 7, >> 2814 ALLOC_CHUNK_FORCE = 8, >> 2815 COMMIT_TRANS = 9, >> 2816 }; >> 2817 >> 2818 int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes); >> 2819 int btrfs_check_data_free_space(struct inode *inode, >> 2820 struct extent_changeset **reserved, u64 start, u64 len); >> 2821 void btrfs_free_reserved_data_space(struct inode *inode, >> 2822 struct extent_changeset *reserved, u64 start, u64 len); >> 2823 void btrfs_delalloc_release_space(struct inode *inode, >> 2824 struct extent_changeset *reserved, >> 2825 u64 start, u64 len, bool qgroup_free); >> 2826 void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start, >> 2827 u64 len); >> 2828 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans); >> 2829 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, >> 2830 struct btrfs_block_rsv *rsv, >> 2831 int nitems, bool use_global_rsv); >> 2832 void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info, >> 2833 struct btrfs_block_rsv *rsv); >> 2834 void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes, >> 2835 bool qgroup_free); >> 2836 >> 2837 int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes); >> 2838 void btrfs_delalloc_release_metadata(struct btrfs_inode *inode, u64 num_bytes, >> 2839 bool qgroup_free); >> 2840 int btrfs_delalloc_reserve_space(struct inode *inode, >> 2841 struct extent_changeset **reserved, u64 start, u64 len); >> 2842 void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type); >> 2843 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info, >> 2844 unsigned short type); >> 2845 void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info, >> 2846 struct btrfs_block_rsv *rsv, >> 2847 unsigned short type); >> 2848 void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info, >> 2849 struct btrfs_block_rsv *rsv); >> 2850 int btrfs_block_rsv_add(struct btrfs_root *root, >> 2851 struct btrfs_block_rsv *block_rsv, u64 num_bytes, >> 2852 enum btrfs_reserve_flush_enum flush); >> 2853 int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor); >> 2854 int btrfs_block_rsv_refill(struct btrfs_root *root, >> 2855 struct btrfs_block_rsv *block_rsv, u64 min_reserved, >> 2856 enum btrfs_reserve_flush_enum flush); >> 2857 int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, >> 2858 struct btrfs_block_rsv *dst_rsv, u64 num_bytes, >> 2859 bool update_size); >> 2860 int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info, >> 2861 struct btrfs_block_rsv *dest, u64 num_bytes, >> 2862 int min_factor); >> 2863 void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info, >> 2864 struct btrfs_block_rsv *block_rsv, >> 2865 u64 num_bytes); >> 2866 void btrfs_delayed_refs_rsv_release(struct btrfs_fs_info *fs_info, int nr); >> 2867 void btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans); >> 2868 int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, >> 2869 enum btrfs_reserve_flush_enum flush); >> 2870 void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info, >> 2871 struct btrfs_block_rsv *src, >> 2872 u64 num_bytes); >> 2873 int btrfs_inc_block_group_ro(struct btrfs_block_group_cache *cache); >> 2874 void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache); >> 2875 void btrfs_put_block_group_cache(struct btrfs_fs_info *info); >> 2876 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); >> 2877 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, >> 2878 u64 start, u64 end); >> 2879 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, >> 2880 u64 num_bytes, u64 *actual_bytes); >> 2881 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type); >> 2882 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); >> 2883 >> 2884 int btrfs_init_space_info(struct btrfs_fs_info *fs_info); >> 2885 int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans, >> 2886 struct btrfs_fs_info *fs_info); >> 2887 int btrfs_start_write_no_snapshotting(struct btrfs_root *root); >> 2888 void btrfs_end_write_no_snapshotting(struct btrfs_root *root); >> 2889 void btrfs_wait_for_snapshot_creation(struct btrfs_root *root); >> 2890 void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type); >> 2891 u64 add_new_free_space(struct btrfs_block_group_cache *block_group, >> 2892 u64 start, u64 end); >> 2893 void btrfs_mark_bg_unused(struct btrfs_block_group_cache *bg); 540 2894 >> 2895 /* ctree.c */ >> 2896 int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, >> 2897 int level, int *slot); >> 2898 int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); 541 int btrfs_previous_item(struct btrfs_root *roo 2899 int btrfs_previous_item(struct btrfs_root *root, 542 struct btrfs_path *pat 2900 struct btrfs_path *path, u64 min_objectid, 543 int type); 2901 int type); 544 int btrfs_previous_extent_item(struct btrfs_ro 2902 int btrfs_previous_extent_item(struct btrfs_root *root, 545 struct btrfs_path *pat 2903 struct btrfs_path *path, u64 min_objectid); 546 void btrfs_set_item_key_safe(struct btrfs_tran !! 2904 void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, 547 const struct btrf !! 2905 struct btrfs_path *path, 548 const struct btrf 2906 const struct btrfs_key *new_key); 549 struct extent_buffer *btrfs_root_node(struct b 2907 struct extent_buffer *btrfs_root_node(struct btrfs_root *root); >> 2908 struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); >> 2909 struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root); 550 int btrfs_find_next_key(struct btrfs_root *roo 2910 int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, 551 struct btrfs_key *key, 2911 struct btrfs_key *key, int lowest_level, 552 u64 min_trans); 2912 u64 min_trans); 553 int btrfs_search_forward(struct btrfs_root *ro 2913 int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, 554 struct btrfs_path *pa 2914 struct btrfs_path *path, 555 u64 min_trans); 2915 u64 min_trans); 556 struct extent_buffer *btrfs_read_node_slot(str !! 2916 enum btrfs_compare_tree_result { 557 int !! 2917 BTRFS_COMPARE_TREE_NEW, 558 !! 2918 BTRFS_COMPARE_TREE_DELETED, >> 2919 BTRFS_COMPARE_TREE_CHANGED, >> 2920 BTRFS_COMPARE_TREE_SAME, >> 2921 }; >> 2922 typedef int (*btrfs_changed_cb_t)(struct btrfs_path *left_path, >> 2923 struct btrfs_path *right_path, >> 2924 struct btrfs_key *key, >> 2925 enum btrfs_compare_tree_result result, >> 2926 void *ctx); >> 2927 int btrfs_compare_trees(struct btrfs_root *left_root, >> 2928 struct btrfs_root *right_root, >> 2929 btrfs_changed_cb_t cb, void *ctx); 559 int btrfs_cow_block(struct btrfs_trans_handle 2930 int btrfs_cow_block(struct btrfs_trans_handle *trans, 560 struct btrfs_root *root, s 2931 struct btrfs_root *root, struct extent_buffer *buf, 561 struct extent_buffer *pare 2932 struct extent_buffer *parent, int parent_slot, 562 struct extent_buffer **cow !! 2933 struct extent_buffer **cow_ret); 563 enum btrfs_lock_nesting ne << 564 int btrfs_force_cow_block(struct btrfs_trans_h << 565 struct btrfs_root *r << 566 struct extent_buffer << 567 struct extent_buffer << 568 struct extent_buffer << 569 u64 search_start, u6 << 570 enum btrfs_lock_nest << 571 int btrfs_copy_root(struct btrfs_trans_handle 2934 int btrfs_copy_root(struct btrfs_trans_handle *trans, 572 struct btrfs_root *root, 2935 struct btrfs_root *root, 573 struct extent_buffer *bu 2936 struct extent_buffer *buf, 574 struct extent_buffer **c 2937 struct extent_buffer **cow_ret, u64 new_root_objectid); 575 bool btrfs_block_can_be_shared(struct btrfs_tr !! 2938 int btrfs_block_can_be_shared(struct btrfs_root *root, 576 struct btrfs_ro !! 2939 struct extent_buffer *buf); 577 struct extent_b !! 2940 void btrfs_extend_item(struct btrfs_path *path, u32 data_size); 578 int btrfs_del_ptr(struct btrfs_trans_handle *t !! 2941 void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end); 579 struct btrfs_path *path, int << 580 void btrfs_extend_item(struct btrfs_trans_hand << 581 const struct btrfs_path << 582 void btrfs_truncate_item(struct btrfs_trans_ha << 583 const struct btrfs_pa << 584 int btrfs_split_item(struct btrfs_trans_handle 2942 int btrfs_split_item(struct btrfs_trans_handle *trans, 585 struct btrfs_root *root, 2943 struct btrfs_root *root, 586 struct btrfs_path *path, 2944 struct btrfs_path *path, 587 const struct btrfs_key *n 2945 const struct btrfs_key *new_key, 588 unsigned long split_offse 2946 unsigned long split_offset); 589 int btrfs_duplicate_item(struct btrfs_trans_ha 2947 int btrfs_duplicate_item(struct btrfs_trans_handle *trans, 590 struct btrfs_root *ro 2948 struct btrfs_root *root, 591 struct btrfs_path *pa 2949 struct btrfs_path *path, 592 const struct btrfs_ke 2950 const struct btrfs_key *new_key); 593 int btrfs_find_item(struct btrfs_root *fs_root 2951 int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, 594 u64 inum, u64 ioff, u8 key_typ 2952 u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); 595 int btrfs_search_slot(struct btrfs_trans_handl 2953 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, 596 const struct btrfs_key * 2954 const struct btrfs_key *key, struct btrfs_path *p, 597 int ins_len, int cow); 2955 int ins_len, int cow); 598 int btrfs_search_old_slot(struct btrfs_root *r 2956 int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key, 599 struct btrfs_path *p 2957 struct btrfs_path *p, u64 time_seq); 600 int btrfs_search_slot_for_read(struct btrfs_ro 2958 int btrfs_search_slot_for_read(struct btrfs_root *root, 601 const struct bt 2959 const struct btrfs_key *key, 602 struct btrfs_pa 2960 struct btrfs_path *p, int find_higher, 603 int return_any) 2961 int return_any); >> 2962 int btrfs_realloc_node(struct btrfs_trans_handle *trans, >> 2963 struct btrfs_root *root, struct extent_buffer *parent, >> 2964 int start_slot, u64 *last_ret, >> 2965 struct btrfs_key *progress); 604 void btrfs_release_path(struct btrfs_path *p); 2966 void btrfs_release_path(struct btrfs_path *p); 605 struct btrfs_path *btrfs_alloc_path(void); 2967 struct btrfs_path *btrfs_alloc_path(void); 606 void btrfs_free_path(struct btrfs_path *p); 2968 void btrfs_free_path(struct btrfs_path *p); 607 DEFINE_FREE(btrfs_free_path, struct btrfs_path !! 2969 void btrfs_set_path_blocking(struct btrfs_path *p); >> 2970 void btrfs_unlock_up_safe(struct btrfs_path *p, int level); 608 2971 609 int btrfs_del_items(struct btrfs_trans_handle 2972 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, 610 struct btrfs_path *path, in 2973 struct btrfs_path *path, int slot, int nr); 611 static inline int btrfs_del_item(struct btrfs_ 2974 static inline int btrfs_del_item(struct btrfs_trans_handle *trans, 612 struct btrfs_ 2975 struct btrfs_root *root, 613 struct btrfs_ 2976 struct btrfs_path *path) 614 { 2977 { 615 return btrfs_del_items(trans, root, pa 2978 return btrfs_del_items(trans, root, path, path->slots[0], 1); 616 } 2979 } 617 2980 618 /* !! 2981 void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, 619 * Describes a batch of items to insert in a b !! 2982 const struct btrfs_key *cpu_key, u32 *data_size, 620 * btrfs_insert_empty_items(). !! 2983 u32 total_data, u32 total_size, int nr); 621 */ << 622 struct btrfs_item_batch { << 623 /* << 624 * Pointer to an array containing the << 625 * sorted order). << 626 */ << 627 const struct btrfs_key *keys; << 628 /* Pointer to an array containing the << 629 const u32 *data_sizes; << 630 /* << 631 * The sum of data sizes for all items << 632 * setting up the data_sizes array, so << 633 * than having btrfs_insert_empty_item << 634 * doing it, as it would avoid an extr << 635 * array, and in the case of setup_ite << 636 * it while holding a write lock on a << 637 * too, unnecessarily increasing the s << 638 */ << 639 u32 total_data_size; << 640 /* Size of the keys and data_sizes arr << 641 int nr; << 642 }; << 643 << 644 void btrfs_setup_item_for_insert(struct btrfs_ << 645 struct btrfs_ << 646 struct btrfs_ << 647 const struct << 648 u32 data_size << 649 int btrfs_insert_item(struct btrfs_trans_handl 2984 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, 650 const struct btrfs_key * 2985 const struct btrfs_key *key, void *data, u32 data_size); 651 int btrfs_insert_empty_items(struct btrfs_tran 2986 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, 652 struct btrfs_root 2987 struct btrfs_root *root, 653 struct btrfs_path 2988 struct btrfs_path *path, 654 const struct btrf !! 2989 const struct btrfs_key *cpu_key, u32 *data_size, >> 2990 int nr); 655 2991 656 static inline int btrfs_insert_empty_item(stru 2992 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, 657 stru 2993 struct btrfs_root *root, 658 stru 2994 struct btrfs_path *path, 659 cons 2995 const struct btrfs_key *key, 660 u32 2996 u32 data_size) 661 { 2997 { 662 struct btrfs_item_batch batch; !! 2998 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1); 663 << 664 batch.keys = key; << 665 batch.data_sizes = &data_size; << 666 batch.total_data_size = data_size; << 667 batch.nr = 1; << 668 << 669 return btrfs_insert_empty_items(trans, << 670 } 2999 } 671 3000 >> 3001 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); >> 3002 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); 672 int btrfs_next_old_leaf(struct btrfs_root *roo 3003 int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path, 673 u64 time_seq); 3004 u64 time_seq); >> 3005 static inline int btrfs_next_old_item(struct btrfs_root *root, >> 3006 struct btrfs_path *p, u64 time_seq) >> 3007 { >> 3008 ++p->slots[0]; >> 3009 if (p->slots[0] >= btrfs_header_nritems(p->nodes[0])) >> 3010 return btrfs_next_old_leaf(root, p, time_seq); >> 3011 return 0; >> 3012 } >> 3013 static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) >> 3014 { >> 3015 return btrfs_next_old_item(root, p, 0); >> 3016 } >> 3017 int btrfs_leaf_free_space(struct extent_buffer *leaf); >> 3018 int __must_check btrfs_drop_snapshot(struct btrfs_root *root, >> 3019 struct btrfs_block_rsv *block_rsv, >> 3020 int update_ref, int for_reloc); >> 3021 int btrfs_drop_subtree(struct btrfs_trans_handle *trans, >> 3022 struct btrfs_root *root, >> 3023 struct extent_buffer *node, >> 3024 struct extent_buffer *parent); >> 3025 static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info) >> 3026 { >> 3027 /* >> 3028 * Do it this way so we only ever do one test_bit in the normal case. >> 3029 */ >> 3030 if (test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags)) { >> 3031 if (test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags)) >> 3032 return 2; >> 3033 return 1; >> 3034 } >> 3035 return 0; >> 3036 } >> 3037 >> 3038 /* >> 3039 * If we remount the fs to be R/O or umount the fs, the cleaner needn't do >> 3040 * anything except sleeping. This function is used to check the status of >> 3041 * the fs. >> 3042 */ >> 3043 static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info) >> 3044 { >> 3045 return fs_info->sb->s_flags & SB_RDONLY || btrfs_fs_closing(fs_info); >> 3046 } >> 3047 >> 3048 static inline void free_fs_info(struct btrfs_fs_info *fs_info) >> 3049 { >> 3050 kfree(fs_info->balance_ctl); >> 3051 kfree(fs_info->delayed_root); >> 3052 kfree(fs_info->extent_root); >> 3053 kfree(fs_info->tree_root); >> 3054 kfree(fs_info->chunk_root); >> 3055 kfree(fs_info->dev_root); >> 3056 kfree(fs_info->csum_root); >> 3057 kfree(fs_info->quota_root); >> 3058 kfree(fs_info->uuid_root); >> 3059 kfree(fs_info->free_space_root); >> 3060 kfree(fs_info->super_copy); >> 3061 kfree(fs_info->super_for_commit); >> 3062 kvfree(fs_info); >> 3063 } >> 3064 >> 3065 /* tree mod log functions from ctree.c */ >> 3066 u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info, >> 3067 struct seq_list *elem); >> 3068 void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info, >> 3069 struct seq_list *elem); >> 3070 int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq); >> 3071 >> 3072 /* root-item.c */ >> 3073 int btrfs_add_root_ref(struct btrfs_trans_handle *trans, u64 root_id, >> 3074 u64 ref_id, u64 dirid, u64 sequence, const char *name, >> 3075 int name_len); >> 3076 int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id, >> 3077 u64 ref_id, u64 dirid, u64 *sequence, const char *name, >> 3078 int name_len); >> 3079 int btrfs_del_root(struct btrfs_trans_handle *trans, >> 3080 const struct btrfs_key *key); >> 3081 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, >> 3082 const struct btrfs_key *key, >> 3083 struct btrfs_root_item *item); >> 3084 int __must_check btrfs_update_root(struct btrfs_trans_handle *trans, >> 3085 struct btrfs_root *root, >> 3086 struct btrfs_key *key, >> 3087 struct btrfs_root_item *item); >> 3088 int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key, >> 3089 struct btrfs_path *path, struct btrfs_root_item *root_item, >> 3090 struct btrfs_key *root_key); >> 3091 int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info); >> 3092 void btrfs_set_root_node(struct btrfs_root_item *item, >> 3093 struct extent_buffer *node); >> 3094 void btrfs_check_and_init_root_item(struct btrfs_root_item *item); >> 3095 void btrfs_update_root_times(struct btrfs_trans_handle *trans, >> 3096 struct btrfs_root *root); >> 3097 >> 3098 /* uuid-tree.c */ >> 3099 int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, >> 3100 u64 subid); >> 3101 int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, >> 3102 u64 subid); >> 3103 int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info, >> 3104 int (*check_func)(struct btrfs_fs_info *, u8 *, u8, >> 3105 u64)); >> 3106 >> 3107 /* dir-item.c */ >> 3108 int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir, >> 3109 const char *name, int name_len); >> 3110 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name, >> 3111 int name_len, struct btrfs_inode *dir, >> 3112 struct btrfs_key *location, u8 type, u64 index); >> 3113 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, >> 3114 struct btrfs_root *root, >> 3115 struct btrfs_path *path, u64 dir, >> 3116 const char *name, int name_len, >> 3117 int mod); >> 3118 struct btrfs_dir_item * >> 3119 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, >> 3120 struct btrfs_root *root, >> 3121 struct btrfs_path *path, u64 dir, >> 3122 u64 objectid, const char *name, int name_len, >> 3123 int mod); >> 3124 struct btrfs_dir_item * >> 3125 btrfs_search_dir_index_item(struct btrfs_root *root, >> 3126 struct btrfs_path *path, u64 dirid, >> 3127 const char *name, int name_len); >> 3128 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, >> 3129 struct btrfs_root *root, >> 3130 struct btrfs_path *path, >> 3131 struct btrfs_dir_item *di); >> 3132 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, >> 3133 struct btrfs_root *root, >> 3134 struct btrfs_path *path, u64 objectid, >> 3135 const char *name, u16 name_len, >> 3136 const void *data, u16 data_len); >> 3137 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, >> 3138 struct btrfs_root *root, >> 3139 struct btrfs_path *path, u64 dir, >> 3140 const char *name, u16 name_len, >> 3141 int mod); >> 3142 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info, >> 3143 struct btrfs_path *path, >> 3144 const char *name, >> 3145 int name_len); >> 3146 >> 3147 /* orphan.c */ >> 3148 int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans, >> 3149 struct btrfs_root *root, u64 offset); >> 3150 int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, >> 3151 struct btrfs_root *root, u64 offset); >> 3152 int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset); >> 3153 >> 3154 /* inode-item.c */ >> 3155 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, >> 3156 struct btrfs_root *root, >> 3157 const char *name, int name_len, >> 3158 u64 inode_objectid, u64 ref_objectid, u64 index); >> 3159 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, >> 3160 struct btrfs_root *root, >> 3161 const char *name, int name_len, >> 3162 u64 inode_objectid, u64 ref_objectid, u64 *index); >> 3163 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, >> 3164 struct btrfs_root *root, >> 3165 struct btrfs_path *path, u64 objectid); >> 3166 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root >> 3167 *root, struct btrfs_path *path, >> 3168 struct btrfs_key *location, int mod); 674 3169 675 int btrfs_search_backwards(struct btrfs_root * !! 3170 struct btrfs_inode_extref * 676 struct btrfs_path * !! 3171 btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans, >> 3172 struct btrfs_root *root, >> 3173 struct btrfs_path *path, >> 3174 const char *name, int name_len, >> 3175 u64 inode_objectid, u64 ref_objectid, int ins_len, >> 3176 int cow); >> 3177 >> 3178 int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot, >> 3179 const char *name, >> 3180 int name_len, struct btrfs_inode_ref **ref_ret); >> 3181 int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot, >> 3182 u64 ref_objectid, const char *name, >> 3183 int name_len, >> 3184 struct btrfs_inode_extref **extref_ret); >> 3185 >> 3186 /* file-item.c */ >> 3187 struct btrfs_dio_private; >> 3188 int btrfs_del_csums(struct btrfs_trans_handle *trans, >> 3189 struct btrfs_fs_info *fs_info, u64 bytenr, u64 len); >> 3190 blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u32 *dst); >> 3191 blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, >> 3192 u64 logical_offset); >> 3193 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, >> 3194 struct btrfs_root *root, >> 3195 u64 objectid, u64 pos, >> 3196 u64 disk_offset, u64 disk_num_bytes, >> 3197 u64 num_bytes, u64 offset, u64 ram_bytes, >> 3198 u8 compression, u8 encryption, u16 other_encoding); >> 3199 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, >> 3200 struct btrfs_root *root, >> 3201 struct btrfs_path *path, u64 objectid, >> 3202 u64 bytenr, int mod); >> 3203 int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, >> 3204 struct btrfs_root *root, >> 3205 struct btrfs_ordered_sum *sums); >> 3206 blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, >> 3207 u64 file_start, int contig); >> 3208 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, >> 3209 struct list_head *list, int search_commit); >> 3210 void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, >> 3211 const struct btrfs_path *path, >> 3212 struct btrfs_file_extent_item *fi, >> 3213 const bool new_inline, >> 3214 struct extent_map *em); >> 3215 >> 3216 /* inode.c */ >> 3217 struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, >> 3218 u64 start, u64 len); >> 3219 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, >> 3220 u64 *orig_start, u64 *orig_block_len, >> 3221 u64 *ram_bytes); >> 3222 >> 3223 void __btrfs_del_delalloc_inode(struct btrfs_root *root, >> 3224 struct btrfs_inode *inode); >> 3225 struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); >> 3226 int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index); >> 3227 int btrfs_unlink_inode(struct btrfs_trans_handle *trans, >> 3228 struct btrfs_root *root, >> 3229 struct btrfs_inode *dir, struct btrfs_inode *inode, >> 3230 const char *name, int name_len); >> 3231 int btrfs_add_link(struct btrfs_trans_handle *trans, >> 3232 struct btrfs_inode *parent_inode, struct btrfs_inode *inode, >> 3233 const char *name, int name_len, int add_backref, u64 index); >> 3234 int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry); >> 3235 int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len, >> 3236 int front); >> 3237 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, >> 3238 struct btrfs_root *root, >> 3239 struct inode *inode, u64 new_size, >> 3240 u32 min_type); 677 3241 678 int btrfs_get_next_valid_item(struct btrfs_roo !! 3242 int btrfs_start_delalloc_snapshot(struct btrfs_root *root); >> 3243 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr); >> 3244 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, >> 3245 unsigned int extra_bits, >> 3246 struct extent_state **cached_state, int dedupe); >> 3247 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, >> 3248 struct btrfs_root *new_root, >> 3249 struct btrfs_root *parent_root, >> 3250 u64 new_dirid); >> 3251 void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state, >> 3252 unsigned *bits); >> 3253 void btrfs_clear_delalloc_extent(struct inode *inode, >> 3254 struct extent_state *state, unsigned *bits); >> 3255 void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new, >> 3256 struct extent_state *other); >> 3257 void btrfs_split_delalloc_extent(struct inode *inode, >> 3258 struct extent_state *orig, u64 split); >> 3259 int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio, >> 3260 unsigned long bio_flags); >> 3261 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end); >> 3262 vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf); >> 3263 int btrfs_readpage(struct file *file, struct page *page); >> 3264 void btrfs_evict_inode(struct inode *inode); >> 3265 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc); >> 3266 struct inode *btrfs_alloc_inode(struct super_block *sb); >> 3267 void btrfs_destroy_inode(struct inode *inode); >> 3268 void btrfs_free_inode(struct inode *inode); >> 3269 int btrfs_drop_inode(struct inode *inode); >> 3270 int __init btrfs_init_cachep(void); >> 3271 void __cold btrfs_destroy_cachep(void); >> 3272 struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location, >> 3273 struct btrfs_root *root, int *new, 679 struct btrfs_pat 3274 struct btrfs_path *path); >> 3275 struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, >> 3276 struct btrfs_root *root, int *was_new); >> 3277 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, >> 3278 struct page *page, size_t pg_offset, >> 3279 u64 start, u64 end, int create); >> 3280 int btrfs_update_inode(struct btrfs_trans_handle *trans, >> 3281 struct btrfs_root *root, >> 3282 struct inode *inode); >> 3283 int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, >> 3284 struct btrfs_root *root, struct inode *inode); >> 3285 int btrfs_orphan_add(struct btrfs_trans_handle *trans, >> 3286 struct btrfs_inode *inode); >> 3287 int btrfs_orphan_cleanup(struct btrfs_root *root); >> 3288 int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size); >> 3289 void btrfs_add_delayed_iput(struct inode *inode); >> 3290 void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info); >> 3291 int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info); >> 3292 int btrfs_prealloc_file_range(struct inode *inode, int mode, >> 3293 u64 start, u64 num_bytes, u64 min_size, >> 3294 loff_t actual_len, u64 *alloc_hint); >> 3295 int btrfs_prealloc_file_range_trans(struct inode *inode, >> 3296 struct btrfs_trans_handle *trans, int mode, >> 3297 u64 start, u64 num_bytes, u64 min_size, >> 3298 loff_t actual_len, u64 *alloc_hint); >> 3299 int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page, >> 3300 u64 start, u64 end, int *page_started, unsigned long *nr_written, >> 3301 struct writeback_control *wbc); >> 3302 int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end); >> 3303 void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start, >> 3304 u64 end, int uptodate); >> 3305 extern const struct dentry_operations btrfs_dentry_operations; >> 3306 >> 3307 /* ioctl.c */ >> 3308 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); >> 3309 long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); >> 3310 int btrfs_ioctl_get_supported_features(void __user *arg); >> 3311 void btrfs_sync_inode_flags_to_i_flags(struct inode *inode); >> 3312 int btrfs_is_empty_uuid(u8 *uuid); >> 3313 int btrfs_defrag_file(struct inode *inode, struct file *file, >> 3314 struct btrfs_ioctl_defrag_range_args *range, >> 3315 u64 newer_than, unsigned long max_pages); >> 3316 void btrfs_get_block_group_info(struct list_head *groups_list, >> 3317 struct btrfs_ioctl_space_info *space); >> 3318 void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info, >> 3319 struct btrfs_ioctl_balance_args *bargs); >> 3320 >> 3321 /* file.c */ >> 3322 int __init btrfs_auto_defrag_init(void); >> 3323 void __cold btrfs_auto_defrag_exit(void); >> 3324 int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, >> 3325 struct btrfs_inode *inode); >> 3326 int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info); >> 3327 void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info); >> 3328 int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); >> 3329 void btrfs_drop_extent_cache(struct btrfs_inode *inode, u64 start, u64 end, >> 3330 int skip_pinned); >> 3331 extern const struct file_operations btrfs_file_operations; >> 3332 int __btrfs_drop_extents(struct btrfs_trans_handle *trans, >> 3333 struct btrfs_root *root, struct inode *inode, >> 3334 struct btrfs_path *path, u64 start, u64 end, >> 3335 u64 *drop_end, int drop_cache, >> 3336 int replace_extent, >> 3337 u32 extent_item_size, >> 3338 int *key_inserted); >> 3339 int btrfs_drop_extents(struct btrfs_trans_handle *trans, >> 3340 struct btrfs_root *root, struct inode *inode, u64 start, >> 3341 u64 end, int drop_cache); >> 3342 int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, >> 3343 struct btrfs_inode *inode, u64 start, u64 end); >> 3344 int btrfs_release_file(struct inode *inode, struct file *file); >> 3345 int btrfs_dirty_pages(struct inode *inode, struct page **pages, >> 3346 size_t num_pages, loff_t pos, size_t write_bytes, >> 3347 struct extent_state **cached); >> 3348 int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); >> 3349 loff_t btrfs_remap_file_range(struct file *file_in, loff_t pos_in, >> 3350 struct file *file_out, loff_t pos_out, >> 3351 loff_t len, unsigned int remap_flags); >> 3352 >> 3353 /* tree-defrag.c */ >> 3354 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, >> 3355 struct btrfs_root *root); >> 3356 >> 3357 /* sysfs.c */ >> 3358 int __init btrfs_init_sysfs(void); >> 3359 void __cold btrfs_exit_sysfs(void); >> 3360 int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info); >> 3361 void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info); >> 3362 >> 3363 /* super.c */ >> 3364 int btrfs_parse_options(struct btrfs_fs_info *info, char *options, >> 3365 unsigned long new_flags); >> 3366 int btrfs_sync_fs(struct super_block *sb, int wait); >> 3367 >> 3368 static inline __printf(2, 3) __cold >> 3369 void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) >> 3370 { >> 3371 } >> 3372 >> 3373 #ifdef CONFIG_PRINTK >> 3374 __printf(2, 3) >> 3375 __cold >> 3376 void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...); >> 3377 #else >> 3378 #define btrfs_printk(fs_info, fmt, args...) \ >> 3379 btrfs_no_printk(fs_info, fmt, ##args) >> 3380 #endif >> 3381 >> 3382 #define btrfs_emerg(fs_info, fmt, args...) \ >> 3383 btrfs_printk(fs_info, KERN_EMERG fmt, ##args) >> 3384 #define btrfs_alert(fs_info, fmt, args...) \ >> 3385 btrfs_printk(fs_info, KERN_ALERT fmt, ##args) >> 3386 #define btrfs_crit(fs_info, fmt, args...) \ >> 3387 btrfs_printk(fs_info, KERN_CRIT fmt, ##args) >> 3388 #define btrfs_err(fs_info, fmt, args...) \ >> 3389 btrfs_printk(fs_info, KERN_ERR fmt, ##args) >> 3390 #define btrfs_warn(fs_info, fmt, args...) \ >> 3391 btrfs_printk(fs_info, KERN_WARNING fmt, ##args) >> 3392 #define btrfs_notice(fs_info, fmt, args...) \ >> 3393 btrfs_printk(fs_info, KERN_NOTICE fmt, ##args) >> 3394 #define btrfs_info(fs_info, fmt, args...) \ >> 3395 btrfs_printk(fs_info, KERN_INFO fmt, ##args) 680 3396 681 /* 3397 /* 682 * Search in @root for a given @key, and store !! 3398 * Wrappers that use printk_in_rcu 683 * << 684 * @root: The root node of the tree. << 685 * @key: The key we are looking for. << 686 * @found_key: Will hold the found item. << 687 * @path: Holds the current slot/leaf. << 688 * @iter_ret: Contains the value returned fr << 689 * btrfs_get_next_valid_item, whi << 690 * << 691 * The @iter_ret is an output variable that wi << 692 * btrfs_search_slot, if it encountered an err << 693 * btrfs_get_next_valid_item otherwise. That r << 694 * slot was found, 1 if there were no more lea << 695 * << 696 * It's recommended to use a separate variable << 697 * set the function return value so there's no << 698 * values stemming from btrfs_search_slot. << 699 */ 3399 */ 700 #define btrfs_for_each_slot(root, key, found_k !! 3400 #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \ 701 for (iter_ret = btrfs_search_slot(NULL !! 3401 btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args) 702 (iter_ret) >= 0 && !! 3402 #define btrfs_alert_in_rcu(fs_info, fmt, args...) \ 703 (iter_ret = btrfs_get_next_val !! 3403 btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args) 704 (path)->slots[0]++ !! 3404 #define btrfs_crit_in_rcu(fs_info, fmt, args...) \ 705 ) !! 3405 btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args) >> 3406 #define btrfs_err_in_rcu(fs_info, fmt, args...) \ >> 3407 btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args) >> 3408 #define btrfs_warn_in_rcu(fs_info, fmt, args...) \ >> 3409 btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args) >> 3410 #define btrfs_notice_in_rcu(fs_info, fmt, args...) \ >> 3411 btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args) >> 3412 #define btrfs_info_in_rcu(fs_info, fmt, args...) \ >> 3413 btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args) 706 3414 707 int btrfs_next_old_item(struct btrfs_root *roo !! 3415 /* >> 3416 * Wrappers that use a ratelimited printk_in_rcu >> 3417 */ >> 3418 #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \ >> 3419 btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args) >> 3420 #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \ >> 3421 btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args) >> 3422 #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \ >> 3423 btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args) >> 3424 #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \ >> 3425 btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args) >> 3426 #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \ >> 3427 btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args) >> 3428 #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \ >> 3429 btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args) >> 3430 #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \ >> 3431 btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args) 708 3432 709 /* 3433 /* 710 * Search the tree again to find a leaf with g !! 3434 * Wrappers that use a ratelimited printk 711 * !! 3435 */ 712 * Returns 0 if it found something or 1 if the !! 3436 #define btrfs_emerg_rl(fs_info, fmt, args...) \ 713 * Returns < 0 on error. !! 3437 btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args) >> 3438 #define btrfs_alert_rl(fs_info, fmt, args...) \ >> 3439 btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args) >> 3440 #define btrfs_crit_rl(fs_info, fmt, args...) \ >> 3441 btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args) >> 3442 #define btrfs_err_rl(fs_info, fmt, args...) \ >> 3443 btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args) >> 3444 #define btrfs_warn_rl(fs_info, fmt, args...) \ >> 3445 btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args) >> 3446 #define btrfs_notice_rl(fs_info, fmt, args...) \ >> 3447 btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args) >> 3448 #define btrfs_info_rl(fs_info, fmt, args...) \ >> 3449 btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args) >> 3450 >> 3451 #if defined(CONFIG_DYNAMIC_DEBUG) >> 3452 #define btrfs_debug(fs_info, fmt, args...) \ >> 3453 _dynamic_func_call_no_desc(fmt, btrfs_printk, \ >> 3454 fs_info, KERN_DEBUG fmt, ##args) >> 3455 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ >> 3456 _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ >> 3457 fs_info, KERN_DEBUG fmt, ##args) >> 3458 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ >> 3459 _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ >> 3460 fs_info, KERN_DEBUG fmt, ##args) >> 3461 #define btrfs_debug_rl(fs_info, fmt, args...) \ >> 3462 _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ >> 3463 fs_info, KERN_DEBUG fmt, ##args) >> 3464 #elif defined(DEBUG) >> 3465 #define btrfs_debug(fs_info, fmt, args...) \ >> 3466 btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) >> 3467 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ >> 3468 btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) >> 3469 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ >> 3470 btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args) >> 3471 #define btrfs_debug_rl(fs_info, fmt, args...) \ >> 3472 btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args) >> 3473 #else >> 3474 #define btrfs_debug(fs_info, fmt, args...) \ >> 3475 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) >> 3476 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ >> 3477 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) >> 3478 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ >> 3479 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) >> 3480 #define btrfs_debug_rl(fs_info, fmt, args...) \ >> 3481 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) >> 3482 #endif >> 3483 >> 3484 #define btrfs_printk_in_rcu(fs_info, fmt, args...) \ >> 3485 do { \ >> 3486 rcu_read_lock(); \ >> 3487 btrfs_printk(fs_info, fmt, ##args); \ >> 3488 rcu_read_unlock(); \ >> 3489 } while (0) >> 3490 >> 3491 #define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \ >> 3492 do { \ >> 3493 rcu_read_lock(); \ >> 3494 btrfs_no_printk(fs_info, fmt, ##args); \ >> 3495 rcu_read_unlock(); \ >> 3496 } while (0) >> 3497 >> 3498 #define btrfs_printk_ratelimited(fs_info, fmt, args...) \ >> 3499 do { \ >> 3500 static DEFINE_RATELIMIT_STATE(_rs, \ >> 3501 DEFAULT_RATELIMIT_INTERVAL, \ >> 3502 DEFAULT_RATELIMIT_BURST); \ >> 3503 if (__ratelimit(&_rs)) \ >> 3504 btrfs_printk(fs_info, fmt, ##args); \ >> 3505 } while (0) >> 3506 >> 3507 #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \ >> 3508 do { \ >> 3509 rcu_read_lock(); \ >> 3510 btrfs_printk_ratelimited(fs_info, fmt, ##args); \ >> 3511 rcu_read_unlock(); \ >> 3512 } while (0) >> 3513 >> 3514 __cold >> 3515 static inline void assfail(const char *expr, const char *file, int line) >> 3516 { >> 3517 if (IS_ENABLED(CONFIG_BTRFS_ASSERT)) { >> 3518 pr_err("assertion failed: %s, file: %s, line: %d\n", >> 3519 expr, file, line); >> 3520 BUG(); >> 3521 } >> 3522 } >> 3523 >> 3524 #define ASSERT(expr) \ >> 3525 (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) >> 3526 >> 3527 /* >> 3528 * Use that for functions that are conditionally exported for sanity tests but >> 3529 * otherwise static 714 */ 3530 */ 715 static inline int btrfs_next_leaf(struct btrfs !! 3531 #ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS >> 3532 #define EXPORT_FOR_TESTS static >> 3533 #else >> 3534 #define EXPORT_FOR_TESTS >> 3535 #endif >> 3536 >> 3537 __cold >> 3538 static inline void btrfs_print_v0_err(struct btrfs_fs_info *fs_info) 716 { 3539 { 717 return btrfs_next_old_leaf(root, path, !! 3540 btrfs_err(fs_info, >> 3541 "Unsupported V0 extent filesystem detected. Aborting. Please re-create your filesystem with a newer kernel"); 718 } 3542 } 719 3543 720 static inline int btrfs_next_item(struct btrfs !! 3544 __printf(5, 6) >> 3545 __cold >> 3546 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function, >> 3547 unsigned int line, int errno, const char *fmt, ...); >> 3548 >> 3549 const char *btrfs_decode_error(int errno); >> 3550 >> 3551 __cold >> 3552 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, >> 3553 const char *function, >> 3554 unsigned int line, int errno); >> 3555 >> 3556 /* >> 3557 * Call btrfs_abort_transaction as early as possible when an error condition is >> 3558 * detected, that way the exact line number is reported. >> 3559 */ >> 3560 #define btrfs_abort_transaction(trans, errno) \ >> 3561 do { \ >> 3562 /* Report first abort since mount */ \ >> 3563 if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ >> 3564 &((trans)->fs_info->fs_state))) { \ >> 3565 if ((errno) != -EIO) { \ >> 3566 WARN(1, KERN_DEBUG \ >> 3567 "BTRFS: Transaction aborted (error %d)\n", \ >> 3568 (errno)); \ >> 3569 } else { \ >> 3570 btrfs_debug((trans)->fs_info, \ >> 3571 "Transaction aborted (error %d)", \ >> 3572 (errno)); \ >> 3573 } \ >> 3574 } \ >> 3575 __btrfs_abort_transaction((trans), __func__, \ >> 3576 __LINE__, (errno)); \ >> 3577 } while (0) >> 3578 >> 3579 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \ >> 3580 do { \ >> 3581 __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \ >> 3582 (errno), fmt, ##args); \ >> 3583 } while (0) >> 3584 >> 3585 __printf(5, 6) >> 3586 __cold >> 3587 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, >> 3588 unsigned int line, int errno, const char *fmt, ...); >> 3589 /* >> 3590 * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic >> 3591 * will panic(). Otherwise we BUG() here. >> 3592 */ >> 3593 #define btrfs_panic(fs_info, errno, fmt, args...) \ >> 3594 do { \ >> 3595 __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \ >> 3596 BUG(); \ >> 3597 } while (0) >> 3598 >> 3599 >> 3600 /* compatibility and incompatibility defines */ >> 3601 >> 3602 #define btrfs_set_fs_incompat(__fs_info, opt) \ >> 3603 __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) >> 3604 >> 3605 static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, >> 3606 u64 flag) >> 3607 { >> 3608 struct btrfs_super_block *disk_super; >> 3609 u64 features; >> 3610 >> 3611 disk_super = fs_info->super_copy; >> 3612 features = btrfs_super_incompat_flags(disk_super); >> 3613 if (!(features & flag)) { >> 3614 spin_lock(&fs_info->super_lock); >> 3615 features = btrfs_super_incompat_flags(disk_super); >> 3616 if (!(features & flag)) { >> 3617 features |= flag; >> 3618 btrfs_set_super_incompat_flags(disk_super, features); >> 3619 btrfs_info(fs_info, "setting %llu feature flag", >> 3620 flag); >> 3621 } >> 3622 spin_unlock(&fs_info->super_lock); >> 3623 } >> 3624 } >> 3625 >> 3626 #define btrfs_clear_fs_incompat(__fs_info, opt) \ >> 3627 __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) >> 3628 >> 3629 static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info, >> 3630 u64 flag) >> 3631 { >> 3632 struct btrfs_super_block *disk_super; >> 3633 u64 features; >> 3634 >> 3635 disk_super = fs_info->super_copy; >> 3636 features = btrfs_super_incompat_flags(disk_super); >> 3637 if (features & flag) { >> 3638 spin_lock(&fs_info->super_lock); >> 3639 features = btrfs_super_incompat_flags(disk_super); >> 3640 if (features & flag) { >> 3641 features &= ~flag; >> 3642 btrfs_set_super_incompat_flags(disk_super, features); >> 3643 btrfs_info(fs_info, "clearing %llu feature flag", >> 3644 flag); >> 3645 } >> 3646 spin_unlock(&fs_info->super_lock); >> 3647 } >> 3648 } >> 3649 >> 3650 #define btrfs_fs_incompat(fs_info, opt) \ >> 3651 __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt) >> 3652 >> 3653 static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag) >> 3654 { >> 3655 struct btrfs_super_block *disk_super; >> 3656 disk_super = fs_info->super_copy; >> 3657 return !!(btrfs_super_incompat_flags(disk_super) & flag); >> 3658 } >> 3659 >> 3660 #define btrfs_set_fs_compat_ro(__fs_info, opt) \ >> 3661 __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) >> 3662 >> 3663 static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, >> 3664 u64 flag) >> 3665 { >> 3666 struct btrfs_super_block *disk_super; >> 3667 u64 features; >> 3668 >> 3669 disk_super = fs_info->super_copy; >> 3670 features = btrfs_super_compat_ro_flags(disk_super); >> 3671 if (!(features & flag)) { >> 3672 spin_lock(&fs_info->super_lock); >> 3673 features = btrfs_super_compat_ro_flags(disk_super); >> 3674 if (!(features & flag)) { >> 3675 features |= flag; >> 3676 btrfs_set_super_compat_ro_flags(disk_super, features); >> 3677 btrfs_info(fs_info, "setting %llu ro feature flag", >> 3678 flag); >> 3679 } >> 3680 spin_unlock(&fs_info->super_lock); >> 3681 } >> 3682 } >> 3683 >> 3684 #define btrfs_clear_fs_compat_ro(__fs_info, opt) \ >> 3685 __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) >> 3686 >> 3687 static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, >> 3688 u64 flag) >> 3689 { >> 3690 struct btrfs_super_block *disk_super; >> 3691 u64 features; >> 3692 >> 3693 disk_super = fs_info->super_copy; >> 3694 features = btrfs_super_compat_ro_flags(disk_super); >> 3695 if (features & flag) { >> 3696 spin_lock(&fs_info->super_lock); >> 3697 features = btrfs_super_compat_ro_flags(disk_super); >> 3698 if (features & flag) { >> 3699 features &= ~flag; >> 3700 btrfs_set_super_compat_ro_flags(disk_super, features); >> 3701 btrfs_info(fs_info, "clearing %llu ro feature flag", >> 3702 flag); >> 3703 } >> 3704 spin_unlock(&fs_info->super_lock); >> 3705 } >> 3706 } >> 3707 >> 3708 #define btrfs_fs_compat_ro(fs_info, opt) \ >> 3709 __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) >> 3710 >> 3711 static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag) >> 3712 { >> 3713 struct btrfs_super_block *disk_super; >> 3714 disk_super = fs_info->super_copy; >> 3715 return !!(btrfs_super_compat_ro_flags(disk_super) & flag); >> 3716 } >> 3717 >> 3718 /* acl.c */ >> 3719 #ifdef CONFIG_BTRFS_FS_POSIX_ACL >> 3720 struct posix_acl *btrfs_get_acl(struct inode *inode, int type); >> 3721 int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type); >> 3722 int btrfs_init_acl(struct btrfs_trans_handle *trans, >> 3723 struct inode *inode, struct inode *dir); >> 3724 #else >> 3725 #define btrfs_get_acl NULL >> 3726 #define btrfs_set_acl NULL >> 3727 static inline int btrfs_init_acl(struct btrfs_trans_handle *trans, >> 3728 struct inode *inode, struct inode *dir) 721 { 3729 { 722 return btrfs_next_old_item(root, p, 0) !! 3730 return 0; 723 } 3731 } 724 int btrfs_leaf_free_space(const struct extent_ !! 3732 #endif >> 3733 >> 3734 /* relocation.c */ >> 3735 int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start); >> 3736 int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, >> 3737 struct btrfs_root *root); >> 3738 int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, >> 3739 struct btrfs_root *root); >> 3740 int btrfs_recover_relocation(struct btrfs_root *root); >> 3741 int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len); >> 3742 int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, >> 3743 struct btrfs_root *root, struct extent_buffer *buf, >> 3744 struct extent_buffer *cow); >> 3745 void btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending, >> 3746 u64 *bytes_to_reserve); >> 3747 int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, >> 3748 struct btrfs_pending_snapshot *pending); >> 3749 >> 3750 /* scrub.c */ >> 3751 int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, >> 3752 u64 end, struct btrfs_scrub_progress *progress, >> 3753 int readonly, int is_dev_replace); >> 3754 void btrfs_scrub_pause(struct btrfs_fs_info *fs_info); >> 3755 void btrfs_scrub_continue(struct btrfs_fs_info *fs_info); >> 3756 int btrfs_scrub_cancel(struct btrfs_fs_info *info); >> 3757 int btrfs_scrub_cancel_dev(struct btrfs_device *dev); >> 3758 int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid, >> 3759 struct btrfs_scrub_progress *progress); >> 3760 static inline void btrfs_init_full_stripe_locks_tree( >> 3761 struct btrfs_full_stripe_locks_tree *locks_root) >> 3762 { >> 3763 locks_root->root = RB_ROOT; >> 3764 mutex_init(&locks_root->lock); >> 3765 } >> 3766 >> 3767 /* dev-replace.c */ >> 3768 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info); >> 3769 void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info); >> 3770 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount); >> 3771 >> 3772 static inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info) >> 3773 { >> 3774 btrfs_bio_counter_sub(fs_info, 1); >> 3775 } >> 3776 >> 3777 /* reada.c */ >> 3778 struct reada_control { >> 3779 struct btrfs_fs_info *fs_info; /* tree to prefetch */ >> 3780 struct btrfs_key key_start; >> 3781 struct btrfs_key key_end; /* exclusive */ >> 3782 atomic_t elems; >> 3783 struct kref refcnt; >> 3784 wait_queue_head_t wait; >> 3785 }; >> 3786 struct reada_control *btrfs_reada_add(struct btrfs_root *root, >> 3787 struct btrfs_key *start, struct btrfs_key *end); >> 3788 int btrfs_reada_wait(void *handle); >> 3789 void btrfs_reada_detach(void *handle); >> 3790 int btree_readahead_hook(struct extent_buffer *eb, int err); 725 3791 726 static inline int is_fstree(u64 rootid) 3792 static inline int is_fstree(u64 rootid) 727 { 3793 { 728 if (rootid == BTRFS_FS_TREE_OBJECTID | 3794 if (rootid == BTRFS_FS_TREE_OBJECTID || 729 ((s64)rootid >= (s64)BTRFS_FIRST_F 3795 ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID && 730 !btrfs_qgroup_level(rootid))) 3796 !btrfs_qgroup_level(rootid))) 731 return 1; 3797 return 1; 732 return 0; 3798 return 0; 733 } 3799 } 734 3800 735 static inline bool btrfs_is_data_reloc_root(co !! 3801 static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) 736 { 3802 { 737 return root->root_key.objectid == BTRF !! 3803 return signal_pending(current); 738 } 3804 } 739 3805 740 u16 btrfs_csum_type_size(u16 type); !! 3806 #define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len)) 741 int btrfs_super_csum_size(const struct btrfs_s << 742 const char *btrfs_super_csum_name(u16 csum_typ << 743 const char *btrfs_super_csum_driver(u16 csum_t << 744 size_t __attribute_const__ btrfs_get_num_csums << 745 3807 746 /* !! 3808 /* Sanity test specific functions */ 747 * We use page status Private2 to indicate the !! 3809 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 748 * unfinished IO. !! 3810 void btrfs_test_inode_set_ops(struct inode *inode); 749 * !! 3811 void btrfs_test_destroy_inode(struct inode *inode); 750 * Rename the Private2 accessors to Ordered, t !! 3812 751 */ !! 3813 static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) 752 #define PageOrdered(page) PagePr !! 3814 { 753 #define SetPageOrdered(page) SetPag !! 3815 return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); 754 #define ClearPageOrdered(page) ClearP !! 3816 } 755 #define folio_test_ordered(folio) folio_ !! 3817 #else 756 #define folio_set_ordered(folio) folio_ !! 3818 static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) 757 #define folio_clear_ordered(folio) folio_ !! 3819 { >> 3820 return 0; >> 3821 } >> 3822 #endif >> 3823 >> 3824 static inline void cond_wake_up(struct wait_queue_head *wq) >> 3825 { >> 3826 /* >> 3827 * This implies a full smp_mb barrier, see comments for >> 3828 * waitqueue_active why. >> 3829 */ >> 3830 if (wq_has_sleeper(wq)) >> 3831 wake_up(wq); >> 3832 } >> 3833 >> 3834 static inline void cond_wake_up_nomb(struct wait_queue_head *wq) >> 3835 { >> 3836 /* >> 3837 * Special case for conditional wakeup where the barrier required for >> 3838 * waitqueue_active is implied by some of the preceding code. Eg. one >> 3839 * of such atomic operations (atomic_dec_and_return, ...), or a >> 3840 * unlock/lock sequence, etc. >> 3841 */ >> 3842 if (waitqueue_active(wq)) >> 3843 wake_up(wq); >> 3844 } 758 3845 759 #endif 3846 #endif 760 3847
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.