btrfs: switch BTRFS_BLOCK_RSV_* to enums
[sfrench/cifs-2.6.git] / fs / btrfs / ctree.h
index 68f322f600a0677813867c5278b5aca9c23a6e8f..becfe1d10e470241892327623c6b5461c1e2edb2 100644 (file)
@@ -109,13 +109,26 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
 }
 
 /*
- * File system states
+ * Runtime (in-memory) states of filesystem
  */
-#define BTRFS_FS_STATE_ERROR           0
-#define BTRFS_FS_STATE_REMOUNTING      1
-#define BTRFS_FS_STATE_TRANS_ABORTED   2
-#define BTRFS_FS_STATE_DEV_REPLACING   3
-#define BTRFS_FS_STATE_DUMMY_FS_INFO   4
+enum {
+       /* Global indicator of serious filesystem errors */
+       BTRFS_FS_STATE_ERROR,
+       /*
+        * Filesystem is being remounted, allow to skip some operations, like
+        * defrag
+        */
+       BTRFS_FS_STATE_REMOUNTING,
+       /* Track if a transaction abort has been reported on this filesystem */
+       BTRFS_FS_STATE_TRANS_ABORTED,
+       /*
+        * Bio operations should be blocked on this filesystem because a source
+        * or target device is being destroyed as part of a device replace
+        */
+       BTRFS_FS_STATE_DEV_REPLACING,
+       /* The btrfs_fs_info created for self-tests */
+       BTRFS_FS_STATE_DUMMY_FS_INFO,
+};
 
 #define BTRFS_BACKREF_REV_MAX          256
 #define BTRFS_BACKREF_REV_SHIFT                56
