From patchwork Wed Sep 27 10:47:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9973731 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 C73F46037F for ; Wed, 27 Sep 2017 10:47:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF8D328628 for ; Wed, 27 Sep 2017 10:47:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3B9628712; Wed, 27 Sep 2017 10:47:07 +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 EDDF728628 for ; Wed, 27 Sep 2017 10:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163AbdI0KrG (ORCPT ); Wed, 27 Sep 2017 06:47:06 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50622 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752157AbdI0KrF (ORCPT ); Wed, 27 Sep 2017 06:47:05 -0400 Received: by mail-wm0-f68.google.com with SMTP id b195so16645157wmb.5; Wed, 27 Sep 2017 03:47:04 -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=JsF/YpTkELGy/OzX1CZsuI5jJHgWtYuXfAbyMlNVa1w=; b=sHpuHJwtcrbcuM+jI4PvTeke95CV4a+kB31D1dLYdDt6tYQ5PSHab9a/xjIqiIeotO 5yOWKk7w05+Ydz7yh4+ftLQvMwgvHjNY+IYjQkgIMoha8K9iFFgAMB55QpVATKb0rSK1 399xV4PCnf8/TiL7jwVsl2qgliITuuZstpR9v08PkJq/XDEEwihP2iClTiINXC60wxhh MClWxF/CG9m1+Y88V68CkJerZQ6KatxiU0JNd02gC4+1mYDYn8hz4mBf8zVrhGWornJx 7Ok5zkOMklT7HH6zjcz29bG7AGtjBV5aUZYW7aCelOMRfFMBBN/C3lqsjO9vwhpwsUeS pHeQ== 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=JsF/YpTkELGy/OzX1CZsuI5jJHgWtYuXfAbyMlNVa1w=; b=glEAK0xIO3092k3Jts1+ft5p6ac9lxBrjGIvUZBqDSAoimnjcb7Gp8NLGx6QfyPYCV 4jJXkecVOvbSMeJNEs9jb8/Im3z0SsFcuPI/01KKswfqG53GSyO/uCDSmF9Tj5kL2EA0 VYeQk503lieDxlMPuxrIBoFgnuQrWKiX9vKpKlo9MzwHyFLEpHSZGK06EL4DkIiXI5hA gJIVRF3chcsnMGsZPxDfgIGQFicxDyBPKxfF2YKuqAv6WA5a/V0JQ4Ly1HtUDcOx4ppp p1v8OkNXF+fpDUi4j5fjZBApm3rMFmV+iqTTQxuffn+VkzjMINQg3APnTxguMy3Hq7XD 9AJg== X-Gm-Message-State: AHPjjUg6JBwfW0cezA/AEr4oF3RdrMhs471zL/xaKotJ3Dn/LBpryM44 ydYvTIJjuKNJ0VNA/qoCRdU= X-Google-Smtp-Source: AOwi7QAvV7BtrwprwVSF9EL5cMxfzy6ARrOG7jNO5h6b6x73eCbmR+bNaN1RGEZMeYaYeypTHqITYg== X-Received: by 10.28.10.142 with SMTP id 136mr1103256wmk.92.1506509223447; Wed, 27 Sep 2017 03:47:03 -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 a19sm14866758wra.64.2017.09.27.03.47.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Sep 2017 03:47:02 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 5/5] overlay: move _overlay helpers to common/overlay Date: Wed, 27 Sep 2017 13:47:32 +0300 Message-Id: <1506509252-4582-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506495852-7295-1-git-send-email-amir73il@gmail.com> References: <1506495852-7295-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 Signed-off-by: Amir Goldstein --- Eryu, If you don't mind, please apply this cleanup patch on top of the OVERLAY_MOUNT_OPTIONS series. This is actaully a prep patch for implementing the first _check_overlay_filesystem, but might as well take it now. Amir. common/overlay | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/rc | 152 +----------------------------------------------------- 2 files changed, 162 insertions(+), 150 deletions(-) create mode 100644 common/overlay diff --git a/common/overlay b/common/overlay new file mode 100644 index 0000000..c3bb9ee --- /dev/null +++ b/common/overlay @@ -0,0 +1,160 @@ +# +# overlayfs specific common functions. +# + +# helper function to do the actual overlayfs mount operation +_overlay_mount_dirs() +{ + local lowerdir=$1 + local upperdir=$2 + local workdir=$3 + shift 3 + + $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \ + -o workdir=$workdir `_common_dev_mount_options $*` +} + +# Mount with same options/mnt/dev of scratch mount, but optionally +# with different lower/upper/work dirs +_overlay_scratch_mount_dirs() +{ + local lowerdir=$1 + local upperdir=$2 + local workdir=$3 + shift 3 + + _overlay_mount_dirs $lowerdir $upperdir $workdir \ + $* $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT +} + +_overlay_mkdirs() +{ + local dir=$1 + + mkdir -p $dir/$OVL_UPPER + mkdir -p $dir/$OVL_LOWER + mkdir -p $dir/$OVL_WORK + mkdir -p $dir/$OVL_MNT +} + +# Given a base fs dir, set up overlay directories and mount on the given mnt. +# The dir is used as the mount device so it can be seen from df or mount +_overlay_mount() +{ + local dir=$1 + local mnt=$2 + shift 2 + + _supports_filetype $dir || _notrun "upper fs needs to support d_type" + + _overlay_mkdirs $dir + + _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER $dir/$OVL_WORK \ + $* $dir $mnt +} + +_overlay_base_test_mount() +{ + if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \ + _check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \ + OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR + then + # no base fs or already mounted + return 0 + elif [ $? -ne 1 ] + then + # base fs mounted but not on mount point + return 1 + fi + + _mount $TEST_FS_MOUNT_OPTS \ + $SELINUX_MOUNT_OPTIONS \ + $OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR +} + +_overlay_test_mount() +{ + _overlay_base_test_mount && \ + _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $* +} + +_overlay_base_scratch_mount() +{ + if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \ + _check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \ + OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT + then + # no base fs or already mounted + return 0 + elif [ $? -ne 1 ] + then + # base fs mounted but not on mount point + return 1 + fi + + _mount $OVL_BASE_MOUNT_OPTIONS \ + $SELINUX_MOUNT_OPTIONS \ + $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT +} + +_overlay_base_scratch_unmount() +{ + [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0 + + $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT +} + +_overlay_scratch_mount() +{ + _overlay_base_scratch_mount && \ + _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $* +} + +_overlay_base_test_unmount() +{ + [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0 + + $UMOUNT_PROG $OVL_BASE_TEST_DIR +} + +_overlay_test_unmount() +{ + $UMOUNT_PROG $TEST_DIR + _overlay_base_test_unmount +} + +_overlay_scratch_unmount() +{ + $UMOUNT_PROG $SCRATCH_MNT + _overlay_base_scratch_unmount +} + +# Require a specific overlayfs feature +_require_scratch_overlay_feature() +{ + local feature=$1 + + # overalyfs features (e.g. redirect_dir, index) are + # configurable from Kconfig (the build default), by module + # parameter (the system default) and per mount by mount + # option ${feature}=[on|off]. + # + # If the module parameter does not exist then there is no + # point in checking the mount option. + local default=`_get_fs_module_param ${feature}` + [ "$default" = Y ] || [ "$default" = N ] || \ + _notrun "feature '${feature}' not supported by ${FSTYP}" + + _scratch_mkfs > /dev/null 2>&1 + _scratch_mount -o ${feature}=on || \ + _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}" + # Check options to be sure. For example, Overlayfs will fallback to + # index=off if underlying fs does not support file handles. + # Overlayfs only displays mount option if it differs from the default. + # Overlayfs may enable the feature, but fallback to read-only mount. + ((( [ "$default" = N ] && _fs_options $SCRATCH_DEV | grep -q "${feature}=on" ) || \ + ( [ "$default" = Y ] && ! _fs_options $SCRATCH_DEV | grep -q "${feature}=off" )) && \ + touch $SCRATCH_MNT/foo 2>/dev/null ) || \ + _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}" + _scratch_unmount +} diff --git a/common/rc b/common/rc index 54f81d3..201159b 100644 --- a/common/rc +++ b/common/rc @@ -171,6 +171,7 @@ case "$FSTYP" in glusterfs) ;; overlay) + . ./common/overlay ;; reiser4) [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found" @@ -333,133 +334,6 @@ _supports_filetype() esac } -# helper function to do the actual overlayfs mount operation -_overlay_mount_dirs() -{ - local lowerdir=$1 - local upperdir=$2 - local workdir=$3 - shift 3 - - $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \ - -o workdir=$workdir `_common_dev_mount_options $*` -} - -# Mount with same options/mnt/dev of scratch mount, but optionally -# with different lower/upper/work dirs -_overlay_scratch_mount_dirs() -{ - local lowerdir=$1 - local upperdir=$2 - local workdir=$3 - shift 3 - - _overlay_mount_dirs $lowerdir $upperdir $workdir \ - $* $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT -} - -_overlay_mkdirs() -{ - local dir=$1 - - mkdir -p $dir/$OVL_UPPER - mkdir -p $dir/$OVL_LOWER - mkdir -p $dir/$OVL_WORK - mkdir -p $dir/$OVL_MNT -} - -# Given a base fs dir, set up overlay directories and mount on the given mnt. -# The dir is used as the mount device so it can be seen from df or mount -_overlay_mount() -{ - local dir=$1 - local mnt=$2 - shift 2 - - _supports_filetype $dir || _notrun "upper fs needs to support d_type" - - _overlay_mkdirs $dir - - _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER $dir/$OVL_WORK \ - $* $dir $mnt -} - -_overlay_base_test_mount() -{ - if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \ - _check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \ - OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR - then - # no base fs or already mounted - return 0 - elif [ $? -ne 1 ] - then - # base fs mounted but not on mount point - return 1 - fi - - _mount $TEST_FS_MOUNT_OPTS \ - $SELINUX_MOUNT_OPTIONS \ - $OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR -} - -_overlay_test_mount() -{ - _overlay_base_test_mount && \ - _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $* -} - -_overlay_base_scratch_mount() -{ - if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \ - _check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \ - OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT - then - # no base fs or already mounted - return 0 - elif [ $? -ne 1 ] - then - # base fs mounted but not on mount point - return 1 - fi - - _mount $OVL_BASE_MOUNT_OPTIONS \ - $SELINUX_MOUNT_OPTIONS \ - $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT -} - -_overlay_base_scratch_unmount() -{ - [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0 - - $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT -} - -_overlay_scratch_mount() -{ - _overlay_base_scratch_mount && \ - _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $* -} - -_overlay_base_test_unmount() -{ - [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0 - - $UMOUNT_PROG $OVL_BASE_TEST_DIR -} - -_overlay_test_unmount() -{ - $UMOUNT_PROG $TEST_DIR - _overlay_base_test_unmount -} - -_overlay_scratch_unmount() -{ - $UMOUNT_PROG $SCRATCH_MNT - _overlay_base_scratch_unmount -} - _scratch_mount() { if [ "$FSTYP" == "overlay" ]; then @@ -3672,29 +3546,7 @@ _require_scratch_feature() case "$FSTYP" in overlay) - # overalyfs features (e.g. redirect_dir, index) are - # configurable from Kconfig (the build default), by module - # parameter (the system default) and per mount by mount - # option ${feature}=[on|off]. - # - # If the module parameter does not exist then there is no - # point in checking the mount option. - local default=`_get_fs_module_param ${feature}` - [ "$default" = Y ] || [ "$default" = N ] || \ - _notrun "feature '${feature}' not supported by ${FSTYP}" - - _scratch_mkfs > /dev/null 2>&1 - _scratch_mount -o ${feature}=on || \ - _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}" - # Check options to be sure. For example, Overlayfs will fallback to - # index=off if underlying fs does not support file handles. - # Overlayfs only displays mount option if it differs from the default. - # Overlayfs may enable the feature, but fallback to read-only mount. - ((( [ "$default" = N ] && _fs_options $SCRATCH_DEV | grep -q "${feature}=on" ) || \ - ( [ "$default" = Y ] && ! _fs_options $SCRATCH_DEV | grep -q "${feature}=off" )) && \ - touch $SCRATCH_MNT/foo 2>/dev/null ) || \ - _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}" - _scratch_unmount + _require_scratch_overlay_feature ${feature} ;; *) _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"