ovl: struct cattr cleanups

* Rename to ovl_cattr

* Fold ovl_create_real() hardlink argument into struct ovl_cattr

* Create macro OVL_CATTR() to initialize struct ovl_cattr from mode

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
Amir Goldstein 2018-05-16 17:35:02 +03:00 committed by Miklos Szeredi
parent 6cf00764b0
commit 471ec5dcf4
4 changed files with 30 additions and 33 deletions

View File

@ -486,7 +486,7 @@ static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp)
struct dentry *temp; struct dentry *temp;
const struct cred *old_creds = NULL; const struct cred *old_creds = NULL;
struct cred *new_creds = NULL; struct cred *new_creds = NULL;
struct cattr cattr = { struct ovl_cattr cattr = {
/* Can't properly set mode on creation because of the umask */ /* Can't properly set mode on creation because of the umask */
.mode = c->stat.mode & S_IFMT, .mode = c->stat.mode & S_IFMT,
.rdev = c->stat.rdev, .rdev = c->stat.rdev,
@ -509,8 +509,7 @@ static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp)
if (IS_ERR(temp)) if (IS_ERR(temp))
goto temp_err; goto temp_err;
err = ovl_create_real(d_inode(c->workdir), temp, &cattr, err = ovl_create_real(d_inode(c->workdir), temp, &cattr);
NULL);
if (err) { if (err) {
dput(temp); dput(temp);
goto out; goto out;

View File

@ -115,15 +115,15 @@ int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir,
} }
int ovl_create_real(struct inode *dir, struct dentry *newdentry, int ovl_create_real(struct inode *dir, struct dentry *newdentry,
struct cattr *attr, struct dentry *hardlink) struct ovl_cattr *attr)
{ {
int err; int err;
if (newdentry->d_inode) if (newdentry->d_inode)
return -ESTALE; return -ESTALE;
if (hardlink) { if (attr->hardlink) {
err = ovl_do_link(hardlink, dir, newdentry); err = ovl_do_link(attr->hardlink, dir, newdentry);
} else { } else {
switch (attr->mode & S_IFMT) { switch (attr->mode & S_IFMT) {
case S_IFREG: case S_IFREG:
@ -213,14 +213,14 @@ static bool ovl_type_origin(struct dentry *dentry)
} }
static int ovl_create_upper(struct dentry *dentry, struct inode *inode, static int ovl_create_upper(struct dentry *dentry, struct inode *inode,
struct cattr *attr, struct dentry *hardlink) struct ovl_cattr *attr)
{ {
struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent);
struct inode *udir = upperdir->d_inode; struct inode *udir = upperdir->d_inode;
struct dentry *newdentry; struct dentry *newdentry;
int err; int err;
if (!hardlink && !IS_POSIXACL(udir)) if (!attr->hardlink && !IS_POSIXACL(udir))
attr->mode &= ~current_umask(); attr->mode &= ~current_umask();
inode_lock_nested(udir, I_MUTEX_PARENT); inode_lock_nested(udir, I_MUTEX_PARENT);
@ -229,7 +229,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,
err = PTR_ERR(newdentry); err = PTR_ERR(newdentry);
if (IS_ERR(newdentry)) if (IS_ERR(newdentry))
goto out_unlock; goto out_unlock;
err = ovl_create_real(udir, newdentry, attr, hardlink); err = ovl_create_real(udir, newdentry, attr);
if (err) if (err)
goto out_dput; goto out_dput;
@ -238,7 +238,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,
ovl_set_opaque(dentry, newdentry); ovl_set_opaque(dentry, newdentry);
} }
ovl_instantiate(dentry, inode, newdentry, !!hardlink); ovl_instantiate(dentry, inode, newdentry, !!attr->hardlink);
newdentry = NULL; newdentry = NULL;
out_dput: out_dput:
dput(newdentry); dput(newdentry);
@ -285,8 +285,7 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry,
if (IS_ERR(opaquedir)) if (IS_ERR(opaquedir))
goto out_unlock; goto out_unlock;
err = ovl_create_real(wdir, opaquedir, err = ovl_create_real(wdir, opaquedir, OVL_CATTR(stat.mode));
&(struct cattr){.mode = stat.mode}, NULL);
if (err) if (err)
goto out_dput; goto out_dput;
@ -354,8 +353,7 @@ static int ovl_set_upper_acl(struct dentry *upperdentry, const char *name,
} }
static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
struct cattr *cattr, struct ovl_cattr *cattr)
struct dentry *hardlink)
{ {
struct dentry *workdir = ovl_workdir(dentry); struct dentry *workdir = ovl_workdir(dentry);
struct inode *wdir = workdir->d_inode; struct inode *wdir = workdir->d_inode;
@ -365,6 +363,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
struct dentry *newdentry; struct dentry *newdentry;
int err; int err;
struct posix_acl *acl, *default_acl; struct posix_acl *acl, *default_acl;
bool hardlink = !!cattr->hardlink;
if (WARN_ON(!workdir)) if (WARN_ON(!workdir))
return -EROFS; return -EROFS;
@ -391,7 +390,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
if (IS_ERR(upper)) if (IS_ERR(upper))
goto out_dput; goto out_dput;
err = ovl_create_real(wdir, newdentry, cattr, hardlink); err = ovl_create_real(wdir, newdentry, cattr);
if (err) if (err)
goto out_dput2; goto out_dput2;
@ -439,7 +438,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
if (err) if (err)
goto out_cleanup; goto out_cleanup;
} }
ovl_instantiate(dentry, inode, newdentry, !!hardlink); ovl_instantiate(dentry, inode, newdentry, hardlink);
newdentry = NULL; newdentry = NULL;
out_dput2: out_dput2:
dput(upper); dput(upper);
@ -460,8 +459,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
} }
static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
struct cattr *attr, struct dentry *hardlink, struct ovl_cattr *attr, bool origin)
bool origin)
{ {
int err; int err;
const struct cred *old_cred; const struct cred *old_cred;
@ -489,7 +487,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
if (override_cred) { if (override_cred) {
override_cred->fsuid = inode->i_uid; override_cred->fsuid = inode->i_uid;
override_cred->fsgid = inode->i_gid; override_cred->fsgid = inode->i_gid;
if (!hardlink) { if (!attr->hardlink) {
err = security_dentry_create_files_as(dentry, err = security_dentry_create_files_as(dentry,
attr->mode, &dentry->d_name, old_cred, attr->mode, &dentry->d_name, old_cred,
override_cred); override_cred);
@ -502,11 +500,9 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
put_cred(override_cred); put_cred(override_cred);
if (!ovl_dentry_is_whiteout(dentry)) if (!ovl_dentry_is_whiteout(dentry))
err = ovl_create_upper(dentry, inode, attr, err = ovl_create_upper(dentry, inode, attr);
hardlink);
else else
err = ovl_create_over_whiteout(dentry, inode, attr, err = ovl_create_over_whiteout(dentry, inode, attr);
hardlink);
} }
out_revert_creds: out_revert_creds:
revert_creds(old_cred); revert_creds(old_cred);
@ -518,7 +514,7 @@ static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev,
{ {
int err; int err;
struct inode *inode; struct inode *inode;
struct cattr attr = { struct ovl_cattr attr = {
.rdev = rdev, .rdev = rdev,
.link = link, .link = link,
}; };
@ -535,7 +531,7 @@ static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev,
inode_init_owner(inode, dentry->d_parent->d_inode, mode); inode_init_owner(inode, dentry->d_parent->d_inode, mode);
attr.mode = inode->i_mode; attr.mode = inode->i_mode;
err = ovl_create_or_link(dentry, inode, &attr, NULL, false); err = ovl_create_or_link(dentry, inode, &attr, false);
if (err) if (err)
iput(inode); iput(inode);
@ -594,8 +590,9 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
inode = d_inode(old); inode = d_inode(old);
ihold(inode); ihold(inode);
err = ovl_create_or_link(new, inode, NULL, ovl_dentry_upper(old), err = ovl_create_or_link(new, inode,
ovl_type_origin(old)); &(struct ovl_cattr) {.hardlink = ovl_dentry_upper(old)},
ovl_type_origin(old));
if (err) if (err)
iput(inode); iput(inode);

View File

@ -349,14 +349,17 @@ extern const struct inode_operations ovl_dir_inode_operations;
struct dentry *ovl_lookup_temp(struct dentry *workdir); struct dentry *ovl_lookup_temp(struct dentry *workdir);
int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir,
struct dentry *dentry); struct dentry *dentry);
struct cattr { struct ovl_cattr {
dev_t rdev; dev_t rdev;
umode_t mode; umode_t mode;
const char *link; const char *link;
struct dentry *hardlink;
}; };
#define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
int ovl_create_real(struct inode *dir, struct dentry *newdentry, int ovl_create_real(struct inode *dir, struct dentry *newdentry,
struct cattr *attr, struct ovl_cattr *attr);
struct dentry *hardlink);
int ovl_cleanup(struct inode *dir, struct dentry *dentry); int ovl_cleanup(struct inode *dir, struct dentry *dentry);
/* copy_up.c */ /* copy_up.c */

View File

@ -611,9 +611,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
goto retry; goto retry;
} }
err = ovl_create_real(dir, work, err = ovl_create_real(dir, work, OVL_CATTR(attr.ia_mode));
&(struct cattr){.mode = S_IFDIR | 0},
NULL);
if (err) if (err)
goto out_dput; goto out_dput;