bdev: claim_module becomes claim.v1.module

In preparation for an updated claims API, refactor
bdev->internal.claim_module into a union that will eventually hold
different information based on the the type of claim.

Change-Id: I7ade6f03128bdb0f8375a95ae953cb63d6aa686d
Signed-off-by: Mike Gerdts <mgerdts@nvidia.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15285
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Mike Gerdts 2022-10-24 10:16:53 -05:00 committed by Jim Harris
parent 93b53c0268
commit 9fd2f931cd
6 changed files with 39 additions and 33 deletions

View File

@ -522,12 +522,17 @@ struct spdk_bdev {
/** The bdev status */ /** The bdev status */
enum spdk_bdev_status status; enum spdk_bdev_status status;
/** /** Which module has claimed this bdev. Must hold spinlock on all updates. */
* Pointer to the module that has claimed this bdev for purposes of creating virtual union __bdev_internal_claim {
* bdevs on top of it. Set to NULL if the bdev has not been claimed. Must hold struct __bdev_internal_claim_v1 {
* spinlock on all updates. /**
*/ * Pointer to the module that has claimed this bdev for purposes of
struct spdk_bdev_module *claim_module; * creating virtual bdevs on top of it. Set to NULL if the bdev has
* not been claimed.
*/
struct spdk_bdev_module *module;
} v1;
} claim;
/** Callback function that will be called after bdev destruct is completed. */ /** Callback function that will be called after bdev destruct is completed. */
spdk_bdev_unregister_cb unregister_cb; spdk_bdev_unregister_cb unregister_cb;

View File

@ -658,13 +658,13 @@ bdev_examine(struct spdk_bdev *bdev)
spdk_spin_unlock(&module->internal.spinlock); spdk_spin_unlock(&module->internal.spinlock);
module->examine_config(bdev); module->examine_config(bdev);
if (action != module->internal.action_in_progress) { if (action != module->internal.action_in_progress) {
SPDK_ERRLOG("examine_config for module %s did not call spdk_bdev_module_examine_done()\n", SPDK_ERRLOG("examine_config for module %s did not call "
module->name); "spdk_bdev_module_examine_done()\n", module->name);
} }
} }
} }
module = bdev->internal.claim_module; module = bdev->internal.claim.v1.module;
if (module != NULL) { if (module != NULL) {
if (module->examine_disk) { if (module->examine_disk) {
spdk_spin_lock(&module->internal.spinlock); spdk_spin_lock(&module->internal.spinlock);
@ -767,7 +767,7 @@ static struct spdk_bdev *
_bdev_next_leaf(struct spdk_bdev *bdev) _bdev_next_leaf(struct spdk_bdev *bdev)
{ {
while (bdev != NULL) { while (bdev != NULL) {
if (bdev->internal.claim_module == NULL) { if (bdev->internal.claim.v1.module == NULL) {
return bdev; return bdev;
} else { } else {
bdev = TAILQ_NEXT(bdev, internal.link); bdev = TAILQ_NEXT(bdev, internal.link);
@ -1823,9 +1823,9 @@ bdev_finish_unregister_bdevs_iter(void *cb_arg, int bdeverrno)
for (bdev = TAILQ_LAST(&g_bdev_mgr.bdevs, spdk_bdev_list); for (bdev = TAILQ_LAST(&g_bdev_mgr.bdevs, spdk_bdev_list);
bdev; bdev = TAILQ_PREV(bdev, spdk_bdev_list, internal.link)) { bdev; bdev = TAILQ_PREV(bdev, spdk_bdev_list, internal.link)) {
spdk_spin_lock(&bdev->internal.spinlock); spdk_spin_lock(&bdev->internal.spinlock);
if (bdev->internal.claim_module != NULL) { if (bdev->internal.claim.v1.module != NULL) {
SPDK_DEBUGLOG(bdev, "Skipping claimed bdev '%s'(<-'%s').\n", SPDK_DEBUGLOG(bdev, "Skipping claimed bdev '%s'(<-'%s').\n",
bdev->name, bdev->internal.claim_module->name); bdev->name, bdev->internal.claim.v1.module->name);
spdk_spin_unlock(&bdev->internal.spinlock); spdk_spin_unlock(&bdev->internal.spinlock);
continue; continue;
} }
@ -6724,7 +6724,7 @@ bdev_register(struct spdk_bdev *bdev)
bdev->internal.status = SPDK_BDEV_STATUS_READY; bdev->internal.status = SPDK_BDEV_STATUS_READY;
bdev->internal.measured_queue_depth = UINT64_MAX; bdev->internal.measured_queue_depth = UINT64_MAX;
bdev->internal.claim_module = NULL; bdev->internal.claim.v1.module = NULL;
bdev->internal.qd_poller = NULL; bdev->internal.qd_poller = NULL;
bdev->internal.qos = NULL; bdev->internal.qos = NULL;
@ -7056,9 +7056,9 @@ bdev_open(struct spdk_bdev *bdev, bool write, struct spdk_bdev_desc *desc)
return -ENODEV; return -ENODEV;
} }
if (write && bdev->internal.claim_module) { if (write && bdev->internal.claim.v1.module) {
SPDK_ERRLOG("Could not open %s - %s module already claimed it\n", SPDK_ERRLOG("Could not open %s - %s module already claimed it\n",
bdev->name, bdev->internal.claim_module->name); bdev->name, bdev->internal.claim.v1.module->name);
spdk_spin_unlock(&bdev->internal.spinlock); spdk_spin_unlock(&bdev->internal.spinlock);
return -EPERM; return -EPERM;
} }
@ -7285,9 +7285,9 @@ spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
{ {
spdk_spin_lock(&bdev->internal.spinlock); spdk_spin_lock(&bdev->internal.spinlock);
if (bdev->internal.claim_module != NULL) { if (bdev->internal.claim.v1.module != NULL) {
SPDK_ERRLOG("bdev %s already claimed by module %s\n", bdev->name, SPDK_ERRLOG("bdev %s already claimed by module %s\n", bdev->name,
bdev->internal.claim_module->name); bdev->internal.claim.v1.module->name);
spdk_spin_unlock(&bdev->internal.spinlock); spdk_spin_unlock(&bdev->internal.spinlock);
return -EPERM; return -EPERM;
} }
@ -7296,7 +7296,7 @@ spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
desc->write = true; desc->write = true;
} }
bdev->internal.claim_module = module; bdev->internal.claim.v1.module = module;
spdk_spin_unlock(&bdev->internal.spinlock); spdk_spin_unlock(&bdev->internal.spinlock);
return 0; return 0;
@ -7307,8 +7307,8 @@ spdk_bdev_module_release_bdev(struct spdk_bdev *bdev)
{ {
spdk_spin_lock(&bdev->internal.spinlock); spdk_spin_lock(&bdev->internal.spinlock);
assert(bdev->internal.claim_module != NULL); assert(bdev->internal.claim.v1.module != NULL);
bdev->internal.claim_module = NULL; bdev->internal.claim.v1.module = NULL;
spdk_spin_unlock(&bdev->internal.spinlock); spdk_spin_unlock(&bdev->internal.spinlock);
} }

View File

@ -710,7 +710,7 @@ rpc_dump_bdev_info(void *ctx, struct spdk_bdev *bdev)
} }
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
spdk_json_write_named_bool(w, "claimed", (bdev->internal.claim_module != NULL)); spdk_json_write_named_bool(w, "claimed", (bdev->internal.claim.v1.module != NULL));
spdk_json_write_named_bool(w, "zoned", bdev->zoned); spdk_json_write_named_bool(w, "zoned", bdev->zoned);
if (bdev->zoned) { if (bdev->zoned) {

View File

@ -837,7 +837,7 @@ claim_test(void)
rc = spdk_bdev_module_claim_bdev(bdev, NULL, &bdev_ut_if); rc = spdk_bdev_module_claim_bdev(bdev, NULL, &bdev_ut_if);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
CU_ASSERT(bdev->internal.claim_module == &bdev_ut_if); CU_ASSERT(bdev->internal.claim.v1.module == &bdev_ut_if);
/* There should be only one open descriptor and it should still be ro */ /* There should be only one open descriptor and it should still be ro */
count = 0; count = 0;
@ -852,7 +852,7 @@ claim_test(void)
spdk_bdev_module_release_bdev(bdev); spdk_bdev_module_release_bdev(bdev);
rc = spdk_bdev_module_claim_bdev(bdev, desc, &bdev_ut_if); rc = spdk_bdev_module_claim_bdev(bdev, desc, &bdev_ut_if);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
CU_ASSERT(bdev->internal.claim_module == &bdev_ut_if); CU_ASSERT(bdev->internal.claim.v1.module == &bdev_ut_if);
/* There should be only one open descriptor and it should be rw */ /* There should be only one open descriptor and it should be rw */
count = 0; count = 0;
@ -6241,7 +6241,7 @@ examine_locks(void)
bdev = allocate_bdev_ctx("bdev0", &ctx); bdev = allocate_bdev_ctx("bdev0", &ctx);
CU_ASSERT(ctx.examine_config_count == 1); CU_ASSERT(ctx.examine_config_count == 1);
CU_ASSERT(ctx.examine_disk_count == 1); CU_ASSERT(ctx.examine_disk_count == 1);
CU_ASSERT(bdev->internal.claim_module == NULL); CU_ASSERT(bdev->internal.claim.v1.module == NULL);
free_bdev(bdev); free_bdev(bdev);
/* Exercise the other path that is taken when examine_config() takes a claim. */ /* Exercise the other path that is taken when examine_config() takes a claim. */
@ -6251,8 +6251,9 @@ examine_locks(void)
bdev = allocate_bdev_ctx("bdev0", &ctx); bdev = allocate_bdev_ctx("bdev0", &ctx);
CU_ASSERT(ctx.examine_config_count == 1); CU_ASSERT(ctx.examine_config_count == 1);
CU_ASSERT(ctx.examine_disk_count == 1); CU_ASSERT(ctx.examine_disk_count == 1);
CU_ASSERT(bdev->internal.claim_module == &vbdev_ut_if); CU_ASSERT(bdev->internal.claim.v1.module == &vbdev_ut_if);
spdk_bdev_module_release_bdev(bdev); spdk_bdev_module_release_bdev(bdev);
CU_ASSERT(bdev->internal.claim.v1.module == NULL);
free_bdev(bdev); free_bdev(bdev);
} }

View File

@ -478,18 +478,18 @@ spdk_bdev_readv_blocks_ext(struct spdk_bdev_desc *desc, struct spdk_io_channel *
void void
spdk_bdev_module_release_bdev(struct spdk_bdev *bdev) spdk_bdev_module_release_bdev(struct spdk_bdev *bdev)
{ {
CU_ASSERT(bdev->internal.claim_module != NULL); CU_ASSERT(bdev->internal.claim.v1.module != NULL);
bdev->internal.claim_module = NULL; bdev->internal.claim.v1.module = NULL;
} }
int int
spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
struct spdk_bdev_module *module) struct spdk_bdev_module *module)
{ {
if (bdev->internal.claim_module != NULL) { if (bdev->internal.claim.v1.module != NULL) {
return -1; return -1;
} }
bdev->internal.claim_module = module; bdev->internal.claim.v1.module = module;
return 0; return 0;
} }

View File

@ -184,18 +184,18 @@ int
spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
struct spdk_bdev_module *module) struct spdk_bdev_module *module)
{ {
if (bdev->internal.claim_module != NULL) { if (bdev->internal.claim.v1.module != NULL) {
return -1; return -1;
} }
bdev->internal.claim_module = module; bdev->internal.claim.v1.module = module;
return 0; return 0;
} }
void void
spdk_bdev_module_release_bdev(struct spdk_bdev *bdev) spdk_bdev_module_release_bdev(struct spdk_bdev *bdev)
{ {
CU_ASSERT(bdev->internal.claim_module != NULL); CU_ASSERT(bdev->internal.claim.v1.module != NULL);
bdev->internal.claim_module = NULL; bdev->internal.claim.v1.module = NULL;
} }
void void