Skip to content

Commit

Permalink
Drop readdir pre-.iterate() compat (el7.5ish).
Browse files Browse the repository at this point in the history
These 2 sections of compat for readdir are wholly obsolete and can be
hard dropped, which restores the method to look like current upstream
code.

Signed-off-by: Auke Kok <[email protected]>
  • Loading branch information
aversecat committed Jul 12, 2024
1 parent 43de817 commit 939b7ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 73 deletions.
20 changes: 0 additions & 20 deletions kmod/src/Makefile.kernelcompat
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@

ccflags-y += -include $(src)/kernelcompat.h

#
# v3.10-rc6-21-gbb6f619b3a49
#
# _readdir changes from fop->readdir() to fop->iterate() and from
# filldir(dirent) to dir_emit(ctx).
#
ifneq (,$(shell grep 'iterate.*dir_context' include/linux/fs.h))
ccflags-y += -DKC_ITERATE_DIR_CONTEXT
endif

#
# v3.10-rc6-23-g5f99f4e79abc
#
# Helpers including dir_emit_dots() are added in the process of
# switching dcache_readdir() from fop->readdir() to fop->iterate()
#
ifneq (,$(shell grep 'dir_emit_dots' include/linux/fs.h))
ccflags-y += -DKC_DIR_EMIT_DOTS
endif

#
# v3.18-rc2-19-gb5ae6b15bd73
#
Expand Down
17 changes: 8 additions & 9 deletions kmod/src/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ static struct dentry *scoutfs_lookup(struct inode *dir, struct dentry *dentry,
* It will need to be careful not to read past the region of the dirent
* hash offset keys that it has access to.
*/
static int KC_DECLARE_READDIR(scoutfs_readdir, struct file *file,
void *dirent, kc_readdir_ctx_t ctx)
static int scoutfs_readdir(struct file *file, struct dir_context *ctx)
{
struct inode *inode = file_inode(file);
struct super_block *sb = inode->i_sb;
Expand All @@ -454,7 +453,7 @@ static int KC_DECLARE_READDIR(scoutfs_readdir, struct file *file,
u64 pos;
int ret;

if (!kc_dir_emit_dots(file, dirent, ctx))
if (!dir_emit_dots(file, ctx))
return 0;

dent = alloc_dirent(SCOUTFS_NAME_LEN);
Expand All @@ -471,7 +470,7 @@ static int KC_DECLARE_READDIR(scoutfs_readdir, struct file *file,

for (;;) {
init_dirent_key(&key, SCOUTFS_READDIR_TYPE, scoutfs_ino(inode),
kc_readdir_pos(file, ctx), 0);
ctx->pos, 0);

ret = scoutfs_item_next(sb, &key, &last_key, dent,
dirent_bytes(SCOUTFS_NAME_LEN),
Expand All @@ -488,23 +487,23 @@ static int KC_DECLARE_READDIR(scoutfs_readdir, struct file *file,
corrupt_dirent_readdir_name_len,
"dir_ino %llu pos %llu key "SK_FMT" len %d",
scoutfs_ino(inode),
kc_readdir_pos(file, ctx),
ctx->pos,
SK_ARG(&key), name_len);
ret = -EIO;
goto out;
}

pos = le64_to_cpu(key.skd_major);
kc_readdir_pos(file, ctx) = pos;
ctx->pos = pos;

if (!kc_dir_emit(ctx, dirent, dent->name, name_len, pos,
if (!dir_emit(ctx, dent->name, name_len,
le64_to_cpu(dent->ino),
dentry_type(dent->type))) {
ret = 0;
break;
}

kc_readdir_pos(file, ctx) = pos + 1;
ctx->pos = pos + 1;
}

out:
Expand Down Expand Up @@ -1944,7 +1943,7 @@ const struct inode_operations scoutfs_symlink_iops = {
};

const struct file_operations scoutfs_dir_fops = {
.KC_FOP_READDIR = scoutfs_readdir,
.iterate = scoutfs_readdir,
#ifdef KC_FMODE_KABI_ITERATE
.open = scoutfs_dir_open,
#endif
Expand Down
44 changes: 0 additions & 44 deletions kmod/src/kernelcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,6 @@ do { \
})
#endif

#ifndef KC_ITERATE_DIR_CONTEXT
typedef filldir_t kc_readdir_ctx_t;
#define KC_DECLARE_READDIR(name, file, dirent, ctx) name(file, dirent, ctx)
#define KC_FOP_READDIR readdir
#define kc_readdir_pos(filp, ctx) (filp)->f_pos
#define kc_dir_emit_dots(file, dirent, ctx) dir_emit_dots(file, dirent, ctx)
#define kc_dir_emit(ctx, dirent, name, name_len, pos, ino, dt) \
(ctx(dirent, name, name_len, pos, ino, dt) == 0)
#else
typedef struct dir_context * kc_readdir_ctx_t;
#define KC_DECLARE_READDIR(name, file, dirent, ctx) name(file, ctx)
#define KC_FOP_READDIR iterate
#define kc_readdir_pos(filp, ctx) (ctx)->pos
#define kc_dir_emit_dots(file, dirent, ctx) dir_emit_dots(file, ctx)
#define kc_dir_emit(ctx, dirent, name, name_len, pos, ino, dt) \
dir_emit(ctx, name, name_len, ino, dt)
#endif

#ifndef KC_DIR_EMIT_DOTS
/*
* Kernels before ->iterate and don't have dir_emit_dots so we give them
* one that works with the ->readdir() filldir() method.
*/
static inline int dir_emit_dots(struct file *file, void *dirent,
filldir_t filldir)
{
if (file->f_pos == 0) {
if (filldir(dirent, ".", 1, 1,
file->f_path.dentry->d_inode->i_ino, DT_DIR))
return 0;
file->f_pos = 1;
}

if (file->f_pos == 1) {
if (filldir(dirent, "..", 2, 1,
parent_ino(file->f_path.dentry), DT_DIR))
return 0;
file->f_pos = 2;
}

return 1;
}
#endif

#ifdef KC_POSIX_ACL_VALID_USER_NS
#define kc_posix_acl_valid(user_ns, acl) posix_acl_valid(user_ns, acl)
#else
Expand Down

0 comments on commit 939b7ec

Please sign in to comment.