Btrfs: Find and remove dead roots the first time a root is loaded.
[deliverable/linux.git] / fs / btrfs / ctree.h
index 756ea9d0123b0e4978aaeac6ce20178bbb2f5da3..6d6e94b63803f79d0d4eb3f27f8245449c84bcc5 100644 (file)
@@ -1,9 +1,28 @@
+/*
+ * Copyright (C) 2007 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
 #ifndef __BTRFS__
 #define __BTRFS__
 
 #include <linux/fs.h>
 #include <linux/buffer_head.h>
-#include <linux/kobject.h>
+#include <linux/workqueue.h>
+#include <linux/completion.h>
 #include "bit-radix.h"
 
 struct btrfs_trans_handle;
@@ -16,11 +35,10 @@ extern struct kmem_cache *btrfs_path_cachep;
 #define BTRFS_MAGIC "_BtRfS_M"
 
 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
-#define BTRFS_DEV_TREE_OBJECTID 2ULL
-#define BTRFS_EXTENT_TREE_OBJECTID 3ULL
-#define BTRFS_FS_TREE_OBJECTID 4ULL
-#define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
-#define BTRFS_FIRST_FREE_OBJECTID 6ULL
+#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
+#define BTRFS_FS_TREE_OBJECTID 3ULL
+#define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
+#define BTRFS_FIRST_FREE_OBJECTID 5ULL
 
 /*
  * we can actually store much bigger names, but lets not confuse the rest
@@ -34,6 +52,16 @@ extern struct kmem_cache *btrfs_path_cachep;
 #define BTRFS_CRC32_SIZE 4
 #define BTRFS_EMPTY_DIR_SIZE 6
 
+#define BTRFS_FT_UNKNOWN       0
+#define BTRFS_FT_REG_FILE      1
+#define BTRFS_FT_DIR           2
+#define BTRFS_FT_CHRDEV                3
+#define BTRFS_FT_BLKDEV                4
+#define BTRFS_FT_FIFO          5
+#define BTRFS_FT_SOCK          6
+#define BTRFS_FT_SYMLINK       7
+#define BTRFS_FT_MAX           8
+
 /*
  * the key defines the order in the tree, and so it also defines (optimal)
  * block layout.  objectid corresonds to the inode number.  The flags
@@ -95,18 +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;
-       __le64 last_device_id;
-       /* fields below here vary with the underlying disk */
-       __le64 device_block_start;
-       __le64 device_num_blocks;
-       __le64 device_root;
-       __le64 device_id;
+       __le32 blocksize;
 } __attribute__ ((__packed__));
 
 /*
@@ -156,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;
 };
 
 /*
@@ -205,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
@@ -241,18 +267,16 @@ struct btrfs_csum_item {
        u8 csum;
 } __attribute__ ((__packed__));
 
-struct btrfs_device_item {
-       __le16 pathlen;
-       __le64 device_id;
-} __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_HINTS 8
 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
+
+
+#define BTRFS_BLOCK_GROUP_DATA 1
 struct btrfs_block_group_item {
        __le64 used;
+       u8 flags;
 } __attribute__ ((__packed__));
 
 struct btrfs_block_group_cache {
@@ -267,37 +291,33 @@ struct btrfs_block_group_cache {
        int cached;
 };
 
-struct crypto_hash;
 struct btrfs_fs_info {
        struct btrfs_root *extent_root;
        struct btrfs_root *tree_root;
-       struct btrfs_root *dev_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 dev_radix;
        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;
        struct mutex trans_mutex;
        struct mutex fs_mutex;
        struct list_head trans_list;
-       struct crypto_hash *hash_tfm;
-       spinlock_t hash_lock;
+       struct list_head dead_roots;
+       struct delayed_work trans_work;
+       struct kobject super_kobj;
+       struct completion kobj_unregister;
        int do_barriers;
-       struct kobject kobj;
+       int closing;
 };
 
 /*
@@ -311,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 */
@@ -369,11 +396,6 @@ struct btrfs_root {
  */
 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
 
-/*
- * dev items list the devices that make up the FS
- */
-#define BTRFS_DEV_ITEM_KEY     35
-
 /*
  * string items are for debugging.  They just store a short string of
  * data in the FS
@@ -789,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);
@@ -864,62 +918,6 @@ static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
        s->root_dir_objectid = cpu_to_le64(val);
 }
 
-static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
-{
-       return le64_to_cpu(s->last_device_id);
-}
-
-static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
-                                                 u64 val)
-{
-       s->last_device_id = cpu_to_le64(val);
-}
-
-static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
-{
-       return le64_to_cpu(s->device_id);
-}
-
-static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
-                                                 u64 val)
-{
-       s->device_id = cpu_to_le64(val);
-}
-
-static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
-{
-       return le64_to_cpu(s->device_block_start);
-}
-
-static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
-                                                     *s, u64 val)
-{
-       s->device_block_start = cpu_to_le64(val);
-}
-
-static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
-{
-       return le64_to_cpu(s->device_num_blocks);
-}
-
-static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
-                                                    *s, u64 val)
-{
-       s->device_num_blocks = cpu_to_le64(val);
-}
-
-static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
-{
-       return le64_to_cpu(s->device_root);
-}
-
-static inline void btrfs_set_super_device_root(struct btrfs_super_block
-                                                     *s, u64 val)
-{
-       s->device_root = cpu_to_le64(val);
-}
-
-
 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
 {
        return (u8 *)l->items;
@@ -1015,28 +1013,6 @@ static inline void btrfs_set_file_extent_num_blocks(struct
        e->num_blocks = cpu_to_le64(val);
 }
 
-static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
-{
-       return le16_to_cpu(d->pathlen);
-}
-
-static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
-                                               u16 val)
-{
-       d->pathlen = cpu_to_le16(val);
-}
-
-static inline u64 btrfs_device_id(struct btrfs_device_item *d)
-{
-       return le64_to_cpu(d->device_id);
-}
-
-static inline void btrfs_set_device_id(struct btrfs_device_item *d,
-                                               u64 val)
-{
-       d->device_id = cpu_to_le64(val);
-}
-
 static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
 {
        return sb->s_fs_info;
@@ -1067,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. */
@@ -1078,7 +1065,19 @@ 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);
 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
                                                 struct btrfs_block_group_cache
                                                 *hint, u64 search_start,
@@ -1086,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);
@@ -1105,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,
@@ -1114,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);
@@ -1128,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);
@@ -1140,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,
@@ -1190,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,
@@ -1201,5 +1208,49 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root, struct btrfs_path *path,
                        u64 isize);
-/* super.c */
+/* 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);
+void btrfs_dirty_inode(struct inode *inode);
+struct inode *btrfs_alloc_inode(struct super_block *sb);
+void btrfs_destroy_inode(struct inode *inode);
+int btrfs_init_cachep(void);
+void btrfs_destroy_cachep(void);
+int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+               unsigned long arg);
+long btrfs_compat_ioctl(struct file *file, unsigned int cmd,
+                              unsigned long arg);
+struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
+                               struct btrfs_root *root);
+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.031152 seconds and 5 git commands to generate.