ovl: use struct copy_up_ctx as function argument
This cleans up functions with too many arguments. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
parent
7ab8b1763f
commit
23f0ab13ea
|
@ -316,38 +316,45 @@ static int ovl_set_origin(struct dentry *dentry, struct dentry *lower,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ovl_install_temp(struct dentry *workdir, struct dentry *upperdir,
|
struct ovl_copy_up_ctx {
|
||||||
struct dentry *dentry,
|
struct dentry *dentry;
|
||||||
struct dentry *temp, struct kstat *pstat,
|
struct path lowerpath;
|
||||||
bool tmpfile, struct dentry **newdentry)
|
struct kstat stat;
|
||||||
|
struct kstat pstat;
|
||||||
|
const char *link;
|
||||||
|
struct dentry *upperdir;
|
||||||
|
struct dentry *workdir;
|
||||||
|
bool tmpfile;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int ovl_install_temp(struct ovl_copy_up_ctx *c, struct dentry *temp,
|
||||||
|
struct dentry **newdentry)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct dentry *upper;
|
struct dentry *upper;
|
||||||
struct inode *udir = d_inode(upperdir);
|
struct inode *udir = d_inode(c->upperdir);
|
||||||
|
|
||||||
upper = lookup_one_len(dentry->d_name.name, upperdir,
|
upper = lookup_one_len(c->dentry->d_name.name, c->upperdir,
|
||||||
dentry->d_name.len);
|
c->dentry->d_name.len);
|
||||||
if (IS_ERR(upper))
|
if (IS_ERR(upper))
|
||||||
return PTR_ERR(upper);
|
return PTR_ERR(upper);
|
||||||
|
|
||||||
if (tmpfile)
|
if (c->tmpfile)
|
||||||
err = ovl_do_link(temp, udir, upper, true);
|
err = ovl_do_link(temp, udir, upper, true);
|
||||||
else
|
else
|
||||||
err = ovl_do_rename(d_inode(workdir), temp, udir, upper, 0);
|
err = ovl_do_rename(d_inode(c->workdir), temp, udir, upper, 0);
|
||||||
|
|
||||||
/* Restore timestamps on parent (best effort) */
|
/* Restore timestamps on parent (best effort) */
|
||||||
if (!err) {
|
if (!err) {
|
||||||
ovl_set_timestamps(upperdir, pstat);
|
ovl_set_timestamps(c->upperdir, &c->pstat);
|
||||||
*newdentry = dget(tmpfile ? upper : temp);
|
*newdentry = dget(c->tmpfile ? upper : temp);
|
||||||
}
|
}
|
||||||
dput(upper);
|
dput(upper);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ovl_get_tmpfile(struct dentry *workdir, struct dentry *dentry,
|
static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp)
|
||||||
struct kstat *stat, const char *link, bool tmpfile,
|
|
||||||
struct dentry **tempp)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct dentry *temp;
|
struct dentry *temp;
|
||||||
|
@ -355,28 +362,28 @@ static int ovl_get_tmpfile(struct dentry *workdir, struct dentry *dentry,
|
||||||
struct cred *new_creds = NULL;
|
struct cred *new_creds = NULL;
|
||||||
struct cattr cattr = {
|
struct cattr cattr = {
|
||||||
/* Can't properly set mode on creation because of the umask */
|
/* Can't properly set mode on creation because of the umask */
|
||||||
.mode = stat->mode & S_IFMT,
|
.mode = c->stat.mode & S_IFMT,
|
||||||
.rdev = stat->rdev,
|
.rdev = c->stat.rdev,
|
||||||
.link = link
|
.link = c->link
|
||||||
};
|
};
|
||||||
|
|
||||||
err = security_inode_copy_up(dentry, &new_creds);
|
err = security_inode_copy_up(c->dentry, &new_creds);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (new_creds)
|
if (new_creds)
|
||||||
old_creds = override_creds(new_creds);
|
old_creds = override_creds(new_creds);
|
||||||
|
|
||||||
if (tmpfile) {
|
if (c->tmpfile) {
|
||||||
temp = ovl_do_tmpfile(workdir, stat->mode);
|
temp = ovl_do_tmpfile(c->workdir, c->stat.mode);
|
||||||
if (IS_ERR(temp))
|
if (IS_ERR(temp))
|
||||||
goto temp_err;
|
goto temp_err;
|
||||||
} else {
|
} else {
|
||||||
temp = ovl_lookup_temp(workdir);
|
temp = ovl_lookup_temp(c->workdir);
|
||||||
if (IS_ERR(temp))
|
if (IS_ERR(temp))
|
||||||
goto temp_err;
|
goto temp_err;
|
||||||
|
|
||||||
err = ovl_create_real(d_inode(workdir), temp, &cattr,
|
err = ovl_create_real(d_inode(c->workdir), temp, &cattr,
|
||||||
NULL, true);
|
NULL, true);
|
||||||
if (err) {
|
if (err) {
|
||||||
dput(temp);
|
dput(temp);
|
||||||
|
@ -398,29 +405,28 @@ temp_err:
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ovl_copy_up_inode(struct dentry *dentry, struct dentry *temp,
|
static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)
|
||||||
struct path *lowerpath, struct kstat *stat)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (S_ISREG(stat->mode)) {
|
if (S_ISREG(c->stat.mode)) {
|
||||||
struct path upperpath;
|
struct path upperpath;
|
||||||
|
|
||||||
ovl_path_upper(dentry, &upperpath);
|
ovl_path_upper(c->dentry, &upperpath);
|
||||||
BUG_ON(upperpath.dentry != NULL);
|
BUG_ON(upperpath.dentry != NULL);
|
||||||
upperpath.dentry = temp;
|
upperpath.dentry = temp;
|
||||||
|
|
||||||
err = ovl_copy_up_data(lowerpath, &upperpath, stat->size);
|
err = ovl_copy_up_data(&c->lowerpath, &upperpath, c->stat.size);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ovl_copy_xattr(lowerpath->dentry, temp);
|
err = ovl_copy_xattr(c->lowerpath.dentry, temp);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
inode_lock(temp->d_inode);
|
inode_lock(temp->d_inode);
|
||||||
err = ovl_set_attr(temp, stat);
|
err = ovl_set_attr(temp, &c->stat);
|
||||||
inode_unlock(temp->d_inode);
|
inode_unlock(temp->d_inode);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -432,8 +438,8 @@ static int ovl_copy_up_inode(struct dentry *dentry, struct dentry *temp,
|
||||||
* Don't set origin when we are breaking the association with a lower
|
* Don't set origin when we are breaking the association with a lower
|
||||||
* hard link.
|
* hard link.
|
||||||
*/
|
*/
|
||||||
if (S_ISDIR(stat->mode) || stat->nlink == 1) {
|
if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1) {
|
||||||
err = ovl_set_origin(dentry, lowerpath->dentry, temp);
|
err = ovl_set_origin(c->dentry, c->lowerpath.dentry, temp);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -441,45 +447,39 @@ static int ovl_copy_up_inode(struct dentry *dentry, struct dentry *temp,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
|
static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c)
|
||||||
struct dentry *dentry, struct path *lowerpath,
|
|
||||||
struct kstat *stat, const char *link,
|
|
||||||
struct kstat *pstat, bool tmpfile)
|
|
||||||
{
|
{
|
||||||
struct inode *wdir = workdir->d_inode;
|
struct inode *udir = c->upperdir->d_inode;
|
||||||
struct inode *udir = upperdir->d_inode;
|
|
||||||
struct dentry *newdentry = NULL;
|
struct dentry *newdentry = NULL;
|
||||||
struct dentry *temp = NULL;
|
struct dentry *temp = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = ovl_get_tmpfile(workdir, dentry, stat, link, tmpfile, &temp);
|
err = ovl_get_tmpfile(c, &temp);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
err = ovl_copy_up_inode(dentry, temp, lowerpath, stat);
|
err = ovl_copy_up_inode(c, temp);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_cleanup;
|
goto out_cleanup;
|
||||||
|
|
||||||
if (tmpfile) {
|
if (c->tmpfile) {
|
||||||
inode_lock_nested(udir, I_MUTEX_PARENT);
|
inode_lock_nested(udir, I_MUTEX_PARENT);
|
||||||
err = ovl_install_temp(workdir, upperdir, dentry, temp, pstat,
|
err = ovl_install_temp(c, temp, &newdentry);
|
||||||
tmpfile, &newdentry);
|
|
||||||
inode_unlock(udir);
|
inode_unlock(udir);
|
||||||
} else {
|
} else {
|
||||||
err = ovl_install_temp(workdir, upperdir, dentry, temp, pstat,
|
err = ovl_install_temp(c, temp, &newdentry);
|
||||||
tmpfile, &newdentry);
|
|
||||||
}
|
}
|
||||||
if (err)
|
if (err)
|
||||||
goto out_cleanup;
|
goto out_cleanup;
|
||||||
|
|
||||||
ovl_inode_update(d_inode(dentry), newdentry);
|
ovl_inode_update(d_inode(c->dentry), newdentry);
|
||||||
out:
|
out:
|
||||||
dput(temp);
|
dput(temp);
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
out_cleanup:
|
out_cleanup:
|
||||||
if (!tmpfile)
|
if (!c->tmpfile)
|
||||||
ovl_cleanup(wdir, temp);
|
ovl_cleanup(d_inode(c->workdir), temp);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,75 +492,70 @@ out_cleanup:
|
||||||
* is possible that the copy up will lock the old parent. At that point
|
* is possible that the copy up will lock the old parent. At that point
|
||||||
* the file will have already been copied up anyway.
|
* the file will have already been copied up anyway.
|
||||||
*/
|
*/
|
||||||
static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
|
static int ovl_copy_up_one(struct dentry *parent, struct ovl_copy_up_ctx *c)
|
||||||
struct path *lowerpath, struct kstat *stat)
|
|
||||||
{
|
{
|
||||||
DEFINE_DELAYED_CALL(done);
|
DEFINE_DELAYED_CALL(done);
|
||||||
struct dentry *workdir = ovl_workdir(dentry);
|
|
||||||
int err;
|
int err;
|
||||||
struct kstat pstat;
|
|
||||||
struct path parentpath;
|
struct path parentpath;
|
||||||
struct dentry *lowerdentry = lowerpath->dentry;
|
struct dentry *lowerdentry = c->lowerpath.dentry;
|
||||||
struct dentry *upperdir;
|
struct ovl_fs *ofs = c->dentry->d_sb->s_fs_info;
|
||||||
const char *link = NULL;
|
|
||||||
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
||||||
|
|
||||||
if (WARN_ON(!workdir))
|
c->workdir = ovl_workdir(c->dentry);
|
||||||
|
if (WARN_ON(!c->workdir))
|
||||||
return -EROFS;
|
return -EROFS;
|
||||||
|
|
||||||
ovl_do_check_copy_up(lowerdentry);
|
ovl_do_check_copy_up(lowerdentry);
|
||||||
|
|
||||||
ovl_path_upper(parent, &parentpath);
|
ovl_path_upper(parent, &parentpath);
|
||||||
upperdir = parentpath.dentry;
|
c->upperdir = parentpath.dentry;
|
||||||
|
|
||||||
/* Mark parent "impure" because it may now contain non-pure upper */
|
/* Mark parent "impure" because it may now contain non-pure upper */
|
||||||
err = ovl_set_impure(parent, upperdir);
|
err = ovl_set_impure(parent, c->upperdir);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = vfs_getattr(&parentpath, &pstat,
|
err = vfs_getattr(&parentpath, &c->pstat,
|
||||||
STATX_ATIME | STATX_MTIME, AT_STATX_SYNC_AS_STAT);
|
STATX_ATIME | STATX_MTIME, AT_STATX_SYNC_AS_STAT);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (S_ISLNK(stat->mode)) {
|
if (S_ISLNK(c->stat.mode)) {
|
||||||
link = vfs_get_link(lowerdentry, &done);
|
c->link = vfs_get_link(lowerdentry, &done);
|
||||||
if (IS_ERR(link))
|
if (IS_ERR(c->link))
|
||||||
return PTR_ERR(link);
|
return PTR_ERR(c->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should we copyup with O_TMPFILE or with workdir? */
|
/* Should we copyup with O_TMPFILE or with workdir? */
|
||||||
if (S_ISREG(stat->mode) && ofs->tmpfile) {
|
if (S_ISREG(c->stat.mode) && ofs->tmpfile) {
|
||||||
err = ovl_copy_up_start(dentry);
|
err = ovl_copy_up_start(c->dentry);
|
||||||
/* err < 0: interrupted, err > 0: raced with another copy-up */
|
/* err < 0: interrupted, err > 0: raced with another copy-up */
|
||||||
if (unlikely(err)) {
|
if (unlikely(err)) {
|
||||||
pr_debug("ovl_copy_up_start(%pd2) = %i\n", dentry, err);
|
pr_debug("ovl_copy_up_start(%pd2) = %i\n", c->dentry,
|
||||||
|
err);
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
err = 0;
|
err = 0;
|
||||||
goto out_done;
|
goto out_done;
|
||||||
}
|
}
|
||||||
|
c->tmpfile = true;
|
||||||
err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath,
|
err = ovl_copy_up_locked(c);
|
||||||
stat, link, &pstat, true);
|
ovl_copy_up_end(c->dentry);
|
||||||
ovl_copy_up_end(dentry);
|
|
||||||
goto out_done;
|
goto out_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = -EIO;
|
err = -EIO;
|
||||||
if (lock_rename(workdir, upperdir) != NULL) {
|
if (lock_rename(c->workdir, c->upperdir) != NULL) {
|
||||||
pr_err("overlayfs: failed to lock workdir+upperdir\n");
|
pr_err("overlayfs: failed to lock workdir+upperdir\n");
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
if (ovl_dentry_upper(dentry)) {
|
if (ovl_dentry_upper(c->dentry)) {
|
||||||
/* Raced with another copy-up? Nothing to do, then... */
|
/* Raced with another copy-up? Nothing to do, then... */
|
||||||
err = 0;
|
err = 0;
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath,
|
err = ovl_copy_up_locked(c);
|
||||||
stat, link, &pstat, false);
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
unlock_rename(workdir, upperdir);
|
unlock_rename(c->workdir, c->upperdir);
|
||||||
out_done:
|
out_done:
|
||||||
do_delayed_call(&done);
|
do_delayed_call(&done);
|
||||||
|
|
||||||
|
@ -575,8 +570,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags)
|
||||||
while (!err) {
|
while (!err) {
|
||||||
struct dentry *next;
|
struct dentry *next;
|
||||||
struct dentry *parent;
|
struct dentry *parent;
|
||||||
struct path lowerpath;
|
struct ovl_copy_up_ctx ctx = { };
|
||||||
struct kstat stat;
|
|
||||||
enum ovl_path_type type = ovl_path_type(dentry);
|
enum ovl_path_type type = ovl_path_type(dentry);
|
||||||
|
|
||||||
if (OVL_TYPE_UPPER(type))
|
if (OVL_TYPE_UPPER(type))
|
||||||
|
@ -595,14 +589,16 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags)
|
||||||
next = parent;
|
next = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
ovl_path_lower(next, &lowerpath);
|
ovl_path_lower(next, &ctx.lowerpath);
|
||||||
err = vfs_getattr(&lowerpath, &stat,
|
err = vfs_getattr(&ctx.lowerpath, &ctx.stat,
|
||||||
STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
|
STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
|
||||||
/* maybe truncate regular file. this has no effect on dirs */
|
/* maybe truncate regular file. this has no effect on dirs */
|
||||||
if (flags & O_TRUNC)
|
if (flags & O_TRUNC)
|
||||||
stat.size = 0;
|
ctx.stat.size = 0;
|
||||||
if (!err)
|
if (!err) {
|
||||||
err = ovl_copy_up_one(parent, next, &lowerpath, &stat);
|
ctx.dentry = next;
|
||||||
|
err = ovl_copy_up_one(parent, &ctx);
|
||||||
|
}
|
||||||
|
|
||||||
dput(parent);
|
dput(parent);
|
||||||
dput(next);
|
dput(next);
|
||||||
|
|
Loading…
Reference in New Issue