Skip to content

Commit

Permalink
ovl: pass dentry into ovl_dir_read_merged()
Browse files Browse the repository at this point in the history
Pass dentry into ovl_dir_read_merged() insted of upperpath and lowerpath.
This cleans up callers and paves the way for multi-layer directory reads.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
  • Loading branch information
Miklos Szeredi committed Nov 20, 2014
1 parent 71d5092 commit c9f00fd
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions fs/overlayfs/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,37 +274,40 @@ static int ovl_dir_mark_whiteouts(struct dentry *dir,
return 0;
}

static inline int ovl_dir_read_merged(struct path *upperpath,
struct path *lowerpath,
struct list_head *list)
static int ovl_dir_read_merged(struct dentry *dentry, struct list_head *list)
{
int err;
struct path lowerpath;
struct path upperpath;
struct ovl_readdir_data rdd = {
.ctx.actor = ovl_fill_merge,
.list = list,
.root = RB_ROOT,
.is_merge = false,
};

if (upperpath->dentry) {
err = ovl_dir_read(upperpath, &rdd);
ovl_path_lower(dentry, &lowerpath);
ovl_path_upper(dentry, &upperpath);

if (upperpath.dentry) {
err = ovl_dir_read(&upperpath, &rdd);
if (err)
goto out;

if (lowerpath->dentry) {
err = ovl_dir_mark_whiteouts(upperpath->dentry, &rdd);
if (lowerpath.dentry) {
err = ovl_dir_mark_whiteouts(upperpath.dentry, &rdd);
if (err)
goto out;
}
}
if (lowerpath->dentry) {
if (lowerpath.dentry) {
/*
* Insert lowerpath entries before upperpath ones, this allows
* offsets to be reasonably constant
*/
list_add(&rdd.middle, rdd.list);
rdd.is_merge = true;
err = ovl_dir_read(lowerpath, &rdd);
err = ovl_dir_read(&lowerpath, &rdd);
list_del(&rdd.middle);
}
out:
Expand All @@ -329,8 +332,6 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)
static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
{
int res;
struct path lowerpath;
struct path upperpath;
struct ovl_dir_cache *cache;

cache = ovl_dir_cache(dentry);
Expand All @@ -347,10 +348,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
cache->refcount = 1;
INIT_LIST_HEAD(&cache->entries);

ovl_path_lower(dentry, &lowerpath);
ovl_path_upper(dentry, &upperpath);

res = ovl_dir_read_merged(&upperpath, &lowerpath, &cache->entries);
res = ovl_dir_read_merged(dentry, &cache->entries);
if (res) {
ovl_cache_free(&cache->entries);
kfree(cache);
Expand Down Expand Up @@ -538,14 +536,9 @@ const struct file_operations ovl_dir_operations = {
int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
{
int err;
struct path lowerpath;
struct path upperpath;
struct ovl_cache_entry *p;

ovl_path_upper(dentry, &upperpath);
ovl_path_lower(dentry, &lowerpath);

err = ovl_dir_read_merged(&upperpath, &lowerpath, list);
err = ovl_dir_read_merged(dentry, list);
if (err)
return err;

Expand Down

0 comments on commit c9f00fd

Please sign in to comment.