From 364d4fdfe0be536bd9519e63ac96963a84e00f17 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 1 Mar 2018 18:27:44 -0700 Subject: [PATCH] bdev: add spdk_bdev_get_uuid() function Add a generic way to get a UUID from a bdev. For now, malloc and null bdevs generate random UUIDs, and no other bdev types report a UUID. Change-Id: Id9608c8c1b3ce3f1783e7f74bef96d44cd5d98a7 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/402177 Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Tested-by: SPDK Automated Test System Reviewed-by: Tomasz Zawadzki --- include/spdk/bdev.h | 12 ++++++++++++ include/spdk_internal/bdev.h | 8 ++++++++ lib/bdev/bdev.c | 6 ++++++ lib/bdev/malloc/bdev_malloc.c | 1 + lib/bdev/null/bdev_null.c | 1 + lib/bdev/rpc/bdev_rpc.c | 8 ++++++++ 6 files changed, 36 insertions(+) diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index c343fadd3..d9beb761c 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -63,6 +63,7 @@ struct spdk_bdev_io; struct spdk_bdev_fn_table; struct spdk_io_channel; struct spdk_json_write_ctx; +struct spdk_uuid; /** bdev status */ enum spdk_bdev_status { @@ -303,6 +304,17 @@ uint32_t spdk_bdev_get_optimal_io_boundary(const struct spdk_bdev *bdev); */ bool spdk_bdev_has_write_cache(const struct spdk_bdev *bdev); +/** + * Get a bdev's UUID. + * + * \param bdev Block device to query. + * \return Pointer to UUID. + * + * Not all bdevs will have a UUID; in this case, the returned UUID will be + * the nil UUID (all bytes zero). + */ +const struct spdk_uuid *spdk_bdev_get_uuid(const struct spdk_bdev *bdev); + /** * Obtain an I/O channel for the block device opened by the specified * descriptor. I/O channels are bound to threads, so the resulting I/O diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 9b6603f5e..21b5f6b48 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -45,6 +45,7 @@ #include "spdk/queue.h" #include "spdk/scsi_spec.h" #include "spdk/io_channel.h" +#include "spdk/uuid.h" /** \page block_backend_modules Block Device Backend Modules * @@ -220,6 +221,13 @@ struct spdk_bdev { */ uint32_t optimal_io_boundary; + /** + * UUID for this bdev. + * + * Fill with zeroes if no uuid is available. + */ + struct spdk_uuid uuid; + /** * Pointer to the bdev module that registered this bdev. */ diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index b44f645d1..540464d90 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -1192,6 +1192,12 @@ spdk_bdev_has_write_cache(const struct spdk_bdev *bdev) return bdev->write_cache; } +const struct spdk_uuid * +spdk_bdev_get_uuid(const struct spdk_bdev *bdev) +{ + return &bdev->uuid; +} + int spdk_bdev_notify_blockcnt_change(struct spdk_bdev *bdev, uint64_t size) { diff --git a/lib/bdev/malloc/bdev_malloc.c b/lib/bdev/malloc/bdev_malloc.c index 485c24725..d0223fa4b 100644 --- a/lib/bdev/malloc/bdev_malloc.c +++ b/lib/bdev/malloc/bdev_malloc.c @@ -396,6 +396,7 @@ struct spdk_bdev *create_malloc_disk(const char *name, uint64_t num_blocks, uint mdisk->disk.write_cache = 1; mdisk->disk.blocklen = block_size; mdisk->disk.blockcnt = num_blocks; + spdk_uuid_generate(&mdisk->disk.uuid); mdisk->disk.ctxt = mdisk; mdisk->disk.fn_table = &malloc_fn_table; diff --git a/lib/bdev/null/bdev_null.c b/lib/bdev/null/bdev_null.c index 5cbcfc587..b87cf76b6 100644 --- a/lib/bdev/null/bdev_null.c +++ b/lib/bdev/null/bdev_null.c @@ -158,6 +158,7 @@ create_null_bdev(const char *name, uint64_t num_blocks, uint32_t block_size) bdev->bdev.write_cache = 0; bdev->bdev.blocklen = block_size; bdev->bdev.blockcnt = num_blocks; + spdk_uuid_generate(&bdev->bdev.uuid); bdev->bdev.ctxt = bdev; bdev->bdev.fn_table = &null_fn_table; diff --git a/lib/bdev/rpc/bdev_rpc.c b/lib/bdev/rpc/bdev_rpc.c index 62d690265..d8d64bcca 100644 --- a/lib/bdev/rpc/bdev_rpc.c +++ b/lib/bdev/rpc/bdev_rpc.c @@ -33,6 +33,7 @@ #include "spdk/log.h" #include "spdk/rpc.h" +#include "spdk/string.h" #include "spdk/util.h" #include "spdk_internal/bdev.h" @@ -66,6 +67,13 @@ spdk_rpc_dump_bdev_info(struct spdk_json_write_ctx *w, spdk_json_write_name(w, "num_blocks"); spdk_json_write_uint64(w, spdk_bdev_get_num_blocks(bdev)); + if (!spdk_mem_all_zero(&bdev->uuid, sizeof(bdev->uuid))) { + char uuid_str[SPDK_UUID_STRING_LEN]; + + spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &bdev->uuid); + spdk_json_write_named_string(w, "uuid", uuid_str); + } + spdk_json_write_name(w, "claimed"); spdk_json_write_bool(w, (bdev->claim_module != NULL));