Btrfs: Add locking around volume management (device add/remove/balance)
[deliverable/linux.git] / fs / btrfs / ctree.h
index d119d95d139ad96e7e29f76f95cb367160faead2..f3783dbd9b600362020dd8296a06a290c39d50f0 100644 (file)
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/fs.h>
-#include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/backing-dev.h>
 #include <asm/kmap_types.h>
 #include "bit-radix.h"
 #include "extent_io.h"
 #include "extent_map.h"
+#include "async-thread.h"
 
 struct btrfs_trans_handle;
 struct btrfs_transaction;
@@ -247,6 +247,7 @@ struct btrfs_header {
  * room to translate 14 chunks with 3 stripes each.
  */
 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
+#define BTRFS_LABEL_SIZE 256
 
 /*
  * the super block basically lists the main trees of the FS
@@ -276,6 +277,7 @@ struct btrfs_super_block {
        u8 root_level;
        u8 chunk_root_level;
        struct btrfs_dev_item dev_item;
+       char label[BTRFS_LABEL_SIZE];
        u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
 } __attribute__ ((__packed__));
 
@@ -327,7 +329,12 @@ struct btrfs_node {
 struct btrfs_path {
        struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
        int slots[BTRFS_MAX_LEVEL];
+       /* if there is real range locking, this locks field will change */
+       int locks[BTRFS_MAX_LEVEL];
        int reada;
+       /* keep some upper locks as we walk down */
+       int keep_locks;
+       int skip_locking;
        int lowest_level;
 };
 
@@ -462,6 +469,7 @@ struct btrfs_space_info {
        u64 bytes_used;
        u64 bytes_pinned;
        int full;
+       int force_alloc;
        struct list_head list;
 };
 
@@ -472,6 +480,7 @@ struct btrfs_block_group_cache {
        u64 pinned;
        u64 flags;
        int cached;
+       int ro;
 };
 
 struct btrfs_device;
@@ -502,34 +511,46 @@ struct btrfs_fs_info {
        u64 alloc_start;
        struct btrfs_transaction *running_transaction;
        struct btrfs_super_block super_copy;
-       struct extent_buffer *sb_buffer;
+       struct btrfs_super_block super_for_commit;
        struct block_device *__bdev;
        struct super_block *sb;
        struct inode *btree_inode;
        struct backing_dev_info bdi;
        spinlock_t hash_lock;
        struct mutex trans_mutex;
-       struct mutex fs_mutex;
+       struct mutex transaction_kthread_mutex;
+       struct mutex cleaner_mutex;
+       struct mutex alloc_mutex;
+       struct mutex chunk_mutex;
+       struct mutex drop_mutex;
+       struct mutex volume_mutex;
        struct list_head trans_list;
        struct list_head hashers;
        struct list_head dead_roots;
-       struct list_head end_io_work_list;
-       struct list_head async_submit_work_list;
-       struct work_struct end_io_work;
-       struct work_struct async_submit_work;
-       spinlock_t end_io_work_lock;
-       spinlock_t async_submit_work_lock;
+       atomic_t nr_async_submits;
+
+       /*
+        * there is a pool of worker threads for checksumming during writes
+        * and a pool for checksumming after reads.  This is because readers
+        * can run with FS locks held, and the writers may be waiting for
+        * those locks.  We don't want ordering in the pending list to cause
+        * deadlocks, and so the two are serviced separately.
+        *
+        * A third pool does submit_bio to avoid deadlocking with the other
+        * two
+        */
+       struct btrfs_workers workers;
+       struct btrfs_workers endio_workers;
+       struct btrfs_workers submit_workers;
+       struct task_struct *transaction_kthread;
+       struct task_struct *cleaner_kthread;
+       int thread_pool_size;
 
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
-       struct work_struct trans_work;
-#else
-       struct delayed_work trans_work;
-#endif
        struct kobject super_kobj;
        struct completion kobj_unregister;
        int do_barriers;
        int closing;
-       unsigned long throttles;
+       atomic_t throttles;
 
        u64 total_pinned;
        struct list_head dirty_cowonly_roots;
@@ -548,6 +569,8 @@ struct btrfs_fs_info {
        u64 data_alloc_profile;
        u64 metadata_alloc_profile;
        u64 system_alloc_profile;
+
+       void *bdev_holder;
 };
 
 /*
@@ -556,6 +579,10 @@ struct btrfs_fs_info {
  */
 struct btrfs_root {
        struct extent_buffer *node;
+
+       /* the node lock is held while changing the node pointer */
+       spinlock_t node_lock;
+
        struct extent_buffer *commit_root;
        struct btrfs_root_item root_item;
        struct btrfs_key root_key;
@@ -563,6 +590,7 @@ struct btrfs_root {
        struct inode *inode;
        struct kobject root_kobj;
        struct completion kobj_unregister;
+       struct mutex objectid_mutex;
        u64 objectid;
        u64 last_trans;
 
@@ -582,7 +610,9 @@ struct btrfs_root {
        u64 last_inode_alloc;
        int ref_cows;
        int track_dirty;
+       u64 defrag_trans_start;
        struct btrfs_key defrag_progress;
+       struct btrfs_key defrag_max;
        int defrag_running;
        int defrag_level;
        char *name;
@@ -652,6 +682,7 @@ struct btrfs_root {
 #define BTRFS_MOUNT_NODATACOW          (1 << 1)
 #define BTRFS_MOUNT_NOBARRIER          (1 << 2)
 #define BTRFS_MOUNT_SSD                        (1 << 3)
+#define BTRFS_MOUNT_DEGRADED           (1 << 4)
 
 #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
 #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
@@ -1203,6 +1234,7 @@ BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
 
 /* struct btrfs_super_block */
 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
+BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 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);
@@ -1319,7 +1351,7 @@ static inline struct dentry *fdentry(struct file *file) {
 /* extent-tree.c */
 u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
                                  struct btrfs_path *count_path,
-                                 u64 first_extent);
+                                 u64 expected_owner, u64 first_extent);
 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
                         struct btrfs_root *root);
 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
@@ -1330,13 +1362,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
                                                 struct btrfs_block_group_cache
                                                 *hint, u64 search_start,
                                                 int data, int owner);
-int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
-                      struct btrfs_root *root, u64 owner_objectid);
 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
