Btrfs: Fix PAGE_CACHE_SHIFT shifts on 32 bit machines
[linux-2.6-block.git] / fs / btrfs / ctree.h
index c4b8298068556458f4b9775635d28187049eb484..70e143b135779bcf184cdd49936adbe71a83a5e6 100644 (file)
 #ifndef __BTRFS__
 #define __BTRFS__
 
+#include <linux/mm.h>
+#include <linux/highmem.h>
 #include <linux/fs.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
+#include <asm/kmap_types.h>
 #include "bit-radix.h"
 #include "extent_map.h"
 
@@ -95,7 +98,7 @@ struct btrfs_key {
 struct btrfs_header {
        u8 csum[BTRFS_CSUM_SIZE];
        u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
-       __le64 blocknr; /* which block this node is supposed to live in */
+       __le64 bytenr; /* which block this node is supposed to live in */
        __le64 generation;
        __le64 owner;
        __le32 nritems;
@@ -121,16 +124,17 @@ struct btrfs_super_block {
        u8 csum[BTRFS_CSUM_SIZE];
        /* the first 3 fields must match struct btrfs_header */
        u8 fsid[16];    /* FS specific uuid */
-       __le64 blocknr; /* this block number */
+       __le64 bytenr; /* this block number */
        __le64 magic;
        __le64 generation;
        __le64 root;
-       __le64 total_blocks;
-       __le64 blocks_used;
+       __le64 total_bytes;
+       __le64 bytes_used;
        __le64 root_dir_objectid;
        __le32 sectorsize;
        __le32 nodesize;
        __le32 leafsize;
+       u8 root_level;
 } __attribute__ ((__packed__));
 
 /*
@@ -230,13 +234,14 @@ struct btrfs_dir_item {
 struct btrfs_root_item {
        struct btrfs_inode_item inode;
        __le64 root_dirid;
-       __le64 blocknr;
-       __le64 block_limit;
-       __le64 blocks_used;
+       __le64 bytenr;
+       __le64 byte_limit;
+       __le64 bytes_used;
        __le32 flags;
        __le32 refs;
        struct btrfs_disk_key drop_progress;
        u8 drop_level;
+       u8 level;
 } __attribute__ ((__packed__));
 
 #define BTRFS_FILE_EXTENT_REG 0
@@ -249,8 +254,8 @@ struct btrfs_file_extent_item {
         * disk space consumed by the extent, checksum blocks are included
         * in these numbers
         */
-       __le64 disk_blocknr;
-       __le64 disk_num_blocks;
+       __le64 disk_bytenr;
+       __le64 disk_num_bytes;
        /*
         * the logical offset in file blocks (no csums)
         * this extent record is for.  This allows a file extent to point
@@ -262,7 +267,7 @@ struct btrfs_file_extent_item {
        /*
         * the logical number of file blocks (no csums included)
         */
-       __le64 num_blocks;
+       __le64 num_bytes;
 } __attribute__ ((__packed__));
 
 struct btrfs_csum_item {
@@ -270,8 +275,6 @@ struct btrfs_csum_item {
 } __attribute__ ((__packed__));
 
 /* tag for the radix tree of block groups in ram */
-#define BTRFS_BLOCK_GROUP_DIRTY 0
-#define BTRFS_BLOCK_GROUP_AVAIL 1
 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
 
 
@@ -284,11 +287,6 @@ struct btrfs_block_group_item {
 struct btrfs_block_group_cache {
        struct btrfs_key key;
        struct btrfs_block_group_item item;
-       struct radix_tree_root *radix;
-       u64 first_free;
-       u64 last_alloc;
-       u64 pinned;
-       u64 last_prealloc;
        int data;
        int cached;
 };
@@ -298,12 +296,13 @@ struct btrfs_fs_info {
        struct btrfs_root *extent_root;
        struct btrfs_root *tree_root;
        struct radix_tree_root fs_roots_radix;
-       struct radix_tree_root pending_del_radix;
-       struct radix_tree_root pinned_radix;
-       struct radix_tree_root block_group_radix;
-       struct radix_tree_root block_group_data_radix;
-       struct radix_tree_root extent_map_radix;
-       struct radix_tree_root extent_ins_radix;
+
+       struct extent_map_tree free_space_cache;
+       struct extent_map_tree block_group_cache;
+       struct extent_map_tree pinned_extents;
+       struct extent_map_tree pending_del;
+       struct extent_map_tree extent_ins;
+
        u64 generation;
        u64 last_trans_committed;
        struct btrfs_transaction *running_transaction;
@@ -311,9 +310,11 @@ struct btrfs_fs_info {
        struct extent_buffer *sb_buffer;
        struct super_block *sb;
        struct inode *btree_inode;
+       spinlock_t hash_lock;
        struct mutex trans_mutex;
        struct mutex fs_mutex;
        struct list_head trans_list;
+       struct list_head hashers;
        struct list_head dead_roots;
        struct delayed_work trans_work;
        struct kobject super_kobj;
@@ -427,33 +428,31 @@ struct btrfs_root {
                            offsetof(type, member),                     \
                           sizeof(((type *)0)->member)))
 
+#ifndef BTRFS_SETGET_FUNCS
 #define BTRFS_SETGET_FUNCS(name, type, member, bits)                   \
-static inline u##bits btrfs_##name(struct extent_buffer *eb,           \
-                                  type *s)                             \
-{                                                                      \
-       __le##bits res;                                                 \
-       read_eb_member(eb, s, type, member, &res);                      \
-       return le##bits##_to_cpu(res);                                  \
-}                                                                      \
-static inline void btrfs_set_##name(struct extent_buffer *eb,          \
-                                   type *s, u##bits val)               \
-{                                                                      \
-       val = cpu_to_le##bits(val);                                     \
-       write_eb_member(eb, s, type, member, &val);                     \
-}
+u##bits btrfs_##name(struct extent_buffer *eb, type *s);               \
+void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
+#endif
 
 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits)            \
 static inline u##bits btrfs_##name(struct extent_buffer *eb)           \
 {                                                                      \
-       __le##bits res;                                                 \
-       read_eb_member(eb, NULL, type, member, &res);                   \
-       return le##bits##_to_cpu(res);                                  \
+       char *kaddr = kmap_atomic(eb->first_page, KM_USER0);            \
+       unsigned long offset = offsetof(type, member);                  \
+       u##bits res;                                                    \
+       __le##bits *tmp = (__le##bits *)(kaddr + offset);               \
+       res = le##bits##_to_cpu(*tmp);                                  \
+       kunmap_atomic(kaddr, KM_USER0);                                 \
+       return res;                                                     \
 }                                                                      \
 static inline void btrfs_set_##name(struct extent_buffer *eb,          \
                                    u##bits val)                        \
 {                                                                      \
-       val = cpu_to_le##bits(val);                                     \
-       write_eb_member(eb, NULL, type, member, &val);                  \
+       char *kaddr = kmap_atomic(eb->first_page, KM_USER0);            \
+       unsigned long offset = offsetof(type, member);                  \
+       __le##bits *tmp = (__le##bits *)(kaddr + offset);               \
+       *tmp = cpu_to_le##bits(val);                                    \
+       kunmap_atomic(kaddr, KM_USER0);                                 \
 }
 
 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits)             \
@@ -523,12 +522,12 @@ BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32);
 
 /* struct btrfs_extent_item */
 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
