Commit 15932c41 authored by Amir Goldstein's avatar Amir Goldstein Committed by Miklos Szeredi

ovl: defer upper dir lock to tempfile link

On copy up of regular file using an O_TMPFILE, lock upper dir only
before linking the tempfile in place.
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent b9ac5c27
...@@ -316,6 +316,35 @@ static int ovl_set_origin(struct dentry *dentry, struct dentry *lower, ...@@ -316,6 +316,35 @@ 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 dentry *dentry,
struct dentry *temp, struct kstat *pstat,
bool tmpfile, struct dentry **newdentry)
{
int err;
struct dentry *upper;
struct inode *udir = d_inode(upperdir);
upper = lookup_one_len(dentry->d_name.name, upperdir,
dentry->d_name.len);
if (IS_ERR(upper))
return PTR_ERR(upper);
if (tmpfile)
err = ovl_do_link(temp, udir, upper, true);
else
err = ovl_do_rename(d_inode(workdir), temp, udir, upper, 0);
/* Restore timestamps on parent (best effort) */
if (!err) {
ovl_set_timestamps(upperdir, pstat);
*newdentry = dget(tmpfile ? upper : temp);
}
dput(upper);
return err;
}
static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
struct dentry *dentry, struct path *lowerpath, struct dentry *dentry, struct path *lowerpath,
struct kstat *stat, const char *link, struct kstat *stat, const char *link,
...@@ -324,7 +353,6 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -324,7 +353,6 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
struct inode *wdir = workdir->d_inode; struct inode *wdir = workdir->d_inode;
struct inode *udir = upperdir->d_inode; struct inode *udir = upperdir->d_inode;
struct dentry *newdentry = NULL; struct dentry *newdentry = NULL;
struct dentry *upper = NULL;
struct dentry *temp = NULL; struct dentry *temp = NULL;
int err; int err;
const struct cred *old_creds = NULL; const struct cred *old_creds = NULL;
...@@ -371,16 +399,7 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -371,16 +399,7 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
BUG_ON(upperpath.dentry != NULL); BUG_ON(upperpath.dentry != NULL);
upperpath.dentry = temp; upperpath.dentry = temp;
if (tmpfile) { err = ovl_copy_up_data(lowerpath, &upperpath, stat->size);
inode_unlock(udir);
err = ovl_copy_up_data(lowerpath, &upperpath,
stat->size);
inode_lock_nested(udir, I_MUTEX_PARENT);
} else {
err = ovl_copy_up_data(lowerpath, &upperpath,
stat->size);
}
if (err) if (err)
goto out_cleanup; goto out_cleanup;
} }
...@@ -408,29 +427,21 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -408,29 +427,21 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
goto out_cleanup; goto out_cleanup;
} }
upper = lookup_one_len(dentry->d_name.name, upperdir, if (tmpfile) {
dentry->d_name.len); inode_lock_nested(udir, I_MUTEX_PARENT);
if (IS_ERR(upper)) { err = ovl_install_temp(workdir, upperdir, dentry, temp, pstat,
err = PTR_ERR(upper); tmpfile, &newdentry);
upper = NULL; inode_unlock(udir);
goto out_cleanup; } else {
err = ovl_install_temp(workdir, upperdir, dentry, temp, pstat,
tmpfile, &newdentry);
} }
if (tmpfile)
err = ovl_do_link(temp, udir, upper, true);
else
err = ovl_do_rename(wdir, temp, udir, upper, 0);
if (err) if (err)
goto out_cleanup; goto out_cleanup;
newdentry = dget(tmpfile ? upper : temp);
ovl_inode_update(d_inode(dentry), newdentry); ovl_inode_update(d_inode(dentry), newdentry);
/* Restore timestamps on parent (best effort) */
ovl_set_timestamps(upperdir, pstat);
out: out:
dput(temp); dput(temp);
dput(upper);
return err; return err;
out_cleanup: out_cleanup:
...@@ -496,10 +507,8 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, ...@@ -496,10 +507,8 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
goto out_done; goto out_done;
} }
inode_lock_nested(upperdir->d_inode, I_MUTEX_PARENT);
err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath, err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath,
stat, link, &pstat, true); stat, link, &pstat, true);
inode_unlock(upperdir->d_inode);
ovl_copy_up_end(dentry); ovl_copy_up_end(dentry);
goto out_done; goto out_done;
} }
......
...@@ -236,7 +236,6 @@ void ovl_inode_update(struct inode *inode, struct dentry *upperdentry) ...@@ -236,7 +236,6 @@ void ovl_inode_update(struct inode *inode, struct dentry *upperdentry)
{ {
struct inode *upperinode = d_inode(upperdentry); struct inode *upperinode = d_inode(upperdentry);
WARN_ON(!inode_is_locked(upperdentry->d_parent->d_inode));
WARN_ON(OVL_I(inode)->__upperdentry); WARN_ON(OVL_I(inode)->__upperdentry);
/* /*
......
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