mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
ovl: narrow locking in ovl_whiteout()
ovl_whiteout() relies on the workdir i_rwsem to provide exclusive access to ofs->whiteout which it manipulates. Rather than depending on this, add a new mutex, "whiteout_lock" to explicitly provide the required locking. Use guard(mutex) for this so that we can return without needing to explicitly unlock. Then take the lock on workdir only when needed - to lookup the temp name and to do the whiteout or link. Signed-off-by: NeilBrown <neil@brown.name> Link: https://lore.kernel.org/20250716004725.1206467-19-neil@brown.name Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
2fa14cf2dc
commit
8afa0a7367
3 changed files with 28 additions and 21 deletions
|
@ -84,41 +84,45 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)
|
||||||
struct dentry *workdir = ofs->workdir;
|
struct dentry *workdir = ofs->workdir;
|
||||||
struct inode *wdir = workdir->d_inode;
|
struct inode *wdir = workdir->d_inode;
|
||||||
|
|
||||||
inode_lock_nested(wdir, I_MUTEX_PARENT);
|
guard(mutex)(&ofs->whiteout_lock);
|
||||||
if (!ofs->whiteout) {
|
|
||||||
whiteout = ovl_lookup_temp(ofs, workdir);
|
|
||||||
if (IS_ERR(whiteout))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
|
if (!ofs->whiteout) {
|
||||||
|
inode_lock_nested(wdir, I_MUTEX_PARENT);
|
||||||
|
whiteout = ovl_lookup_temp(ofs, workdir);
|
||||||
|
if (!IS_ERR(whiteout)) {
|
||||||
err = ovl_do_whiteout(ofs, wdir, whiteout);
|
err = ovl_do_whiteout(ofs, wdir, whiteout);
|
||||||
if (err) {
|
if (err) {
|
||||||
dput(whiteout);
|
dput(whiteout);
|
||||||
whiteout = ERR_PTR(err);
|
whiteout = ERR_PTR(err);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
inode_unlock(wdir);
|
||||||
|
if (IS_ERR(whiteout))
|
||||||
|
return whiteout;
|
||||||
ofs->whiteout = whiteout;
|
ofs->whiteout = whiteout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ofs->no_shared_whiteout) {
|
if (!ofs->no_shared_whiteout) {
|
||||||
|
inode_lock_nested(wdir, I_MUTEX_PARENT);
|
||||||
whiteout = ovl_lookup_temp(ofs, workdir);
|
whiteout = ovl_lookup_temp(ofs, workdir);
|
||||||
if (IS_ERR(whiteout))
|
if (!IS_ERR(whiteout)) {
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = ovl_do_link(ofs, ofs->whiteout, wdir, whiteout);
|
err = ovl_do_link(ofs, ofs->whiteout, wdir, whiteout);
|
||||||
if (!err)
|
if (err) {
|
||||||
goto out;
|
dput(whiteout);
|
||||||
|
whiteout = ERR_PTR(err);
|
||||||
if (err != -EMLINK) {
|
}
|
||||||
|
}
|
||||||
|
inode_unlock(wdir);
|
||||||
|
if (!IS_ERR(whiteout))
|
||||||
|
return whiteout;
|
||||||
|
if (PTR_ERR(whiteout) != -EMLINK) {
|
||||||
pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n",
|
pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n",
|
||||||
ofs->whiteout->d_inode->i_nlink, err);
|
ofs->whiteout->d_inode->i_nlink, err);
|
||||||
ofs->no_shared_whiteout = true;
|
ofs->no_shared_whiteout = true;
|
||||||
}
|
}
|
||||||
dput(whiteout);
|
|
||||||
}
|
}
|
||||||
whiteout = ofs->whiteout;
|
whiteout = ofs->whiteout;
|
||||||
ofs->whiteout = NULL;
|
ofs->whiteout = NULL;
|
||||||
out:
|
|
||||||
inode_unlock(wdir);
|
|
||||||
return whiteout;
|
return whiteout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ struct ovl_fs {
|
||||||
/* Shared whiteout cache */
|
/* Shared whiteout cache */
|
||||||
struct dentry *whiteout;
|
struct dentry *whiteout;
|
||||||
bool no_shared_whiteout;
|
bool no_shared_whiteout;
|
||||||
|
struct mutex whiteout_lock;
|
||||||
/* r/o snapshot of upperdir sb's only taken on volatile mounts */
|
/* r/o snapshot of upperdir sb's only taken on volatile mounts */
|
||||||
errseq_t errseq;
|
errseq_t errseq;
|
||||||
};
|
};
|
||||||
|
|
|
@ -795,6 +795,8 @@ int ovl_init_fs_context(struct fs_context *fc)
|
||||||
fc->s_fs_info = ofs;
|
fc->s_fs_info = ofs;
|
||||||
fc->fs_private = ctx;
|
fc->fs_private = ctx;
|
||||||
fc->ops = &ovl_context_ops;
|
fc->ops = &ovl_context_ops;
|
||||||
|
|
||||||
|
mutex_init(&ofs->whiteout_lock);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_err:
|
out_err:
|
||||||
|
|
Loading…
Add table
Reference in a new issue