Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4797058pxk; Wed, 30 Sep 2020 11:56:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvYf8B4broIbrAU8XkWcRtoV2tiQEjJe5tPzI4YaIC34wrTlND2GGd+FVHpo02qZhm2EvH X-Received: by 2002:a17:906:f92:: with SMTP id q18mr4146878ejj.237.1601492171138; Wed, 30 Sep 2020 11:56:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601492171; cv=none; d=google.com; s=arc-20160816; b=01oAFfugH/Yd2GcbCWldKR0TONxNFP5Fc5iBJHQetfioVnjrAHCjsRYWJRXTlabfsU e8+TIujy4zhn4QCUplmkQQ96wePo+emS/jfzGJvWgRQFs5IO4iu66IOVJySXAL6cM5nw /mgxez29qMQu5P3n+vqP1lkyvygVAAbjNAhvvvn+BRz095daAg+y4yoY5ylZrbPScKya A6Z2XQ6M/BSnxpoV6NDPURbLUQpIksyskpBMYN6J05Kz1bn2mg22rZ6X01wNsUi1nOxs w18/E9YbUkos0INLwO+XAPS4r1YvK9hNknZPBb1/piZqadwdCdCI4aCeTJJ7d7sXP0eP S2ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=bzjNTcoiLhUgERqUAyZo5rx6zkhqOtriV/S0uELJa2Y=; b=excewbw7dbnjyMa9WfhrnH5cSKaGRLU++/B0iy3ZsdH4cFmQTuMAr6ZTthcHXjsjec ZfMc1i7X4QiFk8HeqLCRjmb5LseifzdLRvMMuwPyLfJfXFgiM++3ePXRh3lYaKotQQNM RXh0TP0/L7MIpsAePsAAnSHvVy1LTjB5zegMv4V79+51UqyvnExV7kHmP2fUVyMfDv+W jPhox/mxg+t4kz78pJYPMheGZtTEMJOzy8YUP2+y9vWvLXvfGnQJwlrCzORxqj6WqeAS 7d1qkIlop6iM0BAZiARJ5Wu3JwYoD+oqvTwMp2t9/Gf7W8Y6azg6ORcjc39NLHQFxM4G rWvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@deltatee.com header.s=20200525 header.b=KK11XwRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dx20si1731730ejb.503.2020.09.30.11.55.48; Wed, 30 Sep 2020 11:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@deltatee.com header.s=20200525 header.b=KK11XwRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729992AbgI3Syk (ORCPT + 99 others); Wed, 30 Sep 2020 14:54:40 -0400 Received: from ale.deltatee.com ([204.191.154.188]:37608 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729585AbgI3Syh (ORCPT ); Wed, 30 Sep 2020 14:54:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bzjNTcoiLhUgERqUAyZo5rx6zkhqOtriV/S0uELJa2Y=; b=KK11XwRLGOHjGJ8QkJt+uNjaKr 7WiKVaU9h+8+Ff0BaRrSoRa4rvJQSoMWM3TPeYzlFRFn4yQ8PAt78ZCYaEtKattI4gi2zrTJymmj6 nsQlV94R2dEFnDEh1QCaANT5Rsp+D5EA1S+PW56RpN4drfp6goRYhTngWCax6QSaqnV+st5487zPZ Du3X0Kp3CXyLSc35mFZRhT5VVN5SKaOkFojYP9E8KBggk4Wi6Z89pyDT9uZPVPznXLQLIhPDjFrOX pAG7wpUUu4bFimtFzBkrA56SYLGoCBLAgMTijtI9eKHTC1vYhDqdfKBDNSySAfpoi6UkjweUE2hWb pEBjlQTA==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNhFL-0000uw-24; Wed, 30 Sep 2020 12:54:35 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1kNhFD-00030X-MX; Wed, 30 Sep 2020 12:54:27 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Omar Sandoval Cc: Sagi Grimberg , Chaitanya Kulkarni , Stephen Bates , Logan Gunthorpe Date: Wed, 30 Sep 2020 12:54:16 -0600 Message-Id: <20200930185422.11494-6-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200930185422.11494-1-logang@deltatee.com> References: <20200930185422.11494-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, osandov@osandov.com, sagi@grimberg.me, Chaitanya.Kulkarni@wdc.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH blktests v2 05/11] nvme: Add common helpers for passthru tests X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add some simple helpers to setup a passthru target that passes through to a nvme test device. Signed-off-by: Logan Gunthorpe --- tests/nvme/rc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/nvme/rc b/tests/nvme/rc index dfa57a299625..1ea23308a3f7 100644 --- a/tests/nvme/rc +++ b/tests/nvme/rc @@ -73,6 +73,17 @@ _require_nvme_trtype_is_fabrics() { return 0 } +_test_dev_nvme_ctrl() { + local dev + + dev=$(cat "${TEST_DEV_SYSFS}/device/dev") + echo "/dev/char/${dev}" +} + +_test_dev_nvme_nsid() { + cat "${TEST_DEV_SYSFS}/nsid" +} + _cleanup_nvmet() { local dev local port @@ -257,6 +268,27 @@ _remove_nvmet_subsystem() { rmdir "${subsys_path}" } +_create_nvmet_passthru() { + local nvmet_subsystem="$1" + local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}" + local passthru_path="${subsys_path}/passthru" + + mkdir -p "${subsys_path}" + printf 1 > "${subsys_path}/attr_allow_any_host" + + printf "%s" "$(_test_dev_nvme_ctrl)" > "${passthru_path}/device_path" + printf 1 > "${passthru_path}/enable" +} + +_remove_nvmet_passhtru() { + local nvmet_subsystem="$1" + local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}" + local passthru_path="${subsys_path}/passthru" + + printf 0 > "${passthru_path}/enable" + rmdir "${subsys_path}" +} + _add_nvmet_subsys_to_port() { local port="$1" local nvmet_subsystem="$2" @@ -292,6 +324,50 @@ _find_nvme_dev() { done } +_find_nvme_passthru_loop_dev() { + local subsys=$1 + local nsid + local dev + + dev=$(_find_nvme_dev "${subsys}") + nsid=$(_test_dev_nvme_nsid) + echo "/dev/${dev}n${nsid}" +} + +_nvmet_passthru_target_setup() { + local subsys_name=$1 + + _create_nvmet_passthru "${subsys_name}" + port="$(_create_nvmet_port "loop")" + _add_nvmet_subsys_to_port "${port}" "${subsys_name}" + + echo "$port" +} + +_nvmet_passthru_target_connect() { + local trtype=$1 + local subsys_name=$2 + + _nvme_connect_subsys "${trtype}" "${subsys_name}" + nsdev=$(_find_nvme_passthru_loop_dev "${subsys_name}") + + # The following tests can race with the creation + # of the device so ensure the block device exists + # before continuing + while [ ! -b "${nsdev}" ]; do sleep 1; done + + echo "${nsdev}" +} + +_nvmet_passthru_target_cleanup() { + local port=$1 + local subsys_name=$2 + + _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}" + _remove_nvmet_port "${port}" + _remove_nvmet_passhtru "${subsys_name}" +} + _filter_discovery() { sed -n -r -e "s/Generation counter [0-9]+/Generation counter X/" \ -e '/Discovery Log Number|Log Entry|trtype|subnqn/p' -- 2.20.1