Commit 0af950f5 authored by Amir Goldstein's avatar Amir Goldstein
Browse files

ovl: move ovl_entry into ovl_inode



The lower stacks of all the ovl inode aliases should be identical
and there is redundant information in ovl_entry and ovl_inode.

Move lowerstack into ovl_inode and keep only the OVL_E_FLAGS
per overlay dentry.

Following patches will deduplicate redundant ovl_inode fields.

Note that for pure upper and negative dentries, OVL_E(dentry) may be
NULL now, so it is imporatnt to use the ovl_numlower() accessor.

Reviewed-by: default avatarAlexander Larsson <alexl@redhat.com>
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 163db0da
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -269,7 +269,7 @@ static int ovl_instantiate(struct dentry *dentry, struct inode *inode,

	ovl_dir_modified(dentry->d_parent, false);
	ovl_dentry_set_upper_alias(dentry);
	ovl_dentry_init_reval(dentry, newdentry);
	ovl_dentry_init_reval(dentry, newdentry, NULL);

	if (!hardlink) {
		/*
+12 −10
Original line number Diff line number Diff line
@@ -286,7 +286,7 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
	struct dentry *lower = lowerpath ? lowerpath->dentry : NULL;
	struct dentry *upper = upper_alias ?: index;
	struct dentry *dentry;
	struct inode *inode;
	struct inode *inode = NULL;
	struct ovl_entry *oe;
	struct ovl_inode_params oip = {
		.lowerpath = lowerpath,
@@ -298,9 +298,19 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
	if (d_is_dir(upper ?: lower))
		return ERR_PTR(-EIO);

	oe = ovl_alloc_entry(!!lower);
	if (!oe)
		return ERR_PTR(-ENOMEM);

	oip.upperdentry = dget(upper);
	if (lower) {
		ovl_lowerstack(oe)->dentry = dget(lower);
		ovl_lowerstack(oe)->layer = lowerpath->layer;
	}
	oip.oe = oe;
	inode = ovl_get_inode(sb, &oip);
	if (IS_ERR(inode)) {
		ovl_free_entry(oe);
		dput(upper);
		return ERR_CAST(inode);
	}
@@ -315,19 +325,11 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
	dentry = d_alloc_anon(inode->i_sb);
	if (unlikely(!dentry))
		goto nomem;
	oe = ovl_alloc_entry(lower ? 1 : 0);
	if (!oe)
		goto nomem;

	if (lower) {
		ovl_lowerstack(oe)->dentry = dget(lower);
		ovl_lowerstack(oe)->layer = lowerpath->layer;
	}
	dentry->d_fsdata = oe;
	if (upper_alias)
		ovl_dentry_set_upper_alias(dentry);

	ovl_dentry_init_reval(dentry, upper);
	ovl_dentry_init_reval(dentry, upper, OVL_I_E(inode));

	return d_instantiate_anon(dentry, inode);

+4 −4
Original line number Diff line number Diff line
@@ -1002,8 +1002,9 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
	struct inode *realinode;
	struct ovl_inode *oi = OVL_I(inode);

	if (oip->upperdentry)
	oi->__upperdentry = oip->upperdentry;
	oi->oe = oip->oe;
	oi->redirect = oip->redirect;
	if (oip->lowerpath && oip->lowerpath->dentry) {
		oi->lowerpath.dentry = dget(oip->lowerpath->dentry);
		oi->lowerpath.layer = oip->lowerpath->layer;
@@ -1368,6 +1369,7 @@ struct inode *ovl_get_inode(struct super_block *sb,
			}

			dput(upperdentry);
			ovl_free_entry(oip->oe);
			kfree(oip->redirect);
			goto out;
		}
@@ -1397,8 +1399,6 @@ struct inode *ovl_get_inode(struct super_block *sb,
	if (oip->index)
		ovl_set_flag(OVL_INDEX, inode);

	OVL_I(inode)->redirect = oip->redirect;

	if (bylower)
		ovl_set_flag(OVL_CONST_INO, inode);

+10 −9
Original line number Diff line number Diff line
@@ -831,7 +831,7 @@ static int ovl_fix_origin(struct ovl_fs *ofs, struct dentry *dentry,
struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
			  unsigned int flags)
{
	struct ovl_entry *oe;
	struct ovl_entry *oe = NULL;
	const struct cred *old_cred;
	struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
	struct ovl_entry *poe = OVL_E(dentry->d_parent);
@@ -1067,13 +1067,14 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
		}
	}

	if (ctr) {
		oe = ovl_alloc_entry(ctr);
		err = -ENOMEM;
		if (!oe)
			goto out_put;

		ovl_stack_cpy(ovl_lowerstack(oe), stack, ctr);
	dentry->d_fsdata = oe;
	}

	if (upperopaque)
		ovl_dentry_set_opaque(dentry);
@@ -1107,6 +1108,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
		struct ovl_inode_params oip = {
			.upperdentry = upperdentry,
			.lowerpath = stack,
			.oe = oe,
			.index = index,
			.numlower = ctr,
			.redirect = upperredirect,
@@ -1122,7 +1124,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
			ovl_set_flag(OVL_UPPERDATA, inode);
	}

	ovl_dentry_init_reval(dentry, upperdentry);
	ovl_dentry_init_reval(dentry, upperdentry, OVL_I_E(inode));

	revert_creds(old_cred);
	if (origin_path) {
@@ -1135,7 +1137,6 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
	return d_splice_alias(inode, dentry);

out_free_oe:
	dentry->d_fsdata = NULL;
	ovl_free_entry(oe);
out_put:
	dput(index);
+4 −2
Original line number Diff line number Diff line
@@ -381,9 +381,10 @@ struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
void ovl_free_entry(struct ovl_entry *oe);
bool ovl_dentry_remote(struct dentry *dentry);
void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *realdentry);
void ovl_dentry_init_reval(struct dentry *dentry, struct dentry *upperdentry);
void ovl_dentry_init_reval(struct dentry *dentry, struct dentry *upperdentry,
			   struct ovl_entry *oe);
void ovl_dentry_init_flags(struct dentry *dentry, struct dentry *upperdentry,
			   unsigned int mask);
			   struct ovl_entry *oe, unsigned int mask);
bool ovl_dentry_weird(struct dentry *dentry);
enum ovl_path_type ovl_path_type(struct dentry *dentry);
void ovl_path_upper(struct dentry *dentry, struct path *path);
@@ -653,6 +654,7 @@ struct ovl_inode_params {
	struct inode *newinode;
	struct dentry *upperdentry;
	struct ovl_path *lowerpath;
	struct ovl_entry *oe;
	bool index;
	unsigned int numlower;
	char *redirect;
Loading