Spdk/test/unit/lib/ftl/common/utils.c
Jim Harris 488570ebd4 Replace most BSD 3-clause license text with SPDX identifier.
Many open source projects have moved to using SPDX identifiers
to specify license information, reducing the amount of
boilerplate code in every source file.  This patch replaces
the bulk of SPDK .c, .cpp and Makefiles with the BSD-3-Clause
identifier.

Almost all of these files share the exact same license text,
and this patch only modifies the files that contain the
most common license text.  There can be slight variations
because the third clause contains company names - most say
"Intel Corporation", but there are instances for Nvidia,
Samsung, Eideticom and even "the copyright holder".

Used a bash script to automate replacement of the license text
with SPDX identifier which is checked into scripts/spdx.sh.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iaa88ab5e92ea471691dc298cfe41ebfb5d169780
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12904
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: <qun.wan@intel.com>
2022-06-09 07:35:12 +00:00

145 lines
3.8 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk/ftl.h"
#include "ftl/ftl_core.h"
#include "thread/thread_internal.h"
struct base_bdev_geometry {
size_t write_unit_size;
size_t zone_size;
size_t optimal_open_zones;
size_t blockcnt;
};
extern struct base_bdev_geometry g_geo;
struct spdk_ftl_dev *test_init_ftl_dev(const struct base_bdev_geometry *geo);
struct ftl_band *test_init_ftl_band(struct spdk_ftl_dev *dev, size_t id, size_t zone_size);
void test_free_ftl_dev(struct spdk_ftl_dev *dev);
void test_free_ftl_band(struct ftl_band *band);
uint64_t test_offset_from_addr(struct ftl_addr addr, struct ftl_band *band);
DEFINE_STUB(spdk_bdev_desc_get_bdev, struct spdk_bdev *, (struct spdk_bdev_desc *desc), NULL);
uint64_t
spdk_bdev_get_zone_size(const struct spdk_bdev *bdev)
{
return g_geo.zone_size;
}
uint32_t
spdk_bdev_get_optimal_open_zones(const struct spdk_bdev *bdev)
{
return g_geo.optimal_open_zones;
}
struct spdk_ftl_dev *
test_init_ftl_dev(const struct base_bdev_geometry *geo)
{
struct spdk_ftl_dev *dev;
dev = calloc(1, sizeof(*dev));
SPDK_CU_ASSERT_FATAL(dev != NULL);
dev->xfer_size = geo->write_unit_size;
dev->core_thread = spdk_thread_create("unit_test_thread", NULL);
spdk_set_thread(dev->core_thread);
dev->ioch = calloc(1, sizeof(*dev->ioch)
+ sizeof(struct ftl_io_channel *));
dev->num_bands = geo->blockcnt / (geo->zone_size * geo->optimal_open_zones);
dev->bands = calloc(dev->num_bands, sizeof(*dev->bands));
SPDK_CU_ASSERT_FATAL(dev->bands != NULL);
dev->lba_pool = spdk_mempool_create("ftl_ut", 2, 0x18000,
SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
SPDK_ENV_SOCKET_ID_ANY);
SPDK_CU_ASSERT_FATAL(dev->lba_pool != NULL);
LIST_INIT(&dev->free_bands);
LIST_INIT(&dev->shut_bands);
return dev;
}
struct ftl_band *
test_init_ftl_band(struct spdk_ftl_dev *dev, size_t id, size_t zone_size)
{
struct ftl_band *band;
struct ftl_zone *zone;
SPDK_CU_ASSERT_FATAL(dev != NULL);
SPDK_CU_ASSERT_FATAL(id < dev->num_bands);
band = &dev->bands[id];
band->dev = dev;
band->id = id;
band->state = FTL_BAND_STATE_CLOSED;
LIST_INSERT_HEAD(&dev->shut_bands, band, list_entry);
CIRCLEQ_INIT(&band->zones);
band->lba_map.vld = spdk_bit_array_create(ftl_get_num_blocks_in_band(dev));
SPDK_CU_ASSERT_FATAL(band->lba_map.vld != NULL);
band->zone_buf = calloc(ftl_get_num_punits(dev), sizeof(*band->zone_buf));
SPDK_CU_ASSERT_FATAL(band->zone_buf != NULL);
band->reloc_bitmap = spdk_bit_array_create(ftl_get_num_bands(dev));
SPDK_CU_ASSERT_FATAL(band->reloc_bitmap != NULL);
for (size_t i = 0; i < ftl_get_num_punits(dev); ++i) {
zone = &band->zone_buf[i];
zone->info.state = SPDK_BDEV_ZONE_STATE_FULL;
zone->info.zone_id = zone_size * (id * ftl_get_num_punits(dev) + i);
CIRCLEQ_INSERT_TAIL(&band->zones, zone, circleq);
band->num_zones++;
}
pthread_spin_init(&band->lba_map.lock, PTHREAD_PROCESS_PRIVATE);
return band;
}
void
test_free_ftl_dev(struct spdk_ftl_dev *dev)
{
struct spdk_thread *thread;
SPDK_CU_ASSERT_FATAL(dev != NULL);
free(dev->ioch);
thread = dev->core_thread;
spdk_set_thread(thread);
spdk_thread_exit(thread);
while (!spdk_thread_is_exited(thread)) {
spdk_thread_poll(thread, 0, 0);
}
spdk_thread_destroy(thread);
spdk_mempool_free(dev->lba_pool);
free(dev->bands);
free(dev);
}
void
test_free_ftl_band(struct ftl_band *band)
{
SPDK_CU_ASSERT_FATAL(band != NULL);
spdk_bit_array_free(&band->lba_map.vld);
spdk_bit_array_free(&band->reloc_bitmap);
free(band->zone_buf);
spdk_dma_free(band->lba_map.dma_buf);
}
uint64_t
test_offset_from_addr(struct ftl_addr addr, struct ftl_band *band)
{
struct spdk_ftl_dev *dev = band->dev;
CU_ASSERT_EQUAL(ftl_addr_get_band(dev, addr), band->id);
return addr.offset - band->id * ftl_get_num_blocks_in_band(dev);
}