From 2b9ec05ba7774a02b218f5a766fd9406e80ff334 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 4 May 2021 21:00:50 +0000 Subject: [PATCH] bdev: add __SPDK_BDEV_MODULE_ONLY to bdev_module.h We have some cases where libraries need the spdk_bdev_module structure definition and a couple of related APIs, but not everything else (i.e. spdk_bdev, spdk_bdev_io), for purposes of avoiding abidiff errors. For example, nvmf creates a dummy spdk_bdev_module, and then uses it with the spdk_bdev_module_claim_bdev API to ensure multiple subsystems cannot add the same bdev as a namespace. But when nvmf includes bdev_module.h, it pulls in the spdk_bdev structure definition as well. This means when the spdk_bdev structure is modified, it requires a major version bump since abidiff detects the difference in the debug info. Alternatives considered: * We could add a specific suppression into our abidiff script for nvmf and struct spdk_bdev, but it would be a risk (albeit very very small one) that we could add a real dependency on struct spdk_bdev in the future, and the suppression would hide the difference. * We could also break out bdev_module.h into multiple header files, but the ways of doing that either result in odd file naming, or modifying every bdev module to include a new header. * We could add a public bdev API to expose what the bdev library needs, but that seemed even more intrusive than this change. nvmf is kind of abusing the bdev_module API here, and I'd prefer to not promote that kind of usage by adding something to the bdev API. Signed-off-by: Jim Harris Change-Id: Ie8fdef8ea294d005b9ae7934dde49c62748420d1 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7737 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- include/spdk/bdev_module.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index 66116c6a5..8fb50ce37 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -183,6 +183,14 @@ int spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *d */ void spdk_bdev_module_release_bdev(struct spdk_bdev *bdev); +/* Libraries may define __SPDK_BDEV_MODULE_ONLY so that they include + * only the struct spdk_bdev_module definition, and the relevant APIs + * to claim/release a bdev. This may be useful in some cases to avoid + * abidiff errors related to including the struct spdk_bdev structure + * unnecessarily. + */ +#ifndef __SPDK_BDEV_MODULE_ONLY + typedef void (*spdk_bdev_unregister_cb)(void *cb_arg, int rc); /** @@ -1227,4 +1235,6 @@ static void __attribute__((constructor)) _spdk_bdev_module_register_##name(void) spdk_bdev_module_list_add(module); \ } \ +#endif /* __SPDK_BDEV_MODULE_ONLY */ + #endif /* SPDK_BDEV_MODULE_H */