Commit e6d2ebdd authored by Miklos Szeredi's avatar Miklos Szeredi

ovl: simplify getting inode

Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 13cf199d
...@@ -462,18 +462,28 @@ static int ovl_inode_set(struct inode *inode, void *data) ...@@ -462,18 +462,28 @@ static int ovl_inode_set(struct inode *inode, void *data)
return 0; return 0;
} }
struct inode *ovl_get_inode(struct super_block *sb, struct inode *realinode) struct inode *ovl_get_inode(struct dentry *dentry)
{ {
struct dentry *upperdentry = ovl_dentry_upper(dentry);
struct inode *realinode = d_inode(ovl_dentry_real(dentry));
struct inode *inode; struct inode *inode;
inode = iget5_locked(sb, (unsigned long) realinode, if (upperdentry && !d_is_dir(upperdentry)) {
inode = iget5_locked(dentry->d_sb, (unsigned long) realinode,
ovl_inode_test, ovl_inode_set, realinode); ovl_inode_test, ovl_inode_set, realinode);
if (inode && inode->i_state & I_NEW) { if (!inode || !(inode->i_state & I_NEW))
ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev); goto out;
set_nlink(inode, realinode->i_nlink); set_nlink(inode, realinode->i_nlink);
unlock_new_inode(inode); } else {
inode = new_inode(dentry->d_sb);
if (!inode)
goto out;
} }
ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev);
ovl_inode_init(inode, dentry);
if (inode->i_state & I_NEW)
unlock_new_inode(inode);
out:
return inode; return inode;
} }
...@@ -433,41 +433,29 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, ...@@ -433,41 +433,29 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
if (!oe) if (!oe)
goto out_put; goto out_put;
if (upperdentry || ctr) { oe->opaque = upperopaque;
struct dentry *realdentry; oe->impure = upperimpure;
struct inode *realinode; oe->redirect = upperredirect;
oe->__upperdentry = upperdentry;
realdentry = upperdentry ? upperdentry : stack[0].dentry; memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr);
realinode = d_inode(realdentry); dentry->d_fsdata = oe;
if (upperdentry || ctr) {
err = -ENOMEM; err = -ENOMEM;
if (upperdentry && !d_is_dir(upperdentry)) { inode = ovl_get_inode(dentry);
inode = ovl_get_inode(dentry->d_sb, realinode);
} else {
inode = ovl_new_inode(dentry->d_sb, realinode->i_mode,
realinode->i_rdev);
if (inode)
ovl_inode_init(inode, realinode, !!upperdentry);
}
if (!inode) if (!inode)
goto out_free_oe; goto out_free_oe;
ovl_copyattr(realdentry->d_inode, inode);
} }
revert_creds(old_cred); revert_creds(old_cred);
oe->opaque = upperopaque;
oe->impure = upperimpure;
oe->redirect = upperredirect;
oe->__upperdentry = upperdentry;
memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr);
kfree(stack); kfree(stack);
kfree(d.redirect); kfree(d.redirect);
dentry->d_fsdata = oe;
d_add(dentry, inode); d_add(dentry, inode);
return NULL; return NULL;
out_free_oe: out_free_oe:
dentry->d_fsdata = NULL;
kfree(oe); kfree(oe);
out_put: out_put:
for (i = 0; i < ctr; i++) for (i = 0; i < ctr; i++)
......
...@@ -211,8 +211,7 @@ bool ovl_redirect_dir(struct super_block *sb); ...@@ -211,8 +211,7 @@ bool ovl_redirect_dir(struct super_block *sb);
const char *ovl_dentry_get_redirect(struct dentry *dentry); const char *ovl_dentry_get_redirect(struct dentry *dentry);
void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry); void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
void ovl_inode_init(struct inode *inode, struct inode *realinode, void ovl_inode_init(struct inode *inode, struct dentry *dentry);
bool is_upper);
void ovl_inode_update(struct inode *inode, struct inode *upperinode); void ovl_inode_update(struct inode *inode, struct inode *upperinode);
void ovl_dentry_version_inc(struct dentry *dentry); void ovl_dentry_version_inc(struct dentry *dentry);
u64 ovl_dentry_version_get(struct dentry *dentry); u64 ovl_dentry_version_get(struct dentry *dentry);
...@@ -262,7 +261,7 @@ int ovl_update_time(struct inode *inode, struct timespec *ts, int flags); ...@@ -262,7 +261,7 @@ int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);
bool ovl_is_private_xattr(const char *name); bool ovl_is_private_xattr(const char *name);
struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
struct inode *ovl_get_inode(struct super_block *sb, struct inode *realinode); struct inode *ovl_get_inode(struct dentry *dentry);
static inline void ovl_copyattr(struct inode *from, struct inode *to) static inline void ovl_copyattr(struct inode *from, struct inode *to)
{ {
to->i_uid = from->i_uid; to->i_uid = from->i_uid;
......
...@@ -757,7 +757,6 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -757,7 +757,6 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
struct path upperpath = { }; struct path upperpath = { };
struct path workpath = { }; struct path workpath = { };
struct dentry *root_dentry; struct dentry *root_dentry;
struct inode *realinode;
struct ovl_entry *oe; struct ovl_entry *oe;
struct ovl_fs *ufs; struct ovl_fs *ufs;
struct path *stack = NULL; struct path *stack = NULL;
...@@ -1009,9 +1008,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1009,9 +1008,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
root_dentry->d_fsdata = oe; root_dentry->d_fsdata = oe;
realinode = d_inode(ovl_dentry_real(root_dentry)); ovl_inode_init(d_inode(root_dentry), root_dentry);
ovl_inode_init(d_inode(root_dentry), realinode, !!upperpath.dentry);
ovl_copyattr(realinode, d_inode(root_dentry));
sb->s_root = root_dentry; sb->s_root = root_dentry;
......
...@@ -230,10 +230,15 @@ void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry) ...@@ -230,10 +230,15 @@ void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry)
oe->__upperdentry = upperdentry; oe->__upperdentry = upperdentry;
} }
void ovl_inode_init(struct inode *inode, struct inode *realinode, bool is_upper) void ovl_inode_init(struct inode *inode, struct dentry *dentry)
{ {
struct inode *realinode = d_inode(ovl_dentry_real(dentry));
bool is_upper = ovl_dentry_upper(dentry);
WRITE_ONCE(inode->i_private, (unsigned long) realinode | WRITE_ONCE(inode->i_private, (unsigned long) realinode |
(is_upper ? OVL_ISUPPER_MASK : 0)); (is_upper ? OVL_ISUPPER_MASK : 0));
ovl_copyattr(realinode, inode);
} }
void ovl_inode_update(struct inode *inode, struct inode *upperinode) void ovl_inode_update(struct inode *inode, struct inode *upperinode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment