btrfs: reserve correct number of items for inode creation
[platform/kernel/linux-starfive.git] / fs / btrfs / ctree.h
index 077c95e..768339a 100644 (file)
@@ -3039,6 +3039,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_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)
 {
 static inline int btrfs_next_old_item(struct btrfs_root *root,
                                      struct btrfs_path *p, u64 time_seq)
 {
@@ -3255,10 +3284,32 @@ 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_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
                              unsigned int extra_bits,
                              struct extent_state **cached_state);
+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,
+                          u64 *index);
+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);
 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
-                            struct btrfs_root *new_root,
                             struct btrfs_root *parent_root,
                             struct btrfs_root *parent_root,
-                            struct user_namespace *mnt_userns);
+                            struct btrfs_new_inode_args *args);
  void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
                               unsigned *bits);
 void btrfs_clear_delalloc_extent(struct inode *inode,
  void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
                               unsigned *bits);
 void btrfs_clear_delalloc_extent(struct inode *inode,
@@ -3816,15 +3867,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);
 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
 #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
 
 }
 #endif