From 139da44c43b45d8acdffb65c13a95996388e5565 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 4 Feb 2019 17:21:20 +0900 Subject: [PATCH] lib/bdev: Expose metadata size and setting of bdev To support DIF, bdev will need to expose the following information: - Metadata format - Block size - Metadata size - Metadata setting (interleave or separate) - DIF settings - DIF type 1, 2, or 3 - DIF location - DIF check types - Guard check - Reference tag check - Application tag check This patch is for the metadata format. Subsequent patches will do for the DIF setting and DIF check types. Add fields, md_len and md_interleave, to struct spdk_bdev and add APIs, spdk_bdev_get_md_size and spdk_bdev_is_md_interleaved, to bdev APIs. The fields, md_len and md_interleave, are added to the bdev JSON infomation dump. DIF will be used only in the NVMe bdev module and the upcoming virtual DIF bdev module first. But additional required storage by md_len and md_interleave will be very small and they are simple. Hence add them to struct spdk_bdev simply. Change-Id: I4109f6a63e6f0576efe424feb0305a9a17b9b2e8 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/443183 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- include/spdk/bdev.h | 20 ++++++++++++++++++++ include/spdk/bdev_module.h | 11 +++++++++++ lib/bdev/bdev.c | 12 ++++++++++++ lib/bdev/rpc/bdev_rpc.c | 5 +++++ 4 files changed, 48 insertions(+) diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index 858839e4b..af73eba74 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -405,6 +405,26 @@ bool spdk_bdev_has_write_cache(const struct spdk_bdev *bdev); */ const struct spdk_uuid *spdk_bdev_get_uuid(const struct spdk_bdev *bdev); +/** + * Get block device metadata size. + * + * \param bdev Block device to query. + * \return Size of metadata for this bdev in bytes. + */ +uint32_t spdk_bdev_get_md_size(const struct spdk_bdev *bdev); + +/** + * Query whether metadata is interleaved with block data or separated + * with block data. + * + * \param bdev Block device to query. + * \return true if metadata is interleaved with block data or false + * if metadata is separated with block data. + * + * Note this function is valid only if there is metadata. + */ +bool spdk_bdev_is_md_interleaved(const struct spdk_bdev *bdev); + /** * Get the most recently measured queue depth from a bdev. * diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index 296c6059f..b68c89b17 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -292,6 +292,17 @@ struct spdk_bdev { */ struct spdk_uuid uuid; + /** Size in bytes of a metadata for the backend */ + uint32_t md_len; + + /** + * Specify metadata location and set to true if metadata is interleaved + * with block data or false if metadata is separated with block data. + * + * Note that this field is valid only if there is metadata. + */ + bool md_interleave; + /** * Pointer to the bdev module that registered this bdev. */ diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index f0d960a2c..fa92bf102 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -2319,6 +2319,18 @@ spdk_bdev_get_uuid(const struct spdk_bdev *bdev) return &bdev->uuid; } +uint32_t +spdk_bdev_get_md_size(const struct spdk_bdev *bdev) +{ + return bdev->md_len; +} + +bool +spdk_bdev_is_md_interleaved(const struct spdk_bdev *bdev) +{ + return (bdev->md_len != 0) && bdev->md_interleave; +} + uint64_t spdk_bdev_get_qd(const struct spdk_bdev *bdev) { diff --git a/lib/bdev/rpc/bdev_rpc.c b/lib/bdev/rpc/bdev_rpc.c index 3675a0ad7..6f88c551a 100644 --- a/lib/bdev/rpc/bdev_rpc.c +++ b/lib/bdev/rpc/bdev_rpc.c @@ -245,6 +245,11 @@ spdk_rpc_dump_bdev_info(struct spdk_json_write_ctx *w, spdk_json_write_named_string(w, "uuid", uuid_str); } + if (spdk_bdev_get_md_size(bdev) != 0) { + spdk_json_write_named_uint32(w, "md_size", spdk_bdev_get_md_size(bdev)); + spdk_json_write_named_bool(w, "md_interleave", spdk_bdev_is_md_interleaved(bdev)); + } + spdk_json_write_named_object_begin(w, "assigned_rate_limits"); spdk_bdev_get_qos_rate_limits(bdev, qos_limits); for (i = 0; i < SPDK_BDEV_QOS_NUM_RATE_LIMIT_TYPES; i++) {