From: Ilya Dryomov Date: Tue, 19 Apr 2022 09:21:05 +0000 (+0200) Subject: librbd/cache/pwl: WriteLogCacheEntry constructor must initialize flags X-Git-Tag: v18.0.0~1033^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=91d270b210a908ea2f3578dd7db3263383da95a8;p=ceph.git 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 --- diff --git a/src/librbd/cache/pwl/Types.h b/src/librbd/cache/pwl/Types.h index f7cd6cfac46e7..62ce9ea1e6e00 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();