-BTRFS_SETGET_FUNCS(extent_owner, struct btrfs_extent_item, owner, 32);
+BTRFS_SETGET_FUNCS(extent_owner, struct btrfs_extent_item, owner, 64);
 
 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
                         refs, 32);
 BTRFS_SETGET_STACK_FUNCS(stack_extent_owner, struct btrfs_extent_item,
-                        owner, 32);
+                        owner, 64);
 
 /* struct btrfs_node */
 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
@@ -550,13 +549,13 @@ static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
        btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
 }
 
-static unsigned long btrfs_node_key_ptr_offset(int nr)
+static inline unsigned long btrfs_node_key_ptr_offset(int nr)
 {
        return offsetof(struct btrfs_node, ptrs) +
                sizeof(struct btrfs_key_ptr) * nr;
 }
 
-static void btrfs_node_key(struct extent_buffer *eb,
+static inline void btrfs_node_key(struct extent_buffer *eb,
                           struct btrfs_disk_key *disk_key, int nr)
 {
        unsigned long ptr;
@@ -702,7 +701,7 @@ static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
 }
 
 /* struct btrfs_header */
-BTRFS_SETGET_HEADER_FUNCS(header_blocknr, struct btrfs_header, blocknr, 64);
+BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
                          generation, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
@@ -750,24 +749,28 @@ static inline int btrfs_is_leaf(struct extent_buffer *eb)
 
 /* struct btrfs_root_item */
 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
-BTRFS_SETGET_FUNCS(disk_root_blocknr, struct btrfs_root_item, blocknr, 64);
+BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
+BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
 
-BTRFS_SETGET_STACK_FUNCS(root_blocknr, struct btrfs_root_item, blocknr, 64);
+BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
+BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
-BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, blocks_used, 64);
-BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, block_limit, 64);
+BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
+BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
 
 /* struct btrfs_super_block */
-BTRFS_SETGET_STACK_FUNCS(super_blocknr, struct btrfs_super_block, blocknr, 64);
+BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
                         generation, 64);
 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
-BTRFS_SETGET_STACK_FUNCS(super_total_blocks, struct btrfs_super_block,
-                  total_blocks, 64);
-BTRFS_SETGET_STACK_FUNCS(super_blocks_used, struct btrfs_super_block,
-                  blocks_used, 64);
+BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
+                        root_level, 8);
+BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
+                        total_bytes, 64);
+BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
+                        bytes_used, 64);
 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
                         sectorsize, 32);
 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
