From patchwork Thu Apr 12 15:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10338883 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 6BE90602D8 for ; Thu, 12 Apr 2018 15:25:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 607B32000A for ; Thu, 12 Apr 2018 15:25:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55182201B1; Thu, 12 Apr 2018 15:25:49 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 F0DE22000A for ; Thu, 12 Apr 2018 15:25:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753783AbeDLPZM (ORCPT ); Thu, 12 Apr 2018 11:25:12 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:55515 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753200AbeDLPIh (ORCPT ); Thu, 12 Apr 2018 11:08:37 -0400 Received: by mail-wm0-f67.google.com with SMTP id b127so12426236wmf.5 for ; Thu, 12 Apr 2018 08:08:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7iOJrU0S2IjftfJeTpaKvC6bpOTgiemrIHDIwhx9xW4=; b=EuceEiAac5ciMf1ZaSBocBwatVhkMaAfMwQFuGPfZg9k7eClTuEn2HhFx7siqePa8y dkwdagXMviVL+6n+hQVsj54rQBZqMDyVMp0RqUJdkDBpAxfGnZag2djduEQAV2ybBoVs FTsnmdc78QzdebmuLwXuwLOrNEMANd0QoCfFZXqxVzzoUg+1kwc5qEjD8O3ripkJJRP2 SjN4DW4QH9AuxFdHJ6cgD4NT+AXvCVzR8pLfx+JmUneOi/F+rDPcLt/haZo7ABto/b+V dvN7cTvEEo+Mq1zAdcirom7h6beNpL2lqpPmZwjpCnKMujFCZkJrA6Y0zffcJdUdiXrW zybw== X-Gm-Message-State: ALQs6tDrPYAmBmU02Ui6bD78ihgpzK+w6GOQxnHJBdd/G6DG41afm7tA rNSXfVE0sr056Nea9fixfozLPw== X-Google-Smtp-Source: AIpwx484f+0Z6C7XfBNu1POVygkytTcisVQePOaJb0bY1OCVfn7MukTls7on+t/YAQb0sObRJegzww== X-Received: by 10.28.150.71 with SMTP id y68mr1071204wmd.139.1523545716320; Thu, 12 Apr 2018 08:08:36 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id p197sm2621783wme.43.2018.04.12.08.08.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Apr 2018 08:08:35 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 04/35] ovl: copy up times Date: Thu, 12 Apr 2018 17:07:55 +0200 Message-Id: <20180412150826.20988-5-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180412150826.20988-1-mszeredi@redhat.com> References: <20180412150826.20988-1-mszeredi@redhat.com> 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 Copy up mtime and ctime to overlay inode after times in real object are modified. Be careful not to dirty cachelines when not necessary. This is in preparation for moving overlay functionality out of the VFS. This patch shouldn't have any observable effect. Signed-off-by: Miklos Szeredi --- fs/overlayfs/dir.c | 5 +++++ fs/overlayfs/inode.c | 1 + fs/overlayfs/overlayfs.h | 7 +++++++ fs/overlayfs/util.c | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 839709c7803a..cd0fa2363723 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -507,6 +507,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, else err = ovl_create_over_whiteout(dentry, inode, attr, hardlink); + ovl_copytimes_with_parent(dentry); } out_revert_creds: revert_creds(old_cred); @@ -768,6 +769,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir) drop_nlink(dentry->d_inode); } ovl_nlink_end(dentry, locked); + ovl_copytimes_with_parent(dentry); out_drop_write: ovl_drop_write(dentry); out: @@ -1079,6 +1081,9 @@ static int ovl_rename(struct inode *olddir, struct dentry *old, ovl_dentry_version_inc(new->d_parent, ovl_type_origin(old) || (d_inode(new) && ovl_type_origin(new))); + ovl_copytimes_with_parent(old); + ovl_copytimes_with_parent(new); + out_dput: dput(newdentry); out_dput_old: diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 6e3815fb006b..33635106c5f7 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -303,6 +303,7 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, err = vfs_removexattr(realdentry, name); } revert_creds(old_cred); + ovl_copytimes(d_inode(dentry)); out_drop_write: ovl_drop_write(dentry); diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index e0b7de799f6b..eef720ef0f07 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -258,6 +258,13 @@ bool ovl_need_index(struct dentry *dentry); int ovl_nlink_start(struct dentry *dentry, bool *locked); void ovl_nlink_end(struct dentry *dentry, bool locked); int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); +void ovl_copytimes(struct inode *inode); + +static inline void ovl_copytimes_with_parent(struct dentry *dentry) +{ + ovl_copytimes(d_inode(dentry)); + ovl_copytimes(d_inode(dentry->d_parent)); +} static inline bool ovl_is_impuredir(struct dentry *dentry) { diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 6f1078028c66..11e62e70733a 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -675,3 +675,22 @@ int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir) pr_err("overlayfs: failed to lock workdir+upperdir\n"); return -EIO; } + +void ovl_copytimes(struct inode *inode) +{ + struct inode *upperinode; + + if (!inode) + return; + + upperinode = ovl_inode_upper(inode); + + if (!upperinode) + return; + + if ((!timespec_equal(&inode->i_mtime, &upperinode->i_mtime) || + !timespec_equal(&inode->i_ctime, &upperinode->i_ctime))) { + inode->i_mtime = upperinode->i_mtime; + inode->i_ctime = upperinode->i_ctime; + } +}