Skip to contentSkip to conversation

mdadm: Use kernel raid headers

PATCH In review [email protected] 2 participants 5 messages Mar 19, 2025 – Mar 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mdadm: Use kernel raid headers

From: Mariusz Tkaczyk <[email protected]>

Sending on ML for wider audience. I would like to confirm that there are no objections to remove klibc support.

Kernel is exporting md_p.h and md_u.h which were newer used by mdadm. This patchset integrates them with mdadm. There are some missing defines in kernel headers, so they are redefined in ifndef blocks.

md_p.h includes asm/byteorder.h and it provides endianess casting functions. These functions are also provided by klibc. To fix this, I removed klibc support because I determined that mdadm is not compiling with klibc for at least 3 years.

I also removed uclibc because it is not actively maintained, on other hand we are working to enable musl:
https://github.com/md-raid-utilities/mdadm/issues/76

Thanks for review and feedback.

Mariusz Tkaczyk (3):
mdadm: Remove klibc and uclibc support
mdadm: include asm/byteorder.h
mdadm: use kernel raid headers

 Create.c    |   2 -
 Detail.c    |   2 -
 Examine.c   |   2 -
 Grow.c      |   6 ---
 Kill.c      |   2 -
 Makefile    |  34 ++------------
 Manage.c    |   2 -
 Query.c     |   2 -
 README.md   |   3 --
 mdadm.h     | 108 +++++++-------------------------------------
 mdmonitor.c |   2 -
 super1.c    | 126 ++--------------------------------------------------
 udev.c      |   2 -
 13 files changed, 22 insertions(+), 271 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 mdadm: Remove klibc and uclibc support

From: Mariusz Tkaczyk <[email protected]>

Klibc compilation is not working for at least 3 years because of following error:
mdadm.h:1912:15: error: unknown type name 'sighandler_t'

It will have a conflict with le/be_to_cpu() functions family provided by asm/byteorder.h which will be included with raid/md_p.h. Therefore we need to remove support for it. Also, remove uclibc because it is not actively maintained.

Remove klibc and uclibc targets from Makefile and special klibc code. Targets can be removed safely because using CC is recommended.

---
 Makefile  | 34 +++-------------------------------
 README.md |  3 ---
 mdadm.h   | 37 +------------------------------------
 3 files changed, 4 insertions(+), 70 deletions(-)
Makefile +3 -31
index bcd092de50c7..387e4a56f519 100644
@@ -31,16 +31,6 @@
 # define "CXFLAGS" to give extra flags to CC.
 # e.g.  make CXFLAGS=-O to optimise
 CXFLAGS ?=-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE
-TCC = tcc
-UCLIBC_GCC = $(shell for nm in i386-uclibc-linux-gcc i386-uclibc-gcc; do which $$nm > /dev/null && { echo $$nm ; exit; } ; done; echo false No uclibc found )
-#DIET_GCC = diet gcc
-# sorry, but diet-libc doesn't know about posix_memalign,
-# so we cannot use it any more.
-DIET_GCC = gcc -DHAVE_STDINT_H
-
-KLIBC=/home/src/klibc/klibc-0.77
-
-KLIBC_GCC = gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32
 
 ifdef COVERITY
 COVERITY_FLAGS=-include coverity-gcc-hack.h
@@ -225,8 +215,6 @@ everything: all swap_super test_stripe raid6check \
 	mdadm.Os mdadm.O2 man
 everything-test: all swap_super test_stripe \
 	mdadm.Os mdadm.O2 man
-# mdadm.uclibc doesn't work on x86-64
-# mdadm.tcc doesn't work..
 
 %.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(COVERITY_FLAGS) -o $@ -c $<
@@ -237,13 +225,6 @@ mdadm : $(OBJS) | check_rundir
 mdadm.static : $(OBJS) $(STATICOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -static -o mdadm.static $(OBJS) $(STATICOBJS) $(LDLIBS)
 
-mdadm.tcc : $(SRCS) $(INCL)
-	$(TCC) -o mdadm.tcc $(SRCS)
-
-mdadm.klibc : $(SRCS) $(INCL)
-	rm -f $(OBJS)
-	$(CC) -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS)
-
 mdadm.Os : $(SRCS) $(INCL)
 	$(CC) -o mdadm.Os $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -Os $(SRCS) $(LDLIBS)
 
