diff mbox

[v8,5/5] Scripts to create and delete xen-scsiback nodes in Linux target framework

Message ID 1455205411-25460-6-git-send-email-olaf@aepfle.de (mailing list archive)
State New, archived
Headers show

Commit Message

Olaf Hering Feb. 11, 2016, 3:43 p.m. UTC
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 <olaf@aepfle.de>
---
 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(+)

Comments

Wei Liu Feb. 12, 2016, 5:28 p.m. UTC | #1
On Thu, Feb 11, 2016 at 03:43:31PM +0000, Olaf Hering wrote:
> Just to make them public, not meant for merging:

I might be mistaken, but if you don't provide a hotplug script or some
sort for Xen how do you expect user to make use vscsi?

Wei.
Olaf Hering Feb. 12, 2016, 6:36 p.m. UTC | #2
On Fri, Feb 12, Wei Liu wrote:

> On Thu, Feb 11, 2016 at 03:43:31PM +0000, Olaf Hering wrote:
> > Just to make them public, not meant for merging:
> 
> I might be mistaken, but if you don't provide a hotplug script or some
> sort for Xen how do you expect user to make use vscsi?

The xenlinux backend uses existing SCSI devices. The pvops backend uses
devices provided by xen-scsiback which in turn is a frontend in the SCSI
target framework. This has to be configured manually before usage. I
have to document all this in the wiki.

Jürgen suggested to check if libxl could do the configuration in
configfs, as a replacement for targetcli. Not sure if thats doable. It
would require yet another syntax in vscsi=[]. I will look at this later.

Olaf
Jürgen Groß Feb. 15, 2016, 5:51 a.m. UTC | #3
On 12/02/16 19:36, Olaf Hering wrote:
> On Fri, Feb 12, Wei Liu wrote:
> 
>> On Thu, Feb 11, 2016 at 03:43:31PM +0000, Olaf Hering wrote:
>>> Just to make them public, not meant for merging:
>>
>> I might be mistaken, but if you don't provide a hotplug script or some
>> sort for Xen how do you expect user to make use vscsi?
> 
> The xenlinux backend uses existing SCSI devices. The pvops backend uses
> devices provided by xen-scsiback which in turn is a frontend in the SCSI
> target framework. This has to be configured manually before usage. I
> have to document all this in the wiki.
> 
> Jürgen suggested to check if libxl could do the configuration in
> configfs, as a replacement for targetcli. Not sure if thats doable. It
> would require yet another syntax in vscsi=[]. I will look at this later.

Hmm, I don't see why this would require another syntax. When adding e.g.
/dev/sr0 to a domain via targetcli I need to call:

targetcli /xen-pvscsi create naa.3ccc1c11088e4086
targetcli /backstores/pscsi create "dev=/dev/sr0" ps_0
targetcli /xen-pvscsi/naa.3ccc1c11088e4086/tpg1/luns create
"/backstores/pscsi/ps_0" 0
targetcli /xen-pvscsi/naa.3ccc1c11088e4086/tpg1 set parameter alias=2:0:0

The WWN (naa.3ccc1c11088e4086) is just generated via /dev/random. The
alias for xen-pvscsi (2:0:0) is taken from lsscsi by omitting the LUN:

# lsscsi
[0:0:0:0]    disk    ATA      WDC WD5000AAKX-7 1H19  /dev/sda
[2:0:0:0]    cd/dvd  HL-DT-ST DVD+-RW GHB0N    A100  /dev/sr0

The pscsi backstore name (ps_0) is just a name which can be chosen.

The need to use this kind of configuration is a feature of the current
system which can be easily detected by trying to create the xen-pvscsi
directory in configfs: if it succeeds you need to do it.

So all information for deciding to do the configfs related configuration
and all the data needed for doing it are already present. As this is
specific to Linux I'd add a system specific function which will be a nop
for non-Linux systems and could do the check and possibly the configfs
work on Linux.


Juergen
diff mbox

Patch

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