]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
Support --assume-clean for --create
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index de1f95a93f1c403b77b0902ba43b995d8feafb8e..c8087998d116d94a041d31f523df746e54715c35 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -70,6 +70,7 @@ int main(int argc, char *argv[])
        mddev_dev_t dv;
        int devs_found = 0;
        int verbose = 0;
+       int quiet = 0;
        int brief = 0;
        int force = 0;
        int test = 0;
@@ -91,6 +92,8 @@ int main(int argc, char *argv[])
        int oneshot = 0;
        struct supertype *ss = NULL;
        int writemostly = 0;
+       int re_add = 0;
+       char *shortopt = short_options;
 
        int copies;
 
@@ -111,10 +114,10 @@ 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, so mode-independant options */
+               /* firstly, some mode-independant options */
                switch(opt) {
                case 'h':
                        help_text = Help;
@@ -141,10 +144,17 @@ int main(int argc, char *argv[])
                case 'v': verbose++;
                        continue;
 
+               case 'q': quiet++;
+                       continue;
+
                case 'b':
                        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 ':':
@@ -159,18 +169,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':
-                       if (!mode) newmode = MANAGE; 
+               case 6: /* re-add */
+                       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':
@@ -218,6 +234,7 @@ int main(int argc, char *argv[])
                                        dv->devname = optarg;
                                        dv->disposition = devmode;
                                        dv->writemostly = writemostly;
+                                       dv->re_add = re_add;
                                        dv->next = NULL;
                                        *devlistend = dv;
                                        devlistend = &dv->next;
@@ -267,6 +284,7 @@ int main(int argc, char *argv[])
                        dv->devname = optarg;
                        dv->disposition = devmode;
                        dv->writemostly = writemostly;
+                       dv->re_add = re_add;
                        dv->next = NULL;
                        *devlistend = dv;
                        devlistend = &dv->next;
@@ -663,6 +681,11 @@ int main(int argc, char *argv[])
                case O(GROW,'a'):
                case O(MANAGE,'a'): /* add a drive */
                        devmode = 'a';
+                       re_add = 0;
+                       continue;
+               case O(MANAGE,6):
+                       devmode = 'a';
+                       re_add = 1;
                        continue;
                case O(MANAGE,'r'): /* remove a drive */
                        devmode = 'r';
@@ -860,7 +883,7 @@ int main(int argc, char *argv[])
                        rv = Manage_ro(devlist->devname, mdfd, readonly);
                if (!rv && devs_found>1)
                        rv = Manage_subdevs(devlist->devname, mdfd,
-                                           devlist->next);
+                                           devlist->next, verbose-quiet);
                if (!rv && readonly < 0)
                        rv = Manage_ro(devlist->devname, mdfd, readonly);
                if (!rv && runstop)
@@ -883,14 +906,14 @@ int main(int argc, char *argv[])
                                else {
                                        rv |= Assemble(ss, devlist->devname, mdfd, array_ident, configfile,
                                                       NULL,
-                                                      readonly, runstop, update, verbose, force);
+                                                      readonly, runstop, update, verbose-quiet, force);
                                        close(mdfd);
                                }
                        }
                } else if (!scan)
                        rv = Assemble(ss, devlist->devname, mdfd, &ident, configfile,
                                      devlist->next,
-                                     readonly, runstop, update, verbose, force);
+                                     readonly, runstop, update, verbose-quiet, force);
                else if (devs_found>0) {
                        if (update && devs_found > 1) {
                                fprintf(stderr, Name ": can only update a single array at a time\n");
@@ -912,7 +935,7 @@ int main(int argc, char *argv[])
                                }
                                rv |= Assemble(ss, dv->devname, mdfd, array_ident, configfile,
                                               NULL,
-                                              readonly, runstop, update, verbose, force);
+                                              readonly, runstop, update, verbose-quiet, force);
                                close(mdfd);
                        }
                } else {
@@ -936,7 +959,7 @@ int main(int argc, char *argv[])
                                                rv |= Assemble(ss, array_list->devname, mdfd,
                                                               array_list, configfile,
                                                               NULL,
-                                                              readonly, runstop, NULL, verbose, force);
+                                                              readonly, runstop, NULL, verbose-quiet, force);
                                        close(mdfd);
                                }
                }
@@ -956,20 +979,10 @@ int main(int argc, char *argv[])
                                rv |= 1;
                                break;
                        }
-                       bitmap_fd = open(bitmap_file, O_RDWR,0);
-                       if (bitmap_fd < 0 && errno != ENOENT) {
-                               perror(Name ": cannot create bitmap file");
-                               rv |= 1;
-                               break;
-                       }
-                       if (bitmap_fd < 0) {
-                               bitmap_fd = CreateBitmap(bitmap_file, force, NULL,
-                                                        bitmap_chunk, delay, write_behind, size);
-                       }
                }
                rv = Build(devlist->devname, mdfd, chunk, level, layout,
                           raiddisks, devlist->next, assume_clean,
-                          bitmap_file, bitmap_chunk, write_behind, delay);
+                          bitmap_file, bitmap_chunk, write_behind, delay, verbose-quiet);
                break;
        case CREATE:
                if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
@@ -989,7 +1002,7 @@ int main(int argc, char *argv[])
 
                rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
                            raiddisks, sparedisks, ident.name,
-                           devs_found-1, devlist->next, runstop, verbose, force,
+                           devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
                            bitmap_file, bitmap_chunk, write_behind, delay);
                break;
        case MISC:
@@ -1056,6 +1069,7 @@ int main(int argc, char *argv[])
                                                        put_md_name(name);
                                                }
                                        } while (!last && err);
+                                       if (err) rv |= 1;
                                } else {
                                        fprintf(stderr, Name ": No devices given.\n");
                                        exit(2);
@@ -1085,7 +1099,8 @@ int main(int argc, char *argv[])
                                                rv |= Manage_ro(dv->devname, mdfd, -1); break;
                                        }
                                        close(mdfd);
-                               }
+                               } else
+                                       rv |= 1;
                        }
                }
                break;