]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: use kernel raid headers
authorMariusz Tkaczyk <mtkaczyk@kernel.org>
Mon, 10 Mar 2025 10:16:28 +0000 (11:16 +0100)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Mon, 28 Apr 2025 07:55:30 +0000 (09:55 +0200)
For a years we redefined these headers in mdadm. We should reuse headers
exported by kernel to integrate driver and mdadm better.
Include them and remove mdadm owned headers.

There are 3 defines not available in kernel headers, so define them
directly but put them in ifndef guard to make them transparent later.

Use MD_FEATURE_CLUSTERED instead of MD_FEATURE_BITMAP_VERSIONED. The
value is same, kernel define has different name.

Signed-off-by: Mariusz Tkaczyk <mtkaczyk@kernel.org>
Create.c
Detail.c
Examine.c
Grow.c
Kill.c
Manage.c
Query.c
mdadm.h
mdmonitor.c
super1.c
udev.c

index 2b181dbf820ea9adf414906d8b2eb0e4f9f364b8..de90b0b8e7813f0eeeed9ecdb8c219a2dea58c3d 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -23,8 +23,6 @@
  */
 
 #include       "mdadm.h"
-#include       "md_u.h"
-#include       "md_p.h"
 #include       "udev.h"
 #include       "xmalloc.h"
 
index b804a624574cffa08a9325d9bf8ba146f109b044..3802ef8fa6fcb6650179f87fd11f7aa7d2f37510 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -23,8 +23,6 @@
  */
 
 #include       "mdadm.h"
-#include       "md_p.h"
-#include       "md_u.h"
 #include       "xmalloc.h"
 
 #include       <ctype.h>
index 036b7a5634ad3d0f00c6adeacc98812f390d74b7..9c8564be90d4a1a64f56c43882056e6e21a4ad5b 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -24,8 +24,6 @@
 
 #include       "dlink.h"
 #include       "mdadm.h"
-#include       "md_u.h"
-#include       "md_p.h"
 #include       "xmalloc.h"
 
 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
diff --git a/Grow.c b/Grow.c
index 53b0b3876b26c292650a4ff8a97e24a83720f387..30eaa3c6a65475ad793f576e68c195872086f630 100644 (file)
--- a/Grow.c
+++ b/Grow.c
 #include       <stdint.h>
 #include       <sys/wait.h>
 
