From patchwork Tue Feb 23 11:27:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 8390991 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7F846C0553 for ; Tue, 23 Feb 2016 11:30:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C5FF20274 for ; Tue, 23 Feb 2016 11:30:02 +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 6082120270 for ; Tue, 23 Feb 2016 11:30:01 +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 1aYB7b-0001zm-1t; Tue, 23 Feb 2016 11:27:15 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYB7Y-0001zL-Dk for xen-devel@lists.xen.org; Tue, 23 Feb 2016 11:27:12 +0000 Received: from [193.109.254.147] by server-4.bemta-14.messagelabs.com id 7E/DE-10715-F024CC65; Tue, 23 Feb 2016 11:27:11 +0000 X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-16.tower-27.messagelabs.com!1456226830!25942060!1 X-Originating-IP: [81.169.146.217] 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 13274 invoked from network); 23 Feb 2016 11:27:10 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.217) by server-16.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Feb 2016 11:27:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1456226830; l=5868; s=domk; d=aepfle.de; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Date: Subject:Cc:To:From; bh=kFLQkOxfaLtT18JTu2hU/c/Z4zLL0JiNhiWdXLqFnSg=; b=WdQ/HX7rPX9nQ8WpWb3szUpCk84Ai6TBQYfMVgHQYDi7TB/y7cMMehSXb/+r1i6wWPU +QM+WVGQXeycgcOBc51JUxs0uitAjsAhAzXVjoaIsQkQcEAZSKc5yjMvvCAd6oJg9KHx2 b8BllhipPzAOLzvcKbAMTgMoE8usbSEqNRw= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWi/zfN1cLnDYUgqTAeBk4W9EFtcJhQlEigjKrHZjO+/XyMB8ZtmWA== X-RZG-CLASS-ID: mo00 Received: from probook ([2001:a62:113c:45ff:2082:fb69:3bad:17fe]) by smtp.strato.de (RZmta 37.19 AUTH) with ESMTPSA id L069e0s1NBRABEh (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); Tue, 23 Feb 2016 12:27:10 +0100 (CET) Received: by probook (Postfix, from userid 1000) id C4AB85031E; Tue, 23 Feb 2016 12:27:08 +0100 (CET) From: Olaf Hering To: xen-devel@lists.xen.org Date: Tue, 23 Feb 2016 11:27:01 +0000 Message-Id: <1456226821-24545-7-git-send-email-olaf@aepfle.de> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456226821-24545-1-git-send-email-olaf@aepfle.de> References: <1456226821-24545-1-git-send-email-olaf@aepfle.de> MIME-Version: 1.0 Cc: Olaf Hering Subject: [Xen-devel] [PATCH v9 6/6] 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..d014a0a --- /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 + + 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@'`" + udevadm settle --exit-if-exists="/dev/disk/by-id/${by_id}" + 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 + echo 1,96,S | sfdisk "${f_link}" + udevadm settle + blockdev --rereadpt "${f_link}" + udevadm settle + parted -s "${f_link}" unit s print + + d_link="`readlink \"${f_link}\"`" + if test -n "${d_link}" + then + p_link="${d_link}-part1" + udevadm settle --exit-if-exists="${p_link}" + ls -l "${p_link}" + mkswap -L "swp_${fileio_name}" "${p_link}" + udevadm settle + blockdev --rereadpt "${f_link}" + udevadm settle + 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