"Fossies" - the Fresh Open Source Software Archive

Member "btrfs-progs-v5.4.1/extent_io.h" (9 Jan 2020, 6507 Bytes) of package /linux/misc/btrfs-progs-v5.4.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "extent_io.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: v5.4_vs_v5.4.1.

    1 /*
    2  * Copyright (C) 2007 Oracle.  All rights reserved.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public
    6  * License v2 as published by the Free Software Foundation.
    7  *
    8  * This program is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11  * General Public License for more details.
   12  *
   13  * You should have received a copy of the GNU General Public
   14  * License along with this program; if not, write to the
   15  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   16  * Boston, MA 021110-1307, USA.
   17  */
   18 
   19 #ifndef __BTRFS_EXTENT_IO_H__
   20 #define __BTRFS_EXTENT_IO_H__
   21 
   22 #if BTRFS_FLAT_INCLUDES
   23 #include "kerncompat.h"
   24 #include "extent-cache.h"
   25 #include "kernel-lib/list.h"
   26 #else
   27 #include <btrfs/kerncompat.h>
   28 #include <btrfs/extent-cache.h>
   29 #include <btrfs/list.h>
   30 #endif /* BTRFS_FLAT_INCLUDES */
   31 
   32 #define EXTENT_DIRTY        (1U << 0)
   33 #define EXTENT_WRITEBACK    (1U << 1)
   34 #define EXTENT_UPTODATE     (1U << 2)
   35 #define EXTENT_LOCKED       (1U << 3)
   36 #define EXTENT_NEW      (1U << 4)
   37 #define EXTENT_DELALLOC     (1U << 5)
   38 #define EXTENT_DEFRAG       (1U << 6)
   39 #define EXTENT_DEFRAG_DONE  (1U << 7)
   40 #define EXTENT_BUFFER_FILLED    (1U << 8)
   41 #define EXTENT_CSUM     (1U << 9)
   42 #define EXTENT_BAD_TRANSID  (1U << 10)
   43 #define EXTENT_BUFFER_DUMMY (1U << 11)
   44 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
   45 
   46 #define BLOCK_GROUP_DATA    (1U << 1)
   47 #define BLOCK_GROUP_METADATA    (1U << 2)
   48 #define BLOCK_GROUP_SYSTEM  (1U << 4)
   49 
   50 #define BLOCK_GROUP_DIRTY   (1U)
   51 
   52 /*
   53  * The extent buffer bitmap operations are done with byte granularity instead of
   54  * word granularity for two reasons:
   55  * 1. The bitmaps must be little-endian on disk.
   56  * 2. Bitmap items are not guaranteed to be aligned to a word and therefore a
   57  *    single word in a bitmap may straddle two pages in the extent buffer.
   58  */
   59 #define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE)
   60 #define BYTE_MASK ((1 << BITS_PER_BYTE) - 1)
   61 #define BITMAP_FIRST_BYTE_MASK(start) \
   62     ((BYTE_MASK << ((start) & (BITS_PER_BYTE - 1))) & BYTE_MASK)
   63 #define BITMAP_LAST_BYTE_MASK(nbits) \
   64     (BYTE_MASK >> (-(nbits) & (BITS_PER_BYTE - 1)))
   65 
   66 static inline int le_test_bit(int nr, const u8 *addr)
   67 {
   68     return 1U & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE-1)));
   69 }
   70 
   71 struct btrfs_fs_info;
   72 
   73 struct extent_io_tree {
   74     struct cache_tree state;
   75     struct cache_tree cache;
   76     struct list_head lru;
   77     u64 cache_size;
   78     u64 max_cache_size;
   79 };
   80 
   81 struct extent_state {
   82     struct cache_extent cache_node;
   83     u64 start;
   84     u64 end;
   85     int refs;
   86     unsigned long state;
   87     u64 xprivate;
   88 };
   89 
   90 struct extent_buffer {
   91     struct cache_extent cache_node;
   92     u64 start;
   93     u64 dev_bytenr;
   94     struct extent_io_tree *tree;
   95     struct list_head lru;
   96     struct list_head recow;
   97     u32 len;
   98     int refs;
   99     u32 flags;
  100     int fd;
  101     struct btrfs_fs_info *fs_info;
  102     char data[] __attribute__((aligned(8)));
  103 };
  104 
  105 static inline void extent_buffer_get(struct extent_buffer *eb)
  106 {
  107     eb->refs++;
  108 }
  109 
  110 void extent_io_tree_init(struct extent_io_tree *tree);
  111 void extent_io_tree_init_cache_max(struct extent_io_tree *tree,
  112                    u64 max_cache_size);
  113 void extent_io_tree_cleanup(struct extent_io_tree *tree);
  114 int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, int bits);
  115 int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, int bits);
  116 int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
  117               u64 *start_ret, u64 *end_ret, int bits);
  118 int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
  119            int bits, int filled);
  120 int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end);
  121 int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end);
  122 static inline int set_extent_buffer_uptodate(struct extent_buffer *eb)
  123 {
  124     eb->flags |= EXTENT_UPTODATE;
  125     return 0;
  126 }
  127 
  128 static inline int clear_extent_buffer_uptodate(struct extent_buffer *eb)
  129 {
  130     eb->flags &= ~EXTENT_UPTODATE;
  131     return 0;
  132 }
  133 
  134 static inline int extent_buffer_uptodate(struct extent_buffer *eb)
  135 {
  136     if (!eb || IS_ERR(eb))
  137         return 0;
  138     if (eb->flags & EXTENT_UPTODATE)
  139         return 1;
  140     return 0;
  141 }
  142 
  143 int set_state_private(struct extent_io_tree *tree, u64 start, u64 xprivate);
  144 int get_state_private(struct extent_io_tree *tree, u64 start, u64 *xprivate);
  145 struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
  146                      u64 bytenr, u32 blocksize);
  147 struct extent_buffer *find_first_extent_buffer(struct extent_io_tree *tree,
  148                            u64 start);
  149 struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
  150                       u64 bytenr, u32 blocksize);
  151 struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
  152 struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
  153                         u64 bytenr, u32 blocksize);
  154 void free_extent_buffer(struct extent_buffer *eb);
  155 void free_extent_buffer_nocache(struct extent_buffer *eb);
  156 int read_extent_from_disk(struct extent_buffer *eb,
  157               unsigned long offset, unsigned long len);
  158 int write_extent_to_disk(struct extent_buffer *eb);
  159 int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
  160              unsigned long start, unsigned long len);
  161 void read_extent_buffer(const struct extent_buffer *eb, void *dst,
  162             unsigned long start, unsigned long len);
  163 void write_extent_buffer(struct extent_buffer *eb, const void *src,
  164              unsigned long start, unsigned long len);
  165 void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
  166             unsigned long dst_offset, unsigned long src_offset,
  167             unsigned long len);
  168 void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
  169                unsigned long src_offset, unsigned long len);
  170 void memset_extent_buffer(struct extent_buffer *eb, char c,
  171               unsigned long start, unsigned long len);
  172 int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start,
  173                unsigned long nr);
  174 int set_extent_buffer_dirty(struct extent_buffer *eb);
  175 int clear_extent_buffer_dirty(struct extent_buffer *eb);
  176 int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
  177             u64 bytes, int mirror);
  178 int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
  179                u64 bytes, int mirror);
  180 void extent_buffer_bitmap_clear(struct extent_buffer *eb, unsigned long start,
  181                                 unsigned long pos, unsigned long len);
  182 void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start,
  183                               unsigned long pos, unsigned long len);
  184 
  185 #endif