@@ -298,15 +279,6 @@ install : install-bin install-man install-udev
 install-static : mdadm.static install-man
 	$(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
 
-install-tcc : mdadm.tcc install-man
-	$(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
-
-install-uclibc : mdadm.uclibc install-man
-	$(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
-
-install-klibc : mdadm.klibc install-man
-	$(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
-
 install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
 	$(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
 	$(INSTALL) -D -m 644 mdmon.8 $(DESTDIR)$(MAN8DIR)/mdmon.8
@@ -354,9 +326,9 @@ test: mdadm mdmon test_stripe swap_super raid6check
 
 clean :
 	rm -f mdadm mdmon $(OBJS) $(MON_OBJS) $(STATICOBJS) core *.man \
-	mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt \
-	.merge_file_* mdadm.Os mdadm.O2 mdmon.O2 swap_super init.cpio.gz \
-	mdadm.uclibc.static test_stripe raid6check raid6check.o mdmon mdadm.8
+	mdadm.static *.orig *.porig *.rej *.alt merge_file_* \
+	mdadm.Os mdadm.O2 mdmon.O2 swap_super init.cpio.gz \
+	test_stripe raid6check raid6check.o mdmon mdadm.8
 	rm -rf cov-int
 
 dist : clean
README.md +0 -3
index 0c299a9a26a2..12a26353e7e9 100644
@@ -138,9 +138,6 @@ List of installation targets:
 
 The following targets are deprecated and should not be used:
 - `install-static`
-- `install-tcc`
-- `install-uclibc`
-- `install-klibc`
 
 # License
 
mdadm.h +1 -36
index e84c341c3040..0b86e4849d33 100644
@@ -43,6 +43,7 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 #include	<sys/time.h>
 #include	<getopt.h>
 #include	<fcntl.h>
+#include	<ftw.h>
 #include	<stdio.h>
 #include	<errno.h>
 #include	<string.h>
@@ -189,7 +190,6 @@ struct dlm_lksb {
 			     ((x) & 0x00000000ff000000ULL) << 8 |  \
 			     ((x) & 0x000000ff00000000ULL) >> 8)
 
-#if !defined(__KLIBC__)
 #if BYTE_ORDER == LITTLE_ENDIAN
 #define	__cpu_to_le16(_x) (unsigned int)(_x)
 #define __cpu_to_le32(_x) (unsigned int)(_x)
@@ -221,7 +221,6 @@ struct dlm_lksb {
 #else
 #  error "unknown endianness."
 #endif
-#endif /* __KLIBC__ */
 
 /*
  * Partially stolen from include/linux/unaligned/packed_struct.h
@@ -1530,40 +1529,6 @@ extern void sysfsline(char *line);
 struct stat64;
 #endif
 
-#define HAVE_NFTW  we assume
-#define HAVE_FTW
-
-#ifdef __UCLIBC__
-# include <features.h>
-# ifndef __UCLIBC_HAS_LFS__
-#  define lseek64 lseek
-# endif
-# ifndef  __UCLIBC_HAS_FTW__
-#  undef HAVE_FTW
-#  undef HAVE_NFTW
-# endif
-#endif
-
-#ifdef __dietlibc__
-# undef HAVE_NFTW
-#endif
-
-#if defined(__KLIBC__)
-# undef HAVE_NFTW
-# undef HAVE_FTW
-#endif
-
-#ifndef HAVE_NFTW
-# define FTW_PHYS 1
-# ifndef HAVE_FTW
-  struct FTW {};
-# endif
-#endif
-
-#ifdef HAVE_FTW
-# include <ftw.h>
-#endif
-
 extern int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s);
 
 extern int Manage_ro(char *devname, int fd, int readonly);
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 mdadm: include asm/byteorder.h

In reply to [email protected]

From: Mariusz Tkaczyk <[email protected]>

It will be included by raid/md_p.h anyway. Include it directly and remove custom functions. It is not a problem now.

---
 mdadm.h | 55 +------------------------------------------------------
 1 file changed, 1 insertion(+), 54 deletions(-)
mdadm.h +1 -54
index 0b86e4849d33..d2c2a4dac11b 100644
@@ -34,6 +34,7 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 #endif
 
 #include	<assert.h>
+#include	<asm/byteorder.h>
 #include	<sys/types.h>
 #include	<sys/stat.h>
 #include	<stdarg.h>
@@ -85,7 +86,6 @@ struct dlm_lksb {
 #endif
 
 #include	<linux/kdev_t.h>
-/*#include	<linux/fs.h> */
 #include	<sys/mount.h>
 #include	<asm/types.h>
 #include	<sys/ioctl.h>
@@ -169,59 +169,6 @@ struct dlm_lksb {
 #include	"msg.h"
 #include	"mdadm_status.h"
 
-#include <endian.h>
-/* Redhat don't like to #include <asm/byteorder.h>, and
- * some time include <linux/byteorder/xxx_endian.h> isn't enough,
- * and there is no standard conversion function so... */
-/* And dietlibc doesn't think byteswap is ok, so.. */
-/*  #include <byteswap.h> */
-#define __mdadm_bswap_16(x) (((x) & 0x00ffU) << 8 | \
-			     ((x) & 0xff00U) >> 8)
-#define __mdadm_bswap_32(x) (((x) & 0x000000ffU) << 24 | \
-			     ((x) & 0xff000000U) >> 24 | \
-			     ((x) & 0x0000ff00U) << 8  | \
-			     ((x) & 0x00ff0000U) >> 8)
-#define __mdadm_bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
-			     ((x) & 0xff00000000000000ULL) >> 56 | \
-			     ((x) & 0x000000000000ff00ULL) << 40 | \
-			     ((x) & 0x00ff000000000000ULL) >> 40 | \
-			     ((x) & 0x0000000000ff0000ULL) << 24 | \
-			     ((x) & 0x0000ff0000000000ULL) >> 24 | \
-			     ((x) & 0x00000000ff000000ULL) << 8 |  \
-			     ((x) & 0x000000ff00000000ULL) >> 8)
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define	__cpu_to_le16(_x) (unsigned int)(_x)
-#define __cpu_to_le32(_x) (unsigned int)(_x)
-#define __cpu_to_le64(_x) (unsigned long long)(_x)
-#define	__le16_to_cpu(_x) (unsigned int)(_x)
-#define __le32_to_cpu(_x) (unsigned int)(_x)
-#define __le64_to_cpu(_x) (unsigned long long)(_x)
-
-#define	__cpu_to_be16(_x) __mdadm_bswap_16(_x)
-#define __cpu_to_be32(_x) __mdadm_bswap_32(_x)
-#define __cpu_to_be64(_x) __mdadm_bswap_64(_x)
-#define	__be16_to_cpu(_x) __mdadm_bswap_16(_x)
-#define __be32_to_cpu(_x) __mdadm_bswap_32(_x)
-#define __be64_to_cpu(_x) __mdadm_bswap_64(_x)
-#elif BYTE_ORDER == BIG_ENDIAN
-#define	__cpu_to_le16(_x) __mdadm_bswap_16(_x)
-#define __cpu_to_le32(_x) __mdadm_bswap_32(_x)
-#define __cpu_to_le64(_x) __mdadm_bswap_64(_x)
-#define	__le16_to_cpu(_x) __mdadm_bswap_16(_x)
-#define __le32_to_cpu(_x) __mdadm_bswap_32(_x)
-#define __le64_to_cpu(_x) __mdadm_bswap_64(_x)
-
-#define	__cpu_to_be16(_x) (unsigned int)(_x)
-#define __cpu_to_be32(_x) (unsigned int)(_x)
-#define __cpu_to_be64(_x) (unsigned long long)(_x)
-#define	__be16_to_cpu(_x) (unsigned int)(_x)
-#define __be32_to_cpu(_x) (unsigned int)(_x)
-#define __be64_to_cpu(_x) (unsigned long long)(_x)
-#else
-#  error "unknown endianness."
-#endif
-
 /*
  * Partially stolen from include/linux/unaligned/packed_struct.h
  */
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/3 mdadm: use kernel raid headers

In reply to [email protected]

From: Mariusz Tkaczyk <[email protected]>

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.

---
 Create.c    |   2 -
 Detail.c    |   2 -
 Examine.c   |   2 -
 Grow.c      |   6 ---
 Kill.c      |   2 -
 Manage.c    |   2 -
 Query.c     |   2 -
 mdadm.h     |  16 ++++++-
 mdmonitor.c |   2 -
 super1.c    | 126 ++--------------------------------------------------
 udev.c      |   2 -
 11 files changed, 17 insertions(+), 147 deletions(-)
Create.c +0 -2
index fd6c92152021..4d5c15531df1 100644
@@ -23,8 +23,6 @@
  */
 
 #include	"mdadm.h"
-#include	"md_u.h"
-#include	"md_p.h"
 #include	"udev.h"
 #include	"xmalloc.h"
 
Detail.c +0 -2
index b804a624574c..3802ef8fa6fc 100644
@@ -23,8 +23,6 @@
  */
 
 #include	"mdadm.h"
-#include	"md_p.h"
-#include	"md_u.h"
 #include	"xmalloc.h"
 
 #include	<ctype.h>
Examine.c +0 -2
index 036b7a5634ad..9c8564be90d4 100644
@@ -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)
Grow.c +0 -6
index 53b0b3876b26..30eaa3c6a654 100644
@@ -30,12 +30,6 @@
 #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,
Kill.c +0 -2
index 43c9abed3b42..9f05a1ace8e1 100644
@@ -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)
 {
Manage.c +0 -2
index 034eb00c7f7d..22b1f52b7dc7 100644
@@ -23,8 +23,6 @@
  */
 
 #include "mdadm.h"
-#include "md_u.h"
-#include "md_p.h"
 #include "udev.h"
 #include "xmalloc.h"
 
Query.c +0 -2
index aedb4ce77d83..72f49a4e6e54 100644
@@ -23,8 +23,6 @@
  */
 
 #include	"mdadm.h"
-#include	"md_p.h"
-#include	"md_u.h"
 
 int Query(char *dev)
 {
mdadm.h +14 -2
index d2c2a4dac11b..a34a3ec2c472 100644
@@ -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"
mdmonitor.c +0 -2
index d1cfbf947191..d51617cd0981 100644
@@ -23,8 +23,6 @@
  */
 
 #include	"mdadm.h"
-#include	"md_p.h"
-#include	"md_u.h"
 #include	"udev.h"
 #include	"xmalloc.h"
 
super1.c +3 -123

156 lines not on this page · raw message

udev.c +0 -2
index 88a997818115..961ca970d460 100644
@@ -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>
Signature · 1 line
2.43.0
Acked-by on the v0 series
#4 lore raw
In reply to [email protected]
Quoted 47 lines · On Thu, Mar 20, 2025 at 1:11 AM <[email protected]> wrote:

From: Mariusz Tkaczyk <[email protected]>

Sending on ML for wider audience. I would like to confirm that there are no objections to remove klibc support.

Kernel is exporting md_p.h and md_u.h which were newer used by mdadm. This patchset integrates them with mdadm. There are some missing defines in kernel headers, so they are redefined in ifndef blocks.

md_p.h includes asm/byteorder.h and it provides endianess casting functions. These functions are also provided by klibc. To fix this, I removed klibc support because I determined that mdadm is not compiling with klibc for at least 3 years.

I also removed uclibc because it is not actively maintained, on other hand we are working to enable musl:
https://github.com/md-raid-utilities/mdadm/issues/76

Thanks for review and feedback.

Mariusz Tkaczyk (3):
mdadm: Remove klibc and uclibc support
mdadm: include asm/byteorder.h
mdadm: use kernel raid headers

 Create.c    |   2 -
 Detail.c    |   2 -
 Examine.c   |   2 -
 Grow.c      |   6 ---
 Kill.c      |   2 -
 Makefile    |  34 ++------------
 Manage.c    |   2 -
 Query.c     |   2 -
 README.md   |   3 --
 mdadm.h     | 108 +++++++-------------------------------------
 mdmonitor.c |   2 -
 super1.c    | 126 ++--------------------------------------------------
 udev.c      |   2 -
 13 files changed, 22 insertions(+), 271 deletions(-)
Quoted 3 lines

--
2.43.0

Hi Mariusz

This patch set looks good to me. You need to re-submit the PR based on the latest version of https://github.com/md-raid-utilities/mdadm.
So we can know if regression tests can run successfully.