include: add STATIC_ASSERTS for opts structures with size member

Various opts structures in SPDK have a size member, to enable
ABI compatibility should fields be added in the future.

But this requires the strucures to be packed, otherwise for
example a structure may be padded at the end, and a new
field added may just consume some of that padding.

So add STATIC_ASSERTS for the current sizes in this
patch.  Upcoming patches will make the structures packed
and add in reserved fields to fill in holes.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I9107d01d7b533f8542385a3538894bcd9f8c465d
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14086
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Jim Harris 2022-08-17 20:09:55 +00:00 committed by Tomasz Zawadzki
parent af0d907604
commit c50cb569de
7 changed files with 17 additions and 5 deletions

View File

@ -175,6 +175,7 @@ struct spdk_bdev_opts {
uint32_t small_buf_pool_size;
uint32_t large_buf_pool_size;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_bdev_opts) == 32, "Incorrect size");
/**
* Structure with optional IO request parameters
@ -193,6 +194,7 @@ struct spdk_bdev_ext_io_opts {
/** Metadata buffer, optional */
void *metadata;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_bdev_ext_io_opts) == 32, "Incorrect size");
/**
* Get the options for the bdev module.

View File

@ -34,6 +34,7 @@
#define SPDK_BLOB_H
#include "spdk/stdinc.h"
#include "spdk/assert.h"
#ifdef __cplusplus
extern "C" {
@ -135,6 +136,7 @@ struct spdk_blob_ext_io_opts {
/** Optional user context */
void *user_ctx;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_blob_ext_io_opts) == 32, "Incorrect size");
struct spdk_bs_dev {
/* Create a new channel which is a software construct that is used
@ -237,6 +239,7 @@ struct spdk_bs_opts {
/** Force recovery during import. This is a uint64_t for padding reasons, treated as a bool. */
uint64_t force_recover;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_bs_opts) == 72, "Incorrect size");
/**
* Initialize a spdk_bs_opts structure to the default blobstore option values.
@ -449,6 +452,7 @@ struct spdk_blob_opts {
*/
size_t opts_size;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_blob_opts) == 64, "Incorrect size");
/**
* Initialize a spdk_blob_opts structure to the default blob option values.
@ -637,6 +641,7 @@ struct spdk_blob_open_opts {
*/
size_t opts_size;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_blob_open_opts) == 16, "Incorrect size");
/**
* Initialize a spdk_blob_open_opts structure to the default blob option values.

View File

@ -20,6 +20,7 @@
#include "spdk/queue.h"
#include "spdk/log.h"
#include "spdk/thread.h"
#include "spdk/assert.h"
#ifdef __cplusplus
extern "C" {
@ -127,6 +128,7 @@ struct spdk_app_opts {
*/
size_t msg_mempool_size;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 200, "Incorrect size");
/**
* Initialize the default value of opts

View File

@ -244,6 +244,7 @@ struct spdk_nvme_ctrlr_opts {
*/
bool disable_read_ana_log_page;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_ctrlr_opts) == 616, "Incorrect size");
/**
* NVMe acceleration operation callback.
@ -551,6 +552,7 @@ struct spdk_nvme_ns_cmd_ext_io_opts {
/** Application tag to use end-to-end protection information. */
uint16_t apptag;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_ns_cmd_ext_io_opts) == 48, "Incorrect size");
/**
* Parse the string representation of a transport ID.
@ -1543,6 +1545,7 @@ struct spdk_nvme_io_qpair_opts {
*/
bool async_mode;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_io_qpair_opts) == 72, "Incorrect size");
/**
* Get the default options for I/O qpair creation for a specific NVMe controller.

View File

@ -89,6 +89,7 @@ struct spdk_nvmf_transport_opts {
/* Use zero-copy operations if the underlying bdev supports them */
bool zcopy;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_transport_opts) == 64, "Incorrect size");
struct spdk_nvmf_listen_opts {
/**
@ -101,6 +102,7 @@ struct spdk_nvmf_listen_opts {
const struct spdk_json_val *transport_specific;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listen_opts) == 16, "Incorrect size");
/**
* Initialize listen options
@ -741,6 +743,7 @@ struct spdk_nvmf_ns_opts {
*/
uint32_t anagrpid;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ns_opts) == 64, "Incorrect size");
/**
* Get default namespace creation options.

View File

@ -14,6 +14,7 @@
#include "spdk/queue.h"
#include "spdk/json.h"
#include "spdk/assert.h"
#ifdef __cplusplus
extern "C" {
@ -191,6 +192,7 @@ struct spdk_sock_opts {
*/
size_t impl_opts_size;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_sock_opts) == 40, "Incorrect size");
/**
* Initialize the default value of opts.

View File

@ -962,11 +962,6 @@ nvme_ctrlr_opts_init(struct spdk_nvme_ctrlr_opts *opts,
SET_FIELD(fabrics_connect_timeout_us);
SET_FIELD(disable_read_ana_log_page);
/* Do not remove this statement. When you add a new field, please do update this
* assert with the correct size. And do not forget to add a new SET_FIELD statement
* related with your new added field. */
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_ctrlr_opts) == 616, "Incorrect size");
#undef FIELD_OK
#undef SET_FIELD
#undef SET_FIELD_ARRAY