@@ -195,9 +208,10 @@ struct btrfs_root_backup {
  * it currently lacks any block count etc etc
  */
 struct btrfs_super_block {
-       u8 csum[BTRFS_CSUM_SIZE];
        /* the first 4 fields must match struct btrfs_header */
-       u8 fsid[BTRFS_FSID_SIZE];    /* FS specific uuid */
+       u8 csum[BTRFS_CSUM_SIZE];
+       /* FS specific UUID, visible to user */
+       u8 fsid[BTRFS_FSID_SIZE];
        __le64 bytenr; /* this block number */
        __le64 flags;
 
@@ -234,8 +248,11 @@ struct btrfs_super_block {
        __le64 cache_generation;
        __le64 uuid_tree_generation;
 
+       /* the UUID written into btree blocks */
+       u8 metadata_uuid[BTRFS_FSID_SIZE];
+
        /* future expansion */
-       __le64 reserved[30];
+       __le64 reserved[28];
        u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
        struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
 } __attribute__ ((__packed__));
@@ -265,7 +282,8 @@ struct btrfs_super_block {
         BTRFS_FEATURE_INCOMPAT_RAID56 |                \
         BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |         \
         BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |       \
-        BTRFS_FEATURE_INCOMPAT_NO_HOLES)
+        BTRFS_FEATURE_INCOMPAT_NO_HOLES        |       \
+        BTRFS_FEATURE_INCOMPAT_METADATA_UUID)
 
 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET                        \
        (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
@@ -443,13 +461,18 @@ struct btrfs_space_info {
        struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
 };
 
-#define        BTRFS_BLOCK_RSV_GLOBAL          1
-#define        BTRFS_BLOCK_RSV_DELALLOC        2
-#define        BTRFS_BLOCK_RSV_TRANS           3
-#define        BTRFS_BLOCK_RSV_CHUNK           4
-#define        BTRFS_BLOCK_RSV_DELOPS          5
-#define        BTRFS_BLOCK_RSV_EMPTY           6
-#define        BTRFS_BLOCK_RSV_TEMP            7
+/*
+ * Types of block reserves
+ */
+enum {
+       BTRFS_BLOCK_RSV_GLOBAL,
+       BTRFS_BLOCK_RSV_DELALLOC,
+       BTRFS_BLOCK_RSV_TRANS,
+       BTRFS_BLOCK_RSV_CHUNK,
+       BTRFS_BLOCK_RSV_DELOPS,
+       BTRFS_BLOCK_RSV_EMPTY,
+       BTRFS_BLOCK_RSV_TEMP,
+};
 
 struct btrfs_block_rsv {
        u64 size;
@@ -712,6 +735,28 @@ struct btrfs_fs_devices;
 struct btrfs_balance_control;
 struct btrfs_delayed_root;
 
+/*
+ * Block group or device which contains an active swapfile. Used for preventing
+ * unsafe operations while a swapfile is active.
+ *
+ * These are sorted on (ptr, inode) (note that a block group or device can
+ * contain more than one swapfile). We compare the pointer values because we
+ * don't actually care what the object is, we just need a quick check whether
+ * the object exists in the rbtree.
+ */
+struct btrfs_swapfile_pin {
+       struct rb_node node;
+       void *ptr;
+       struct inode *inode;
+       /*
+        * If true, ptr points to a struct btrfs_block_group_cache. Otherwise,
+        * ptr points to a struct btrfs_device.
+        */
+       bool is_block_group;
+};
+
+bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
+
 #define BTRFS_FS_BARRIER                       1
 #define BTRFS_FS_CLOSING_START                 2
 #define BTRFS_FS_CLOSING_DONE                  3
@@ -746,7 +791,6 @@ struct btrfs_delayed_root;
 #define BTRFS_FS_BALANCE_RUNNING               18
 
 struct btrfs_fs_info {
-       u8 fsid[BTRFS_FSID_SIZE];
        u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
        unsigned long flags;
        struct btrfs_root *extent_root;
@@ -1114,6 +1158,10 @@ struct btrfs_fs_info {
        u32 sectorsize;
        u32 stripesize;
 
+       /* Block groups and devices containing active swapfiles. */
+       spinlock_t swapfile_pins_lock;
+       struct rb_root swapfile_pins;
+
 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
        spinlock_t ref_verify_lock;
        struct rb_root block_tree;
@@ -1274,6 +1322,9 @@ struct btrfs_root {
        u64 qgroup_meta_rsv_pertrans;
        u64 qgroup_meta_rsv_prealloc;
 
+       /* Number of active swapfiles */
+       atomic_t nr_swapfiles;
+
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
        u64 alloc_bytenr;
 #endif
@@ -3141,7 +3192,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
                               struct inode *inode, u64 new_size,
                               u32 min_type);
 
-int btrfs_start_delalloc_inodes(struct btrfs_root *root);
+int btrfs_start_delalloc_snapshot(struct btrfs_root *root);
 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr);
 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
                              unsigned int extra_bits,
@@ -3150,9 +3201,16 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
                             struct btrfs_root *new_root,
                             struct btrfs_root *parent_root,
                             u64 new_dirid);
-int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
-                        size_t size, struct bio *bio,
-                        unsigned long bio_flags);
+ void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
+                              unsigned *bits);
+void btrfs_clear_delalloc_extent(struct inode *inode,
+                                struct extent_state *state, unsigned *bits);
+void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
+                                struct extent_state *other);
+void btrfs_split_delalloc_extent(struct inode *inode,
+                                struct extent_state *orig, u64 split);
+int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
+                            unsigned long bio_flags);
 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
 vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
 int btrfs_readpage(struct file *file, struct page *page);
@@ -3189,6 +3247,12 @@ int btrfs_prealloc_file_range_trans(struct inode *inode,
                                    struct btrfs_trans_handle *trans, int mode,
                                    u64 start, u64 num_bytes, u64 min_size,
                                    loff_t actual_len, u64 *alloc_hint);
+int btrfs_run_delalloc_range(void *private_data, struct page *locked_page,
+               u64 start, u64 end, int *page_started, unsigned long *nr_written,
+               struct writeback_control *wbc);
+int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
+void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
+                                         u64 end, int uptodate);
 extern const struct dentry_operations btrfs_dentry_operations;
 
 /* ioctl.c */
@@ -3428,6 +3492,16 @@ static inline void assfail(const char *expr, const char *file, int line)
 #define ASSERT(expr)   ((void)0)
 #endif
 
+/*
+ * Use that for functions that are conditionally exported for sanity tests but
+ * otherwise static
+ */
+#ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+#define EXPORT_FOR_TESTS static
+#else
+#define EXPORT_FOR_TESTS
+#endif
+
 __cold
 static inline void btrfs_print_v0_err(struct btrfs_fs_info *fs_info)
 {