Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef BTRFS_EXTENT_MAP_H
0004 #define BTRFS_EXTENT_MAP_H
0005 
0006 #include <linux/rbtree.h>
0007 #include <linux/refcount.h>
0008 
0009 #define EXTENT_MAP_LAST_BYTE ((u64)-4)
0010 #define EXTENT_MAP_HOLE ((u64)-3)
0011 #define EXTENT_MAP_INLINE ((u64)-2)
0012 /* used only during fiemap calls */
0013 #define EXTENT_MAP_DELALLOC ((u64)-1)
0014 
0015 /* bits for the extent_map::flags field */
0016 enum {
0017     /* this entry not yet on disk, don't free it */
0018     EXTENT_FLAG_PINNED,
0019     EXTENT_FLAG_COMPRESSED,
0020     /* pre-allocated extent */
0021     EXTENT_FLAG_PREALLOC,
0022     /* Logging this extent */
0023     EXTENT_FLAG_LOGGING,
0024     /* Filling in a preallocated extent */
0025     EXTENT_FLAG_FILLING,
0026     /* filesystem extent mapping type */
0027     EXTENT_FLAG_FS_MAPPING,
0028     /* This em is merged from two or more physically adjacent ems */
0029     EXTENT_FLAG_MERGED,
0030 };
0031 
0032 struct extent_map {
0033     struct rb_node rb_node;
0034 
0035     /* all of these are in bytes */
0036     u64 start;
0037     u64 len;
0038     u64 mod_start;
0039     u64 mod_len;
0040     u64 orig_start;
0041     u64 orig_block_len;
0042     u64 ram_bytes;
0043     u64 block_start;
0044     u64 block_len;
0045 
0046     /*
0047      * Generation of the extent map, for merged em it's the highest
0048      * generation of all merged ems.
0049      * For non-merged extents, it's from btrfs_file_extent_item::generation.
0050      */
0051     u64 generation;
0052     unsigned long flags;
0053     /* Used for chunk mappings, flag EXTENT_FLAG_FS_MAPPING must be set */
0054     struct map_lookup *map_lookup;
0055     refcount_t refs;
0056     unsigned int compress_type;
0057     struct list_head list;
0058 };
0059 
0060 struct extent_map_tree {
0061     struct rb_root_cached map;
0062     struct list_head modified_extents;
0063     rwlock_t lock;
0064 };
0065 
0066 static inline int extent_map_in_tree(const struct extent_map *em)
0067 {
0068     return !RB_EMPTY_NODE(&em->rb_node);
0069 }
0070 
0071 static inline u64 extent_map_end(struct extent_map *em)
0072 {
0073     if (em->start + em->len < em->start)
0074         return (u64)-1;
0075     return em->start + em->len;
0076 }
0077 
0078 static inline u64 extent_map_block_end(struct extent_map *em)
0079 {
0080     if (em->block_start + em->block_len < em->block_start)
0081         return (u64)-1;
0082     return em->block_start + em->block_len;
0083 }
0084 
0085 void extent_map_tree_init(struct extent_map_tree *tree);
0086 struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
0087                      u64 start, u64 len);
0088 int add_extent_mapping(struct extent_map_tree *tree,
0089                struct extent_map *em, int modified);
0090 void remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
0091 void replace_extent_mapping(struct extent_map_tree *tree,
0092                 struct extent_map *cur,
0093                 struct extent_map *new,
0094                 int modified);
0095 
0096 struct extent_map *alloc_extent_map(void);
0097 void free_extent_map(struct extent_map *em);
0098 int __init extent_map_init(void);
0099 void __cold extent_map_exit(void);
0100 int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, u64 gen);
0101 void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em);
0102 struct extent_map *search_extent_mapping(struct extent_map_tree *tree,
0103                      u64 start, u64 len);
0104 int btrfs_add_extent_mapping(struct btrfs_fs_info *fs_info,
0105                  struct extent_map_tree *em_tree,
0106                  struct extent_map **em_in, u64 start, u64 len);
0107 
0108 #endif