From patchwork Fri Apr 8 07:01:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 8781471 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 777ECC0553 for ; Fri, 8 Apr 2016 07:03:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C83FB2026D for ; Fri, 8 Apr 2016 07:03:42 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C110620222 for ; Fri, 8 Apr 2016 07:03:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoQQK-0005gE-2j; Fri, 08 Apr 2016 07:01:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoQQJ-0005g1-G6 for xen-devel@lists.xen.org; Fri, 08 Apr 2016 07:01:43 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 37/A1-07924-65757075; Fri, 08 Apr 2016 07:01:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRWlGSWpSXmKPExsUSuHLSXd2wcPZ wg0/vuC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ox1M/ML5upWHFwxl6WB8YJaFyMXB4vAYmaJ Fe83M3UxcnJICPhKrOuYxtjFyAFki0g8+Z8GUiMk8IhJ4vuu6ewgNUIC6RJ/f/8Es9kElCT2H jzOCGKLCEhLXPt8GcxmFlCQePF8K9hMYYEkiYZZn5hAZrIIqEp8218GEuYVsJM4d/cqO8RaOY mb5zqZQWxOAXuJf7uOs4GUCwHV7OmThygXlDg58wkLxHR5ieats5knMArMQpKahSS1gJFpFaN 6cWpRWWqRrrleUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkZg+DEAwQ7Gxu9Ohxgl OZiURHn1wtjDhfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw1oPkBItS01Mr0jJzgJEAk5bg4FES4 W0GSfMWFyTmFmemQ6ROMepybFlwYy2TEEtefl6qlDhvGUiRAEhRRmke3AhYVF5ilJUS5mUEOk qIpyC1KDezBFX+FaM4B6OSMG8HyBSezLwSuE2vgI5gAjriAj8byBEliQgpqQbGBXqPb13rkv7 XyMjPqz5Nc1pU7Yy2D99cjKffCC21Tr6qudXP4GzCkrNbarqze1o5jUJ2n6zKjuMsTJ74JPu9 1Lri5j9b8it+bDttpxM0wd3t6iyuyfYJUfPOJ307c6P344GV0w9Luri/PaEsbPTx8/opN18z9 Ww+GSM41zXgOwuntM4GF5U/SizFGYmGWsxFxYkAi2A5GcUCAAA= X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-11.tower-31.messagelabs.com!1460098902!7441183!1 X-Originating-IP: [81.169.146.221] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43251 invoked from network); 8 Apr 2016 07:01:42 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.221) by server-11.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Apr 2016 07:01:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1460098902; 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=g5JHPNR4GDARnTZCrfDWaVG18HqpjQ8I4GCWNsmuAYnuW7KCK+iUZC2zcqTWGdZ6Cxg V5OQ4txKZ/xM7V09Eg1ou7xrIGNYhDCKClOyfE5L4426gzYizYQBqGtE5ulaclioLLhIM ctECzqQ2bvdUNUHlBRHPQwHsLTUNqBfV/Ko= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWtqWFmrC5F/k8z92bDrkQ== X-RZG-CLASS-ID: mo00 Received: from probook (aftr-185-17-206-120.dynamic.mnet-online.de [185.17.206.120]) by smtp.strato.de (RZmta 37.22 DYNA|AUTH) with ESMTPSA id t07426s3871gxuZ (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, 8 Apr 2016 09:01:42 +0200 (CEST) Received: by probook (Postfix, from userid 1000) id ADDEA50906; Fri, 8 Apr 2016 09:01:41 +0200 (CEST) From: Olaf Hering To: xen-devel@lists.xen.org Date: Fri, 8 Apr 2016 07:01:31 +0000 Message-Id: <1460098891-13278-3-git-send-email-olaf@aepfle.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1460098891-13278-1-git-send-email-olaf@aepfle.de> References: <1460098891-13278-1-git-send-email-olaf@aepfle.de> MIME-Version: 1.0 Cc: Olaf Hering Subject: [Xen-devel] [PATCH v11 2/2] Scripts to create and delete xen-scsiback nodes in Linux target framework X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" 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 Acked-by: Wei Liu --- 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