return bidx;
}
-bool early_match_name(size_t namelen, f2fs_hash_t namehash,
+static bool early_match_name(size_t namelen, f2fs_hash_t namehash,
struct f2fs_dir_entry *de)
{
if (le16_to_cpu(de->name_len) != namelen)
}
static struct f2fs_dir_entry *find_in_block(struct page *dentry_page,
- struct qstr *name, int *max_slots,
- f2fs_hash_t namehash, struct page **res_page)
+ struct qstr *name, int *max_slots,
+ struct page **res_page)
+{
+ struct f2fs_dentry_block *dentry_blk;
+ struct f2fs_dir_entry *de;
+
+ *max_slots = NR_DENTRY_IN_BLOCK;
+
+ dentry_blk = (struct f2fs_dentry_block *)kmap(dentry_page);
+ de = find_target_dentry(name, max_slots, &dentry_blk->dentry_bitmap,
+ dentry_blk->dentry,
+ dentry_blk->filename);
+ if (de)
+ *res_page = dentry_page;
+ else
+ kunmap(dentry_page);
+
+ /*
+ * For the most part, it should be a bug when name_len is zero.
+ * We stop here for figuring out where the bugs has occurred.
+ */
+ f2fs_bug_on(F2FS_P_SB(dentry_page), *max_slots < 0);
+ return de;
+}
+
+struct f2fs_dir_entry *find_target_dentry(struct qstr *name, int *max_slots,
+ const void *bitmap, struct f2fs_dir_entry *dentry,
+ __u8 (*filenames)[F2FS_SLOT_LEN])
{
struct f2fs_dir_entry *de;
unsigned long bit_pos = 0;
- struct f2fs_dentry_block *dentry_blk = kmap(dentry_page);
- const void *dentry_bits = &dentry_blk->dentry_bitmap;
+ f2fs_hash_t namehash = f2fs_dentry_hash(name);
+ int max_bits = *max_slots;
int max_len = 0;
- while (bit_pos < NR_DENTRY_IN_BLOCK) {
- if (!test_bit_le(bit_pos, dentry_bits)) {
+ *max_slots = 0;
+ while (bit_pos < max_bits) {
+ if (!test_bit_le(bit_pos, bitmap)) {
if (bit_pos == 0)
max_len = 1;
- else if (!test_bit_le(bit_pos - 1, dentry_bits))
+ else if (!test_bit_le(bit_pos - 1, bitmap))
max_len++;
bit_pos++;
continue;
}
- de = &dentry_blk->dentry[bit_pos];
- if (early_match_name(name->len, namehash, de)) {
- if (!memcmp(dentry_blk->filename[bit_pos],
- name->name,
- name->len)) {
- *res_page = dentry_page;
- goto found;
- }
- }
- if (max_len > *max_slots) {
+ de = &dentry[bit_pos];
+ if (early_match_name(name->len, namehash, de) &&
+ !memcmp(filenames[bit_pos], name->name, name->len))
+ goto found;
+
+ if (*max_slots >= 0 && max_len > *max_slots) {
*max_slots = max_len;
max_len = 0;
}
- /*
- * For the most part, it should be a bug when name_len is zero.
- * We stop here for figuring out where the bugs has occurred.
- */
- f2fs_bug_on(F2FS_P_SB(dentry_page), !de->name_len);
+ /* remain bug on condition */
+ if (unlikely(!de->name_len))
+ *max_slots = -1;
bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
}
de = NULL;
- kunmap(dentry_page);
found:
if (max_len > *max_slots)
*max_slots = max_len;
struct page *dentry_page;
struct f2fs_dir_entry *de = NULL;
bool room = false;
- int max_slots = 0;
+ int max_slots;
f2fs_bug_on(F2FS_I_SB(dir), level > MAX_DIR_HASH_DEPTH);
continue;
}
- de = find_in_block(dentry_page, name, &max_slots,
- namehash, res_page);
+ de = find_in_block(dentry_page, name, &max_slots, res_page);
if (de)
break;
struct qstr *name, struct page **res_page)
{
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
- struct page *ipage;
+ struct f2fs_inline_dentry *inline_dentry;
struct f2fs_dir_entry *de;
- f2fs_hash_t namehash;
- unsigned long bit_pos = 0;
- struct f2fs_inline_dentry *dentry_blk;
- const void *dentry_bits;
+ struct page *ipage;
+ int max_slots = NR_INLINE_DENTRY;
ipage = get_node_page(sbi, dir->i_ino);
if (IS_ERR(ipage))
return NULL;
- namehash = f2fs_dentry_hash(name);
-
- dentry_blk = inline_data_addr(ipage);
- dentry_bits = &dentry_blk->dentry_bitmap;
-
- while (bit_pos < NR_INLINE_DENTRY) {
- if (!test_bit_le(bit_pos, dentry_bits)) {
- bit_pos++;
- continue;
- }
- de = &dentry_blk->dentry[bit_pos];
- if (early_match_name(name->len, namehash, de)) {
- if (!memcmp(dentry_blk->filename[bit_pos],
- name->name,
- name->len)) {
- *res_page = ipage;
- goto found;
- }
- }
-
- /*
- * For the most part, it should be a bug when name_len is zero.
- * We stop here for figuring out where the bugs are occurred.
- */
- f2fs_bug_on(F2FS_P_SB(ipage), !de->name_len);
-
- bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
- }
+ inline_dentry = inline_data_addr(ipage);
- de = NULL;
-found:
+ de = find_target_dentry(name, &max_slots, &inline_dentry->dentry_bitmap,
+ inline_dentry->dentry,
+ inline_dentry->filename);
unlock_page(ipage);
+ if (de)
+ *res_page = ipage;
+ else
+ f2fs_put_page(ipage, 0);
+
+ /*
+ * For the most part, it should be a bug when name_len is zero.
+ * We stop here for figuring out where the bugs has occurred.
+ */
+ f2fs_bug_on(sbi, max_slots < 0);
return de;
}