Merge tag 'i2c-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
[linux-2.6-microblaze.git] / fs / btrfs / ctree.h
index 077c95e..0e49b1a 100644 (file)
@@ -675,13 +675,13 @@ struct btrfs_fs_info {
        rwlock_t global_root_lock;
        struct rb_root global_root_tree;
 
-       spinlock_t fs_roots_radix_lock;
-       struct radix_tree_root fs_roots_radix;
+       /* The xarray that holds all the FS roots */
+       spinlock_t fs_roots_lock;
+       struct xarray fs_roots;
 
        /* block group cache stuff */
-       spinlock_t block_group_cache_lock;
-       u64 first_logical_byte;
-       struct rb_root block_group_cache_tree;
+       rwlock_t block_group_cache_lock;
+       struct rb_root_cached block_group_cache_tree;
 
        /* keep track of unallocated space */
        atomic64_t free_chunk_space;
@@ -848,12 +848,13 @@ struct btrfs_fs_info {
         * two
         */
        struct btrfs_workqueue *workers;
+       struct btrfs_workqueue *hipri_workers;
        struct btrfs_workqueue *delalloc_workers;
        struct btrfs_workqueue *flush_workers;
        struct btrfs_workqueue *endio_workers;
        struct btrfs_workqueue *endio_meta_workers;
        struct btrfs_workqueue *endio_raid56_workers;
-       struct btrfs_workqueue *rmw_workers;
+       struct workqueue_struct *rmw_workers;
        struct btrfs_workqueue *endio_meta_write_workers;
        struct btrfs_workqueue *endio_write_workers;
        struct btrfs_workqueue *endio_freespace_worker;
@@ -946,9 +947,9 @@ struct btrfs_fs_info {
         * running.
         */
        refcount_t scrub_workers_refcnt;
-       struct btrfs_workqueue *scrub_workers;
-       struct btrfs_workqueue *scrub_wr_completion_workers;
-       struct btrfs_workqueue *scrub_parity_workers;
+       struct workqueue_struct *scrub_workers;
+       struct workqueue_struct *scrub_wr_completion_workers;
+       struct workqueue_struct *scrub_parity_workers;
        struct btrfs_subpage_info *subpage_info;
 
        struct btrfs_discard_ctl discard_ctl;
@@ -994,10 +995,10 @@ struct btrfs_fs_info {
 
        struct btrfs_delayed_root *delayed_root;
 
-       /* Extent buffer radix tree */
+       /* Extent buffer xarray */
        spinlock_t buffer_lock;
        /* Entries are eb->start / sectorsize */
-       struct radix_tree_root buffer_radix;
+       struct xarray extent_buffers;
 
        /* next backup root to be overwritten */
        int backup_root_index;
@@ -1045,10 +1046,7 @@ struct btrfs_fs_info {
         * Zone size > 0 when in ZONED mode, otherwise it's used for a check
         * if the mode is enabled
         */
-       union {
-               u64 zone_size;
-               u64 zoned;
-       };
+       u64 zone_size;
 
        struct mutex zoned_meta_io_lock;
        spinlock_t treelog_bg_lock;
@@ -1121,7 +1119,8 @@ enum {
         */
        BTRFS_ROOT_SHAREABLE,
        BTRFS_ROOT_TRACK_DIRTY,
-       BTRFS_ROOT_IN_RADIX,
+       /* The root is tracked in fs_info::fs_roots */
+       BTRFS_ROOT_REGISTERED,
        BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
        BTRFS_ROOT_DEFRAG_RUNNING,
        BTRFS_ROOT_FORCE_COW,
@@ -1225,10 +1224,10 @@ struct btrfs_root {
        struct rb_root inode_tree;
 
        /*
-        * radix tree that keeps track of delayed nodes of every inode,
-        * protected by inode_lock
+        * Xarray that keeps track of delayed nodes of every inode, protected
+        * by inode_lock
         */
-       struct radix_tree_root delayed_nodes_tree;
+       struct xarray delayed_nodes;
        /*
         * right now this just gets used so that a root has its own devid
         * for stat.  It may be used for more later
@@ -2784,7 +2783,8 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
                                    u64 bytenr, u64 num_bytes);
 int btrfs_exclude_logged_extents(struct extent_buffer *eb);
 int btrfs_cross_ref_exist(struct btrfs_root *root,
-                         u64 objectid, u64 offset, u64 bytenr, bool strict);
+                         u64 objectid, u64 offset, u64 bytenr, bool strict,
+                         struct btrfs_path *path);
 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
                                             struct btrfs_root *root,
                                             u64 parent, u64 root_objectid,
@@ -2811,8 +2811,7 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                  struct extent_buffer *buf, int full_backref);
 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
-                               struct extent_buffer *eb, u64 flags,
-                               int level, int is_data);
+                               struct extent_buffer *eb, u64 flags, int level);
 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
 
 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
@@ -2892,7 +2891,7 @@ void btrfs_subvolume_release_metadata(struct btrfs_root *root,
 void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
 
 int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes,
-                                   u64 disk_num_bytes);
+                                   u64 disk_num_bytes, bool noflush);
 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
                                   u64 start, u64 end);
@@ -3039,6 +3038,35 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
 int btrfs_search_backwards(struct btrfs_root *root, struct btrfs_key *key,
                           struct btrfs_path *path);
 
+int btrfs_get_next_valid_item(struct btrfs_root *root, struct btrfs_key *key,
+                             struct btrfs_path *path);
+
+/*
+ * Search in @root for a given @key, and store the slot found in @found_key.
+ *
+ * @root:      The root node of the tree.
+ * @key:       The key we are looking for.
+ * @found_key: Will hold the found item.
+ * @path:      Holds the current slot/leaf.
+ * @iter_ret:  Contains the value returned from btrfs_search_slot or
+ *             btrfs_get_next_valid_item, whichever was executed last.
+ *
+ * The @iter_ret is an output variable that will contain the return value of
+ * btrfs_search_slot, if it encountered an error, or the value returned from
+ * btrfs_get_next_valid_item otherwise. That return value can be 0, if a valid
+ * slot was found, 1 if there were no more leaves, and <0 if there was an error.
+ *
+ * It's recommended to use a separate variable for iter_ret and then use it to
+ * set the function return value so there's no confusion of the 0/1/errno
+ * values stemming from btrfs_search_slot.
+ */
+#define btrfs_for_each_slot(root, key, found_key, path, iter_ret)              \
+       for (iter_ret = btrfs_search_slot(NULL, (root), (key), (path), 0, 0);   \
+               (iter_ret) >= 0 &&                                              \
+               (iter_ret = btrfs_get_next_valid_item((root), (found_key), (path))) == 0; \
+               (path)->slots[0]++                                              \
+       )
+
 static inline int btrfs_next_old_item(struct btrfs_root *root,
                                      struct btrfs_path *p, u64 time_seq)
 {
@@ -3190,7 +3218,6 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
 int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset);
 
 /* file-item.c */
-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);
@@ -3224,8 +3251,8 @@ void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_siz
 u64 btrfs_file_extent_end(const struct btrfs_path *path);
 
 /* inode.c */
-blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
-                                  int mirror_num, unsigned long bio_flags);
+void btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
+                          int mirror_num, enum btrfs_compression_type compress_type);
 unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio,
                                    u32 bio_offset, struct page *page,
                                    u64 start, u64 end);
@@ -3255,10 +3282,28 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
 int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
                              unsigned int extra_bits,
                              struct extent_state **cached_state);
-int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
-                            struct btrfs_root *new_root,
-                            struct btrfs_root *parent_root,
-                            struct user_namespace *mnt_userns);
+struct btrfs_new_inode_args {
+       /* Input */
+       struct inode *dir;
+       struct dentry *dentry;
+       struct inode *inode;
+       bool orphan;
+       bool subvol;
+
+       /*
+        * Output from btrfs_new_inode_prepare(), input to
+        * btrfs_create_new_inode().
+        */
+       struct posix_acl *default_acl;
+       struct posix_acl *acl;
+};
+int btrfs_new_inode_prepare(struct btrfs_new_inode_args *args,
+                           unsigned int *trans_num_items);
+int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
+                          struct btrfs_new_inode_args *args);
+void btrfs_new_inode_args_destroy(struct btrfs_new_inode_args *args);
+struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns,
+                                    struct inode *dir);
  void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
                               unsigned *bits);
 void btrfs_clear_delalloc_extent(struct inode *inode,
@@ -3269,7 +3314,6 @@ void btrfs_split_delalloc_extent(struct inode *inode,
                                 struct extent_state *orig, u64 split);
 void btrfs_set_range_writeback(struct btrfs_inode *inode, u64 start, u64 end);
 vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
-int btrfs_readpage(struct file *file, struct page *page);
 void btrfs_evict_inode(struct inode *inode);
 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
 struct inode *btrfs_alloc_inode(struct super_block *sb);
@@ -3314,9 +3358,9 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter,
 ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
                             const struct btrfs_ioctl_encoded_io_args *encoded);
 
