dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0047-super-intel-don-t-mark-structs-packed-unnecessarily.patch

5d5466
From 761e3bd9f5e3aafa95ad3ae50a637dc67c8774f0 Mon Sep 17 00:00:00 2001
5d5466
From: NeilBrown <neilb@suse.de>
5d5466
Date: Thu, 31 Oct 2019 15:15:38 +1100
5d5466
Subject: [RHEL7.8 PATCH V2 47/47] super-intel: don't mark structs 'packed'
5d5466
 unnecessarily
5d5466
5d5466
super-intel marks a number of structures 'packed', but this
5d5466
doesn't change the layout - they are already well organized.
5d5466
5d5466
This is a problem a gcc warns when code takes the address
5d5466
of a field in a packet struct - as super-intel sometimes does.
5d5466
5d5466
So remove the marking where isn't needed.
5d5466
Do ensure this does introduce a regression, add a compile-time
5d5466
assertion that the size of the structure is exactly the value
5d5466
it had before the 'packed' notation was removed.
5d5466
5d5466
Note that a couple of structure do need to be packed.
5d5466
As the address of fields is never taken, that is safe.
5d5466
5d5466
Signed-off-by: NeilBrown <neilb@suse.de>
5d5466
Acked-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
5d5466
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5d5466
---
5d5466
 super-intel.c | 32 ++++++++++++++++++++++++++------
5d5466
 1 file changed, 26 insertions(+), 6 deletions(-)
5d5466
5d5466
diff --git a/super-intel.c b/super-intel.c
5d5466
index 713058c..a7fbed4 100644
5d5466
--- a/super-intel.c
5d5466
+++ b/super-intel.c
5d5466
@@ -96,6 +96,19 @@
5d5466
 						   * mutliple PPL area
5d5466
 						   */
5d5466
 
5d5466
+/*
5d5466
+ * This macro let's us ensure that no-one accidentally
5d5466
+ * changes the size of a struct
5d5466
+ */
5d5466
+#define ASSERT_SIZE(_struct, size) \
5d5466
+static inline void __assert_size_##_struct(void)	\
5d5466
+{							\
5d5466
+	switch (0) {					\
5d5466
+	case 0: break;					\
5d5466
+	case (sizeof(struct _struct) == size): break;	\
5d5466
+	}						\
5d5466
+}
5d5466
+
5d5466
 /* Disk configuration info. */
5d5466
 #define IMSM_MAX_DEVICES 255
5d5466
 struct imsm_disk {
5d5466
@@ -112,6 +125,7 @@ struct imsm_disk {
5d5466
 #define	IMSM_DISK_FILLERS	3
5d5466
 	__u32 filler[IMSM_DISK_FILLERS]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
5d5466
 };
5d5466
+ASSERT_SIZE(imsm_disk, 48)
5d5466
 
5d5466
 /* map selector for map managment
5d5466
  */
5d5466
@@ -146,7 +160,8 @@ struct imsm_map {
5d5466
 	__u32 disk_ord_tbl[1];	/* disk_ord_tbl[num_members],
5d5466
 				 * top byte contains some flags
5d5466
 				 */
5d5466
-} __attribute__ ((packed));
5d5466
+};
5d5466
+ASSERT_SIZE(imsm_map, 52)
5d5466
 
5d5466
 struct imsm_vol {
5d5466
 	__u32 curr_migr_unit;
5d5466
@@ -169,7 +184,8 @@ struct imsm_vol {
5d5466
 	__u32 filler[4];
5d5466
 	struct imsm_map map[1];
5d5466
 	/* here comes another one if migr_state */
5d5466
-} __attribute__ ((packed));
5d5466
+};
5d5466
+ASSERT_SIZE(imsm_vol, 84)
5d5466
 
5d5466
 struct imsm_dev {
5d5466
 	__u8  volume[MAX_RAID_SERIAL_LEN];
5d5466
@@ -220,7 +236,8 @@ struct imsm_dev {
5d5466
 #define IMSM_DEV_FILLERS 3
5d5466
 	__u32 filler[IMSM_DEV_FILLERS];
5d5466
 	struct imsm_vol vol;
5d5466
-} __attribute__ ((packed));
5d5466
+};
5d5466
+ASSERT_SIZE(imsm_dev, 164)
5d5466
 
5d5466
 struct imsm_super {
5d5466
 	__u8 sig[MAX_SIGNATURE_LENGTH];	/* 0x00 - 0x1F */
5d5466
@@ -248,7 +265,8 @@ struct imsm_super {
5d5466
 	struct imsm_disk disk[1];	/* 0xD8 diskTbl[numDisks] */
5d5466
 	/* here comes imsm_dev[num_raid_devs] */
5d5466
 	/* here comes BBM logs */
5d5466
-} __attribute__ ((packed));
5d5466
+};
5d5466
+ASSERT_SIZE(imsm_super, 264)
5d5466
 
5d5466
 #define BBM_LOG_MAX_ENTRIES 254
5d5466
 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256		/* Represents 256 LBAs */
5d5466
@@ -269,7 +287,8 @@ struct bbm_log {
5d5466
 	__u32 signature; /* 0xABADB10C */
5d5466
 	__u32 entry_count;
5d5466
 	struct bbm_log_entry marked_block_entries[BBM_LOG_MAX_ENTRIES];
5d5466
-} __attribute__ ((__packed__));
5d5466
+};
5d5466
+ASSERT_SIZE(bbm_log, 2040)
5d5466
 
5d5466
 static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" };
5d5466
 
5d5466
@@ -323,7 +342,8 @@ struct migr_record {
5d5466
 				       * destination - high order 32 bits */
5d5466
 	__u32 num_migr_units_hi;      /* Total num migration units-of-op
5d5466
 				       * high order 32 bits */
5d5466
-} __attribute__ ((__packed__));
5d5466
+};
5d5466
+ASSERT_SIZE(migr_record, 64)
5d5466
 
5d5466
 struct md_list {
5d5466
 	/* usage marker:
5d5466
-- 
5d5466
2.7.5
5d5466