From b58a5d73ef70b9458ef589f5858c2a72c1f8e47c Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 3 Mar 2017 13:44:04 -0700 Subject: [PATCH] util: add SPDK_COUNTOF() array size macro SPDK_COUNTOF works like sizeof, except it returns the number of elements in an array instead of the number of bytes. Change-Id: I38ff4dd3485ed9b630cc5660ff84851d0031911f Signed-off-by: Daniel Verkamp --- app/nvmf_tgt/nvmf_rpc.c | 7 ++++--- examples/nvme/identify/identify.c | 5 +++-- examples/nvme/nvme_manage/nvme_manage.c | 3 ++- include/spdk/util.h | 2 ++ lib/bdev/aio/blockdev_aio_rpc.c | 3 ++- lib/bdev/malloc/blockdev_malloc_rpc.c | 3 ++- lib/bdev/nvme/blockdev_nvme_rpc.c | 3 ++- lib/bdev/rbd/blockdev_rbd_rpc.c | 3 ++- lib/env_dpdk/vtophys.c | 3 ++- lib/event/rpc/app_rpc.c | 5 +++-- lib/iscsi/iscsi_rpc.c | 15 ++++++++------- lib/jsonrpc/jsonrpc_server.c | 4 +++- lib/log/rpc/log_rpc.c | 5 +++-- lib/net/net_rpc.c | 5 +++-- lib/nvmf/direct.c | 3 ++- lib/nvmf/session.c | 3 ++- lib/nvmf/transport.c | 3 ++- lib/nvmf/virtual.c | 3 ++- lib/scsi/scsi_rpc.c | 3 ++- lib/vhost/vhost_rpc.c | 5 +++-- test/lib/json/write/json_write_ut.c | 4 +++- test/lib/nvme/sgl/sgl.c | 5 +++-- 22 files changed, 60 insertions(+), 35 deletions(-) diff --git a/app/nvmf_tgt/nvmf_rpc.c b/app/nvmf_tgt/nvmf_rpc.c index 0666b5a5a..79b783ec7 100644 --- a/app/nvmf_tgt/nvmf_rpc.c +++ b/app/nvmf_tgt/nvmf_rpc.c @@ -40,6 +40,7 @@ #include "spdk/env.h" #include "spdk/nvme.h" #include "spdk/nvmf.h" +#include "spdk/util.h" #include "nvmf_tgt.h" @@ -176,7 +177,7 @@ decode_rpc_listen_address(const struct spdk_json_val *val, void *out) { struct rpc_listen_address *req = (struct rpc_listen_address *)out; if (spdk_json_decode_object(val, rpc_listen_address_decoders, - sizeof(rpc_listen_address_decoders) / sizeof(*rpc_listen_address_decoders), + SPDK_COUNTOF(rpc_listen_address_decoders), req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); return -1; @@ -297,7 +298,7 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_server_conn *conn, req.core = -1; /* Explicitly set the core as the uninitialized value */ if (spdk_json_decode_object(params, rpc_subsystem_decoders, - sizeof(rpc_subsystem_decoders) / sizeof(*rpc_subsystem_decoders), + SPDK_COUNTOF(rpc_subsystem_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; @@ -349,7 +350,7 @@ spdk_rpc_delete_nvmf_subsystem(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_delete_subsystem_decoders, - sizeof(rpc_delete_subsystem_decoders) / sizeof(*rpc_delete_subsystem_decoders), + SPDK_COUNTOF(rpc_delete_subsystem_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index ebe16f686..f260b89c1 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -47,6 +47,7 @@ #include "spdk/nvme_intel.h" #include "spdk/nvmf_spec.h" #include "spdk/pci_ids.h" +#include "spdk/util.h" static int outstanding_commands; @@ -166,7 +167,7 @@ get_features(struct spdk_nvme_ctrlr *ctrlr) /* Submit several GET FEATURES commands and wait for them to complete */ outstanding_commands = 0; - for (i = 0; i < sizeof(features_to_get) / sizeof(*features_to_get); i++) { + for (i = 0; i < SPDK_COUNTOF(features_to_get); i++) { if (get_feature(ctrlr, features_to_get[i]) == 0) { outstanding_commands++; } else { @@ -714,7 +715,7 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport printf("Intel Health Information\n"); printf("==================\n"); for (i = 0; - i < sizeof(intel_smart_page.attributes) / sizeof(intel_smart_page.attributes[0]); i++) { + i < SPDK_COUNTOF(intel_smart_page.attributes); i++) { if (intel_smart_page.attributes[i].code == SPDK_NVME_INTEL_SMART_PROGRAM_FAIL_COUNT) { printf("Program Fail Count:\n"); printf(" Normalized Value : %d\n", diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index f04f6222e..49f11853e 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -47,6 +47,7 @@ #include "spdk/nvme.h" #include "spdk/env.h" +#include "spdk/util.h" #define MAX_DEVS 64 @@ -386,7 +387,7 @@ get_allocated_nsid(struct dev *dev) } printf("Allocated Namespace IDs:\n"); - for (i = 0; i < sizeof(ns_list->ns_list) / sizeof(*ns_list->ns_list); i++) { + for (i = 0; i < SPDK_COUNTOF(ns_list->ns_list); i++) { if (ns_list->ns_list[i] == 0) { break; } diff --git a/include/spdk/util.h b/include/spdk/util.h index 952fa53cc..ec5ff793f 100644 --- a/include/spdk/util.h +++ b/include/spdk/util.h @@ -48,6 +48,8 @@ extern "C" { #define spdk_min(a,b) (((a)<(b))?(a):(b)) #define spdk_max(a,b) (((a)>(b))?(a):(b)) +#define SPDK_COUNTOF(arr) (sizeof(arr) / sizeof((arr)[0])) + static inline uint32_t spdk_u32log2(uint32_t x) { diff --git a/lib/bdev/aio/blockdev_aio_rpc.c b/lib/bdev/aio/blockdev_aio_rpc.c index 97fbab1f9..943de453a 100644 --- a/lib/bdev/aio/blockdev_aio_rpc.c +++ b/lib/bdev/aio/blockdev_aio_rpc.c @@ -33,6 +33,7 @@ #include "blockdev_aio.h" #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -60,7 +61,7 @@ spdk_rpc_construct_aio_bdev(struct spdk_jsonrpc_server_conn *conn, struct spdk_bdev *bdev; if (spdk_json_decode_object(params, rpc_construct_aio_decoders, - sizeof(rpc_construct_aio_decoders) / sizeof(*rpc_construct_aio_decoders), + SPDK_COUNTOF(rpc_construct_aio_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/bdev/malloc/blockdev_malloc_rpc.c b/lib/bdev/malloc/blockdev_malloc_rpc.c index a78a85d49..20c123f0c 100644 --- a/lib/bdev/malloc/blockdev_malloc_rpc.c +++ b/lib/bdev/malloc/blockdev_malloc_rpc.c @@ -33,6 +33,7 @@ #include "blockdev_malloc.h" #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -56,7 +57,7 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_server_conn *conn, struct spdk_bdev *bdev; if (spdk_json_decode_object(params, rpc_construct_malloc_decoders, - sizeof(rpc_construct_malloc_decoders) / sizeof(*rpc_construct_malloc_decoders), + SPDK_COUNTOF(rpc_construct_malloc_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/bdev/nvme/blockdev_nvme_rpc.c b/lib/bdev/nvme/blockdev_nvme_rpc.c index 8cd61827a..f8a71c0b1 100644 --- a/lib/bdev/nvme/blockdev_nvme_rpc.c +++ b/lib/bdev/nvme/blockdev_nvme_rpc.c @@ -35,6 +35,7 @@ #include "blockdev_nvme.h" #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -67,7 +68,7 @@ spdk_rpc_construct_nvme_bdev(struct spdk_jsonrpc_server_conn *conn, size_t i; if (spdk_json_decode_object(params, rpc_construct_nvme_decoders, - sizeof(rpc_construct_nvme_decoders) / sizeof(*rpc_construct_nvme_decoders), + SPDK_COUNTOF(rpc_construct_nvme_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/bdev/rbd/blockdev_rbd_rpc.c b/lib/bdev/rbd/blockdev_rbd_rpc.c index 75995ebe2..a10a06ae7 100644 --- a/lib/bdev/rbd/blockdev_rbd_rpc.c +++ b/lib/bdev/rbd/blockdev_rbd_rpc.c @@ -33,6 +33,7 @@ #include "blockdev_rbd.h" #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -65,7 +66,7 @@ spdk_rpc_construct_rbd_bdev(struct spdk_jsonrpc_server_conn *conn, struct spdk_bdev *bdev; if (spdk_json_decode_object(params, rpc_construct_rbd_decoders, - sizeof(rpc_construct_rbd_decoders) / sizeof(*rpc_construct_rbd_decoders), + SPDK_COUNTOF(rpc_construct_rbd_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/env_dpdk/vtophys.c b/lib/env_dpdk/vtophys.c index 0a97e8344..7ef7a8daa 100644 --- a/lib/env_dpdk/vtophys.c +++ b/lib/env_dpdk/vtophys.c @@ -45,6 +45,7 @@ #include "spdk/assert.h" #include "spdk/likely.h" +#include "spdk/util.h" /* x86-64 userspace virtual addresses use only the low 47 bits [0..46], * which is enough to cover 128 TB. @@ -138,7 +139,7 @@ spdk_mem_map_get_map_1gb(struct spdk_mem_map *map, uint64_t vfn_2mb) map_1gb = malloc(sizeof(struct map_1gb)); if (map_1gb) { /* initialize all entries to default translation */ - for (i = 0; i < sizeof(map_1gb->map) / sizeof(map_1gb->map[0]); i++) { + for (i = 0; i < SPDK_COUNTOF(map_1gb->map); i++) { map_1gb->map[i].translation_2mb = map->default_translation; } memset(map_1gb->ref_count, 0, sizeof(map_1gb->ref_count)); diff --git a/lib/event/rpc/app_rpc.c b/lib/event/rpc/app_rpc.c index 1ebcd3864..11b4d8719 100644 --- a/lib/event/rpc/app_rpc.c +++ b/lib/event/rpc/app_rpc.c @@ -39,6 +39,7 @@ #include #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -77,13 +78,13 @@ spdk_rpc_kill_instance(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_kill_instance_decoders, - sizeof(rpc_kill_instance_decoders) / sizeof(*rpc_kill_instance_decoders), + SPDK_COUNTOF(rpc_kill_instance_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; } - sig_count = sizeof(signals) / sizeof(*signals); + sig_count = SPDK_COUNTOF(signals); signal = atoi(req.sig_name); for (i = 0 ; i < sig_count; i++) { if (strcmp(req.sig_name, signals[i].signal_string) == 0 || diff --git a/lib/iscsi/iscsi_rpc.c b/lib/iscsi/iscsi_rpc.c index a594fd1c0..4c40cf3fc 100644 --- a/lib/iscsi/iscsi_rpc.c +++ b/lib/iscsi/iscsi_rpc.c @@ -39,6 +39,7 @@ #include "iscsi/init_grp.h" #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -171,7 +172,7 @@ spdk_rpc_add_initiator_group(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_initiator_group_decoders, - sizeof(rpc_initiator_group_decoders) / sizeof(*rpc_initiator_group_decoders), &req)) { + SPDK_COUNTOF(rpc_initiator_group_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; } @@ -259,7 +260,7 @@ spdk_rpc_delete_initiator_group(struct spdk_jsonrpc_server_conn *conn, struct spdk_iscsi_init_grp *ig; if (spdk_json_decode_object(params, rpc_delete_initiator_group_decoders, - sizeof(rpc_delete_initiator_group_decoders) / sizeof(*rpc_delete_initiator_group_decoders), + SPDK_COUNTOF(rpc_delete_initiator_group_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; @@ -500,7 +501,7 @@ spdk_rpc_construct_target_node(struct spdk_jsonrpc_server_conn *conn, struct spdk_iscsi_tgt_node *target; if (spdk_json_decode_object(params, rpc_target_node_decoders, - sizeof(rpc_target_node_decoders) / sizeof(*rpc_target_node_decoders), + SPDK_COUNTOF(rpc_target_node_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; @@ -580,7 +581,7 @@ spdk_rpc_delete_target_node(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_delete_target_node_decoders, - sizeof(rpc_delete_target_node_decoders) / sizeof(*rpc_delete_target_node_decoders), + SPDK_COUNTOF(rpc_delete_target_node_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; @@ -714,7 +715,7 @@ decode_rpc_portal(const struct spdk_json_val *val, void *out) struct rpc_portal *portal = out; return spdk_json_decode_object(val, rpc_portal_decoders, - sizeof(rpc_portal_decoders) / sizeof(*rpc_portal_decoders), + SPDK_COUNTOF(rpc_portal_decoders), portal); } @@ -743,7 +744,7 @@ spdk_rpc_add_portal_group(struct spdk_jsonrpc_server_conn *conn, size_t i; if (spdk_json_decode_object(params, rpc_portal_group_decoders, - sizeof(rpc_portal_group_decoders) / sizeof(*rpc_portal_group_decoders), + SPDK_COUNTOF(rpc_portal_group_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; @@ -805,7 +806,7 @@ spdk_rpc_delete_portal_group(struct spdk_jsonrpc_server_conn *conn, struct spdk_iscsi_portal_grp *pg; if (spdk_json_decode_object(params, rpc_delete_portal_group_decoders, - sizeof(rpc_delete_portal_group_decoders) / sizeof(*rpc_delete_portal_group_decoders), + SPDK_COUNTOF(rpc_delete_portal_group_decoders), &req)) { SPDK_ERRLOG("spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/jsonrpc/jsonrpc_server.c b/lib/jsonrpc/jsonrpc_server.c index 223132052..f64e7fa43 100644 --- a/lib/jsonrpc/jsonrpc_server.c +++ b/lib/jsonrpc/jsonrpc_server.c @@ -33,6 +33,8 @@ #include "jsonrpc_internal.h" +#include "spdk/util.h" + struct jsonrpc_request { const struct spdk_json_val *version; const struct spdk_json_val *method; @@ -63,7 +65,7 @@ parse_single_request(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_val struct jsonrpc_request req = {}; if (spdk_json_decode_object(values, jsonrpc_request_decoders, - sizeof(jsonrpc_request_decoders) / sizeof(*jsonrpc_request_decoders), + SPDK_COUNTOF(jsonrpc_request_decoders), &req)) { invalid = true; goto done; diff --git a/lib/log/rpc/log_rpc.c b/lib/log/rpc/log_rpc.c index 0f18443ad..3392469fd 100644 --- a/lib/log/rpc/log_rpc.c +++ b/lib/log/rpc/log_rpc.c @@ -32,6 +32,7 @@ */ #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -58,7 +59,7 @@ spdk_rpc_set_trace_flag(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_trace_flag_decoders, - sizeof(rpc_trace_flag_decoders) / sizeof(*rpc_trace_flag_decoders), &req)) { + SPDK_COUNTOF(rpc_trace_flag_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; } @@ -95,7 +96,7 @@ spdk_rpc_clear_trace_flag(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_trace_flag_decoders, - sizeof(rpc_trace_flag_decoders) / sizeof(*rpc_trace_flag_decoders), &req)) { + SPDK_COUNTOF(rpc_trace_flag_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; } diff --git a/lib/net/net_rpc.c b/lib/net/net_rpc.c index 40f462314..54159f8f8 100644 --- a/lib/net/net_rpc.c +++ b/lib/net/net_rpc.c @@ -38,6 +38,7 @@ #include "spdk/rpc.h" #include "spdk/net.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -66,7 +67,7 @@ spdk_rpc_add_ip_address(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_ip_address_decoders, - sizeof(rpc_ip_address_decoders) / sizeof(*rpc_ip_address_decoders), + SPDK_COUNTOF(rpc_ip_address_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; @@ -102,7 +103,7 @@ spdk_rpc_delete_ip_address(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_ip_address_decoders, - sizeof(rpc_ip_address_decoders) / sizeof(*rpc_ip_address_decoders), + SPDK_COUNTOF(rpc_ip_address_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/nvmf/direct.c b/lib/nvmf/direct.c index 8c08ec96a..e76c6d8a7 100644 --- a/lib/nvmf/direct.c +++ b/lib/nvmf/direct.c @@ -38,6 +38,7 @@ #include "spdk/nvme.h" #include "spdk/nvmf_spec.h" #include "spdk/trace.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -96,7 +97,7 @@ nvmf_direct_ctrlr_admin_identify_nslist(struct spdk_nvme_ctrlr *ctrlr, } ns_list->ns_list[count++] = i; - if (count == sizeof(*ns_list) / sizeof(uint32_t)) { + if (count == SPDK_COUNTOF(ns_list->ns_list)) { break; } } diff --git a/lib/nvmf/session.c b/lib/nvmf/session.c index 67a95a9d9..348c42ed5 100644 --- a/lib/nvmf/session.c +++ b/lib/nvmf/session.c @@ -43,6 +43,7 @@ #include "spdk/trace.h" #include "spdk/nvme_spec.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -527,7 +528,7 @@ find_prop(uint32_t ofst) { size_t i; - for (i = 0; i < sizeof(nvmf_props) / sizeof(*nvmf_props); i++) { + for (i = 0; i < SPDK_COUNTOF(nvmf_props); i++) { const struct nvmf_prop *prop = &nvmf_props[i]; if (prop->ofst == ofst) { diff --git a/lib/nvmf/transport.c b/lib/nvmf/transport.c index cfef6b84e..bd4f56a74 100644 --- a/lib/nvmf/transport.c +++ b/lib/nvmf/transport.c @@ -39,6 +39,7 @@ #include "spdk/log.h" #include "spdk/nvmf.h" #include "spdk/queue.h" +#include "spdk/util.h" #include "nvmf_internal.h" @@ -48,7 +49,7 @@ static const struct spdk_nvmf_transport *const g_transports[] = { #endif }; -#define NUM_TRANSPORTS (sizeof(g_transports) / sizeof(*g_transports)) +#define NUM_TRANSPORTS (SPDK_COUNTOF(g_transports)) int spdk_nvmf_transport_init(void) diff --git a/lib/nvmf/virtual.c b/lib/nvmf/virtual.c index 02407e286..7f8d87576 100644 --- a/lib/nvmf/virtual.c +++ b/lib/nvmf/virtual.c @@ -46,6 +46,7 @@ #include "spdk/trace.h" #include "spdk/scsi_spec.h" #include "spdk/string.h" +#include "spdk/util.h" #include "spdk_internal/log.h" @@ -230,7 +231,7 @@ identify_active_ns_list(struct spdk_nvmf_subsystem *subsystem, continue; } ns_list->ns_list[count++] = i; - if (count == sizeof(*ns_list) / sizeof(uint32_t)) { + if (count == SPDK_COUNTOF(ns_list->ns_list)) { break; } } diff --git a/lib/scsi/scsi_rpc.c b/lib/scsi/scsi_rpc.c index 0af4083a7..762cbc827 100644 --- a/lib/scsi/scsi_rpc.c +++ b/lib/scsi/scsi_rpc.c @@ -35,6 +35,7 @@ #include "scsi_internal.h" #include "spdk/rpc.h" +#include "spdk/util.h" static void spdk_rpc_get_luns(struct spdk_jsonrpc_server_conn *conn, @@ -100,7 +101,7 @@ spdk_rpc_delete_lun(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w; if (spdk_json_decode_object(params, rpc_delete_lun_decoders, - sizeof(rpc_delete_lun_decoders) / sizeof(*rpc_delete_lun_decoders), + SPDK_COUNTOF(rpc_delete_lun_decoders), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); goto invalid; diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index 493b19be2..65dd91309 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -35,6 +35,7 @@ #include "spdk_internal/log.h" #include "spdk/rpc.h" +#include "spdk/util.h" #include "spdk/vhost.h" #include "task.h" @@ -144,7 +145,7 @@ spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_server_conn *conn, uint64_t cpumask; if (spdk_json_decode_object(params, rpc_construct_vhost_ctrlr, - sizeof(rpc_construct_vhost_ctrlr) / sizeof(*rpc_construct_vhost_ctrlr), + SPDK_COUNTOF(rpc_construct_vhost_ctrlr), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); rc = -EINVAL; @@ -193,7 +194,7 @@ spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_server_conn *conn, int rc; if (spdk_json_decode_object(params, rpc_vhost_add_lun, - sizeof(rpc_vhost_add_lun) / sizeof(*rpc_vhost_add_lun), + SPDK_COUNTOF(rpc_vhost_add_lun), &req)) { SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); rc = -EINVAL; diff --git a/test/lib/json/write/json_write_ut.c b/test/lib/json/write/json_write_ut.c index 7cfb5df46..6afca1438 100644 --- a/test/lib/json/write/json_write_ut.c +++ b/test/lib/json/write/json_write_ut.c @@ -38,6 +38,8 @@ #include #include +#include "spdk/util.h" + static uint8_t g_buf[1000]; static uint8_t *g_write_pos; @@ -590,7 +592,7 @@ test_write_val(void) struct spdk_json_val values[100]; char src[] = "{\"a\":[1,2,3],\"b\":{\"c\":\"d\"},\"e\":true,\"f\":false,\"g\":null}"; - CU_ASSERT(spdk_json_parse(src, strlen(src), values, sizeof(values) / sizeof(*values), NULL, + CU_ASSERT(spdk_json_parse(src, strlen(src), values, SPDK_COUNTOF(values), NULL, SPDK_JSON_PARSE_FLAG_DECODE_IN_PLACE) == 19); BEGIN(); diff --git a/test/lib/nvme/sgl/sgl.c b/test/lib/nvme/sgl/sgl.c index 8bcd4935b..505eeeb98 100644 --- a/test/lib/nvme/sgl/sgl.c +++ b/test/lib/nvme/sgl/sgl.c @@ -39,6 +39,7 @@ #include "spdk/nvme.h" #include "spdk/env.h" +#include "spdk/util.h" #define MAX_DEVS 64 @@ -261,8 +262,8 @@ static void build_io_request_9(struct io_request *req) const size_t req_off[] = { 0x800, 0x0, 0x0, 0x100, 0x800, 0x800 }; struct sgl_element *iovs = req->iovs; uint32_t i; - req->nseg = sizeof(req_len) / sizeof(req_len[0]); - assert(sizeof(req_len) / sizeof(req_len[0]) == sizeof(req_off) / sizeof(req_off[0])); + req->nseg = SPDK_COUNTOF(req_len); + assert(SPDK_COUNTOF(req_len) == SPDK_COUNTOF(req_off)); for (i = 0; i < req->nseg; i++) { iovs[i].base = spdk_zmalloc(req_off[i] + req_len[i], 0x4000, NULL);