From patchwork Tue May 29 14:45:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10435849 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 6A91C60327 for ; Tue, 29 May 2018 14:58:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D1F3286CC for ; Tue, 29 May 2018 14:58:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5128D28776; Tue, 29 May 2018 14:58:48 +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 C7F74287A8 for ; Tue, 29 May 2018 14:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935746AbeE2O6d (ORCPT ); Tue, 29 May 2018 10:58:33 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35630 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936532AbeE2OqX (ORCPT ); Tue, 29 May 2018 10:46:23 -0400 Received: by mail-wm0-f67.google.com with SMTP id o78-v6so41495651wmg.0 for ; Tue, 29 May 2018 07:46:22 -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=ylIQzqFlNWtR3XOy2OS8/zoI3po2thy1SYZ3oZoDtzA=; b=a9ne1i2MvQZUYPE4AEeKv59PQ1TZddJcOmCa1mijN+rPYnJka54GSLXfWxzPr3WNHe Aw8Si4glKt9ABiNd+RmOShq0qV0beJ15rm7AK3cmM/XY5WUxZpvrajIZFnhMwUzvnmiA wc2DBhHLa2/hrpIzrdCMqSKSGMJXsbzcUatzMVlceNxHRzFuiaKgGT7JRmoPez622Tz7 K/QE9407DuRRCQ2smSZAZIqL79ZMevElhUJaUApz5MRFGzi+t4V/V4nXFm5R9QTt3Ysh D4xIGMKeEA4I8pU3fmQvPzp7V9Vaglo5lCwq7GQnlTvo7AxCLPw9mxw+iT/7Z0FDlJvL Rn5w== X-Gm-Message-State: ALKqPweeIbi39aut85vJwvLNcoDYmNgDvDPRI3dtksy0wPVajOD1rnQL JN7k5NlMOVc77DbAedsssGCnNA== X-Google-Smtp-Source: ADUXVKK7yOXRFaZumHQMDzHMe7EBhSDvMpUiIoTwAcZQyoefcLLF1FYbT3IKu/RzIMPb2UWyWIhEeA== X-Received: by 2002:a1c:7204:: with SMTP id n4-v6mr10999568wmc.138.1527605181673; Tue, 29 May 2018 07:46:21 -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 n71-v6sm20942227wmi.14.2018.05.29.07.46.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 07:46:21 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/28] ovl: Add helper ovl_already_copied_up() Date: Tue, 29 May 2018 16:45:50 +0200 Message-Id: <20180529144612.16675-7-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180529144612.16675-1-mszeredi@redhat.com> References: <20180529144612.16675-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 From: Vivek Goyal There are couple of places where we need to know if file is already copied up (in lockless manner). Right now its open coded and there are only two conditions to check. Soon this patch series will introduce another condition to check and Amir wants to introduce one more. So introduce a helper instead to check this so that code is easier to read. Signed-off-by: Vivek Goyal Reviewed-by: Amir Goldstein Signed-off-by: Miklos Szeredi --- fs/overlayfs/copy_up.c | 20 ++------------------ fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/util.c | 26 +++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 38cfd1acc196..6247617fea0b 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -761,21 +761,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags) struct dentry *next; struct dentry *parent = NULL; - /* - * Check if copy-up has happened as well as for upper alias (in - * case of hard links) is there. - * - * Both checks are lockless: - * - false negatives: will recheck under oi->lock - * - false positives: - * + ovl_dentry_upper() uses memory barriers to ensure the - * upper dentry is up-to-date - * + ovl_dentry_has_upper_alias() relies on locking of - * upper parent i_rwsem to prevent reordering copy-up - * with rename. - */ - if (ovl_dentry_upper(dentry) && - (ovl_dentry_has_upper_alias(dentry) || disconnected)) + if (ovl_already_copied_up(dentry)) break; next = dget(dentry); @@ -803,9 +789,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags) static bool ovl_open_need_copy_up(struct dentry *dentry, int flags) { /* Copy up of disconnected dentry does not set upper alias */ - if (ovl_dentry_upper(dentry) && - (ovl_dentry_has_upper_alias(dentry) || - (dentry->d_flags & DCACHE_DISCONNECTED))) + if (ovl_already_copied_up(dentry)) return false; if (special_file(d_inode(dentry)->i_mode)) diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 9172d3d5d870..2a9c5a80ae48 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -238,6 +238,7 @@ bool ovl_is_whiteout(struct dentry *dentry); struct file *ovl_path_open(struct path *path, int flags); int ovl_copy_up_start(struct dentry *dentry); void ovl_copy_up_end(struct dentry *dentry); +bool ovl_already_copied_up(struct dentry *dentry); bool ovl_check_origin_xattr(struct dentry *dentry); bool ovl_check_dir_xattr(struct dentry *dentry, const char *name); int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry, diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 25d202b47326..43235294e77b 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -377,13 +377,37 @@ struct file *ovl_path_open(struct path *path, int flags) return dentry_open(path, flags | O_NOATIME, current_cred()); } +bool ovl_already_copied_up(struct dentry *dentry) +{ + bool disconnected = dentry->d_flags & DCACHE_DISCONNECTED; + + /* + * Check if copy-up has happened as well as for upper alias (in + * case of hard links) is there. + * + * Both checks are lockless: + * - false negatives: will recheck under oi->lock + * - false positives: + * + ovl_dentry_upper() uses memory barriers to ensure the + * upper dentry is up-to-date + * + ovl_dentry_has_upper_alias() relies on locking of + * upper parent i_rwsem to prevent reordering copy-up + * with rename. + */ + if (ovl_dentry_upper(dentry) && + (ovl_dentry_has_upper_alias(dentry) || disconnected)) + return true; + + return false; +} + int ovl_copy_up_start(struct dentry *dentry) { struct ovl_inode *oi = OVL_I(d_inode(dentry)); int err; err = mutex_lock_interruptible(&oi->lock); - if (!err && ovl_dentry_has_upper_alias(dentry)) { + if (!err && ovl_already_copied_up(dentry)) { err = 1; /* Already copied up */ mutex_unlock(&oi->lock); }