-                                           struct btrfs_root *root, u32 size,
-                                           u64 root_objectid,
-                                           u64 hint, u64 empty_size);
-struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
                                             struct btrfs_root *root,
                                             u32 blocksize,
                                             u64 root_objectid,
@@ -1345,8 +1371,6 @@ struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
                                             int level,
                                             u64 hint,
                                             u64 empty_size);
-int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
-                          struct btrfs_root *root, u64 new_size);
 int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
 int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
                                 struct btrfs_root *root,
@@ -1359,7 +1383,7 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
                       u64 root_objectid, u64 ref_generation,
                       u64 owner, u64 owner_offset,
                       u64 empty_size, u64 hint_byte,
-                      u64 search_end, struct btrfs_key *ins, int data);
+                      u64 search_end, struct btrfs_key *ins, u64 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
@@ -1386,6 +1410,16 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
 int btrfs_previous_item(struct btrfs_root *root,
                        struct btrfs_path *path, u64 min_objectid,
                        int type);
+
+struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
+struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
+int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
+                       struct btrfs_key *key, int lowest_level,
+                       int cache_only, u64 min_trans);
+int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
+                        struct btrfs_path *path, int cache_only,
+                        u64 min_trans);
+
 int btrfs_cow_block(struct btrfs_trans_handle *trans,
                    struct btrfs_root *root, struct extent_buffer *buf,
                    struct extent_buffer *parent, int parent_slot,
@@ -1453,6 +1487,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_search_root(struct btrfs_root *root, u64 search_start,
+                     u64 *found_objectid);
 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
                          struct btrfs_root *latest_root);
 /* dir-item.c */
@@ -1511,9 +1547,9 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
 /* file-item.c */
 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
                               struct btrfs_root *root,
-                              u64 objectid, u64 pos, u64 offset,
+                              u64 objectid, u64 pos, u64 disk_offset,
                               u64 disk_num_bytes,
-                              u64 num_bytes);
+                            u64 num_bytes, u64 offset);
 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root,
                             struct btrfs_path *path, u64 objectid,
@@ -1532,6 +1568,13 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root, struct btrfs_path *path,
                        u64 isize);
 /* inode.c */
+int btrfs_create_subvol_root(struct btrfs_root *new_root,
+               struct btrfs_trans_handle *trans, u64 new_dirid,
+               struct btrfs_block_group_cache *block_group);
+
+void btrfs_invalidate_dcache_root(struct btrfs_root *root, char *name,
+                                 int namelen);
+
 int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
                         size_t size, struct bio *bio);
 
@@ -1560,7 +1603,7 @@ 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);
-long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+long btrfs_ioctl_trans_end(struct file *file);
 struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
                                struct btrfs_root *root);
 struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
@@ -1573,6 +1616,10 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
 int btrfs_update_inode(struct btrfs_trans_handle *trans,
                              struct btrfs_root *root,
                              struct inode *inode);
+
+/* ioctl.c */
+long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+
 /* file.c */
 int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
 int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
@@ -1580,6 +1627,8 @@ 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 inline_limit, u64 *hint_block);
+int btrfs_release_file(struct inode *inode, struct file *file);
+
 /* tree-defrag.c */
 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root, int cache_only);
@@ -1598,4 +1647,6 @@ int btrfs_delete_xattrs(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root, struct inode *inode);
 /* super.c */
 u64 btrfs_parse_size(char *str);
+int btrfs_parse_options(struct btrfs_root *root, char *options);
+int btrfs_sync_fs(struct super_block *sb, int wait);
 #endif
This page took 0.029224 seconds and 5 git commands to generate.