aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/dir-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/dir-item.c')
-rw-r--r--fs/btrfs/dir-item.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c
index c62f02f6ae69..f53fb3847c96 100644
--- a/fs/btrfs/dir-item.c
+++ b/fs/btrfs/dir-item.c
@@ -124,8 +124,9 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
124 * to use for the second index (if one is created). 124 * to use for the second index (if one is created).
125 */ 125 */
126int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root 126int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
127 *root, const char *name, int name_len, u64 dir, 127 *root, const char *name, int name_len,
128 struct btrfs_key *location, u8 type, u64 index) 128 struct inode *dir, struct btrfs_key *location,
129 u8 type, u64 index)
129{ 130{
130 int ret = 0; 131 int ret = 0;
131 int ret2 = 0; 132 int ret2 = 0;
@@ -137,13 +138,17 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
137 struct btrfs_disk_key disk_key; 138 struct btrfs_disk_key disk_key;
138 u32 data_size; 139 u32 data_size;
139 140
140 key.objectid = dir; 141 key.objectid = dir->i_ino;
141 btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY); 142 btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
142 key.offset = btrfs_name_hash(name, name_len); 143 key.offset = btrfs_name_hash(name, name_len);
143 144
144 path = btrfs_alloc_path(); 145 path = btrfs_alloc_path();
146 if (!path)
147 return -ENOMEM;
145 path->leave_spinning = 1; 148 path->leave_spinning = 1;
146 149
150 btrfs_cpu_key_to_disk(&disk_key, location);
151
147 data_size = sizeof(*dir_item) + name_len; 152 data_size = sizeof(*dir_item) + name_len;
148 dir_item = insert_with_overflow(trans, root, path, &key, data_size, 153 dir_item = insert_with_overflow(trans, root, path, &key, data_size,
149 name, name_len); 154 name, name_len);
@@ -155,7 +160,6 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
155 } 160 }
156 161
157 leaf = path->nodes[0]; 162 leaf = path->nodes[0];
158 btrfs_cpu_key_to_disk(&disk_key, location);
159 btrfs_set_dir_item_key(leaf, dir_item, &disk_key); 163 btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
160 btrfs_set_dir_type(leaf, dir_item, type); 164 btrfs_set_dir_type(leaf, dir_item, type);
161 btrfs_set_dir_data_len(leaf, dir_item, 0); 165 btrfs_set_dir_data_len(leaf, dir_item, 0);
@@ -174,27 +178,9 @@ second_insert:
174 } 178 }
175 btrfs_release_path(root, path); 179 btrfs_release_path(root, path);
176 180
177 btrfs_set_key_type(&key, BTRFS_DIR_INDEX_KEY); 181 ret2 = btrfs_insert_delayed_dir_index(trans, root, name, name_len, dir,
178 key.offset = index; 182 &disk_key, type, index);
179 dir_item = insert_with_overflow(trans, root, path, &key, data_size,
180 name, name_len);
181 if (IS_ERR(dir_item)) {
182 ret2 = PTR_ERR(dir_item);
183 goto out_free;
184 }
185 leaf = path->nodes[0];
186 btrfs_cpu_key_to_disk(&disk_key, location);
187 btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
188 btrfs_set_dir_type(leaf, dir_item, type);
189 btrfs_set_dir_data_len(leaf, dir_item, 0);
190 btrfs_set_dir_name_len(leaf, dir_item, name_len);
191 btrfs_set_dir_transid(leaf, dir_item, trans->transid);
192 name_ptr = (unsigned long)(dir_item + 1);
193 write_extent_buffer(leaf, name, name_ptr, name_len);
194 btrfs_mark_buffer_dirty(leaf);
195
196out_free: 183out_free:
197
198 btrfs_free_path(path); 184 btrfs_free_path(path);
199 if (ret) 185 if (ret)
200 return ret; 186 return ret;