bdev/part: use internal buffers for part and product name.
This removes assumptions about hte lifecycle of these variables relative to the parent bdev and allows us to avoid ambiguity about who is responsible for freeing these buffers. Change-Id: Ia996653562d532fa1501faf21d3fdff85033ab33 Signed-off-by: Seth Howell <seth.howell@intel.com> Reviewed-on: https://review.gerrithub.io/424105 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
9f2035c7cc
commit
c8341f12bd
@ -289,6 +289,7 @@ _spdk_vbdev_error_create(struct spdk_bdev *base_bdev)
|
||||
|
||||
rc = spdk_bdev_part_construct(&disk->part, base, name, 0, base_bdev->blockcnt,
|
||||
"Error Injection Disk");
|
||||
free(name);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not construct part for bdev %s\n", spdk_bdev_get_name(base_bdev));
|
||||
/* spdk_bdev_part_construct will free name on failure */
|
||||
|
@ -273,6 +273,7 @@ vbdev_gpt_create_bdevs(struct gpt_base *gpt_base)
|
||||
|
||||
rc = spdk_bdev_part_construct(&d->part, gpt_base->part_base, name,
|
||||
lba_start, lba_end - lba_start, "GPT Disk");
|
||||
free(name);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not construct bdev part\n");
|
||||
/* spdk_bdev_part_construct will free name on failure */
|
||||
|
@ -114,6 +114,7 @@ spdk_bdev_part_free_cb(void *io_device)
|
||||
|
||||
spdk_bdev_destruct_done(&part->internal.bdev, 0);
|
||||
free(part->internal.bdev.name);
|
||||
free(part->internal.bdev.product_name);
|
||||
free(part);
|
||||
}
|
||||
|
||||
@ -321,18 +322,29 @@ spdk_bdev_part_construct(struct spdk_bdev_part *part, struct spdk_bdev_part_base
|
||||
char *name, uint64_t offset_blocks, uint64_t num_blocks,
|
||||
char *product_name)
|
||||
{
|
||||
part->internal.bdev.name = name;
|
||||
part->internal.bdev.blocklen = base->bdev->blocklen;
|
||||
part->internal.bdev.blockcnt = num_blocks;
|
||||
part->internal.offset_blocks = offset_blocks;
|
||||
|
||||
part->internal.bdev.write_cache = base->bdev->write_cache;
|
||||
part->internal.bdev.need_aligned_buffer = base->bdev->need_aligned_buffer;
|
||||
part->internal.bdev.product_name = product_name;
|
||||
part->internal.bdev.ctxt = part;
|
||||
part->internal.bdev.module = base->module;
|
||||
part->internal.bdev.fn_table = base->fn_table;
|
||||
|
||||
part->internal.bdev.name = strdup(name);
|
||||
part->internal.bdev.product_name = strdup(product_name);
|
||||
|
||||
if (part->internal.bdev.name == NULL) {
|
||||
SPDK_ERRLOG("Failed to allocate name for new part of bdev %s\n", spdk_bdev_get_name(base->bdev));
|
||||
return -1;
|
||||
} else if (part->internal.bdev.product_name == NULL) {
|
||||
free(part->internal.bdev.name);
|
||||
SPDK_ERRLOG("Failed to allocate product name for new part of bdev %s\n",
|
||||
spdk_bdev_get_name(base->bdev));
|
||||
return -1;
|
||||
}
|
||||
|
||||
__sync_fetch_and_add(&base->ref, 1);
|
||||
part->internal.base = base;
|
||||
|
||||
@ -343,6 +355,7 @@ spdk_bdev_part_construct(struct spdk_bdev_part *part, struct spdk_bdev_part_base
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not claim bdev %s\n", spdk_bdev_get_name(base->bdev));
|
||||
free(part->internal.bdev.name);
|
||||
free(part->internal.bdev.product_name);
|
||||
return -1;
|
||||
}
|
||||
base->claimed = true;
|
||||
|
@ -228,6 +228,7 @@ vbdev_split_create(struct spdk_vbdev_split_config *cfg)
|
||||
|
||||
rc = spdk_bdev_part_construct(d, cfg->split_base, name, offset_blocks, split_size_blocks,
|
||||
"Split Disk");
|
||||
free(name);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not construct bdev part\n");
|
||||
/* spdk_bdev_part_construct will free name if it fails */
|
||||
|
@ -54,6 +54,13 @@ _part_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx)
|
||||
fn(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
_part_cleanup(struct spdk_bdev_part *part)
|
||||
{
|
||||
free(part->internal.bdev.name);
|
||||
free(part->internal.bdev.product_name);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io,
|
||||
int *sc, int *sk, int *asc, int *ascq)
|
||||
@ -120,6 +127,8 @@ part_test(void)
|
||||
spdk_bdev_part_base_hotremove(&bdev_base, &tailq);
|
||||
|
||||
spdk_bdev_part_base_free(base);
|
||||
_part_cleanup(&part1);
|
||||
_part_cleanup(&part2);
|
||||
spdk_bdev_unregister(&bdev_base, NULL, NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user