From patchwork Thu Jun 4 13:29:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 6547281 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D11BB9F443 for ; Thu, 4 Jun 2015 13:30:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD107204D9 for ; Thu, 4 Jun 2015 13:30:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2AFC207E6 for ; Thu, 4 Jun 2015 13:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932141AbbFDNaX (ORCPT ); Thu, 4 Jun 2015 09:30:23 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:35497 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932093AbbFDNaE (ORCPT ); Thu, 4 Jun 2015 09:30:04 -0400 Received: by wiga1 with SMTP id a1so47875033wig.0 for ; Thu, 04 Jun 2015 06:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7Od9UECdeu9MZmX6Ozw6gyiEIVX1+bLaihXyD8nWxds=; b=ixLrhSDhYCRxaOOyYw4kWatngTyngKp14THoT3RGtAeJrA78WAFMh/qnar2wHUdxE5 d/N4xSXM9nro6xk0Q9riagwJ5vQCxU0QRzlPm9bidLUIkf7JtH1IEUVFRcolDaHHAriT iODxERo+eYm2Tr1FcT2tia/8OYQllyn6vC7mo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7Od9UECdeu9MZmX6Ozw6gyiEIVX1+bLaihXyD8nWxds=; b=iFlxWqYJ+6G/Mzs+rpJXAOcwaYcYj9WNND6TjuaiRqBlvRQ8U1A8YyJMBBF9C01934 xryAUUReuanLlQZz7/4H+54chaaHKqG8TusZiJPnU0Se6tJpXAr6esE5v5Yx1qihZc0K fk303fKbWcdes7EQX5pAGJun4Evrdt3SkYBupNYGoOZvVNLkFLet9WaEzmppPfSjPPYG ycblyvd6fUjimOPxB7/fql2jydOdeKjbzu1cqF9Oqles9trxyJGKZ9OteidXGGxJJeYi ubD4zQ5Hzpq8A9hsjH3vb885afnyfdH4umH+udVUUV9ev+WxFxgbMzi2Z6pDnjwN+oSU a1mQ== X-Gm-Message-State: ALoCoQkOlEbIb4HZ3WwJR5UhmdqYansbfHfEgKxz1Rwz7xCyJwBErsBj5xcRWJ3NVH874OluZ02t X-Received: by 10.180.96.167 with SMTP id dt7mr7685893wib.80.1433424603386; Thu, 04 Jun 2015 06:30:03 -0700 (PDT) Received: from tucsk.pomaz.szeredi.hu (pool-dsl-26-0066.externet.hu. [217.173.38.102]) by mx.google.com with ESMTPSA id pd7sm5792736wjb.27.2015.06.04.06.30.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jun 2015 06:30:02 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: sa-dev@rainbow.by, andre.roth@roche.com Subject: [PATCH 2/2] ovl: allow distributed fs as lower layer Date: Thu, 4 Jun 2015 15:29:46 +0200 Message-Id: <1433424586-7771-3-git-send-email-miklos@szeredi.hu> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433424586-7771-1-git-send-email-miklos@szeredi.hu> References: <1433424586-7771-1-git-send-email-miklos@szeredi.hu> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miklos Szeredi Allow filesystems with .d_revalidate as lower layer(s), but not as upper layer. For local filesystems the rule was that modifications on the layers directly while being part of the overlay results in undefined behavior. This can easily be extended to distributed filesystems: we assume the tree used as lower layer is static, which means ->d_revalidate() should always return "1". If that is not the case, return -ESTALE, don't try to work around the modification. Signed-off-by: Miklos Szeredi --- fs/overlayfs/super.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index de9d2ee68ccf..822e6bbe7bf7 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -273,10 +273,52 @@ static void ovl_dentry_release(struct dentry *dentry) } } +static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) +{ + 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 ? ret : -ESTALE; + } + } + return 1; +} + +static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) +{ + 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) + return ret ? ret : -ESTALE; + } + } + return 1; +} + static const struct dentry_operations ovl_dentry_operations = { .d_release = ovl_dentry_release, }; +static const struct dentry_operations ovl_reval_dentry_operations = { + .d_release = ovl_dentry_release, + .d_revalidate = ovl_dentry_revalidate, + .d_weak_revalidate = ovl_dentry_weak_revalidate, +}; + static struct ovl_entry *ovl_alloc_entry(unsigned int numlower) { size_t size = offsetof(struct ovl_entry, lowerstack[numlower]); @@ -705,18 +747,23 @@ static bool ovl_is_allowed_fs_type(struct dentry *root) /* * We don't support: * - autofs - * - filesystems with revalidate (FIXME for lower layer) * - filesystems with case insensitive names */ if (dop && (dop->d_manage || - dop->d_revalidate || dop->d_weak_revalidate || dop->d_compare || dop->d_hash)) { return false; } return true; } +static bool ovl_remote(struct dentry *root) +{ + const struct dentry_operations *dop = root->d_op; + + return dop && (dop->d_revalidate || dop->d_weak_revalidate); +} + static int ovl_mount_dir_noesc(const char *name, struct path *path) { int err = -EINVAL; @@ -755,13 +802,21 @@ static int ovl_mount_dir(const char *name, struct path *path) if (tmp) { ovl_unescape(tmp); err = ovl_mount_dir_noesc(tmp, path); + + if (!err) + if (ovl_remote(path->dentry)) { + pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n", + tmp); + path_put(path); + err = -EINVAL; + } kfree(tmp); } return err; } static int ovl_lower_dir(const char *name, struct path *path, long *namelen, - int *stack_depth) + int *stack_depth, bool *remote) { int err; struct kstatfs statfs; @@ -778,6 +833,9 @@ static int ovl_lower_dir(const char *name, struct path *path, long *namelen, *namelen = max(*namelen, statfs.f_namelen); *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth); + if (ovl_remote(path->dentry)) + *remote = true; + return 0; out_put: @@ -831,6 +889,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) unsigned int numlower; unsigned int stacklen = 0; unsigned int i; + bool remote = false; int err; err = -ENOMEM; @@ -904,7 +963,8 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) lower = lowertmp; for (numlower = 0; numlower < stacklen; numlower++) { err = ovl_lower_dir(lower, &stack[numlower], - &ufs->lower_namelen, &sb->s_stack_depth); + &ufs->lower_namelen, &sb->s_stack_depth, + &remote); if (err) goto out_put_lowerpath; @@ -962,7 +1022,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) if (!ufs->upper_mnt) sb->s_flags |= MS_RDONLY; - sb->s_d_op = &ovl_dentry_operations; + if (remote) + sb->s_d_op = &ovl_reval_dentry_operations; + else + sb->s_d_op = &ovl_dentry_operations; err = -ENOMEM; oe = ovl_alloc_entry(numlower);