From patchwork Fri Jan 27 08:56:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9540861 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 6C08160429 for ; Fri, 27 Jan 2017 09:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 648C020952 for ; Fri, 27 Jan 2017 09:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A6B27FC0; Fri, 27 Jan 2017 09:24:35 +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 C251720952 for ; Fri, 27 Jan 2017 09:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932344AbdA0JXy (ORCPT ); Fri, 27 Jan 2017 04:23:54 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33031 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754581AbdA0JXe (ORCPT ); Fri, 27 Jan 2017 04:23:34 -0500 Received: by mail-wm0-f65.google.com with SMTP id r144so56875942wme.0; Fri, 27 Jan 2017 01:23:33 -0800 (PST) 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=PUOHQsv42rNPL1Yen2JQlBeEvGCLzqaDrpMpzuMVlc8=; b=AVIszlfRDr2sFK+waQwz9ZG2VUJhZQCPVjlGi0m4dAb7nfRJAsNiFsrKowoZPDQaNq JezpdF8nktvISkmPO5+tqhGJuHDEMmKAgqoUpoDYqKdPTrkWsDAzeL73qdhw3j2VUGoh O3pZ7F9jAWUaMKygu7ns7CruqfUqNtG/RjopwAaeu81TkB8n0yDFfZWDQT9IXSj/Q+la JFOwqluywf/VvGQDEtwN2Pu4fyY1PbaRNo+IP3IRW6uO3fFtp/1e08xjMJTmLojvLL/O YscZdtzJPAL7Y4Rufzq0tnzSXfrtx2S6pE+OjGd7Yj4s0Q1y2TTNLTHi9zU56IUNHR2S APeg== 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=PUOHQsv42rNPL1Yen2JQlBeEvGCLzqaDrpMpzuMVlc8=; b=UUcp3MmP/w+lIULd2NQYdg1QP116Q29sFKsP1A2yyVqVnwaLpbTQdTW9yFXInchN4R Z43ioNvvI5WdtmREr8Pubv+lhncVb91y8EJEAQx9ynG905k+qKDahRKtNLcILkpOoHtn coZhHRE8xQXXyY6ZJZOkVjQvw+o3L7p0Yj8Bhf6Hvs7PE6UM2t0Zr+DTUUL4TelWC5cj e6mK2CWnsQ6GfTv7AeeWXreLiHoGgHAU4237VnjgRWOGYWbaaO6eYvVJZCyh+irVVy2o clYCaflPCqJq+DEfjaf4aj4HDVPu9isdi++AQn7I2xu+jQDSf3RWHD57gKwmsYSoGVZw cg3w== X-Gm-Message-State: AIkVDXKEneatqW+SzXf3bYOjqw8VsYgv1jfzAfH4tkjMtgEnnPzOumISHJwzDgvSbl5ENA== X-Received: by 10.28.155.5 with SMTP id d5mr517645wme.85.1485507381194; Fri, 27 Jan 2017 00:56:21 -0800 (PST) Received: from amir-VirtualBox.Home (bzq-79-176-143-83.red.bezeqint.net. [79.176.143.83]) by smtp.gmail.com with ESMTPSA id n13sm6697916wrn.40.2017.01.27.00.56.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jan 2017 00:56:20 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 3/3] overlay: mount/unmount base fs before/after running tests Date: Fri, 27 Jan 2017 10:56:05 +0200 Message-Id: <1485507365-29012-4-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485507365-29012-1-git-send-email-amir73il@gmail.com> References: <1485507365-29012-1-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 Optionally configure TEST/SCRATCH_BASE_DEV, for overlay base fs to be mounted/unmounted before/after running tests. For example: +export TEST_BASE_DEV=/dev/mapper/base-test export TEST_BASE_MNT=/mnt/base/test +export SCRATCH_BASE_DEV=/dev/mapper/base-scratch export SCRATCH_BASE_MNT=/mnt/base/scratch export TEST_DIR=/mnt/test export SCRATCH_MNT=/mnt/scratch export FSTYP=overlay With this change, the base fs is mounted before running tests, unmounted after running tests and recycled on _test_cycle_mount along with the overlay mounts. This helps catching overlayfs bugs related to leaking objects in underlying (base) fs. The standard way that overlay tests work is: - _scratch_mkfs - setup lower/upper dir files - _scratch_mount (or custom overlay mount) - (sometimes) _scratch_unmount/_scratch_mount recycle To preserve expected tests behavior, the semantics are: - _scratch_mkfs mounts the base fs, cleans the lower/upper dirs and keeps base fs mounted. - _scratch_mount mounts or recycles base fs and mounts overlay - _scratch_unmount unmounts overlay and base fs Tests that use _scratch_unmount to unmount a custom overlay mount and expect to have access to overlay base dir, were converted to use explicit umount $SCRATCH_MNT instead. --- common/config | 6 +++++- common/rc | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/overlay/003 | 3 ++- tests/overlay/004 | 3 ++- tests/overlay/014 | 5 +++-- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/common/config b/common/config index db5721c..f431a8d 100644 --- a/common/config +++ b/common/config @@ -35,7 +35,9 @@ # RMT_TAPE_DEV - the remote tape device for the xfsdump tests # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests # RMT_TAPE_USER - remote user for tape device +# TEST_BASE_DEV - device for base fs containing overlay test dirs # TEST_BASE_MNT - mount point for base fs of overlay test dirs +# SCRATCH_BASE_DEV- device for base fs containing overlay scratch dirs # SCRATCH_BASE_MNT- mount point for base fs of overlay scratch dirs # # - These can be added to $HOST_CONFIG_DIR (witch default to ./config) @@ -470,11 +472,12 @@ _config_overlay() [ -z "$TEST_DEV" ] || export TEST_BASE_DIR="$TEST_DEV" [ -z "$SCRATCH_DEV" ] || export SCRATCH_BASE_DIR="$SCRATCH_DEV" - # 2. set SCRATCH/TEST_BASE_MNT to configure base fs. + # 2. set SCRATCH/TEST_BASE_DEV/MNT to configure base fs. # SCRATCH/TEST_DEV are derived from SCRATCH/TEST_BASE_MNT # and therein, overlay fs directories will be created. [ -n "$TEST_BASE_MNT" ] || return + _check_device TEST_BASE_DEV optional $TEST_BASE_DEV if [ ! -d "$TEST_BASE_MNT" ]; then echo "common/config: Error: \$TEST_BASE_MNT ($TEST_BASE_MNT) is not a directory" exit 1 @@ -486,6 +489,7 @@ _config_overlay() [ -n "$SCRATCH_BASE_MNT" ] || return + _check_device SCRATCH_BASE_DEV optional $SCRATCH_BASE_DEV if [ ! -d "$SCRATCH_BASE_MNT" ]; then echo "common/config: Error: \$SCRATCH_BASE_MNT ($SCRATCH_BASE_MNT) is not a directory" exit 1 diff --git a/common/rc b/common/rc index f5ab869..5033ed4 100644 --- a/common/rc +++ b/common/rc @@ -320,24 +320,62 @@ _overlay_mount() $SELINUX_MOUNT_OPTIONS $* $dir $mnt } +_overlay_test_base_mount() +{ + if [ -n "$TEST_BASE_DEV" -a -n "$TEST_BASE_MNT" ]; then + _mount $TEST_BASE_MOUNT_OPTIONS \ + $SELINUX_MOUNT_OPTIONS \ + $TEST_BASE_DEV $TEST_BASE_MNT + fi +} + _overlay_test_mount() { + _overlay_test_base_mount _overlay_mount $TEST_BASE_DIR $TEST_DIR $* } +_overlay_scratch_base_mount() +{ + if [ -n "$SCRATCH_BASE_DEV" -a -n "$SCRATCH_BASE_MNT" ]; then + _mount $SCRATCH_BASE_MOUNT_OPTIONS \ + $SELINUX_MOUNT_OPTIONS \ + $SCRATCH_BASE_DEV $SCRATCH_BASE_MNT + fi +} + +_overlay_scratch_base_unmount() +{ + if [ -n "$SCRATCH_BASE_DEV" -a -n "$SCRATCH_BASE_MNT" ]; then + $UMOUNT_PROG $SCRATCH_BASE_MNT + fi +} + _overlay_scratch_mount() { + # base fs may be mounted after overlay mkfs + _overlay_scratch_base_unmount 2>/dev/null + _overlay_scratch_base_mount _overlay_mount $SCRATCH_BASE_DIR $SCRATCH_MNT $* } +_overlay_test_base_unmount() +{ + if [ -n "$TEST_BASE_DEV" -a -n "$TEST_BASE_MNT" ]; then + $UMOUNT_PROG $TEST_BASE_MNT + fi +} + _overlay_test_unmount() { $UMOUNT_PROG $TEST_DIR + _overlay_test_base_unmount } _overlay_scratch_unmount() { $UMOUNT_PROG $SCRATCH_MNT + _overlay_scratch_base_unmount } _scratch_mount() @@ -643,7 +681,11 @@ _scratch_cleanup_files() overlay) # Avoid rm -rf /* if we messed up [ -n "$SCRATCH_BASE_DIR" ] || return + # overlay 'mkfs' needs to make sure base fs is mounted and clean + _overlay_scratch_base_unmount 2>/dev/null + _overlay_scratch_base_mount rm -rf $SCRATCH_BASE_DIR/* + # leave base fs mouted so tests can setup lower dir ;; *) [ -n "$SCRATCH_MNT" ] || return diff --git a/tests/overlay/003 b/tests/overlay/003 index bb59700..81aea85 100755 --- a/tests/overlay/003 +++ b/tests/overlay/003 @@ -89,7 +89,8 @@ rm -rf ${SCRATCH_MNT}/* # nothing should be listed ls ${SCRATCH_MNT}/ -_scratch_unmount +# unmount overlayfs but not base fs +$UMOUNT_PROG $SCRATCH_MNT rm -rf $lowerdir echo "Silence is golden" diff --git a/tests/overlay/004 b/tests/overlay/004 index 6d78f9f..26ac547 100755 --- a/tests/overlay/004 +++ b/tests/overlay/004 @@ -85,7 +85,8 @@ _user_do "chmod g+t ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1" _user_do "chmod u-X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1" stat -c %a ${SCRATCH_MNT}/attr_file2 -_scratch_unmount +# unmount overlayfs but not base fs +$UMOUNT_PROG $SCRATCH_MNT # check mode bits of the file that has been copied up, and # the file that should not have been copied up. diff --git a/tests/overlay/014 b/tests/overlay/014 index 7426c31..6519432 100755 --- a/tests/overlay/014 +++ b/tests/overlay/014 @@ -73,7 +73,8 @@ mkdir -p $lowerdir1/testdir/d _overlay_mount_dirs $lowerdir1 $lowerdir2 $workdir $SCRATCH_BASE_DIR $SCRATCH_MNT rm -rf $SCRATCH_MNT/testdir mkdir -p $SCRATCH_MNT/testdir/visibledir -_scratch_unmount +# unmount overlayfs but not base fs +$UMOUNT_PROG $SCRATCH_MNT # mount overlay again, with lowerdir1 and lowerdir2 as multiple lowerdirs, # and create a new file in testdir, triggers copyup from lowerdir, @@ -84,7 +85,7 @@ touch $SCRATCH_MNT/testdir/visiblefile # umount and mount overlay again, buggy kernel treats the copied-up dir as # opaque, visibledir is not seen in merged dir. -_scratch_unmount +$UMOUNT_PROG $SCRATCH_MNT _overlay_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir \ $SCRATCH_BASE_DIR $SCRATCH_MNT ls $SCRATCH_MNT/testdir