Commit c21c839b authored by Chengguang Xu's avatar Chengguang Xu Committed by Miklos Szeredi

ovl: whiteout inode sharing

Share inode with different whiteout files for saving inode and speeding up
delete operation.

If EMLINK is encountered when linking a shared whiteout, create a new one.
In case of any other error, disable sharing for this super block.

Note: ofs->whiteout is protected by inode lock on workdir.
Signed-off-by: default avatarChengguang Xu <cgxu519@mykernel.net>
Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 654255fa
...@@ -62,35 +62,59 @@ struct dentry *ovl_lookup_temp(struct dentry *workdir) ...@@ -62,35 +62,59 @@ struct dentry *ovl_lookup_temp(struct dentry *workdir)
} }
/* caller holds i_mutex on workdir */ /* caller holds i_mutex on workdir */
static struct dentry *ovl_whiteout(struct dentry *workdir) static struct dentry *ovl_whiteout(struct ovl_fs *ofs)
{ {
int err; int err;
struct dentry *whiteout; struct dentry *whiteout;
struct dentry *workdir = ofs->workdir;
struct inode *wdir = workdir->d_inode; struct inode *wdir = workdir->d_inode;
whiteout = ovl_lookup_temp(workdir); if (!ofs->whiteout) {
if (IS_ERR(whiteout)) whiteout = ovl_lookup_temp(workdir);
return whiteout; if (IS_ERR(whiteout))
goto out;
err = ovl_do_whiteout(wdir, whiteout); err = ovl_do_whiteout(wdir, whiteout);
if (err) { if (err) {
dput(whiteout); dput(whiteout);
whiteout = ERR_PTR(err); whiteout = ERR_PTR(err);
goto out;
}
ofs->whiteout = whiteout;
} }
if (ofs->share_whiteout) {
whiteout = ovl_lookup_temp(workdir);
if (IS_ERR(whiteout))
goto out;
err = ovl_do_link(ofs->whiteout, wdir, whiteout);
if (!err)
goto out;
if (err != -EMLINK) {
pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n",
ofs->whiteout->d_inode->i_nlink, err);
ofs->share_whiteout = false;
}
dput(whiteout);
}
whiteout = ofs->whiteout;
ofs->whiteout = NULL;
out:
return whiteout; return whiteout;
} }
/* Caller must hold i_mutex on both workdir and dir */ /* Caller must hold i_mutex on both workdir and dir */
int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
struct dentry *dentry) struct dentry *dentry)
{ {
struct inode *wdir = workdir->d_inode; struct inode *wdir = ofs->workdir->d_inode;
struct dentry *whiteout; struct dentry *whiteout;
int err; int err;
int flags = 0; int flags = 0;
whiteout = ovl_whiteout(workdir); whiteout = ovl_whiteout(ofs);
err = PTR_ERR(whiteout); err = PTR_ERR(whiteout);
if (IS_ERR(whiteout)) if (IS_ERR(whiteout))
return err; return err;
...@@ -715,6 +739,7 @@ static bool ovl_matches_upper(struct dentry *dentry, struct dentry *upper) ...@@ -715,6 +739,7 @@ static bool ovl_matches_upper(struct dentry *dentry, struct dentry *upper)
static int ovl_remove_and_whiteout(struct dentry *dentry, static int ovl_remove_and_whiteout(struct dentry *dentry,
struct list_head *list) struct list_head *list)
{ {
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
struct dentry *workdir = ovl_workdir(dentry); struct dentry *workdir = ovl_workdir(dentry);
struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent);
struct dentry *upper; struct dentry *upper;
...@@ -748,7 +773,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, ...@@ -748,7 +773,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry,
goto out_dput_upper; goto out_dput_upper;
} }
err = ovl_cleanup_and_whiteout(workdir, d_inode(upperdir), upper); err = ovl_cleanup_and_whiteout(ofs, d_inode(upperdir), upper);
if (err) if (err)
goto out_d_drop; goto out_d_drop;
......
...@@ -455,7 +455,7 @@ static inline void ovl_copyflags(struct inode *from, struct inode *to) ...@@ -455,7 +455,7 @@ static inline void ovl_copyflags(struct inode *from, struct inode *to)
/* dir.c */ /* dir.c */
extern const struct inode_operations ovl_dir_inode_operations; extern const struct inode_operations ovl_dir_inode_operations;
int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
struct dentry *dentry); struct dentry *dentry);
struct ovl_cattr { struct ovl_cattr {
dev_t rdev; dev_t rdev;
......
...@@ -68,6 +68,7 @@ struct ovl_fs { ...@@ -68,6 +68,7 @@ struct ovl_fs {
/* Did we take the inuse lock? */ /* Did we take the inuse lock? */
bool upperdir_locked; bool upperdir_locked;
bool workdir_locked; bool workdir_locked;
bool share_whiteout;
/* Traps in ovl inode cache */ /* Traps in ovl inode cache */
struct inode *upperdir_trap; struct inode *upperdir_trap;
struct inode *workbasedir_trap; struct inode *workbasedir_trap;
...@@ -77,6 +78,8 @@ struct ovl_fs { ...@@ -77,6 +78,8 @@ struct ovl_fs {
int xino_mode; int xino_mode;
/* For allocation of non-persistent inode numbers */ /* For allocation of non-persistent inode numbers */
atomic_long_t last_ino; atomic_long_t last_ino;
/* Whiteout dentry cache */
struct dentry *whiteout;
}; };
static inline struct ovl_fs *OVL_FS(struct super_block *sb) static inline struct ovl_fs *OVL_FS(struct super_block *sb)
......
...@@ -1154,7 +1154,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs) ...@@ -1154,7 +1154,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
* Whiteout orphan index to block future open by * Whiteout orphan index to block future open by
* handle after overlay nlink dropped to zero. * handle after overlay nlink dropped to zero.
*/ */
err = ovl_cleanup_and_whiteout(indexdir, dir, index); err = ovl_cleanup_and_whiteout(ofs, dir, index);
} else { } else {
/* Cleanup orphan index entries */ /* Cleanup orphan index entries */
err = ovl_cleanup(dir, index); err = ovl_cleanup(dir, index);
......
...@@ -217,6 +217,7 @@ static void ovl_free_fs(struct ovl_fs *ofs) ...@@ -217,6 +217,7 @@ static void ovl_free_fs(struct ovl_fs *ofs)
iput(ofs->indexdir_trap); iput(ofs->indexdir_trap);
iput(ofs->workdir_trap); iput(ofs->workdir_trap);
iput(ofs->upperdir_trap); iput(ofs->upperdir_trap);
dput(ofs->whiteout);
dput(ofs->indexdir); dput(ofs->indexdir);
dput(ofs->workdir); dput(ofs->workdir);
if (ofs->workdir_locked) if (ofs->workdir_locked)
...@@ -1776,6 +1777,9 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1776,6 +1777,9 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
if (!cred) if (!cred)
goto out_err; goto out_err;
/* Is there a reason anyone would want not to share whiteouts? */
ofs->share_whiteout = true;
ofs->config.index = ovl_index_def; ofs->config.index = ovl_index_def;
ofs->config.nfs_export = ovl_nfs_export_def; ofs->config.nfs_export = ovl_nfs_export_def;
ofs->config.xino = ovl_xino_def(); ofs->config.xino = ovl_xino_def();
......
...@@ -707,7 +707,8 @@ static void ovl_cleanup_index(struct dentry *dentry) ...@@ -707,7 +707,8 @@ static void ovl_cleanup_index(struct dentry *dentry)
index = NULL; index = NULL;
} else if (ovl_index_all(dentry->d_sb)) { } else if (ovl_index_all(dentry->d_sb)) {
/* Whiteout orphan index to block future open by handle */ /* Whiteout orphan index to block future open by handle */
err = ovl_cleanup_and_whiteout(indexdir, dir, index); err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb),
dir, index);
} else { } else {
/* Cleanup orphan index entries */ /* Cleanup orphan index entries */
err = ovl_cleanup(dir, index); err = ovl_cleanup(dir, index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment