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()
1602 if (ocfs2_dir_indexed(dir)) { in __ocfs2_add_entry()
1606 * An indexed dir may require that we update the free space in __ocfs2_add_entry()
1616 INODE_CACHE(dir), bh, in __ocfs2_add_entry()
1621 INODE_CACHE(dir), bh, in __ocfs2_add_entry()
1628 } else if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in __ocfs2_add_entry()
1630 size = i_size_read(dir); in __ocfs2_add_entry()
1644 if (!ocfs2_check_dir_entry(dir, de, insert_bh, data_start, in __ocfs2_add_entry()
1656 mlog_bug_on_msg(ocfs2_skip_dir_trailer(dir, de, offset, size), in __ocfs2_add_entry()
1657 "Hit dir trailer trying to insert %.*s " in __ocfs2_add_entry()
1662 offset, ocfs2_dir_trailer_blk_off(dir->i_sb)); in __ocfs2_add_entry()
1665 inode_set_mtime_to_ts(dir, in __ocfs2_add_entry()
1666 inode_set_ctime_current(dir)); in __ocfs2_add_entry()
1667 retval = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh); in __ocfs2_add_entry()
1675 INODE_CACHE(dir), in __ocfs2_add_entry()
1680 INODE_CACHE(dir), in __ocfs2_add_entry()
1684 if (!retval && ocfs2_dir_indexed(dir)) in __ocfs2_add_entry()
1685 retval = ocfs2_dx_dir_insert(dir, in __ocfs2_add_entry()
1715 if (ocfs2_dir_indexed(dir)) in __ocfs2_add_entry()
1716 ocfs2_recalc_free_list(dir, handle, lookup); in __ocfs2_add_entry()
1718 inode_inc_iversion(dir); in __ocfs2_add_entry()
1751 mlog(ML_ERROR, "Unable to read inode block for dir %llu\n", in ocfs2_dir_foreach_blk_id()
1760 /* If the dir block has changed since the last call to in ocfs2_dir_foreach_blk_id()
1851 /* If the dir block has changed since the last call to in ocfs2_dir_foreach_blk_el()
1968 * NOTE: this should always be called with parent dir i_rwsem taken.
1997 int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name, in ocfs2_lookup_ino_from_name() argument
2003 ret = ocfs2_find_files_on_disk(name, namelen, blkno, dir, &lookup); in ocfs2_lookup_ino_from_name()
2014 * Callers should have i_rwsem + a cluster lock on dir
2016 int ocfs2_check_dir_for_entry(struct inode *dir, in ocfs2_check_dir_for_entry() argument
2024 (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen, name); in ocfs2_check_dir_for_entry()
2026 if (ocfs2_find_entry(name, namelen, dir, &lookup) == 0) { in ocfs2_check_dir_for_entry()
2117 * Returns 1 if dir is empty, zero otherwise.
2143 mlog(ML_ERROR, "bad directory (dir #%llu) - no `.' or `..'\n", in ocfs2_empty_dir()
2291 handle_t *handle, struct inode *dir, in ocfs2_dx_dir_attach_index() argument
2306 ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb); in ocfs2_dx_dir_attach_index()
2316 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_attach_index()
2324 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_attach_index()
2326 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_dx_dir_attach_index()
2341 dx_root->dr_dir_blkno = cpu_to_le64(OCFS2_I(dir)->ip_blkno); in ocfs2_dx_dir_attach_index()
2358 ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh, in ocfs2_dx_dir_attach_index()
2367 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_attach_index()
2368 OCFS2_I(dir)->ip_dyn_features |= OCFS2_INDEXED_DIR_FL; in ocfs2_dx_dir_attach_index()
2369 di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features); in ocfs2_dx_dir_attach_index()
2370 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_attach_index()
2383 handle_t *handle, struct inode *dir, in ocfs2_dx_dir_format_cluster() argument
2399 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), bh); in ocfs2_dx_dir_format_cluster()
2401 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), bh, in ocfs2_dx_dir_format_cluster()
2418 (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_format_cluster()
2431 * Allocates and formats a new cluster for use in an indexed dir
2435 static int __ocfs2_dx_dir_new_cluster(struct inode *dir, in __ocfs2_dx_dir_new_cluster() argument
2444 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in __ocfs2_dx_dir_new_cluster()
2463 ret = ocfs2_dx_dir_format_cluster(osb, handle, dir, dx_leaves, in __ocfs2_dx_dir_new_cluster()
2475 static int ocfs2_dx_dir_new_cluster(struct inode *dir, in ocfs2_dx_dir_new_cluster() argument
2486 ret = __ocfs2_dx_dir_new_cluster(dir, cpos, handle, data_ac, dx_leaves, in ocfs2_dx_dir_new_cluster()
2592 static int ocfs2_dx_dir_index_block(struct inode *dir, in ocfs2_dx_dir_index_block() argument
2607 limit = de_buf + dir->i_sb->s_blocksize; in ocfs2_dx_dir_index_block()
2616 ocfs2_dx_dir_name_hash(dir, de->name, namelen, &hinfo); in ocfs2_dx_dir_index_block()
2618 i = ocfs2_dx_dir_hash_idx(OCFS2_SB(dir->i_sb), &hinfo); in ocfs2_dx_dir_index_block()
2621 ret = __ocfs2_dx_dir_leaf_insert(dir, handle, &hinfo, in ocfs2_dx_dir_index_block()
2641 static void ocfs2_dx_dir_index_root_block(struct inode *dir, in ocfs2_dx_dir_index_root_block() argument
2654 limit = de_buf + dir->i_sb->s_blocksize; in ocfs2_dx_dir_index_root_block()
2662 ocfs2_dx_dir_name_hash(dir, de->name, de->name_len, &hinfo); in ocfs2_dx_dir_index_root_block()
2665 (unsigned long long)dir->i_ino, in ocfs2_dx_dir_index_root_block()
2684 static int ocfs2_new_dx_should_be_inline(struct inode *dir, in ocfs2_new_dx_should_be_inline() argument
2693 limit = de_buf + i_size_read(dir); in ocfs2_new_dx_should_be_inline()
2705 return dirent_count < ocfs2_dx_entries_per_root(dir->i_sb); in ocfs2_new_dx_should_be_inline()
2711 * expansion from an inline directory to one with extents. The first dir block
2717 * accounting. We do this here since we're already walking the entire dir
2720 * We add the dir trailer if this filesystem wants it.
2723 struct inode *dir) in ocfs2_expand_last_dirent() argument
2725 struct super_block *sb = dir->i_sb; in ocfs2_expand_last_dirent()
2733 if (ocfs2_new_dir_wants_trailer(dir)) in ocfs2_expand_last_dirent()
2772 static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, in ocfs2_expand_inline_dir() argument
2778 struct super_block *sb = dir->i_sb; in ocfs2_expand_inline_dir()
2783 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_expand_inline_dir()
2784 struct ocfs2_inode_info *oi = OCFS2_I(dir); in ocfs2_expand_inline_dir()
2796 ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(dir), di_bh); in ocfs2_expand_inline_dir()
2806 dx_inline = ocfs2_new_dx_should_be_inline(dir, di_bh); in ocfs2_expand_inline_dir()
2857 ret = dquot_alloc_space_nodirty(dir, in ocfs2_expand_inline_dir()
2869 ret = __ocfs2_dx_dir_new_cluster(dir, 0, handle, data_ac, in ocfs2_expand_inline_dir()
2876 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
2891 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
2898 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); in ocfs2_expand_inline_dir()
2906 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dirdata_bh); in ocfs2_expand_inline_dir()
2908 ret = ocfs2_journal_access_db(handle, INODE_CACHE(dir), dirdata_bh, in ocfs2_expand_inline_dir()
2915 memcpy(dirdata_bh->b_data, di->id2.i_data.id_data, i_size_read(dir)); in ocfs2_expand_inline_dir()
2916 memset(dirdata_bh->b_data + i_size_read(dir), 0, in ocfs2_expand_inline_dir()
2917 sb->s_blocksize - i_size_read(dir)); in ocfs2_expand_inline_dir()
2918 i = ocfs2_expand_last_dirent(dirdata_bh->b_data, i_size_read(dir), dir); in ocfs2_expand_inline_dir()
2919 if (ocfs2_new_dir_wants_trailer(dir)) { in ocfs2_expand_inline_dir()
2921 * Prepare the dir trailer up front. It will otherwise look in ocfs2_expand_inline_dir()
2923 * (unlikely), then all we'll have done is given first dir in ocfs2_expand_inline_dir()
2926 ocfs2_init_dir_trailer(dir, dirdata_bh, i); in ocfs2_expand_inline_dir()
2929 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_expand_inline_dir()
2941 ret = ocfs2_dx_dir_index_block(dir, handle, dx_leaves, in ocfs2_expand_inline_dir()
2958 ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh, in ocfs2_expand_inline_dir()
2970 ocfs2_dinode_new_extent_list(dir, di); in ocfs2_expand_inline_dir()
2972 i_size_write(dir, sb->s_blocksize); in ocfs2_expand_inline_dir()
2973 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); in ocfs2_expand_inline_dir()
2976 di->i_ctime = di->i_mtime = cpu_to_le64(inode_get_ctime_sec(dir)); in ocfs2_expand_inline_dir()
2977 di->i_ctime_nsec = di->i_mtime_nsec = cpu_to_le32(inode_get_ctime_nsec(dir)); in ocfs2_expand_inline_dir()
2978 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_expand_inline_dir()
2995 dir->i_blocks = ocfs2_inode_sector_count(dir); in ocfs2_expand_inline_dir()
3000 ret = ocfs2_dx_dir_attach_index(osb, handle, dir, di_bh, in ocfs2_expand_inline_dir()
3009 ocfs2_dx_dir_index_root_block(dir, dx_root_bh, in ocfs2_expand_inline_dir()
3013 INODE_CACHE(dir), in ocfs2_expand_inline_dir()
3033 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); in ocfs2_expand_inline_dir()
3041 bytes_allocated += ocfs2_clusters_to_bytes(dir->i_sb, 1); in ocfs2_expand_inline_dir()
3065 dquot_free_space_nodirty(dir, bytes_allocated); in ocfs2_expand_inline_dir()
3091 struct inode *dir, in ocfs2_do_extend_dir() argument
3101 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_do_extend_dir()
3102 extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)); in ocfs2_do_extend_dir()
3103 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_do_extend_dir()
3106 u32 offset = OCFS2_I(dir)->ip_clusters; in ocfs2_do_extend_dir()
3108 status = dquot_alloc_space_nodirty(dir, in ocfs2_do_extend_dir()
3114 status = ocfs2_add_inode_data(OCFS2_SB(sb), dir, &offset, in ocfs2_do_extend_dir()
3124 v_blkno = ocfs2_blocks_for_bytes(sb, i_size_read(dir)); in ocfs2_do_extend_dir()
3125 status = ocfs2_extent_map_get_blocks(dir, v_blkno, &p_blkno, NULL, NULL); in ocfs2_do_extend_dir()
3140 dquot_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1)); in ocfs2_do_extend_dir()
3155 struct inode *dir, in ocfs2_extend_dir() argument
3175 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in ocfs2_extend_dir()
3182 status = ocfs2_expand_inline_dir(dir, parent_fe_bh, in ocfs2_extend_dir()
3213 down_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3215 dir_i_size = i_size_read(dir); in ocfs2_extend_dir()
3220 down_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3222 dir_i_size = i_size_read(dir); in ocfs2_extend_dir()
3223 trace_ocfs2_extend_dir((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_extend_dir()
3226 /* dir->i_size is always block aligned. */ in ocfs2_extend_dir()
3227 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3228 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { in ocfs2_extend_dir()
3229 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3230 ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(dir), in ocfs2_extend_dir()
3256 data_ac->ac_resv = &OCFS2_I(dir)->ip_la_data_resv; in ocfs2_extend_dir()
3260 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_extend_dir()
3265 if (ocfs2_dir_indexed(dir)) in ocfs2_extend_dir()
3277 status = ocfs2_do_extend_dir(osb->sb, handle, dir, parent_fe_bh, in ocfs2_extend_dir()
3284 ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), new_bh); in ocfs2_extend_dir()
3286 status = ocfs2_journal_access_db(handle, INODE_CACHE(dir), new_bh, in ocfs2_extend_dir()
3296 if (ocfs2_supports_dir_trailer(dir)) { in ocfs2_extend_dir()
3299 ocfs2_init_dir_trailer(dir, new_bh, le16_to_cpu(de->rec_len)); in ocfs2_extend_dir()
3301 if (ocfs2_dir_indexed(dir)) { in ocfs2_extend_dir()
3302 status = ocfs2_dx_dir_link_trailer(dir, handle, in ocfs2_extend_dir()
3312 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_extend_dir()
3315 dir_i_size += dir->i_sb->s_blocksize; in ocfs2_extend_dir()
3316 i_size_write(dir, dir_i_size); in ocfs2_extend_dir()
3317 dir->i_blocks = ocfs2_inode_sector_count(dir); in ocfs2_extend_dir()
3318 status = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh); in ocfs2_extend_dir()
3331 up_write(&OCFS2_I(dir)->ip_alloc_sem); in ocfs2_extend_dir()
3343 static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh, in ocfs2_find_dir_space_id() argument
3349 struct super_block *sb = dir->i_sb; in ocfs2_find_dir_space_id()
3360 if (ocfs2_new_dir_wants_trailer(dir)) in ocfs2_find_dir_space_id()
3361 free_space = ocfs2_dir_trailer_blk_off(sb) - i_size_read(dir); in ocfs2_find_dir_space_id()
3363 free_space = dir->i_sb->s_blocksize - i_size_read(dir); in ocfs2_find_dir_space_id()
3367 limit = de_buf + i_size_read(dir); in ocfs2_find_dir_space_id()
3373 if (!ocfs2_check_dir_entry(dir, de, di_bh, first_de, in ocfs2_find_dir_space_id()
3374 i_size_read(dir), offset)) { in ocfs2_find_dir_space_id()
3416 static int ocfs2_find_dir_space_el(struct inode *dir, const char *name, in ocfs2_find_dir_space_el() argument
3423 struct super_block *sb = dir->i_sb; in ocfs2_find_dir_space_el()
3425 int blocksize = dir->i_sb->s_blocksize; in ocfs2_find_dir_space_el()
3427 status = ocfs2_read_dir_block(dir, 0, &bh, 0); in ocfs2_find_dir_space_el()
3439 if (i_size_read(dir) <= offset) { in ocfs2_find_dir_space_el()
3447 status = ocfs2_read_dir_block(dir, in ocfs2_find_dir_space_el()
3456 if (!ocfs2_check_dir_entry(dir, de, bh, bh->b_data, blocksize, in ocfs2_find_dir_space_el()
3466 if (ocfs2_skip_dir_trailer(dir, de, offset % blocksize, in ocfs2_find_dir_space_el()
3628 static void ocfs2_dx_dir_transfer_leaf(struct inode *dir, u32 split_hash, in ocfs2_dx_dir_transfer_leaf() argument
3650 memcpy(tmp_dx_leaf, orig_dx_leaf, dir->i_sb->s_blocksize); in ocfs2_dx_dir_transfer_leaf()
3664 memcpy(orig_dx_leaf, tmp_dx_leaf, dir->i_sb->s_blocksize); in ocfs2_dx_dir_transfer_leaf()
3685 static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir, in ocfs2_dx_dir_rebalance() argument
3704 trace_ocfs2_dx_dir_rebalance((unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_rebalance()
3708 ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_rebalance()
3720 mlog(ML_ERROR, "DX Dir: %llu, Asked to rebalance empty leaf: " in ocfs2_dx_dir_rebalance()
3721 "%llu, %d\n", (unsigned long long)OCFS2_I(dir)->ip_blkno, in ocfs2_dx_dir_rebalance()
3741 ret = ocfs2_lock_allocators(dir, &et, 1, 0, &data_ac, &meta_ac); in ocfs2_dx_dir_rebalance()
3757 ret = dquot_alloc_space_nodirty(dir, in ocfs2_dx_dir_rebalance()
3758 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_dx_dir_rebalance()
3763 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh, in ocfs2_dx_dir_rebalance()
3813 orig_leaves_start = ocfs2_block_to_cluster_start(dir->i_sb, leaf_blkno); in ocfs2_dx_dir_rebalance()
3814 ret = ocfs2_read_dx_leaves(dir, orig_leaves_start, num_dx_leaves, in ocfs2_dx_dir_rebalance()
3822 ret = ocfs2_dx_dir_new_cluster(dir, &et, cpos, handle, in ocfs2_dx_dir_rebalance()
3831 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), in ocfs2_dx_dir_rebalance()
3839 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), in ocfs2_dx_dir_rebalance()
3848 ocfs2_dx_dir_transfer_leaf(dir, split_hash, handle, tmp_dx_leaf, in ocfs2_dx_dir_rebalance()
3853 dquot_free_space_nodirty(dir, in ocfs2_dx_dir_rebalance()
3854 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_dx_dir_rebalance()
3856 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_dx_dir_rebalance()
3880 static int ocfs2_find_dir_space_dx(struct ocfs2_super *osb, struct inode *dir, in ocfs2_find_dir_space_dx() argument
3896 ret = ocfs2_dx_dir_lookup(dir, &dx_root->dr_list, &lookup->dl_hinfo, in ocfs2_find_dir_space_dx()
3903 ret = ocfs2_read_dx_leaf(dir, blkno, &dx_leaf_bh); in ocfs2_find_dir_space_dx()
3925 ret = ocfs2_dx_dir_rebalance(osb, dir, dx_root_bh, dx_leaf_bh, in ocfs2_find_dir_space_dx()
3953 static int ocfs2_search_dx_free_list(struct inode *dir, in ocfs2_search_dx_free_list() argument
3973 ret = ocfs2_read_dir_block_direct(dir, next_block, &leaf_bh); in ocfs2_search_dx_free_list()
3979 db = ocfs2_trailer_from_bh(leaf_bh, dir->i_sb); in ocfs2_search_dx_free_list()
4001 static int ocfs2_expand_inline_dx_root(struct inode *dir, in ocfs2_expand_inline_dx_root() argument
4009 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_expand_inline_dx_root()
4036 ret = dquot_alloc_space_nodirty(dir, in ocfs2_expand_inline_dx_root()
4047 ret = ocfs2_journal_access_dr(handle, INODE_CACHE(dir), dx_root_bh, in ocfs2_expand_inline_dx_root()
4054 ret = __ocfs2_dx_dir_new_cluster(dir, 0, handle, data_ac, dx_leaves, in ocfs2_expand_inline_dx_root()
4089 ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh); in ocfs2_expand_inline_dx_root()
4095 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_expand_inline_dx_root()
4100 dquot_free_space_nodirty(dir, in ocfs2_expand_inline_dx_root()
4101 ocfs2_clusters_to_bytes(dir->i_sb, 1)); in ocfs2_expand_inline_dx_root()
4132 static int ocfs2_prepare_dx_dir_for_insert(struct inode *dir, in ocfs2_prepare_dx_dir_for_insert() argument
4139 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_prepare_dx_dir_for_insert()
4145 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh); in ocfs2_prepare_dx_dir_for_insert()
4169 ret = ocfs2_expand_inline_dx_root(dir, dx_root_bh); in ocfs2_prepare_dx_dir_for_insert()
4182 ret = ocfs2_find_dir_space_dx(osb, dir, di_bh, dx_root_bh, name, in ocfs2_prepare_dx_dir_for_insert()
4196 ret = ocfs2_search_dx_free_list(dir, dx_root_bh, namelen, lookup); in ocfs2_prepare_dx_dir_for_insert()
4207 ret = ocfs2_extend_dir(osb, dir, di_bh, 1, lookup, &leaf_bh); in ocfs2_prepare_dx_dir_for_insert()
4230 * happens here. Success returns zero, and enough context in the dir
4235 struct inode *dir, in ocfs2_prepare_dir_for_insert() argument
4246 (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen); in ocfs2_prepare_dir_for_insert()
4260 ocfs2_dx_dir_name_hash(dir, name, namelen, &lookup->dl_hinfo); in ocfs2_prepare_dir_for_insert()
4262 if (ocfs2_dir_indexed(dir)) { in ocfs2_prepare_dir_for_insert()
4263 ret = ocfs2_prepare_dx_dir_for_insert(dir, parent_fe_bh, in ocfs2_prepare_dir_for_insert()
4270 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { in ocfs2_prepare_dir_for_insert()
4271 ret = ocfs2_find_dir_space_id(dir, parent_fe_bh, name, in ocfs2_prepare_dir_for_insert()
4274 ret = ocfs2_find_dir_space_el(dir, name, namelen, &bh); in ocfs2_prepare_dir_for_insert()
4287 ret = ocfs2_extend_dir(osb, dir, parent_fe_bh, blocks_wanted, in ocfs2_prepare_dir_for_insert()
4305 static int ocfs2_dx_dir_remove_index(struct inode *dir, in ocfs2_dx_dir_remove_index() argument
4310 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_remove_index()
4345 ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh, in ocfs2_dx_dir_remove_index()
4352 spin_lock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_remove_index()
4353 OCFS2_I(dir)->ip_dyn_features &= ~OCFS2_INDEXED_DIR_FL; in ocfs2_dx_dir_remove_index()
4354 di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features); in ocfs2_dx_dir_remove_index()
4355 spin_unlock(&OCFS2_I(dir)->ip_lock); in ocfs2_dx_dir_remove_index()
4357 ocfs2_update_inode_fsync_trans(handle, dir, 1); in ocfs2_dx_dir_remove_index()
4386 int ocfs2_dx_dir_truncate(struct inode *dir, struct buffer_head *di_bh) in ocfs2_dx_dir_truncate() argument
4392 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); in ocfs2_dx_dir_truncate()
4401 if (!ocfs2_dir_indexed(dir)) in ocfs2_dx_dir_truncate()
4404 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh); in ocfs2_dx_dir_truncate()
4414 ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_truncate()
4418 ret = ocfs2_dx_dir_lookup_rec(dir, &dx_root->dr_list, in ocfs2_dx_dir_truncate()
4425 p_cpos = ocfs2_blocks_to_clusters(dir->i_sb, blkno); in ocfs2_dx_dir_truncate()
4427 ret = ocfs2_remove_btree_range(dir, &et, cpos, p_cpos, clen, 0, in ocfs2_dx_dir_truncate()
4441 ret = ocfs2_dx_dir_remove_index(dir, di_bh, dx_root_bh); in ocfs2_dx_dir_truncate()
4447 ocfs2_remove_from_cache(INODE_CACHE(dir), dx_root_bh); in ocfs2_dx_dir_truncate()