@@ -789,33 +792,33 @@ static inline unsigned long btrfs_file_extent_inline_start(struct
                                                   btrfs_file_extent_item *e)
 {
        unsigned long offset = (unsigned long)e;
-       offset += offsetof(struct btrfs_file_extent_item, disk_blocknr);
+       offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
        return offset;
 }
 
 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
 {
-       return offsetof(struct btrfs_file_extent_item, disk_blocknr) + datasize;
+       return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
 }
 
 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
                                               struct btrfs_item *e)
 {
        unsigned long offset;
-       offset = offsetof(struct btrfs_file_extent_item, disk_blocknr);
+       offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
        return btrfs_item_size(eb, e) - offset;
 }
 
-BTRFS_SETGET_FUNCS(file_extent_disk_blocknr, struct btrfs_file_extent_item,
-                  disk_blocknr, 64);
+BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
+                  disk_bytenr, 64);
 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
                   generation, 64);
-BTRFS_SETGET_FUNCS(file_extent_disk_num_blocks, struct btrfs_file_extent_item,
-                  disk_num_blocks, 64);
+BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
+                  disk_num_bytes, 64);
 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
                  offset, 64);
-BTRFS_SETGET_FUNCS(file_extent_num_blocks, struct btrfs_file_extent_item,
-                  num_blocks, 64);
+BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
+                  num_bytes, 64);
 
 static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
 {
@@ -839,6 +842,12 @@ static inline int btrfs_set_root_name(struct btrfs_root *root,
        return 0;
 }
 
+static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
+       if (level == 0)
+               return root->leafsize;
+       return root->nodesize;
+}
+
 /* helper function to cast into the data area of the leaf. */
 #define btrfs_item_ptr(leaf, slot, type) \
        ((type *)(btrfs_leaf_data(leaf) + \
@@ -857,10 +866,10 @@ static inline int btrfs_set_root_name(struct btrfs_root *root,
 /* extent-tree.c */
 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
                         struct btrfs_root *root);
-int btrfs_copy_pinned(struct btrfs_root *root, struct radix_tree_root *copy);
+int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy);
 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
                                                         btrfs_fs_info *info,
-                                                        u64 blocknr);
+                                                        u64 bytenr);
 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
                                                 struct btrfs_block_group_cache
                                                 *hint, u64 search_start,
@@ -868,22 +877,22 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
                       struct btrfs_root *root);
 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
-                                           struct btrfs_root *root, u64 hint,
-                                           u64 empty_size);
+                                           struct btrfs_root *root, u32 size,
+                                           u64 hint, u64 empty_size);
 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
                       struct btrfs_root *root, u64 owner,
-                      u64 num_blocks, u64 empty_size, u64 search_start,
+                      u64 num_bytes, u64 empty_size, u64 search_start,
                       u64 search_end, struct btrfs_key *ins, int data);
 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                  struct extent_buffer *buf);
 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
-                     *root, u64 blocknr, u64 num_blocks, int pin);
+                     *root, u64 bytenr, u64 num_bytes, int pin);
 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
                               struct btrfs_root *root,
-                              struct radix_tree_root *unpin_radix);
+                              struct extent_map_tree *unpin);
 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
-                               u64 blocknr, u64 num_blocks);
+                               u64 bytenr, u64 num_bytes);
 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
                                    struct btrfs_root *root);
 int btrfs_free_block_groups(struct btrfs_fs_info *info);
@@ -904,7 +913,8 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
                      ins_len, int cow);
 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
                       struct btrfs_root *root, struct extent_buffer *parent,
-                      int cache_only, u64 *last_ret);
+                      int start_slot, int cache_only, u64 *last_ret,
+                      struct btrfs_key *progress);
 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
 struct btrfs_path *btrfs_alloc_path(void);
 void btrfs_free_path(struct btrfs_path *p);
@@ -973,14 +983,15 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
                               struct btrfs_root *root,
                               u64 objectid, u64 pos, u64 offset,
-                              u64 disk_num_blocks,
-                              u64 num_blocks);
+                              u64 disk_num_bytes,
+                              u64 num_bytes);
 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root,
                             struct btrfs_path *path, u64 objectid,
-                            u64 blocknr, int mod);
+                            u64 bytenr, int mod);
 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
                          struct btrfs_root *root,
+                         struct inode *inode,
                          u64 objectid, u64 offset,
                          char *data, size_t len);
 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
@@ -1018,7 +1029,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
 extern struct file_operations btrfs_file_operations;
 int btrfs_drop_extents(struct btrfs_trans_handle *trans,
                       struct btrfs_root *root, struct inode *inode,
-                      u64 start, u64 end, u64 *hint_block);
+                      u64 start, u64 end, u64 inline_end, u64 *hint_block);
 /* tree-defrag.c */
 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root, int cache_only);