Btrfs: Find and remove dead roots the first time a root is loaded.
[deliverable/linux.git] / fs / btrfs / ctree.h
index 4bd648d68e88c85764bb2b72a6be6ec82e255273..6d6e94b63803f79d0d4eb3f27f8245449c84bcc5 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/fs.h>
 #include <linux/buffer_head.h>
 #include <linux/workqueue.h>
+#include <linux/completion.h>
 #include "bit-radix.h"
 
 struct btrfs_trans_handle;
@@ -122,12 +123,12 @@ struct btrfs_super_block {
        u8 fsid[16];    /* FS specific uuid */
        __le64 blocknr; /* this block number */
        __le64 magic;
-       __le32 blocksize;
        __le64 generation;
        __le64 root;
        __le64 total_blocks;
        __le64 blocks_used;
        __le64 root_dir_objectid;
+       __le32 blocksize;
 } __attribute__ ((__packed__));
 
 /*
@@ -177,6 +178,8 @@ struct btrfs_node {
 struct btrfs_path {
        struct buffer_head *nodes[BTRFS_MAX_LEVEL];
        int slots[BTRFS_MAX_LEVEL];
+       int reada;
+       int lowest_level;
 };
 
 /*
@@ -226,10 +229,12 @@ struct btrfs_root_item {
        struct btrfs_inode_item inode;
        __le64 root_dirid;
        __le64 blocknr;
-       __le32 flags;
        __le64 block_limit;
        __le64 blocks_used;
+       __le32 flags;
        __le32 refs;
+       struct btrfs_disk_key drop_progress;
+       u8 drop_level;
 } __attribute__ ((__packed__));
 
 #define BTRFS_FILE_EXTENT_REG 0
@@ -286,10 +291,7 @@ struct btrfs_block_group_cache {
        int cached;
 };
 
-struct crypto_hash;
-
 struct btrfs_fs_info {
-       spinlock_t hash_lock;
        struct btrfs_root *extent_root;
        struct btrfs_root *tree_root;
        struct radix_tree_root fs_roots_radix;
@@ -298,15 +300,12 @@ struct btrfs_fs_info {
        struct radix_tree_root block_group_radix;
        struct radix_tree_root block_group_data_radix;
        struct radix_tree_root extent_map_radix;
-
-       u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3];
-       int extent_tree_insert_nr;
-       u64 extent_tree_prealloc[BTRFS_MAX_LEVEL * 3];
-       int extent_tree_prealloc_nr;
-
+       struct radix_tree_root extent_ins_radix;
        u64 generation;
+       u64 last_trans_committed;
        struct btrfs_transaction *running_transaction;
        struct btrfs_super_block *disk_super;
+       struct btrfs_super_block super_copy;
        struct buffer_head *sb_buffer;
        struct super_block *sb;
        struct inode *btree_inode;
@@ -314,8 +313,9 @@ struct btrfs_fs_info {
        struct mutex fs_mutex;
        struct list_head trans_list;
        struct list_head dead_roots;
-       struct crypto_hash *hash_tfm;
        struct delayed_work trans_work;
+       struct kobject super_kobj;
+       struct completion kobj_unregister;
        int do_barriers;
        int closing;
 };
@@ -331,13 +331,20 @@ struct btrfs_root {
        struct btrfs_key root_key;
        struct btrfs_fs_info *fs_info;
        struct inode *inode;
+       struct kobject root_kobj;
+       struct completion kobj_unregister;
+       struct rw_semaphore snap_sem;
        u64 objectid;
        u64 last_trans;
        u32 blocksize;
-       int ref_cows;
        u32 type;
        u64 highest_inode;
        u64 last_inode_alloc;
+       int ref_cows;
+       struct btrfs_key defrag_progress;
+       int defrag_running;
+       int defrag_level;
+       char *name;
 };
 
 /* the lower bits in the key flags defines the item type */
@@ -804,6 +811,38 @@ static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
        item->refs = cpu_to_le32(val);
 }
 
+static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
+{
+       return le32_to_cpu(item->flags);
+}
+
+static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
+{
+       item->flags = cpu_to_le32(val);
+}
+
+static inline void btrfs_set_root_blocks_used(struct btrfs_root_item *item,
+                                                  u64 val)
+{
+       item->blocks_used = cpu_to_le64(val);
+}
+
+static inline u64 btrfs_root_blocks_used(struct btrfs_root_item *item)
+{
+       return le64_to_cpu(item->blocks_used);
+}
+
+static inline void btrfs_set_root_block_limit(struct btrfs_root_item *item,
+                                               u64 val)
+{
+       item->block_limit = cpu_to_le64(val);
+}
+
+static inline u64 btrfs_root_block_limit(struct btrfs_root_item *item)
+{
+       return le64_to_cpu(item->block_limit);
+}
+
 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
 {
        return le64_to_cpu(s->blocknr);
@@ -1004,10 +1043,21 @@ static inline void btrfs_memmove(struct btrfs_root *root,
        memmove(dst, src, nr);
 }
 
-static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh)
+static inline int btrfs_set_root_name(struct btrfs_root *root,
+                                     const char *name, int len)
 {
-       WARN_ON(!atomic_read(&bh->b_count));
-       mark_buffer_dirty(bh);
+       /* if we already have a name just free it */
+       if (root->name)
+               kfree(root->name);
+
+       root->name = kmalloc(len+1, GFP_KERNEL);
+       if (!root->name)
+               return -ENOMEM;
+
+       memcpy(root->name, name, len);
+       root->name[len] ='\0';
+
+       return 0;
 }
 
 /* helper function to cast into the data area of the leaf. */
