From patchwork Thu Sep 28 11:55:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9975863 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 6D57360365 for ; Thu, 28 Sep 2017 11:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F2DF2955E for ; Thu, 28 Sep 2017 11:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53C6429575; Thu, 28 Sep 2017 11:54:45 +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 680952955E for ; Thu, 28 Sep 2017 11:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752580AbdI1Lym (ORCPT ); Thu, 28 Sep 2017 07:54:42 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38181 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752359AbdI1Lyl (ORCPT ); Thu, 28 Sep 2017 07:54:41 -0400 Received: by mail-wr0-f194.google.com with SMTP id p37so1807794wrb.5; Thu, 28 Sep 2017 04:54:41 -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=RRUfmpGn2p5JxIrDlYdef5/9U9nZjp9XCRdeHKt+oP0=; b=Afj/Ilvstsoo05epQiElbvR/PgtrhjTF0gBra4EaGoJJN+bIjPibksmHKoJobKqnVS EKAbko6Ph+vsVFc+7eMM7SV4z8qT9VOpelT5Np5Xre5dmnwk/Ea1Arj8bRY1N1akPhgC 8DlYGYYNV1KsXxdLPn1DB43xO9YhaKdgKLYxdc3nZ4VM2UCjebMEVNwVTNN0l1zyqYO/ 89sTbYJVioP0G+YAo9/tLzTCcap16ho6F1bRnMoT4OKHSSZU6LoHCbpxwxozHBkuLaZe /0sIHgG+ofqnma8UZRudBNT7RIsouyZ1Vhz2swtsza8Qqbh/o5dZNmcqtuF6D55wMvSg 3w4A== 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=RRUfmpGn2p5JxIrDlYdef5/9U9nZjp9XCRdeHKt+oP0=; b=fGoYHfEpmN8PupqCKNnpeKV2RjvyUKN2YqGw6aJqrGzcFGppkakxSqTAt0N2lYrDJD 7UuqyxewZuvBdHHkYoMxkGzga/XIs4SvW3W7vaiVLMeGswVH+SDx3atb1vLV3GGUSOxH AFfNvSocCk6PtXkUENT8v05nvMfCpKGfAZaf0FEU2gxcJJLyzZqVOJeu1eAA9encNPXO ufJxpa6L7KIKsc+8T3VqNZbMqMhxEq/ASkgn414/q99FD+Q/urOVySaezfgwP4eIu0+N ivPbnJ8o8JIdCVQDiVm4gkZqsjvrDjTytpuV04LMQAZbWbk0LoH4yGTL95HgtOrwc6Hh z8dw== X-Gm-Message-State: AHPjjUgv5c48Lj4LaillwgVJsS3zzsChKazlHhuXmwxx8aFad14FI/JY wQfZOE+CuDxXf/oc8ftIxSbNrw== X-Google-Smtp-Source: AOwi7QDKZBBdanUcemDcjBEY1ZqPQiJVjNJ9Zt0uAkkNeLAfwCWroMQgwsNrHg5o0E3XsapJzMNIww== X-Received: by 10.223.199.130 with SMTP id l2mr696456wrg.113.1506599680325; Thu, 28 Sep 2017 04:54:40 -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 56sm695110wrx.2.2017.09.28.04.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Sep 2017 04:54:38 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 6/6] overlay: deduplicate code in overlay mount helpers Date: Thu, 28 Sep 2017 14:55:10 +0300 Message-Id: <1506599710-9751-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 factor out helpers _overlay_base_mount() and _overlay_base_umount() to reduce code duplication. Signed-off-by: Amir Goldstein --- Eryu, Appologies for the rolling series, but since you said you are looking into re-factoring mount option handling, I figured you may want to take this additional cleanup as well. Beyond reducing code duplication, this change puts the difference in mount options for base test fs and base scratch fs in wrapper functions and leaves the common code free of those differences. Amir. common/overlay | 66 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/common/overlay b/common/overlay index c3bb9ee..79097ba 100644 --- a/common/overlay +++ b/common/overlay @@ -53,23 +53,31 @@ _overlay_mount() $* $dir $mnt } -_overlay_base_test_mount() +_overlay_base_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 + local devname=$1 + local mntname=$2 + local dev=$3 + local mnt=$4 + shift 4 + + if [ -z "$dev" -o -z "$mnt" ] || \ + _check_mounted_on $devname $dev $mntname $mnt; then # no base fs or already mounted return 0 - elif [ $? -ne 1 ] - then + 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 + _mount $* $dev $mnt +} + +_overlay_base_test_mount() +{ + _overlay_base_mount OVL_BASE_TEST_DEV OVL_BASE_TEST_DIR \ + "$OVL_BASE_TEST_DEV" "$OVL_BASE_TEST_DIR" \ + $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS } _overlay_test_mount() @@ -80,28 +88,9 @@ _overlay_test_mount() _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_base_mount OVL_BASE_SCRATCH_DEV OVL_BASE_SCRATCH_MNT \ + "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT" \ + $OVL_BASE_MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS } _overlay_scratch_mount() @@ -110,23 +99,26 @@ _overlay_scratch_mount() _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $* } -_overlay_base_test_unmount() +_overlay_base_unmount() { - [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0 + local dev=$1 + local mnt=$2 + + [ -n "$dev" -a -n "$mnt" ] || return 0 - $UMOUNT_PROG $OVL_BASE_TEST_DIR + $UMOUNT_PROG $mnt } _overlay_test_unmount() { $UMOUNT_PROG $TEST_DIR - _overlay_base_test_unmount + _overlay_base_unmount "$OVL_BASE_TEST_DEV" "$OVL_BASE_TEST_DIR" } _overlay_scratch_unmount() { $UMOUNT_PROG $SCRATCH_MNT - _overlay_base_scratch_unmount + _overlay_base_unmount "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT" } # Require a specific overlayfs feature