summaryrefslogtreecommitdiff
path: root/fs/overlayfs
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2017-05-16 01:26:49 +0300
committerMiklos Szeredi <mszeredi@redhat.com>2017-07-04 22:03:18 +0200
commit15932c415b3ed20bd1c1e05d071b4ad498656280 (patch)
tree9a5c7e198c8529323c57534720791e232a64ddb4 /fs/overlayfs
parentb9ac5c274b8c9d642567022c0e319bca4db31956 (diff)
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: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs')
-rw-r--r--fs/overlayfs/copy_up.c67
-rw-r--r--fs/overlayfs/util.c1
2 files changed, 38 insertions, 30 deletions
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 5e8fd99557e1..28711af7f9db 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -316,6 +316,35 @@ static int ovl_set_origin(struct dentry *dentry, struct dentry *lower,
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,
struct dentry *dentry, struct path *lowerpath,
struct kstat *stat, const char *link,
@@ -324,7 +353,6 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
struct inode *wdir = workdir->d_inode;
struct inode *udir = upperdir->d_inode;
struct dentry *newdentry = NULL;
- struct dentry *upper = NULL;
struct dentry *temp = NULL;
int err;
const struct cred *old_creds = NULL;
@@ -371,16 +399,7 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
BUG_ON(upperpath.dentry != NULL);
upperpath.dentry = temp;
- if (tmpfile) {
- 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);
- }
-
+ err = ovl_copy_up_data(lowerpath, &upperpath, stat->size);
if (err)
goto out_cleanup;
}
@@ -408,29 +427,21 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
goto out_cleanup;
}
- upper = lookup_one_len(dentry->d_name.name, upperdir,
- dentry->d_name.len);
- if (IS_ERR(upper)) {
- err = PTR_ERR(upper);
- upper = NULL;
- goto out_cleanup;
+ if (tmpfile) {
+ inode_lock_nested(udir, I_MUTEX_PARENT);
+ err = ovl_install_temp(workdir, upperdir, dentry, temp, pstat,
+ tmpfile, &newdentry);
+ inode_unlock(udir);
+ } 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)
goto out_cleanup;
- newdentry = dget(tmpfile ? upper : temp);
ovl_inode_update(d_inode(dentry), newdentry);
-
- /* Restore timestamps on parent (best effort) */
- ovl_set_timestamps(upperdir, pstat);
out:
dput(temp);
- dput(upper);
return err;
out_cleanup:
@@ -496,10 +507,8 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
goto out_done;
}
- inode_lock_nested(upperdir->d_inode, I_MUTEX_PARENT);
err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath,
stat, link, &pstat, true);
- inode_unlock(upperdir->d_inode);
ovl_copy_up_end(dentry);
goto out_done;
}
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 22ed51f80e58..c80b4bf1e64f 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -236,7 +236,6 @@ void ovl_inode_update(struct inode *inode, struct dentry *upperdentry)
{
struct inode *upperinode = d_inode(upperdentry);
- WARN_ON(!inode_is_locked(upperdentry->d_parent->d_inode));
WARN_ON(OVL_I(inode)->__upperdentry);
/*