From patchwork Wed Jul 12 12:07:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9836563 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 C5211602BD for ; Wed, 12 Jul 2017 12:07:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA46A28500 for ; Wed, 12 Jul 2017 12:07:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E45F2857F; Wed, 12 Jul 2017 12:07:50 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 1B4CA28500 for ; Wed, 12 Jul 2017 12:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756633AbdGLMHt (ORCPT ); Wed, 12 Jul 2017 08:07:49 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35255 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756539AbdGLMHs (ORCPT ); Wed, 12 Jul 2017 08:07:48 -0400 Received: by mail-wr0-f196.google.com with SMTP id y28so781068wrd.2; Wed, 12 Jul 2017 05:07:47 -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=lS2YFJYbL6DGgMPEuPibhEMt/75ZE7KtCGzh5XCDzNU=; b=Jn6ski1gOkZBye/w6zUEsw7RtjCTp59Ni2HuST6IArDKCBlrkha+TGIp/ItfOOJc/X ZWhyOjNggIycc/cKkWnak9P6PJg+4RzE9EOOPRVbC2m1GQnkeh/++ZOS68KiGCsayehK iN5vr/TiB6+QR6sQWkyF3hi3G824a+xslGr3Z6soHlV6YKe6UmqKCIoe+AeCHw6qqKN7 WHuuEfT3qJram9+O9OEv5Oj0t0Qv92Tu/44VYarMWknRzyv7ULBlP2fXBxFYlJATOwcQ qmS9qVNx2Cc+3HFv4BlfF9cWwSDLSlhngpNZKAPHqlPB5ChOCm3i0HyCivAP5wV5YI8J xeeA== 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=lS2YFJYbL6DGgMPEuPibhEMt/75ZE7KtCGzh5XCDzNU=; b=AVrt2fq2WyojvbpUa45IZZTyjevlGKnlAh9osZO6ZTy5N94AAgULTXCAoK37GVtuXX q8KB8bHTOLcfP1YN58ymoIO7tyIuARz/TCt+vQRX86JWoHt9RkS7qb6+inC+0olx4uDZ XKFhR7oZhgi4vJQn1fY7L5519zNEjQ2xTmIU+4sDxJLz/QJrMy/6BK0zBDnZ5X9PAaXH 6XrmHkuTDufi/CSHYOmx2YrGMavCPVpRSWls2JTzAFDs8xuROVIoXf1qrTXTyZ38yMB+ FsICT6vlkBNCYmK7kSzJD6l4odHCfmG1SqWw4nZqeQg5SILCnctyTtud3tyOkPRUH4aY HPXw== X-Gm-Message-State: AIVw113o9PAaaJJq/+q50AszYUlQAMzq+M+yOd/ty5GJK4tNob0PZD0M Z/AySqb279U0JA== X-Received: by 10.223.128.80 with SMTP id 74mr2977990wrk.9.1499861266893; Wed, 12 Jul 2017 05:07:46 -0700 (PDT) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id o131sm2362988wmd.26.2017.07.12.05.07.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Jul 2017 05:07:46 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 5/5] overlay: test mount error cases with exclusive directories Date: Wed, 12 Jul 2017 15:07:59 +0300 Message-Id: <1499861279-18789-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499802726-11045-6-git-send-email-amir73il@gmail.com> References: <1499802726-11045-6-git-send-email-amir73il@gmail.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Overlayfs is often used to mount several mounts that share a single lower dir, but every overlayfs mount should have its own private upperdir and private workdir. Overlayfs mount on kernel <= v4.12 does not check if upper/work dirs are currently in-use by another overlayfs mount on the system and bad things can happen with such configuration. Expect EBUSY when trying to mount overlay when: - Upper dir is in-use by another overlay mount - Work dir is in-use by another overlay mount This test does not depend on the overlay index feature. Signed-off-by: Amir Goldstein --- tests/overlay/036 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/036.out | 3 ++ tests/overlay/group | 1 + 3 files changed, 95 insertions(+) create mode 100755 tests/overlay/036 create mode 100644 tests/overlay/036.out diff --git a/tests/overlay/036 b/tests/overlay/036 new file mode 100755 index 0000000..d44efc1 --- /dev/null +++ b/tests/overlay/036 @@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 036 +# +# Test mount error cases with exclusive directories +# +# Overlayfs is often used to mount several mounts that share a single +# lower dir, but every overlayfs mount should have its own private +# upperdir and private workdir. +# +# Overlayfs mount on kernel <= v4.12 does not check if upper/work dirs +# are currently in-use by another overlayfs mount on the system and bad +# things can happen with such configuration. +# +# Expect EBUSY when trying to mount overlay when: +# - Upper dir is in-use by another overlay mount +# - Work dir is in-use by another overlay mount +# +#----------------------------------------------------------------------- +# Copyright (C) 2017 CTERA Networks. All Rights Reserved. +# Author: Amir Goldstein +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* + # unmount the two extra mounts in case they did not fail + $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null + $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_supported_os Linux +_require_scratch + +# Remove all files from previous tests +_scratch_mkfs + +# Create multiple lowerdirs, upperdirs and workdirs +lowerdir=$OVL_BASE_SCRATCH_MNT/lower +lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2 +upperdir=$OVL_BASE_SCRATCH_MNT/upper +upperdir2=$OVL_BASE_SCRATCH_MNT/upper2 +workdir=$OVL_BASE_SCRATCH_MNT/workdir +workdir2=$OVL_BASE_SCRATCH_MNT/workdir2 +mkdir -p $lowerdir $lowerdir2 $upperdir $upperdir2 $workdir $workdir2 + +# Mount overlay with lowerdir, upperdir, workdir +_overlay_mount_dirs $lowerdir $upperdir $workdir \ + overlay1 $SCRATCH_MNT +# Try to mount another overlay with the same upperdir - expect EBUSY +_overlay_mount_dirs $lowerdir2 $upperdir $workdir2 \ + overlay2 $SCRATCH_MNT 2>&1 | _filter_scratch +# Try to mount another overlay with the same workdir - expect EBUSY +_overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \ + overlay3 $SCRATCH_MNT 2>&1 | _filter_scratch + +# success, all done +status=0 +exit diff --git a/tests/overlay/036.out b/tests/overlay/036.out new file mode 100644 index 0000000..5174611 --- /dev/null +++ b/tests/overlay/036.out @@ -0,0 +1,3 @@ +QA output created by 036 +mount: overlay2 is already mounted or SCRATCH_MNT busy +mount: overlay3 is already mounted or SCRATCH_MNT busy diff --git a/tests/overlay/group b/tests/overlay/group index 87e3aaf..4cc1d74 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -38,3 +38,4 @@ 033 auto quick copyup hardlink 034 auto quick copyup hardlink 035 auto quick mount +036 auto quick mount