+ssize_t btrfs_dio_rw(struct kiocb *iocb, struct iov_iter *iter, size_t done_before);
+
 extern const struct dentry_operations btrfs_dentry_operations;
-extern const struct iomap_ops btrfs_dio_iomap_ops;
-extern const struct iomap_dio_ops btrfs_dio_ops;
 
 /* Inode locking type flags, by default the exclusive lock is taken */
 #define BTRFS_ILOCK_SHARED     (1U << 0)
@@ -3328,6 +3372,7 @@ void btrfs_inode_unlock(struct inode *inode, unsigned int ilock_flags);
 void btrfs_update_inode_bytes(struct btrfs_inode *inode,
                              const u64 add_bytes,
                              const u64 del_bytes);
+void btrfs_assert_inode_range_clean(struct btrfs_inode *inode, u64 start, u64 end);
 
 /* ioctl.c */
 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
@@ -3403,11 +3448,29 @@ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 {
 }
 
-#ifdef CONFIG_PRINTK
+#ifdef CONFIG_PRINTK_INDEX
+
+#define btrfs_printk(fs_info, fmt, args...)                                    \
+do {                                                                           \
+       printk_index_subsys_emit("%sBTRFS %s (device %s): ", NULL, fmt);        \
+       _btrfs_printk(fs_info, fmt, ##args);                                    \
+} while (0)
+
 __printf(2, 3)
 __cold
-void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
+void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
+
+#elif defined(CONFIG_PRINTK)
+
+#define btrfs_printk(fs_info, fmt, args...)                            \
+       _btrfs_printk(fs_info, fmt, ##args)
+
+__printf(2, 3)
+__cold
+void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
+
 #else
+
 #define btrfs_printk(fs_info, fmt, args...) \
        btrfs_no_printk(fs_info, fmt, ##args)
 #endif
@@ -3658,12 +3721,25 @@ do {                                                            \
                                  __LINE__, (errno));           \
 } while (0)
 
+#ifdef CONFIG_PRINTK_INDEX
+
 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...)            \
-do {                                                           \
-       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,  \
-                         (errno), fmt, ##args);                \
+do {                                                                   \
+       printk_index_subsys_emit(                                       \
+               "BTRFS: error (device %s%s) in %s:%d: errno=%d %s",     \
+               KERN_CRIT, fmt);                                        \
+       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,          \
+                               (errno), fmt, ##args);                  \
 } while (0)
 
+#else
+
+#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)            \
+       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,          \
+                               (errno), fmt, ##args)
+
+#endif
+
 #define BTRFS_FS_ERROR(fs_info)        (unlikely(test_bit(BTRFS_FS_STATE_ERROR, \
                                                   &(fs_info)->fs_state)))
 #define BTRFS_FS_LOG_CLEANUP_ERROR(fs_info)                            \
@@ -3816,15 +3892,16 @@ static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
 struct posix_acl *btrfs_get_acl(struct inode *inode, int type, bool rcu);
 int btrfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
                  struct posix_acl *acl, int type);
-int btrfs_init_acl(struct btrfs_trans_handle *trans,
-                  struct inode *inode, struct inode *dir);
+int __btrfs_set_acl(struct btrfs_trans_handle *trans, struct inode *inode,
+                   struct posix_acl *acl, int type);
 #else
 #define btrfs_get_acl NULL
 #define btrfs_set_acl NULL
-static inline int btrfs_init_acl(struct btrfs_trans_handle *trans,
-                                struct inode *inode, struct inode *dir)
+static inline int __btrfs_set_acl(struct btrfs_trans_handle *trans,
+                                 struct inode *inode, struct posix_acl *acl,
+                                 int type)
 {
-       return 0;
+       return -EOPNOTSUPP;
 }
 #endif
 
@@ -3929,7 +4006,7 @@ static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
 
 static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info)
 {
-       return fs_info->zoned != 0;
+       return fs_info->zone_size > 0;
 }
 
 static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root)