From patchwork Wed Apr 26 21:35:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9702087 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 E0F9F603F4 for ; Wed, 26 Apr 2017 21:35:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C42285E7 for ; Wed, 26 Apr 2017 21:35:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C556B285EF; Wed, 26 Apr 2017 21:35:21 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham 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 42E31285E7 for ; Wed, 26 Apr 2017 21:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030848AbdDZVfR (ORCPT ); Wed, 26 Apr 2017 17:35:17 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35341 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030841AbdDZVfL (ORCPT ); Wed, 26 Apr 2017 17:35:11 -0400 Received: by mail-wr0-f196.google.com with SMTP id g12so1673623wrg.2; Wed, 26 Apr 2017 14:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WDA0H1gOH+oKxdqIYD8ygigvyvgCPVBhyMsNL8EwOuE=; b=BiSQX5GlSfJZaqPEFlyV3V76U/bPfq2cDmAb88gJpdSpMUo7OsoJg0c99GAlvq55j3 4dudL0IzXlz5G9hViqEa93XZMaoWSvmWoqjUzVB9+NIBAkF9tlNkCs6C0uR3P6zfpUrY E52LfGVcoFnP1UZpmBLbKrjwaszW+Al7F/RKulWU7EHo16qKN8X+KsxmbCE/7fbl2pv7 lcouOX/UwCwGB+yvBoD6ur4kD/6wR0mrvuCBEolUfjOx2HS3jQwWNxb3b0K3b5MLAYot OA+4h2XJJO3egttWAYi4tEcnK8ZLPZpG49quKNrqS1d2yib05hqs0ney0R1i4S1h8qoi XSAA== 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=WDA0H1gOH+oKxdqIYD8ygigvyvgCPVBhyMsNL8EwOuE=; b=EjFrhvHKgghaE5nHUs1HEwhUlsS4v1ZBBlJVdbRmm6xj/dQ5LoMpMSsZqQZ4Sg3Qh7 HlJZugLcXyfNT78Qzr6ZVMntJaX4NoJ86R4sbJJakke3Ij61yqNxAknZJUFj+aYkTFUs VLS6gOIFYtD7ZlFCi/Y+tffzb1OrqOHCmTJFV0PgfrFKlw8pKvPyqsVD83NVjvbguD/b Y8Fb9Yt3NM5hawAnn53hssQ0/lHbyqAALp0QtqnJd/9wZZ0Ci1PX8sR+n6XDQwBiwCME ZlH6VL/wNjTlvH8arr41UetYHz0JdGktMhUqetyR4kwH5Uki7wJuBpHuYsyOTWqljjNv 2Apw== X-Gm-Message-State: AN3rC/5Abjjb1+7qYWC2q56ymDEm6LBgQuwD6hVZ/R4obAZ2s+SYxZvO +GxYJmrelaNiHg== X-Received: by 10.223.134.35 with SMTP id 32mr1457290wrv.30.1493242510218; Wed, 26 Apr 2017 14:35:10 -0700 (PDT) Received: from amir-VirtualBox.lan (bzq-79-179-55-127.red.bezeqint.net. [79.179.55.127]) by smtp.gmail.com with ESMTPSA id 81sm931577wmj.9.2017.04.26.14.35.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Apr 2017 14:35:09 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Vivek Goyal , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 01/16] ovl: store path type in dentry Date: Thu, 27 Apr 2017 00:35:03 +0300 Message-Id: <1493242518-15266-2-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493242518-15266-1-git-send-email-amir73il@gmail.com> References: <1493242518-15266-1-git-send-email-amir73il@gmail.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 We would like to add more state info to ovl_entry soon (for const ino) and this state info would be added as type flags. Store the type value in ovl_entry and update the UPPER and MERGE type flags when needed, so ovl_path_type() just returns the stored value. Signed-off-by: Amir Goldstein --- fs/overlayfs/namei.c | 1 + fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/ovl_entry.h | 3 +++ fs/overlayfs/super.c | 1 + fs/overlayfs/util.c | 30 ++++++++++++++++++++++++------ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index b8b0778..8788fd7 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -338,6 +338,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, kfree(stack); kfree(d.redirect); dentry->d_fsdata = oe; + ovl_update_type(dentry, d.is_dir); d_add(dentry, inode); return NULL; diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 741dc0b..e90a548 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -155,6 +155,7 @@ struct ovl_entry *ovl_alloc_entry(unsigned int numlower); bool ovl_dentry_remote(struct dentry *dentry); bool ovl_dentry_weird(struct dentry *dentry); enum ovl_path_type ovl_path_type(struct dentry *dentry); +enum ovl_path_type ovl_update_type(struct dentry *dentry, bool is_dir); void ovl_path_upper(struct dentry *dentry, struct path *path); void ovl_path_lower(struct dentry *dentry, struct path *path); enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h index 59614fa..293be5f 100644 --- a/fs/overlayfs/ovl_entry.h +++ b/fs/overlayfs/ovl_entry.h @@ -31,6 +31,8 @@ struct ovl_fs { wait_queue_head_t copyup_wq; }; +enum ovl_path_type; + /* private information held for every overlayfs dentry */ struct ovl_entry { struct dentry *__upperdentry; @@ -44,6 +46,7 @@ struct ovl_entry { }; struct rcu_head rcu; }; + enum ovl_path_type __type; unsigned numlower; struct path lowerstack[]; }; diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index c072a0c..671bac0 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -961,6 +961,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) kfree(stack); root_dentry->d_fsdata = oe; + ovl_update_type(root_dentry, true); realinode = d_inode(ovl_dentry_real(root_dentry)); ovl_inode_init(d_inode(root_dentry), realinode, !!upperpath.dentry); diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 8a1e24a..bbd6074 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -70,21 +70,38 @@ bool ovl_dentry_weird(struct dentry *dentry) enum ovl_path_type ovl_path_type(struct dentry *dentry) { struct ovl_entry *oe = dentry->d_fsdata; - enum ovl_path_type type = 0; + enum ovl_path_type type = oe->__type; - if (oe->__upperdentry) { - type = __OVL_PATH_UPPER; + /* Matches smp_wmb() in ovl_update_type() */ + smp_rmb(); + return type; +} + +enum ovl_path_type ovl_update_type(struct dentry *dentry, bool is_dir) +{ + struct ovl_entry *oe = dentry->d_fsdata; + enum ovl_path_type type = oe->__type; + /* Update UPPER/MERGE flags and preserve the rest */ + type &= ~(__OVL_PATH_UPPER | __OVL_PATH_MERGE); + if (oe->__upperdentry) { + type |= __OVL_PATH_UPPER; /* - * Non-dir dentry can hold lower dentry from previous - * location. + * Non-dir dentry can hold lower dentry from before + * copy-up. */ - if (oe->numlower && d_is_dir(dentry)) + if (oe->numlower && is_dir) type |= __OVL_PATH_MERGE; } else { if (oe->numlower > 1) type |= __OVL_PATH_MERGE; } + /* + * Make sure type is consistent with __upperdentry before making it + * visible to ovl_path_type(). + */ + smp_wmb(); + oe->__type = type; return type; } @@ -220,6 +237,7 @@ void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry) */ smp_wmb(); oe->__upperdentry = upperdentry; + ovl_update_type(dentry, d_is_dir(dentry)); } void ovl_inode_init(struct inode *inode, struct inode *realinode, bool is_upper)