Commit 428b3078 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Jim Harris
Browse files

ublk: emit ublk_create_target in write_config_json



Otherwise, the configuration saved via save_config cannot be loaded,
because the ublk target isn't created.  Also, add a simple test
verifying this.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ic6c5073e3dfb52881d13e385578c60064a4bde13
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17992


Reviewed-by: default avatarXiaodong Liu <xiaodong.liu@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarMichal Berger <michal.berger@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
parent e90d1a81
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -624,6 +624,17 @@ spdk_ublk_write_config_json(struct spdk_json_write_ctx *w)

	spdk_json_write_array_begin(w);

	if (g_ublk_tgt.active) {
		spdk_json_write_object_begin(w);

		spdk_json_write_named_string(w, "method", "ublk_create_target");
		spdk_json_write_named_object_begin(w, "params");
		spdk_json_write_named_string(w, "cpumask", spdk_cpuset_fmt(&g_core_mask));
		spdk_json_write_object_end(w);

		spdk_json_write_object_end(w);
	}

	TAILQ_FOREACH(ublk, &g_ublk_devs, tailq) {
		spdk_json_write_object_begin(w);

+34 −0
Original line number Diff line number Diff line
@@ -96,11 +96,45 @@ function test_create_multi_ublk() {
	check_leftover_devices
}

test_save_config() (
	local tgtpid blkpath config

	"$rootdir/build/bin/spdk_tgt" -L ublk &
	tgtpid=$!
	trap 'killprocess $tgtpid' EXIT

	waitforlisten $tgtpid
	blkpath=/dev/ublkb0
	rpc_cmd <<- EOF
		ublk_create_target
		bdev_malloc_create -b malloc0 32 4096
		ublk_start_disk malloc0 0
	EOF

	# Ensure that ublk properly saves its config
	config=$(rpc_cmd save_config)
	killprocess $tgtpid

	"$rootdir/build/bin/spdk_tgt" -L ublk -c <(echo "$config") &
	tgtpid=$!

	waitforlisten $tgtpid
	[[ $(rpc_cmd ublk_get_disks | jq -r '.[0].ublk_device') == "$blkpath" ]]
	[[ -b "$blkpath" ]]

	killprocess $tgtpid
	trap - EXIT
)

function cleanup() {
	killprocess $spdk_pid
}

modprobe ublk_drv

# test_save_config starts up and terminates its own target process
run_test "test_save_ublk_config" test_save_config

"$SPDK_BIN_DIR/spdk_tgt" -m 0x3 -L ublk &
spdk_pid=$!
trap 'cleanup; exit 1' SIGINT SIGTERM EXIT