goto out_cleanup;
newdentry = dget(tmpfile ? upper : temp);
- ovl_dentry_update(dentry, newdentry);
- ovl_inode_update(d_inode(dentry), d_inode(newdentry));
+ ovl_inode_update(d_inode(dentry), newdentry);
/* Restore timestamps on parent (best effort) */
ovl_set_timestamps(upperdir, pstat);
struct dentry *newdentry, bool hardlink)
{
ovl_dentry_version_inc(dentry->d_parent);
- ovl_dentry_update(dentry, newdentry);
if (!hardlink) {
- ovl_inode_update(inode, d_inode(newdentry));
+ ovl_inode_update(inode, newdentry);
ovl_copyattr(newdentry->d_inode, inode);
} else {
- WARN_ON(ovl_inode_real(inode, NULL) != d_inode(newdentry));
+ WARN_ON(ovl_inode_real(inode) != d_inode(newdentry));
+ dput(newdentry);
inc_nlink(inode);
}
d_instantiate(dentry, inode);
new_opaque = ovl_dentry_is_opaque(new);
err = -ESTALE;
- if (ovl_dentry_upper(new)) {
+ if (d_inode(new) && ovl_dentry_upper(new)) {
if (opaquedir) {
if (newdentry != opaquedir)
goto out_dput;
int ovl_permission(struct inode *inode, int mask)
{
- bool is_upper;
- struct inode *realinode = ovl_inode_real(inode, &is_upper);
+ struct inode *upperinode = ovl_inode_upper(inode);
+ struct inode *realinode = upperinode ?: ovl_inode_lower(inode);
const struct cred *old_cred;
int err;
return err;
old_cred = ovl_override_creds(inode->i_sb);
- if (!is_upper && !special_file(realinode->i_mode) && mask & MAY_WRITE) {
+ if (!upperinode &&
+ !special_file(realinode->i_mode) && mask & MAY_WRITE) {
mask &= ~(MAY_WRITE | MAY_APPEND);
/* Make sure mounter can read file for copy up later */
mask |= MAY_READ;
struct posix_acl *ovl_get_acl(struct inode *inode, int type)
{
- struct inode *realinode = ovl_inode_real(inode, NULL);
+ struct inode *realinode = ovl_inode_real(inode);
const struct cred *old_cred;
struct posix_acl *acl;
return 0;
}
-struct inode *ovl_get_inode(struct dentry *dentry)
+struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry)
{
- struct dentry *upperdentry = ovl_dentry_upper(dentry);
- struct inode *realinode = d_inode(ovl_dentry_real(dentry));
+ struct dentry *lowerdentry = ovl_dentry_lower(dentry);
+ struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL;
struct inode *inode;
+ if (!realinode)
+ realinode = d_inode(lowerdentry);
+
if (upperdentry && !d_is_dir(upperdentry)) {
inode = iget5_locked(dentry->d_sb, (unsigned long) realinode,
ovl_inode_test, ovl_inode_set, realinode);
- if (!inode || !(inode->i_state & I_NEW))
+ if (!inode)
goto out;
+ if (!(inode->i_state & I_NEW)) {
+ dput(upperdentry);
+ goto out;
+ }
set_nlink(inode, realinode->i_nlink);
} else {
goto out;
}
ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev);
- ovl_inode_init(inode, dentry);
+ ovl_inode_init(inode, upperdentry, lowerdentry);
if (inode->i_state & I_NEW)
unlock_new_inode(inode);
out:
return ERR_PTR(-ENAMETOOLONG);
old_cred = ovl_override_creds(dentry->d_sb);
- upperdir = ovl_upperdentry_dereference(poe);
+ upperdir = ovl_dentry_upper(dentry->d_parent);
if (upperdir) {
err = ovl_lookup_layer(upperdir, &d, &upperdentry);
if (err)
oe->opaque = upperopaque;
oe->impure = upperimpure;
oe->redirect = upperredirect;
- oe->__upperdentry = upperdentry;
memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr);
dentry->d_fsdata = oe;
if (upperdentry || ctr) {
err = -ENOMEM;
- inode = ovl_get_inode(dentry);
+ inode = ovl_get_inode(dentry, upperdentry);
if (!inode)
goto out_free_oe;
}
return oe->opaque;
/* Negative upper -> positive lower */
- if (!oe->__upperdentry)
+ if (!ovl_dentry_upper(dentry))
return true;
/* Positive upper -> have to look up lower to see whether it exists */
struct dentry *ovl_dentry_upper(struct dentry *dentry);
struct dentry *ovl_dentry_lower(struct dentry *dentry);
struct dentry *ovl_dentry_real(struct dentry *dentry);
-struct inode *ovl_inode_real(struct inode *inode, bool *is_upper);
+struct inode *ovl_inode_upper(struct inode *inode);
+struct inode *ovl_inode_lower(struct inode *inode);
+struct inode *ovl_inode_real(struct inode *inode);
struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry);
void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache);
bool ovl_dentry_is_opaque(struct dentry *dentry);
bool ovl_redirect_dir(struct super_block *sb);
const char *ovl_dentry_get_redirect(struct dentry *dentry);
void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
-void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
-void ovl_inode_init(struct inode *inode, struct dentry *dentry);
-void ovl_inode_update(struct inode *inode, struct inode *upperinode);
+void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
+ struct dentry *lowerdentry);
+void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
void ovl_dentry_version_inc(struct dentry *dentry);
u64 ovl_dentry_version_get(struct dentry *dentry);
bool ovl_is_whiteout(struct dentry *dentry);
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_get_inode(struct dentry *dentry);
+struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry);
static inline void ovl_copyattr(struct inode *from, struct inode *to)
{
to->i_uid = from->i_uid;
/* private information held for every overlayfs dentry */
struct ovl_entry {
- struct dentry *__upperdentry;
struct ovl_dir_cache *cache;
union {
struct {
struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
-static inline struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe)
-{
- return lockless_dereference(oe->__upperdentry);
-}
-
struct ovl_inode {
struct inode vfs_inode;
- struct inode *upper;
+ struct dentry *__upperdentry;
struct inode *lower;
};
{
return container_of(inode, struct ovl_inode, vfs_inode);
}
+
+static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
+{
+ return lockless_dereference(oi->__upperdentry);
+}
if (oe) {
unsigned int i;
- dput(oe->__upperdentry);
kfree(oe->redirect);
for (i = 0; i < oe->numlower; i++)
dput(oe->lowerstack[i].dentry);
{
struct ovl_inode *oi = kmem_cache_alloc(ovl_inode_cachep, GFP_KERNEL);
- oi->upper = NULL;
+ oi->__upperdentry = NULL;
oi->lower = NULL;
return &oi->vfs_inode;
static void ovl_destroy_inode(struct inode *inode)
{
+ struct ovl_inode *oi = OVL_I(inode);
+
+ dput(oi->__upperdentry);
+
call_rcu(&inode->i_rcu, ovl_i_callback);
}
size_t size, int flags)
{
struct dentry *workdir = ovl_workdir(dentry);
- struct inode *realinode = ovl_inode_real(inode, NULL);
+ struct inode *realinode = ovl_inode_real(inode);
struct posix_acl *acl = NULL;
int err;
err = ovl_xattr_set(dentry, handler->name, value, size, flags);
if (!err)
- ovl_copyattr(ovl_inode_real(inode, NULL), inode);
+ ovl_copyattr(ovl_inode_real(inode), inode);
return err;
kfree(lowertmp);
if (upperpath.dentry) {
- oe->__upperdentry = upperpath.dentry;
oe->impure = ovl_is_impuredir(upperpath.dentry);
}
for (i = 0; i < numlower; i++) {
root_dentry->d_fsdata = oe;
- ovl_inode_init(d_inode(root_dentry), root_dentry);
+ ovl_inode_init(d_inode(root_dentry), upperpath.dentry,
+ ovl_dentry_lower(root_dentry));
sb->s_root = root_dentry;
struct ovl_entry *oe = dentry->d_fsdata;
enum ovl_path_type type = 0;
- if (oe->__upperdentry) {
+ if (ovl_dentry_upper(dentry)) {
type = __OVL_PATH_UPPER;
/*
void ovl_path_upper(struct dentry *dentry, struct path *path)
{
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
- struct ovl_entry *oe = dentry->d_fsdata;
path->mnt = ofs->upper_mnt;
- path->dentry = ovl_upperdentry_dereference(oe);
+ path->dentry = ovl_dentry_upper(dentry);
}
void ovl_path_lower(struct dentry *dentry, struct path *path)
struct dentry *ovl_dentry_upper(struct dentry *dentry)
{
- struct ovl_entry *oe = dentry->d_fsdata;
-
- return ovl_upperdentry_dereference(oe);
-}
-
-static struct dentry *__ovl_dentry_lower(struct ovl_entry *oe)
-{
- return oe->numlower ? oe->lowerstack[0].dentry : NULL;
+ return ovl_upperdentry_dereference(OVL_I(d_inode(dentry)));
}
struct dentry *ovl_dentry_lower(struct dentry *dentry)
{
struct ovl_entry *oe = dentry->d_fsdata;
- return __ovl_dentry_lower(oe);
+ return oe->numlower ? oe->lowerstack[0].dentry : NULL;
}
struct dentry *ovl_dentry_real(struct dentry *dentry)
{
- struct ovl_entry *oe = dentry->d_fsdata;
- struct dentry *realdentry;
-
- realdentry = ovl_upperdentry_dereference(oe);
- if (!realdentry)
- realdentry = __ovl_dentry_lower(oe);
-
- return realdentry;
+ return ovl_dentry_upper(dentry) ?: ovl_dentry_lower(dentry);
}
-struct inode *ovl_inode_real(struct inode *inode, bool *is_upper)
+struct inode *ovl_inode_upper(struct inode *inode)
{
- struct inode *realinode = lockless_dereference(OVL_I(inode)->upper);
- bool isup = false;
+ struct dentry *upperdentry = ovl_upperdentry_dereference(OVL_I(inode));
- if (!realinode)
- realinode = OVL_I(inode)->lower;
- else
- isup = true;
+ return upperdentry ? d_inode(upperdentry) : NULL;
+}
- if (is_upper)
- *is_upper = isup;
+struct inode *ovl_inode_lower(struct inode *inode)
+{
+ return OVL_I(inode)->lower;
+}
- return realinode;
+struct inode *ovl_inode_real(struct inode *inode)
+{
+ return ovl_inode_upper(inode) ?: ovl_inode_lower(inode);
}
+
struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry)
{
struct ovl_entry *oe = dentry->d_fsdata;
oe->redirect = redirect;
}
-void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry)
+void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
+ struct dentry *lowerdentry)
{
- struct ovl_entry *oe = dentry->d_fsdata;
+ if (upperdentry)
+ OVL_I(inode)->__upperdentry = upperdentry;
+ if (lowerdentry)
+ OVL_I(inode)->lower = d_inode(lowerdentry);
- WARN_ON(!inode_is_locked(upperdentry->d_parent->d_inode));
- WARN_ON(oe->__upperdentry);
- /*
- * Make sure upperdentry is consistent before making it visible to
- * ovl_upperdentry_dereference().
- */
- smp_wmb();
- oe->__upperdentry = upperdentry;
+ ovl_copyattr(d_inode(upperdentry ?: lowerdentry), inode);
}
-void ovl_inode_init(struct inode *inode, struct dentry *dentry)
+void ovl_inode_update(struct inode *inode, struct dentry *upperdentry)
{
- struct inode *realinode = d_inode(ovl_dentry_real(dentry));
+ struct inode *upperinode = d_inode(upperdentry);
- if (ovl_dentry_upper(dentry))
- OVL_I(inode)->upper = realinode;
- else
- OVL_I(inode)->lower = realinode;
-
- ovl_copyattr(realinode, inode);
-}
-
-void ovl_inode_update(struct inode *inode, struct inode *upperinode)
-{
- WARN_ON(!upperinode);
WARN_ON(!inode_unhashed(inode));
+ WARN_ON(!inode_is_locked(upperdentry->d_parent->d_inode));
+ WARN_ON(OVL_I(inode)->__upperdentry);
+
/*
- * Make sure upperinode is consistent before making it visible to
- * ovl_inode_real();
+ * Make sure upperdentry is consistent before making it visible
*/
smp_wmb();
- OVL_I(inode)->upper = upperinode;
+ OVL_I(inode)->__upperdentry = upperdentry;
if (!S_ISDIR(upperinode->i_mode)) {
inode->i_private = upperinode;
__insert_inode_hash(inode, (unsigned long) upperinode);
spin_lock(&ofs->copyup_wq.lock);
err = wait_event_interruptible_locked(ofs->copyup_wq, !oe->copying);
if (!err) {
- if (oe->__upperdentry)
+ if (ovl_dentry_upper(dentry))
err = 1; /* Already copied up */
else
oe->copying = true;