From 75b4f332f43638c7982e42fb0273de7e8c2e12f6 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 27 Jun 2019 02:44:24 -0700 Subject: [PATCH] bdev: All bdevs now have a UUID. For devices that don't have a UUID, the UUID is generated at registration time. That means that some devices will not have the same UUID from run to run, but this seems no worse than having no UUID at all. Change-Id: Icf6b8517ffcffabafa2b73176dc03d896d0017fe Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459604 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto --- include/spdk/bdev.h | 4 ++-- include/spdk/bdev_module.h | 3 ++- lib/bdev/bdev.c | 5 +++++ test/spdkcli/match_files/spdkcli_details_vhost.test.match | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index 4e76415dd..3978ea42d 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -411,8 +411,8 @@ bool spdk_bdev_has_write_cache(const struct spdk_bdev *bdev); * \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). + * All bdevs will have a UUID, but not all UUIDs will be persistent across + * application runs. */ const struct spdk_uuid *spdk_bdev_get_uuid(const struct spdk_bdev *bdev); diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index ac6549f9f..1af89306d 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -293,7 +293,8 @@ struct spdk_bdev { /** * UUID for this bdev. * - * Fill with zeroes if no uuid is available. + * Fill with zeroes if no uuid is available. The bdev layer + * will automatically populate this if necessary. */ struct spdk_uuid uuid; diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index cbb9b5f35..d6d0791bc 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -4022,6 +4022,11 @@ spdk_bdev_init(struct spdk_bdev *bdev) bdev->internal.qd_poller = NULL; bdev->internal.qos = NULL; + /* If the user didn't specify a uuid, generate one. */ + if (spdk_mem_all_zero(&bdev->uuid, sizeof(bdev->uuid))) { + spdk_uuid_generate(&bdev->uuid); + } + 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, diff --git a/test/spdkcli/match_files/spdkcli_details_vhost.test.match b/test/spdkcli/match_files/spdkcli_details_vhost.test.match index 757d2d398..735771cf2 100644 --- a/test/spdkcli/match_files/spdkcli_details_vhost.test.match +++ b/test/spdkcli/match_files/spdkcli_details_vhost.test.match @@ -26,5 +26,6 @@ "unmap": $(S), "write": $(S), "write_zeroes": $(S) - } + }, + "uuid": "$(S)" }