From 4759b0b6a66c9be4cccd9330750ea74888968a93 Mon Sep 17 00:00:00 2001 From: Kozlowski Mateusz Date: Sat, 9 Jul 2022 01:14:11 +0200 Subject: [PATCH] ftl: Add explicit values to the ftl_layout_region_type This should prevent accidental reordering/removal of regions from causing problems after loading against such changed metadata. Signed-off-by: Kozlowski Mateusz Change-Id: I75c62810157db4bb0de4dfc84f5656fd187befde Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13614 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/ftl/ftl_layout.h | 49 ++++++++++++++-------------- lib/ftl/mngt/ftl_mngt_md.c | 2 +- lib/ftl/upgrade/ftl_layout_upgrade.c | 6 ++-- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/ftl/ftl_layout.h b/lib/ftl/ftl_layout.h index 73614b1e1..518440572 100644 --- a/lib/ftl/ftl_layout.h +++ b/lib/ftl/ftl_layout.h @@ -15,54 +15,53 @@ struct ftl_md; (FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MAX - FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MIN + 1) enum ftl_layout_region_type { -#ifdef SPDK_FTL_VSS_EMU - /** VSS region for NV cache VSS emulation */ - FTL_LAYOUT_REGION_TYPE_VSS, -#endif /* Superblock describing the basic FTL information */ - FTL_LAYOUT_REGION_TYPE_SB, + FTL_LAYOUT_REGION_TYPE_SB = 0, /* Mirrored instance of the superblock on the base device */ - FTL_LAYOUT_REGION_TYPE_SB_BASE, + FTL_LAYOUT_REGION_TYPE_SB_BASE = 1, /* If using cached L2P, this region stores the serialized instance of it */ - FTL_LAYOUT_REGION_TYPE_L2P, + FTL_LAYOUT_REGION_TYPE_L2P = 2, /* State of bands */ - FTL_LAYOUT_REGION_TYPE_BAND_MD, + FTL_LAYOUT_REGION_TYPE_BAND_MD = 3, /* Mirrored instance of bands state */ - FTL_LAYOUT_REGION_TYPE_BAND_MD_MIRROR, + FTL_LAYOUT_REGION_TYPE_BAND_MD_MIRROR = 4, /* Map of valid physical addresses, used for more efficient garbage collection */ - FTL_LAYOUT_REGION_TYPE_VALID_MAP, + FTL_LAYOUT_REGION_TYPE_VALID_MAP = 5, /* State of chunks */ - FTL_LAYOUT_REGION_TYPE_NVC_MD, + FTL_LAYOUT_REGION_TYPE_NVC_MD = 6, /* Mirrored instance of the state of chunks */ - FTL_LAYOUT_REGION_TYPE_NVC_MD_MIRROR, + FTL_LAYOUT_REGION_TYPE_NVC_MD_MIRROR = 7, /* User data region on the nv cache device */ - FTL_LAYOUT_REGION_TYPE_DATA_NVC, + FTL_LAYOUT_REGION_TYPE_DATA_NVC = 8, /* User data region on the base device */ - FTL_LAYOUT_REGION_TYPE_DATA_BASE, + FTL_LAYOUT_REGION_TYPE_DATA_BASE = 9, /* P2L checkpointing allows for emulation of VSS on base device. - * 4 entries are needed - 2 for each writer - * Although the naming may suggest a particular region is assigned to its corresponding writer, it's not - * the case - they can be used interchangeably - */ - FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC, + * 4 entries are needed - 2 for each writer */ + FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC = 10, FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MIN = FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC, - FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC_NEXT, - FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP, - FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP_NEXT, + FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC_NEXT = 11, + FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP = 12, + FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP_NEXT = 13, FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MAX = FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP_NEXT, /* Information about trimmed space in FTL */ - FTL_LAYOUT_REGION_TYPE_TRIM_MD, + FTL_LAYOUT_REGION_TYPE_TRIM_MD = 14, /* Mirrored information about trim */ - FTL_LAYOUT_REGION_TYPE_TRIM_MD_MIRROR, + FTL_LAYOUT_REGION_TYPE_TRIM_MD_MIRROR = 15, - FTL_LAYOUT_REGION_TYPE_MAX, +#ifndef SPDK_FTL_VSS_EMU + FTL_LAYOUT_REGION_TYPE_MAX = 16 +#else + /* VSS region for NV cache VSS emulation */ + FTL_LAYOUT_REGION_TYPE_VSS = 16, + FTL_LAYOUT_REGION_TYPE_MAX = 17, +#endif }; /* last nvc/base region in terms of lba address space */ diff --git a/lib/ftl/mngt/ftl_mngt_md.c b/lib/ftl/mngt/ftl_mngt_md.c index dd8211b4a..ad06716f3 100644 --- a/lib/ftl/mngt/ftl_mngt_md.c +++ b/lib/ftl/mngt/ftl_mngt_md.c @@ -534,7 +534,7 @@ ftl_mngt_md_init_vss_emu(struct spdk_ftl_dev *dev, struct ftl_mngt_process *mngt /* Allocate md buf */ layout->md[FTL_LAYOUT_REGION_TYPE_VSS] = ftl_md_create(dev, region->current.blocks, - region->vss_blksz, NULL, 0, region); + region->vss_blksz, NULL, FTL_MD_CREATE_HEAP, region); if (NULL == layout->md[FTL_LAYOUT_REGION_TYPE_VSS]) { ftl_mngt_fail_step(mngt); return; diff --git a/lib/ftl/upgrade/ftl_layout_upgrade.c b/lib/ftl/upgrade/ftl_layout_upgrade.c index 67f862a44..5c3465d58 100644 --- a/lib/ftl/upgrade/ftl_layout_upgrade.c +++ b/lib/ftl/upgrade/ftl_layout_upgrade.c @@ -33,9 +33,6 @@ extern struct ftl_region_upgrade_desc nvc_upgrade_desc[]; extern struct ftl_region_upgrade_desc band_upgrade_desc[]; static struct ftl_layout_upgrade_desc_list layout_upgrade_desc[] = { -#ifdef SPDK_FTL_VSS_EMU - [FTL_LAYOUT_REGION_TYPE_VSS] = {}, -#endif [FTL_LAYOUT_REGION_TYPE_SB] = { .count = FTL_SB_VERSION_CURRENT, .desc = sb_upgrade_desc, @@ -82,6 +79,9 @@ static struct ftl_layout_upgrade_desc_list layout_upgrade_desc[] = { }, [FTL_LAYOUT_REGION_TYPE_TRIM_MD] = {}, [FTL_LAYOUT_REGION_TYPE_TRIM_MD_MIRROR] = {}, +#ifdef SPDK_FTL_VSS_EMU + [FTL_LAYOUT_REGION_TYPE_VSS] = {}, +#endif }; SPDK_STATIC_ASSERT(sizeof(layout_upgrade_desc) / sizeof(*layout_upgrade_desc) ==