Commit 99b072bb authored by Jaegeuk Kim's avatar Jaegeuk Kim Committed by Al Viro

f2fs: fix readdir incorrectness

In the previous Al Viro's readdir patch set, there occurs a bug when
running
xfstest: 006 as follows.

[Error output]
alpha size = 4, name length = 6, total files = 4096, nproc=1
1023 files created
rm: cannot remove `/mnt/f2fs/permname.15150/a': Directory not empty

[Correct output]
alpha size = 4, name length = 6, total files = 4096, nproc=1
4097 files created

This bug is due to the misupdate of directory position in ctx.
So, this patch fixes this.

[AV: fixed a braino]

CC: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 3de91f92
...@@ -610,13 +610,12 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) ...@@ -610,13 +610,12 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
unsigned long npages = dir_blocks(inode); unsigned long npages = dir_blocks(inode);
unsigned int bit_pos = 0, start_bit_pos = 0; unsigned int bit_pos = 0;
struct f2fs_dentry_block *dentry_blk = NULL; struct f2fs_dentry_block *dentry_blk = NULL;
struct f2fs_dir_entry *de = NULL; struct f2fs_dir_entry *de = NULL;
struct page *dentry_page = NULL; struct page *dentry_page = NULL;
unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK); unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
unsigned char d_type = DT_UNKNOWN; unsigned char d_type = DT_UNKNOWN;
int slots;
bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK); bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK);
...@@ -625,7 +624,6 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) ...@@ -625,7 +624,6 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
if (IS_ERR(dentry_page)) if (IS_ERR(dentry_page))
continue; continue;
start_bit_pos = bit_pos;
dentry_blk = kmap(dentry_page); dentry_blk = kmap(dentry_page);
while (bit_pos < NR_DENTRY_IN_BLOCK) { while (bit_pos < NR_DENTRY_IN_BLOCK) {
bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
...@@ -634,19 +632,19 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) ...@@ -634,19 +632,19 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
if (bit_pos >= NR_DENTRY_IN_BLOCK) if (bit_pos >= NR_DENTRY_IN_BLOCK)
break; break;
ctx->pos += bit_pos - start_bit_pos;
de = &dentry_blk->dentry[bit_pos]; de = &dentry_blk->dentry[bit_pos];
if (de->file_type < F2FS_FT_MAX) if (de->file_type < F2FS_FT_MAX)
d_type = f2fs_filetype_table[de->file_type]; d_type = f2fs_filetype_table[de->file_type];
else else
d_type = DT_UNKNOWN; d_type = DT_UNKNOWN;
if (!dir_emit(ctx, if (!dir_emit(ctx,
dentry_blk->filename[bit_pos], dentry_blk->filename[bit_pos],
le16_to_cpu(de->name_len), le16_to_cpu(de->name_len),
le32_to_cpu(de->ino), d_type)) le32_to_cpu(de->ino), d_type))
goto success; goto stop;
slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
bit_pos += slots; bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
ctx->pos = n * NR_DENTRY_IN_BLOCK + bit_pos;
} }
bit_pos = 0; bit_pos = 0;
ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK; ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;
...@@ -654,7 +652,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) ...@@ -654,7 +652,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
f2fs_put_page(dentry_page, 1); f2fs_put_page(dentry_page, 1);
dentry_page = NULL; dentry_page = NULL;
} }
success: stop:
if (dentry_page && !IS_ERR(dentry_page)) { if (dentry_page && !IS_ERR(dentry_page)) {
kunmap(dentry_page); kunmap(dentry_page);
f2fs_put_page(dentry_page, 1); f2fs_put_page(dentry_page, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment