From patchwork Thu Apr 6 13:19:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Monakhov X-Patchwork-Id: 9667253 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 E00516021C for ; Thu, 6 Apr 2017 13:19:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 016A526E4E for ; Thu, 6 Apr 2017 13:19:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA76B2823D; Thu, 6 Apr 2017 13:19:21 +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_SIGNED, 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 CD8D826E4E for ; Thu, 6 Apr 2017 13:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757095AbdDFNTT (ORCPT ); Thu, 6 Apr 2017 09:19:19 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:35125 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754902AbdDFNTQ (ORCPT ); Thu, 6 Apr 2017 09:19:16 -0400 Received: by mail-lf0-f66.google.com with SMTP id v2so3640420lfi.2; Thu, 06 Apr 2017 06:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=k4pQGFLYOZBodLowXoTZzzkPsSmpdImzZOcgCd/71h4=; b=bwd4DurQkoz/WxalTPfLTgAywfa2Ac1s6kqU8H77qCjHJhWBbnQXp6LzEBCKMNnKB2 m/l0Qa2rSjDwNJe3bxH3/WTJCZNgoyfIQpudNPowafk01M1AvhAhjJTbYHr1sYPwaRO8 nvWH7n/dz5bJqlx7R+fpPQTS4MYQ+kt8CdINVUWnSj/THZjUU3G8vFpAFUvMPkV92G+i KhHjd5jJfxBffxKfw+2E2iwSiVJ556vpV02i+9NaduBUuPegT9AH8vJsywF6UTVRAMas e2oOwsea6cssWsXUi4AaC38wTxoQAxHkkNJfx8DmzQ2utrArmDUZA5Jq5a+dFcxmmhjO Z5fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=k4pQGFLYOZBodLowXoTZzzkPsSmpdImzZOcgCd/71h4=; b=ZgaKyFg90VQR+Q74wcbZvyy5O8QLOzEFZSHDsC6U4wL6orh/u3a+NzYtJRMd5AXQLM L6AJKBRJqpK09t4c7WlL9oHB6TwDjBGxxBhw69ozhQAll+wEgOm+QfV1FxhJ9kB+TVLT y7Qs8JB8TKmHsfbsKN6x1p3U9Lq9eE4o0nJnKcl+T52sNmxxen0sdkQPtvoLpkm5U9TB 20pnlIsDE9PrLzN4wveveI+XS49CwwrHJdS7jJhiZcu1Zv7y5eSpRGqdsdCMU+eilZ5V vLjaBjN9Xx3Ac7PByIra1Kxn1CNwuCbFUMG3pdsN2F0Pkf+aP/t3W3Y9BMqBoECbRtz+ puBA== X-Gm-Message-State: AFeK/H2ngg+rYWzgdwjkwGuFB9m3J6bPDF4tnmu1eb0l4kJ8Kd0JadEFa13gBVF3ny5mtQ== X-Received: by 10.25.190.2 with SMTP id o2mr11980716lff.80.1491484754455; Thu, 06 Apr 2017 06:19:14 -0700 (PDT) Received: from smtp.gmail.com (msk-vpn.virtuozzo.com. [195.214.232.6]) by smtp.gmail.com with ESMTPSA id 4sm342354ljf.33.2017.04.06.06.19.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 06:19:13 -0700 (PDT) From: Dmitry Monakhov To: fstests@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Dmitry Monakhov Subject: [PATCH 1/6] add lio-target helpers Date: Thu, 6 Apr 2017 17:19:05 +0400 Message-Id: <1491484750-9164-2-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1491484750-9164-1-git-send-email-dmonakhov@openvz.org> References: <1491484750-9164-1-git-send-email-dmonakhov@openvz.org> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Linux-IO Target is very good framework for testing block backend. It is more flexible than scsi_debug. http://linux-iscsi.org/wiki/LIO Signed-off-by: Dmitry Monakhov --- common/config | 2 + common/liotarget | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 common/liotarget diff --git a/common/config b/common/config index 59041a3..cfe7913 100644 --- a/common/config +++ b/common/config @@ -212,6 +212,8 @@ export XZ_PROG="`set_prog_path xz`" export FLOCK_PROG="`set_prog_path flock`" export LDD_PROG="`set_prog_path ldd`" export TIMEOUT_PROG="`set_prog_path timeout`" +export TARGETCLI_PROG="`set_prog_path targetcli`" +export TARGETCTL_PROG="`set_prog_path targetctl`" # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled. # newer systems have udevadm command but older systems like RHEL5 don't. diff --git a/common/liotarget b/common/liotarget new file mode 100644 index 0000000..f821692 --- /dev/null +++ b/common/liotarget @@ -0,0 +1,111 @@ +#!/bin/bash +# +# Copyright (c) 2017 Virtuozzo Inc +# All Rights Reserved. +# +# Written by Dmitry Monakhov +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# +# Functions for Linux-IO Target manipulation +# + +_require_liotarget() +{ + which $TARGETCLI_PROG >>$seqres.full 2>&1 || \ + _notrun "this test requires 'targetcli' tool" + which $TARGETCLI_PROG >>$seqres.full 2>&1 || \ + _notrun "this test requires 'targetcli' tool" + + $TARGETCLI_PROG ls /backstores/ramdisk >>$seqres.full 2>&1 ||\ + _notrun "kernel compiled w/o CONFIG_TARGET_CORE" + $TARGETCLI_PROG ls /backstores/fileio >>$seqres.full 2>&1 ||\ + _notrun "kernel compiled w/o CONFIG_TCM_FILEIO" + $TARGETCLI_PROG ls /loopback >>$seqres.full 2>&1 ||\ + _notrun "kernel compiled w/o CONFIG_LOOPBACK_TARGET" +} + +_liotgt_create_fileio() +{ + local name=$1 + local img=$2 + local sz=$3 + + $TARGETCLI_PROG /backstores/fileio create \ + name=$name file_or_dev=$img size=$sz >>$seqres.full ||\ + _fail "Can not create /backstores/fileio/$name" + + local cfg_path=`ls -d /sys/kernel/config/target/core/fileio_*/$name` + [ -d "$cfg_path" ] || _fail "Bad config path" + echo $cfg_path +} + +_liotgt_set_attribute() +{ + local path=$1 + local attr_name=$2 + local attr_val=$3 + + [ -f $path/attrib/$attr_name ] || _fail "Bad attribute $attr_name" + echo "echo $attr_val > $path/attrib/$attr_name " >>$seqres.full + echo $attr_val > $path/attrib/$attr_name +} + +_liotgt_create_loopback() +{ + local out=`$TARGETCLI_PROG /loopback/ create 2>&1` + [ $? -eq 0 ] || _fail "Can not create loopback target" + echo $out >>$seqres.full + + local naa=`echo $out | gawk '{ print $3 }'` + echo ${naa:0:20} >>$seqres.full + + echo ${naa:0:20} +} + +_liotgt_find_dev() +{ + local found="" + local name=$1 + local drives=`find /sys/devices -type f -name model` + for d in $drives;do + local dir=`dirname $d` + local vendor=`cat $dir/vendor` + local model=`cat $dir/model` + if [ "${vendor//[[:space:]]/}" == "LIO-ORG" ] && \ + [ "${model//[[:space:]]/}" == "$name" ]; then + found=/dev/$(ls $dir/block) + break + fi + done + [ -z "$found" ] && _fail "Can not find device with backend $name" + echo "$found" +} + +_liotgt_attach_target() +{ + local path=$1 + local name=`basename $path` + local naa=$(_liotgt_create_loopback) + + $TARGETCLI_PROG /loopback/$naa/luns create $path >>$seqres.full 2>&1 ||\ + _fail "Can not attach $path to tcm_loop" + _liotgt_find_dev $name +} + +_liotgt_cleanup() +{ + $TARGETCTL_PROG clear +}