]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
mdadm-1.1.0
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index 95e7005a9c40920ca9132a973f94ec4390a2205d..d86d1a5bf5095d3f63871fd7bfb4645ebd80a55f 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -65,6 +65,7 @@ int main(int argc, char *argv[])
        struct mddev_ident_s ident;
        char *configfile = NULL;
        char *cp;
+       char *update = NULL;
        int scan = 0;
        char devmode = 0;
        int runstop = 0;
@@ -81,6 +82,7 @@ int main(int argc, char *argv[])
        char *mailaddr = NULL;
        char *program = NULL;
        int delay = 0;
+       int daemonise = 0;
 
        int mdfd = -1;
 
@@ -357,18 +359,35 @@ int main(int argc, char *argv[])
                        continue;
 
                case O(ASSEMBLE,'m'): /* super-minor for array */
-                       if (ident.super_minor >= 0) {
+                       if (ident.super_minor != -1) {
                                fprintf(stderr, Name ": super-minor cannot be set twice.  "
                                        "Second value: %s.\n", optarg);
                                exit(2);
                        }
-                       ident.super_minor = strtoul(optarg, &cp, 10);
-                       if (!optarg[0] || *cp) {
-                               fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg);
-                               exit(2);
+                       if (strcmp(optarg, "dev")==0)
+                               ident.super_minor = -2;
+                       else {
+                               ident.super_minor = strtoul(optarg, &cp, 10);
+                               if (!optarg[0] || *cp) {
+                                       fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg);
+                                       exit(2);
+                               }
                        }
                        continue;
 
+               case O(ASSEMBLE,'U'): /* update the superblock */
+                       if (update) {
+                               fprintf(stderr, Name ": Can only update one aspect of superblock, both %s and %s given.\n",
+                                       update, optarg);
+                               exit(2);
+                       }
+                       update = optarg;
+                       if (strcmp(update, "sparc2.2")==0) continue;
+                       if (strcmp(update, "super-minor") == 0)
+                               continue;
+                       fprintf(stderr, Name ": '--update %s' invalid.  Only 'sparc2.2' or 'super-minor' supported\n",update);
+                       exit(2);
+
                case O(ASSEMBLE,'c'): /* config file */
                case O(MISC, 'c'):
                case O(MONITOR,'c'):
@@ -415,6 +434,9 @@ int main(int argc, char *argv[])
                                }
                        }
                        continue;
+               case O(MONITOR,'f'): /* daemonise */
+                       daemonise = 1;
+                       continue;
                        
 
                        /* now the general management options.  Some are applicable
@@ -489,13 +511,6 @@ int main(int argc, char *argv[])
                        }
                        SparcAdjust = 1;
                        continue;
-               case O(MISC,23):
-                       if (devmode != 'E') {
-                               fprintf(stderr, Name ": --sparc2.2update only allowed with --examine\n");
-                               exit(2);
-                       }
-                       SparcAdjust = 2;
-                       continue;
                }
                /* We have now processed all the valid options. Anything else is
                 * an error
@@ -528,6 +543,11 @@ int main(int argc, char *argv[])
                mdfd = open_mddev(devlist->devname);
                if (mdfd < 0)
                        exit(1);
+               if (ident.super_minor == -2) {
+                       struct stat stb;
+                       fstat(mdfd, &stb);
+                       ident.super_minor = MINOR(stb.st_rdev);
+               }
        }
 
        rv = 0;
@@ -545,11 +565,33 @@ int main(int argc, char *argv[])
                        rv = Manage_runstop(devlist->devname, mdfd, runstop);
                break;
        case ASSEMBLE:
-               if (!scan)
+               if (devs_found == 1 && ident.uuid_set == 0 &&
+                   ident.super_minor == -1 && !scan ) {
+                       /* Only a device has been given, so get details from config file */
+                       mddev_ident_t array_ident = conf_get_ident(configfile, devlist->devname);
+                       mdfd = open_mddev(devlist->devname);
+                       if (mdfd < 0)
+                               rv |= 1;
+                       else {
+                               if (array_ident == NULL) {
+                                       fprintf(stderr, Name ": %s not identified in config file.\n",
+                                               devlist->devname);
+                                       rv |= 1;
+                               }
+                               else 
+                                       rv |= Assemble(devlist->devname, mdfd, array_ident, configfile,
+                                                      NULL,
+                                                      readonly, runstop, update, verbose, force);
+                       }
+               } else if (!scan)
                        rv = Assemble(devlist->devname, mdfd, &ident, configfile,
                                      devlist->next,
-                                     readonly, runstop, verbose, force);
-               else if (devs_found>0)
+                                     readonly, runstop, update, verbose, force);
+               else if (devs_found>0) {
+                       if (update && devs_found > 1) {
+                               fprintf(stderr, Name ": can only update a single array at a time\n");
+                               exit(1);
+                       }
                        for (dv = devlist ; dv ; dv=dv->next) {
                                mddev_ident_t array_ident = conf_get_ident(configfile, dv->devname);
                                mdfd = open_mddev(dv->devname);
@@ -565,9 +607,9 @@ int main(int argc, char *argv[])
                                }
                                rv |= Assemble(dv->devname, mdfd, array_ident, configfile,
                                               NULL,
-                                              readonly, runstop, verbose, force);
+                                              readonly, runstop, update, verbose, force);
                        }
-               else {
+               else {
                        mddev_ident_t array_list =  conf_get_ident(configfile, NULL);
                        if (!array_list) {
                                fprintf(stderr, Name ": No arrays found in config file\n");
@@ -586,7 +628,7 @@ int main(int argc, char *argv[])
                                        rv |= Assemble(array_list->devname, mdfd,
                                                       array_list, configfile,
                                                       NULL,
-                                                      readonly, runstop, verbose, force);
+                                                      readonly, runstop, NULL, verbose, force);
                                }
                }
                break;
@@ -665,14 +707,13 @@ int main(int argc, char *argv[])
                }
                break;
        case MONITOR:
-/*
                if (!devlist && !scan) {
                        fprintf(stderr, Name ": Cannot monitor: need --scan or at least one device\n");
                        rv = 1;
                        break;
                }
-*/             rv= Monitor(devlist, mailaddr, program,
-                           delay?delay:60, scan, configfile);
+               rv= Monitor(devlist, mailaddr, program,
+                           delay?delay:60, daemonise, scan, configfile);
                break;
        }
        exit(rv);