]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
Update ChangeLog and release 2.3
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index 8af61e9627df5e5ea241e0f5ab30e8a74ee82935..7b6c3d01039c3d463494fb7f19131cf1596e64f9 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -40,13 +40,12 @@ int main(int argc, char *argv[])
        int mode = 0;
        int opt;
        int option_index;
-       char *help_text;
        char *c;
        int rv;
        int i;
 
        int chunk = 0;
-       int size = -1;
+       long long size = -1;
        int level = UnSet;
        int layout = UnSet;
        int raiddisks = 0;
@@ -93,8 +92,11 @@ int main(int argc, char *argv[])
        struct supertype *ss = NULL;
        int writemostly = 0;
        int re_add = 0;
+       char *shortopt = short_options;
+       int dosyslog = 0;
 
        int copies;
+       int print_help = 0;
 
        int mdfd = -1;
 
@@ -113,28 +115,18 @@ int main(int argc, char *argv[])
 
        while ((option_index = -1) ,
               (opt=getopt_long(argc, argv,
-                               short_options, long_options,
+                               shortopt, long_options,
                                &option_index)) != -1) {
                int newmode = mode;
                /* firstly, some mode-independant options */
                switch(opt) {
                case 'h':
-                       help_text = Help;
                        if (option_index > 0 && 
                            strcmp(long_options[option_index].name, "help-options")==0)
-                               help_text = OptionHelp;
+                               print_help = 2;
                        else
-                               switch (mode) {
-                               case ASSEMBLE : help_text = Help_assemble; break;
-                               case BUILD    : help_text = Help_build; break;
-                               case CREATE   : help_text = Help_create; break;
-                               case MANAGE   : help_text = Help_manage; break;
-                               case MISC     : help_text = Help_misc; break;
-                               case MONITOR  : help_text = Help_monitor; break;
-                               case GROW     : help_text = Help_grow; break;
-                               }
-                       fputs(help_text,stderr);
-                       exit(0);
+                               print_help = 1;
+                       continue;
 
                case 'V':
                        fputs(Version, stderr);
@@ -150,6 +142,10 @@ int main(int argc, char *argv[])
                        if (mode == ASSEMBLE || mode == BUILD || mode == CREATE || mode == GROW)
                                break; /* b means bitmap */
                        brief = 1;
+                       if (optarg) {
+                               fprintf(stderr, Name ": -b cannot have any extra immediately after it, sorry.\n");
+                               exit(2);
+                       }
                        continue;
 
                case ':':
@@ -164,19 +160,24 @@ int main(int argc, char *argv[])
 
                switch(opt) {
                case '@': /* just incase they say --manage */
-                       newmode = MANAGE; break;
+                       newmode = MANAGE;
+                       shortopt = short_bitmap_auto_options;
+                       break;
                case 'a':
                case 'r':
                case 'f':
                case 6: /* re-add */
-                       if (!mode) newmode = MANAGE; 
+                       if (!mode) {
+                               newmode = MANAGE;
+                               shortopt = short_bitmap_auto_options;
+                       }
                        break;
 
-               case 'A': newmode = ASSEMBLE; break;
-               case 'B': newmode = BUILD; break;
-               case 'C': newmode = CREATE; break;
+               case 'A': newmode = ASSEMBLE; shortopt = short_bitmap_auto_options; break;
+               case 'B': newmode = BUILD; shortopt = short_bitmap_auto_options; break;
+               case 'C': newmode = CREATE; shortopt = short_bitmap_auto_options; break;
                case 'F': newmode = MONITOR;break;
-               case 'G': newmode = GROW; break;
+               case 'G': newmode = GROW; shortopt = short_bitmap_auto_options; break;
 
                case '#':
                case 'D':
@@ -336,7 +337,7 @@ int main(int argc, char *argv[])
                        if (strcmp(optarg, "max")==0)
                                size = 0;
                        else {
-                               size = strtol(optarg, &c, 10);
+                               size = strtoll(optarg, &c, 10);
                                if (!optarg[0] || *c || size < 4) {
                                        fprintf(stderr, Name ": invalid size: %s\n",
                                                optarg);
@@ -582,6 +583,8 @@ int main(int argc, char *argv[])
                                continue;
                        if (strcmp(update, "resync")==0)
                                continue;
+                       if (strcmp(update, "uuid")==0)
+                               continue;
                        if (strcmp(update, "byteorder")==0) {
                                if (ss) {
                                        fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n");
@@ -596,7 +599,7 @@ int main(int argc, char *argv[])
 
                                continue;
                        }
-                       fprintf(stderr, Name ": '--update %s' invalid.  Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update);
+                       fprintf(stderr, Name ": '--update %s' invalid.  Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update);
                        exit(2);
 
                case O(ASSEMBLE,'c'): /* config file */
@@ -664,6 +667,10 @@ int main(int argc, char *argv[])
                case O(MONITOR,'t'): /* test */
                        test = 1;
                        continue;
+               case O(MONITOR,'y'): /* log messages to syslog */
+                       openlog("mdadm", 0, SYSLOG_FACILITY);
+                       dosyslog = 1;
+                       continue;
 
                        /* now the general management options.  Some are applicable
                         * to other modes. None have arguments.
@@ -804,6 +811,24 @@ int main(int argc, char *argv[])
 
        }
 
+       if (print_help) {
+               char *help_text = Help;
+               if (print_help == 2)
+                       help_text = OptionHelp;
+               else
+                       switch (mode) {
+                       case ASSEMBLE : help_text = Help_assemble; break;
+                       case BUILD    : help_text = Help_build; break;
+                       case CREATE   : help_text = Help_create; break;
+                       case MANAGE   : help_text = Help_manage; break;
+                       case MISC     : help_text = Help_misc; break;
+                       case MONITOR  : help_text = Help_monitor; break;
+                       case GROW     : help_text = Help_grow; break;
+                       }
+               fputs(help_text,stderr);
+               exit(0);
+       }
+
        if (!mode && devs_found) {
                mode = MISC;
                devmode = 'Q';
@@ -981,18 +1006,10 @@ int main(int argc, char *argv[])
                        rv = 1;
                        break;
                }
-               if (ss == NULL) {
-                       for(i=0; !ss && superlist[i]; i++) 
-                               ss = superlist[i]->match_metadata_desc("default");
-               }
-               if (!ss) {
-                       fprintf(stderr, Name ": internal error - no default metadata style\n");
-                       exit(2);
-               }
 
                rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
                            raiddisks, sparedisks, ident.name,
-                           devs_found-1, devlist->next, runstop, verbose-quiet, force,
+                           devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
                            bitmap_file, bitmap_chunk, write_behind, delay);
                break;
        case MISC:
@@ -1013,7 +1030,7 @@ int main(int argc, char *argv[])
                        if (devlist == NULL) {
                                if (devmode=='D' && scan) {
                                        /* apply --detail to all devices in /proc/mdstat */
-                                       struct mdstat_ent *ms = mdstat_read(0);
+                                       struct mdstat_ent *ms = mdstat_read(0, 1);
                                        struct mdstat_ent *e;
                                        for (e=ms ; e ; e=e->next) {
                                                char *name = get_md_name(e->devnum);
@@ -1034,7 +1051,7 @@ int main(int argc, char *argv[])
                                        int progress=1, err;
                                        int last = 0;
                                        do {
-                                               struct mdstat_ent *ms = mdstat_read(0);
+                                               struct mdstat_ent *ms = mdstat_read(0, 0);
                                                struct mdstat_ent *e;
 
                                                if (!progress) last = 1;
@@ -1106,7 +1123,8 @@ int main(int argc, char *argv[])
                        break;
                }
                rv= Monitor(devlist, mailaddr, program,
-                           delay?delay:60, daemonise, scan, oneshot, configfile, test, pidfile);
+                           delay?delay:60, daemonise, scan, oneshot,
+                           dosyslog, configfile, test, pidfile);
                break;
 
        case GROW:
@@ -1134,7 +1152,7 @@ int main(int argc, char *argv[])
                else if (bitmap_file) {
                        if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
                        rv = Grow_addbitmap(devlist->devname, mdfd, bitmap_file,
-                                           bitmap_chunk, delay, write_behind);
+                                           bitmap_chunk, delay, write_behind, force);
                } else
                        fprintf(stderr, Name ": no changes to --grow\n");
                break;