Commit 450ffbc6 authored by Xiaodong Liu's avatar Xiaodong Liu Committed by Jim Harris
Browse files

nbd: part bdev through bdev_svc



Change-Id: I667df64dd2363c606f39b52c0411c6ba7f55d5ba
Signed-off-by: default avatarXiaodong Liu <xiaodong.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/391370


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 381af577
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -194,12 +194,14 @@ The bdev NBD app can be used to temporarily expose an SPDK bdev through the Linu
block stack so that standard partitioning tools can be used.

~~~
# Expose bdev Nvme0n1 as kernel block device /dev/nbd0
# Assumes bdev.conf is already configured with a bdev named Nvme0n1 -
# see the NVMe section above.
test/lib/bdev/nbd/nbd -c bdev.conf -b Nvme0n1 -n /dev/nbd0 &
test/app/bdev_svc/bdev_svc -c bdev.conf &
nbd_pid=$!

# Expose bdev Nvme0n1 as kernel block device /dev/nbd0 by JSON-RPC
scripts/rpc.py start_nbd_disk Nvme0n1 /dev/nbd0

# Create GPT partition table.
parted -s /dev/nbd0 mklabel gpt

+13 −7
Original line number Diff line number Diff line
@@ -370,6 +370,8 @@ function part_dev_by_gpt () {
		devname=$2
		rootdir=$3
		operation=$4
		local nbd_path=/dev/nbd0
		local rpc_server=/var/tmp/spdk-gpt-bdevs.sock

		if [ ! -e $conf ]; then
			return 1
@@ -384,24 +386,28 @@ function part_dev_by_gpt () {
		echo "  Disable Yes" >> ${conf}.gpt

		modprobe nbd
		$rootdir/test/lib/bdev/nbd/nbd -c ${conf}.gpt -b $devname -n /dev/nbd0 &
		$rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -i 0 -c ${conf}.gpt &
		nbd_pid=$!
		echo "Process nbd pid: $nbd_pid"
		waitforlisten $nbd_pid
		waitfornbd nbd0
		waitforlisten $nbd_pid $rpc_server

		# Start bdev as a nbd device
		$rootdir/scripts/rpc.py -s "$rpc_server" start_nbd_disk $devname $nbd_path

		waitfornbd ${nbd_path:5}

		if [ "$operation" = create ]; then
			parted -s /dev/nbd0 mklabel gpt mkpart first '0%' '50%' mkpart second '50%' '100%'
			parted -s $nbd_path mklabel gpt mkpart first '0%' '50%' mkpart second '50%' '100%'

			# change the GUID to SPDK GUID value
			SPDK_GPT_GUID=`grep SPDK_GPT_PART_TYPE_GUID $rootdir/lib/bdev/gpt/gpt.h \
				| awk -F "(" '{ print $2}' | sed 's/)//g' \
				| awk -F ", " '{ print $1 "-" $2 "-" $3 "-" $4 "-" $5}' | sed 's/0x//g'`
			sgdisk -t 1:$SPDK_GPT_GUID /dev/nbd0
			sgdisk -t 2:$SPDK_GPT_GUID /dev/nbd0
			sgdisk -t 1:$SPDK_GPT_GUID $nbd_path
			sgdisk -t 2:$SPDK_GPT_GUID $nbd_path
		elif [ "$operation" = reset ]; then
			# clear the partition table
			dd if=/dev/zero of=/dev/nbd0 bs=4096 count=8 oflag=direct
			dd if=/dev/zero of=$nbd_path bs=4096 count=8 oflag=direct
		fi

		killprocess $nbd_pid