Skip to content

Commit

Permalink
configfs_readdir(): make safe under shared lock
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed May 9, 2016
1 parent 884be17 commit a01b300
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions fs/configfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,11 +1633,9 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)

if (!dir_emit_dots(file, ctx))
return 0;
if (ctx->pos == 2) {
spin_lock(&configfs_dirent_lock);
spin_lock(&configfs_dirent_lock);
if (ctx->pos == 2)
list_move(q, &parent_sd->s_children);
spin_unlock(&configfs_dirent_lock);
}
for (p = q->next; p != &parent_sd->s_children; p = p->next) {
struct configfs_dirent *next;
const char *name;
Expand All @@ -1648,9 +1646,6 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
if (!next->s_element)
continue;

name = configfs_get_name(next);
len = strlen(name);

/*
* We'll have a dentry and an inode for
* PINNED items and for open attribute
Expand All @@ -1664,7 +1659,6 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
* they close it. Beyond that, we don't
* care.
*/
spin_lock(&configfs_dirent_lock);
dentry = next->s_dentry;
if (dentry)
inode = d_inode(dentry);
Expand All @@ -1674,31 +1668,32 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
if (!inode)
ino = iunique(sb, 2);

name = configfs_get_name(next);
len = strlen(name);

if (!dir_emit(ctx, name, len, ino, dt_type(next)))
return 0;

spin_lock(&configfs_dirent_lock);
list_move(q, p);
spin_unlock(&configfs_dirent_lock);
p = q;
ctx->pos++;
}
spin_unlock(&configfs_dirent_lock);
return 0;
}

static loff_t configfs_dir_lseek(struct file *file, loff_t offset, int whence)
{
struct dentry * dentry = file->f_path.dentry;

inode_lock(d_inode(dentry));
switch (whence) {
case 1:
offset += file->f_pos;
case 0:
if (offset >= 0)
break;
default:
inode_unlock(d_inode(dentry));
return -EINVAL;
}
if (offset != file->f_pos) {
Expand All @@ -1724,7 +1719,6 @@ static loff_t configfs_dir_lseek(struct file *file, loff_t offset, int whence)
spin_unlock(&configfs_dirent_lock);
}
}
inode_unlock(d_inode(dentry));
return offset;
}

Expand All @@ -1733,7 +1727,7 @@ const struct file_operations configfs_dir_operations = {
.release = configfs_dir_close,
.llseek = configfs_dir_lseek,
.read = generic_read_dir,
.iterate = configfs_readdir,
.iterate_shared = configfs_readdir,
};

/**
Expand Down

0 comments on commit a01b300

Please sign in to comment.