Lines Matching +full:de +full:- +full:be

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Creates, reads, walks and deletes directory-nodes
13 * Laboratoire MASI - Institut Blaise pascal
71 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_supports_dir_trailer()
73 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_supports_dir_trailer()
84 * is turned off. Only directory-initialization type functions should
89 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_new_dir_wants_trailer()
97 return sb->s_blocksize - sizeof(struct ocfs2_dir_block_trailer); in ocfs2_dir_trailer_blk_off()
100 #define ocfs2_trailer_from_bh(_bh, _sb) ((struct ocfs2_dir_block_trailer *) ((_bh)->b_data + ocfs2_…
102 /* XXX ocfs2_block_dqtrailer() is similar but not quite - can we make
109 p += blocksize - sizeof(struct ocfs2_dir_block_trailer); in ocfs2_dir_trailer_from_size()
118 struct ocfs2_dir_entry *de, in ocfs2_skip_dir_trailer() argument
122 unsigned long toff = blklen - sizeof(struct ocfs2_dir_block_trailer); in ocfs2_skip_dir_trailer()
138 trailer = ocfs2_trailer_from_bh(bh, inode->i_sb); in ocfs2_init_dir_trailer()
139 strcpy(trailer->db_signature, OCFS2_DIR_TRAILER_SIGNATURE); in ocfs2_init_dir_trailer()
140 trailer->db_compat_rec_len = in ocfs2_init_dir_trailer()
142 trailer->db_parent_dinode = cpu_to_le64(OCFS2_I(inode)->ip_blkno); in ocfs2_init_dir_trailer()
143 trailer->db_blkno = cpu_to_le64(bh->b_blocknr); in ocfs2_init_dir_trailer()
144 trailer->db_free_rec_len = cpu_to_le16(rec_len); in ocfs2_init_dir_trailer()
165 trailer = ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb); in ocfs2_dx_dir_link_trailer()
166 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_dx_dir_link_trailer()
168 trailer->db_free_next = dx_root->dr_free_blk; in ocfs2_dx_dir_link_trailer()
169 dx_root->dr_free_blk = cpu_to_le64(dirdata_bh->b_blocknr); in ocfs2_dx_dir_link_trailer()
179 return res->dl_prev_leaf_bh == NULL; in ocfs2_free_list_at_root()
184 brelse(res->dl_dx_root_bh); in ocfs2_free_dir_lookup_result()
185 brelse(res->dl_leaf_bh); in ocfs2_free_dir_lookup_result()
186 brelse(res->dl_dx_leaf_bh); in ocfs2_free_dir_lookup_result()
187 brelse(res->dl_prev_leaf_bh); in ocfs2_free_dir_lookup_result()
192 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INDEXED_DIR_FL) in ocfs2_dir_indexed()
199 return dx_root->dr_flags & OCFS2_DX_FLAG_INLINE; in ocfs2_dx_root_inline()
218 } while (--n); in TEA_transform()
242 num--; in str2hashbuf()
245 if (--num >= 0) in str2hashbuf()
247 while (--num >= 0) in str2hashbuf()
254 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_name_hash()
271 * should never allow this to be selected without hand editing in ocfs2_dx_dir_name_hash()
278 memcpy(buf, osb->osb_dx_seed, sizeof(buf)); in ocfs2_dx_dir_name_hash()
284 len -= 16; in ocfs2_dx_dir_name_hash()
289 hinfo->major_hash = buf[0]; in ocfs2_dx_dir_name_hash()
290 hinfo->minor_hash = buf[1]; in ocfs2_dx_dir_name_hash()
294 * bh passed here can be an inode block or a dir data block, depending
298 struct ocfs2_dir_entry * de, in ocfs2_check_dir_entry() argument
303 const int rlen = le16_to_cpu(de->rec_len); in ocfs2_check_dir_entry()
309 else if (unlikely(rlen < OCFS2_DIR_REC_LEN(de->name_len))) in ocfs2_check_dir_entry()
312 ((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)) in ocfs2_check_dir_entry()
316 mlog(ML_ERROR, "bad entry in directory #%llu: %s - " in ocfs2_check_dir_entry()
318 (unsigned long long)OCFS2_I(dir)->ip_blkno, error_msg, in ocfs2_check_dir_entry()
319 offset, (unsigned long long)le64_to_cpu(de->inode), rlen, in ocfs2_check_dir_entry()
320 de->name_len); in ocfs2_check_dir_entry()
327 struct ocfs2_dir_entry *de) in ocfs2_match() argument
329 if (len != de->name_len) in ocfs2_match()
331 if (!de->inode) in ocfs2_match()
333 return !memcmp(name, de->name, len); in ocfs2_match()
337 * Returns 0 if not found, -1 on failure, and 1 on success
347 struct ocfs2_dir_entry *de; in ocfs2_search_dirblock() local
359 de = (struct ocfs2_dir_entry *) de_buf; in ocfs2_search_dirblock()
362 ocfs2_match(namelen, name, de)) { in ocfs2_search_dirblock()
363 /* found a match - just to be sure, do a full check */ in ocfs2_search_dirblock()
364 if (!ocfs2_check_dir_entry(dir, de, bh, offset)) { in ocfs2_search_dirblock()
365 ret = -1; in ocfs2_search_dirblock()
368 *res_dir = de; in ocfs2_search_dirblock()
374 de_len = le16_to_cpu(de->rec_len); in ocfs2_search_dirblock()
376 ret = -1; in ocfs2_search_dirblock()
405 di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_find_entry_id()
406 data = &di->id2.i_data; in ocfs2_find_entry_id()
409 data->id_data, i_size_read(dir), res_dir); in ocfs2_find_entry_id()
428 * in-place when the code walks them. in ocfs2_validate_dir_block()
430 trace_ocfs2_validate_dir_block((unsigned long long)bh->b_blocknr); in ocfs2_validate_dir_block()
443 rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &trailer->db_check); in ocfs2_validate_dir_block()
446 (unsigned long long)bh->b_blocknr); in ocfs2_validate_dir_block()
462 trailer = ocfs2_trailer_from_bh(bh, dir->i_sb); in ocfs2_check_dir_trailer()
464 rc = ocfs2_error(dir->i_sb, in ocfs2_check_dir_trailer()
466 (unsigned long long)bh->b_blocknr, 7, in ocfs2_check_dir_trailer()
467 trailer->db_signature); in ocfs2_check_dir_trailer()
470 if (le64_to_cpu(trailer->db_blkno) != bh->b_blocknr) { in ocfs2_check_dir_trailer()
471 rc = ocfs2_error(dir->i_sb, in ocfs2_check_dir_trailer()
473 (unsigned long long)bh->b_blocknr, in ocfs2_check_dir_trailer()
474 (unsigned long long)le64_to_cpu(trailer->db_blkno)); in ocfs2_check_dir_trailer()
477 if (le64_to_cpu(trailer->db_parent_dinode) != in ocfs2_check_dir_trailer()
478 OCFS2_I(dir)->ip_blkno) { in ocfs2_check_dir_trailer()
479 rc = ocfs2_error(dir->i_sb, in ocfs2_check_dir_trailer()
481 (unsigned long long)bh->b_blocknr, in ocfs2_check_dir_trailer()
482 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_check_dir_trailer()
483 (unsigned long long)le64_to_cpu(trailer->db_blkno)); in ocfs2_check_dir_trailer()
491 * This function forces all errors to -EIO for consistency with its
525 return rc ? -EIO : 0; in ocfs2_read_dir_block()
530 * inode. This function does no virtual->physical block translation -
531 * what's passed in is assumed to be a valid directory block.
570 dx_root = (struct ocfs2_dx_root_block *) bh->b_data; in ocfs2_validate_dx_root()
572 ret = ocfs2_validate_meta_ecc(sb, bh->b_data, &dx_root->dr_check); in ocfs2_validate_dx_root()
576 (unsigned long long)bh->b_blocknr); in ocfs2_validate_dx_root()
583 (unsigned long long)le64_to_cpu(dx_root->dr_blkno), in ocfs2_validate_dx_root()
584 7, dx_root->dr_signature); in ocfs2_validate_dx_root()
594 u64 blkno = le64_to_cpu(di->i_dx_root); in ocfs2_read_dx_root()
611 struct ocfs2_dx_leaf *dx_leaf = (struct ocfs2_dx_leaf *)bh->b_data; in ocfs2_validate_dx_leaf()
615 ret = ocfs2_validate_meta_ecc(sb, bh->b_data, &dx_leaf->dl_check); in ocfs2_validate_dx_leaf()
619 (unsigned long long)bh->b_blocknr); in ocfs2_validate_dx_leaf()
625 7, dx_leaf->dl_signature); in ocfs2_validate_dx_leaf()
649 * pointers to be NULL on function entry.
679 sb = dir->i_sb; in ocfs2_find_entry_el()
681 nblocks = i_size_read(dir) >> sb->s_blocksize_bits; in ocfs2_find_entry_el()
682 start = OCFS2_I(dir)->ip_dir_start_lookup; in ocfs2_find_entry_el()
690 * We deal with the read-ahead logic here. in ocfs2_find_entry_el()
721 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_find_entry_el()
726 block << sb->s_blocksize_bits, in ocfs2_find_entry_el()
727 bh->b_data, sb->s_blocksize, in ocfs2_find_entry_el()
730 OCFS2_I(dir)->ip_dir_start_lookup = block; in ocfs2_find_entry_el()
748 nblocks = i_size_read(dir) >> sb->s_blocksize_bits; in ocfs2_find_entry_el()
755 /* Clean up the read-ahead blocks */ in ocfs2_find_entry_el()
775 if (el->l_tree_depth) { in ocfs2_dx_dir_lookup_rec()
783 eb = (struct ocfs2_extent_block *) eb_bh->b_data; in ocfs2_dx_dir_lookup_rec()
784 el = &eb->h_list; in ocfs2_dx_dir_lookup_rec()
786 if (el->l_tree_depth) { in ocfs2_dx_dir_lookup_rec()
787 ret = ocfs2_error(inode->i_sb, in ocfs2_dx_dir_lookup_rec()
789 inode->i_ino, in ocfs2_dx_dir_lookup_rec()
790 (unsigned long long)eb_bh->b_blocknr); in ocfs2_dx_dir_lookup_rec()
796 for (i = le16_to_cpu(el->l_next_free_rec) - 1; i >= 0; i--) { in ocfs2_dx_dir_lookup_rec()
797 rec = &el->l_recs[i]; in ocfs2_dx_dir_lookup_rec()
799 if (le32_to_cpu(rec->e_cpos) <= major_hash) { in ocfs2_dx_dir_lookup_rec()
806 ret = ocfs2_error(inode->i_sb, in ocfs2_dx_dir_lookup_rec()
808 inode->i_ino, in ocfs2_dx_dir_lookup_rec()
809 le32_to_cpu(rec->e_cpos), in ocfs2_dx_dir_lookup_rec()
815 *ret_phys_blkno = le64_to_cpu(rec->e_blkno); in ocfs2_dx_dir_lookup_rec()
817 *ret_cpos = le32_to_cpu(rec->e_cpos); in ocfs2_dx_dir_lookup_rec()
819 *ret_clen = le16_to_cpu(rec->e_leaf_clusters); in ocfs2_dx_dir_lookup_rec()
833 return minor_hash & osb->osb_dx_mask; in __ocfs2_dx_dir_hash_idx()
839 return __ocfs2_dx_dir_hash_idx(osb, hinfo->minor_hash); in ocfs2_dx_dir_hash_idx()
852 u32 name_hash = hinfo->major_hash; in ocfs2_dx_dir_lookup()
864 blkno += ocfs2_clusters_to_blocks(inode->i_sb, clen - 1); in ocfs2_dx_dir_lookup()
865 cpos += clen - 1; in ocfs2_dx_dir_lookup()
867 blkno += ocfs2_clusters_to_blocks(inode->i_sb, in ocfs2_dx_dir_lookup()
868 name_hash - cpos); in ocfs2_dx_dir_lookup()
877 blkno += ocfs2_dx_dir_hash_idx(OCFS2_SB(inode->i_sb), hinfo); in ocfs2_dx_dir_lookup()
901 struct ocfs2_dx_hinfo *hinfo = &res->dl_hinfo; in ocfs2_dx_dir_search()
905 ocfs2_dx_dir_name_hash(dir, name, namelen, &res->dl_hinfo); in ocfs2_dx_dir_search()
908 entry_list = &dx_root->dr_entries; in ocfs2_dx_dir_search()
912 dr_el = &dx_root->dr_list; in ocfs2_dx_dir_search()
920 trace_ocfs2_dx_dir_search((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_search()
921 namelen, name, hinfo->major_hash, in ocfs2_dx_dir_search()
922 hinfo->minor_hash, (unsigned long long)phys); in ocfs2_dx_dir_search()
930 dx_leaf = (struct ocfs2_dx_leaf *) dx_leaf_bh->b_data; in ocfs2_dx_dir_search()
933 le16_to_cpu(dx_leaf->dl_list.de_num_used), in ocfs2_dx_dir_search()
934 le16_to_cpu(dx_leaf->dl_list.de_count)); in ocfs2_dx_dir_search()
936 entry_list = &dx_leaf->dl_list; in ocfs2_dx_dir_search()
943 for (i = 0; i < le16_to_cpu(entry_list->de_num_used); i++) { in ocfs2_dx_dir_search()
944 dx_entry = &entry_list->de_entries[i]; in ocfs2_dx_dir_search()
946 if (hinfo->major_hash != le32_to_cpu(dx_entry->dx_major_hash) in ocfs2_dx_dir_search()
947 || hinfo->minor_hash != le32_to_cpu(dx_entry->dx_minor_hash)) in ocfs2_dx_dir_search()
955 le64_to_cpu(dx_entry->dx_dirent_blk), in ocfs2_dx_dir_search()
968 0, dir_ent_bh->b_data, in ocfs2_dx_dir_search()
969 dir->i_sb->s_blocksize, &dir_ent); in ocfs2_dx_dir_search()
973 if (found == -1) { in ocfs2_dx_dir_search()
975 ret = -EIO; in ocfs2_dx_dir_search()
985 ret = -ENOENT; in ocfs2_dx_dir_search()
989 res->dl_leaf_bh = dir_ent_bh; in ocfs2_dx_dir_search()
990 res->dl_entry = dir_ent; in ocfs2_dx_dir_search()
991 res->dl_dx_leaf_bh = dx_leaf_bh; in ocfs2_dx_dir_search()
992 res->dl_dx_entry = dx_entry; in ocfs2_dx_dir_search()
1019 di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_find_entry_dx()
1026 dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; in ocfs2_find_entry_dx()
1030 if (ret != -ENOENT) in ocfs2_find_entry_dx()
1035 lookup->dl_dx_root_bh = dx_root_bh; in ocfs2_find_entry_dx()
1046 * If nothing was found, -ENOENT is returned. Otherwise, zero is
1051 * buffer_heads - they are passed back only so that it can be passed
1054 * data block, in the inline-data case it actually points to an inode,
1071 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_find_entry()
1077 return -ENOENT; in ocfs2_find_entry()
1079 lookup->dl_leaf_bh = bh; in ocfs2_find_entry()
1080 lookup->dl_entry = res_dir; in ocfs2_find_entry()
1093 struct ocfs2_dir_entry *de = res->dl_entry; in ocfs2_update_entry() local
1094 struct buffer_head *de_bh = res->dl_leaf_bh; in ocfs2_update_entry()
1097 * The same code works fine for both inline-data and extent in ocfs2_update_entry()
1102 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_update_entry()
1112 de->inode = cpu_to_le64(OCFS2_I(new_entry_inode)->ip_blkno); in ocfs2_update_entry()
1113 ocfs2_set_de_type(de, new_entry_inode->i_mode); in ocfs2_update_entry()
1130 struct ocfs2_dir_entry *de, *pde; in __ocfs2_delete_entry() local
1131 int i, status = -ENOENT; in __ocfs2_delete_entry()
1134 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in __ocfs2_delete_entry()
1139 de = (struct ocfs2_dir_entry *) first_de; in __ocfs2_delete_entry()
1141 if (!ocfs2_check_dir_entry(dir, de, bh, i)) { in __ocfs2_delete_entry()
1142 status = -EIO; in __ocfs2_delete_entry()
1146 if (de == de_del) { in __ocfs2_delete_entry()
1150 status = -EIO; in __ocfs2_delete_entry()
1155 le16_add_cpu(&pde->rec_len, in __ocfs2_delete_entry()
1156 le16_to_cpu(de->rec_len)); in __ocfs2_delete_entry()
1157 de->inode = 0; in __ocfs2_delete_entry()
1162 i += le16_to_cpu(de->rec_len); in __ocfs2_delete_entry()
1163 pde = de; in __ocfs2_delete_entry()
1164 de = (struct ocfs2_dir_entry *)((char *)de + le16_to_cpu(de->rec_len)); in __ocfs2_delete_entry()
1170 static unsigned int ocfs2_figure_dirent_hole(struct ocfs2_dir_entry *de) in ocfs2_figure_dirent_hole() argument
1174 if (le64_to_cpu(de->inode) == 0) in ocfs2_figure_dirent_hole()
1175 hole = le16_to_cpu(de->rec_len); in ocfs2_figure_dirent_hole()
1177 hole = le16_to_cpu(de->rec_len) - in ocfs2_figure_dirent_hole()
1178 OCFS2_DIR_REC_LEN(de->name_len); in ocfs2_figure_dirent_hole()
1187 char *trailer, *de_buf, *limit, *start = dirblock_bh->b_data; in ocfs2_find_max_rec_len()
1188 struct ocfs2_dir_entry *de; in ocfs2_find_max_rec_len() local
1194 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_find_max_rec_len()
1197 this_hole = ocfs2_figure_dirent_hole(de); in ocfs2_find_max_rec_len()
1202 de_buf += le16_to_cpu(de->rec_len); in ocfs2_find_max_rec_len()
1203 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_find_max_rec_len()
1214 int num_used = le16_to_cpu(entry_list->de_num_used); in ocfs2_dx_list_remove_entry()
1216 if (num_used == 1 || index == (num_used - 1)) in ocfs2_dx_list_remove_entry()
1219 memmove(&entry_list->de_entries[index], in ocfs2_dx_list_remove_entry()
1220 &entry_list->de_entries[index + 1], in ocfs2_dx_list_remove_entry()
1221 (num_used - index - 1)*sizeof(struct ocfs2_dx_entry)); in ocfs2_dx_list_remove_entry()
1223 num_used--; in ocfs2_dx_list_remove_entry()
1224 memset(&entry_list->de_entries[num_used], 0, in ocfs2_dx_list_remove_entry()
1226 entry_list->de_num_used = cpu_to_le16(num_used); in ocfs2_dx_list_remove_entry()
1233 struct buffer_head *dx_root_bh = lookup->dl_dx_root_bh; in ocfs2_delete_entry_dx()
1234 struct buffer_head *leaf_bh = lookup->dl_leaf_bh; in ocfs2_delete_entry_dx()
1236 struct ocfs2_dx_entry *dx_entry = lookup->dl_dx_entry; in ocfs2_delete_entry_dx()
1252 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_delete_entry_dx()
1254 entry_list = &dx_root->dr_entries; in ocfs2_delete_entry_dx()
1256 dx_leaf = (struct ocfs2_dx_leaf *) lookup->dl_dx_leaf_bh->b_data; in ocfs2_delete_entry_dx()
1257 entry_list = &dx_leaf->dl_list; in ocfs2_delete_entry_dx()
1260 /* Neither of these are a disk corruption - that should have in ocfs2_delete_entry_dx()
1262 BUG_ON(le16_to_cpu(entry_list->de_count) <= 0); in ocfs2_delete_entry_dx()
1263 BUG_ON(le16_to_cpu(entry_list->de_num_used) <= 0); in ocfs2_delete_entry_dx()
1265 index = (char *)dx_entry - (char *)entry_list->de_entries; in ocfs2_delete_entry_dx()
1268 if (index >= le16_to_cpu(entry_list->de_num_used)) { in ocfs2_delete_entry_dx()
1270 (unsigned long long)OCFS2_I(dir)->ip_blkno, index, in ocfs2_delete_entry_dx()
1272 return -EIO; in ocfs2_delete_entry_dx()
1280 trailer = ocfs2_trailer_from_bh(leaf_bh, dir->i_sb); in ocfs2_delete_entry_dx()
1281 if (trailer->db_free_rec_len == 0) in ocfs2_delete_entry_dx()
1292 * the entry count needs to be updated. Also, we might be in ocfs2_delete_entry_dx()
1304 lookup->dl_dx_leaf_bh, in ocfs2_delete_entry_dx()
1312 trace_ocfs2_delete_entry_dx((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_delete_entry_dx()
1315 ret = __ocfs2_delete_entry(handle, dir, lookup->dl_entry, in ocfs2_delete_entry_dx()
1316 leaf_bh, leaf_bh->b_data, leaf_bh->b_size); in ocfs2_delete_entry_dx()
1322 max_rec_len = ocfs2_find_max_rec_len(dir->i_sb, leaf_bh); in ocfs2_delete_entry_dx()
1323 trailer->db_free_rec_len = cpu_to_le16(max_rec_len); in ocfs2_delete_entry_dx()
1325 trailer->db_free_next = dx_root->dr_free_blk; in ocfs2_delete_entry_dx()
1326 dx_root->dr_free_blk = cpu_to_le64(leaf_bh->b_blocknr); in ocfs2_delete_entry_dx()
1333 le32_add_cpu(&dx_root->dr_num_entries, -1); in ocfs2_delete_entry_dx()
1339 ocfs2_journal_dirty(handle, lookup->dl_dx_leaf_bh); in ocfs2_delete_entry_dx()
1361 di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_delete_entry_id()
1362 data = &di->id2.i_data; in ocfs2_delete_entry_id()
1364 ret = __ocfs2_delete_entry(handle, dir, de_del, bh, data->id_data, in ocfs2_delete_entry_id()
1377 return __ocfs2_delete_entry(handle, dir, de_del, bh, bh->b_data, in ocfs2_delete_entry_el()
1378 bh->b_size); in ocfs2_delete_entry_el()
1392 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_delete_entry()
1393 return ocfs2_delete_entry_id(handle, dir, res->dl_entry, in ocfs2_delete_entry()
1394 res->dl_leaf_bh); in ocfs2_delete_entry()
1396 return ocfs2_delete_entry_el(handle, dir, res->dl_entry, in ocfs2_delete_entry()
1397 res->dl_leaf_bh); in ocfs2_delete_entry()
1401 * Check whether 'de' has enough room to hold an entry of
1404 static inline int ocfs2_dirent_would_fit(struct ocfs2_dir_entry *de, in ocfs2_dirent_would_fit() argument
1410 if (le64_to_cpu(de->inode) == 0 && in ocfs2_dirent_would_fit()
1411 le16_to_cpu(de->rec_len) >= new_rec_len) in ocfs2_dirent_would_fit()
1418 de_really_used = OCFS2_DIR_REC_LEN(de->name_len); in ocfs2_dirent_would_fit()
1419 if (le16_to_cpu(de->rec_len) >= (de_really_used + new_rec_len)) in ocfs2_dirent_would_fit()
1430 i = le16_to_cpu(dx_leaf->dl_list.de_num_used); in ocfs2_dx_dir_leaf_insert_tail()
1431 dx_leaf->dl_list.de_entries[i] = *dx_new_entry; in ocfs2_dx_dir_leaf_insert_tail()
1433 le16_add_cpu(&dx_leaf->dl_list.de_num_used, 1); in ocfs2_dx_dir_leaf_insert_tail()
1443 i = le16_to_cpu(entry_list->de_num_used); in ocfs2_dx_entry_list_insert()
1444 dx_entry = &entry_list->de_entries[i]; in ocfs2_dx_entry_list_insert()
1447 dx_entry->dx_major_hash = cpu_to_le32(hinfo->major_hash); in ocfs2_dx_entry_list_insert()
1448 dx_entry->dx_minor_hash = cpu_to_le32(hinfo->minor_hash); in ocfs2_dx_entry_list_insert()
1449 dx_entry->dx_dirent_blk = cpu_to_le64(dirent_blk); in ocfs2_dx_entry_list_insert()
1451 le16_add_cpu(&entry_list->de_num_used, 1); in ocfs2_dx_entry_list_insert()
1469 dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data; in __ocfs2_dx_dir_leaf_insert()
1470 ocfs2_dx_entry_list_insert(&dx_leaf->dl_list, hinfo, dirent_blk); in __ocfs2_dx_dir_leaf_insert()
1482 ocfs2_dx_entry_list_insert(&dx_root->dr_entries, hinfo, dirent_blk); in ocfs2_dx_inline_root_insert()
1490 struct buffer_head *dx_root_bh = lookup->dl_dx_root_bh; in ocfs2_dx_dir_insert()
1499 dx_root = (struct ocfs2_dx_root_block *)lookup->dl_dx_root_bh->b_data; in ocfs2_dx_dir_insert()
1502 &lookup->dl_hinfo, in ocfs2_dx_dir_insert()
1503 lookup->dl_leaf_bh->b_blocknr, in ocfs2_dx_dir_insert()
1506 ret = __ocfs2_dx_dir_leaf_insert(dir, handle, &lookup->dl_hinfo, in ocfs2_dx_dir_insert()
1507 lookup->dl_leaf_bh->b_blocknr, in ocfs2_dx_dir_insert()
1508 lookup->dl_dx_leaf_bh); in ocfs2_dx_dir_insert()
1513 le32_add_cpu(&dx_root->dr_num_entries, 1); in ocfs2_dx_dir_insert()
1528 trailer = ocfs2_trailer_from_bh(lookup->dl_leaf_bh, dir->i_sb); in ocfs2_remove_block_from_free_list()
1531 bh = lookup->dl_dx_root_bh; in ocfs2_remove_block_from_free_list()
1532 dx_root = (struct ocfs2_dx_root_block *)bh->b_data; in ocfs2_remove_block_from_free_list()
1533 dx_root->dr_free_blk = trailer->db_free_next; in ocfs2_remove_block_from_free_list()
1535 bh = lookup->dl_prev_leaf_bh; in ocfs2_remove_block_from_free_list()
1536 prev = ocfs2_trailer_from_bh(bh, dir->i_sb); in ocfs2_remove_block_from_free_list()
1537 prev->db_free_next = trailer->db_free_next; in ocfs2_remove_block_from_free_list()
1540 trailer->db_free_rec_len = cpu_to_le16(0); in ocfs2_remove_block_from_free_list()
1541 trailer->db_free_next = cpu_to_le64(0); in ocfs2_remove_block_from_free_list()
1544 ocfs2_journal_dirty(handle, lookup->dl_leaf_bh); in ocfs2_remove_block_from_free_list()
1549 * lookup->dl_prev_leaf_bh or lookup->dl_dx_root_bh
1558 max_rec_len = ocfs2_find_max_rec_len(dir->i_sb, lookup->dl_leaf_bh); in ocfs2_recalc_free_list()
1565 trailer = ocfs2_trailer_from_bh(lookup->dl_leaf_bh, dir->i_sb); in ocfs2_recalc_free_list()
1566 trailer->db_free_rec_len = cpu_to_le16(max_rec_len); in ocfs2_recalc_free_list()
1567 ocfs2_journal_dirty(handle, lookup->dl_leaf_bh); in ocfs2_recalc_free_list()
1588 struct ocfs2_dir_entry *de, *de1; in __ocfs2_add_entry() local
1589 struct ocfs2_dinode *di = (struct ocfs2_dinode *)parent_fe_bh->b_data; in __ocfs2_add_entry()
1590 struct super_block *sb = dir->i_sb; in __ocfs2_add_entry()
1592 unsigned int size = sb->s_blocksize; in __ocfs2_add_entry()
1593 struct buffer_head *insert_bh = lookup->dl_leaf_bh; in __ocfs2_add_entry()
1594 char *data_start = insert_bh->b_data; in __ocfs2_add_entry()
1597 return -EINVAL; in __ocfs2_add_entry()
1607 * XXX: This can be either a dx_root_block, or an unindexed in __ocfs2_add_entry()
1611 bh = lookup->dl_dx_root_bh; in __ocfs2_add_entry()
1616 bh = lookup->dl_prev_leaf_bh; in __ocfs2_add_entry()
1625 } else if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in __ocfs2_add_entry()
1626 data_start = di->id2.i_data.id_data; in __ocfs2_add_entry()
1634 de = (struct ocfs2_dir_entry *) data_start; in __ocfs2_add_entry()
1636 BUG_ON((char *)de >= (size + data_start)); in __ocfs2_add_entry()
1641 if (!ocfs2_check_dir_entry(dir, de, insert_bh, offset)) { in __ocfs2_add_entry()
1642 retval = -ENOENT; in __ocfs2_add_entry()
1645 if (ocfs2_match(namelen, name, de)) { in __ocfs2_add_entry()
1646 retval = -EEXIST; in __ocfs2_add_entry()
1652 mlog_bug_on_msg(ocfs2_skip_dir_trailer(dir, de, offset, size), in __ocfs2_add_entry()
1657 (unsigned long long)parent_fe_bh->b_blocknr, in __ocfs2_add_entry()
1658 offset, ocfs2_dir_trailer_blk_off(dir->i_sb)); in __ocfs2_add_entry()
1660 if (ocfs2_dirent_would_fit(de, rec_len)) { in __ocfs2_add_entry()
1661 dir->i_mtime = dir->i_ctime = current_time(dir); in __ocfs2_add_entry()
1691 offset += le16_to_cpu(de->rec_len); in __ocfs2_add_entry()
1692 if (le64_to_cpu(de->inode)) { in __ocfs2_add_entry()
1693 de1 = (struct ocfs2_dir_entry *)((char *) de + in __ocfs2_add_entry()
1694 OCFS2_DIR_REC_LEN(de->name_len)); in __ocfs2_add_entry()
1695 de1->rec_len = in __ocfs2_add_entry()
1696 cpu_to_le16(le16_to_cpu(de->rec_len) - in __ocfs2_add_entry()
1697 OCFS2_DIR_REC_LEN(de->name_len)); in __ocfs2_add_entry()
1698 de->rec_len = cpu_to_le16(OCFS2_DIR_REC_LEN(de->name_len)); in __ocfs2_add_entry()
1699 de = de1; in __ocfs2_add_entry()
1701 de->file_type = FT_UNKNOWN; in __ocfs2_add_entry()
1703 de->inode = cpu_to_le64(blkno); in __ocfs2_add_entry()
1704 ocfs2_set_de_type(de, inode->i_mode); in __ocfs2_add_entry()
1706 de->inode = 0; in __ocfs2_add_entry()
1707 de->name_len = namelen; in __ocfs2_add_entry()
1708 memcpy(de->name, name, namelen); in __ocfs2_add_entry()
1719 offset += le16_to_cpu(de->rec_len); in __ocfs2_add_entry()
1720 de = (struct ocfs2_dir_entry *) ((char *) de + le16_to_cpu(de->rec_len)); in __ocfs2_add_entry()
1725 retval = -ENOSPC; in __ocfs2_add_entry()
1738 unsigned long offset = ctx->pos; in ocfs2_dir_foreach_blk_id()
1742 struct ocfs2_dir_entry *de; in ocfs2_dir_foreach_blk_id() local
1747 (unsigned long long)OCFS2_I(inode)->ip_blkno); in ocfs2_dir_foreach_blk_id()
1751 di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_dir_foreach_blk_id()
1752 data = &di->id2.i_data; in ocfs2_dir_foreach_blk_id()
1754 while (ctx->pos < i_size_read(inode)) { in ocfs2_dir_foreach_blk_id()
1756 * readdir(2), then we might be pointing to an invalid in ocfs2_dir_foreach_blk_id()
1761 de = (struct ocfs2_dir_entry *) in ocfs2_dir_foreach_blk_id()
1762 (data->id_data + i); in ocfs2_dir_foreach_blk_id()
1766 * least that it is non-zero. A in ocfs2_dir_foreach_blk_id()
1767 * failure will be detected in the in ocfs2_dir_foreach_blk_id()
1769 if (le16_to_cpu(de->rec_len) < in ocfs2_dir_foreach_blk_id()
1772 i += le16_to_cpu(de->rec_len); in ocfs2_dir_foreach_blk_id()
1774 ctx->pos = offset = i; in ocfs2_dir_foreach_blk_id()
1778 de = (struct ocfs2_dir_entry *) (data->id_data + ctx->pos); in ocfs2_dir_foreach_blk_id()
1779 if (!ocfs2_check_dir_entry(inode, de, di_bh, ctx->pos)) { in ocfs2_dir_foreach_blk_id()
1781 ctx->pos = i_size_read(inode); in ocfs2_dir_foreach_blk_id()
1784 offset += le16_to_cpu(de->rec_len); in ocfs2_dir_foreach_blk_id()
1785 if (le64_to_cpu(de->inode)) { in ocfs2_dir_foreach_blk_id()
1786 if (!dir_emit(ctx, de->name, de->name_len, in ocfs2_dir_foreach_blk_id()
1787 le64_to_cpu(de->inode), in ocfs2_dir_foreach_blk_id()
1788 fs_ftype_to_dtype(de->file_type))) in ocfs2_dir_foreach_blk_id()
1791 ctx->pos += le16_to_cpu(de->rec_len); in ocfs2_dir_foreach_blk_id()
1799 * NOTE: This function can be called against unindexed directories,
1810 struct ocfs2_dir_entry * de; in ocfs2_dir_foreach_blk_el() local
1811 struct super_block * sb = inode->i_sb; in ocfs2_dir_foreach_blk_el()
1817 offset = ctx->pos & (sb->s_blocksize - 1); in ocfs2_dir_foreach_blk_el()
1819 while (ctx->pos < i_size_read(inode)) { in ocfs2_dir_foreach_blk_el()
1820 blk = ctx->pos >> sb->s_blocksize_bits; in ocfs2_dir_foreach_blk_el()
1823 ctx->pos += sb->s_blocksize - offset; in ocfs2_dir_foreach_blk_el()
1827 /* The idea here is to begin with 8k read-ahead and to stay in ocfs2_dir_foreach_blk_el()
1831 * make sure it's cluster-safe... */ in ocfs2_dir_foreach_blk_el()
1833 || (((last_ra_blk - blk) << 9) <= (ra_sectors / 2))) { in ocfs2_dir_foreach_blk_el()
1834 for (i = ra_sectors >> (sb->s_blocksize_bits - 9); in ocfs2_dir_foreach_blk_el()
1835 i > 0; i--) { in ocfs2_dir_foreach_blk_el()
1846 * readdir(2), then we might be pointing to an invalid in ocfs2_dir_foreach_blk_el()
1850 for (i = 0; i < sb->s_blocksize && i < offset; ) { in ocfs2_dir_foreach_blk_el()
1851 de = (struct ocfs2_dir_entry *) (bh->b_data + i); in ocfs2_dir_foreach_blk_el()
1855 * least that it is non-zero. A in ocfs2_dir_foreach_blk_el()
1856 * failure will be detected in the in ocfs2_dir_foreach_blk_el()
1858 if (le16_to_cpu(de->rec_len) < in ocfs2_dir_foreach_blk_el()
1861 i += le16_to_cpu(de->rec_len); in ocfs2_dir_foreach_blk_el()
1864 ctx->pos = (ctx->pos & ~(sb->s_blocksize - 1)) in ocfs2_dir_foreach_blk_el()
1869 while (ctx->pos < i_size_read(inode) in ocfs2_dir_foreach_blk_el()
1870 && offset < sb->s_blocksize) { in ocfs2_dir_foreach_blk_el()
1871 de = (struct ocfs2_dir_entry *) (bh->b_data + offset); in ocfs2_dir_foreach_blk_el()
1872 if (!ocfs2_check_dir_entry(inode, de, bh, offset)) { in ocfs2_dir_foreach_blk_el()
1875 ctx->pos = (ctx->pos | (sb->s_blocksize - 1)) + 1; in ocfs2_dir_foreach_blk_el()
1878 if (le64_to_cpu(de->inode)) { in ocfs2_dir_foreach_blk_el()
1879 if (!dir_emit(ctx, de->name, in ocfs2_dir_foreach_blk_el()
1880 de->name_len, in ocfs2_dir_foreach_blk_el()
1881 le64_to_cpu(de->inode), in ocfs2_dir_foreach_blk_el()
1882 fs_ftype_to_dtype(de->file_type))) { in ocfs2_dir_foreach_blk_el()
1888 offset += le16_to_cpu(de->rec_len); in ocfs2_dir_foreach_blk_el()
1889 ctx->pos += le16_to_cpu(de->rec_len); in ocfs2_dir_foreach_blk_el()
1904 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_dir_foreach_blk()
1910 * This is intended to be called from inside other kernel functions,
1930 trace_ocfs2_readdir((unsigned long long)OCFS2_I(inode)->ip_blkno); in ocfs2_readdir()
1932 error = ocfs2_inode_lock_atime(inode, file->f_path.mnt, &lock_level, 1); in ocfs2_readdir()
1942 if (error != -ENOENT) in ocfs2_readdir()
1948 error = ocfs2_dir_foreach_blk(inode, &file->f_version, ctx, false); in ocfs2_readdir()
1960 * NOTE: this should always be called with parent dir i_rwsem taken.
1968 int status = -ENOENT; in ocfs2_find_files_on_disk()
1971 (unsigned long long)OCFS2_I(inode)->ip_blkno); in ocfs2_find_files_on_disk()
1977 *blkno = le64_to_cpu(lookup->dl_entry->inode); in ocfs2_find_files_on_disk()
2004 * Return -EEXIST if the directory contains the name
2016 (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen, name); in ocfs2_check_dir_for_entry()
2019 ret = -EEXIST; in ocfs2_check_dir_for_entry()
2043 * Check the positions of "." and ".." records to be sure in ocfs2_empty_dir_filldir()
2054 p->seen_dot = 1; in ocfs2_empty_dir_filldir()
2060 p->seen_dot_dot = 1; in ocfs2_empty_dir_filldir()
2062 if (p->dx_dir && p->seen_dot) in ocfs2_empty_dir_filldir()
2068 p->seen_other = 1; in ocfs2_empty_dir_filldir()
2081 priv->dx_dir = 1; in ocfs2_empty_dir_dx()
2088 di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_empty_dir_dx()
2095 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_empty_dir_dx()
2097 if (le32_to_cpu(dx_root->dr_num_entries) != 2) in ocfs2_empty_dir_dx()
2098 priv->seen_other = 1; in ocfs2_empty_dir_dx()
2135 mlog(ML_ERROR, "bad directory (dir #%llu) - no `.' or `..'\n", in ocfs2_empty_dir()
2136 (unsigned long long)OCFS2_I(inode)->ip_blkno); in ocfs2_empty_dir()
2148 * "..", which might be used during creation of a directory with a trailing
2156 struct ocfs2_dir_entry *de = (struct ocfs2_dir_entry *)start; in ocfs2_fill_initial_dirents() local
2158 de->inode = cpu_to_le64(OCFS2_I(inode)->ip_blkno); in ocfs2_fill_initial_dirents()
2159 de->name_len = 1; in ocfs2_fill_initial_dirents()
2160 de->rec_len = in ocfs2_fill_initial_dirents()
2161 cpu_to_le16(OCFS2_DIR_REC_LEN(de->name_len)); in ocfs2_fill_initial_dirents()
2162 strcpy(de->name, "."); in ocfs2_fill_initial_dirents()
2163 ocfs2_set_de_type(de, S_IFDIR); in ocfs2_fill_initial_dirents()
2165 de = (struct ocfs2_dir_entry *) ((char *)de + le16_to_cpu(de->rec_len)); in ocfs2_fill_initial_dirents()
2166 de->inode = cpu_to_le64(OCFS2_I(parent)->ip_blkno); in ocfs2_fill_initial_dirents()
2167 de->rec_len = cpu_to_le16(size - OCFS2_DIR_REC_LEN(1)); in ocfs2_fill_initial_dirents()
2168 de->name_len = 2; in ocfs2_fill_initial_dirents()
2169 strcpy(de->name, ".."); in ocfs2_fill_initial_dirents()
2170 ocfs2_set_de_type(de, S_IFDIR); in ocfs2_fill_initial_dirents()
2172 return de; in ocfs2_fill_initial_dirents()
2177 * the inline-data flag and initializes the inline-data section.
2186 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_fill_new_dir_id()
2187 struct ocfs2_inline_data *data = &di->id2.i_data; in ocfs2_fill_new_dir_id()
2188 unsigned int size = le16_to_cpu(data->id_count); in ocfs2_fill_new_dir_id()
2197 ocfs2_fill_initial_dirents(inode, parent, data->id_data, size); in ocfs2_fill_new_dir_id()
2202 inode->i_blocks = ocfs2_inode_sector_count(inode); in ocfs2_fill_new_dir_id()
2221 unsigned int size = osb->sb->s_blocksize; in ocfs2_fill_new_dir_el()
2223 struct ocfs2_dir_entry *de; in ocfs2_fill_new_dir_el() local
2226 size = ocfs2_dir_trailer_blk_off(parent->i_sb); in ocfs2_fill_new_dir_el()
2228 status = ocfs2_do_extend_dir(osb->sb, handle, inode, fe_bh, in ocfs2_fill_new_dir_el()
2243 memset(new_bh->b_data, 0, osb->sb->s_blocksize); in ocfs2_fill_new_dir_el()
2245 de = ocfs2_fill_initial_dirents(inode, parent, new_bh->b_data, size); in ocfs2_fill_new_dir_el()
2247 int size = le16_to_cpu(de->rec_len); in ocfs2_fill_new_dir_el()
2254 size -= OCFS2_DIR_REC_LEN(2); in ocfs2_fill_new_dir_el()
2255 size -= sizeof(struct ocfs2_dir_block_trailer); in ocfs2_fill_new_dir_el()
2262 i_size_write(inode, inode->i_sb->s_blocksize); in ocfs2_fill_new_dir_el()
2264 inode->i_blocks = ocfs2_inode_sector_count(inode); in ocfs2_fill_new_dir_el()
2291 struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data; in ocfs2_dx_dir_attach_index()
2298 ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb); in ocfs2_dx_dir_attach_index()
2308 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_attach_index()
2311 dx_root_bh = sb_getblk(osb->sb, dr_blkno); in ocfs2_dx_dir_attach_index()
2313 ret = -ENOMEM; in ocfs2_dx_dir_attach_index()
2325 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_dx_dir_attach_index()
2326 memset(dx_root, 0, osb->sb->s_blocksize); in ocfs2_dx_dir_attach_index()
2327 strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE); in ocfs2_dx_dir_attach_index()
2328 dx_root->dr_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); in ocfs2_dx_dir_attach_index()
2329 dx_root->dr_suballoc_loc = cpu_to_le64(suballoc_loc); in ocfs2_dx_dir_attach_index()
2330 dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit); in ocfs2_dx_dir_attach_index()
2331 dx_root->dr_fs_generation = cpu_to_le32(osb->fs_generation); in ocfs2_dx_dir_attach_index()
2332 dx_root->dr_blkno = cpu_to_le64(dr_blkno); in ocfs2_dx_dir_attach_index()
2333 dx_root->dr_dir_blkno = cpu_to_le64(OCFS2_I(dir)->ip_blkno); in ocfs2_dx_dir_attach_index()
2334 dx_root->dr_num_entries = cpu_to_le32(num_entries); in ocfs2_dx_dir_attach_index()
2335 if (le16_to_cpu(trailer->db_free_rec_len)) in ocfs2_dx_dir_attach_index()
2336 dx_root->dr_free_blk = cpu_to_le64(dirdata_bh->b_blocknr); in ocfs2_dx_dir_attach_index()
2338 dx_root->dr_free_blk = cpu_to_le64(0); in ocfs2_dx_dir_attach_index()
2341 dx_root->dr_flags |= OCFS2_DX_FLAG_INLINE; in ocfs2_dx_dir_attach_index()
2342 dx_root->dr_entries.de_count = in ocfs2_dx_dir_attach_index()
2343 cpu_to_le16(ocfs2_dx_entries_per_root(osb->sb)); in ocfs2_dx_dir_attach_index()
2345 dx_root->dr_list.l_count = in ocfs2_dx_dir_attach_index()
2346 cpu_to_le16(ocfs2_extent_recs_per_dx_root(osb->sb)); in ocfs2_dx_dir_attach_index()
2357 di->i_dx_root = cpu_to_le64(dr_blkno); in ocfs2_dx_dir_attach_index()
2359 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_attach_index()
2360 OCFS2_I(dir)->ip_dyn_features |= OCFS2_INDEXED_DIR_FL; in ocfs2_dx_dir_attach_index()
2361 di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features); in ocfs2_dx_dir_attach_index()
2362 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_attach_index()
2384 bh = sb_getblk(osb->sb, start_blk + i); in ocfs2_dx_dir_format_cluster()
2386 ret = -ENOMEM; in ocfs2_dx_dir_format_cluster()
2400 dx_leaf = (struct ocfs2_dx_leaf *) bh->b_data; in ocfs2_dx_dir_format_cluster()
2402 memset(dx_leaf, 0, osb->sb->s_blocksize); in ocfs2_dx_dir_format_cluster()
2403 strcpy(dx_leaf->dl_signature, OCFS2_DX_LEAF_SIGNATURE); in ocfs2_dx_dir_format_cluster()
2404 dx_leaf->dl_fs_generation = cpu_to_le32(osb->fs_generation); in ocfs2_dx_dir_format_cluster()
2405 dx_leaf->dl_blkno = cpu_to_le64(bh->b_blocknr); in ocfs2_dx_dir_format_cluster()
2406 dx_leaf->dl_list.de_count = in ocfs2_dx_dir_format_cluster()
2407 cpu_to_le16(ocfs2_dx_entries_per_leaf(osb->sb)); in ocfs2_dx_dir_format_cluster()
2410 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_format_cluster()
2411 (unsigned long long)bh->b_blocknr, in ocfs2_dx_dir_format_cluster()
2412 le16_to_cpu(dx_leaf->dl_list.de_count)); in ocfs2_dx_dir_format_cluster()
2424 * leaf. This version will not do the extent insert, so that it can be
2436 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in __ocfs2_dx_dir_new_cluster()
2454 phys_blkno = ocfs2_clusters_to_blocks(osb->sb, phys); in __ocfs2_dx_dir_new_cluster()
2546 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_fill_new_dir_dx()
2547 entry_list = &dx_root->dr_entries; in ocfs2_fill_new_dir_dx()
2551 ocfs2_dx_entry_list_insert(entry_list, &hinfo, leaf_bh->b_blocknr); in ocfs2_fill_new_dir_dx()
2554 ocfs2_dx_entry_list_insert(entry_list, &hinfo, leaf_bh->b_blocknr); in ocfs2_fill_new_dir_dx()
2573 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_fill_new_dir()
2593 struct ocfs2_dir_entry *de; in ocfs2_dx_dir_index_block() local
2596 u64 dirent_blk = dirent_bh->b_blocknr; in ocfs2_dx_dir_index_block()
2598 de_buf = dirent_bh->b_data; in ocfs2_dx_dir_index_block()
2599 limit = de_buf + dir->i_sb->s_blocksize; in ocfs2_dx_dir_index_block()
2602 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_dx_dir_index_block()
2604 namelen = de->name_len; in ocfs2_dx_dir_index_block()
2605 if (!namelen || !de->inode) in ocfs2_dx_dir_index_block()
2608 ocfs2_dx_dir_name_hash(dir, de->name, namelen, &hinfo); in ocfs2_dx_dir_index_block()
2610 i = ocfs2_dx_dir_hash_idx(OCFS2_SB(dir->i_sb), &hinfo); in ocfs2_dx_dir_index_block()
2623 de_buf += le16_to_cpu(de->rec_len); in ocfs2_dx_dir_index_block()
2631 * XXX: This expects dx_root_bh to already be part of the transaction.
2639 struct ocfs2_dir_entry *de; in ocfs2_dx_dir_index_root_block() local
2641 u64 dirent_blk = dirent_bh->b_blocknr; in ocfs2_dx_dir_index_root_block()
2643 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_dx_dir_index_root_block()
2645 de_buf = dirent_bh->b_data; in ocfs2_dx_dir_index_root_block()
2646 limit = de_buf + dir->i_sb->s_blocksize; in ocfs2_dx_dir_index_root_block()
2649 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_dx_dir_index_root_block()
2651 if (!de->name_len || !de->inode) in ocfs2_dx_dir_index_root_block()
2654 ocfs2_dx_dir_name_hash(dir, de->name, de->name_len, &hinfo); in ocfs2_dx_dir_index_root_block()
2657 (unsigned long long)dir->i_ino, in ocfs2_dx_dir_index_root_block()
2659 de->name_len, de->name, in ocfs2_dx_dir_index_root_block()
2660 le16_to_cpu(dx_root->dr_entries.de_num_used)); in ocfs2_dx_dir_index_root_block()
2662 ocfs2_dx_entry_list_insert(&dx_root->dr_entries, &hinfo, in ocfs2_dx_dir_index_root_block()
2665 le32_add_cpu(&dx_root->dr_num_entries, 1); in ocfs2_dx_dir_index_root_block()
2667 de_buf += le16_to_cpu(de->rec_len); in ocfs2_dx_dir_index_root_block()
2681 struct ocfs2_dir_entry *de; in ocfs2_new_dx_should_be_inline() local
2682 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_new_dx_should_be_inline()
2684 de_buf = di->id2.i_data.id_data; in ocfs2_new_dx_should_be_inline()
2688 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_new_dx_should_be_inline()
2690 if (de->name_len && de->inode) in ocfs2_new_dx_should_be_inline()
2693 de_buf += le16_to_cpu(de->rec_len); in ocfs2_new_dx_should_be_inline()
2697 return dirent_count < ocfs2_dx_entries_per_root(dir->i_sb); in ocfs2_new_dx_should_be_inline()
2717 struct super_block *sb = dir->i_sb; in ocfs2_expand_last_dirent()
2718 struct ocfs2_dir_entry *de; in ocfs2_expand_last_dirent() local
2721 unsigned int new_size = sb->s_blocksize; in ocfs2_expand_last_dirent()
2728 bytes = new_size - old_size; in ocfs2_expand_last_dirent()
2732 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_expand_last_dirent()
2734 this_hole = ocfs2_figure_dirent_hole(de); in ocfs2_expand_last_dirent()
2738 prev_de = de; in ocfs2_expand_last_dirent()
2739 de_buf += le16_to_cpu(de->rec_len); in ocfs2_expand_last_dirent()
2740 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_expand_last_dirent()
2743 le16_add_cpu(&prev_de->rec_len, bytes); in ocfs2_expand_last_dirent()
2770 struct super_block *sb = dir->i_sb; in ocfs2_expand_inline_dir()
2774 bytes = blocks_wanted << sb->s_blocksize_bits; in ocfs2_expand_inline_dir()
2775 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_expand_inline_dir()
2782 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_expand_inline_dir()
2793 down_write(&oi->ip_alloc_sem); in ocfs2_expand_inline_dir()
2805 ret = -ENOMEM; in ocfs2_expand_inline_dir()
2821 * tree - maximum dirent size is far less than one block. In in ocfs2_expand_inline_dir()
2850 ocfs2_clusters_to_bytes(osb->sb, alloc + dx_alloc)); in ocfs2_expand_inline_dir()
2868 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
2874 * will be claimed after the conversion to extents. in ocfs2_expand_inline_dir()
2877 data_ac->ac_resv = &oi->ip_la_data_resv; in ocfs2_expand_inline_dir()
2883 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
2890 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); in ocfs2_expand_inline_dir()
2893 ret = -ENOMEM; in ocfs2_expand_inline_dir()
2907 memcpy(dirdata_bh->b_data, di->id2.i_data.id_data, i_size_read(dir)); in ocfs2_expand_inline_dir()
2908 memset(dirdata_bh->b_data + i_size_read(dir), 0, in ocfs2_expand_inline_dir()
2909 sb->s_blocksize - i_size_read(dir)); in ocfs2_expand_inline_dir()
2910 i = ocfs2_expand_last_dirent(dirdata_bh->b_data, i_size_read(dir), dir); in ocfs2_expand_inline_dir()
2930 * be correctly set once the dx_root has been in ocfs2_expand_inline_dir()
2945 * be fully accessible from system calls. in ocfs2_expand_inline_dir()
2947 * We let the later dirent insert modify c/mtime - to the user in ocfs2_expand_inline_dir()
2957 spin_lock(&oi->ip_lock); in ocfs2_expand_inline_dir()
2958 oi->ip_dyn_features &= ~OCFS2_INLINE_DATA_FL; in ocfs2_expand_inline_dir()
2959 di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); in ocfs2_expand_inline_dir()
2960 spin_unlock(&oi->ip_lock); in ocfs2_expand_inline_dir()
2964 i_size_write(dir, sb->s_blocksize); in ocfs2_expand_inline_dir()
2965 dir->i_mtime = dir->i_ctime = current_time(dir); in ocfs2_expand_inline_dir()
2967 di->i_size = cpu_to_le64(sb->s_blocksize); in ocfs2_expand_inline_dir()
2968 di->i_ctime = di->i_mtime = cpu_to_le64(dir->i_ctime.tv_sec); in ocfs2_expand_inline_dir()
2969 di->i_ctime_nsec = di->i_mtime_nsec = cpu_to_le32(dir->i_ctime.tv_nsec); in ocfs2_expand_inline_dir()
2987 dir->i_blocks = ocfs2_inode_sector_count(dir); in ocfs2_expand_inline_dir()
3025 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); in ocfs2_expand_inline_dir()
3033 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
3047 &lookup->dl_hinfo); in ocfs2_expand_inline_dir()
3049 lookup->dl_dx_leaf_bh = dx_leaves[off]; in ocfs2_expand_inline_dir()
3051 lookup->dl_dx_root_bh = dx_root_bh; in ocfs2_expand_inline_dir()
3062 up_write(&oi->ip_alloc_sem); in ocfs2_expand_inline_dir()
3093 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_do_extend_dir()
3094 extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)); in ocfs2_do_extend_dir()
3095 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_do_extend_dir()
3098 u32 offset = OCFS2_I(dir)->ip_clusters; in ocfs2_do_extend_dir()
3109 BUG_ON(status == -EAGAIN); in ocfs2_do_extend_dir()
3125 status = -ENOMEM; in ocfs2_do_extend_dir()
3140 * is to be turned into an extent based one. The size of the dirent to
3141 * insert might be larger than the space gained by growing to just one
3144 * If the directory is already indexed, dx_root_bh must be provided.
3156 struct ocfs2_dinode *fe = (struct ocfs2_dinode *) parent_fe_bh->b_data; in ocfs2_extend_dir()
3157 struct ocfs2_extent_list *el = &fe->id2.i_list; in ocfs2_extend_dir()
3162 struct ocfs2_dir_entry * de; in ocfs2_extend_dir() local
3163 struct super_block *sb = osb->sb; in ocfs2_extend_dir()
3165 struct buffer_head *dx_root_bh = lookup->dl_dx_root_bh; in ocfs2_extend_dir()
3167 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in ocfs2_extend_dir()
3169 * This would be a code error as an inline directory should in ocfs2_extend_dir()
3184 dx_root_bh = lookup->dl_dx_root_bh; in ocfs2_extend_dir()
3199 * Get rid of 'new_bh' - we want to format the 2nd in ocfs2_extend_dir()
3205 down_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3212 down_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3215 trace_ocfs2_extend_dir((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_extend_dir()
3218 /* dir->i_size is always block aligned. */ in ocfs2_extend_dir()
3219 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3220 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { in ocfs2_extend_dir()
3221 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3234 if (status != -ENOSPC) in ocfs2_extend_dir()
3242 if (status != -ENOSPC) in ocfs2_extend_dir()
3248 data_ac->ac_resv = &OCFS2_I(dir)->ip_la_data_resv; in ocfs2_extend_dir()
3252 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3269 status = ocfs2_do_extend_dir(osb->sb, handle, dir, parent_fe_bh, in ocfs2_extend_dir()
3284 memset(new_bh->b_data, 0, sb->s_blocksize); in ocfs2_extend_dir()
3286 de = (struct ocfs2_dir_entry *) new_bh->b_data; in ocfs2_extend_dir()
3287 de->inode = 0; in ocfs2_extend_dir()
3289 de->rec_len = cpu_to_le16(ocfs2_dir_trailer_blk_off(sb)); in ocfs2_extend_dir()
3291 ocfs2_init_dir_trailer(dir, new_bh, le16_to_cpu(de->rec_len)); in ocfs2_extend_dir()
3302 de->rec_len = cpu_to_le16(sb->s_blocksize); in ocfs2_extend_dir()
3307 dir_i_size += dir->i_sb->s_blocksize; in ocfs2_extend_dir()
3309 dir->i_blocks = ocfs2_inode_sector_count(dir); in ocfs2_extend_dir()
3323 up_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3341 struct super_block *sb = dir->i_sb; in ocfs2_find_dir_space_id()
3342 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_find_dir_space_id()
3343 struct ocfs2_dir_entry *de, *last_de = NULL; in ocfs2_find_dir_space_id() local
3353 free_space = ocfs2_dir_trailer_blk_off(sb) - i_size_read(dir); in ocfs2_find_dir_space_id()
3355 free_space = dir->i_sb->s_blocksize - i_size_read(dir); in ocfs2_find_dir_space_id()
3357 de_buf = di->id2.i_data.id_data; in ocfs2_find_dir_space_id()
3362 de = (struct ocfs2_dir_entry *)de_buf; in ocfs2_find_dir_space_id()
3364 if (!ocfs2_check_dir_entry(dir, de, di_bh, offset)) { in ocfs2_find_dir_space_id()
3365 ret = -ENOENT; in ocfs2_find_dir_space_id()
3368 if (ocfs2_match(namelen, name, de)) { in ocfs2_find_dir_space_id()
3369 ret = -EEXIST; in ocfs2_find_dir_space_id()
3377 if (ocfs2_dirent_would_fit(de, rec_len)) { in ocfs2_find_dir_space_id()
3386 last_de = de; in ocfs2_find_dir_space_id()
3387 de_buf += le16_to_cpu(de->rec_len); in ocfs2_find_dir_space_id()
3388 offset += le16_to_cpu(de->rec_len); in ocfs2_find_dir_space_id()
3392 * We're going to require expansion of the directory - figure in ocfs2_find_dir_space_id()
3394 * dirent can be found. in ocfs2_find_dir_space_id()
3397 new_rec_len = le16_to_cpu(last_de->rec_len) + free_space; in ocfs2_find_dir_space_id()
3398 if (new_rec_len < (rec_len + OCFS2_DIR_REC_LEN(last_de->name_len))) in ocfs2_find_dir_space_id()
3401 ret = -ENOSPC; in ocfs2_find_dir_space_id()
3412 struct ocfs2_dir_entry *de; in ocfs2_find_dir_space_el() local
3413 struct super_block *sb = dir->i_sb; in ocfs2_find_dir_space_el()
3415 int blocksize = dir->i_sb->s_blocksize; in ocfs2_find_dir_space_el()
3423 de = (struct ocfs2_dir_entry *) bh->b_data; in ocfs2_find_dir_space_el()
3425 if ((char *)de >= sb->s_blocksize + bh->b_data) { in ocfs2_find_dir_space_el()
3434 status = -ENOSPC; in ocfs2_find_dir_space_el()
3438 offset >> sb->s_blocksize_bits, in ocfs2_find_dir_space_el()
3444 de = (struct ocfs2_dir_entry *) bh->b_data; in ocfs2_find_dir_space_el()
3446 if (!ocfs2_check_dir_entry(dir, de, bh, offset)) { in ocfs2_find_dir_space_el()
3447 status = -ENOENT; in ocfs2_find_dir_space_el()
3450 if (ocfs2_match(namelen, name, de)) { in ocfs2_find_dir_space_el()
3451 status = -EEXIST; in ocfs2_find_dir_space_el()
3455 if (ocfs2_skip_dir_trailer(dir, de, offset % blocksize, in ocfs2_find_dir_space_el()
3459 if (ocfs2_dirent_would_fit(de, rec_len)) { in ocfs2_find_dir_space_el()
3468 offset += le16_to_cpu(de->rec_len); in ocfs2_find_dir_space_el()
3469 de = (struct ocfs2_dir_entry *)((char *) de + le16_to_cpu(de->rec_len)); in ocfs2_find_dir_space_el()
3484 u32 major_hash1 = le32_to_cpu(entry1->dx_major_hash); in dx_leaf_sort_cmp()
3485 u32 major_hash2 = le32_to_cpu(entry2->dx_major_hash); in dx_leaf_sort_cmp()
3486 u32 minor_hash1 = le32_to_cpu(entry1->dx_minor_hash); in dx_leaf_sort_cmp()
3487 u32 minor_hash2 = le32_to_cpu(entry2->dx_minor_hash); in dx_leaf_sort_cmp()
3492 return -1; in dx_leaf_sort_cmp()
3500 return -1; in dx_leaf_sort_cmp()
3516 struct ocfs2_dx_entry_list *dl_list = &dx_leaf->dl_list; in ocfs2_dx_leaf_same_major()
3517 int i, num = le16_to_cpu(dl_list->de_num_used); in ocfs2_dx_leaf_same_major()
3519 for (i = 0; i < (num - 1); i++) { in ocfs2_dx_leaf_same_major()
3520 if (le32_to_cpu(dl_list->de_entries[i].dx_major_hash) != in ocfs2_dx_leaf_same_major()
3521 le32_to_cpu(dl_list->de_entries[i + 1].dx_major_hash)) in ocfs2_dx_leaf_same_major()
3530 * entries to be in sorted order.
3535 * This function is only concerned with the major hash - that which
3542 struct ocfs2_dx_entry_list *dl_list = &dx_leaf->dl_list; in ocfs2_dx_dir_find_leaf_split()
3543 int i, num_used = le16_to_cpu(dl_list->de_num_used); in ocfs2_dx_dir_find_leaf_split()
3556 u32 val = le32_to_cpu(dl_list->de_entries[0].dx_major_hash); in ocfs2_dx_dir_find_leaf_split()
3564 * won't be space after the split. in ocfs2_dx_dir_find_leaf_split()
3566 return -ENOSPC; in ocfs2_dx_dir_find_leaf_split()
3574 * know that insert_hash *must* be larger than in ocfs2_dx_dir_find_leaf_split()
3577 * We also know then, that there cannot be an in ocfs2_dx_dir_find_leaf_split()
3578 * adjacent extent (otherwise we'd be looking in ocfs2_dx_dir_find_leaf_split()
3588 * val can not be the same as insert hash, and in ocfs2_dx_dir_find_leaf_split()
3589 * also must be larger than leaf_cpos. Also, in ocfs2_dx_dir_find_leaf_split()
3590 * we know that there can't be a leaf between in ocfs2_dx_dir_find_leaf_split()
3592 * hash 'val' would be there. in ocfs2_dx_dir_find_leaf_split()
3609 if (le32_to_cpu(dl_list->de_entries[i].dx_major_hash) > in ocfs2_dx_dir_find_leaf_split()
3613 BUG_ON(i == num_used); /* Should be impossible */ in ocfs2_dx_dir_find_leaf_split()
3614 *split_hash = le32_to_cpu(dl_list->de_entries[i].dx_major_hash); in ocfs2_dx_dir_find_leaf_split()
3624 * of minor_hash, we can optimize - an item at block offset X within
3625 * the original cluster, will be at offset X within the new cluster.
3640 tmp_list = &tmp_dx_leaf->dl_list; in ocfs2_dx_dir_transfer_leaf()
3643 orig_dx_leaf = (struct ocfs2_dx_leaf *) orig_dx_leaves[i]->b_data; in ocfs2_dx_dir_transfer_leaf()
3644 orig_list = &orig_dx_leaf->dl_list; in ocfs2_dx_dir_transfer_leaf()
3645 new_dx_leaf = (struct ocfs2_dx_leaf *) new_dx_leaves[i]->b_data; in ocfs2_dx_dir_transfer_leaf()
3647 num_used = le16_to_cpu(orig_list->de_num_used); in ocfs2_dx_dir_transfer_leaf()
3649 memcpy(tmp_dx_leaf, orig_dx_leaf, dir->i_sb->s_blocksize); in ocfs2_dx_dir_transfer_leaf()
3650 tmp_list->de_num_used = cpu_to_le16(0); in ocfs2_dx_dir_transfer_leaf()
3651 memset(&tmp_list->de_entries, 0, sizeof(*dx_entry)*num_used); in ocfs2_dx_dir_transfer_leaf()
3654 dx_entry = &orig_list->de_entries[j]; in ocfs2_dx_dir_transfer_leaf()
3655 major_hash = le32_to_cpu(dx_entry->dx_major_hash); in ocfs2_dx_dir_transfer_leaf()
3663 memcpy(orig_dx_leaf, tmp_dx_leaf, dir->i_sb->s_blocksize); in ocfs2_dx_dir_transfer_leaf()
3673 int credits = ocfs2_clusters_to_blocks(osb->sb, 3); in ocfs2_dx_dir_rebalance_credits()
3675 credits += ocfs2_calc_extend_credits(osb->sb, &dx_root->dr_list); in ocfs2_dx_dir_rebalance_credits()
3676 credits += ocfs2_quota_trans_credits(osb->sb); in ocfs2_dx_dir_rebalance_credits()
3690 struct ocfs2_dx_leaf *dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data; in ocfs2_dx_dir_rebalance()
3692 u32 cpos, split_hash, insert_hash = hinfo->major_hash; in ocfs2_dx_dir_rebalance()
3703 trace_ocfs2_dx_dir_rebalance((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_rebalance()
3709 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_dx_dir_rebalance()
3714 if (le32_to_cpu(dx_root->dr_clusters) == UINT_MAX) in ocfs2_dx_dir_rebalance()
3715 return -ENOSPC; in ocfs2_dx_dir_rebalance()
3717 num_used = le16_to_cpu(dx_leaf->dl_list.de_num_used); in ocfs2_dx_dir_rebalance()
3718 if (num_used < le16_to_cpu(dx_leaf->dl_list.de_count)) { in ocfs2_dx_dir_rebalance()
3720 "%llu, %d\n", (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_rebalance()
3722 ret = -EIO; in ocfs2_dx_dir_rebalance()
3726 orig_dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->sb, &num_dx_leaves); in ocfs2_dx_dir_rebalance()
3728 ret = -ENOMEM; in ocfs2_dx_dir_rebalance()
3733 new_dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->sb, NULL); in ocfs2_dx_dir_rebalance()
3735 ret = -ENOMEM; in ocfs2_dx_dir_rebalance()
3742 if (ret != -ENOSPC) in ocfs2_dx_dir_rebalance()
3757 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_dx_dir_rebalance()
3772 sort(dx_leaf->dl_list.de_entries, num_used, in ocfs2_dx_dir_rebalance()
3789 * which want to be in the new cluster before insert, but in in ocfs2_dx_dir_rebalance()
3805 tmp_dx_leaf = kmalloc(osb->sb->s_blocksize, GFP_NOFS); in ocfs2_dx_dir_rebalance()
3807 ret = -ENOMEM; in ocfs2_dx_dir_rebalance()
3812 orig_leaves_start = ocfs2_block_to_cluster_start(dir->i_sb, leaf_blkno); in ocfs2_dx_dir_rebalance()
3853 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_dx_dir_rebalance()
3892 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_find_dir_space_dx()
3895 ret = ocfs2_dx_dir_lookup(dir, &dx_root->dr_list, &lookup->dl_hinfo, in ocfs2_find_dir_space_dx()
3908 dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data; in ocfs2_find_dir_space_dx()
3910 if (le16_to_cpu(dx_leaf->dl_list.de_num_used) >= in ocfs2_find_dir_space_dx()
3911 le16_to_cpu(dx_leaf->dl_list.de_count)) { in ocfs2_find_dir_space_dx()
3920 ret = -ENOSPC; in ocfs2_find_dir_space_dx()
3925 &lookup->dl_hinfo, leaf_cpos, in ocfs2_find_dir_space_dx()
3928 if (ret != -ENOSPC) in ocfs2_find_dir_space_dx()
3944 lookup->dl_dx_leaf_bh = dx_leaf_bh; in ocfs2_find_dir_space_dx()
3957 int ret = -ENOSPC; in ocfs2_search_dx_free_list()
3964 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_search_dx_free_list()
3965 next_block = le64_to_cpu(dx_root->dr_free_blk); in ocfs2_search_dx_free_list()
3978 db = ocfs2_trailer_from_bh(leaf_bh, dir->i_sb); in ocfs2_search_dx_free_list()
3979 if (rec_len <= le16_to_cpu(db->db_free_rec_len)) { in ocfs2_search_dx_free_list()
3980 lookup->dl_leaf_bh = leaf_bh; in ocfs2_search_dx_free_list()
3981 lookup->dl_prev_leaf_bh = prev_leaf_bh; in ocfs2_search_dx_free_list()
3987 next_block = le64_to_cpu(db->db_free_next); in ocfs2_search_dx_free_list()
3991 ret = -ENOSPC; in ocfs2_search_dx_free_list()
4008 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_expand_inline_dx_root()
4021 dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->sb, &num_dx_leaves); in ocfs2_expand_inline_dx_root()
4023 ret = -ENOMEM; in ocfs2_expand_inline_dx_root()
4028 handle = ocfs2_start_trans(osb, ocfs2_calc_dxi_expand_credits(osb->sb)); in ocfs2_expand_inline_dx_root()
4036 ocfs2_clusters_to_bytes(osb->sb, 1)); in ocfs2_expand_inline_dx_root()
4064 dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; in ocfs2_expand_inline_dx_root()
4065 entry_list = &dx_root->dr_entries; in ocfs2_expand_inline_dx_root()
4067 for (i = 0; i < le16_to_cpu(entry_list->de_num_used); i++) { in ocfs2_expand_inline_dx_root()
4068 dx_entry = &entry_list->de_entries[i]; in ocfs2_expand_inline_dx_root()
4071 le32_to_cpu(dx_entry->dx_minor_hash)); in ocfs2_expand_inline_dx_root()
4072 target_leaf = (struct ocfs2_dx_leaf *)dx_leaves[j]->b_data; in ocfs2_expand_inline_dx_root()
4080 dx_root->dr_flags &= ~OCFS2_DX_FLAG_INLINE; in ocfs2_expand_inline_dx_root()
4081 memset(&dx_root->dr_list, 0, osb->sb->s_blocksize - in ocfs2_expand_inline_dx_root()
4083 dx_root->dr_list.l_count = in ocfs2_expand_inline_dx_root()
4084 cpu_to_le16(ocfs2_extent_recs_per_dx_root(osb->sb)); in ocfs2_expand_inline_dx_root()
4100 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_expand_inline_dx_root()
4121 dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; in ocfs2_inline_dx_has_space()
4122 entry_list = &dx_root->dr_entries; in ocfs2_inline_dx_has_space()
4124 if (le16_to_cpu(entry_list->de_num_used) >= in ocfs2_inline_dx_has_space()
4125 le16_to_cpu(entry_list->de_count)) in ocfs2_inline_dx_has_space()
4126 return -ENOSPC; in ocfs2_inline_dx_has_space()
4138 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_prepare_dx_dir_for_insert()
4141 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_prepare_dx_dir_for_insert()
4150 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_prepare_dx_dir_for_insert()
4151 if (le32_to_cpu(dx_root->dr_num_entries) == OCFS2_DX_ENTRIES_MAX) { in ocfs2_prepare_dx_dir_for_insert()
4152 ret = -ENOSPC; in ocfs2_prepare_dx_dir_for_insert()
4196 if (ret && ret != -ENOSPC) { in ocfs2_prepare_dx_dir_for_insert()
4201 /* Do this up here - ocfs2_extend_dir might need the dx_root */ in ocfs2_prepare_dx_dir_for_insert()
4202 lookup->dl_dx_root_bh = dx_root_bh; in ocfs2_prepare_dx_dir_for_insert()
4205 if (ret == -ENOSPC) { in ocfs2_prepare_dx_dir_for_insert()
4217 lookup->dl_prev_leaf_bh = NULL; in ocfs2_prepare_dx_dir_for_insert()
4218 lookup->dl_leaf_bh = leaf_bh; in ocfs2_prepare_dx_dir_for_insert()
4230 * lookup result that ocfs2_add_entry() will be able complete the task
4245 (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen); in ocfs2_prepare_dir_for_insert()
4248 ret = -EINVAL; in ocfs2_prepare_dir_for_insert()
4256 * The directory might start inline, then be turned into an in ocfs2_prepare_dir_for_insert()
4265 ocfs2_dx_dir_name_hash(dir, name, namelen, &lookup->dl_hinfo); in ocfs2_prepare_dir_for_insert()
4275 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in ocfs2_prepare_dir_for_insert()
4281 if (ret && ret != -ENOSPC) { in ocfs2_prepare_dir_for_insert()
4286 if (ret == -ENOSPC) { in ocfs2_prepare_dir_for_insert()
4295 if (ret != -ENOSPC) in ocfs2_prepare_dir_for_insert()
4303 lookup->dl_leaf_bh = bh; in ocfs2_prepare_dir_for_insert()
4315 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_remove_index()
4316 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_dx_dir_remove_index()
4325 dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; in ocfs2_dx_dir_remove_index()
4329 le16_to_cpu(dx_root->dr_suballoc_slot)); in ocfs2_dx_dir_remove_index()
4331 ret = -ENOMEM; in ocfs2_dx_dir_remove_index()
4357 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_remove_index()
4358 OCFS2_I(dir)->ip_dyn_features &= ~OCFS2_INDEXED_DIR_FL; in ocfs2_dx_dir_remove_index()
4359 di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features); in ocfs2_dx_dir_remove_index()
4360 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_remove_index()
4361 di->i_dx_root = cpu_to_le64(0ULL); in ocfs2_dx_dir_remove_index()
4366 blk = le64_to_cpu(dx_root->dr_blkno); in ocfs2_dx_dir_remove_index()
4367 bit = le16_to_cpu(dx_root->dr_suballoc_bit); in ocfs2_dx_dir_remove_index()
4368 if (dx_root->dr_suballoc_loc) in ocfs2_dx_dir_remove_index()
4369 bg_blkno = le64_to_cpu(dx_root->dr_suballoc_loc); in ocfs2_dx_dir_remove_index()
4397 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_truncate()
4400 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; in ocfs2_dx_dir_truncate()
4414 dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; in ocfs2_dx_dir_truncate()
4422 while (le32_to_cpu(dx_root->dr_clusters)) { in ocfs2_dx_dir_truncate()
4423 ret = ocfs2_dx_dir_lookup_rec(dir, &dx_root->dr_list, in ocfs2_dx_dir_truncate()
4430 p_cpos = ocfs2_blocks_to_clusters(dir->i_sb, blkno); in ocfs2_dx_dir_truncate()
4442 major_hash = cpos - 1; in ocfs2_dx_dir_truncate()