Commit b58a5d73 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent ba5081db
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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;
+3 −2
Original line number Diff line number Diff line
@@ -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",
+2 −1
Original line number Diff line number Diff line
@@ -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;
		}
+2 −0
Original line number Diff line number Diff line
@@ -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)
{
+2 −1
Original line number Diff line number Diff line
@@ -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;
Loading