Skip to content

Commit cd91304

Browse files
author
Miklos Szeredi
committed
ovl: fix relatime for directories
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)" <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 495e642 commit cd91304

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

fs/inode.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,11 +1569,24 @@ EXPORT_SYMBOL(bmap);
15691569
static void update_ovl_inode_times(struct dentry *dentry, struct inode *inode,
15701570
bool rcu)
15711571
{
1572-
if (!rcu) {
1573-
struct inode *realinode = d_real_inode(dentry);
1572+
struct dentry *upperdentry;
15741573

1575-
if (unlikely(inode != realinode) &&
1576-
(!timespec_equal(&inode->i_mtime, &realinode->i_mtime) ||
1574+
/*
1575+
* Nothing to do if in rcu or if non-overlayfs
1576+
*/
1577+
if (rcu || likely(!(dentry->d_flags & DCACHE_OP_REAL)))
1578+
return;
1579+
1580+
upperdentry = d_real(dentry, NULL, 0, D_REAL_UPPER);
1581+
1582+
/*
1583+
* If file is on lower then we can't update atime, so no worries about
1584+
* stale mtime/ctime.
1585+
*/
1586+
if (upperdentry) {
1587+
struct inode *realinode = d_inode(upperdentry);
1588+
1589+
if ((!timespec_equal(&inode->i_mtime, &realinode->i_mtime) ||
15771590
!timespec_equal(&inode->i_ctime, &realinode->i_ctime))) {
15781591
inode->i_mtime = realinode->i_mtime;
15791592
inode->i_ctime = realinode->i_ctime;

fs/overlayfs/super.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static struct dentry *ovl_d_real(struct dentry *dentry,
7575
struct dentry *real;
7676
int err;
7777

78+
if (flags & D_REAL_UPPER)
79+
return ovl_dentry_upper(dentry);
80+
7881
if (!d_is_reg(dentry)) {
7982
if (!inode || inode == d_inode(dentry))
8083
return dentry;

include/linux/dcache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ static inline struct dentry *d_backing_dentry(struct dentry *upper)
562562
return upper;
563563
}
564564

565+
/* d_real() flags */
566+
#define D_REAL_UPPER 0x2 /* return upper dentry or NULL if non-upper */
567+
565568
/**
566569
* d_real - Return the real dentry
567570
* @dentry: the dentry to query

0 commit comments

Comments
 (0)