Lines Matching full:dir

3  * dir.c
9 * Portions of this code from linux/fs/ext3/dir.c
18 * linux/fs/minix/dir.c
37 #include "dir.h"
58 struct inode *dir,
69 static int ocfs2_supports_dir_trailer(struct inode *dir) in ocfs2_supports_dir_trailer() argument
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()
76 return ocfs2_meta_ecc(osb) || ocfs2_dir_indexed(dir); in ocfs2_supports_dir_trailer()
87 static int ocfs2_new_dir_wants_trailer(struct inode *dir) in ocfs2_new_dir_wants_trailer() argument
89 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_new_dir_wants_trailer()
117 static int ocfs2_skip_dir_trailer(struct inode *dir, in ocfs2_skip_dir_trailer() argument
124 if (!ocfs2_supports_dir_trailer(dir)) in ocfs2_skip_dir_trailer()
147 * Link an unindexed block with a dir trailer structure into the index free
151 static int ocfs2_dx_dir_link_trailer(struct inode *dir, handle_t *handle, in ocfs2_dx_dir_link_trailer() argument
159 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_dx_dir_link_trailer()
165 trailer = ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb); in ocfs2_dx_dir_link_trailer()
251 static void ocfs2_dx_dir_name_hash(struct inode *dir, const char *name, int len, in ocfs2_dx_dir_name_hash() argument
254 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_name_hash()
294 * bh passed here can be an inode block or a dir data block, depending
297 static int ocfs2_check_dir_entry(struct inode *dir, in ocfs2_check_dir_entry() argument
323 (unsigned long long)OCFS2_I(dir)->ip_blkno, error_msg, in ocfs2_check_dir_entry()
345 struct inode *dir, in ocfs2_search_dirblock() argument
369 if (!ocfs2_check_dir_entry(dir, de, bh, first_de, in ocfs2_search_dirblock()
397 struct inode *dir, in ocfs2_find_entry_id() argument
405 ret = ocfs2_read_inode_block(dir, &di_bh); in ocfs2_find_entry_id()
414 found = ocfs2_search_dirblock(di_bh, dir, name, namelen, 0, in ocfs2_find_entry_id()
415 data->id_data, i_size_read(dir), res_dir); in ocfs2_find_entry_id()
463 static int ocfs2_check_dir_trailer(struct inode *dir, struct buffer_head *bh) in ocfs2_check_dir_trailer() argument
468 trailer = ocfs2_trailer_from_bh(bh, dir->i_sb); in ocfs2_check_dir_trailer()
470 rc = ocfs2_error(dir->i_sb, in ocfs2_check_dir_trailer()
477 rc = ocfs2_error(dir->i_sb, in ocfs2_check_dir_trailer()
484 OCFS2_I(dir)->ip_blkno) { in ocfs2_check_dir_trailer()
485 rc = ocfs2_error(dir->i_sb, in ocfs2_check_dir_trailer()
488 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_check_dir_trailer()
539 static int ocfs2_read_dir_block_direct(struct inode *dir, u64 phys, in ocfs2_read_dir_block_direct() argument
545 ret = ocfs2_read_block(INODE_CACHE(dir), phys, &tmp, in ocfs2_read_dir_block_direct()
552 if (ocfs2_supports_dir_trailer(dir)) { in ocfs2_read_dir_block_direct()
553 ret = ocfs2_check_dir_trailer(dir, tmp); in ocfs2_read_dir_block_direct()
581 "Checksum failed for dir index root block %llu\n", in ocfs2_validate_dx_root()
588 "Dir Index Root # %llu has bad signature %.*s\n", in ocfs2_validate_dx_root()
596 static int ocfs2_read_dx_root(struct inode *dir, struct ocfs2_dinode *di, in ocfs2_read_dx_root() argument
603 ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp, in ocfs2_read_dx_root()
624 "Checksum failed for dir index leaf block %llu\n", in ocfs2_validate_dx_leaf()
630 ret = ocfs2_error(sb, "Dir Index Leaf has bad signature %.*s\n", in ocfs2_validate_dx_leaf()
637 static int ocfs2_read_dx_leaf(struct inode *dir, u64 blkno, in ocfs2_read_dx_leaf() argument
643 ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp, in ocfs2_read_dx_leaf()
657 static int ocfs2_read_dx_leaves(struct inode *dir, u64 start, int num, in ocfs2_read_dx_leaves() argument
662 ret = ocfs2_read_blocks(INODE_CACHE(dir), start, num, dx_leaf_bhs, 0, in ocfs2_read_dx_leaves()
671 struct inode *dir, in ocfs2_find_entry_el() argument
685 sb = dir->i_sb; in ocfs2_find_entry_el()
687 nblocks = i_size_read(dir) >> sb->s_blocksize_bits; in ocfs2_find_entry_el()
688 start = OCFS2_I(dir)->ip_dir_start_lookup; in ocfs2_find_entry_el()
715 ocfs2_read_dir_block(dir, b++, &bh, in ocfs2_find_entry_el()
722 if (ocfs2_read_dir_block(dir, block, &bh, 0)) { in ocfs2_find_entry_el()
727 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_find_entry_el()
731 i = ocfs2_search_dirblock(bh, dir, name, namelen, in ocfs2_find_entry_el()
736 OCFS2_I(dir)->ip_dir_start_lookup = block; in ocfs2_find_entry_el()
754 nblocks = i_size_read(dir) >> sb->s_blocksize_bits; in ocfs2_find_entry_el()
896 struct inode *dir, in ocfs2_dx_dir_search() argument
911 ocfs2_dx_dir_name_hash(dir, name, namelen, &res->dl_hinfo); in ocfs2_dx_dir_search()
920 ret = ocfs2_dx_dir_lookup(dir, dr_el, hinfo, NULL, &phys); in ocfs2_dx_dir_search()
926 trace_ocfs2_dx_dir_search((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_search()
930 ret = ocfs2_read_dx_leaf(dir, phys, &dx_leaf_bh); in ocfs2_dx_dir_search()
960 ret = ocfs2_read_dir_block_direct(dir, in ocfs2_dx_dir_search()
973 found = ocfs2_search_dirblock(dir_ent_bh, dir, name, namelen, in ocfs2_dx_dir_search()
975 dir->i_sb->s_blocksize, &dir_ent); in ocfs2_dx_dir_search()
1010 struct inode *dir, in ocfs2_find_entry_dx() argument
1019 ret = ocfs2_read_inode_block(dir, &di_bh); in ocfs2_find_entry_dx()
1027 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh); in ocfs2_find_entry_dx()
1034 ret = ocfs2_dx_dir_search(name, namelen, dir, dx_root, lookup); in ocfs2_find_entry_dx()
1050 * Try to find an entry of the provided name within 'dir'.
1064 struct inode *dir, struct ocfs2_dir_lookup_result *lookup) in ocfs2_find_entry() argument
1069 if (ocfs2_dir_indexed(dir)) in ocfs2_find_entry()
1070 return ocfs2_find_entry_dx(name, namelen, dir, lookup); in ocfs2_find_entry()
1073 * The unindexed dir code only uses part of the lookup in ocfs2_find_entry()
1077 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_find_entry()
1078 bh = ocfs2_find_entry_id(name, namelen, dir, &res_dir); in ocfs2_find_entry()
1080 bh = ocfs2_find_entry_el(name, namelen, dir, &res_dir); in ocfs2_find_entry()
1093 int ocfs2_update_entry(struct inode *dir, handle_t *handle, in ocfs2_update_entry() argument
1108 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_update_entry()
1111 ret = access(handle, INODE_CACHE(dir), de_bh, in ocfs2_update_entry()
1131 static int __ocfs2_delete_entry(handle_t *handle, struct inode *dir, in __ocfs2_delete_entry() argument
1140 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in __ocfs2_delete_entry()
1147 if (!ocfs2_check_dir_entry(dir, de, bh, first_de, bytes, i)) { in __ocfs2_delete_entry()
1153 status = access(handle, INODE_CACHE(dir), bh, in __ocfs2_delete_entry()
1164 inode_inc_iversion(dir); in __ocfs2_delete_entry()
1235 static int ocfs2_delete_entry_dx(handle_t *handle, struct inode *dir, in ocfs2_delete_entry_dx() argument
1275 mlog(ML_ERROR, "Dir %llu: Bad dx_entry ptr idx %d, (%p, %p)\n", in ocfs2_delete_entry_dx()
1276 (unsigned long long)OCFS2_I(dir)->ip_blkno, index, in ocfs2_delete_entry_dx()
1286 trailer = ocfs2_trailer_from_bh(leaf_bh, dir->i_sb); in ocfs2_delete_entry_dx()
1301 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_delete_entry_dx()
1309 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), in ocfs2_delete_entry_dx()
1318 trace_ocfs2_delete_entry_dx((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_delete_entry_dx()
1321 ret = __ocfs2_delete_entry(handle, dir, lookup->dl_entry, in ocfs2_delete_entry_dx()
1328 max_rec_len = ocfs2_find_max_rec_len(dir->i_sb, leaf_bh); in ocfs2_delete_entry_dx()
1352 struct inode *dir, in ocfs2_delete_entry_id() argument
1361 ret = ocfs2_read_inode_block(dir, &di_bh); in ocfs2_delete_entry_id()
1370 ret = __ocfs2_delete_entry(handle, dir, de_del, bh, data->id_data, in ocfs2_delete_entry_id()
1371 i_size_read(dir)); in ocfs2_delete_entry_id()
1379 struct inode *dir, in ocfs2_delete_entry_el() argument
1383 return __ocfs2_delete_entry(handle, dir, de_del, bh, bh->b_data, in ocfs2_delete_entry_el()
1392 struct inode *dir, in ocfs2_delete_entry() argument
1395 if (ocfs2_dir_indexed(dir)) in ocfs2_delete_entry()
1396 return ocfs2_delete_entry_dx(handle, dir, res); in ocfs2_delete_entry()
1398 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) in ocfs2_delete_entry()
1399 return ocfs2_delete_entry_id(handle, dir, res->dl_entry, in ocfs2_delete_entry()
1402 return ocfs2_delete_entry_el(handle, dir, res->dl_entry, in ocfs2_delete_entry()
1460 static int __ocfs2_dx_dir_leaf_insert(struct inode *dir, handle_t *handle, in __ocfs2_dx_dir_leaf_insert() argument
1468 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh, in __ocfs2_dx_dir_leaf_insert()
1483 static void ocfs2_dx_inline_root_insert(struct inode *dir, handle_t *handle, in ocfs2_dx_inline_root_insert() argument
1491 static int ocfs2_dx_dir_insert(struct inode *dir, handle_t *handle, in ocfs2_dx_dir_insert() argument
1498 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_dx_dir_insert()
1507 ocfs2_dx_inline_root_insert(dir, handle, in ocfs2_dx_dir_insert()
1512 ret = __ocfs2_dx_dir_leaf_insert(dir, handle, &lookup->dl_hinfo, in ocfs2_dx_dir_insert()
1526 static void ocfs2_remove_block_from_free_list(struct inode *dir, in ocfs2_remove_block_from_free_list() argument
1534 trailer = ocfs2_trailer_from_bh(lookup->dl_leaf_bh, dir->i_sb); in ocfs2_remove_block_from_free_list()
1542 prev = ocfs2_trailer_from_bh(bh, dir->i_sb); in ocfs2_remove_block_from_free_list()
1557 static void ocfs2_recalc_free_list(struct inode *dir, handle_t *handle, in ocfs2_recalc_free_list() argument
1564 max_rec_len = ocfs2_find_max_rec_len(dir->i_sb, lookup->dl_leaf_bh); in ocfs2_recalc_free_list()
1571 trailer = ocfs2_trailer_from_bh(lookup->dl_leaf_bh, dir->i_sb); in ocfs2_recalc_free_list()
1575 ocfs2_remove_block_from_free_list(dir, handle, lookup); in ocfs2_recalc_free_list()
1580 * like orphan dir can call this instead.
1586 struct inode *dir, in __ocfs2_add_entry() argument
1596 struct super_block *sb = dir->i_sb; in __ocfs2_add_entry()
1605 if (ocfs2_dir_indexed(dir)) { in __ocfs2_add_entry()
1609 * An indexed dir may require that we update the free space in __ocfs2_add_entry()
1619 INODE_CACHE(dir), bh, in __ocfs2_add_entry()
1624 INODE_CACHE(dir), bh, in __ocfs2_add_entry()
1631 } else if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in __ocfs2_add_entry()
1633 size = i_size_read(dir); in __ocfs2_add_entry()
1647 if (!ocfs2_check_dir_entry(dir, de, insert_bh, data_start, in __ocfs2_add_entry()
1659 mlog_bug_on_msg(ocfs2_skip_dir_trailer(dir, de, offset, size), in __ocfs2_add_entry()
1660 "Hit dir trailer trying to insert %.*s " in __ocfs2_add_entry()
1665 offset, ocfs2_dir_trailer_blk_off(dir->i_sb)); in __ocfs2_add_entry()
1668 inode_set_mtime_to_ts(dir, in __ocfs2_add_entry()
1669 inode_set_ctime_current(dir)); in __ocfs2_add_entry()
1670 retval = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh); in __ocfs2_add_entry()
1678 INODE_CACHE(dir), in __ocfs2_add_entry()
1683 INODE_CACHE(dir), in __ocfs2_add_entry()
1687 if (!retval && ocfs2_dir_indexed(dir)) in __ocfs2_add_entry()
1688 retval = ocfs2_dx_dir_insert(dir, in __ocfs2_add_entry()
1718 if (ocfs2_dir_indexed(dir)) in __ocfs2_add_entry()
1719 ocfs2_recalc_free_list(dir, handle, lookup); in __ocfs2_add_entry()
1721 inode_inc_iversion(dir); in __ocfs2_add_entry()
1754 mlog(ML_ERROR, "Unable to read inode block for dir %llu\n", in ocfs2_dir_foreach_blk_id()
1763 /* If the dir block has changed since the last call to in ocfs2_dir_foreach_blk_id()
1854 /* If the dir block has changed since the last call to in ocfs2_dir_foreach_blk_el()
1970 * NOTE: this should always be called with parent dir i_rwsem taken.
1999 int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name, in ocfs2_lookup_ino_from_name() argument
2005 ret = ocfs2_find_files_on_disk(name, namelen, blkno, dir, &lookup); in ocfs2_lookup_ino_from_name()
2016 * Callers should have i_rwsem + a cluster lock on dir
2018 int ocfs2_check_dir_for_entry(struct inode *dir, in ocfs2_check_dir_for_entry() argument
2026 (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen, name); in ocfs2_check_dir_for_entry()
2028 if (ocfs2_find_entry(name, namelen, dir, &lookup) == 0) { in ocfs2_check_dir_for_entry()
2119 * Returns 1 if dir is empty, zero otherwise.
2145 mlog(ML_ERROR, "bad directory (dir #%llu) - no `.' or `..'\n", in ocfs2_empty_dir()
2293 handle_t *handle, struct inode *dir, in ocfs2_dx_dir_attach_index() argument
2308 ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb); in ocfs2_dx_dir_attach_index()
2318 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_attach_index()
2326 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_attach_index()
2328 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_dx_dir_attach_index()
2343 dx_root->dr_dir_blkno = cpu_to_le64(OCFS2_I(dir)->ip_blkno); in ocfs2_dx_dir_attach_index()
2360 ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh, in ocfs2_dx_dir_attach_index()
2369 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_attach_index()
2370 OCFS2_I(dir)->ip_dyn_features |= OCFS2_INDEXED_DIR_FL; in ocfs2_dx_dir_attach_index()
2371 di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features); in ocfs2_dx_dir_attach_index()
2372 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_attach_index()
2385 handle_t *handle, struct inode *dir, in ocfs2_dx_dir_format_cluster() argument
2401 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), bh); in ocfs2_dx_dir_format_cluster()
2403 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), bh, in ocfs2_dx_dir_format_cluster()
2420 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_format_cluster()
2433 * Allocates and formats a new cluster for use in an indexed dir
2437 static int __ocfs2_dx_dir_new_cluster(struct inode *dir, in __ocfs2_dx_dir_new_cluster() argument
2446 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in __ocfs2_dx_dir_new_cluster()
2465 ret = ocfs2_dx_dir_format_cluster(osb, handle, dir, dx_leaves, in __ocfs2_dx_dir_new_cluster()
2477 static int ocfs2_dx_dir_new_cluster(struct inode *dir, in ocfs2_dx_dir_new_cluster() argument
2488 ret = __ocfs2_dx_dir_new_cluster(dir, cpos, handle, data_ac, dx_leaves, in ocfs2_dx_dir_new_cluster()
2594 static int ocfs2_dx_dir_index_block(struct inode *dir, in ocfs2_dx_dir_index_block() argument
2609 limit = de_buf + dir->i_sb->s_blocksize; in ocfs2_dx_dir_index_block()
2618 ocfs2_dx_dir_name_hash(dir, de->name, namelen, &hinfo); in ocfs2_dx_dir_index_block()
2620 i = ocfs2_dx_dir_hash_idx(OCFS2_SB(dir->i_sb), &hinfo); in ocfs2_dx_dir_index_block()
2623 ret = __ocfs2_dx_dir_leaf_insert(dir, handle, &hinfo, in ocfs2_dx_dir_index_block()
2643 static void ocfs2_dx_dir_index_root_block(struct inode *dir, in ocfs2_dx_dir_index_root_block() argument
2656 limit = de_buf + dir->i_sb->s_blocksize; in ocfs2_dx_dir_index_root_block()
2664 ocfs2_dx_dir_name_hash(dir, de->name, de->name_len, &hinfo); in ocfs2_dx_dir_index_root_block()
2667 (unsigned long long)dir->i_ino, in ocfs2_dx_dir_index_root_block()
2686 static int ocfs2_new_dx_should_be_inline(struct inode *dir, in ocfs2_new_dx_should_be_inline() argument
2695 limit = de_buf + i_size_read(dir); in ocfs2_new_dx_should_be_inline()
2707 return dirent_count < ocfs2_dx_entries_per_root(dir->i_sb); in ocfs2_new_dx_should_be_inline()
2713 * expansion from an inline directory to one with extents. The first dir block
2719 * accounting. We do this here since we're already walking the entire dir
2722 * We add the dir trailer if this filesystem wants it.
2725 struct inode *dir) in ocfs2_expand_last_dirent() argument
2727 struct super_block *sb = dir->i_sb; in ocfs2_expand_last_dirent()
2735 if (ocfs2_new_dir_wants_trailer(dir)) in ocfs2_expand_last_dirent()
2774 static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, in ocfs2_expand_inline_dir() argument
2780 struct super_block *sb = dir->i_sb; in ocfs2_expand_inline_dir()
2785 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_expand_inline_dir()
2786 struct ocfs2_inode_info *oi = OCFS2_I(dir); in ocfs2_expand_inline_dir()
2798 ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(dir), di_bh); in ocfs2_expand_inline_dir()
2808 dx_inline = ocfs2_new_dx_should_be_inline(dir, di_bh); in ocfs2_expand_inline_dir()
2859 ret = dquot_alloc_space_nodirty(dir, in ocfs2_expand_inline_dir()
2871 ret = __ocfs2_dx_dir_new_cluster(dir, 0, handle, data_ac, in ocfs2_expand_inline_dir()
2878 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
2893 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
2900 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); in ocfs2_expand_inline_dir()
2908 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dirdata_bh); in ocfs2_expand_inline_dir()
2910 ret = ocfs2_journal_access_db(handle, INODE_CACHE(dir), dirdata_bh, in ocfs2_expand_inline_dir()
2917 memcpy(dirdata_bh->b_data, di->id2.i_data.id_data, i_size_read(dir)); in ocfs2_expand_inline_dir()
2918 memset(dirdata_bh->b_data + i_size_read(dir), 0, in ocfs2_expand_inline_dir()
2919 sb->s_blocksize - i_size_read(dir)); in ocfs2_expand_inline_dir()
2920 i = ocfs2_expand_last_dirent(dirdata_bh->b_data, i_size_read(dir), dir); in ocfs2_expand_inline_dir()
2921 if (ocfs2_new_dir_wants_trailer(dir)) { in ocfs2_expand_inline_dir()
2923 * Prepare the dir trailer up front. It will otherwise look in ocfs2_expand_inline_dir()
2925 * (unlikely), then all we'll have done is given first dir in ocfs2_expand_inline_dir()
2928 ocfs2_init_dir_trailer(dir, dirdata_bh, i); in ocfs2_expand_inline_dir()
2931 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_expand_inline_dir()
2943 ret = ocfs2_dx_dir_index_block(dir, handle, dx_leaves, in ocfs2_expand_inline_dir()
2960 ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh, in ocfs2_expand_inline_dir()
2972 ocfs2_dinode_new_extent_list(dir, di); in ocfs2_expand_inline_dir()
2974 i_size_write(dir, sb->s_blocksize); in ocfs2_expand_inline_dir()
2975 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); in ocfs2_expand_inline_dir()
2978 di->i_ctime = di->i_mtime = cpu_to_le64(inode_get_ctime_sec(dir)); in ocfs2_expand_inline_dir()
2979 di->i_ctime_nsec = di->i_mtime_nsec = cpu_to_le32(inode_get_ctime_nsec(dir)); in ocfs2_expand_inline_dir()
2980 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_expand_inline_dir()
2997 dir->i_blocks = ocfs2_inode_sector_count(dir); in ocfs2_expand_inline_dir()
3002 ret = ocfs2_dx_dir_attach_index(osb, handle, dir, di_bh, in ocfs2_expand_inline_dir()
3011 ocfs2_dx_dir_index_root_block(dir, dx_root_bh, in ocfs2_expand_inline_dir()
3015 INODE_CACHE(dir), in ocfs2_expand_inline_dir()
3035 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); in ocfs2_expand_inline_dir()
3043 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
3067 dquot_free_space_nodirty(dir, bytes_allocated); in ocfs2_expand_inline_dir()
3093 struct inode *dir, in ocfs2_do_extend_dir() argument
3103 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_do_extend_dir()
3104 extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)); in ocfs2_do_extend_dir()
3105 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_do_extend_dir()
3108 u32 offset = OCFS2_I(dir)->ip_clusters; in ocfs2_do_extend_dir()
3110 status = dquot_alloc_space_nodirty(dir, in ocfs2_do_extend_dir()
3116 status = ocfs2_add_inode_data(OCFS2_SB(sb), dir, &offset, in ocfs2_do_extend_dir()
3126 v_blkno = ocfs2_blocks_for_bytes(sb, i_size_read(dir)); in ocfs2_do_extend_dir()
3127 status = ocfs2_extent_map_get_blocks(dir, v_blkno, &p_blkno, NULL, NULL); in ocfs2_do_extend_dir()
3142 dquot_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1)); in ocfs2_do_extend_dir()
3157 struct inode *dir, in ocfs2_extend_dir() argument
3177 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in ocfs2_extend_dir()
3184 status = ocfs2_expand_inline_dir(dir, parent_fe_bh, in ocfs2_extend_dir()
3215 down_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3217 dir_i_size = i_size_read(dir); in ocfs2_extend_dir()
3222 down_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3224 dir_i_size = i_size_read(dir); in ocfs2_extend_dir()
3225 trace_ocfs2_extend_dir((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_extend_dir()
3228 /* dir->i_size is always block aligned. */ in ocfs2_extend_dir()
3229 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3230 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { in ocfs2_extend_dir()
3231 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3232 ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(dir), in ocfs2_extend_dir()
3258 data_ac->ac_resv = &OCFS2_I(dir)->ip_la_data_resv; in ocfs2_extend_dir()
3262 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3267 if (ocfs2_dir_indexed(dir)) in ocfs2_extend_dir()
3279 status = ocfs2_do_extend_dir(osb->sb, handle, dir, parent_fe_bh, in ocfs2_extend_dir()
3286 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), new_bh); in ocfs2_extend_dir()
3288 status = ocfs2_journal_access_db(handle, INODE_CACHE(dir), new_bh, in ocfs2_extend_dir()
3298 if (ocfs2_supports_dir_trailer(dir)) { in ocfs2_extend_dir()
3301 ocfs2_init_dir_trailer(dir, new_bh, le16_to_cpu(de->rec_len)); in ocfs2_extend_dir()
3303 if (ocfs2_dir_indexed(dir)) { in ocfs2_extend_dir()
3304 status = ocfs2_dx_dir_link_trailer(dir, handle, in ocfs2_extend_dir()
3314 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_extend_dir()
3317 dir_i_size += dir->i_sb->s_blocksize; in ocfs2_extend_dir()
3318 i_size_write(dir, dir_i_size); in ocfs2_extend_dir()
3319 dir->i_blocks = ocfs2_inode_sector_count(dir); in ocfs2_extend_dir()
3320 status = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh); in ocfs2_extend_dir()
3333 up_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3345 static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, in ocfs2_find_dir_space_id() argument
3351 struct super_block *sb = dir->i_sb; in ocfs2_find_dir_space_id()
3362 if (ocfs2_new_dir_wants_trailer(dir)) in ocfs2_find_dir_space_id()
3363 free_space = ocfs2_dir_trailer_blk_off(sb) - i_size_read(dir); in ocfs2_find_dir_space_id()
3365 free_space = dir->i_sb->s_blocksize - i_size_read(dir); in ocfs2_find_dir_space_id()
3369 limit = de_buf + i_size_read(dir); in ocfs2_find_dir_space_id()
3375 if (!ocfs2_check_dir_entry(dir, de, di_bh, first_de, in ocfs2_find_dir_space_id()
3376 i_size_read(dir), offset)) { in ocfs2_find_dir_space_id()
3418 static int ocfs2_find_dir_space_el(struct inode *dir, const char *name, in ocfs2_find_dir_space_el() argument
3425 struct super_block *sb = dir->i_sb; in ocfs2_find_dir_space_el()
3427 int blocksize = dir->i_sb->s_blocksize; in ocfs2_find_dir_space_el()
3429 status = ocfs2_read_dir_block(dir, 0, &bh, 0); in ocfs2_find_dir_space_el()
3441 if (i_size_read(dir) <= offset) { in ocfs2_find_dir_space_el()
3449 status = ocfs2_read_dir_block(dir, in ocfs2_find_dir_space_el()
3458 if (!ocfs2_check_dir_entry(dir, de, bh, bh->b_data, blocksize, in ocfs2_find_dir_space_el()
3468 if (ocfs2_skip_dir_trailer(dir, de, offset % blocksize, in ocfs2_find_dir_space_el()
3640 static void ocfs2_dx_dir_transfer_leaf(struct inode *dir, u32 split_hash, in ocfs2_dx_dir_transfer_leaf() argument
3662 memcpy(tmp_dx_leaf, orig_dx_leaf, dir->i_sb->s_blocksize); in ocfs2_dx_dir_transfer_leaf()
3676 memcpy(orig_dx_leaf, tmp_dx_leaf, dir->i_sb->s_blocksize); in ocfs2_dx_dir_transfer_leaf()
3697 static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir, in ocfs2_dx_dir_rebalance() argument
3716 trace_ocfs2_dx_dir_rebalance((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_rebalance()
3720 ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_rebalance()
3732 mlog(ML_ERROR, "DX Dir: %llu, Asked to rebalance empty leaf: " in ocfs2_dx_dir_rebalance()
3733 "%llu, %d\n", (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_rebalance()
3753 ret = ocfs2_lock_allocators(dir, &et, 1, 0, &data_ac, &meta_ac); in ocfs2_dx_dir_rebalance()
3769 ret = dquot_alloc_space_nodirty(dir, in ocfs2_dx_dir_rebalance()
3770 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_dx_dir_rebalance()
3775 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh, in ocfs2_dx_dir_rebalance()
3825 orig_leaves_start = ocfs2_block_to_cluster_start(dir->i_sb, leaf_blkno); in ocfs2_dx_dir_rebalance()
3826 ret = ocfs2_read_dx_leaves(dir, orig_leaves_start, num_dx_leaves, in ocfs2_dx_dir_rebalance()
3834 ret = ocfs2_dx_dir_new_cluster(dir, &et, cpos, handle, in ocfs2_dx_dir_rebalance()
3843 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), in ocfs2_dx_dir_rebalance()
3851 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), in ocfs2_dx_dir_rebalance()
3860 ocfs2_dx_dir_transfer_leaf(dir, split_hash, handle, tmp_dx_leaf, in ocfs2_dx_dir_rebalance()
3865 dquot_free_space_nodirty(dir, in ocfs2_dx_dir_rebalance()
3866 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_dx_dir_rebalance()
3868 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_dx_dir_rebalance()
3892 static int ocfs2_find_dir_space_dx(struct ocfs2_super *osb, struct inode *dir, in ocfs2_find_dir_space_dx() argument
3908 ret = ocfs2_dx_dir_lookup(dir, &dx_root->dr_list, &lookup->dl_hinfo, in ocfs2_find_dir_space_dx()
3915 ret = ocfs2_read_dx_leaf(dir, blkno, &dx_leaf_bh); in ocfs2_find_dir_space_dx()
3937 ret = ocfs2_dx_dir_rebalance(osb, dir, dx_root_bh, dx_leaf_bh, in ocfs2_find_dir_space_dx()
3965 static int ocfs2_search_dx_free_list(struct inode *dir, in ocfs2_search_dx_free_list() argument
3985 ret = ocfs2_read_dir_block_direct(dir, next_block, &leaf_bh); in ocfs2_search_dx_free_list()
3991 db = ocfs2_trailer_from_bh(leaf_bh, dir->i_sb); in ocfs2_search_dx_free_list()
4013 static int ocfs2_expand_inline_dx_root(struct inode *dir, in ocfs2_expand_inline_dx_root() argument
4021 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_expand_inline_dx_root()
4048 ret = dquot_alloc_space_nodirty(dir, in ocfs2_expand_inline_dx_root()
4059 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_expand_inline_dx_root()
4066 ret = __ocfs2_dx_dir_new_cluster(dir, 0, handle, data_ac, dx_leaves, in ocfs2_expand_inline_dx_root()
4101 ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh); in ocfs2_expand_inline_dx_root()
4107 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_expand_inline_dx_root()
4112 dquot_free_space_nodirty(dir, in ocfs2_expand_inline_dx_root()
4113 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_expand_inline_dx_root()
4144 static int ocfs2_prepare_dx_dir_for_insert(struct inode *dir, in ocfs2_prepare_dx_dir_for_insert() argument
4151 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_prepare_dx_dir_for_insert()
4157 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh); in ocfs2_prepare_dx_dir_for_insert()
4181 ret = ocfs2_expand_inline_dx_root(dir, dx_root_bh); in ocfs2_prepare_dx_dir_for_insert()
4194 ret = ocfs2_find_dir_space_dx(osb, dir, di_bh, dx_root_bh, name, in ocfs2_prepare_dx_dir_for_insert()
4208 ret = ocfs2_search_dx_free_list(dir, dx_root_bh, namelen, lookup); in ocfs2_prepare_dx_dir_for_insert()
4219 ret = ocfs2_extend_dir(osb, dir, di_bh, 1, lookup, &leaf_bh); in ocfs2_prepare_dx_dir_for_insert()
4242 * happens here. Success returns zero, and enough context in the dir
4247 struct inode *dir, in ocfs2_prepare_dir_for_insert() argument
4258 (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen); in ocfs2_prepare_dir_for_insert()
4278 ocfs2_dx_dir_name_hash(dir, name, namelen, &lookup->dl_hinfo); in ocfs2_prepare_dir_for_insert()
4280 if (ocfs2_dir_indexed(dir)) { in ocfs2_prepare_dir_for_insert()
4281 ret = ocfs2_prepare_dx_dir_for_insert(dir, parent_fe_bh, in ocfs2_prepare_dir_for_insert()
4288 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in ocfs2_prepare_dir_for_insert()
4289 ret = ocfs2_find_dir_space_id(dir, parent_fe_bh, name, in ocfs2_prepare_dir_for_insert()
4292 ret = ocfs2_find_dir_space_el(dir, name, namelen, &bh); in ocfs2_prepare_dir_for_insert()
4305 ret = ocfs2_extend_dir(osb, dir, parent_fe_bh, blocks_wanted, in ocfs2_prepare_dir_for_insert()
4323 static int ocfs2_dx_dir_remove_index(struct inode *dir, in ocfs2_dx_dir_remove_index() argument
4328 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_remove_index()
4363 ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh, in ocfs2_dx_dir_remove_index()
4370 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_remove_index()
4371 OCFS2_I(dir)->ip_dyn_features &= ~OCFS2_INDEXED_DIR_FL; in ocfs2_dx_dir_remove_index()
4372 di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features); in ocfs2_dx_dir_remove_index()
4373 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_remove_index()
4375 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_dx_dir_remove_index()
4404 int ocfs2_dx_dir_truncate(struct inode *dir, struct buffer_head *di_bh) in ocfs2_dx_dir_truncate() argument
4410 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_truncate()
4419 if (!ocfs2_dir_indexed(dir)) in ocfs2_dx_dir_truncate()
4422 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh); in ocfs2_dx_dir_truncate()
4432 ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_truncate()
4436 ret = ocfs2_dx_dir_lookup_rec(dir, &dx_root->dr_list, in ocfs2_dx_dir_truncate()
4443 p_cpos = ocfs2_blocks_to_clusters(dir->i_sb, blkno); in ocfs2_dx_dir_truncate()
4445 ret = ocfs2_remove_btree_range(dir, &et, cpos, p_cpos, clen, 0, in ocfs2_dx_dir_truncate()
4459 ret = ocfs2_dx_dir_remove_index(dir, di_bh, dx_root_bh); in ocfs2_dx_dir_truncate()
4465 ocfs2_remove_from_cache(INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_truncate()