]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/btrfs/ctree.h
Btrfs: fix race between using extent maps and merging them
[linux.git] / fs / btrfs / ctree.h
index ea49e4b52cd26a8602f6426cd940ac894cc53b34..36df977b64d91d1f3bbdd90edcb9da91751e87e4 100644 (file)
@@ -101,6 +101,14 @@ struct btrfs_ref;
 
 #define BTRFS_MAX_EXTENT_SIZE SZ_128M
 
+/*
+ * Deltas are an effective way to populate global statistics.  Give macro names
+ * to make it clear what we're doing.  An example is discard_extents in
+ * btrfs_free_space_ctl.
+ */
+#define BTRFS_STAT_NR_ENTRIES  2
+#define BTRFS_STAT_CURR                0
+#define BTRFS_STAT_PREV                1
 
 /*
  * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
@@ -440,6 +448,36 @@ struct btrfs_full_stripe_locks_tree {
        struct mutex lock;
 };
 
+/* Discard control. */
+/*
+ * Async discard uses multiple lists to differentiate the discard filter
+ * parameters.  Index 0 is for completely free block groups where we need to
+ * ensure the entire block group is trimmed without being lossy.  Indices
+ * afterwards represent monotonically decreasing discard filter sizes to
+ * prioritize what should be discarded next.
+ */
+#define BTRFS_NR_DISCARD_LISTS         3
+#define BTRFS_DISCARD_INDEX_UNUSED     0
+#define BTRFS_DISCARD_INDEX_START      1
+
+struct btrfs_discard_ctl {
+       struct workqueue_struct *discard_workers;
+       struct delayed_work work;
+       spinlock_t lock;
+       struct btrfs_block_group *block_group;
+       struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
+       u64 prev_discard;
+       atomic_t discardable_extents;
+       atomic64_t discardable_bytes;
+       u64 max_discard_size;
+       unsigned long delay;
+       u32 iops_limit;
+       u32 kbps_limit;
+       u64 discard_extent_bytes;
+       u64 discard_bitmap_bytes;
+       atomic64_t discard_bytes_saved;
+};
+
 /* delayed seq elem */
 struct seq_list {
        struct list_head list;
@@ -526,6 +564,9 @@ enum {
         * so we don't need to offload checksums to workqueues.
         */
        BTRFS_FS_CSUM_IMPL_FAST,
+
+       /* Indicate that the discard workqueue can service discards. */
+       BTRFS_FS_DISCARD_RUNNING,
 };
 
 struct btrfs_fs_info {
@@ -673,14 +714,12 @@ struct btrfs_fs_info {
        atomic_t nr_delayed_iputs;
        wait_queue_head_t delayed_iputs_wait;
 
-       /* this protects tree_mod_seq_list */
-       spinlock_t tree_mod_seq_lock;
        atomic64_t tree_mod_seq;
-       struct list_head tree_mod_seq_list;
 
-       /* this protects tree_mod_log */
+       /* this protects tree_mod_log and tree_mod_seq_list */
        rwlock_t tree_mod_log_lock;
        struct rb_root tree_mod_log;
+       struct list_head tree_mod_seq_list;
 
        atomic_t async_delalloc_pages;
 
@@ -816,6 +855,8 @@ struct btrfs_fs_info {
        struct btrfs_workqueue *scrub_wr_completion_workers;
        struct btrfs_workqueue *scrub_parity_workers;
 
+       struct btrfs_discard_ctl discard_ctl;
+
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
        u32 check_integrity_print_mask;
 #endif
@@ -902,6 +943,11 @@ struct btrfs_fs_info {
        spinlock_t ref_verify_lock;
        struct rb_root block_tree;
 #endif
+
+#ifdef CONFIG_BTRFS_DEBUG
+       struct kobject *debug_kobj;
+       struct kobject *discard_debug_kobj;
+#endif
 };
 
 static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
@@ -1170,7 +1216,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 #define BTRFS_MOUNT_FLUSHONCOMMIT       (1 << 7)
 #define BTRFS_MOUNT_SSD_SPREAD         (1 << 8)
 #define BTRFS_MOUNT_NOSSD              (1 << 9)
-#define BTRFS_MOUNT_DISCARD            (1 << 10)
+#define BTRFS_MOUNT_DISCARD_SYNC       (1 << 10)
 #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
 #define BTRFS_MOUNT_SPACE_CACHE                (1 << 12)
 #define BTRFS_MOUNT_CLEAR_CACHE                (1 << 13)
@@ -1189,6 +1235,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 #define BTRFS_MOUNT_FREE_SPACE_TREE    (1 << 26)
 #define BTRFS_MOUNT_NOLOGREPLAY                (1 << 27)
 #define BTRFS_MOUNT_REF_VERIFY         (1 << 28)
+#define BTRFS_MOUNT_DISCARD_ASYNC      (1 << 29)
 
 #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
 #define BTRFS_DEFAULT_MAX_INLINE       (2048)
@@ -2789,9 +2836,7 @@ struct btrfs_dio_private;
 int btrfs_del_csums(struct btrfs_trans_handle *trans,
                    struct btrfs_root *root, u64 bytenr, u64 len);
 blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
-                                  u8 *dst);
-blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio,
-                             u64 logical_offset);
+                                  u64 offset, u8 *dst);
 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root,
                             u64 objectid, u64 pos,
@@ -2877,7 +2922,7 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
                         struct btrfs_root *root);
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
                                    struct page *page, size_t pg_offset,
-                                   u64 start, u64 end, int create);
+                                   u64 start, u64 end);
 int btrfs_update_inode(struct btrfs_trans_handle *trans,
                              struct btrfs_root *root,
                              struct inode *inode);
@@ -3110,17 +3155,21 @@ do {                                                            \
        rcu_read_unlock();                                      \
 } while (0)
 
-__cold
-static inline void assfail(const char *expr, const char *file, int line)
+#ifdef CONFIG_BTRFS_ASSERT
+__cold __noreturn
+static inline void assertfail(const char *expr, const char *file, int line)
 {
-       if (IS_ENABLED(CONFIG_BTRFS_ASSERT)) {
-               pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
-               BUG();
-       }
+       pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
+       BUG();
 }
 
-#define ASSERT(expr)   \
-       (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
+#define ASSERT(expr)                                           \
+       (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
+
+#else
+static inline void assertfail(const char *expr, const char* file, int line) { }
+#define ASSERT(expr)   (void)(expr)
+#endif
 
 /*
  * Use that for functions that are conditionally exported for sanity tests but