All of lore.kernel.org
 help / color / mirror / Atom feed
From: chaitanya.kulkarni@wdc.com (Chaitanya Kulkarni)
Subject: [PATCH] blktests: use global configfs variable
Date: Tue,  8 May 2018 01:45:32 -0400	[thread overview]
Message-ID: <20180508054532.13712-1-chaitanya.kulkarni@wdc.com> (raw)

This patch introduces a global variable to hold the
configfs nvmet path. Now we don't need repetitive
local variables to hold the path and testcases
can use the newly introduced variable if needed.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 common/nvme | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/common/nvme b/common/nvme
index c6718f0..797e6db 100644
--- a/common/nvme
+++ b/common/nvme
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+NVMET_CFS="/sys/kernel/config/nvmet/"
+
 _test_dev_is_nvme() {
 	if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q nvme; then
 		SKIP_REASON="$TEST_DEV is not a NVMe device"
@@ -27,33 +29,29 @@ _test_dev_is_nvme() {
 
 _create_nvmet_port() {
 	local trtype="$1"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
-
 	local port
 	for ((port = 0; ; port++)); do
-		if [[ ! -e "${nvmet_cfs}/${port}" ]]; then
+		if [[ ! -e "${NVMET_CFS}/${port}" ]]; then
 			break
 		fi
 	done
 
-	mkdir "${nvmet_cfs}/ports/${port}"
-	echo "${trtype}" > "${nvmet_cfs}/ports/${port}/addr_trtype"
+	mkdir "${NVMET_CFS}/ports/${port}"
+	echo "${trtype}" > "${NVMET_CFS}/ports/${port}/addr_trtype"
 
 	echo "${port}"
 }
 
 _remove_nvmet_port() {
 	local port="$1"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
-	rmdir "${nvmet_cfs}/ports/${port}"
+	rmdir "${NVMET_CFS}/ports/${port}"
 }
 
 _create_nvmet_subsystem() {
 	local nvmet_subsystem="$1"
 	local blkdev="$2"
 	local uuid="00000000-0000-0000-0000-000000000000"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
-	local cfs_path="${nvmet_cfs}/subsystems/${nvmet_subsystem}"
+	local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
 
 	if [[ $# -eq 3 ]]; then
 		uuid="$3"
@@ -69,8 +67,7 @@ _create_nvmet_subsystem() {
 
 _remove_nvmet_subsystem() {
 	local nvmet_subsystem="$1"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
-	local cfs_path="${nvmet_cfs}/subsystems/${nvmet_subsystem}"
+	local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
 
 	echo 0 > "${cfs_path}/namespaces/1/enable"
 	rmdir "${cfs_path}/namespaces/1/"
@@ -80,16 +77,14 @@ _remove_nvmet_subsystem() {
 _add_nvmet_subsys_to_port() {
 	local port="$1"
 	local nvmet_subsystem="$2"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
 
-	ln -s "${nvmet_cfs}/subsystems/${nvmet_subsystem}" \
-		"${nvmet_cfs}/ports/${port}/subsystems/${nvmet_subsystem}"
+	ln -s "${NVMET_CFS}/subsystems/${nvmet_subsystem}" \
+		"${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
 }
 
 _remove_nvmet_subsystem_from_port() {
 	local port="$1"
 	local nvmet_subsystem="$2"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
 
-	rm "${nvmet_cfs}/ports/${port}/subsystems/${nvmet_subsystem}"
+	rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
 }
-- 
2.9.5

             reply	other threads:[~2018-05-08  5:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08  5:45 Chaitanya Kulkarni [this message]
2018-05-08  6:38 ` [PATCH] blktests: use global configfs variable Johannes Thumshirn
2018-05-14 20:07 ` Omar Sandoval
  -- strict thread matches above, loose matches on Subject: below --
2018-05-07 20:04 Chaitanya Kulkarni
2018-05-07 20:41 ` chaitany kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180508054532.13712-1-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.