From patchwork Fri Jan 31 11:50:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11359753 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5090139A for ; Fri, 31 Jan 2020 11:50:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A34C620705 for ; Fri, 31 Jan 2020 11:50:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="faizN3sw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728515AbgAaLuV (ORCPT ); Fri, 31 Jan 2020 06:50:21 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:30440 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728423AbgAaLuU (ORCPT ); Fri, 31 Jan 2020 06:50:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580471419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2WGviQLsH6AvMNQjdMyzX3t1BULCm9mhpUqub5Zuv+E=; b=faizN3swDaIaPLlz4ejrVKZ26IXZF3OhnJ+4valxzC9X5IA6ldOTb76w0lxI70l52SFslX EtbOaVsseV2ltc0bAHdrL3VhMGzdxoR1BdyCMvtaEilsW4Cn24OeYaBbajDF7nxUA6nn/d 2if6USN6oFkqMBpLm4g4/ztn4xtY/WE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-ap7XyLcGPnOlinU_8z2HKw-1; Fri, 31 Jan 2020 06:50:15 -0500 X-MC-Unique: ap7XyLcGPnOlinU_8z2HKw-1 Received: by mail-wr1-f71.google.com with SMTP id k18so3267988wrw.9 for ; Fri, 31 Jan 2020 03:50:15 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=2WGviQLsH6AvMNQjdMyzX3t1BULCm9mhpUqub5Zuv+E=; b=nnScw5/hNRSTIyz53AfCJ60IvUUAhmoXOkBSFn4Vv+hTkRPQXL2cGwNcEkUewJ7Xc6 hxPWF89HPE27TkN3fk+NzgETV/KZB+0tb+wCVFvaoGDN9HQOGL+xMsCHF6dh7QxTZ4a0 SllGNacaCSlqKPa7lzrELRcZbWF3AUk1F5/LP59oced3WIc7VKMDE2Gi9nX5xG9J6Di6 ZWMxlr2TSoWh9/PzlFFvYI3bA7eWXag0YLkY95//HLX0hHs15vlnQI5PcTJrS7vGprOP KOjuZF0FzCnMjXBZYvz0Fkdo+CGoM1LC8UdM9tTM3KmCu3jkR6JSP5oTNiQ8sebVDbdy 6Jxw== X-Gm-Message-State: APjAAAWcQaeWQ0z36wQ8cLeS/TXB21DLIL6j63a7V+HbnbJejys8/lyb PTWhKC0xgiyiaf26ZyGtOVAZI+TdXt+8PVJumVHNFnZ/otSiYJkGWQ18C8HF84+PuLFHGyvtCWE aNe4lByPMHeadpOwMtfMl/RhJeQ== X-Received: by 2002:a5d:4e0a:: with SMTP id p10mr12489960wrt.229.1580471414691; Fri, 31 Jan 2020 03:50:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxpyFnDsYUD/UFMSZ5RGBKK5QG7dbAHqvgHv8woAFzPIbBp14lwxTvhrqmj9sRgsB5dMvp6nw== X-Received: by 2002:a5d:4e0a:: with SMTP id p10mr12489935wrt.229.1580471414456; Fri, 31 Jan 2020 03:50:14 -0800 (PST) Received: from miu.piliscsaba.redhat.com (84-236-74-45.pool.digikabel.hu. [84.236.74.45]) by smtp.gmail.com with ESMTPSA id s1sm2746622wro.66.2020.01.31.03.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 03:50:13 -0800 (PST) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Vivek Goyal Subject: [PATCH 1/4] ovl: restructure dentry revalidation Date: Fri, 31 Jan 2020 12:50:01 +0100 Message-Id: <20200131115004.17410-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200131115004.17410-1-mszeredi@redhat.com> References: <20200131115004.17410-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use a common loop for plain and weak revalidation. This will aid doing revalidation on upper layer. This patch doesn't change behavior. Signed-off-by: Miklos Szeredi --- fs/overlayfs/super.c | 51 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 319fe0d355b0..852a1816fea1 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -113,47 +113,48 @@ static struct dentry *ovl_d_real(struct dentry *dentry, return dentry; } -static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) +static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak) { - struct ovl_entry *oe = dentry->d_fsdata; - unsigned int i; int ret = 1; - for (i = 0; i < oe->numlower; i++) { - struct dentry *d = oe->lowerstack[i].dentry; - - if (d->d_flags & DCACHE_OP_REVALIDATE) { - ret = d->d_op->d_revalidate(d, flags); - if (ret < 0) - return ret; - if (!ret) { - if (!(flags & LOOKUP_RCU)) - d_invalidate(d); - return -ESTALE; - } + if (weak) { + if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) + ret = d->d_op->d_weak_revalidate(d, flags); + } else if (d->d_flags & DCACHE_OP_REVALIDATE) { + ret = d->d_op->d_revalidate(d, flags); + if (!ret) { + if (!(flags & LOOKUP_RCU)) + d_invalidate(d); + ret = -ESTALE; } } - return 1; + return ret; } -static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) +static int ovl_dentry_revalidate_common(struct dentry *dentry, + unsigned int flags, bool weak) { struct ovl_entry *oe = dentry->d_fsdata; unsigned int i; int ret = 1; - for (i = 0; i < oe->numlower; i++) { - struct dentry *d = oe->lowerstack[i].dentry; - - if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) { - ret = d->d_op->d_weak_revalidate(d, flags); - if (ret <= 0) - break; - } + for (i = 0; ret > 0 && i < oe->numlower; i++) { + ret = ovl_revalidate_real(oe->lowerstack[i].dentry, flags, + weak); } return ret; } +static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) +{ + return ovl_dentry_revalidate_common(dentry, flags, false); +} + +static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) +{ + return ovl_dentry_revalidate_common(dentry, flags, true); +} + static const struct dentry_operations ovl_dentry_operations = { .d_release = ovl_dentry_release, .d_real = ovl_d_real, From patchwork Fri Jan 31 11:50:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11359751 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A648D139A for ; Fri, 31 Jan 2020 11:50:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84C4720CC7 for ; Fri, 31 Jan 2020 11:50:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WlU4ydYi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728512AbgAaLuT (ORCPT ); Fri, 31 Jan 2020 06:50:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25055 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728423AbgAaLuT (ORCPT ); Fri, 31 Jan 2020 06:50:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580471418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Gs10o8erqjXnGfNlK1akrFju0qr46cuwrqKnpu2IuE=; b=WlU4ydYinuCZgclzT3CGO/IzmuOVjlIIuCX+kp9YTuIH3F2E5wIDmRxTTsDkwa3mNQiigg 8EdtSroRnnn+Ed+VFfqJPfwvd6azBcC9ogjVwuehVLzEFWu77CJrl2yNUmEcitrVRuX7oR /yLhbHNpQs4nI735MKM1q3OB+tePwMk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-146-po4ZvCt1NlyftMAnDiNiJw-1; Fri, 31 Jan 2020 06:50:16 -0500 X-MC-Unique: po4ZvCt1NlyftMAnDiNiJw-1 Received: by mail-wm1-f71.google.com with SMTP id g26so2702654wmk.6 for ; Fri, 31 Jan 2020 03:50:16 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=1Gs10o8erqjXnGfNlK1akrFju0qr46cuwrqKnpu2IuE=; b=O6vablVLuzVPWLIQf76dPtqEUJa9VS9/5J25tEWfsdyH4nQwYa1lb5T0dtolE+MHwg Zdp9dxOSo0d4AnWCaGD94oeV8yohuyEGToDs4lfELHK19nIxPfH4HkQufrMSpwaW8c84 RBVAkPACunZbgD9aEAh5XQfRWiMYXySSzqkQN2k+9MRk2apejPACBhYDeVrF4aghfQn2 S1dw8kv7Md4rJjlzRDZZXZKfS/p6gY/y/8oqxFINuNB0ZHCP6UhBef53oB8R6rct5KtO v1w4HpICgpTsajkRBPwycjVJyCJpVP4pblJ8htG2VNvfALPF6voUBcAempLEVjJAygfF PDSA== X-Gm-Message-State: APjAAAXrVkcW86/vRyd8Prh6cuHHK5154dDsQhu2/utFN9XBFmpyYrfR 5lDMtwomD9gNOkOWIA7FbedqDmd8BPXAodAp6/bBYUXFlAqpip48nqHwHMn0zNvD0DALyLIylrA jMtcgMPdHDrFLFKR7zpBSZgTTDA== X-Received: by 2002:a1c:1fd0:: with SMTP id f199mr11335624wmf.113.1580471415541; Fri, 31 Jan 2020 03:50:15 -0800 (PST) X-Google-Smtp-Source: APXvYqy5XnMHv+48gW8liIrBqG0aVQmKuS27GqhXks1xZLqKou+Dbno3hgisv0P7LNmG0pxMXvfAQA== X-Received: by 2002:a1c:1fd0:: with SMTP id f199mr11335605wmf.113.1580471415325; Fri, 31 Jan 2020 03:50:15 -0800 (PST) Received: from miu.piliscsaba.redhat.com (84-236-74-45.pool.digikabel.hu. [84.236.74.45]) by smtp.gmail.com with ESMTPSA id s1sm2746622wro.66.2020.01.31.03.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 03:50:14 -0800 (PST) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Vivek Goyal Subject: [PATCH 2/4] ovl: separate detection of remote upper layer from stacked overlay Date: Fri, 31 Jan 2020 12:50:02 +0100 Message-Id: <20200131115004.17410-3-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200131115004.17410-1-mszeredi@redhat.com> References: <20200131115004.17410-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Following patch will allow remote as upper layer, but not overlay stacked on upper layer. Separate the two concepts. This patch is doesn't change behavior. Signed-off-by: Miklos Szeredi --- fs/overlayfs/namei.c | 3 ++- fs/overlayfs/super.c | 14 +++++++------- fs/overlayfs/util.c | 3 +-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index ed9e129fae04..a5b998a93a24 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -845,7 +845,8 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, if (err) goto out; - if (upperdentry && unlikely(ovl_dentry_remote(upperdentry))) { + if (upperdentry && (upperdentry->d_flags & DCACHE_OP_REAL || + unlikely(ovl_dentry_remote(upperdentry)))) { dput(upperdentry); err = -EREMOTE; goto out; diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 852a1816fea1..7e294bf719ff 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -752,13 +752,13 @@ static int ovl_mount_dir(const char *name, struct path *path) ovl_unescape(tmp); err = ovl_mount_dir_noesc(tmp, path); - if (!err) - if (ovl_dentry_remote(path->dentry)) { - pr_err("filesystem on '%s' not supported as upperdir\n", - tmp); - path_put_init(path); - err = -EINVAL; - } + if (!err && (ovl_dentry_remote(path->dentry) || + path->dentry->d_flags & DCACHE_OP_REAL)) { + pr_err("filesystem on '%s' not supported as upperdir\n", + tmp); + path_put_init(path); + err = -EINVAL; + } kfree(tmp); } return err; diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index ea005085803f..67cd2866aaa2 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -93,8 +93,7 @@ struct ovl_entry *ovl_alloc_entry(unsigned int numlower) bool ovl_dentry_remote(struct dentry *dentry) { return dentry->d_flags & - (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE | - DCACHE_OP_REAL); + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE); } bool ovl_dentry_weird(struct dentry *dentry) From patchwork Fri Jan 31 11:50:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11359755 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42990921 for ; Fri, 31 Jan 2020 11:50:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16D6920705 for ; Fri, 31 Jan 2020 11:50:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PCrfGzt7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728522AbgAaLuV (ORCPT ); Fri, 31 Jan 2020 06:50:21 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39040 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728513AbgAaLuU (ORCPT ); Fri, 31 Jan 2020 06:50:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580471419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MFQinq7lbM8X1ugDYdWFA1VKBJHOWbYtqUqc3Robc/U=; b=PCrfGzt7CoCKBHO9kiqcv2niGenUz9aZyK37PBK5C4m5Jb5Dr9IznxwlYYoBhu7C2v0xEJ zJB4FXdPRLft5scleM5xwz5HTLFoDPLeasZRG2xbjUpLSm0eNASGIeMAHJLqJSUGeAyqbp lHdTRDfek+L/HCBnVFmeJG2ktBUBeWg= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-OaglEk6IONmJ1evie5nM2Q-1; Fri, 31 Jan 2020 06:50:18 -0500 X-MC-Unique: OaglEk6IONmJ1evie5nM2Q-1 Received: by mail-wr1-f71.google.com with SMTP id b13so3210520wrx.22 for ; Fri, 31 Jan 2020 03:50:17 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=MFQinq7lbM8X1ugDYdWFA1VKBJHOWbYtqUqc3Robc/U=; b=qe8cMKhONw1vSpBY8oH8QExwTVu+Paomzj8duRsZ6KH1B3N+f++OUM9/A+ftd8dF5W DsDK0Qmr4emGHxvLccO88idLXj0CBuTcKa0kThpEzaX8mYHPTq5SSyo8S1viEKjrHFTH oH8/LNJ9v5JtJcLeVFRka1QCPRk4EsIgkXdhxVNXDns7vgUW6Dv5cIxvnU2N8Jiv1EOc ho2hHmpmai0ZeuHTY7NaWGAu4s6Nzaqo8tAag9+T0ENa/oJCm+5iVr6ap45WF1mNwF4i qe0xwf7Swo5C2d5p8BdU4uKCak+7SWdyzmGn1BHFxsUJZPck9SaFvSgbSekuvbq/a/yR iERg== X-Gm-Message-State: APjAAAUBFDTOwC4ctvwErnw40PPkUWX+TSn3eVb2xA7P+a8jC4qNnMTW ipCXU9gS4uSY9O91/LR3mp771z/ynmZ0oS8Tw33rNQSS7I7SQKXVCFcwlgND1cxHHnXm6HHpfzq /skY6ZE14JJ3tO7Ssymqk+MmlOA== X-Received: by 2002:a1c:8086:: with SMTP id b128mr11160853wmd.80.1580471416558; Fri, 31 Jan 2020 03:50:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzC8wk9ehLS4CTz4yXT0vWkebv2Q+kfM4w5h1WFFvNRqsV/MuExO4wiNwQljLvCfF0JMbhQGA== X-Received: by 2002:a1c:8086:: with SMTP id b128mr11160827wmd.80.1580471416205; Fri, 31 Jan 2020 03:50:16 -0800 (PST) Received: from miu.piliscsaba.redhat.com (84-236-74-45.pool.digikabel.hu. [84.236.74.45]) by smtp.gmail.com with ESMTPSA id s1sm2746622wro.66.2020.01.31.03.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 03:50:15 -0800 (PST) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Vivek Goyal Subject: [PATCH 3/4] ovl: decide if revalidate needed on a per-dentry bases Date: Fri, 31 Jan 2020 12:50:03 +0100 Message-Id: <20200131115004.17410-4-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200131115004.17410-1-mszeredi@redhat.com> References: <20200131115004.17410-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Allow completely skipping ->revalidate() on a per-dentry bases, in case the underlying layers used for a dentry do not themselves have ->revalidate(). E.g. negative overlay dentry has no underlying layers, hence revalidate is unnecessary. Or if lower layer is remote but overlay dentry is pure-upper, then can skip revalidate. The following places need to update whether the dentry needs revalidate or not: - fill-super (root dentry) - lookup - create - fh_to_dentry Signed-off-by: Miklos Szeredi --- fs/overlayfs/dir.c | 3 +++ fs/overlayfs/export.c | 2 ++ fs/overlayfs/namei.c | 3 +++ fs/overlayfs/overlayfs.h | 3 ++- fs/overlayfs/super.c | 23 +++++++---------------- fs/overlayfs/util.c | 15 ++++++++++++--- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 8e57d5372b8f..b3471ef51440 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -243,6 +243,9 @@ static int ovl_instantiate(struct dentry *dentry, struct inode *inode, ovl_dir_modified(dentry->d_parent, false); ovl_dentry_set_upper_alias(dentry); + ovl_dentry_update_reval(dentry, newdentry, + DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE); + if (!hardlink) { /* * ovl_obtain_alias() can be called after ovl_create_real() diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 6f54d70cef27..a58b3d9b06b9 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c @@ -324,6 +324,8 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb, if (upper_alias) ovl_dentry_set_upper_alias(dentry); } + ovl_dentry_update_reval(dentry, upper, + DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE); return d_instantiate_anon(dentry, inode); diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index a5b998a93a24..76e61cc27822 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -1077,6 +1077,9 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, goto out_free_oe; } + ovl_dentry_update_reval(dentry, upperdentry, + DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE); + revert_creds(old_cred); if (origin_path) { dput(origin_path->dentry); diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 3623d28aa4fa..68124a4f8f9b 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -229,7 +229,8 @@ struct dentry *ovl_indexdir(struct super_block *sb); bool ovl_index_all(struct super_block *sb); bool ovl_verify_lower(struct super_block *sb); struct ovl_entry *ovl_alloc_entry(unsigned int numlower); -bool ovl_dentry_remote(struct dentry *dentry); +void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry, + unsigned int mask); bool ovl_dentry_weird(struct dentry *dentry); enum ovl_path_type ovl_path_type(struct dentry *dentry); void ovl_path_upper(struct dentry *dentry, struct path *path); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 7e294bf719ff..26d4153240a8 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -158,11 +158,6 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) static const struct dentry_operations ovl_dentry_operations = { .d_release = ovl_dentry_release, .d_real = ovl_d_real, -}; - -static const struct dentry_operations ovl_reval_dentry_operations = { - .d_release = ovl_dentry_release, - .d_real = ovl_d_real, .d_revalidate = ovl_dentry_revalidate, .d_weak_revalidate = ovl_dentry_weak_revalidate, }; @@ -779,7 +774,7 @@ static int ovl_check_namelen(struct path *path, struct ovl_fs *ofs, } static int ovl_lower_dir(const char *name, struct path *path, - struct ovl_fs *ofs, int *stack_depth, bool *remote) + struct ovl_fs *ofs, int *stack_depth) { int fh_type; int err; @@ -794,9 +789,6 @@ static int ovl_lower_dir(const char *name, struct path *path, *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth); - if (ovl_dentry_remote(path->dentry)) - *remote = true; - /* * The inodes index feature and NFS export need to encode and decode * file handles, so they require that all layers support them. @@ -1439,7 +1431,6 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, char *lowertmp, *lower; struct path *stack = NULL; unsigned int stacklen, numlower = 0, i; - bool remote = false; struct ovl_entry *oe; err = -ENOMEM; @@ -1471,7 +1462,7 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, lower = lowertmp; for (numlower = 0; numlower < stacklen; numlower++) { err = ovl_lower_dir(lower, &stack[numlower], ofs, - &sb->s_stack_depth, &remote); + &sb->s_stack_depth); if (err) goto out_err; @@ -1499,11 +1490,6 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, oe->lowerstack[i].layer = &ofs->layers[i+1]; } - if (remote) - sb->s_d_op = &ovl_reval_dentry_operations; - else - sb->s_d_op = &ovl_dentry_operations; - out: for (i = 0; i < numlower; i++) path_put(&stack[i]); @@ -1597,6 +1583,8 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) struct cred *cred; int err; + sb->s_d_op = &ovl_dentry_operations; + err = -ENOMEM; ofs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL); if (!ofs) @@ -1724,6 +1712,9 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ovl_inode_init(d_inode(root_dentry), upperpath.dentry, ovl_dentry_lower(root_dentry), NULL); + ovl_dentry_update_reval(root_dentry, upperpath.dentry, + DCACHE_OP_WEAK_REVALIDATE); + sb->s_root = root_dentry; return 0; diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 67cd2866aaa2..3ad8fb291f7d 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -90,10 +90,19 @@ struct ovl_entry *ovl_alloc_entry(unsigned int numlower) return oe; } -bool ovl_dentry_remote(struct dentry *dentry) +void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry, + unsigned int mask) { - return dentry->d_flags & - (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE); + struct ovl_entry *oe = OVL_E(dentry); + unsigned int i, flags = 0; + + for (i = 0; i < oe->numlower; i++) + flags |= oe->lowerstack[i].dentry->d_flags; + + spin_lock(&dentry->d_lock); + dentry->d_flags &= ~mask; + dentry->d_flags |= flags & mask; + spin_unlock(&dentry->d_lock); } bool ovl_dentry_weird(struct dentry *dentry) From patchwork Fri Jan 31 11:50:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11359757 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73A94139A for ; Fri, 31 Jan 2020 11:50:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 526CE215A4 for ; Fri, 31 Jan 2020 11:50:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RjlB8fh2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728531AbgAaLuW (ORCPT ); Fri, 31 Jan 2020 06:50:22 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39244 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728532AbgAaLuW (ORCPT ); Fri, 31 Jan 2020 06:50:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580471422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nQ17yO5W5w5qlWY/ou9U5Zs/oUqInXzTRAcl/4EyG5I=; b=RjlB8fh2PCaMYb2YmYFSWQk5wgV7CKxrXtTCJWs1Q4xMTzIcrkvrex9N0ugiQQ7D9Rdgl7 bnML/4OtPz58gnhxSk8Ydu3Meck6YD73DtQyIOUVbMFTMgVPxXFIl14cDWLG24QkxtjIgh Cp5C0cEc+FmByBtjkDfSVNf/nRVEHIA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-147-kWuHB4ZwM6e9BjdZ3BQBgQ-1; Fri, 31 Jan 2020 06:50:18 -0500 X-MC-Unique: kWuHB4ZwM6e9BjdZ3BQBgQ-1 Received: by mail-wr1-f69.google.com with SMTP id u8so2242214wrp.10 for ; Fri, 31 Jan 2020 03:50:18 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=nQ17yO5W5w5qlWY/ou9U5Zs/oUqInXzTRAcl/4EyG5I=; b=q0POZ5jKBVgicu9XTK8dp6NV8+SA56SOZgMvZrscW2X+AoKq+zTc3tXtqiW7rFheX0 ergy6npIncTckvN8CbqIhNbxiShUFmlL8ZRQ/FWigkawL6wYMj4gVvM5fbW2TPhP6Ss2 yapSEvs7Lhip5PLHc7HjI+wWenej/vNhzHgLUElPbczt4T36MlqEdCP4MZbJcI+V5MLO BhyNj61Z8z4wbecF3uMXgop5poFnNzaU/dJJjSbdAXllH4+4XCi9xjiyKqZuL5EdpHLc EFXzhHyerkQkHCp0Y3sbRxb7+nt8x4ROEthqeZpshdsFQ352/4sLSEHNdLov/ZbkZJ+G nOrA== X-Gm-Message-State: APjAAAU388jo/SAUTD1rF4gnbv1OgdWLNLFUFcp0SDzPHzIX4wc9HZhA e2uenDU/kbyjA5K3h2IbwKwafz0JUzj9ykl6G3vW03B4xtUpfbCRWlJhLl7Ik/BT4f6kGyx71kE c9szdXKWXDDQrxLZEGA3SHseXvQ== X-Received: by 2002:a7b:c392:: with SMTP id s18mr11697472wmj.169.1580471417371; Fri, 31 Jan 2020 03:50:17 -0800 (PST) X-Google-Smtp-Source: APXvYqywPWhJTRUZpBkOIsW+lcecG5d1oMkcsu1k0suFAsbAcNAiz2UC4Oc6MWvdVzVLHNED2OGdiQ== X-Received: by 2002:a7b:c392:: with SMTP id s18mr11697450wmj.169.1580471417132; Fri, 31 Jan 2020 03:50:17 -0800 (PST) Received: from miu.piliscsaba.redhat.com (84-236-74-45.pool.digikabel.hu. [84.236.74.45]) by smtp.gmail.com with ESMTPSA id s1sm2746622wro.66.2020.01.31.03.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 03:50:16 -0800 (PST) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Vivek Goyal Subject: [PATCH 4/4] ovl: alllow remote upper Date: Fri, 31 Jan 2020 12:50:04 +0100 Message-Id: <20200131115004.17410-5-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200131115004.17410-1-mszeredi@redhat.com> References: <20200131115004.17410-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No reason to prevent upper layer being a remote filesystem. Do the revalidation in that case, just as we already do for lower layers. This lets virtiofs be used as upper layer, which appears to be a real use case. Signed-off-by: Miklos Szeredi --- fs/overlayfs/namei.c | 3 +-- fs/overlayfs/super.c | 8 ++++++-- fs/overlayfs/util.c | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 76e61cc27822..0db23baf98e7 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -845,8 +845,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, if (err) goto out; - if (upperdentry && (upperdentry->d_flags & DCACHE_OP_REAL || - unlikely(ovl_dentry_remote(upperdentry)))) { + if (upperdentry && upperdentry->d_flags & DCACHE_OP_REAL) { dput(upperdentry); err = -EREMOTE; goto out; diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 26d4153240a8..ed3a11db9039 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -135,9 +135,14 @@ static int ovl_dentry_revalidate_common(struct dentry *dentry, unsigned int flags, bool weak) { struct ovl_entry *oe = dentry->d_fsdata; + struct dentry *upper; unsigned int i; int ret = 1; + upper = ovl_dentry_upper(dentry); + if (upper) + ret = ovl_revalidate_real(upper, flags, weak); + for (i = 0; ret > 0 && i < oe->numlower; i++) { ret = ovl_revalidate_real(oe->lowerstack[i].dentry, flags, weak); @@ -747,8 +752,7 @@ static int ovl_mount_dir(const char *name, struct path *path) ovl_unescape(tmp); err = ovl_mount_dir_noesc(tmp, path); - if (!err && (ovl_dentry_remote(path->dentry) || - path->dentry->d_flags & DCACHE_OP_REAL)) { + if (!err && path->dentry->d_flags & DCACHE_OP_REAL) { pr_err("filesystem on '%s' not supported as upperdir\n", tmp); path_put_init(path); diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 3ad8fb291f7d..c793722739e1 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -96,6 +96,8 @@ void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry, struct ovl_entry *oe = OVL_E(dentry); unsigned int i, flags = 0; + if (upperdentry) + flags |= upperdentry->d_flags; for (i = 0; i < oe->numlower; i++) flags |= oe->lowerstack[i].dentry->d_flags;