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)" }