summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs/util.c
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2017-07-04 22:03:16 +0200
committerMiklos Szeredi <mszeredi@redhat.com>2017-07-04 22:03:16 +0200
commit25b7713afe50963e70f98c1c964f60baf1e7e373 (patch)
treed84b8eea29d36cdfe1ea23536ed6c9ac6e3f1e07 /fs/overlayfs/util.c
parente6d2ebddbc5205635a021a910f2f0e93bc2aa534 (diff)
downloadlinux-25b7713afe50963e70f98c1c964f60baf1e7e373.tar.bz2
ovl: use i_private only as a key
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/util.c')
-rw-r--r--fs/overlayfs/util.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index f4847eff3284..fc7b1447435b 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -155,6 +155,22 @@ struct dentry *ovl_dentry_real(struct dentry *dentry)
return realdentry;
}
+struct inode *ovl_inode_real(struct inode *inode, bool *is_upper)
+{
+ struct inode *realinode = lockless_dereference(OVL_I(inode)->upper);
+ bool isup = false;
+
+ if (!realinode)
+ realinode = OVL_I(inode)->lower;
+ else
+ isup = true;
+
+ if (is_upper)
+ *is_upper = isup;
+
+ return realinode;
+}
+
struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry)
{
struct ovl_entry *oe = dentry->d_fsdata;
@@ -233,10 +249,11 @@ void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry)
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 |
- (is_upper ? OVL_ISUPPER_MASK : 0));
+ if (ovl_dentry_upper(dentry))
+ OVL_I(inode)->upper = realinode;
+ else
+ OVL_I(inode)->lower = realinode;
ovl_copyattr(realinode, inode);
}
@@ -245,10 +262,16 @@ void ovl_inode_update(struct inode *inode, struct inode *upperinode)
{
WARN_ON(!upperinode);
WARN_ON(!inode_unhashed(inode));
- WRITE_ONCE(inode->i_private,
- (unsigned long) upperinode | OVL_ISUPPER_MASK);
- if (!S_ISDIR(upperinode->i_mode))
+ /*
+ * Make sure upperinode is consistent before making it visible to
+ * ovl_inode_real();
+ */
+ smp_wmb();
+ OVL_I(inode)->upper = upperinode;
+ if (!S_ISDIR(upperinode->i_mode)) {
+ inode->i_private = upperinode;
__insert_inode_hash(inode, (unsigned long) upperinode);
+ }
}
void ovl_dentry_version_inc(struct dentry *dentry)