ovl: fix relatime for directories
authorMiklos Szeredi <mszeredi@redhat.com>
Tue, 5 Sep 2017 10:53:11 +0000 (12:53 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 5 Sep 2017 10:53:11 +0000 (12:53 +0200)
Need to treat non-regular overlayfs files the same as regular files when
checking for an atime update.

Add a d_real() flag to make it return the upper dentry for all file types.

Reported-by: "zhangyi (F)" <yi.zhang@huawei.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/inode.c
fs/overlayfs/super.c
include/linux/dcache.h

index 50370599e37104708b95ede3a627052cc0d910d3..eed15033e36bc369fe1b0df45bcbcb097e1bd647 100644 (file)
@@ -1569,11 +1569,24 @@ EXPORT_SYMBOL(bmap);
 static void update_ovl_inode_times(struct dentry *dentry, struct inode *inode,
                               bool rcu)
 {
-       if (!rcu) {
-               struct inode *realinode = d_real_inode(dentry);
+       struct dentry *upperdentry;
 
-               if (unlikely(inode != realinode) &&
-                   (!timespec_equal(&inode->i_mtime, &realinode->i_mtime) ||
+       /*
+        * Nothing to do if in rcu or if non-overlayfs
+        */
+       if (rcu || likely(!(dentry->d_flags & DCACHE_OP_REAL)))
+               return;
+
+       upperdentry = d_real(dentry, NULL, 0, D_REAL_UPPER);
+
+       /*
+        * If file is on lower then we can't update atime, so no worries about
+        * stale mtime/ctime.
+        */
+       if (upperdentry) {
+               struct inode *realinode = d_inode(upperdentry);
+
+               if ((!timespec_equal(&inode->i_mtime, &realinode->i_mtime) ||
                     !timespec_equal(&inode->i_ctime, &realinode->i_ctime))) {
                        inode->i_mtime = realinode->i_mtime;
                        inode->i_ctime = realinode->i_ctime;
index 19e89ce39017167ed7b8b6088bd4ea40c3d89c2c..cd49c0298ddf9c69b4331e578b97f26c89c72caf 100644 (file)
@@ -75,6 +75,9 @@ static struct dentry *ovl_d_real(struct dentry *dentry,
        struct dentry *real;
        int err;
 
+       if (flags & D_REAL_UPPER)
+               return ovl_dentry_upper(dentry);
+
        if (!d_is_reg(dentry)) {
                if (!inode || inode == d_inode(dentry))
                        return dentry;
index fd0721e520f4737a7950269717d4297d0403c457..ed1a7cf6923af31a3c08a591ca74444b6771e71d 100644 (file)
@@ -562,6 +562,9 @@ static inline struct dentry *d_backing_dentry(struct dentry *upper)
        return upper;
 }
 
+/* d_real() flags */
+#define D_REAL_UPPER   0x2     /* return upper dentry or NULL if non-upper */
+
 /**
  * d_real - Return the real dentry
  * @dentry: the dentry to query