]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
Add new mode: --incremental
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index 9fe56abe6c084a76c5b3d7660a8590933ae9b855..9bec29589c6291ae9af9e7df91df174f83c36e9a 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -75,6 +75,7 @@ int main(int argc, char *argv[])
        int force = 0;
        int test = 0;
        int assume_clean = 0;
+       char *symlinks = NULL;
        /* autof indicates whether and how to create device node.
         * bottom 3 bits are style.  Rest (when shifted) are number of parts
         * 0  - unset
@@ -100,6 +101,7 @@ int main(int argc, char *argv[])
        int re_add = 0;
        char *shortopt = short_options;
        int dosyslog = 0;
+       int rebuild_map = 0;
        int auto_update_home = 0;
 
        int copies;
@@ -190,6 +192,7 @@ int main(int argc, char *argv[])
                case 'C': newmode = CREATE; shortopt = short_bitmap_auto_options; break;
                case 'F': newmode = MONITOR;break;
                case 'G': newmode = GROW; shortopt = short_bitmap_auto_options; break;
+               case 'I': newmode = INCREMENTAL; break;
 
                case '#':
                case 'D':
@@ -200,6 +203,7 @@ int main(int argc, char *argv[])
                case 'S':
                case 'o':
                case 'w':
+               case 'W':
                case 'K': if (!mode) newmode = MISC; break;
                }
                if (mode && newmode == mode) {
@@ -267,6 +271,7 @@ int main(int argc, char *argv[])
                case 'C':
                case 'F':
                case 'G':
+               case 'I':
                        continue;
                }
                if (opt == 1) {
@@ -319,6 +324,7 @@ int main(int argc, char *argv[])
                case O(ASSEMBLE,AutoHomeHost):
                        auto_update_home = 1;
                        continue;
+               case O(INCREMENTAL, 'e'):
                case O(CREATE,'e'):
                case O(ASSEMBLE,'e'):
                case O(MISC,'e'): /* set metadata (superblock) information */
@@ -499,6 +505,12 @@ int main(int argc, char *argv[])
                        autof = parse_auto(optarg, "--auto flag", 0);
                        continue;
 
+               case O(CREATE,Symlinks):
+               case O(BUILD,Symlinks):
+               case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */
+                       symlinks = optarg;
+                       continue;
+
                case O(BUILD,'f'): /* force honouring '-n 1' */
                case O(GROW,'f'): /* ditto */
                case O(CREATE,'f'): /* force honouring of device list */
@@ -508,6 +520,7 @@ int main(int argc, char *argv[])
                        continue;
 
                        /* now for the Assemble options */
