Skip to content

Commit 9cdda8d

Browse files
author
Al Viro
committed
[readdir] convert btrfs
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 8e28bc7 commit 9cdda8d

3 files changed

Lines changed: 21 additions & 40 deletions

File tree

‎fs/btrfs/delayed-inode.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,8 +1681,7 @@ int btrfs_should_delete_dir_index(struct list_head *del_list,
16811681
* btrfs_readdir_delayed_dir_index - read dir info stored in the delayed tree
16821682
*
16831683
*/
1684-
int btrfs_readdir_delayed_dir_index(struct file *filp, void *dirent,
1685-
filldir_t filldir,
1684+
int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
16861685
struct list_head *ins_list)
16871686
{
16881687
struct btrfs_dir_item *di;
@@ -1704,13 +1703,13 @@ int btrfs_readdir_delayed_dir_index(struct file *filp, void *dirent,
17041703
list_for_each_entry_safe(curr, next, ins_list, readdir_list) {
17051704
list_del(&curr->readdir_list);
17061705

1707-
if (curr->key.offset < filp->f_pos) {
1706+
if (curr->key.offset < ctx->pos) {
17081707
if (atomic_dec_and_test(&curr->refs))
17091708
kfree(curr);
17101709
continue;
17111710
}
17121711

1713-
filp->f_pos = curr->key.offset;
1712+
ctx->pos = curr->key.offset;
17141713

17151714
di = (struct btrfs_dir_item *)curr->data;
17161715
name = (char *)(di + 1);
@@ -1719,7 +1718,7 @@ int btrfs_readdir_delayed_dir_index(struct file *filp, void *dirent,
17191718
d_type = btrfs_filetype_table[di->type];
17201719
btrfs_disk_key_to_cpu(&location, &di->location);
17211720

1722-
over = filldir(dirent, name, name_len, curr->key.offset,
1721+
over = !dir_emit(ctx, name, name_len,
17231722
location.objectid, d_type);
17241723

17251724
if (atomic_dec_and_test(&curr->refs))

‎fs/btrfs/delayed-inode.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ void btrfs_put_delayed_items(struct list_head *ins_list,
139139
struct list_head *del_list);
140140
int btrfs_should_delete_dir_index(struct list_head *del_list,
141141
u64 index);
142-
int btrfs_readdir_delayed_dir_index(struct file *filp, void *dirent,
143-
filldir_t filldir,
142+
int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
144143
struct list_head *ins_list);
145144

146145
/* for init */

‎fs/btrfs/inode.c‎

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,10 +5137,9 @@ unsigned char btrfs_filetype_table[] = {
51375137
DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
51385138
};
51395139

5140-
static int btrfs_real_readdir(struct file *filp, void *dirent,
5141-
filldir_t filldir)
5140+
static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
51425141
{
5143-
struct inode *inode = file_inode(filp);
5142+
struct inode *inode = file_inode(file);
51445143
struct btrfs_root *root = BTRFS_I(inode)->root;
51455144
struct btrfs_item *item;
51465145
struct btrfs_dir_item *di;
@@ -5161,29 +5160,15 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
51615160
char tmp_name[32];
51625161
char *name_ptr;
51635162
int name_len;
5164-
int is_curr = 0; /* filp->f_pos points to the current index? */
5163+
int is_curr = 0; /* ctx->pos points to the current index? */
51655164

51665165
/* FIXME, use a real flag for deciding about the key type */
51675166
if (root->fs_info->tree_root == root)
51685167
key_type = BTRFS_DIR_ITEM_KEY;
51695168

5170-
/* special case for "." */
5171-
if (filp->f_pos == 0) {
5172-
over = filldir(dirent, ".", 1,
5173-
filp->f_pos, btrfs_ino(inode), DT_DIR);
5174-
if (over)
5175-
return 0;
5176-
filp->f_pos = 1;
5177-
}
5178-
/* special case for .., just use the back ref */
5179-
if (filp->f_pos == 1) {
5180-
u64 pino = parent_ino(filp->f_path.dentry);
5181-
over = filldir(dirent, "..", 2,
5182-
filp->f_pos, pino, DT_DIR);
5183-
if (over)
5184-
return 0;
5185-
filp->f_pos = 2;
5186-
}
5169+
if (!dir_emit_dots(file, ctx))
5170+
return 0;
5171+
51875172
path = btrfs_alloc_path();
51885173
if (!path)
51895174
return -ENOMEM;
@@ -5197,7 +5182,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
51975182
}
51985183

51995184
btrfs_set_key_type(&key, key_type);
5200-
key.offset = filp->f_pos;
5185+
key.offset = ctx->pos;
52015186
key.objectid = btrfs_ino(inode);
52025187

52035188
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
@@ -5223,14 +5208,14 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
52235208
break;
52245209
if (btrfs_key_type(&found_key) != key_type)
52255210
break;
5226-
if (found_key.offset < filp->f_pos)
5211+
if (found_key.offset < ctx->pos)
52275212
goto next;
52285213
if (key_type == BTRFS_DIR_INDEX_KEY &&
52295214
btrfs_should_delete_dir_index(&del_list,
52305215
found_key.offset))
52315216
goto next;
52325217

5233-
filp->f_pos = found_key.offset;
5218+
ctx->pos = found_key.offset;
52345219
is_curr = 1;
52355220

52365221
di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
@@ -5274,9 +5259,8 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
52745259
over = 0;
52755260
goto skip;
52765261
}
5277-
over = filldir(dirent, name_ptr, name_len,
5278-
found_key.offset, location.objectid,
5279-
d_type);
5262+
over = !dir_emit(ctx, name_ptr, name_len,
5263+
location.objectid, d_type);
52805264

52815265
skip:
52825266
if (name_ptr != tmp_name)
@@ -5295,9 +5279,8 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
52955279

52965280
if (key_type == BTRFS_DIR_INDEX_KEY) {
52975281
if (is_curr)
5298-
filp->f_pos++;
5299-
ret = btrfs_readdir_delayed_dir_index(filp, dirent, filldir,
5300-
&ins_list);
5282+
ctx->pos++;
5283+
ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list);
53015284
if (ret)
53025285
goto nopos;
53035286
}
@@ -5308,9 +5291,9 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
53085291
* 32-bit glibc will use getdents64, but then strtol -
53095292
* so the last number we can serve is this.
53105293
*/
5311-
filp->f_pos = 0x7fffffff;
5294+
ctx->pos = 0x7fffffff;
53125295
else
5313-
filp->f_pos++;
5296+
ctx->pos++;
53145297
nopos:
53155298
ret = 0;
53165299
err:
@@ -8731,7 +8714,7 @@ static const struct inode_operations btrfs_dir_ro_inode_operations = {
87318714
static const struct file_operations btrfs_dir_file_operations = {
87328715
.llseek = generic_file_llseek,
87338716
.read = generic_read_dir,
8734-
.readdir = btrfs_real_readdir,
8717+
.iterate = btrfs_real_readdir,
87358718
.unlocked_ioctl = btrfs_ioctl,
87368719
#ifdef CONFIG_COMPAT
87378720
.compat_ioctl = btrfs_ioctl,

0 commit comments

Comments
 (0)