-#if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
-#error no endian defined
-#endif
-#include       "md_u.h"
-#include       "md_p.h"
-
 int restore_backup(struct supertype *st,
                   struct mdinfo *content,
                   int working_disks,
diff --git a/Kill.c b/Kill.c
index 43c9abed3b42b512448ca49cba943ba4ebe5603c..9f05a1ace8e16551c193e0dde54d6664571ece75 100644 (file)
--- a/Kill.c
+++ b/Kill.c
@@ -26,8 +26,6 @@
  */
 
 #include       "mdadm.h"
-#include       "md_u.h"
-#include       "md_p.h"
 
 int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl)
 {
index 034eb00c7f7d33db8609be1bc0f0b461346b476d..22b1f52b7dc7ee49db97d73453c362830091c6b1 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -23,8 +23,6 @@
  */
 
 #include "mdadm.h"
-#include "md_u.h"
-#include "md_p.h"
 #include "udev.h"
 #include "xmalloc.h"
 
diff --git a/Query.c b/Query.c
index aedb4ce77d8399db8428f5e84dc4f73b9547cdc9..72f49a4e6e54fa6ade9c9b0996c51810629d05da 100644 (file)
--- a/Query.c
+++ b/Query.c
@@ -23,8 +23,6 @@
  */
 
 #include       "mdadm.h"
-#include       "md_p.h"
-#include       "md_u.h"
 
 int Query(char *dev)
 {
diff --git a/mdadm.h b/mdadm.h
index 7471cedc3ebe6e63312c677a8d0d19013cfa0a79..ce9c216bf74ddaf1d11a2205d20400eeea01f3b5 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -163,8 +163,20 @@ struct dlm_lksb {
 #define GROW_SERVICE "mdadm-grow-continue"
 #endif /* GROW_SERVICE */
 
-#include       "md_u.h"
-#include       "md_p.h"
+#include       <linux/raid/md_u.h>
+#include       <linux/raid/md_p.h>
+
+/* These defines might be missing in raid headers*/
+#ifndef MD_SB_BLOCK_CONTAINER_RESHAPE
+#define MD_SB_BLOCK_CONTAINER_RESHAPE  3
+#endif
+#ifndef MD_SB_BLOCK_VOLUME
+#define MD_SB_BLOCK_VOLUME             4
+#endif
+#ifndef MD_DISK_REPLACEMENT
+#define MD_DISK_REPLACEMENT            17
+#endif
+
 #include       "bitmap.h"
 #include       "msg.h"
 #include       "mdadm_status.h"
index d1cfbf947191e073ed6643daaabfdffcb249e49f..d51617cd0981ec4a98e19d28bc25e40205d05c72 100644 (file)
@@ -23,8 +23,6 @@
  */
 
 #include       "mdadm.h"
-#include       "md_p.h"
-#include       "md_u.h"
 #include       "udev.h"
 #include       "xmalloc.h"
 
index fb93f462cc953f7878a4874e1372eb125aa62a2a..84d735738401c067e5d2913cb613ae69ba1199bf 100644 (file)
--- a/super1.c
+++ b/super1.c
 #include "mdadm.h"
 #include "xmalloc.h"
 
-/*
- * The version-1 superblock :
- * All numeric fields are little-endian.
- *
- * total size: 256 bytes plus 2 per device.
- *  1K allows 384 devices.
- */
-struct mdp_superblock_1 {
-       /* constant array information - 128 bytes */
-       __u32   magic;          /* MD_SB_MAGIC: 0xa92b4efc - little endian */
-       __u32   major_version;  /* 1 */
-       __u32   feature_map;    /* 0 for now */
-       __u32   pad0;           /* always set to 0 when writing */
-
-       __u8    set_uuid[16];   /* user-space generated. */
-       char    set_name[32];   /* set and interpreted by user-space */
-
-       __u64   ctime;          /* lo 40 bits are seconds, top 24 are microseconds or 0*/
-       __u32   level;          /* -4 (multipath), -1 (linear), 0,1,4,5 */
-       __u32   layout;         /* used for raid5, raid6, raid10, and raid0 */
-       __u64   size;           /* used size of component devices, in 512byte sectors */
-
-       __u32   chunksize;      /* in 512byte sectors */
-       __u32   raid_disks;
-       union {
-               __u32   bitmap_offset;  /* sectors after start of superblock that bitmap starts
-                                        * NOTE: signed, so bitmap can be before superblock
-                                        * only meaningful of feature_map[0] is set.
-                                        */
-
-               /* only meaningful when feature_map[MD_FEATURE_PPL] is set */
-               struct {
-                       __s16 offset; /* sectors from start of superblock that ppl starts */
-                       __u16 size; /* ppl size in sectors */
-               } ppl;
-       };
-
-       /* These are only valid with feature bit '4' */
-       __u32   new_level;      /* new level we are reshaping to                */
-       __u64   reshape_position;       /* next address in array-space for reshape */
-       __u32   delta_disks;    /* change in number of raid_disks               */
-       __u32   new_layout;     /* new layout                                   */
-       __u32   new_chunk;      /* new chunk size (sectors)                     */
-       __u32   new_offset;     /* signed number to add to data_offset in new
-                                * layout.  0 == no-change.  This can be
-                                * different on each device in the array.
-                                */
-
-       /* constant this-device information - 64 bytes */
-       __u64   data_offset;    /* sector start of data, often 0 */
-       __u64   data_size;      /* sectors in this device that can be used for data */
-       __u64   super_offset;   /* sector start of this superblock */
-       union {
-               __u64   recovery_offset;/* sectors before this offset (from data_offset) have been recovered */
-               __u64   journal_tail;/* journal tail of journal device (from data_offset) */
-       };
-       __u32   dev_number;     /* permanent identifier of this  device - not role in raid */
-       __u32   cnt_corrected_read; /* number of read errors that were corrected by re-writing */
-       __u8    device_uuid[16]; /* user-space setable, ignored by kernel */
-       __u8    devflags;        /* per-device flags.  Only one defined...*/
-#define WriteMostly1    1        /* mask for writemostly flag in above */
-#define FailFast1      2        /* Device should get FailFast requests */
-       /* bad block log.  If there are any bad blocks the feature flag is set.
-        * if offset and size are non-zero, that space is reserved and available.
-        */
-       __u8    bblog_shift;    /* shift from sectors to block size for badblock list */
-       __u16   bblog_size;     /* number of sectors reserved for badblock list */
-       __u32   bblog_offset;   /* sector offset from superblock to bblog, signed */
-
-       /* array state information - 64 bytes */
-       __u64   utime;          /* 40 bits second, 24 bits microseconds */
-       __u64   events;         /* incremented when superblock updated */
-       __u64   resync_offset;  /* data before this offset (from data_offset) known to be in sync */
-       __u32   sb_csum;        /* checksum upto dev_roles[max_dev] */
-       __u32   max_dev;        /* size of dev_roles[] array to consider */
-       __u8    pad3[64-32];    /* set to 0 when writing */
-
-       /* device state information. Indexed by dev_number.
-        * 2 bytes per device
-        * Note there are no per-device state flags. State information is rolled
-        * into the 'roles' value.  If a device is spare or faulty, then it doesn't
-        * have a meaningful role.
-        */
-       __u16   dev_roles[0];   /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
-};
-
 #define MAX_SB_SIZE 4096
 /* bitmap super size is 256, but we round up to a sector for alignment */
 #define BM_SUPER_SIZE 512
@@ -126,40 +40,6 @@ struct misc_dev_info {
 #define MULTIPLE_PPL_AREA_SIZE_SUPER1 (1024 * 1024) /* Size of the whole
                                                     * mutliple PPL area
                                                     */
-/* feature_map bits */
-#define MD_FEATURE_BITMAP_OFFSET       1
-#define        MD_FEATURE_RECOVERY_OFFSET      2 /* recovery_offset is present and
-                                          * must be honoured
-                                          */
-#define        MD_FEATURE_RESHAPE_ACTIVE       4
-#define        MD_FEATURE_BAD_BLOCKS           8 /* badblock list is not empty */
-#define        MD_FEATURE_REPLACEMENT          16 /* This device is replacing an
-                                           * active device with same 'role'.
-                                           * 'recovery_offset' is also set.
-                                           */
-#define        MD_FEATURE_RESHAPE_BACKWARDS    32 /* Reshape doesn't change number
-                                           * of devices, but is going
-                                           * backwards anyway.
-                                           */
-#define        MD_FEATURE_NEW_OFFSET           64 /* new_offset must be honoured */
-#define        MD_FEATURE_BITMAP_VERSIONED     256 /* bitmap version number checked properly */
-#define        MD_FEATURE_JOURNAL              512 /* support write journal */
-#define        MD_FEATURE_PPL                  1024 /* support PPL */
-#define        MD_FEATURE_MUTLIPLE_PPLS        2048 /* support for multiple PPLs */
-#define        MD_FEATURE_RAID0_LAYOUT         4096 /* layout is meaningful in RAID0 */
-#define        MD_FEATURE_ALL                  (MD_FEATURE_BITMAP_OFFSET       \
-                                       |MD_FEATURE_RECOVERY_OFFSET     \
-                                       |MD_FEATURE_RESHAPE_ACTIVE      \
-                                       |MD_FEATURE_BAD_BLOCKS          \
-                                       |MD_FEATURE_REPLACEMENT         \
-                                       |MD_FEATURE_RESHAPE_BACKWARDS   \
-                                       |MD_FEATURE_NEW_OFFSET          \
-                                       |MD_FEATURE_BITMAP_VERSIONED    \
-                                       |MD_FEATURE_JOURNAL             \
-                                       |MD_FEATURE_PPL                 \
-                                       |MD_FEATURE_MULTIPLE_PPLS       \
-                                       |MD_FEATURE_RAID0_LAYOUT        \
-                                       )
 
 static int role_from_sb(struct mdp_superblock_1 *sb)
 {
@@ -319,7 +199,7 @@ static int awrite(struct align_fd *afd, void *buf, int len)
 static inline unsigned int md_feature_any_ppl_on(__u32 feature_map)
 {
        return ((__cpu_to_le32(feature_map) &
-           (MD_FEATURE_PPL | MD_FEATURE_MUTLIPLE_PPLS)));
+           (MD_FEATURE_PPL | MD_FEATURE_MULTIPLE_PPLS)));
 }
 
 static inline unsigned int choose_ppl_space(int chunk)
@@ -1483,7 +1363,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
        }
        case UOPT_NO_PPL:
                sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_PPL |
-                                                  MD_FEATURE_MUTLIPLE_PPLS);
+                                                 MD_FEATURE_MULTIPLE_PPLS);
                break;
        case UOPT_DEVICESIZE:
                if (__le64_to_cpu(sb->super_offset) >=
@@ -2650,7 +2530,7 @@ add_internal_bitmap1(struct supertype *st,
        bms->nodes = __cpu_to_le32(st->nodes);
        if (st->nodes)
                sb->feature_map = __cpu_to_le32(__le32_to_cpu(sb->feature_map) |
-                                               MD_FEATURE_BITMAP_VERSIONED);
+                                               MD_FEATURE_CLUSTERED);
        if (st->cluster_name) {
                len = sizeof(bms->cluster_name);
                strncpy((char *)bms->cluster_name, st->cluster_name, len);
diff --git a/udev.c b/udev.c
index 88a997818115995677e025aa47db27c4827ad265..961ca970d46009c95a6ce51103135c9fc971dead 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -20,8 +20,6 @@
 
 #include       "mdadm.h"
 #include       "udev.h"
-#include       "md_p.h"
-#include       "md_u.h"
 #include       "xmalloc.h"
 
 #include       <sys/wait.h>