From 411181040378351bb0c83663b11ac5d4b1fcab4e Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Tue, 19 Apr 2022 11:21:05 +0200 Subject: [PATCH] librbd/cache/pwl: WriteLogCacheEntry constructor must initialize flags Initializing the individual bit field members leaves the remaining two bits uninitialized and that garbage state gets persisted. In general, using bit fields in a structure where the layout actually matters is not desirable. Even with a few single bits, such as here, their order, strictly speaking, is not guaranteed: An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined. The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined. The alignment of the addressable storage unit is unspecified. Signed-off-by: Ilya Dryomov (cherry picked from commit 91d270b210a908ea2f3578dd7db3263383da95a8) --- src/librbd/cache/pwl/Types.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librbd/cache/pwl/Types.h b/src/librbd/cache/pwl/Types.h index 06d5b52bdb0c7..15a2fe80b67c4 100644 --- a/src/librbd/cache/pwl/Types.h +++ b/src/librbd/cache/pwl/Types.h @@ -221,7 +221,7 @@ struct WriteLogCacheEntry { uint64_t write_data_pos = 0; /* SSD data offset */ #endif union { - uint8_t flags; + uint8_t flags = 0; struct { uint8_t entry_valid :1; /* if 0, this entry is free */ uint8_t sync_point :1; /* No data. No write sequence number. Marks sync @@ -236,9 +236,7 @@ struct WriteLogCacheEntry { uint32_t entry_index = 0; /* For debug consistency check. Can be removed if * we need the space */ WriteLogCacheEntry(uint64_t image_offset_bytes=0, uint64_t write_bytes=0) - : image_offset_bytes(image_offset_bytes), write_bytes(write_bytes), - entry_valid(0), sync_point(0), sequenced(0), has_data(0), discard(0), writesame(0) { - } + : image_offset_bytes(image_offset_bytes), write_bytes(write_bytes) {} BlockExtent block_extent(); uint64_t get_offset_bytes(); uint64_t get_write_bytes(); -- 2.39.5