Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp507128rwr; Thu, 4 May 2023 06:16:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7gamrIFzFph+iphzeNl/aCi8UU+FaY5WTMn7668C2DkebPXZ/8M/DyCl5unM5dMT0AS4Tj X-Received: by 2002:a17:902:e5ca:b0:1ab:d6f:51a6 with SMTP id u10-20020a170902e5ca00b001ab0d6f51a6mr3439375plf.53.1683206214266; Thu, 04 May 2023 06:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683206214; cv=none; d=google.com; s=arc-20160816; b=KE5QPJVzkpto8sC0DE8XvTFs9jy82jKdHriG52N7n/BwgJWvz9nhaKdzR1x6uVBQ9T 4CzGJqzXr3DToJumzDmeQjvrF3YPMUMl6Fmo45jDEakPuo/WPbRTP9+yAAASHxnOa8lo 2fUNFijO7tXhUbW/zv8gnHPyLi9/efuUo03RWlSwcMDwzGQbWrd0RO0S3nA0tb0D8LvX LUwniVER1+ynZCnAfzh0RqKLTv8IIX0WGxw6VMhPwgOVuUs79Ne8LioK8mBTaUHm+6SZ XZKLs3zJI0R/3x/cl1/9eWKf0VA/rWLiQmnW7Y8AxWtR8vw1bZnU3BdC3JQWq+87Hg0h X11w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=ewYSS6/K3VhhpPZUmvT8hvwvjLF4gKgkfo/wRmB4X9g=; b=YTsOXmgU98I3zBw9m78NjoCniUPIgpveZki6fcz8H9yflT7AfeihvXhGPC63NFFk7g 5sX/MOsCrq+at3Nq3jaeE5M4Ewx3MAy1Vb0Xb5Fl0vrL1Fl4DErUM15golMlrcZAKwwK owspKWctsgsySYlMI74JOJyi3Tuov5rc9Gwigw0DkqzsmRHHQTfX4D4MlYOMv1LlRCbe 40qpxnJ60CyMLN1CJ9orjAvXH6HMyxEV+rr6JSEIrTdLaIGbD6J/yQoJqvHFNwGVHLig EK0MJBK+XC9mE0Osh6xpD5TzRjbgvjGV6353sRHeWvCE5vl0T4TZxir3EfaKXBNKpxrj mqgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=E9Ih9tvz; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020a170902f68100b001a1d78af685si103048plg.466.2023.05.04.06.16.27; Thu, 04 May 2023 06:16:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=E9Ih9tvz; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230179AbjEDNOI (ORCPT + 99 others); Thu, 4 May 2023 09:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjEDNOH (ORCPT ); Thu, 4 May 2023 09:14:07 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFBC96EA2 for ; Thu, 4 May 2023 06:14:05 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5FFCB1FDAB; Thu, 4 May 2023 13:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1683206044; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ewYSS6/K3VhhpPZUmvT8hvwvjLF4gKgkfo/wRmB4X9g=; b=E9Ih9tvzeZPIKkLAQFfUK+297UXRlZu7kRAYy7slDEtQR2g8qtBKONOk9AK6QS9d+9s3aX H299MRcrEj+LgJKihrQmlEsxCmVFWPeeDvXYholNQZNOpg7gbU5vF9rfeQiRU6y4bDnAof tQrTGOhu+CL3BKhntq3OlDwoyGShJoQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1683206044; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ewYSS6/K3VhhpPZUmvT8hvwvjLF4gKgkfo/wRmB4X9g=; b=FJhX2+jPNEhQon8s9bfiOgbz3GJsCh+HhcSqBSQCCpp33kzj7SKXaJDBppTmuHy4DPkFeA dPI4XzB+jLto0SDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D1DD813444; Thu, 4 May 2023 13:14:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WOzGMJuvU2TXVgAAMHmgww (envelope-from ); Thu, 04 May 2023 13:14:03 +0000 From: Petr Vorel To: ltp@lists.linux.it Cc: Petr Vorel , NeilBrown , Cyril Hrubis , linux-nfs@vger.kernel.org, Jeff Layton Subject: [PATCH v5 1/5] nfs_lib.sh: Cleanup local and remote directories setup Date: Thu, 4 May 2023 15:14:10 +0200 Message-Id: <20230504131414.3826283-2-pvorel@suse.cz> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230504131414.3826283-1-pvorel@suse.cz> References: <20230504131414.3826283-1-pvorel@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Logic for creating local and remote directories was on more places. Create get_local_dir() and get_remote_dir() functions to keep it on single place. local dir is needed in nfs_mount(), but was defined in nfs_setup() and reused local variable with shell inheritance (ugly!), because there were all parameters from loop. Similarly, remote dir is needed in both nfs_mount() and nfs_setup_server(), but created with shell inheritance in nfs_setup(). Pass these params to nfs_mount() and nfs_setup_server() and define variables with new functions get_local_dir() and get_remote_dir(). Use get_remote_dir() in nfs_get_remote_path(). Move cd to local directory to the end of nfs_mount() (it used to cd after nfs_mount(), but only if -v parameter contained single version, but it does not harm to always cd). Signed-off-by: Petr Vorel --- testcases/network/nfs/nfs_stress/nfs_lib.sh | 52 ++++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/testcases/network/nfs/nfs_stress/nfs_lib.sh b/testcases/network/nfs/nfs_stress/nfs_lib.sh index af7d46a21..1b5604ab5 100644 --- a/testcases/network/nfs/nfs_stress/nfs_lib.sh +++ b/testcases/network/nfs/nfs_stress/nfs_lib.sh @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) Linux Test Project, 2016-2022 +# Copyright (c) Linux Test Project, 2016-2023 # Copyright (c) 2015-2018 Oracle and/or its affiliates. All Rights Reserved. # Copyright (c) International Business Machines Corp., 2001 @@ -53,6 +53,24 @@ get_socket_type() done } +# directory mounted by NFS client +get_local_dir() +{ + local v="$1" + local n="$2" + + echo "$TST_TMPDIR/$v/$n" +} + +# directory on NFS server +get_remote_dir() +{ + local v="$1" + local n="$2" + + echo "$TST_TMPDIR/$v/$n" +} + nfs_get_remote_path() { local v @@ -63,7 +81,7 @@ nfs_get_remote_path() done v=${1:-$v} - echo "$TST_TMPDIR/$v/$type" + echo "$(get_remote_dir $v $type)" } nfs_server_udp_enabled() @@ -78,8 +96,8 @@ nfs_server_udp_enabled() nfs_setup_server() { - - local fsid="$1" + local remote_dir="$1" + local fsid="$2" local export_cmd="exportfs -i -o fsid=$fsid,no_root_squash,rw *:$remote_dir" [ -z "$fsid" ] && tst_brk TBROK "empty fsid" @@ -97,10 +115,14 @@ nfs_setup_server() nfs_mount() { - local opts="$1" + local local_dir="$1" + local remote_dir="$2" + local opts="$3" local host_type=rhost local mount_dir + mkdir -p "$local_dir" + tst_net_use_netns && host_type= if [ $TST_IPV6 ]; then @@ -131,6 +153,8 @@ nfs_mount() tst_brk TBROK "mount command failed" fi + + cd "$local_dir" } nfs_setup() @@ -162,20 +186,12 @@ nfs_setup() tst_brk TCONF "UDP support disabled on NFS server" fi - local_dir="$TST_TMPDIR/$i/$n" - remote_dir="$TST_TMPDIR/$i/$type" - mkdir -p $local_dir - - nfs_setup_server $(($$ + n)) - - nfs_mount "-o proto=$type,vers=$i" + remote_dir="$(get_remote_dir $i $type)" + nfs_setup_server "$remote_dir" "$(($$ + n))" + nfs_mount "$(get_local_dir $i $n)" "$remote_dir" "-o proto=$type,vers=$i" n=$(( n + 1 )) done - - if [ "$n" -eq 1 ]; then - cd ${VERSION}/0 - fi } nfs_cleanup() @@ -190,7 +206,7 @@ nfs_cleanup() local n=0 for i in $VERSION; do - local_dir="$TST_TMPDIR/$i/$n" + local_dir="$(get_local_dir $i $n)" grep -q "$local_dir" /proc/mounts && umount $local_dir n=$(( n + 1 )) done @@ -198,7 +214,7 @@ nfs_cleanup() n=0 for i in $VERSION; do type=$(get_socket_type $n) - remote_dir="$TST_TMPDIR/$i/$type" + remote_dir="$(get_remote_dir $i $type)" tst_rhost_run -c "test -d $remote_dir && exportfs -u *:$remote_dir" tst_rhost_run -c "test -d $remote_dir && rm -rf $remote_dir" n=$(( n + 1 )) -- 2.40.0