small patches to mdadm
Neil,
i made some small patches to mdadm 1.7.0
the first is just some makefile cleanup
the second adds a -i (pid) option to monitor mode which causes mdadm to write its own pid to the specified file, this comes useful to simplify init scripts that call mdadm --monitor --daemonize.
Regards,
L.
Signature · 6 lines
Luca Berra -- [email protected] Communication Media & Services S.r.l. /"\ \ / ASCII RIBBON CAMPAIGN X AGAINST HTML MAIL / \
Makefile renamed from Makefile.makefile +21 -10
@@ -31,6 +31,11 @@ # e.g. make CXFLAGS=-O to optimise 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 + +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 CC = gcc CXFLAGS = -ggdb
@@ -52,11 +57,9 @@ MAN5DIR = $(MANDIR)/man5 MAN8DIR = $(MANDIR)/man8 - -KLIBC=/home/src/klibc/klibc-0.77 - OBJS = mdadm.o config.o mdstat.o ReadMe.o util.o Manage.o Assemble.o Build.o Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o SRCS = mdadm.c config.c mdstat.c ReadMe.c util.c Manage.c Assemble.c Build.c Create.c Detail.c Examine.c Grow.c Monitor.c dlink.c Kill.c Query.c +ASSEMBLE_SRCS = mdassemble.c Assemble.c config.c dlink.c util.c all : mdadm mdadm.man md.man mdadm.conf.man
@@ -66,7 +69,7 @@ $(CC) $(LDFLAGS) -o mdadm $^ mdadm.static : $(OBJS) - $(CC) $(LDFLAGS) --static -o mdadm.static $^ + $(CC) $(LDFLAGS) -static -o mdadm.static $^ mdadm.tcc : $(SRCS) mdadm.h $(TCC) -o mdadm.tcc $(SRCS)
@@ -78,15 +81,22 @@ rm -f $(OBJS) gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS) -mdassemble : mdassemble.c Assemble.c config.c dlink.c util.c mdadm.h +mdassemble : $(ASSEMBLE_SRCS) mdadm.h rm -f $(OBJS) - diet gcc -o mdassemble mdassemble.c Assemble.c config.c dlink.c util.c + $(DIET_GCC) -o mdassemble $(ASSEMBLE_SRCS) -# This doesn't work -mdassemble.klibc : mdassemble.c Assemble.c config.c dlink.c util.c mdadm.h +mdassemble.static : $(ASSEMBLE_SRCS) mdadm.h + rm -f $(OBJS) + $(CC) $(LDFLAGS) -static -o mdassemble $(ASSEMBLE_SRCS) + +mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h rm -f $(OBJS) - gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) -o mdassemble mdassemble.c Assemble.c config.c dlink.c util.c + $(UCLIBC_GCC) -DUCLIBC -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) +# This doesn't work +mdassemble.klibc : $(ASSEMBLE_SRCS) mdadm.h + rm -f $(OBJS) + $(KLIBC_GCC) $(CFLAGS) -o mdassemble $(ASSEMBLE_SRCS) mdadm.man : mdadm.8 nroff -man mdadm.8 > mdadm.man
@@ -106,7 +116,8 @@ $(INSTALL) -D -m 644 mdadm.conf.5 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 clean : - rm -f mdadm $(OBJS) core *.man mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt + rm -f mdadm $(OBJS) core *.man mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt \ + mdassemble mdassemble.static mdassemble.uclibc mdassemble.klibc dist : clean ./makedist
ReadMe.c renamed from ReadMe.c.pidfile +3 -1
@@ -90,7 +90,7 @@* At the time if writing, there is only minimal support. */ -char short_options[]="-ABCDEFGQhVvbc:l:p:m:n:x:u:c:d:z:U:sa::rfRSow1t" ; +char short_options[]="-ABCDEFGQhVvbc:i:l:p:m:n:x:u:c:d:z:U:sa::rfRSow1t" ;struct option long_options[] = { {"manage" ,0 ,0 ,'@' }, {"misc" ,0 ,0 ,'#' },
@@ -157,6 +157,7 @@ {"daemonise", 0, 0, 'f'}, {"daemonize", 0, 0, 'f'}, {"oneshot", 0, 0, '1'}, + {"pid", 1, 0, 'i'}, {0, 0, 0, 0} };
@@ -418,6 +419,7 @@" --config= -c : specify a different config file\n" " --scan -s : find mail-address/program in config file\n" " --daemonise -f : Fork and continue in child, parent exits\n" +" --pid= -i : In daemon mode write pid to specified file instead of stdout\n" " --oneshot -1 : Check for degraded arrays, then exit\n" " --test -t : Generate a TestMessage event against each array at startup\n" ;
Monitor.c renamed from Monitor.c.pidfile +15 -2
@@ -47,7 +47,7 @@int Monitor (mddev_dev_t devlist,char *mailaddr,char *alert_cmd,int period,int daemonise,int scan,int oneshot, -char *config,int test) +char *config,int test,char * pidfile) {/* * Every few seconds, scan every md device looking for changes
@@ -127,7 +127,18 @@if (daemonise) {int pid =fork ();if (pid >0 ) { -printf ("%d\n" , pid); +if (!pidfile) +printf ("%d\n" , pid); +else { +FILE *pid_file; + pid_file=fopen (pidfile,"w" ); +if (!pid_file) +perror ("cannot create pid file" ); +else { +fprintf (pid_file,"%d\n" , pid); +fclose (pid_file); + } + }return 0 ; }if (pid <0 ) {
@@ -428,6 +439,8 @@ } test =0 ; } +if (pidfile) +unlink (pidfile);return 0 ; }
mdadm.c renamed from mdadm.c.pidfile +14 -1
@@ -233,6 +233,7 @@char *program =NULL ;int delay =0 ;int daemonise =0 ; +char *pidfile =NULL ;int oneshot =0 ;int copies;
@@ -677,6 +678,13 @@case O (MONITOR ,'f' ):/* daemonise */ daemonise =1 ;continue ; +case O (MONITOR ,'i' ):/* pid */ +if (pidfile) +fprintf (stderr, Name": only specify one pid file. %s ignored.\n" , + optarg); +else + pidfile = optarg; +continue ;case O (MONITOR ,'1' ):/* oneshot */ oneshot =1 ;continue ;
@@ -963,8 +971,13 @@ rv =1 ;break ; } +if (pidfile && !daemonise) { +fprintf (stderr, Name": Cannot write a pid file when not in daemon mode\n" ); + rv =1 ; +break ; + } rv=Monitor (devlist, mailaddr, program, - delay?delay:60 , daemonise, scan, oneshot, configfile, test); + delay?delay:60 , daemonise, scan, oneshot, configfile, test, pidfile);break ;case GROW :
mdadm.h renamed from mdadm.h.pidfile +1 -1
@@ -187,7 +187,7 @@extern int Monitor (mddev_dev_t devlist,char *mailaddr,char *alert_cmd,int period,int daemonise,int scan,int oneshot, -char *config,int test); +char *config,int test,char *pidfile);extern int Kill (char *dev,int force);
mdadm.8 renamed from mdadm.8.pidfile +7 -0
@@ -540,6 +540,13 @@ is found in the config file. .TP +.BR -i ", " --pid +When +.B mdadm +is running in daemon mode, write the pid of the daemon process to +the specified file, instead of printing it on standard output. + +.TP .BR -1 ", " --oneshot Check arrays only once. This will generate .B NewArray
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · Neil Brown
They'll both be in the next release.
thanks a lot!
here is another patch for mdassemble.
1) add raid6 and raid10
2) add support for the auto=... option.
the auto= can be disabled in the Makefile, allowing users to save about 5k (on x86).
L.
Signature · 6 lines
Luca Berra -- [email protected] Communication Media & Services S.r.l. /"\ \ / ASCII RIBBON CAMPAIGN X AGAINST HTML MAIL / \
mdadm.c renamed from mdadm.c.mdassemble +2 -1
@@ -193,7 +193,7 @@ } - +#ifndef MDASSEMBLE_AUTO int main (int argc,char *argv[]) {int mode =0 ;
@@ -1004,3 +1004,4 @@ }exit (rv); } +#endif /* MDASSEMBLE_AUTO */
mdassemble.c renamed from mdassemble.c.mdassemble +11 -3
@@ -46,11 +46,15 @@ { "5", 5}, { "multipath", -4}, { "mp", -4}, + { "raid6", 6}, + { "6", 6}, + { "raid10", 10}, + { "10", 10}, { NULL, 0} }; -/* from mdadm.c */ -int open_mddev (char *dev) +#ifndef MDASSEMBLE_AUTO +int open_mddev(char *dev, int autof /*ignored*/) { int mdfd = open(dev, O_RDWR, 0); if (mdfd < 0)
@@ -64,6 +68,10 @@ }return mdfd; } +#else +#include "mdstat.c" +#include "mdadm.c" +#endif char *configfile =NULL ;int rv;
@@ -81,7 +89,7 @@ }else for (; array_list; array_list = array_list->next) {mdu_array_info_t array; - mdfd =open_mddev (array_list->devname); + mdfd =open_mddev (array_list->devname, array_list->autof);if (mdfd <0 ) { rv |=1 ;continue ;
Makefile renamed from Makefile.mdassemble +6 -4
@@ -44,6 +44,8 @@ CONFFILE = $(SYSCONFDIR)/mdadm.conf MAILCMD =/usr/sbin/sendmail -t CFLAGS = $(CWFLAGS) -DCONFFILE=\"$(CONFFILE)\" $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\" +# build mdassemble with support for auto= +ASSEMBLE_FLAGS=-DMDASSEMBLE_AUTO # If you want a static binary, you might uncomment these # LDFLAGS = -static
@@ -83,20 +85,20 @@ mdassemble : $(ASSEMBLE_SRCS) mdadm.h rm -f $(OBJS) - $(DIET_GCC) -o mdassemble $(ASSEMBLE_SRCS) + $(DIET_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) mdassemble.static : $(ASSEMBLE_SRCS) mdadm.h rm -f $(OBJS) - $(CC) $(LDFLAGS) -static -o mdassemble $(ASSEMBLE_SRCS) + $(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -o mdassemble $(ASSEMBLE_SRCS) mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h rm -f $(OBJS) - $(UCLIBC_GCC) -DUCLIBC -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) + $(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DUCLIBC -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) # This doesn't work mdassemble.klibc : $(ASSEMBLE_SRCS) mdadm.h rm -f $(OBJS) - $(KLIBC_GCC) $(CFLAGS) -o mdassemble $(ASSEMBLE_SRCS) + $(KLIBC_GCC) $(CFLAGS) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) mdadm.man : mdadm.8 nroff -man mdadm.8 > mdadm.man
mdadm.h renamed from mdadm.h.mdassemble +3 -0
@@ -27,6 +27,8 @@* Australia */ +#ifndef _MDADM_H +#define _MDADM_H 1#define __USE_LARGEFILE64#include <unistd.h> #ifndef __dietlibc__
@@ -227,3 +229,4 @@extern char *get_md_name (int dev);extern char DefaultConfFile[]; +#endif /* _MDADM_H */
Quoted 8 lines · On Monday August 30, [email protected] wrote:
Quoted 1 line · Neil Brown
They'll both be in the next release.
thanks a lot!
here is another patch for mdassemble.
1) add raid6 and raid10
2) add support for the auto=... option.
the auto= can be disabled in theMakefile, allowing users to save about 5k (on x86).
Thanks.
I redid the auto= stuff. I moved mddev_open into a separate file.
It'll be in the next mdadm.
NeilBrown