Skip to content

Commit

Permalink
um: hostfs: Reduce number of syscalls in readdir
Browse files Browse the repository at this point in the history
Currently hostfs issues every time a seekdir(), in fact
it has to do this only upon the first call.
Also telldir() can be omitted as we can obtain the directory
offset from readdir().

Signed-off-by: Richard Weinberger <[email protected]>
  • Loading branch information
richardweinberger committed Apr 13, 2015
1 parent a98a6d8 commit 0c9bd63
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion fs/hostfs/hostfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ extern int stat_file(const char *path, struct hostfs_stat *p, int fd);
extern int access_file(char *path, int r, int w, int x);
extern int open_file(char *path, int r, int w, int append);
extern void *open_dir(char *path, int *err_out);
extern char *read_dir(void *stream, unsigned long long *pos,
extern void seek_dir(void *stream, unsigned long long pos);
extern char *read_dir(void *stream, unsigned long long *pos_out,
unsigned long long *ino_out, int *len_out,
unsigned int *type_out);
extern void close_file(void *stream);
Expand Down
1 change: 1 addition & 0 deletions fs/hostfs/hostfs_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static int hostfs_readdir(struct file *file, struct dir_context *ctx)
if (dir == NULL)
return -error;
next = ctx->pos;
seek_dir(dir, next);
while ((name = read_dir(dir, &next, &ino, &len, &type)) != NULL) {
if (!dir_emit(ctx, name, len, ino, type))
break;
Expand Down
12 changes: 9 additions & 3 deletions fs/hostfs/hostfs_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,27 @@ void *open_dir(char *path, int *err_out)
return dir;
}

char *read_dir(void *stream, unsigned long long *pos,
void seek_dir(void *stream, unsigned long long pos)
{
DIR *dir = stream;

seekdir(dir, pos);
}

char *read_dir(void *stream, unsigned long long *pos_out,
unsigned long long *ino_out, int *len_out,
unsigned int *type_out)
{
DIR *dir = stream;
struct dirent *ent;

seekdir(dir, *pos);
ent = readdir(dir);
if (ent == NULL)
return NULL;
*len_out = strlen(ent->d_name);
*ino_out = ent->d_ino;
*type_out = ent->d_type;
*pos = telldir(dir);
*pos_out = ent->d_off;
return ent->d_name;
}

Expand Down

0 comments on commit 0c9bd63

Please sign in to comment.