From patchwork Thu Feb 11 15:43: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: 8281801 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 9AE4EBEEE5 for ; Thu, 11 Feb 2016 15:45:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E90C020306 for ; Thu, 11 Feb 2016 15:45:57 +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 C96762024F for ; Thu, 11 Feb 2016 15:45:56 +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 1aTtP9-0000Vq-V0; Thu, 11 Feb 2016 15:43:39 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aTtP8-0000VQ-7r for xen-devel@lists.xen.org; Thu, 11 Feb 2016 15:43:38 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id 33/BA-31122-92CACB65; Thu, 11 Feb 2016 15:43:37 +0000 X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-7.tower-21.messagelabs.com!1455205416!15374323!1 X-Originating-IP: [81.169.146.221] 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 54243 invoked from network); 11 Feb 2016 15:43:36 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.221) by server-7.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Feb 2016 15:43:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1455205416; 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=oURDdDrETOYMFd4cUDtNcJmlZxmj6kqwZ7xHGskY7TyzoC3/1GGKbSRD8ktmLO8E/dm dyzxFwAhQlxHtmlgtMyv3z8qCZThyyNKdOxe7XFwgoGK3PqB8KoZE/BPMLpZM2LBdWzGp aDCn3knPALlDCd7s8AypUEGd1YgJm07jndg= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWtqWFmrC5F/k8792rbvkQ== X-RZG-CLASS-ID: mo00 Received: from probook (aftr-185-17-204-244.dynamic.mnet-online.de [185.17.204.244]) by smtp.strato.de (RZmta 37.17 DYNA|AUTH) with ESMTPSA id J0368bs1BFham15 (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); Thu, 11 Feb 2016 16:43:36 +0100 (CET) Received: by probook (Postfix, from userid 1000) id AD4D9508D4; Thu, 11 Feb 2016 16:43:35 +0100 (CET) From: Olaf Hering To: xen-devel@lists.xen.org Date: Thu, 11 Feb 2016 15:43:31 +0000 Message-Id: <1455205411-25460-6-git-send-email-olaf@aepfle.de> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1455205411-25460-1-git-send-email-olaf@aepfle.de> References: <1455205411-25460-1-git-send-email-olaf@aepfle.de> MIME-Version: 1.0 Cc: Olaf Hering Subject: [Xen-devel] [PATCH v8 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..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