nbd: part bdev through bdev_svc

Change-Id: I667df64dd2363c606f39b52c0411c6ba7f55d5ba
Signed-off-by: Xiaodong Liu <xiaodong.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/391370
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Xiaodong Liu 2017-12-11 01:56:40 -05:00 committed by Jim Harris
parent 381af5775f
commit 450ffbc63a
2 changed files with 17 additions and 9 deletions

View File

@ -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. 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 - # Assumes bdev.conf is already configured with a bdev named Nvme0n1 -
# see the NVMe section above. # 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=$! 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. # Create GPT partition table.
parted -s /dev/nbd0 mklabel gpt parted -s /dev/nbd0 mklabel gpt

View File

@ -370,6 +370,8 @@ function part_dev_by_gpt () {
devname=$2 devname=$2
rootdir=$3 rootdir=$3
operation=$4 operation=$4
local nbd_path=/dev/nbd0
local rpc_server=/var/tmp/spdk-gpt-bdevs.sock
if [ ! -e $conf ]; then if [ ! -e $conf ]; then
return 1 return 1
@ -384,24 +386,28 @@ function part_dev_by_gpt () {
echo " Disable Yes" >> ${conf}.gpt echo " Disable Yes" >> ${conf}.gpt
modprobe nbd 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=$! nbd_pid=$!
echo "Process nbd pid: $nbd_pid" echo "Process nbd pid: $nbd_pid"
waitforlisten $nbd_pid waitforlisten $nbd_pid $rpc_server
waitfornbd nbd0
# 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 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 # change the GUID to SPDK GUID value
SPDK_GPT_GUID=`grep SPDK_GPT_PART_TYPE_GUID $rootdir/lib/bdev/gpt/gpt.h \ 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 $2}' | sed 's/)//g' \
| awk -F ", " '{ print $1 "-" $2 "-" $3 "-" $4 "-" $5}' | sed 's/0x//g'` | awk -F ", " '{ print $1 "-" $2 "-" $3 "-" $4 "-" $5}' | sed 's/0x//g'`
sgdisk -t 1:$SPDK_GPT_GUID /dev/nbd0 sgdisk -t 1:$SPDK_GPT_GUID $nbd_path
sgdisk -t 2:$SPDK_GPT_GUID /dev/nbd0 sgdisk -t 2:$SPDK_GPT_GUID $nbd_path
elif [ "$operation" = reset ]; then elif [ "$operation" = reset ]; then
# clear the partition table # 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 fi
killprocess $nbd_pid killprocess $nbd_pid