]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/cache/pwl: WriteLogCacheEntry constructor must initialize flags
authorIlya Dryomov <idryomov@gmail.com>
Tue, 19 Apr 2022 09:21:05 +0000 (11:21 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 19 Apr 2022 09:21:05 +0000 (11:21 +0200)
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 <idryomov@gmail.com>
src/librbd/cache/pwl/Types.h

index f7cd6cfac46e707a655f724e3a882017f3d4cbd6..62ce9ea1e6e0058a1de9ce2988adabd590434655 100644 (file)
@@ -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();