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 <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/402177
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Daniel Verkamp 2018-03-01 18:27:44 -07:00 committed by Jim Harris
parent 4c06ce9b9d
commit 364d4fdfe0
6 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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.
*/

View File

@ -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)
{

View File

@ -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;

View File

@ -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;

View File

@ -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));