40 #include <linux/types.h>
41 #include <linux/slab.h>
67 #define NAMEI_RA_CHUNKS 2
68 #define NAMEI_RA_BLOCKS 4
69 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
70 #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
72 static unsigned char ocfs2_filetype_table[] = {
79 struct buffer_head *parent_fe_bh,
82 struct buffer_head **new_bh);
83 static int ocfs2_dir_indexed(
struct inode *
inode);
89 static int ocfs2_supports_dir_trailer(
struct inode *dir)
96 return ocfs2_meta_ecc(osb) || ocfs2_dir_indexed(dir);
107 static int ocfs2_new_dir_wants_trailer(
struct inode *dir)
111 return ocfs2_meta_ecc(osb) ||
112 ocfs2_supports_indexed_dirs(osb);
115 static inline unsigned int ocfs2_dir_trailer_blk_off(
struct super_block *
sb)
120 #define ocfs2_trailer_from_bh(_bh, _sb) ((struct ocfs2_dir_block_trailer *) ((_bh)->b_data + ocfs2_dir_trailer_blk_off((_sb))))
137 static int ocfs2_skip_dir_trailer(
struct inode *dir,
144 if (!ocfs2_supports_dir_trailer(dir))
153 static void ocfs2_init_dir_trailer(
struct inode *
inode,
171 static int ocfs2_dx_dir_link_trailer(
struct inode *dir, handle_t *
handle,
172 struct buffer_head *dx_root_bh,
173 struct buffer_head *dirdata_bh)
210 static int ocfs2_dir_indexed(
struct inode *inode)
225 #define DELTA 0x9E3779B9
230 __u32 b0 = buf[0], b1 = buf[1];
231 __u32 a = in[0],
b = in[1],
c = in[2],
d = in[3];
236 b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b);
237 b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d);
244 static void str2hashbuf(
const char *
msg,
int len,
__u32 *
buf,
int num)
255 for (i = 0; i < len; i++) {
258 val = msg[
i] + (val << 8);
271 static void ocfs2_dx_dir_name_hash(
struct inode *dir,
const char *
name,
int len,
282 if ((len == 1 && !
strncmp(
".", name, 1)) ||
283 (len == 2 && !
strncmp(
"..", name, 2))) {
288 #ifdef OCFS2_DEBUG_DX_DIRS
294 buf[0] = buf[1] = len;
302 str2hashbuf(p, len, in, 4);
303 TEA_transform(buf, in);
317 static int ocfs2_check_dir_entry(
struct inode * dir,
319 struct buffer_head * bh,
320 unsigned long offset)
322 const char *error_msg =
NULL;
326 error_msg =
"rec_len is smaller than minimal";
328 error_msg =
"rec_len % 4 != 0";
330 error_msg =
"rec_len is too small for name_len";
332 ((
char *) de - bh->b_data) + rlen > dir->
i_sb->s_blocksize))
333 error_msg =
"directory entry across blocks";
337 "offset=%lu, inode=%llu, rec_len=%d, name_len=%d\n",
338 (
unsigned long long)OCFS2_I(dir)->ip_blkno, error_msg,
342 return error_msg ==
NULL ? 1 : 0;
345 static inline int ocfs2_match(
int len,
346 const char *
const name,
359 static inline int ocfs2_search_dirblock(
struct buffer_head *bh,
362 unsigned long offset,
368 char *dlimit, *de_buf;
373 dlimit = de_buf +
bytes;
375 while (de_buf < dlimit) {
381 if (de_buf + namelen <= dlimit &&
382 ocfs2_match(namelen, name, de)) {
384 if (!ocfs2_check_dir_entry(dir, de, bh, offset)) {
405 trace_ocfs2_search_dirblock(ret);
409 static struct buffer_head *ocfs2_find_entry_id(
const char *name,
415 struct buffer_head *di_bh =
NULL;
428 found = ocfs2_search_dirblock(di_bh, dir, name, namelen, 0,
429 data->
id_data, i_size_read(dir), res_dir);
439 struct buffer_head *bh)
450 trace_ocfs2_validate_dir_block((
unsigned long long)bh->b_blocknr);
452 BUG_ON(!buffer_uptodate(bh));
466 (
unsigned long long)bh->b_blocknr);
477 static int ocfs2_check_dir_trailer(
struct inode *dir,
struct buffer_head *bh)
486 "Invalid dirblock #%llu: "
487 "signature = %.*s\n",
488 (
unsigned long long)bh->b_blocknr, 7,
495 "Directory block #%llu has an invalid "
497 (
unsigned long long)bh->b_blocknr,
502 OCFS2_I(dir)->ip_blkno) {
505 "Directory block #%llu on dinode "
506 "#%llu has an invalid parent_dinode "
508 (
unsigned long long)bh->b_blocknr,
509 (
unsigned long long)OCFS2_I(dir)->ip_blkno,
523 static int ocfs2_read_dir_block(
struct inode *inode,
u64 v_block,
524 struct buffer_head **bh,
int flags)
527 struct buffer_head *
tmp = *bh;
530 ocfs2_validate_dir_block);
537 ocfs2_supports_dir_trailer(inode)) {
538 rc = ocfs2_check_dir_trailer(inode, tmp);
552 return rc ? -
EIO : 0;
560 static int ocfs2_read_dir_block_direct(
struct inode *dir,
u64 phys,
561 struct buffer_head **bh)
564 struct buffer_head *tmp = *bh;
566 ret = ocfs2_read_block(INODE_CACHE(dir), phys, &tmp,
567 ocfs2_validate_dir_block);
573 if (ocfs2_supports_dir_trailer(dir)) {
574 ret = ocfs2_check_dir_trailer(dir, tmp);
589 static int ocfs2_validate_dx_root(
struct super_block *sb,
590 struct buffer_head *bh)
595 BUG_ON(!buffer_uptodate(bh));
602 "Checksum failed for dir index root block %llu\n",
603 (
unsigned long long)bh->b_blocknr);
609 "Dir Index Root # %llu has bad signature %.*s",
618 static int ocfs2_read_dx_root(
struct inode *dir,
struct ocfs2_dinode *di,
619 struct buffer_head **dx_root_bh)
623 struct buffer_head *tmp = *dx_root_bh;
625 ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp,
626 ocfs2_validate_dx_root);
629 if (!ret && !*dx_root_bh)
635 static int ocfs2_validate_dx_leaf(
struct super_block *sb,
636 struct buffer_head *bh)
641 BUG_ON(!buffer_uptodate(bh));
646 "Checksum failed for dir index leaf block %llu\n",
647 (
unsigned long long)bh->b_blocknr);
652 ocfs2_error(sb,
"Dir Index Leaf has bad signature %.*s",
660 static int ocfs2_read_dx_leaf(
struct inode *dir,
u64 blkno,
661 struct buffer_head **dx_leaf_bh)
664 struct buffer_head *tmp = *dx_leaf_bh;
666 ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp,
667 ocfs2_validate_dx_leaf);
670 if (!ret && !*dx_leaf_bh)
680 static int ocfs2_read_dx_leaves(
struct inode *dir,
u64 start,
int num,
681 struct buffer_head **dx_leaf_bhs)
686 ocfs2_validate_dx_leaf);
693 static struct buffer_head *ocfs2_find_entry_el(
const char *name,
int namelen,
699 struct buffer_head *bh, *ret =
NULL;
711 start = OCFS2_I(dir)->ip_dir_start_lookup;
712 if (start >= nblocks)
721 if (ra_ptr >= ra_max) {
731 if (b >= nblocks || (num && block == start)) {
732 bh_use[ra_max] =
NULL;
738 err = ocfs2_read_dir_block(dir, b++, &bh,
743 if ((bh = bh_use[ra_ptr++]) ==
NULL)
745 if (ocfs2_read_dir_block(dir, block, &bh, 0)) {
750 (
unsigned long long)OCFS2_I(dir)->ip_blkno,
754 i = ocfs2_search_dirblock(bh, dir, name, namelen,
759 OCFS2_I(dir)->ip_dir_start_lookup =
block;
761 goto cleanup_and_exit;
765 goto cleanup_and_exit;
768 if (++block >= nblocks)
770 }
while (block != start);
778 if (block < nblocks) {
785 for (; ra_ptr < ra_max; ra_ptr++)
786 brelse(bh_use[ra_ptr]);
788 trace_ocfs2_find_entry_el(ret);
792 static int ocfs2_dx_dir_lookup_rec(
struct inode *inode,
797 unsigned int *ret_clen)
799 int ret = 0,
i, found;
800 struct buffer_head *eb_bh =
NULL;
817 "Inode %lu has non zero tree depth in "
818 "btree tree block %llu\n", inode->
i_ino,
819 (
unsigned long long)eb_bh->b_blocknr);
837 "record (%u, %u, 0) in btree", inode->
i_ino,
839 ocfs2_rec_clusters(el, rec));
860 static inline unsigned int __ocfs2_dx_dir_hash_idx(
struct ocfs2_super *osb,
866 static inline unsigned int ocfs2_dx_dir_hash_idx(
struct ocfs2_super *osb,
869 return __ocfs2_dx_dir_hash_idx(osb, hinfo->
minor_hash);
872 static int ocfs2_dx_dir_lookup(
struct inode *inode,
884 ret = ocfs2_dx_dir_lookup_rec(inode, el, name_hash, &cpos, &blkno,
892 if (name_hash >= cend) {
894 blkno += ocfs2_clusters_to_blocks(inode->
i_sb, clen - 1);
897 blkno += ocfs2_clusters_to_blocks(inode->
i_sb,
907 blkno += ocfs2_dx_dir_hash_idx(
OCFS2_SB(inode->
i_sb), hinfo);
910 *ret_phys_blkno = blkno;
919 static int ocfs2_dx_dir_search(
const char *name,
int namelen,
926 struct buffer_head *dx_leaf_bh =
NULL;
929 struct buffer_head *dir_ent_bh =
NULL;
935 ocfs2_dx_dir_name_hash(dir, name, namelen, &res->
dl_hinfo);
937 if (ocfs2_dx_root_inline(dx_root)) {
944 ret = ocfs2_dx_dir_lookup(dir, dr_el, hinfo,
NULL, &phys);
950 trace_ocfs2_dx_dir_search((
unsigned long long)OCFS2_I(dir)->ip_blkno,
954 ret = ocfs2_read_dx_leaf(dir, phys, &dx_leaf_bh);
962 trace_ocfs2_dx_dir_search_leaf_info(
966 entry_list = &dx_leaf->
dl_list;
984 ret = ocfs2_read_dir_block_direct(dir,
997 found = ocfs2_search_dirblock(dir_ent_bh, dir, name, namelen,
998 0, dir_ent_bh->b_data,
999 dir->
i_sb->s_blocksize, &dir_ent);
1033 static int ocfs2_find_entry_dx(
const char *name,
int namelen,
1038 struct buffer_head *di_bh =
NULL;
1040 struct buffer_head *dx_root_bh =
NULL;
1051 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh);
1058 ret = ocfs2_dx_dir_search(name, namelen, dir, dx_root, lookup);
1090 struct buffer_head *bh;
1093 if (ocfs2_dir_indexed(dir))
1094 return ocfs2_find_entry_dx(name, namelen, dir, lookup);
1102 bh = ocfs2_find_entry_id(name, namelen, dir, &res_dir);
1104 bh = ocfs2_find_entry_el(name, namelen, dir, &res_dir);
1119 struct inode *new_entry_inode)
1135 ret =
access(handle, INODE_CACHE(dir), de_bh,
1143 ocfs2_set_de_type(de, new_entry_inode->
i_mode);
1155 static int __ocfs2_delete_entry(handle_t *handle,
struct inode *dir,
1157 struct buffer_head *bh,
char *first_de,
1171 if (!ocfs2_check_dir_entry(dir, de, bh, i)) {
1177 status =
access(handle, INODE_CACHE(dir), bh,
1200 static unsigned int ocfs2_figure_dirent_hole(
struct ocfs2_dir_entry *de)
1213 static int ocfs2_find_max_rec_len(
struct super_block *sb,
1214 struct buffer_head *dirblock_bh)
1216 int size, this_hole, largest_hole = 0;
1217 char *trailer, *de_buf, *
limit, *start = dirblock_bh->b_data;
1221 size = ocfs2_dir_trailer_blk_off(sb);
1222 limit = start +
size;
1226 if (de_buf != trailer) {
1227 this_hole = ocfs2_figure_dirent_hole(de);
1228 if (this_hole > largest_hole)
1229 largest_hole = this_hole;
1234 }
while (de_buf < limit);
1237 return largest_hole;
1246 if (num_used == 1 || index == (num_used - 1))
1259 static int ocfs2_delete_entry_dx(handle_t *handle,
struct inode *dir,
1262 int ret,
index, max_rec_len, add_to_free_list = 0;
1264 struct buffer_head *leaf_bh = lookup->
dl_leaf_bh;
1283 if (ocfs2_dx_root_inline(dx_root)) {
1287 entry_list = &dx_leaf->
dl_list;
1295 index = (
char *)dx_entry - (
char *)entry_list->
de_entries;
1296 index /=
sizeof(*dx_entry);
1299 mlog(
ML_ERROR,
"Dir %llu: Bad dx_entry ptr idx %d, (%p, %p)\n",
1300 (
unsigned long long)OCFS2_I(dir)->ip_blkno, index,
1301 entry_list, dx_entry);
1312 add_to_free_list = 1;
1332 if (!ocfs2_dx_root_inline(dx_root)) {
1342 trace_ocfs2_delete_entry_dx((
unsigned long long)OCFS2_I(dir)->ip_blkno,
1345 ret = __ocfs2_delete_entry(handle, dir, lookup->
dl_entry,
1346 leaf_bh, leaf_bh->b_data, leaf_bh->b_size);
1352 max_rec_len = ocfs2_find_max_rec_len(dir->
i_sb, leaf_bh);
1354 if (add_to_free_list) {
1366 ocfs2_dx_list_remove_entry(entry_list, index);
1368 if (!ocfs2_dx_root_inline(dx_root))
1375 static inline int ocfs2_delete_entry_id(handle_t *handle,
1378 struct buffer_head *bh)
1381 struct buffer_head *di_bh =
NULL;
1394 ret = __ocfs2_delete_entry(handle, dir, de_del, bh, data->
id_data,
1402 static inline int ocfs2_delete_entry_el(handle_t *handle,
1405 struct buffer_head *bh)
1407 return __ocfs2_delete_entry(handle, dir, de_del, bh, bh->b_data,
1419 if (ocfs2_dir_indexed(dir))
1420 return ocfs2_delete_entry_dx(handle, dir, res);
1422 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
1423 return ocfs2_delete_entry_id(handle, dir, res->
dl_entry,
1426 return ocfs2_delete_entry_el(handle, dir, res->
dl_entry,
1435 unsigned int new_rec_len)
1437 unsigned int de_really_used;
1455 static void ocfs2_dx_dir_leaf_insert_tail(
struct ocfs2_dx_leaf *dx_leaf,
1461 dx_leaf->
dl_list.de_entries[
i] = *dx_new_entry;
1463 le16_add_cpu(&dx_leaf->
dl_list.de_num_used, 1);
1476 memset(dx_entry, 0,
sizeof(*dx_entry));
1484 static int __ocfs2_dx_dir_leaf_insert(
struct inode *dir, handle_t *handle,
1487 struct buffer_head *dx_leaf_bh)
1500 ocfs2_dx_entry_list_insert(&dx_leaf->
dl_list, hinfo, dirent_blk);
1507 static void ocfs2_dx_inline_root_insert(
struct inode *dir, handle_t *handle,
1512 ocfs2_dx_entry_list_insert(&dx_root->
dr_entries, hinfo, dirent_blk);
1515 static int ocfs2_dx_dir_insert(
struct inode *dir, handle_t *handle,
1530 if (ocfs2_dx_root_inline(dx_root)) {
1531 ocfs2_dx_inline_root_insert(dir, handle,
1536 ret = __ocfs2_dx_dir_leaf_insert(dir, handle, &lookup->
dl_hinfo,
1550 static void ocfs2_remove_block_from_free_list(
struct inode *dir,
1556 struct buffer_head *bh;
1560 if (ocfs2_free_list_at_root(lookup)) {
1581 static void ocfs2_recalc_free_list(
struct inode *dir, handle_t *handle,
1588 max_rec_len = ocfs2_find_max_rec_len(dir->
i_sb, lookup->
dl_leaf_bh);
1599 ocfs2_remove_block_from_free_list(dir, handle, lookup);
1611 const char *name,
int namelen,
1612 struct inode *inode,
u64 blkno,
1613 struct buffer_head *parent_fe_bh,
1623 struct buffer_head *insert_bh = lookup->
dl_leaf_bh;
1629 if (ocfs2_dir_indexed(dir)) {
1630 struct buffer_head *bh;
1640 if (ocfs2_free_list_at_root(lookup)) {
1643 INODE_CACHE(dir), bh,
1648 INODE_CACHE(dir), bh,
1655 }
else if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
1657 size = i_size_read(dir);
1659 BUG_ON(insert_bh != parent_fe_bh);
1671 if (!ocfs2_check_dir_entry(dir, de, insert_bh, offset)) {
1675 if (ocfs2_match(namelen, name, de)) {
1683 "Hit dir trailer trying to insert %.*s "
1684 "(namelen %d) into directory %llu. "
1685 "offset is %lu, trailer offset is %d\n",
1686 namelen, name, namelen,
1687 (
unsigned long long)parent_fe_bh->b_blocknr,
1688 offset, ocfs2_dir_trailer_blk_off(dir->
i_sb));
1690 if (ocfs2_dirent_would_fit(de, rec_len)) {
1698 if (insert_bh == parent_fe_bh)
1709 if (ocfs2_dir_indexed(dir)) {
1710 status = ocfs2_dx_dir_insert(dir,
1734 ocfs2_set_de_type(de, inode->
i_mode);
1740 if (ocfs2_dir_indexed(dir))
1741 ocfs2_recalc_free_list(dir, handle, lookup);
1763 static int ocfs2_dir_foreach_blk_id(
struct inode *inode,
1765 loff_t *f_pos,
void *
priv,
1768 int ret,
i, filldir_ret;
1769 unsigned long offset = *f_pos;
1770 struct buffer_head *di_bh =
NULL;
1777 mlog(
ML_ERROR,
"Unable to read inode block for dir %llu\n",
1778 (
unsigned long long)OCFS2_I(inode)->ip_blkno);
1785 while (*f_pos < i_size_read(inode)) {
1792 for (i = 0; i < i_size_read(inode) && i <
offset; ) {
1806 *f_pos = offset =
i;
1811 if (!ocfs2_check_dir_entry(inode, de, di_bh, *f_pos)) {
1813 *f_pos = i_size_read(inode);
1829 d_type = ocfs2_filetype_table[de->
file_type];
1831 filldir_ret = filldir(priv, de->
name,
1838 *filldir_err = filldir_ret;
1841 if (version != *f_version)
1857 static int ocfs2_dir_foreach_blk_el(
struct inode *inode,
1859 loff_t *f_pos,
void *priv,
1863 unsigned long offset,
blk, last_ra_blk = 0;
1865 struct buffer_head * bh, *
tmp;
1868 unsigned int ra_sectors = 16;
1875 while (!error && !stored && *f_pos < i_size_read(inode)) {
1877 if (ocfs2_read_dir_block(inode, blk, &bh, 0)) {
1889 || (((last_ra_blk - blk) << 9) <= (ra_sectors / 2))) {
1893 if (!ocfs2_read_dir_block(inode, ++blk, &tmp,
1894 OCFS2_BH_READAHEAD))
1926 while (!error && *f_pos < i_size_read(inode)
1929 if (!ocfs2_check_dir_entry(inode, de, bh, offset)) {
1945 unsigned long version = *f_version;
1949 d_type = ocfs2_filetype_table[de->
file_type];
1950 error = filldir(priv, de->
name,
1957 *filldir_err =
error;
1960 if (version != *f_version)
1976 static int ocfs2_dir_foreach_blk(
struct inode *inode,
u64 *f_version,
1977 loff_t *f_pos,
void *priv,
filldir_t filldir,
1980 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
1981 return ocfs2_dir_foreach_blk_id(inode, f_version, f_pos, priv,
1982 filldir, filldir_err);
1984 return ocfs2_dir_foreach_blk_el(inode, f_version, f_pos, priv, filldir,
1995 int ret = 0, filldir_err = 0;
1998 while (*f_pos < i_size_read(inode)) {
1999 ret = ocfs2_dir_foreach_blk(inode, &version, f_pos, priv,
2000 filldir, &filldir_err);
2001 if (ret || filldir_err)
2018 struct inode *inode = filp->
f_path.dentry->d_inode;
2021 trace_ocfs2_readdir((
unsigned long long)OCFS2_I(inode)->ip_blkno);
2024 if (lock_level && error >= 0) {
2039 error = ocfs2_dir_foreach_blk(inode, &filp->
f_version, &filp->
f_pos,
2040 dirent, filldir,
NULL);
2057 struct inode *inode,
2062 trace_ocfs2_find_files_on_disk(namelen, name, blkno,
2063 (
unsigned long long)OCFS2_I(inode)->ip_blkno);
2082 int namelen,
u64 *blkno)
2107 trace_ocfs2_check_dir_for_entry(
2108 (
unsigned long long)OCFS2_I(dir)->ip_blkno, namelen, name);
2129 static int ocfs2_empty_dir_filldir(
void *priv,
const char *name,
int name_len,
2145 if (name_len == 1 && !
strncmp(
".", name, 1) && pos == 0) {
2150 if (name_len == 2 && !
strncmp(
"..", name, 2) &&
2164 static int ocfs2_empty_dir_dx(
struct inode *inode,
2168 struct buffer_head *di_bh =
NULL;
2169 struct buffer_head *dx_root_bh =
NULL;
2182 ret = ocfs2_read_dx_root(inode, di, &dx_root_bh);
2211 memset(&priv, 0,
sizeof(priv));
2213 if (ocfs2_dir_indexed(inode)) {
2214 ret = ocfs2_empty_dir_dx(inode, &priv);
2228 mlog(
ML_ERROR,
"bad directory (dir #%llu) - no `.' or `..'\n",
2229 (
unsigned long long)OCFS2_I(inode)->ip_blkno);
2244 static struct ocfs2_dir_entry *ocfs2_fill_initial_dirents(
struct inode *inode,
2245 struct inode *parent,
2256 ocfs2_set_de_type(de,
S_IFDIR);
2263 ocfs2_set_de_type(de,
S_IFDIR);
2272 static int ocfs2_fill_new_dir_id(
struct ocfs2_super *osb,
2274 struct inode *parent,
2275 struct inode *inode,
2276 struct buffer_head *di_bh)
2290 ocfs2_fill_initial_dirents(inode, parent, data->
id_data, size);
2293 i_size_write(inode, size);
2295 inode->
i_blocks = ocfs2_inode_sector_count(inode);
2305 static int ocfs2_fill_new_dir_el(
struct ocfs2_super *osb,
2307 struct inode *parent,
2308 struct inode *inode,
2309 struct buffer_head *fe_bh,
2311 struct buffer_head **ret_new_bh)
2314 unsigned int size = osb->
sb->s_blocksize;
2315 struct buffer_head *new_bh =
NULL;
2318 if (ocfs2_new_dir_wants_trailer(inode))
2319 size = ocfs2_dir_trailer_blk_off(parent->
i_sb);
2321 status = ocfs2_do_extend_dir(osb->
sb, handle, inode, fe_bh,
2322 data_ac,
NULL, &new_bh);
2336 memset(new_bh->b_data, 0, osb->
sb->s_blocksize);
2338 de = ocfs2_fill_initial_dirents(inode, parent, new_bh->b_data, size);
2339 if (ocfs2_new_dir_wants_trailer(inode)) {
2350 ocfs2_init_dir_trailer(inode, new_bh, size);
2355 i_size_write(inode, inode->
i_sb->s_blocksize);
2357 inode->
i_blocks = ocfs2_inode_sector_count(inode);
2366 *ret_new_bh = new_bh;
2375 static int ocfs2_dx_dir_attach_index(
struct ocfs2_super *osb,
2376 handle_t *handle,
struct inode *dir,
2377 struct buffer_head *di_bh,
2378 struct buffer_head *dirdata_bh,
2381 struct buffer_head **ret_dx_root_bh)
2385 u16 dr_suballoc_bit;
2386 u64 suballoc_loc, dr_blkno;
2387 unsigned int num_bits;
2388 struct buffer_head *dx_root_bh =
NULL;
2394 &dr_suballoc_bit, &num_bits, &dr_blkno);
2400 trace_ocfs2_dx_dir_attach_index(
2401 (
unsigned long long)OCFS2_I(dir)->ip_blkno,
2402 (
unsigned long long)dr_blkno);
2404 dx_root_bh = sb_getblk(osb->
sb, dr_blkno);
2405 if (dx_root_bh ==
NULL) {
2419 memset(dx_root, 0, osb->
sb->s_blocksize);
2452 spin_lock(&OCFS2_I(dir)->ip_lock);
2455 spin_unlock(&OCFS2_I(dir)->ip_lock);
2459 *ret_dx_root_bh = dx_root_bh;
2467 static int ocfs2_dx_dir_format_cluster(
struct ocfs2_super *osb,
2468 handle_t *handle,
struct inode *dir,
2469 struct buffer_head **dx_leaves,
2470 int num_dx_leaves,
u64 start_blk)
2474 struct buffer_head *bh;
2476 for (i = 0; i < num_dx_leaves; i++) {
2477 bh = sb_getblk(osb->
sb, start_blk + i);
2495 memset(dx_leaf, 0, osb->
sb->s_blocksize);
2502 trace_ocfs2_dx_dir_format_cluster(
2503 (
unsigned long long)OCFS2_I(dir)->ip_blkno,
2504 (
unsigned long long)bh->b_blocknr,
2520 static int __ocfs2_dx_dir_new_cluster(
struct inode *dir,
2521 u32 cpos, handle_t *handle,
2523 struct buffer_head **dx_leaves,
2524 int num_dx_leaves,
u64 *ret_phys_blkno)
2547 phys_blkno = ocfs2_clusters_to_blocks(osb->
sb, phys);
2548 ret = ocfs2_dx_dir_format_cluster(osb, handle, dir, dx_leaves,
2549 num_dx_leaves, phys_blkno);
2555 *ret_phys_blkno = phys_blkno;
2560 static int ocfs2_dx_dir_new_cluster(
struct inode *dir,
2562 u32 cpos, handle_t *handle,
2565 struct buffer_head **dx_leaves,
2571 ret = __ocfs2_dx_dir_new_cluster(dir, cpos, handle, data_ac, dx_leaves,
2572 num_dx_leaves, &phys_blkno);
2586 static struct buffer_head **ocfs2_dx_dir_kmalloc_leaves(
struct super_block *sb,
2587 int *ret_num_leaves)
2589 int num_dx_leaves = ocfs2_clusters_to_blocks(sb, 1);
2590 struct buffer_head **dx_leaves;
2592 dx_leaves = kcalloc(num_dx_leaves,
sizeof(
struct buffer_head *),
2594 if (dx_leaves && ret_num_leaves)
2595 *ret_num_leaves = num_dx_leaves;
2600 static int ocfs2_fill_new_dir_dx(
struct ocfs2_super *osb,
2602 struct inode *parent,
2603 struct inode *inode,
2604 struct buffer_head *di_bh,
2609 struct buffer_head *leaf_bh =
NULL;
2610 struct buffer_head *dx_root_bh =
NULL;
2626 ret = ocfs2_fill_new_dir_el(osb, handle, parent, inode, di_bh,
2633 ret = ocfs2_dx_dir_attach_index(osb, handle, inode, di_bh, leaf_bh,
2634 meta_ac, 1, 2, &dx_root_bh);
2643 ocfs2_dx_dir_name_hash(inode,
".", 1, &hinfo);
2644 ocfs2_dx_entry_list_insert(entry_list, &hinfo, leaf_bh->b_blocknr);
2646 ocfs2_dx_dir_name_hash(inode,
"..", 2, &hinfo);
2647 ocfs2_dx_entry_list_insert(entry_list, &hinfo, leaf_bh->b_blocknr);
2657 struct inode *parent,
2658 struct inode *inode,
2659 struct buffer_head *fe_bh,
2664 BUG_ON(!ocfs2_supports_inline_data(osb) && data_ac ==
NULL);
2666 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
2667 return ocfs2_fill_new_dir_id(osb, handle, parent, inode, fe_bh);
2669 if (ocfs2_supports_indexed_dirs(osb))
2670 return ocfs2_fill_new_dir_dx(osb, handle, parent, inode, fe_bh,
2673 return ocfs2_fill_new_dir_el(osb, handle, parent, inode, fe_bh,
2677 static int ocfs2_dx_dir_index_block(
struct inode *dir,
2679 struct buffer_head **dx_leaves,
2681 u32 *num_dx_entries,
2682 struct buffer_head *dirent_bh)
2685 char *de_buf, *
limit;
2687 struct buffer_head *dx_leaf_bh;
2689 u64 dirent_blk = dirent_bh->b_blocknr;
2691 de_buf = dirent_bh->b_data;
2692 limit = de_buf + dir->
i_sb->s_blocksize;
2694 while (de_buf < limit) {
2698 if (!namelen || !de->
inode)
2701 ocfs2_dx_dir_name_hash(dir, de->
name, namelen, &hinfo);
2703 i = ocfs2_dx_dir_hash_idx(
OCFS2_SB(dir->
i_sb), &hinfo);
2704 dx_leaf_bh = dx_leaves[
i];
2706 ret = __ocfs2_dx_dir_leaf_insert(dir, handle, &hinfo,
2707 dirent_blk, dx_leaf_bh);
2713 *num_dx_entries = *num_dx_entries + 1;
2726 static void ocfs2_dx_dir_index_root_block(
struct inode *dir,
2727 struct buffer_head *dx_root_bh,
2728 struct buffer_head *dirent_bh)
2730 char *de_buf, *
limit;
2734 u64 dirent_blk = dirent_bh->b_blocknr;
2738 de_buf = dirent_bh->b_data;
2739 limit = de_buf + dir->
i_sb->s_blocksize;
2741 while (de_buf < limit) {
2747 ocfs2_dx_dir_name_hash(dir, de->
name, de->
name_len, &hinfo);
2749 trace_ocfs2_dx_dir_index_root_block(
2750 (
unsigned long long)dir->
i_ino,
2755 ocfs2_dx_entry_list_insert(&dx_root->
dr_entries, &hinfo,
2769 static int ocfs2_new_dx_should_be_inline(
struct inode *dir,
2770 struct buffer_head *di_bh)
2772 int dirent_count = 0;
2773 char *de_buf, *
limit;
2778 limit = de_buf + i_size_read(dir);
2780 while (de_buf < limit) {
2790 return dirent_count < ocfs2_dx_entries_per_root(dir->
i_sb);
2807 static unsigned int ocfs2_expand_last_dirent(
char *start,
unsigned int old_size,
2813 char *de_buf, *
limit;
2815 unsigned int bytes, this_hole;
2816 unsigned int largest_hole = 0;
2818 if (ocfs2_new_dir_wants_trailer(dir))
2819 new_size = ocfs2_dir_trailer_blk_off(sb);
2827 this_hole = ocfs2_figure_dirent_hole(de);
2828 if (this_hole > largest_hole)
2829 largest_hole = this_hole;
2834 }
while (de_buf < limit);
2836 le16_add_cpu(&prev_de->
rec_len, bytes);
2840 this_hole = ocfs2_figure_dirent_hole(prev_de);
2841 if (this_hole > largest_hole)
2842 largest_hole = this_hole;
2845 return largest_hole;
2857 static int ocfs2_expand_inline_dir(
struct inode *dir,
struct buffer_head *di_bh,
2858 unsigned int blocks_wanted,
2860 struct buffer_head **first_block_bh)
2862 u32 alloc, dx_alloc, bit_off, len, num_dx_entries = 0;
2864 int ret,
i, num_dx_leaves = 0, dx_inline = 0,
2865 credits = ocfs2_inline_to_extents_credits(sb);
2866 u64 dx_insert_blkno, blkno,
2872 struct buffer_head *dirdata_bh =
NULL;
2873 struct buffer_head *dx_root_bh =
NULL;
2874 struct buffer_head **dx_leaves =
NULL;
2879 int did_quota = 0, bytes_allocated = 0;
2883 alloc = ocfs2_clusters_for_bytes(sb, bytes);
2888 if (ocfs2_supports_indexed_dirs(osb)) {
2889 credits += ocfs2_add_dir_index_credits(sb);
2891 dx_inline = ocfs2_new_dx_should_be_inline(dir, di_bh);
2895 dx_leaves = ocfs2_dx_dir_kmalloc_leaves(sb,
2936 if (IS_ERR(handle)) {
2937 ret = PTR_ERR(handle);
2942 ret = dquot_alloc_space_nodirty(dir,
2943 ocfs2_clusters_to_bytes(osb->
sb, alloc + dx_alloc));
2948 if (ocfs2_supports_indexed_dirs(osb) && !dx_inline) {
2954 ret = __ocfs2_dx_dir_new_cluster(dir, 0, handle, data_ac,
2955 dx_leaves, num_dx_leaves,
2961 bytes_allocated += ocfs2_clusters_to_bytes(dir->
i_sb, 1);
2976 bytes_allocated += ocfs2_clusters_to_bytes(dir->
i_sb, 1);
2983 blkno = ocfs2_clusters_to_blocks(dir->
i_sb, bit_off);
2984 dirdata_bh = sb_getblk(sb, blkno);
3001 memset(dirdata_bh->b_data + i_size_read(dir), 0,
3003 i = ocfs2_expand_last_dirent(dirdata_bh->b_data, i_size_read(dir), dir);
3004 if (ocfs2_new_dir_wants_trailer(dir)) {
3011 ocfs2_init_dir_trailer(dir, dirdata_bh, i);
3016 if (ocfs2_supports_indexed_dirs(osb) && !dx_inline) {
3025 ret = ocfs2_dx_dir_index_block(dir, handle, dx_leaves,
3026 num_dx_leaves, &num_dx_entries,
3078 dir->
i_blocks = ocfs2_inode_sector_count(dir);
3082 if (ocfs2_supports_indexed_dirs(osb)) {
3083 ret = ocfs2_dx_dir_attach_index(osb, handle, dir, di_bh,
3084 dirdata_bh, meta_ac, dx_inline,
3085 num_dx_entries, &dx_root_bh);
3092 ocfs2_dx_dir_index_root_block(dir, dx_root_bh,
3099 dx_insert_blkno, 1, 0,
NULL);
3116 blkno = ocfs2_clusters_to_blocks(dir->
i_sb, bit_off);
3119 blkno, len, 0,
NULL);
3124 bytes_allocated += ocfs2_clusters_to_bytes(dir->
i_sb, 1);
3127 *first_block_bh = dirdata_bh;
3129 if (ocfs2_supports_indexed_dirs(osb)) {
3139 get_bh(dx_leaves[off]);
3147 if (ret < 0 && did_quota)
3148 dquot_free_space_nodirty(dir, bytes_allocated);
3160 for (i = 0; i < num_dx_leaves; i++)
3161 brelse(dx_leaves[i]);
3172 static int ocfs2_do_extend_dir(
struct super_block *sb,
3175 struct buffer_head *parent_fe_bh,
3178 struct buffer_head **new_bh)
3181 int extend, did_quota = 0;
3182 u64 p_blkno, v_blkno;
3184 spin_lock(&OCFS2_I(dir)->ip_lock);
3185 extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters));
3186 spin_unlock(&OCFS2_I(dir)->ip_lock);
3189 u32 offset = OCFS2_I(dir)->ip_clusters;
3191 status = dquot_alloc_space_nodirty(dir,
3192 ocfs2_clusters_to_bytes(sb, 1));
3198 1, 0, parent_fe_bh, handle,
3199 data_ac, meta_ac,
NULL);
3207 v_blkno = ocfs2_blocks_for_bytes(sb, i_size_read(dir));
3214 *new_bh = sb_getblk(sb, p_blkno);
3222 if (did_quota && status < 0)
3223 dquot_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1));
3237 static int ocfs2_extend_dir(
struct ocfs2_super *osb,
3239 struct buffer_head *parent_fe_bh,
3240 unsigned int blocks_wanted,
3242 struct buffer_head **new_de_bh)
3245 int credits, num_free_extents, drop_alloc_sem = 0;
3251 handle_t *handle =
NULL;
3252 struct buffer_head *new_bh =
NULL;
3265 status = ocfs2_expand_inline_dir(dir, parent_fe_bh,
3266 blocks_wanted, lookup,
3277 if (blocks_wanted == 1) {
3298 dir_i_size = i_size_read(dir);
3305 dir_i_size = i_size_read(dir);
3306 trace_ocfs2_extend_dir((
unsigned long long)OCFS2_I(dir)->ip_blkno,
3310 spin_lock(&OCFS2_I(dir)->ip_lock);
3311 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) {
3312 spin_unlock(&OCFS2_I(dir)->ip_lock);
3316 if (num_free_extents < 0) {
3317 status = num_free_extents;
3322 if (!num_free_extents) {
3339 data_ac->
ac_resv = &OCFS2_I(dir)->ip_la_data_resv;
3341 credits = ocfs2_calc_extend_credits(sb, el, 1);
3343 spin_unlock(&OCFS2_I(dir)->ip_lock);
3348 if (ocfs2_dir_indexed(dir))
3353 if (IS_ERR(handle)) {
3354 status = PTR_ERR(handle);
3360 status = ocfs2_do_extend_dir(osb->
sb, handle, dir, parent_fe_bh,
3361 data_ac, meta_ac, &new_bh);
3379 if (ocfs2_supports_dir_trailer(dir)) {
3384 if (ocfs2_dir_indexed(dir)) {
3385 status = ocfs2_dx_dir_link_trailer(dir, handle,
3386 dx_root_bh, new_bh);
3397 dir_i_size += dir->
i_sb->s_blocksize;
3398 i_size_write(dir, dir_i_size);
3399 dir->
i_blocks = ocfs2_inode_sector_count(dir);
3407 *new_de_bh = new_bh;
3413 up_write(&OCFS2_I(dir)->ip_alloc_sem);
3425 static int ocfs2_find_dir_space_id(
struct inode *dir,
struct buffer_head *di_bh,
3426 const char *name,
int namelen,
3427 struct buffer_head **ret_de_bh,
3428 unsigned int *blocks_wanted)
3434 char *de_buf, *limit;
3435 unsigned long offset = 0;
3436 unsigned int rec_len, new_rec_len, free_space = dir->
i_sb->s_blocksize;
3442 if (ocfs2_new_dir_wants_trailer(dir))
3443 free_space = ocfs2_dir_trailer_blk_off(sb) - i_size_read(dir);
3445 free_space = dir->
i_sb->s_blocksize - i_size_read(dir);
3448 limit = de_buf + i_size_read(dir);
3451 while (de_buf < limit) {
3454 if (!ocfs2_check_dir_entry(dir, de, di_bh, offset)) {
3458 if (ocfs2_match(namelen, name, de)) {
3467 if (ocfs2_dirent_would_fit(de, rec_len)) {
3487 new_rec_len =
le16_to_cpu(last_de->rec_len) + free_space;
3496 static int ocfs2_find_dir_space_el(
struct inode *dir,
const char *name,
3497 int namelen,
struct buffer_head **ret_de_bh)
3500 struct buffer_head *bh =
NULL;
3505 int blocksize = dir->
i_sb->s_blocksize;
3507 status = ocfs2_read_dir_block(dir, 0, &bh, 0);
3521 if (i_size_read(dir) <= offset) {
3529 status = ocfs2_read_dir_block(dir,
3539 if (!ocfs2_check_dir_entry(dir, de, bh, offset)) {
3543 if (ocfs2_match(namelen, name, de)) {
3548 if (ocfs2_skip_dir_trailer(dir, de, offset % blocksize,
3552 if (ocfs2_dirent_would_fit(de, rec_len)) {
3574 static int dx_leaf_sort_cmp(
const void *
a,
const void *b)
3583 if (major_hash1 > major_hash2)
3585 if (major_hash1 < major_hash2)
3591 if (minor_hash1 > minor_hash2)
3593 if (minor_hash1 < minor_hash2)
3598 static void dx_leaf_sort_swap(
void *a,
void *b,
int size)
3604 BUG_ON(size !=
sizeof(*entry1));
3611 static int ocfs2_dx_leaf_same_major(
struct ocfs2_dx_leaf *dx_leaf)
3616 for (i = 0; i < (num - 1); i++) {
3635 static int ocfs2_dx_dir_find_leaf_split(
struct ocfs2_dx_leaf *dx_leaf,
3636 u32 leaf_cpos,
u32 insert_hash,
3651 allsame = ocfs2_dx_leaf_same_major(dx_leaf);
3655 if (val == insert_hash) {
3666 if (val == leaf_cpos) {
3679 *split_hash = leaf_cpos + 1;
3683 if (val > insert_hash) {
3695 *split_hash = insert_hash;
3705 for (i = (num_used / 2); i < num_used; i++)
3724 static void ocfs2_dx_dir_transfer_leaf(
struct inode *dir,
u32 split_hash,
3727 struct buffer_head **orig_dx_leaves,
3728 struct buffer_head **new_dx_leaves,
3737 tmp_list = &tmp_dx_leaf->
dl_list;
3739 for (i = 0; i < num_dx_leaves; i++) {
3740 orig_dx_leaf = (
struct ocfs2_dx_leaf *) orig_dx_leaves[i]->b_data;
3741 orig_list = &orig_dx_leaf->
dl_list;
3742 new_dx_leaf = (
struct ocfs2_dx_leaf *) new_dx_leaves[i]->b_data;
3743 new_list = &new_dx_leaf->
dl_list;
3747 memcpy(tmp_dx_leaf, orig_dx_leaf, dir->
i_sb->s_blocksize);
3751 for (j = 0; j < num_used; j++) {
3754 if (major_hash >= split_hash)
3755 ocfs2_dx_dir_leaf_insert_tail(new_dx_leaf,
3758 ocfs2_dx_dir_leaf_insert_tail(tmp_dx_leaf,
3761 memcpy(orig_dx_leaf, tmp_dx_leaf, dir->
i_sb->s_blocksize);
3768 static int ocfs2_dx_dir_rebalance_credits(
struct ocfs2_super *osb,
3771 int credits = ocfs2_clusters_to_blocks(osb->
sb, 2);
3773 credits += ocfs2_calc_extend_credits(osb->
sb, &dx_root->
dr_list, 1);
3774 credits += ocfs2_quota_trans_credits(osb->
sb);
3782 static int ocfs2_dx_dir_rebalance(
struct ocfs2_super *osb,
struct inode *dir,
3783 struct buffer_head *dx_root_bh,
3784 struct buffer_head *dx_leaf_bh,
3789 int credits, ret, i, num_used, did_quota = 0;
3791 u64 orig_leaves_start;
3793 struct buffer_head **orig_dx_leaves =
NULL;
3794 struct buffer_head **new_dx_leaves =
NULL;
3797 handle_t *handle =
NULL;
3801 trace_ocfs2_dx_dir_rebalance((
unsigned long long)OCFS2_I(dir)->ip_blkno,
3802 (
unsigned long long)leaf_blkno,
3817 mlog(
ML_ERROR,
"DX Dir: %llu, Asked to rebalance empty leaf: "
3818 "%llu, %d\n", (
unsigned long long)OCFS2_I(dir)->ip_blkno,
3819 (
unsigned long long)leaf_blkno, num_used);
3824 orig_dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->
sb, &num_dx_leaves);
3825 if (!orig_dx_leaves) {
3831 new_dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->
sb,
NULL);
3832 if (!new_dx_leaves) {
3845 credits = ocfs2_dx_dir_rebalance_credits(osb, dx_root);
3847 if (IS_ERR(handle)) {
3848 ret = PTR_ERR(handle);
3854 ret = dquot_alloc_space_nodirty(dir,
3855 ocfs2_clusters_to_bytes(dir->
i_sb, 1));
3876 ret = ocfs2_dx_dir_find_leaf_split(dx_leaf, leaf_cpos, insert_hash,
3883 trace_ocfs2_dx_dir_rebalance_split(leaf_cpos, split_hash, insert_hash);
3910 orig_leaves_start = ocfs2_block_to_cluster_start(dir->
i_sb, leaf_blkno);
3911 ret = ocfs2_read_dx_leaves(dir, orig_leaves_start, num_dx_leaves,
3919 ret = ocfs2_dx_dir_new_cluster(dir, &et, cpos, handle,
3920 data_ac, meta_ac, new_dx_leaves,
3927 for (i = 0; i < num_dx_leaves; i++) {
3945 ocfs2_dx_dir_transfer_leaf(dir, split_hash, handle, tmp_dx_leaf,
3946 orig_dx_leaves, new_dx_leaves, num_dx_leaves);
3949 if (ret < 0 && did_quota)
3950 dquot_free_space_nodirty(dir,
3951 ocfs2_clusters_to_bytes(dir->
i_sb, 1));
3956 if (orig_dx_leaves || new_dx_leaves) {
3957 for (i = 0; i < num_dx_leaves; i++) {
3959 brelse(orig_dx_leaves[i]);
3961 brelse(new_dx_leaves[i]);
3963 kfree(orig_dx_leaves);
3964 kfree(new_dx_leaves);
3976 static int ocfs2_find_dir_space_dx(
struct ocfs2_super *osb,
struct inode *dir,
3977 struct buffer_head *di_bh,
3978 struct buffer_head *dx_root_bh,
3979 const char *name,
int namelen,
3982 int ret, rebalanced = 0;
3984 struct buffer_head *dx_leaf_bh =
NULL;
3993 &leaf_cpos, &blkno);
3999 ret = ocfs2_read_dx_leaf(dir, blkno, &dx_leaf_bh);
4021 ret = ocfs2_dx_dir_rebalance(osb, dir, dx_root_bh, dx_leaf_bh,
4038 goto restart_search;
4049 static int ocfs2_search_dx_free_list(
struct inode *dir,
4050 struct buffer_head *dx_root_bh,
4055 struct buffer_head *leaf_bh =
NULL, *prev_leaf_bh =
NULL;
4064 while (next_block) {
4065 brelse(prev_leaf_bh);
4066 prev_leaf_bh = leaf_bh;
4069 ret = ocfs2_read_dir_block_direct(dir, next_block, &leaf_bh);
4080 prev_leaf_bh =
NULL;
4093 brelse(prev_leaf_bh);
4097 static int ocfs2_expand_inline_dx_root(
struct inode *dir,
4098 struct buffer_head *dx_root_bh)
4100 int ret, num_dx_leaves,
i,
j, did_quota = 0;
4101 struct buffer_head **dx_leaves =
NULL;
4106 handle_t *handle =
NULL;
4118 dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->
sb, &num_dx_leaves);
4126 if (IS_ERR(handle)) {
4127 ret = PTR_ERR(handle);
4132 ret = dquot_alloc_space_nodirty(dir,
4133 ocfs2_clusters_to_bytes(osb->
sb, 1));
4150 ret = __ocfs2_dx_dir_new_cluster(dir, 0, handle, data_ac, dx_leaves,
4151 num_dx_leaves, &insert_blkno);
4167 j = __ocfs2_dx_dir_hash_idx(osb,
4171 ocfs2_dx_dir_leaf_insert_tail(target_leaf, dx_entry);
4194 if (ret < 0 && did_quota)
4195 dquot_free_space_nodirty(dir,
4196 ocfs2_clusters_to_bytes(dir->
i_sb, 1));
4205 for (i = 0; i < num_dx_leaves; i++)
4206 brelse(dx_leaves[i]);
4212 static int ocfs2_inline_dx_has_space(
struct buffer_head *dx_root_bh)
4227 static int ocfs2_prepare_dx_dir_for_insert(
struct inode *dir,
4228 struct buffer_head *di_bh,
4233 int ret, free_dx_root = 1;
4235 struct buffer_head *dx_root_bh =
NULL;
4236 struct buffer_head *leaf_bh =
NULL;
4240 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh);
4253 if (ocfs2_dx_root_inline(dx_root)) {
4254 ret = ocfs2_inline_dx_has_space(dx_root_bh);
4264 ret = ocfs2_expand_inline_dx_root(dir, dx_root_bh);
4277 ret = ocfs2_find_dir_space_dx(osb, dir, di_bh, dx_root_bh, name,
4291 ret = ocfs2_search_dx_free_list(dir, dx_root_bh, namelen, lookup);
4292 if (ret && ret != -
ENOSPC) {
4302 ret = ocfs2_extend_dir(osb, dir, di_bh, 1, lookup, &leaf_bh);
4331 struct buffer_head *parent_fe_bh,
4337 unsigned int blocks_wanted = 1;
4338 struct buffer_head *bh =
NULL;
4340 trace_ocfs2_prepare_dir_for_insert(
4341 (
unsigned long long)OCFS2_I(dir)->ip_blkno, namelen);
4360 if (ocfs2_supports_indexed_dirs(osb))
4361 ocfs2_dx_dir_name_hash(dir, name, namelen, &lookup->
dl_hinfo);
4363 if (ocfs2_dir_indexed(dir)) {
4364 ret = ocfs2_prepare_dx_dir_for_insert(dir, parent_fe_bh,
4365 name, namelen, lookup);
4371 if (OCFS2_I(dir)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
4372 ret = ocfs2_find_dir_space_id(dir, parent_fe_bh, name,
4373 namelen, &bh, &blocks_wanted);
4375 ret = ocfs2_find_dir_space_el(dir, name, namelen, &bh);
4377 if (ret && ret != -
ENOSPC) {
4388 ret = ocfs2_extend_dir(osb, dir, parent_fe_bh, blocks_wanted,
4406 static int ocfs2_dx_dir_remove_index(
struct inode *dir,
4407 struct buffer_head *di_bh,
4408 struct buffer_head *dx_root_bh)
4414 struct inode *dx_alloc_inode =
NULL;
4415 struct buffer_head *dx_alloc_bh =
NULL;
4426 if (!dx_alloc_inode) {
4440 if (IS_ERR(handle)) {
4441 ret = PTR_ERR(handle);
4453 spin_lock(&OCFS2_I(dir)->ip_lock);
4456 spin_unlock(&OCFS2_I(dir)->ip_lock);
4466 bg_blkno = ocfs2_which_suballoc_group(blk,
bit);
4480 brelse(dx_alloc_bh);
4482 iput(dx_alloc_inode);
4493 struct buffer_head *dx_root_bh =
NULL;
4499 ocfs2_init_dealloc_ctxt(&dealloc);
4501 if (!ocfs2_dir_indexed(dir))
4504 ret = ocfs2_read_dx_root(dir, di, &dx_root_bh);
4511 if (ocfs2_dx_root_inline(dx_root))
4518 ret = ocfs2_dx_dir_lookup_rec(dir, &dx_root->
dr_list,
4519 major_hash, &cpos, &blkno, &clen);
4525 p_cpos = ocfs2_blocks_to_clusters(dir->
i_sb, blkno);
4537 major_hash = cpos - 1;
4541 ret = ocfs2_dx_dir_remove_index(dir, di_bh, dx_root_bh);