From patchwork Mon May 7 08:37:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10383677 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 6AE8960353 for ; Mon, 7 May 2018 08:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60BFE28BB4 for ; Mon, 7 May 2018 08:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5439028BAB; Mon, 7 May 2018 08:50:51 +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 CF27028BB3 for ; Mon, 7 May 2018 08:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752475AbeEGIt0 (ORCPT ); Mon, 7 May 2018 04:49:26 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36625 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752084AbeEGIiV (ORCPT ); Mon, 7 May 2018 04:38:21 -0400 Received: by mail-wr0-f195.google.com with SMTP id f2-v6so16028833wrm.3 for ; Mon, 07 May 2018 01:38:20 -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=EeTHeFHl2eq/O+gx4CZAJEhe7vsx66jv1ArLl+y7Ubk=; b=NU+AHnk/UUyT3ZGwbzr1Z9/vrVRTmOnak198pbxYHjArGcPNliOQ2gpZYyc8r93arg j2eEzJqn466nriRbPff9THWBL6KIlUZiOnP50JH4u6uxgayaIcoSM+chGio2I1/56f7P jDOKKmJWjfGdhMj7ioEMRaCkMJ5gzsWV2OkKBPle307JyyHOrfPMGAhkTfDpPymjLUIC P6ThceBn4VxtB+TCJxJ8g0pdZhQulzGy3FbUfYRfZVlpJp/5OK3fx22vr3IQlPLEHkJ1 fOvbg2eg6O1Uly/tx5mHKqRg4ZZ0C/PADcRCWpoU9H/jflwZPaE/enBX9+c1y9qaxUqt Bxkw== X-Gm-Message-State: ALQs6tD6aiTQ97Ke383acCyADgLRYcSpEI4fRhCjEPwY0Mwq7ELz7zgi Cl20xv+BMVo71GHuUN3KV3MVCeVp9rE= X-Google-Smtp-Source: AB8JxZqSEabGurQRrIuoPp1l7zYYai6YjaX19AMSBTbak1NaHXrtKXM+iaMOi4JS8+LO6uXYVNwUrw== X-Received: by 2002:adf:8827:: with SMTP id d36-v6mr28133026wrd.41.1525682299720; Mon, 07 May 2018 01:38:19 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id h8-v6sm5908050wmc.16.2018.05.07.01.38.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 01:38:19 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/35] ovl: copy up times Date: Mon, 7 May 2018 10:37:38 +0200 Message-Id: <20180507083807.28792-7-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180507083807.28792-1-mszeredi@redhat.com> References: <20180507083807.28792-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 | 33 +++++++++++++++++++++++++-------- fs/overlayfs/inode.c | 3 +++ fs/overlayfs/overlayfs.h | 2 +- fs/overlayfs/util.c | 10 +++++++++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 839709c7803a..47dc980e8b33 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -186,11 +186,11 @@ static int ovl_set_opaque(struct dentry *dentry, struct dentry *upperdentry) static void ovl_instantiate(struct dentry *dentry, struct inode *inode, struct dentry *newdentry, bool hardlink) { - ovl_dentry_version_inc(dentry->d_parent, false); + ovl_dir_modified(dentry->d_parent, false); + ovl_copyattr(d_inode(newdentry), inode); ovl_dentry_set_upper_alias(dentry); if (!hardlink) { ovl_inode_update(inode, newdentry); - ovl_copyattr(newdentry->d_inode, inode); } else { WARN_ON(ovl_inode_real(inode) != d_inode(newdentry)); dput(newdentry); @@ -658,7 +658,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, if (err) goto out_d_drop; - ovl_dentry_version_inc(dentry->d_parent, true); + ovl_dir_modified(dentry->d_parent, true); out_d_drop: d_drop(dentry); out_dput_upper: @@ -703,7 +703,7 @@ static int ovl_remove_upper(struct dentry *dentry, bool is_dir, err = vfs_rmdir(dir, upper); else err = vfs_unlink(dir, upper, NULL); - ovl_dentry_version_inc(dentry->d_parent, ovl_type_origin(dentry)); + ovl_dir_modified(dentry->d_parent, ovl_type_origin(dentry)); /* * Keeping this dentry hashed would mean having to release @@ -733,6 +733,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir) int err; bool locked = false; const struct cred *old_cred; + struct dentry *upperdentry; bool lower_positive = ovl_lower_positive(dentry); LIST_HEAD(list); @@ -768,6 +769,17 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir) drop_nlink(dentry->d_inode); } ovl_nlink_end(dentry, locked); + + /* + * Copy ctime + * + * Note: we fail to update ctime if there was no copy-up, only a + * whiteout + */ + upperdentry = ovl_dentry_upper(dentry); + if (upperdentry) + ovl_copyattr(d_inode(upperdentry), d_inode(dentry)); + out_drop_write: ovl_drop_write(dentry); out: @@ -1074,10 +1086,15 @@ static int ovl_rename(struct inode *olddir, struct dentry *old, drop_nlink(d_inode(new)); } - ovl_dentry_version_inc(old->d_parent, ovl_type_origin(old) || - (!overwrite && ovl_type_origin(new))); - ovl_dentry_version_inc(new->d_parent, ovl_type_origin(old) || - (d_inode(new) && ovl_type_origin(new))); + ovl_dir_modified(old->d_parent, ovl_type_origin(old) || + (!overwrite && ovl_type_origin(new))); + ovl_dir_modified(new->d_parent, ovl_type_origin(old) || + (d_inode(new) && ovl_type_origin(new))); + + /* copy ctime: */ + ovl_copyattr(d_inode(olddentry), d_inode(old)); + if (d_inode(new) && ovl_dentry_upper(new)) + ovl_copyattr(d_inode(newdentry), d_inode(new)); out_dput: dput(newdentry); diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 6e3815fb006b..d3700f0de165 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -304,6 +304,9 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, } revert_creds(old_cred); + /* copy c/mtime */ + ovl_copyattr(d_inode(realdentry), inode); + out_drop_write: ovl_drop_write(dentry); out: diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index e0b7de799f6b..271561fa7882 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -237,7 +237,7 @@ void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); void ovl_inode_init(struct inode *inode, struct dentry *upperdentry, struct dentry *lowerdentry); void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); -void ovl_dentry_version_inc(struct dentry *dentry, bool impurity); +void ovl_dir_modified(struct dentry *dentry, bool impurity); u64 ovl_dentry_version_get(struct dentry *dentry); bool ovl_is_whiteout(struct dentry *dentry); struct file *ovl_path_open(struct path *path, int flags); diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 6f1078028c66..30a05d1d679d 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -333,7 +333,7 @@ void ovl_inode_update(struct inode *inode, struct dentry *upperdentry) } } -void ovl_dentry_version_inc(struct dentry *dentry, bool impurity) +static void ovl_dentry_version_inc(struct dentry *dentry, bool impurity) { struct inode *inode = d_inode(dentry); @@ -348,6 +348,14 @@ void ovl_dentry_version_inc(struct dentry *dentry, bool impurity) OVL_I(inode)->version++; } +void ovl_dir_modified(struct dentry *dentry, bool impurity) +{ + /* Copy mtime/ctime */ + ovl_copyattr(d_inode(ovl_dentry_upper(dentry)), d_inode(dentry)); + + ovl_dentry_version_inc(dentry, impurity); +} + u64 ovl_dentry_version_get(struct dentry *dentry) { struct inode *inode = d_inode(dentry);