Skip to content

Commit 01ad3eb

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: concurrent copy up of regular files
Now that copy up of regular file is done using O_TMPFILE, we don't need to hold rename_lock throughout copy up. Use the copy up waitqueue to synchronize concurrent copy up of the same file. Different regular files can be copied up concurrently. The upper dir inode_lock is taken instead of rename_lock, because it is needed for lookup and later for linking the temp file, but it is released while copying up data. Suggested-by: Al Viro <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 39d3d60 commit 01ad3eb

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

fs/overlayfs/copy_up.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,16 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
291291
BUG_ON(upperpath.dentry != NULL);
292292
upperpath.dentry = temp;
293293

294-
err = ovl_copy_up_data(lowerpath, &upperpath, stat->size);
294+
if (tmpfile) {
295+
inode_unlock(udir);
296+
err = ovl_copy_up_data(lowerpath, &upperpath,
297+
stat->size);
298+
inode_lock_nested(udir, I_MUTEX_PARENT);
299+
} else {
300+
err = ovl_copy_up_data(lowerpath, &upperpath,
301+
stat->size);
302+
}
303+
295304
if (err)
296305
goto out_cleanup;
297306
}
@@ -353,8 +362,6 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
353362
struct dentry *upperdir;
354363
const char *link = NULL;
355364
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
356-
/* Should we copyup with O_TMPFILE or with workdir? */
357-
bool tmpfile = S_ISREG(stat->mode) && ofs->tmpfile;
358365

359366
if (WARN_ON(!workdir))
360367
return -EROFS;
@@ -374,6 +381,25 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
374381
return PTR_ERR(link);
375382
}
376383

384+
/* Should we copyup with O_TMPFILE or with workdir? */
385+
if (S_ISREG(stat->mode) && ofs->tmpfile) {
386+
err = ovl_copy_up_start(dentry);
387+
/* err < 0: interrupted, err > 0: raced with another copy-up */
388+
if (unlikely(err)) {
389+
pr_debug("ovl_copy_up_start(%pd2) = %i\n", dentry, err);
390+
if (err > 0)
391+
err = 0;
392+
goto out_done;
393+
}
394+
395+
inode_lock_nested(upperdir->d_inode, I_MUTEX_PARENT);
396+
err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath,
397+
stat, link, &pstat, true);
398+
inode_unlock(upperdir->d_inode);
399+
ovl_copy_up_end(dentry);
400+
goto out_done;
401+
}
402+
377403
err = -EIO;
378404
if (lock_rename(workdir, upperdir) != NULL) {
379405
pr_err("overlayfs: failed to lock workdir+upperdir\n");
@@ -386,9 +412,10 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
386412
}
387413

388414
err = ovl_copy_up_locked(workdir, upperdir, dentry, lowerpath,
389-
stat, link, &pstat, tmpfile);
415+
stat, link, &pstat, false);
390416
out_unlock:
391417
unlock_rename(workdir, upperdir);
418+
out_done:
392419
do_delayed_call(&done);
393420

394421
return err;

0 commit comments

Comments
 (0)