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

bdev: register bdev's UUID as its alias



In many cases, addressing bdevs by their UUIDs is often easier than
using their names, which can be somewhat arbitrary.  For instance, the
NVMe bdev builds a name by addng the n{NSID} suffix to the controller's
name, while the UUID is filled with NGUID (if available).

The UUID alias is stored in the form defined by RFC 4122, meaning five
groups of lower-case hexadecimal characters.  It's important to note
that bdev layer uses case-sensitive name comparison, so the user needs
to use the same textual UUID representation.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent a5895656
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -5717,6 +5717,7 @@ static int
bdev_register(struct spdk_bdev *bdev)
{
	char *bdev_name;
	char uuid[SPDK_UUID_STRING_LEN];
	int ret;

	assert(bdev->module != NULL);
@@ -5761,6 +5762,18 @@ bdev_register(struct spdk_bdev *bdev)
		spdk_uuid_generate(&bdev->uuid);
	}

	/* Add the UUID alias only if it's different than the name */
	spdk_uuid_fmt_lower(uuid, sizeof(uuid), &bdev->uuid);
	if (strcmp(bdev->name, uuid) != 0) {
		ret = spdk_bdev_alias_add(bdev, uuid);
		if (ret != 0) {
			SPDK_ERRLOG("Unable to add uuid:%s alias for bdev %s\n", uuid, bdev->name);
			bdev_name_del(&bdev->internal.bdev_name);
			free(bdev_name);
			return ret;
		}
	}

	if (spdk_bdev_get_buf_align(bdev) > 1) {
		if (bdev->split_on_optimal_io_boundary) {
			bdev->optimal_io_boundary = spdk_min(bdev->optimal_io_boundary,
@@ -5889,6 +5902,7 @@ bdev_unregister_unsafe(struct spdk_bdev *bdev)
{
	struct spdk_bdev_desc	*desc, *tmp;
	int			rc = 0;
	char			uuid[SPDK_UUID_STRING_LEN];

	/* Notify each descriptor about hotremoval */
	TAILQ_FOREACH_SAFE(desc, &bdev->internal.open_descs, link, tmp) {
@@ -5909,7 +5923,12 @@ bdev_unregister_unsafe(struct spdk_bdev *bdev)
	if (rc == 0) {
		TAILQ_REMOVE(&g_bdev_mgr.bdevs, bdev, internal.link);
		SPDK_DEBUGLOG(bdev, "Removing bdev %s from list done\n", bdev->name);

		/* Delete the name and the UUID alias */
		spdk_uuid_fmt_lower(uuid, sizeof(uuid), &bdev->uuid);
		bdev_name_del_unsafe(&bdev->internal.bdev_name);
		bdev_alias_del(bdev, uuid, bdev_name_del_unsafe);

		spdk_notify_send("bdev_unregister", spdk_bdev_get_name(bdev));
	}

+5 −1
Original line number Diff line number Diff line
@@ -12,6 +12,10 @@ null_block_size=512
null_bdev=null0
nvme_bdev=nvme0

# Since we're connecting the same bdev, we need to use a different NGUID to avoid errors when
# registering the bdev during bdev_nvme_attach_controller
nguid=$(uuidgen | tr -d '-')

if [ "$TEST_TRANSPORT" != "tcp" ]; then
	echo "This test can only be executed with TCP for now"
	exit 0
@@ -25,7 +29,7 @@ $rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS
$rpc_py bdev_null_create $null_bdev $null_bdev_size $null_block_size
$rpc_py bdev_wait_for_examine
$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode0 -a
$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode0 $null_bdev
$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode0 $null_bdev -g $nguid
$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode0 -t $TEST_TRANSPORT \
	-a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT

+3 −1
Original line number Diff line number Diff line
{
  "aliases": [],
  "aliases": [
    "$(UUID)"
  ],
  "assigned_rate_limits": {
    "r_mbytes_per_sec": $(N),
    "rw_ios_per_sec": $(N),
+2 −2
Original line number Diff line number Diff line
o- pmemblk .............................................................................................................. [Bdevs: 2]
  o- pmem_bdev0 .......................................................................................... [Size=31.6M, Not claimed]
  o- pmem_bdev1 .......................................................................................... [Size=31.6M, Not claimed]
  o- pmem_bdev0 $(S) [$(UUID), Size=31.6M, Not claimed]
  o- pmem_bdev1 $(S) [$(UUID), Size=31.6M, Not claimed]
+3 −3
Original line number Diff line number Diff line
@@ -4,13 +4,13 @@ o- bdevs .......................................................................
  o- iscsi .............................................................................................................. [Bdevs: 0]
  o- logical_volume ..................................................................................................... [Bdevs: 0]
  o- malloc ............................................................................................................. [Bdevs: 2]
  | o- Malloc1 ................................................................................................ [Size=8.0M, Claimed]
  | o- Malloc2 ................................................................................................ [Size=8.0M, Claimed]
  | o- Malloc1 $(S) [$(UUID), Size=8.0M, Claimed]
  | o- Malloc2 $(S) [$(UUID), Size=8.0M, Claimed]
  o- null ............................................................................................................... [Bdevs: 0]
  o- nvme ............................................................................................................... [Bdevs: 0]
  o- pmemblk ............................................................................................................ [Bdevs: 0]
  o- raid_volume ........................................................................................................ [Bdevs: 1]
  | o- testraid .......................................................................................... [Size=16.0M, Not claimed]
  | o- testraid $(S) [$(UUID), Size=16.0M, Not claimed]
  o- rbd ................................................................................................................ [Bdevs: 0]
  o- split_disk ......................................................................................................... [Bdevs: 0]
  o- virtioblk_disk ..................................................................................................... [Bdevs: 0]
Loading