43 #define xfs_dir2_leaf_check(dp, bp)
46 int *indexp,
struct xfs_buf **dbpp);
47 static void xfs_dir2_leaf_log_bests(
struct xfs_trans *tp,
struct xfs_buf *bp,
49 static void xfs_dir2_leaf_log_tail(
struct xfs_trans *tp,
struct xfs_buf *bp);
76 trace_xfs_dir2_block_to_leaf(args);
89 ldb = xfs_dir2_da_to_db(mp, blkno);
101 btp = xfs_dir2_block_tail_p(mp, hdr);
102 blp = xfs_dir2_block_leaf_p(btp);
124 &needlog, &needscan);
134 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
136 bestsp = xfs_dir2_leaf_bests_p(ltp);
145 xfs_dir2_leaf_log_bests(tp, lbp, 0, 0);
159 for (*lowstale = index - 1; *lowstale >= 0; --*lowstale) {
170 for (*highstale = index;
176 if (*lowstale >= 0 && index - *lowstale <= *highstale - index)
231 index - lowstale - 1 < highstale - index)) {
232 ASSERT(index - lowstale - 1 >= 0);
240 if (index - lowstale - 1 > 0) {
242 &leaf->
ents[lowstale + 1],
243 (index - lowstale - 1) *
246 *lfloglow =
MIN(lowstale, *lfloglow);
247 *lfloghigh =
MAX(index - 1, *lfloghigh);
249 return &leaf->
ents[index - 1];
255 ASSERT(highstale - index >= 0);
263 if (highstale - index > 0) {
268 *lfloglow =
MIN(index, *lfloglow);
269 *lfloghigh =
MAX(highstale, *lfloghigh);
309 trace_xfs_dir2_leaf_addname(args);
331 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
332 bestsp = xfs_dir2_leaf_bests_p(ltp);
333 length = xfs_dir2_data_entsize(args->
namelen);
340 for (use_block = -1, lep = &leaf->
ents[index];
356 if (use_block == -1) {
435 if (args->
total == 0 && use_block == -1) {
447 &lfloglow, &lfloghigh);
461 if (use_block == -1) {
483 memmove(&bestsp[0], &bestsp[1],
486 xfs_dir2_leaf_log_tail(tp, lbp);
493 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
519 needscan = needlog = 0;
525 &needlog, &needscan);
533 tagp = xfs_dir2_data_entry_tag_p(dep);
553 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
557 highstale, &lfloglow, &lfloghigh);
582 struct xfs_inode *
dp,
600 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
605 (
char *)xfs_dir2_leaf_bests_p(ltp));
703 index - lowstale <= highstale - index))
704 keepstale = lowstale;
706 keepstale = highstale;
717 if (from != keepstale &&
727 if (from == keepstale)
728 lowstale = highstale = to;
747 be16_add_cpu(&leaf->
hdr.
count, -(from - to));
753 if (lowstale >= newindex)
758 *lowstalep = lowstale;
759 *highstalep = highstale;
778 struct xfs_inode *dp,
784 struct xfs_mount *mp = dp->i_mount;
805 for (i = mp->m_dirblkfsbs; i > 0; ) {
825 mp->m_sb.sb_blocksize) - 1;
861 mip->
map_off = xfs_dir2_byte_to_da(mp,
874 sizeof(map[i]) * length);
887 *curoff = xfs_dir2_da_to_byte(mp, mip->
map_off);
918 i += mp->m_dirblkfsbs) {
925 xfs_buf_readahead(mp->m_ddev_targp,
929 (
int)
BTOBB(mp->m_dirblksize));
948 for (j = 0; j < mp->m_dirblkfsbs; j++) {
953 length =
min_t(
int, mp->m_dirblkfsbs,
1013 length =
howmany(bufsize + mp->m_dirblksize,
1014 mp->m_sb.sb_blocksize);
1024 curoff = xfs_dir2_dataptr_to_byte(mp, *offset);
1030 map_info->
map_off = xfs_dir2_db_to_da(mp,
1031 xfs_dir2_byte_to_db(mp, curoff));
1042 if (!bp || ptr >= (
char *)bp->
b_addr + mp->m_dirblksize) {
1052 newoff = xfs_dir2_db_off_to_byte(mp, map_info->
curdb, 0);
1056 if (curoff < newoff)
1061 else if (curoff > newoff)
1062 ASSERT(xfs_dir2_byte_to_db(mp, curoff) ==
1069 ptr = (
char *)(hdr + 1);
1070 byteoff = xfs_dir2_byte_to_off(mp, curoff);
1075 curoff += (
uint)
sizeof(*hdr);
1080 while ((
char *)ptr - (
char *)hdr < byteoff) {
1092 xfs_dir2_data_entsize(dep->
namelen);
1099 xfs_dir2_db_off_to_byte(mp,
1100 xfs_dir2_byte_to_db(mp, curoff),
1101 (
char *)ptr - (
char *)hdr);
1102 if (ptr >= (
char *)hdr + mp->m_dirblksize) {
1123 length = xfs_dir2_data_entsize(dep->
namelen);
1125 if (filldir(dirent, (
char *)dep->
name, dep->
namelen,
1126 xfs_dir2_byte_to_dataptr(mp, curoff) & 0x7fffffff,
1136 bufsize = bufsize > length ? bufsize - length : 0;
1145 *offset = xfs_dir2_byte_to_dataptr(mp, curoff) & 0x7fffffff;
1179 error =
xfs_da_get_buf(tp, dp, xfs_dir2_db_to_da(mp, bno), -1, &bp,
1201 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1203 xfs_dir2_leaf_log_tail(tp, bp);
1213 xfs_dir2_leaf_log_bests(
1226 ltp = xfs_dir2_leaf_tail_p(tp->t_mountp, leaf);
1227 firstb = xfs_dir2_leaf_bests_p(ltp) +
first;
1228 lastb = xfs_dir2_leaf_bests_p(ltp) + last;
1230 (
uint)((
char *)lastb - (
char *)leaf +
sizeof(*lastb) - 1));
1251 lastlep = &leaf->
ents[last];
1253 (
uint)((
char *)lastlep - (
char *)leaf +
sizeof(*lastlep) - 1));
1261 struct xfs_trans *tp,
1270 (
uint)(
sizeof(leaf->
hdr) - 1));
1277 xfs_dir2_leaf_log_tail(
1278 struct xfs_trans *tp,
1288 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1290 (
uint)(mp->m_dirblksize - 1));
1312 trace_xfs_dir2_leaf_lookup(args);
1317 if ((error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp))) {
1351 xfs_dir2_leaf_lookup_int(
1409 if (newdb != curdb) {
1413 xfs_dir2_db_to_da(mp, newdb),
1432 cmp = mp->m_dirnameops->compname(args, dep->
name, dep->
namelen);
1452 if (cidb != curdb) {
1455 xfs_dir2_db_to_da(mp, cidb),
1501 trace_xfs_dir2_leaf_removename(args);
1506 if ((error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp))) {
1522 needscan = needlog = 0;
1524 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1525 bestsp = xfs_dir2_leaf_bests_p(ltp);
1532 xfs_dir2_data_entsize(dep->
namelen), &needlog, &needscan);
1554 xfs_dir2_leaf_log_bests(tp, lbp, db, db);
1561 mp->m_dirblksize - (
uint)
sizeof(*hdr)) {
1562 ASSERT(db != mp->m_dirdatablk);
1584 for (i = db - 1; i > 0; i--) {
1592 memmove(&bestsp[db - i], bestsp,
1594 be32_add_cpu(<p->
bestcount, -(db - i));
1595 xfs_dir2_leaf_log_tail(tp, lbp);
1603 else if (db != mp->m_dirdatablk)
1630 trace_xfs_dir2_leaf_replace(args);
1635 if ((error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp))) {
1692 mid = (low +
high) >> 1;
1693 if ((hash =
be32_to_cpu(lep[mid].hashval)) == hashwant)
1695 if (hash < hashwant)
1703 if (hash == hashwant) {
1704 while (mid > 0 &&
be32_to_cpu(lep[mid - 1].hashval) == hashwant) {
1711 else if (hash < hashwant)
1741 if ((error =
xfs_da_read_buf(tp, dp, xfs_dir2_db_to_da(mp, db), -1, &dbp,
1747 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1755 mp->m_dirblksize - (
uint)
sizeof(*hdr));
1771 bestsp = xfs_dir2_leaf_bests_p(ltp);
1774 xfs_dir2_leaf_log_tail(tp, lbp);
1779 static inline size_t
1823 trace_xfs_dir2_node_to_leaf(args);
1834 fo -= mp->m_dirblkfsbs;
1841 while (fo > mp->m_dirfreeblk) {
1846 fo -= mp->m_dirblkfsbs;
1897 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1905 xfs_dir2_leaf_log_tail(tp, lbp);