Lines Matching +full:time +full:- +full:slots

1 // SPDX-License-Identifier: GPL-2.0
9 #include "inode-item.h"
10 #include "disk-io.h"
12 #include "space-info.h"
14 #include "extent-tree.h"
15 #include "file-item.h"
35 if (len != name->len) in btrfs_find_name_in_backref()
37 if (memcmp_extent_buffer(leaf, name->name, name_ptr, in btrfs_find_name_in_backref()
38 name->len) == 0) in btrfs_find_name_in_backref()
60 * looking through any collisions so most of the time this is in btrfs_find_name_in_ext_backref()
66 name_ptr = (unsigned long)(&extref->name); in btrfs_find_name_in_ext_backref()
69 if (ref_name_len == name->len && in btrfs_find_name_in_ext_backref()
71 (memcmp_extent_buffer(leaf, name->name, name_ptr, in btrfs_find_name_in_ext_backref()
72 name->len) == 0)) in btrfs_find_name_in_ext_backref()
94 key.offset = btrfs_extref_hash(ref_objectid, name->name, name->len); in btrfs_lookup_inode_extref()
101 return btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0], in btrfs_lookup_inode_extref()
117 int del_len = name->len + sizeof(*extref); in btrfs_del_inode_extref()
124 key.offset = btrfs_extref_hash(ref_objectid, name->name, name->len); in btrfs_del_inode_extref()
128 return -ENOMEM; in btrfs_del_inode_extref()
130 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in btrfs_del_inode_extref()
132 ret = -ENOENT; in btrfs_del_inode_extref()
137 * Sanity check - did we find the right item for this name? in btrfs_del_inode_extref()
141 extref = btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0], in btrfs_del_inode_extref()
144 btrfs_abort_transaction(trans, -ENOENT); in btrfs_del_inode_extref()
145 ret = -ENOENT; in btrfs_del_inode_extref()
149 leaf = path->nodes[0]; in btrfs_del_inode_extref()
150 item_size = btrfs_item_size(leaf, path->slots[0]); in btrfs_del_inode_extref()
164 item_start = btrfs_item_ptr_offset(leaf, path->slots[0]); in btrfs_del_inode_extref()
167 item_size - (ptr + del_len - item_start)); in btrfs_del_inode_extref()
169 btrfs_truncate_item(trans, path, item_size - del_len, 1); in btrfs_del_inode_extref()
191 int del_len = name->len + sizeof(*ref); in btrfs_del_inode_ref()
199 return -ENOMEM; in btrfs_del_inode_ref()
201 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in btrfs_del_inode_ref()
203 ret = -ENOENT; in btrfs_del_inode_ref()
210 ref = btrfs_find_name_in_backref(path->nodes[0], path->slots[0], name); in btrfs_del_inode_ref()
212 ret = -ENOENT; in btrfs_del_inode_ref()
216 leaf = path->nodes[0]; in btrfs_del_inode_ref()
217 item_size = btrfs_item_size(leaf, path->slots[0]); in btrfs_del_inode_ref()
227 sub_item_len = name->len + sizeof(*ref); in btrfs_del_inode_ref()
228 item_start = btrfs_item_ptr_offset(leaf, path->slots[0]); in btrfs_del_inode_ref()
230 item_size - (ptr + sub_item_len - item_start)); in btrfs_del_inode_ref()
231 btrfs_truncate_item(trans, path, item_size - sub_item_len, 1); in btrfs_del_inode_ref()
261 int ins_len = name->len + sizeof(*extref); in btrfs_insert_inode_extref()
269 key.offset = btrfs_extref_hash(ref_objectid, name->name, name->len); in btrfs_insert_inode_extref()
273 return -ENOMEM; in btrfs_insert_inode_extref()
277 if (ret == -EEXIST) { in btrfs_insert_inode_extref()
278 if (btrfs_find_name_in_ext_backref(path->nodes[0], in btrfs_insert_inode_extref()
279 path->slots[0], in btrfs_insert_inode_extref()
290 leaf = path->nodes[0]; in btrfs_insert_inode_extref()
291 ptr = (unsigned long)btrfs_item_ptr(leaf, path->slots[0], char); in btrfs_insert_inode_extref()
292 ptr += btrfs_item_size(leaf, path->slots[0]) - ins_len; in btrfs_insert_inode_extref()
295 btrfs_set_inode_extref_name_len(path->nodes[0], extref, name->len); in btrfs_insert_inode_extref()
296 btrfs_set_inode_extref_index(path->nodes[0], extref, index); in btrfs_insert_inode_extref()
297 btrfs_set_inode_extref_parent(path->nodes[0], extref, ref_objectid); in btrfs_insert_inode_extref()
299 ptr = (unsigned long)&extref->name; in btrfs_insert_inode_extref()
300 write_extent_buffer(path->nodes[0], name->name, ptr, name->len); in btrfs_insert_inode_extref()
301 btrfs_mark_buffer_dirty(trans, path->nodes[0]); in btrfs_insert_inode_extref()
308 /* Will return 0, -ENOMEM, -EMLINK, or -EEXIST or anything from the CoW path */
313 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_insert_inode_ref()
319 int ins_len = name->len + sizeof(*ref); in btrfs_insert_inode_ref()
327 return -ENOMEM; in btrfs_insert_inode_ref()
329 path->skip_release_on_error = 1; in btrfs_insert_inode_ref()
332 if (ret == -EEXIST) { in btrfs_insert_inode_ref()
334 ref = btrfs_find_name_in_backref(path->nodes[0], path->slots[0], in btrfs_insert_inode_ref()
339 old_size = btrfs_item_size(path->nodes[0], path->slots[0]); in btrfs_insert_inode_ref()
341 ref = btrfs_item_ptr(path->nodes[0], path->slots[0], in btrfs_insert_inode_ref()
344 btrfs_set_inode_ref_name_len(path->nodes[0], ref, name->len); in btrfs_insert_inode_ref()
345 btrfs_set_inode_ref_index(path->nodes[0], ref, index); in btrfs_insert_inode_ref()
349 if (ret == -EOVERFLOW) { in btrfs_insert_inode_ref()
350 if (btrfs_find_name_in_backref(path->nodes[0], in btrfs_insert_inode_ref()
351 path->slots[0], in btrfs_insert_inode_ref()
353 ret = -EEXIST; in btrfs_insert_inode_ref()
355 ret = -EMLINK; in btrfs_insert_inode_ref()
359 ref = btrfs_item_ptr(path->nodes[0], path->slots[0], in btrfs_insert_inode_ref()
361 btrfs_set_inode_ref_name_len(path->nodes[0], ref, name->len); in btrfs_insert_inode_ref()
362 btrfs_set_inode_ref_index(path->nodes[0], ref, index); in btrfs_insert_inode_ref()
365 write_extent_buffer(path->nodes[0], name->name, ptr, name->len); in btrfs_insert_inode_ref()
366 btrfs_mark_buffer_dirty(trans, path->nodes[0]); in btrfs_insert_inode_ref()
371 if (ret == -EMLINK) { in btrfs_insert_inode_ref()
372 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_insert_inode_ref()
404 int ins_len = mod < 0 ? -1 : 0; in btrfs_lookup_inode()
412 if (ret > 0 && location->type == BTRFS_ROOT_ITEM_KEY && in btrfs_lookup_inode()
413 location->offset == (u64)-1 && path->slots[0] != 0) { in btrfs_lookup_inode()
414 slot = path->slots[0] - 1; in btrfs_lookup_inode()
415 leaf = path->nodes[0]; in btrfs_lookup_inode()
417 if (found_key.objectid == location->objectid && in btrfs_lookup_inode()
418 found_key.type == location->type) { in btrfs_lookup_inode()
419 path->slots[0]--; in btrfs_lookup_inode()
462 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_truncate_inode_items()
468 u64 new_size = control->new_size; in btrfs_truncate_inode_items()
472 u32 found_type = (u8)-1; in btrfs_truncate_inode_items()
476 int extent_type = -1; in btrfs_truncate_inode_items()
481 ASSERT(control->inode || !control->clear_extent_range); in btrfs_truncate_inode_items()
482 ASSERT(new_size == 0 || control->min_type == BTRFS_EXTENT_DATA_KEY); in btrfs_truncate_inode_items()
484 control->last_size = new_size; in btrfs_truncate_inode_items()
485 control->sub_bytes = 0; in btrfs_truncate_inode_items()
488 * For shareable roots we want to back off from time to time, this turns in btrfs_truncate_inode_items()
491 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in btrfs_truncate_inode_items()
496 return -ENOMEM; in btrfs_truncate_inode_items()
497 path->reada = READA_BACK; in btrfs_truncate_inode_items()
499 key.objectid = control->ino; in btrfs_truncate_inode_items()
500 key.offset = (u64)-1; in btrfs_truncate_inode_items()
501 key.type = (u8)-1; in btrfs_truncate_inode_items()
506 * huge file in a single leaf. Most of the time that bytes_deleted is in btrfs_truncate_inode_items()
507 * > 0, it will be huge by the time we get here in btrfs_truncate_inode_items()
511 ret = -EAGAIN; in btrfs_truncate_inode_items()
515 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in btrfs_truncate_inode_items()
522 if (path->slots[0] == 0) in btrfs_truncate_inode_items()
524 path->slots[0]--; in btrfs_truncate_inode_items()
532 leaf = path->nodes[0]; in btrfs_truncate_inode_items()
533 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); in btrfs_truncate_inode_items()
536 if (found_key.objectid != control->ino) in btrfs_truncate_inode_items()
539 if (found_type < control->min_type) in btrfs_truncate_inode_items()
544 fi = btrfs_item_ptr(leaf, path->slots[0], in btrfs_truncate_inode_items()
553 btrfs_trace_truncate(control->inode, leaf, fi, in btrfs_truncate_inode_items()
555 path->slots[0]); in btrfs_truncate_inode_items()
556 item_end--; in btrfs_truncate_inode_items()
558 if (found_type > control->min_type) { in btrfs_truncate_inode_items()
573 control->extents_found++; in btrfs_truncate_inode_items()
583 extent_num_bytes = ALIGN(new_size - in btrfs_truncate_inode_items()
585 fs_info->sectorsize); in btrfs_truncate_inode_items()
586 clear_start = ALIGN(new_size, fs_info->sectorsize); in btrfs_truncate_inode_items()
590 num_dec = (orig_num_bytes - extent_num_bytes); in btrfs_truncate_inode_items()
592 control->sub_bytes += num_dec; in btrfs_truncate_inode_items()
597 extent_offset = found_key.offset - in btrfs_truncate_inode_items()
603 control->sub_bytes += num_dec; in btrfs_truncate_inode_items()
615 u32 size = (u32)(new_size - found_key.offset); in btrfs_truncate_inode_items()
633 clear_len = fs_info->sectorsize; in btrfs_truncate_inode_items()
636 control->sub_bytes += item_end + 1 - new_size; in btrfs_truncate_inode_items()
644 if (control->clear_extent_range) { in btrfs_truncate_inode_items()
645 ret = btrfs_inode_clear_file_extent_range(control->inode, in btrfs_truncate_inode_items()
655 ((path->slots[0] + 1) == pending_del_slot)); in btrfs_truncate_inode_items()
657 control->last_size = found_key.offset; in btrfs_truncate_inode_items()
660 pending_del_slot = path->slots[0]; in btrfs_truncate_inode_items()
662 } else if (path->slots[0] + 1 == pending_del_slot) { in btrfs_truncate_inode_items()
665 pending_del_slot = path->slots[0]; in btrfs_truncate_inode_items()
668 control->last_size = new_size; in btrfs_truncate_inode_items()
672 if (del_item && extent_start != 0 && !control->skip_ref_updates) { in btrfs_truncate_inode_items()
683 btrfs_init_data_ref(&ref, control->ino, extent_offset, in btrfs_truncate_inode_items()
697 if (path->slots[0] == 0 || in btrfs_truncate_inode_items()
698 path->slots[0] != pending_del_slot || in btrfs_truncate_inode_items()
726 ret = -EAGAIN; in btrfs_truncate_inode_items()
732 path->slots[0]--; in btrfs_truncate_inode_items()
747 ASSERT(control->last_size >= new_size); in btrfs_truncate_inode_items()
748 if (!ret && control->last_size > new_size) in btrfs_truncate_inode_items()
749 control->last_size = new_size; in btrfs_truncate_inode_items()