@@ -1015,7 +1065,16 @@ static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh)
        ((type *)(btrfs_leaf_data(leaf) + \
        btrfs_item_offset((leaf)->items + (slot))))
 
+/* mount option defines and helpers */
+#define BTRFS_MOUNT_SUBVOL             0x000001
+#define btrfs_clear_opt(o, opt)                o &= ~BTRFS_MOUNT_##opt
+#define btrfs_set_opt(o, opt)          o |= BTRFS_MOUNT_##opt
+#define btrfs_test_opt(sb, opt)                (BTRFS_SB(sb)->s_mount_opt & \
+                                        BTRFS_MOUNT_##opt)
 /* 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);
 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
                                                         btrfs_fs_info *info,
                                                         u64 blocknr);
@@ -1026,17 +1085,19 @@ 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 buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
-                                           struct btrfs_root *root, u64 hint);
+                                           struct btrfs_root *root, u64 hint,
+                                           u64 empty_size);
 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
                       struct btrfs_root *root, u64 owner,
-                      u64 num_blocks, u64 search_start,
+                      u64 num_blocks, 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 buffer_head *buf);
 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
                      *root, u64 blocknr, u64 num_blocks, int pin);
-int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
-                              btrfs_root *root);
+int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
+                              struct btrfs_root *root,
+                              struct radix_tree_root *unpin_radix);
 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
                                u64 blocknr, u64 num_blocks);
@@ -1045,6 +1106,10 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
 int btrfs_free_block_groups(struct btrfs_fs_info *info);
 int btrfs_read_block_groups(struct btrfs_root *root);
 /* ctree.c */
+int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root
+                          *root, struct buffer_head *buf, struct buffer_head
+                          *parent, int parent_slot, struct buffer_head
+                          **cow_ret);
 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
                      *root, struct btrfs_path *path, u32 data_size);
 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
@@ -1054,6 +1119,9 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans,
 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
                      *root, struct btrfs_key *key, struct btrfs_path *p, int
                      ins_len, int cow);
+int btrfs_realloc_node(struct btrfs_trans_handle *trans,
+                      struct btrfs_root *root, struct buffer_head *parent,
+                      int cache_only, u64 *last_ret);
 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);
@@ -1068,7 +1136,7 @@ int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
-                       *root, struct buffer_head *snap);
+                       *root);
 /* root-item.c */
 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                   struct btrfs_key *key);
@@ -1080,6 +1148,8 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
                      *item);
 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
                         btrfs_root_item *item, struct btrfs_key *key);
+int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
+                         struct btrfs_root *latest_root);
 /* dir-item.c */
 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
                          *root, const char *name, int name_len, u64 dir,
@@ -1130,9 +1200,6 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
                          struct btrfs_root *root,
                          u64 objectid, u64 offset,
                          char *data, size_t len);
-int btrfs_csum_verify_file_block(struct btrfs_root *root,
-                                u64 objectid, u64 offset,
-                                char *data, size_t len);
 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
                                          struct btrfs_root *root,
                                          struct btrfs_path *path,
@@ -1142,6 +1209,8 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root, struct btrfs_path *path,
                        u64 isize);
 /* inode.c */
+int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
+int btrfs_readpage(struct file *file, struct page *page);
 void btrfs_delete_inode(struct inode *inode);
 void btrfs_read_locked_inode(struct inode *inode);
 int btrfs_write_inode(struct inode *inode, int wait);
@@ -1160,9 +1229,28 @@ int btrfs_commit_write(struct file *file, struct page *page,
                       unsigned from, unsigned to);
 int btrfs_get_block(struct inode *inode, sector_t iblock,
                    struct buffer_head *result, int create);
+struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
+                                   size_t page_offset, u64 start, u64 end,
+                                   int create);
+int btrfs_update_inode(struct btrfs_trans_handle *trans,
+                             struct btrfs_root *root,
+                             struct inode *inode);
 /* file.c */
+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);
+/* tree-defrag.c */
+int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
+                       struct btrfs_root *root, int cache_only);
+
+/* sysfs.c */
+int btrfs_init_sysfs(void);
+void btrfs_exit_sysfs(void);
+int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
+int btrfs_sysfs_add_root(struct btrfs_root *root);
+void btrfs_sysfs_del_root(struct btrfs_root *root);
+void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
+
 #endif
This page took 0.044693 seconds and 5 git commands to generate.