From patchwork Tue Jul 19 12:38:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9236931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15DE6602F0 for ; Tue, 19 Jul 2016 12:39:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0761B1FF21 for ; Tue, 19 Jul 2016 12:39:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F05B626929; Tue, 19 Jul 2016 12:39:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A09921FF21 for ; Tue, 19 Jul 2016 12:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753290AbcGSMir (ORCPT ); Tue, 19 Jul 2016 08:38:47 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:36638 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752896AbcGSMiq (ORCPT ); Tue, 19 Jul 2016 08:38:46 -0400 Received: by mail-wm0-f42.google.com with SMTP id q128so17896825wma.1 for ; Tue, 19 Jul 2016 05:38:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oSqnBWRRuHMj/kmFU1D1+L2obxrijp2SOsV4gfwCy5Y=; b=GpgxyOjmuYS5mCHl9mNRhRuaatBXJCk8sr+Wp77CKsxMcxhghXSaZ1CVTumCRBf7AT QF/MUvX6VpZknj8/lJC4SLzyACu+n/wfDkRB38gGVoHRcf+oOm9KM+VJ31BvTE5eihcZ k+Vk3i4A+djm6o+h8/Npu8NOQE4E52wEiQtFE7pQ4Q+rtm7Tz/PL3zZR9mCT14ZqqaHR OXQIQBOf8RFVv0SWnKYZPj4hVZDq2+d6M6145Lcaee0zy3/tncRG5vedmiENWMTkXYpJ a65RhEJ42d5MGgrMaLQRd0m6iFWURTtOijZFip0BRsviE4Vv0qg2rxDACKFj0MNpM7Oe cSaQ== X-Gm-Message-State: ALyK8tJna2oqZE9hYLDRSzo9t8V+pyMVQ1m052FHqsoLef7IvFbaBbUde71VPRwXQq0VqyU/ X-Received: by 10.28.87.3 with SMTP id l3mr4143414wmb.71.1468931924597; Tue, 19 Jul 2016 05:38:44 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (563B8D07.dsl.pool.telekom.hu. [86.59.141.7]) by smtp.gmail.com with ESMTPSA id x62sm22625545wmf.13.2016.07.19.05.38.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 05:38:43 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH] vfs: update ovl inode before relatime check Date: Tue, 19 Jul 2016 14:38:41 +0200 Message-Id: <1468931921-26746-1-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On overlayfs relatime_need_update() needs inode times to be correct on overlay inode. But i_mtime and i_ctime are updated by filesystem code on underlying inode only, so they will be out-of-date on the overlay inode. This patch copies the times from the underlying inode if needed. This can't be done if called from RCU lookup (link following) but link m/ctime are not updated by fs, so this is all right. This patch doesn't change functionality for anything but overlayfs. Signed-off-by: Miklos Szeredi --- fs/inode.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4ccbc21b30ce..6a2d447c8775 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1534,16 +1534,36 @@ sector_t bmap(struct inode *inode, sector_t block) EXPORT_SYMBOL(bmap); /* + * Update times in overlayed inode from underlying real inode + */ +static void update_ovl_inode_times(struct dentry *dentry, struct inode *inode, + bool rcu) +{ + if (!rcu) { + struct inode *realinode = d_real_inode(dentry); + + if (unlikely(inode != realinode)) { + inode->i_mtime = realinode->i_mtime; + inode->i_ctime = realinode->i_ctime; + WARN_ON_ONCE(!timespec_equal(&inode->i_atime, + &realinode->i_atime)); + } + } +} + +/* * With relative atime, only update atime if the previous atime is * earlier than either the ctime or mtime or if at least a day has * passed since the last atime update. */ -static int relatime_need_update(struct vfsmount *mnt, struct inode *inode, - struct timespec now) +static int relatime_need_update(const struct path *path, struct inode *inode, + struct timespec now, bool rcu) { - if (!(mnt->mnt_flags & MNT_RELATIME)) + if (!(path->mnt->mnt_flags & MNT_RELATIME)) return 1; + + update_ovl_inode_times(path->dentry, inode, rcu); /* * Is mtime younger than atime? If yes, update atime: */ @@ -1610,7 +1630,8 @@ static int update_time(struct inode *inode, struct timespec *time, int flags) * This function automatically handles read only file systems and media, * as well as the "noatime" flag and inode specific "noatime" markers. */ -bool atime_needs_update(const struct path *path, struct inode *inode) +static bool __atime_needs_update(const struct path *path, struct inode *inode, + bool rcu) { struct vfsmount *mnt = path->mnt; struct timespec now; @@ -1629,7 +1650,7 @@ bool atime_needs_update(const struct path *path, struct inode *inode) now = current_fs_time(inode->i_sb); - if (!relatime_need_update(mnt, inode, now)) + if (!relatime_need_update(path, inode, now, rcu)) return false; if (timespec_equal(&inode->i_atime, &now)) @@ -1638,13 +1659,18 @@ bool atime_needs_update(const struct path *path, struct inode *inode) return true; } +bool atime_needs_update(const struct path *path, struct inode *inode) +{ + return __atime_needs_update(path, inode, true); +} + void touch_atime(const struct path *path) { struct vfsmount *mnt = path->mnt; struct inode *inode = d_inode(path->dentry); struct timespec now; - if (!atime_needs_update(path, inode)) + if (!__atime_needs_update(path, inode, false)) return; if (!sb_start_write_trylock(inode->i_sb))