From 920c1cca18eebe6c27a7921eb183564bb16a00cb Mon Sep 17 00:00:00 2001 From: Kozlowski Mateusz Date: Thu, 1 Sep 2022 14:15:47 +0200 Subject: [PATCH] ftl: Change metadata to use structure packing Don't rely on compiler for metadata packing to 4KiB size and add reserved fields manually. For compatibility reasons against metadata relying on automatic padding the reserved fields are also added in-between existing fields as needed. Signed-off-by: Kozlowski Mateusz Change-Id: I5e342d5bf5948c213d455590d09597ae120b3c62 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14307 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/ftl/ftl_band.h | 8 +++++++- lib/ftl/ftl_nv_cache.h | 5 ++++- lib/ftl/ftl_sb_common.h | 12 +++++++++--- lib/ftl/ftl_sb_current.h | 10 +++------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/ftl/ftl_band.h b/lib/ftl/ftl_band.h index cba5e709a..82dabe3d1 100644 --- a/lib/ftl/ftl_band.h +++ b/lib/ftl/ftl_band.h @@ -64,6 +64,9 @@ struct ftl_band_md { /* nv_cache p2l md region associated with band */ enum ftl_layout_region_type p2l_md_region; + /* Reserved */ + uint8_t reserved[4]; + /* Sequence ID when band was opened */ uint64_t seq; @@ -78,7 +81,10 @@ struct ftl_band_md { /* CRC32 checksum of the associated P2L map when band is in closed state */ uint32_t p2l_map_checksum; -} __attribute__((aligned(FTL_BLOCK_SIZE))); + + /* Reserved */ + uint8_t reserved2[4028]; +} __attribute__((packed)); SPDK_STATIC_ASSERT(sizeof(struct ftl_band_md) == FTL_BLOCK_SIZE, "Incorrect metadata size"); diff --git a/lib/ftl/ftl_nv_cache.h b/lib/ftl/ftl_nv_cache.h index c32fc413d..d68493985 100644 --- a/lib/ftl/ftl_nv_cache.h +++ b/lib/ftl/ftl_nv_cache.h @@ -83,7 +83,10 @@ struct ftl_nv_cache_chunk_md { /* CRC32 checksum of the associated P2L map when chunk is in closed state */ uint32_t p2l_map_checksum; -} __attribute__((aligned(FTL_BLOCK_SIZE))); + + /* Reserved */ + uint8_t reserved[4052]; +} __attribute__((packed)); #define FTL_NV_CACHE_CHUNK_MD_SIZE sizeof(struct ftl_nv_cache_chunk_md) SPDK_STATIC_ASSERT(FTL_NV_CACHE_CHUNK_MD_SIZE == FTL_BLOCK_SIZE, diff --git a/lib/ftl/ftl_sb_common.h b/lib/ftl/ftl_sb_common.h index c667e288b..d0b26bed4 100644 --- a/lib/ftl/ftl_sb_common.h +++ b/lib/ftl/ftl_sb_common.h @@ -33,13 +33,17 @@ struct ftl_superblock_gc_info { uint64_t band_phys_id; /* May be updating multiple fields at the same time, clearing/setting this marks the transaction */ uint64_t is_valid; -}; +} __attribute__((packed)); +SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_gc_info) == 32, + "ftl_superblock_gc_info incorrect size"); struct ftl_superblock_header { uint64_t magic; uint64_t crc; uint64_t version; -}; +} __attribute__((packed)); +SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_header) == 24, + "ftl_superblock_header incorrect size"); struct ftl_superblock_md_region { uint32_t type; @@ -47,7 +51,9 @@ struct ftl_superblock_md_region { uint64_t blk_offs; uint64_t blk_sz; ftl_df_obj_id df_next; -}; +} __attribute__((packed)); +SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_md_region) == 32, + "ftl_superblock_md_region incorrect size"); struct ftl_superblock_shm { /* SHM initialization completed */ diff --git a/lib/ftl/ftl_sb_current.h b/lib/ftl/ftl_sb_current.h index b4ab2f656..4a8f233eb 100644 --- a/lib/ftl/ftl_sb_current.h +++ b/lib/ftl/ftl_sb_current.h @@ -32,12 +32,8 @@ struct ftl_superblock { /* Maximum IO depth per band relocate */ uint64_t max_reloc_qdepth; - /* Reserved fields */ - uint64_t reserved; - - bool reserved3; - - uint32_t reserved2; + /* Reserved field */ + uint8_t reserved3[16]; /* Last L2P checkpoint +1 (i.e. min_seq_id, 0:no ckpt) */ uint64_t ckpt_seq_id; @@ -45,7 +41,7 @@ struct ftl_superblock { struct ftl_superblock_gc_info gc_info; struct ftl_superblock_md_region md_layout_head; -}; +} __attribute__((packed)); SPDK_STATIC_ASSERT(offsetof(struct ftl_superblock, header) == 0, "Invalid placement of header");