| .. | .. |
|---|
| 8 | 8 | #include "transaction.h" |
|---|
| 9 | 9 | #include "print-tree.h" |
|---|
| 10 | 10 | |
|---|
| 11 | | -int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot, |
|---|
| 12 | | - const char *name, |
|---|
| 13 | | - int name_len, struct btrfs_inode_ref **ref_ret) |
|---|
| 11 | +struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf, |
|---|
| 12 | + int slot, const char *name, |
|---|
| 13 | + int name_len) |
|---|
| 14 | 14 | { |
|---|
| 15 | 15 | struct btrfs_inode_ref *ref; |
|---|
| 16 | 16 | unsigned long ptr; |
|---|
| .. | .. |
|---|
| 28 | 28 | cur_offset += len + sizeof(*ref); |
|---|
| 29 | 29 | if (len != name_len) |
|---|
| 30 | 30 | continue; |
|---|
| 31 | | - if (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0) { |
|---|
| 32 | | - if (ref_ret) |
|---|
| 33 | | - *ref_ret = ref; |
|---|
| 34 | | - return 1; |
|---|
| 35 | | - } |
|---|
| 31 | + if (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0) |
|---|
| 32 | + return ref; |
|---|
| 36 | 33 | } |
|---|
| 37 | | - return 0; |
|---|
| 34 | + return NULL; |
|---|
| 38 | 35 | } |
|---|
| 39 | 36 | |
|---|
| 40 | | -int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot, |
|---|
| 41 | | - u64 ref_objectid, |
|---|
| 42 | | - const char *name, int name_len, |
|---|
| 43 | | - struct btrfs_inode_extref **extref_ret) |
|---|
| 37 | +struct btrfs_inode_extref *btrfs_find_name_in_ext_backref( |
|---|
| 38 | + struct extent_buffer *leaf, int slot, u64 ref_objectid, |
|---|
| 39 | + const char *name, int name_len) |
|---|
| 44 | 40 | { |
|---|
| 45 | 41 | struct btrfs_inode_extref *extref; |
|---|
| 46 | 42 | unsigned long ptr; |
|---|
| .. | .. |
|---|
| 65 | 61 | |
|---|
| 66 | 62 | if (ref_name_len == name_len && |
|---|
| 67 | 63 | btrfs_inode_extref_parent(leaf, extref) == ref_objectid && |
|---|
| 68 | | - (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)) { |
|---|
| 69 | | - if (extref_ret) |
|---|
| 70 | | - *extref_ret = extref; |
|---|
| 71 | | - return 1; |
|---|
| 72 | | - } |
|---|
| 64 | + (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)) |
|---|
| 65 | + return extref; |
|---|
| 73 | 66 | |
|---|
| 74 | 67 | cur_offset += ref_name_len + sizeof(*extref); |
|---|
| 75 | 68 | } |
|---|
| 76 | | - return 0; |
|---|
| 69 | + return NULL; |
|---|
| 77 | 70 | } |
|---|
| 78 | 71 | |
|---|
| 79 | 72 | /* Returns NULL if no extref found */ |
|---|
| .. | .. |
|---|
| 87 | 80 | { |
|---|
| 88 | 81 | int ret; |
|---|
| 89 | 82 | struct btrfs_key key; |
|---|
| 90 | | - struct btrfs_inode_extref *extref; |
|---|
| 91 | 83 | |
|---|
| 92 | 84 | key.objectid = inode_objectid; |
|---|
| 93 | 85 | key.type = BTRFS_INODE_EXTREF_KEY; |
|---|
| .. | .. |
|---|
| 98 | 90 | return ERR_PTR(ret); |
|---|
| 99 | 91 | if (ret > 0) |
|---|
| 100 | 92 | return NULL; |
|---|
| 101 | | - if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0], |
|---|
| 102 | | - ref_objectid, name, name_len, |
|---|
| 103 | | - &extref)) |
|---|
| 104 | | - return NULL; |
|---|
| 105 | | - return extref; |
|---|
| 93 | + return btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0], |
|---|
| 94 | + ref_objectid, name, name_len); |
|---|
| 95 | + |
|---|
| 106 | 96 | } |
|---|
| 107 | 97 | |
|---|
| 108 | 98 | static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans, |
|---|
| .. | .. |
|---|
| 142 | 132 | * This should always succeed so error here will make the FS |
|---|
| 143 | 133 | * readonly. |
|---|
| 144 | 134 | */ |
|---|
| 145 | | - if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0], |
|---|
| 146 | | - ref_objectid, |
|---|
| 147 | | - name, name_len, &extref)) { |
|---|
| 135 | + extref = btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0], |
|---|
| 136 | + ref_objectid, name, name_len); |
|---|
| 137 | + if (!extref) { |
|---|
| 148 | 138 | btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL); |
|---|
| 149 | 139 | ret = -EROFS; |
|---|
| 150 | 140 | goto out; |
|---|
| .. | .. |
|---|
| 170 | 160 | memmove_extent_buffer(leaf, ptr, ptr + del_len, |
|---|
| 171 | 161 | item_size - (ptr + del_len - item_start)); |
|---|
| 172 | 162 | |
|---|
| 173 | | - btrfs_truncate_item(root->fs_info, path, item_size - del_len, 1); |
|---|
| 163 | + btrfs_truncate_item(path, item_size - del_len, 1); |
|---|
| 174 | 164 | |
|---|
| 175 | 165 | out: |
|---|
| 176 | 166 | btrfs_free_path(path); |
|---|
| .. | .. |
|---|
| 213 | 203 | } else if (ret < 0) { |
|---|
| 214 | 204 | goto out; |
|---|
| 215 | 205 | } |
|---|
| 216 | | - if (!btrfs_find_name_in_backref(path->nodes[0], path->slots[0], |
|---|
| 217 | | - name, name_len, &ref)) { |
|---|
| 206 | + |
|---|
| 207 | + ref = btrfs_find_name_in_backref(path->nodes[0], path->slots[0], name, |
|---|
| 208 | + name_len); |
|---|
| 209 | + if (!ref) { |
|---|
| 218 | 210 | ret = -ENOENT; |
|---|
| 219 | 211 | search_ext_refs = 1; |
|---|
| 220 | 212 | goto out; |
|---|
| .. | .. |
|---|
| 234 | 226 | item_start = btrfs_item_ptr_offset(leaf, path->slots[0]); |
|---|
| 235 | 227 | memmove_extent_buffer(leaf, ptr, ptr + sub_item_len, |
|---|
| 236 | 228 | item_size - (ptr + sub_item_len - item_start)); |
|---|
| 237 | | - btrfs_truncate_item(root->fs_info, path, item_size - sub_item_len, 1); |
|---|
| 229 | + btrfs_truncate_item(path, item_size - sub_item_len, 1); |
|---|
| 238 | 230 | out: |
|---|
| 239 | 231 | btrfs_free_path(path); |
|---|
| 240 | 232 | |
|---|
| .. | .. |
|---|
| 285 | 277 | if (btrfs_find_name_in_ext_backref(path->nodes[0], |
|---|
| 286 | 278 | path->slots[0], |
|---|
| 287 | 279 | ref_objectid, |
|---|
| 288 | | - name, name_len, NULL)) |
|---|
| 280 | + name, name_len)) |
|---|
| 289 | 281 | goto out; |
|---|
| 290 | 282 | |
|---|
| 291 | | - btrfs_extend_item(root->fs_info, path, ins_len); |
|---|
| 283 | + btrfs_extend_item(path, ins_len); |
|---|
| 292 | 284 | ret = 0; |
|---|
| 293 | 285 | } |
|---|
| 294 | 286 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 341 | 333 | ins_len); |
|---|
| 342 | 334 | if (ret == -EEXIST) { |
|---|
| 343 | 335 | u32 old_size; |
|---|
| 344 | | - |
|---|
| 345 | | - if (btrfs_find_name_in_backref(path->nodes[0], path->slots[0], |
|---|
| 346 | | - name, name_len, &ref)) |
|---|
| 336 | + ref = btrfs_find_name_in_backref(path->nodes[0], path->slots[0], |
|---|
| 337 | + name, name_len); |
|---|
| 338 | + if (ref) |
|---|
| 347 | 339 | goto out; |
|---|
| 348 | 340 | |
|---|
| 349 | 341 | old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]); |
|---|
| 350 | | - btrfs_extend_item(fs_info, path, ins_len); |
|---|
| 342 | + btrfs_extend_item(path, ins_len); |
|---|
| 351 | 343 | ref = btrfs_item_ptr(path->nodes[0], path->slots[0], |
|---|
| 352 | 344 | struct btrfs_inode_ref); |
|---|
| 353 | 345 | ref = (struct btrfs_inode_ref *)((unsigned long)ref + old_size); |
|---|
| .. | .. |
|---|
| 359 | 351 | if (ret == -EOVERFLOW) { |
|---|
| 360 | 352 | if (btrfs_find_name_in_backref(path->nodes[0], |
|---|
| 361 | 353 | path->slots[0], |
|---|
| 362 | | - name, name_len, &ref)) |
|---|
| 354 | + name, name_len)) |
|---|
| 363 | 355 | ret = -EEXIST; |
|---|
| 364 | 356 | else |
|---|
| 365 | 357 | ret = -EMLINK; |
|---|