lib/bdev: Expose enabled DIF check types of bdev.

This patch is for DIF check types.

Add enum spdk_dif_check_type to DIF library.
Add a field dif_check_flags to struct spdk_bdev and add
spdk_bdev_is_dif_check_enabled to bdev APIs.

Added enum is intended to improve usability. If no enum, the
caller will have to get raw data of flags and mask each bit.

Change-Id: Ia46a37a9684dc968dcc51963674f0a9963e0cd4d
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/443339
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-02-07 17:41:06 +09:00 committed by Jim Harris
parent 7bb007d206
commit f4e58a003a
5 changed files with 49 additions and 0 deletions

View File

@ -445,6 +445,16 @@ enum spdk_dif_type spdk_bdev_get_dif_type(const struct spdk_bdev *bdev);
*/ */
bool spdk_bdev_is_dif_head_of_md(const struct spdk_bdev *bdev); bool spdk_bdev_is_dif_head_of_md(const struct spdk_bdev *bdev);
/**
* Check whether the DIF check type is enabled.
*
* \param bdev Block device to query.
* \param check_type The specific DIF check type.
* \return true if enabled, false otherwise.
*/
bool spdk_bdev_is_dif_check_enabled(const struct spdk_bdev *bdev,
enum spdk_dif_check_type check_type);
/** /**
* Get the most recently measured queue depth from a bdev. * Get the most recently measured queue depth from a bdev.
* *

View File

@ -320,6 +320,11 @@ struct spdk_bdev {
*/ */
bool dif_is_head_of_md; bool dif_is_head_of_md;
/**
* Specify whether each DIF check type is enabled.
*/
uint32_t dif_check_flags;
/** /**
* Pointer to the bdev module that registered this bdev. * Pointer to the bdev module that registered this bdev.
*/ */

View File

@ -53,6 +53,12 @@ enum spdk_dif_type {
SPDK_DIF_TYPE3 = 3, SPDK_DIF_TYPE3 = 3,
}; };
enum spdk_dif_check_type {
SPDK_DIF_CHECK_TYPE_REFTAG = 1,
SPDK_DIF_CHECK_TYPE_APPTAG = 2,
SPDK_DIF_CHECK_TYPE_GUARD = 3,
};
struct spdk_dif { struct spdk_dif {
uint16_t guard; uint16_t guard;
uint16_t app_tag; uint16_t app_tag;

View File

@ -2350,6 +2350,26 @@ spdk_bdev_is_dif_head_of_md(const struct spdk_bdev *bdev)
} }
} }
bool
spdk_bdev_is_dif_check_enabled(const struct spdk_bdev *bdev,
enum spdk_dif_check_type check_type)
{
if (spdk_bdev_get_dif_type(bdev) == SPDK_DIF_DISABLE) {
return false;
}
switch (check_type) {
case SPDK_DIF_CHECK_TYPE_REFTAG:
return (bdev->dif_check_flags & SPDK_DIF_FLAGS_REFTAG_CHECK) != 0;
case SPDK_DIF_CHECK_TYPE_APPTAG:
return (bdev->dif_check_flags & SPDK_DIF_FLAGS_APPTAG_CHECK) != 0;
case SPDK_DIF_CHECK_TYPE_GUARD:
return (bdev->dif_check_flags & SPDK_DIF_FLAGS_GUARD_CHECK) != 0;
default:
return false;
}
}
uint64_t uint64_t
spdk_bdev_get_qd(const struct spdk_bdev *bdev) spdk_bdev_get_qd(const struct spdk_bdev *bdev)
{ {

View File

@ -251,6 +251,14 @@ spdk_rpc_dump_bdev_info(struct spdk_json_write_ctx *w,
spdk_json_write_named_uint32(w, "dif_type", spdk_bdev_get_dif_type(bdev)); spdk_json_write_named_uint32(w, "dif_type", spdk_bdev_get_dif_type(bdev));
if (spdk_bdev_get_dif_type(bdev) != SPDK_DIF_DISABLE) { if (spdk_bdev_get_dif_type(bdev) != SPDK_DIF_DISABLE) {
spdk_json_write_named_bool(w, "dif_is_head_of_md", spdk_bdev_is_dif_head_of_md(bdev)); spdk_json_write_named_bool(w, "dif_is_head_of_md", spdk_bdev_is_dif_head_of_md(bdev));
spdk_json_write_named_object_begin(w, "enabled_dif_check_types");
spdk_json_write_named_bool(w, "reftag",
spdk_bdev_is_dif_check_enabled(bdev, SPDK_DIF_CHECK_TYPE_REFTAG));
spdk_json_write_named_bool(w, "apptag",
spdk_bdev_is_dif_check_enabled(bdev, SPDK_DIF_CHECK_TYPE_APPTAG));
spdk_json_write_named_bool(w, "guard",
spdk_bdev_is_dif_check_enabled(bdev, SPDK_DIF_CHECK_TYPE_GUARD));
spdk_json_write_object_end(w);
} }
} }