+               case O(CREATE,'u'): /* uuid of array */
                case O(ASSEMBLE,'u'): /* uuid of array */
                        if (ident.uuid_set) {
                                fprintf(stderr, Name ": uuid cannot be set twice.  "
@@ -575,6 +588,8 @@ int main(int argc, char *argv[])
                                continue;
                        if (strcmp(update, "homehost")==0)
                                continue;
+                       if (strcmp(update, "devicesize")==0)
+                               continue;
                        if (strcmp(update, "byteorder")==0) {
                                if (ss) {
                                        fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n");
@@ -589,7 +604,13 @@ int main(int argc, char *argv[])
 
                                continue;
                        }
-                       fprintf(stderr, Name ": '--update %s' invalid.  Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update);
+                       if (strcmp(update,"?") == 0 || strcmp(update, "help") == 0)
+                               fprintf(stderr, Name ": ");
+                       else
+                               fprintf(stderr, Name ": '--update=%s' is invalid.  ", update);
+                       fprintf(stderr, "Valid --update options are:\n"
+               "     'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
+               "     'summaries', 'homehost', 'byteorder', 'devicesize'.\n");
                        exit(2);
 
                case O(ASSEMBLE,NoDegraded): /* --no-degraded */
@@ -611,6 +632,7 @@ int main(int argc, char *argv[])
                case O(ASSEMBLE,'s'): /* scan */
                case O(MISC,'s'):
                case O(MONITOR,'s'):
+               case O(INCREMENTAL,'s'):
                        scan = 1;
                        continue;
 
@@ -685,6 +707,7 @@ int main(int argc, char *argv[])
                case O(MANAGE,'f'): /* set faulty */
                        devmode = 'f';
                        continue;
+               case O(INCREMENTAL,'R'):
                case O(MANAGE,'R'):
                case O(ASSEMBLE,'R'):
                case O(BUILD,'R'):
@@ -727,6 +750,7 @@ int main(int argc, char *argv[])
                case O(MISC,'X'):
                case O(MISC,'o'):
                case O(MISC,'w'):
+               case O(MISC,'W'):
                        if (devmode && devmode != opt &&
                            (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
                                fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n",
@@ -815,6 +839,10 @@ int main(int argc, char *argv[])
                                }
                        }
                        continue;
+
+               case O(INCREMENTAL, 'r'):
+                       rebuild_map = 1;
+                       continue;
                }
                /* We have now processed all the valid options. Anything else is
                 * an error
@@ -843,6 +871,7 @@ int main(int argc, char *argv[])
                        case MISC     : help_text = Help_misc; break;
                        case MONITOR  : help_text = Help_monitor; break;
                        case GROW     : help_text = Help_grow; break;
+                       case INCREMENTAL:help_text= Help_incr; break;
                        }
                fputs(help_text,stderr);
                exit(0);
@@ -858,6 +887,19 @@ int main(int argc, char *argv[])
                fputs(Usage, stderr);
                exit(2);
        }
+
+       if (symlinks) {
+               struct createinfo *ci = conf_get_create_info();
+
+               if (strcasecmp(symlinks, "yes") == 0)
+                       ci->symlinks = 1;
+               else if (strcasecmp(symlinks, "no") == 0)
+                       ci->symlinks = 0;
+               else {
+                       fprintf(stderr, Name ": option --symlinks must be 'no' or 'yes'\n");
+                       exit(2);
+               }
+       }
        /* Ok, got the option parsing out of the way
         * hopefully it's mostly right but there might be some stuff
         * missing
@@ -1013,7 +1055,7 @@ int main(int argc, char *argv[])
                                }
                                if (ioctl(mdfd, GET_ARRAY_INFO, &array)>=0)
                                        /* already assembled, skip */
-                                       ;
+                                       cnt++;
                                else {
                                        rv |= Assemble(ss, array_list->devname, mdfd,
                                                       array_list,
@@ -1106,11 +1148,11 @@ int main(int argc, char *argv[])
 
                rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
                            raiddisks, sparedisks, ident.name, homehost,
+                           ident.uuid_set ? ident.uuid : NULL,
                            devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
                            bitmap_file, bitmap_chunk, write_behind, delay);
                break;
        case MISC:
-
                if (devmode == 'E') {
                        if (devlist == NULL && !scan) {
                                fprintf(stderr, Name ": No devices to examine\n");
@@ -1122,6 +1164,8 @@ int main(int argc, char *argv[])
                                fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile);
                                exit(1);
                        }
+                       if (brief && verbose)
+                               brief = 2;
                        rv = Examine(devlist, scan?(verbose>1?0:verbose+1):brief, scan, SparcAdjust, ss, homehost);
                } else {
                        if (devlist == NULL) {
@@ -1189,6 +1233,8 @@ int main(int argc, char *argv[])
                                        rv |= Query(dv->devname); continue;
                                case 'X':
                                        rv |= ExamineBitmap(dv->devname, brief, ss); continue;
+                               case 'W':
+                                       rv |= Wait(dv->devname); continue;
                                }
                                mdfd = open_mddev(dv->devname, 1);
                                if (mdfd>=0) {
@@ -1254,6 +1300,34 @@ int main(int argc, char *argv[])
                } else
                        fprintf(stderr, Name ": no changes to --grow\n");
                break;
+       case INCREMENTAL:
+               if (rebuild_map) {
+                       RebuildMap();
+               }
+               if (scan) {
+                       if (runstop <= 0) {
+                               fprintf(stderr, Name
+                        ": --incremental --scan meaningless without --run.\n");
+                               break;
+                       }
+                       rv = IncrementalScan(verbose);
+               }
+               if (!devlist) {
+                       if (!rebuild_map && !scan) {
+                               fprintf(stderr, Name
+                                       ": --incremental requires a device.\n");
+                               rv = 1;
+                       }
+                       break;
+               }
+               if (devlist->next) {
+                       fprintf(stderr, Name
+                              ": --incremental can only handle one device.\n");
+                       rv = 1;
+                       break;
+               }
+               rv = Incremental(devlist->devname, verbose-quiet, runstop,
+                                ss, homehost, autof);
        }
        exit(rv);
 }