From patchwork Fri Feb 5 10:12:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 8233221 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5CFDF9F37A for ; Fri, 5 Feb 2016 10:15:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 36F8620397 for ; Fri, 5 Feb 2016 10:15:48 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 118382026D for ; Fri, 5 Feb 2016 10:15:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aRdNy-0004ad-Jc; Fri, 05 Feb 2016 10:13:06 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aRdNw-0004aO-O7 for xen-devel@lists.xen.org; Fri, 05 Feb 2016 10:13:05 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 5D/49-23747-FA574B65; Fri, 05 Feb 2016 10:13:03 +0000 X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-10.tower-31.messagelabs.com!1454667183!20519132!1 X-Originating-IP: [81.169.146.163] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20473 invoked from network); 5 Feb 2016 10:13:03 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.163) by server-10.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Feb 2016 10:13:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1454667183; l=5852; s=domk; d=aepfle.de; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Date: Subject:Cc:To:From; bh=2w6Qg/4Vpx4G9ArbRAZD9oIofe9oyFfq6RTs+o9hSGs=; b=r6JUcf4/W89mSlH0U3uhXFNd/kICBBJEVH41SZR78IVI8Q43lNgh9d4+t+V0T8xLo9K jxXNouFB3NM485R0FWOn5NhQu9sYig2IIQHHmMX14PC+g86wy9Bjts+j7zNeSKZSAPktM Has9nIhMoznqpGvVi7yxkKP4eHaegJMYht4= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWtqWFmrC5F/k8z92bPokQ== X-RZG-CLASS-ID: mo00 Received: from probook (aftr-185-17-206-113.dynamic.mnet-online.de [185.17.206.113]) by smtp.strato.de (RZmta 37.17 DYNA|AUTH) with ESMTPSA id K07438s15AD3VGE (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Fri, 5 Feb 2016 11:13:03 +0100 (CET) Received: by probook (Postfix, from userid 1000) id C67A3508D8; Fri, 5 Feb 2016 11:13:02 +0100 (CET) From: Olaf Hering To: xen-devel@lists.xen.org Date: Fri, 5 Feb 2016 10:12:55 +0000 Message-Id: <1454667175-24282-6-git-send-email-olaf@aepfle.de> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454667175-24282-1-git-send-email-olaf@aepfle.de> References: <1454667175-24282-1-git-send-email-olaf@aepfle.de> MIME-Version: 1.0 Cc: Olaf Hering Subject: [Xen-devel] [PATCH v7 5/5] Scripts to create and delete xen-scsiback nodes in Linux target framework X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Just to make them public, not meant for merging: The scripts used during development to create a bunch of SCSI devices in dom0 using the Linux target framework. targetcli3 and rtslib3 is used. A patch is required for python-rtslib: http://article.gmane.org/gmane.linux.scsi.target.devel/8146 Signed-off-by: Olaf Hering --- tools/misc/Makefile | 4 + tools/misc/target-create-xen-scsiback.sh | 135 +++++++++++++++++++++++++++++++ tools/misc/target-delete-xen-scsiback.sh | 41 ++++++++++ 3 files changed, 180 insertions(+) diff --git a/tools/misc/Makefile b/tools/misc/Makefile index a2ef0ec..180c9f5 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -35,6 +35,8 @@ INSTALL_SBIN += $(INSTALL_SBIN-y) # Everything to be installed in a private bin/ INSTALL_PRIVBIN += xenpvnetboot +INSTALL_PRIVBIN += target-create-xen-scsiback.sh +INSTALL_PRIVBIN += target-delete-xen-scsiback.sh # Everything to be installed TARGETS_ALL := $(INSTALL_BIN) $(INSTALL_SBIN) $(INSTALL_PRIVBIN) @@ -45,6 +47,8 @@ TARGETS_COPY += xen-ringwatch TARGETS_COPY += xencons TARGETS_COPY += xencov_split TARGETS_COPY += xenpvnetboot +TARGETS_COPY += target-create-xen-scsiback.sh +TARGETS_COPY += target-delete-xen-scsiback.sh # Everything which needs to be built TARGETS_BUILD := $(filter-out $(TARGETS_COPY),$(TARGETS_ALL)) diff --git a/tools/misc/target-create-xen-scsiback.sh b/tools/misc/target-create-xen-scsiback.sh new file mode 100755 index 0000000..96d4c39 --- /dev/null +++ b/tools/misc/target-create-xen-scsiback.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env bash +unset LANG +unset ${!LC_*} +set -x +set -e + +modprobe --version +targetcli --version +udevadm --version +blockdev --version +parted --version +sfdisk --version +mkswap --version + +configfs=/sys/kernel/config +target_path=$configfs/target + +num_luns=4 +num_hosts=4 + +case "$1" in + -p) + backend="pvops" + ;; + -x) + backend="xenlinux" + ;; + *) + : "usage: $0 [-p|-x]" + if grep -qw xenfs$ /proc/filesystems + then + backend="pvops" + else + backend="xenlinux" + fi + ;; +esac + +get_wwn() { + sed ' + s@-@@g + s@^\(.\{16\}\)\(.*\)@\1@ + ' /proc/sys/kernel/random/uuid +} + +if test ! -d "${target_path}" +then + modprobe -v configfs + mount -vt configfs configfs $configfs + modprobe -v target_core_mod +fi +if test "${backend}" = "pvops" +then + modprobe -v xen-scsiback +fi + +host=0 +while test $host -lt $num_hosts +do + host=$(( $host + 1 )) + lun=0 + loopback_wwn="naa.`get_wwn`" + pvscsi_wwn="naa.`get_wwn`" + targetcli /loopback create ${loopback_wwn} + if test "${backend}" = "pvops" + then + targetcli /xen-pvscsi create ${pvscsi_wwn} + fi + while test $lun -lt $num_luns + do + : h $host l $lun + f_file=/dev/shm/Fileio.${host}.${lun}.file + f_uuid=/dev/shm/Fileio.${host}.${lun}.uuid + f_link=/dev/shm/Fileio.${host}.${lun}.link + fileio_name="fio_${host}.${lun}" + pscsi_name="ps_${host}.${lun}" + + targetcli /backstores/fileio create name=${fileio_name} "file_or_dev=${f_file}" size=$((1024*1024 * 8 )) sparse=true + targetcli /loopback/${loopback_wwn}/luns create /backstores/fileio/${fileio_name} $lun + + udevadm settle --timeout=4 + + vpd_uuid="`sed -n '/^T10 VPD Unit Serial Number:/s@^[^:]\+:[[:blank:]]\+@@p' /sys/kernel/config/target/core/fileio_*/${fileio_name}/wwn/vpd_unit_serial`" + if test -z "${vpd_uuid}" + then + exit 1 + fi + echo "${vpd_uuid}" > "${f_uuid}" + by_id="`echo ${vpd_uuid} | sed 's@-@@g;s@^\(.\{25\}\)\(.*\)@scsi-36001405\1@'`" + ln -sfvbn "/dev/disk/by-id/${by_id}" "${f_link}" + + f_major=$((`stat --dereference --format=0x%t "${f_link}"`)) + f_minor=$((`stat --dereference --format=0x%T "${f_link}"`)) + if test -z "${f_major}" || test -z "${f_minor}" + then + exit 1 + fi + f_alias=`ls -d /sys/dev/block/${f_major}:${f_minor}/device/scsi_device/*:*:*:*` + if test -z "${f_alias}" + then + exit 1 + fi + f_alias=${f_alias##*/} + + blockdev --rereadpt "${f_link}" + udevadm settle --timeout=4 + echo 1,12,S | sfdisk "${f_link}" + udevadm settle --timeout=4 + blockdev --rereadpt "${f_link}" + udevadm settle --timeout=4 + parted -s "${f_link}" unit s print + + d_link="`readlink \"${f_link}\"`" + if test -n "${d_link}" + then + p_link="${d_link}-part1" + ls -l "${p_link}" + mkswap -L "swp_${fileio_name}" "${p_link}" + udevadm settle --timeout=4 + blockdev --rereadpt "${f_link}" + udevadm settle --timeout=4 + parted -s "${f_link}" unit s print + fi + + targetcli /backstores/pscsi create "dev=${f_link}" "${pscsi_name}" + if test "${backend}" = "pvops" + then + targetcli /xen-pvscsi/${pvscsi_wwn}/tpg1/luns create "/backstores/pscsi/${pscsi_name}" $lun + targetcli /xen-pvscsi/${pvscsi_wwn}/tpg1 set parameter alias=${f_alias%:*} + fi + + lun=$(( $lun + 1 )) + done +done + diff --git a/tools/misc/target-delete-xen-scsiback.sh b/tools/misc/target-delete-xen-scsiback.sh new file mode 100755 index 0000000..5b6dc54 --- /dev/null +++ b/tools/misc/target-delete-xen-scsiback.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +unset LANG +unset ${!LC_*} +set -x +set -e + +targetcli --version + +configfs=/sys/kernel/config +target_path=$configfs/target + +cd "${target_path}" +if cd xen-pvscsi +then + for wwn in `ls -d naa.*` + do + targetcli /xen-pvscsi delete $wwn + done +fi +cd "${target_path}" +cd core +for name in `ls -d pscsi_*/*/wwn` +do + name=${name%/wwn} + name=${name##*/} + targetcli /backstores/pscsi delete $name +done +cd "${target_path}" +cd loopback +for wwn in `ls -d naa.*` +do + targetcli /loopback delete $wwn +done +cd "${target_path}" +cd core +for name in `ls -d fileio_*/*/wwn` +do + name=${name%/wwn} + name=${name##*/} + targetcli /backstores/fileio delete $name +done