From patchwork Tue Feb 14 00:55:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 9570919 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 1E0F960589 for ; Tue, 14 Feb 2017 00:55:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C59F28174 for ; Tue, 14 Feb 2017 00:55:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0182428178; Tue, 14 Feb 2017 00:55:54 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 AA56F28174 for ; Tue, 14 Feb 2017 00:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751534AbdBNAzy (ORCPT ); Mon, 13 Feb 2017 19:55:54 -0500 Received: from imap.thunk.org ([74.207.234.97]:36762 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751477AbdBNAzx (ORCPT ); Mon, 13 Feb 2017 19:55:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=v8GT37JHp9IQ6XlociKlGGvaY5r3uMex2vUOVyxW3xk=; b=kgQ4P1i0oDQ1nGTios/wOSA7BedPGBw183VlMS/pINo3RXh3HfTrwveifWLq/kEPQw/J1eAI0zCRWEJPJBVq87dkNuU7rGWF97Q0yn+F0E9hdz57hbqrBlhV0ugATnqgYpmWcvUMHL/tdxKdnjDbzKRSe0UZWIJSYkEaOTcY/RY=; Received: from root (helo=callcc.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.84_2) (envelope-from ) id 1cdRPL-0000LI-Gr; Tue, 14 Feb 2017 00:55:51 +0000 Received: by callcc.thunk.org (Postfix, from userid 15806) id E2D41C006B9; Mon, 13 Feb 2017 19:55:50 -0500 (EST) From: Theodore Ts'o To: fstests@vger.kernel.org Cc: Zorro Lang , Theodore Ts'o Subject: [PATCH 1/4] common/rc: new functions for multi-level mount/umount operations Date: Mon, 13 Feb 2017 19:55:42 -0500 Message-Id: <20170214005545.29373-2-tytso@mit.edu> X-Mailer: git-send-email 2.11.0.rc0.7.gbe5a750 In-Reply-To: <20170214005545.29373-1-tytso@mit.edu> References: <20170214005545.29373-1-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Zorro Lang When I try to write cases about mount shared subtrees test, I find I always need to do many mount operations, then then umount those mount point one by one. For make the code clear, I use a stack to save mounted points sequentially, then I write 3 common functions to operate this stack. 1. The global stack named MOUNTED_POINT_STACK 2. _get_mount() accept mount parameters likes _mount(), but the mountpoint parameter must be the last one. It will run the mount operation and push the mountpoint name into stack. 3. _put_mount() don't need any parameters. It will pull the newest mountpoint name from the stack, and umount it. 4. _clear_mount_stack() don't need any parameters either. It will umount all mountpoints in the stack sequentially, and set MOUNTED_POINT_STACK="" Generally, the _clear_mount_stack() function also can be used as _init_mount_stack() at the beginning of a case. Because it will prepare an empty stack. Signed-off-by: Zorro Lang Signed-off-by: Theodore Ts'o --- common/rc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/common/rc b/common/rc index 2f4778f4..0771a06a 100644 --- a/common/rc +++ b/common/rc @@ -160,6 +160,37 @@ _mount() $MOUNT_PROG `_mount_ops_filter $*` } +# the mount point must be the last parameter +_get_mount() +{ + local mnt_point=${!#} + + _mount $* + if [ $? -eq 0 ];then + MOUNTED_POINT_STACK=`echo "$mnt_point $MOUNTED_POINT_STACK"` + else + return 1 + fi +} + +_put_mount() +{ + local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'` + + if [ -n "$last_mnt" ];then + umount $last_mnt + fi + MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-` +} + +_clear_mount_stack() +{ + if [ -n "$MOUNTED_POINT_STACK" ];then + umount $MOUNTED_POINT_STACK + fi + MOUNTED_POINT_STACK="" +} + _scratch_options() { type=$1