Reflow the creation routine in preparation of porting it to a guard. Signed-off-by: Christian Brauner --- fs/overlayfs/dir.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index a276eafb5e78..ff30a91e07f8 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -644,14 +644,23 @@ static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry, return override_cred; } +static int do_ovl_create_or_link(struct dentry *dentry, struct inode *inode, + struct ovl_cattr *attr) +{ + if (!ovl_dentry_is_whiteout(dentry)) + return ovl_create_upper(dentry, inode, attr); + + return ovl_create_over_whiteout(dentry, inode, attr); +} + static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, struct ovl_cattr *attr, bool origin) { int err; - const struct cred *new_cred __free(put_cred) = NULL; struct dentry *parent = dentry->d_parent; scoped_class(override_creds_ovl, old_cred, dentry->d_sb) { + const struct cred *new_cred __free(put_cred) = NULL; /* * When linking a file with copy up origin into a new parent, mark the * new parent dir "impure". @@ -662,7 +671,6 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, return err; } - if (!attr->hardlink) { /* * In the creation cases(create, mkdir, mknod, symlink), * ovl should transfer current's fs{u,g}id to underlying @@ -676,16 +684,15 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, * create a new inode, so just use the ovl mounter's * fs{u,g}id. */ + + if (attr->hardlink) + return do_ovl_create_or_link(dentry, inode, attr); + new_cred = ovl_setup_cred_for_create(dentry, inode, attr->mode, old_cred); if (IS_ERR(new_cred)) return PTR_ERR(new_cred); - } - - if (!ovl_dentry_is_whiteout(dentry)) - return ovl_create_upper(dentry, inode, attr); - - return ovl_create_over_whiteout(dentry, inode, attr); + return do_ovl_create_or_link(dentry, inode, attr); } return err; } -- 2.47.3