]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
Change Incremental and related functions to take struct context
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index 55bfa24dc177a44a3ca2ac598cfa5b33f4b105d0..c979b94e3e5e5a9eb021f4e77ad1b6be14c9152e 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
 #include <ctype.h>
 
 
-static int scan_assemble(int autof, struct supertype *ss,
-                        int readonly, int runstop,
-                        struct mddev_ident *ident,
-                        char *homehost, int require_homehost,
-                        int verbose, int force,
-                        int freeze_reshape);
-static int misc_scan(char devmode, int verbose, int export, int test,
-                    char *homehost, char *prefer);
-static int stop_scan(int quiet);
+static int scan_assemble(struct supertype *ss,
+                        struct context *c,
+                        struct mddev_ident *ident);
+static int misc_scan(char devmode, struct context *c);
+static int stop_scan(int verbose);
 static int misc_list(struct mddev_dev *devlist,
-                    int brief, int verbose, int export, int test,
-                    char *homehost, char *prefer, char *subarray,
-                    char *update, struct mddev_ident *ident,
-                    struct supertype *ss, int force, int quiet);
+                    struct mddev_ident *ident,
+                    struct supertype *ss, struct context *c);
 
 
 int main(int argc, char *argv[])
@@ -148,7 +142,7 @@ int main(int argc, char *argv[])
                case 'v': c.verbose++;
                        continue;
 
-               case 'q': c.quiet++;
+               case 'q': c.verbose--;
                        continue;
 
                case 'b':
@@ -1226,6 +1220,10 @@ int main(int argc, char *argv[])
 
        ident.autof = c.autof;
 
+       if (c.scan && c.verbose < 2)
+               /* --scan implied --brief unless -vv */
+               c.brief = 1;
+
        rv = 0;
        switch(mode) {
        case MANAGE:
@@ -1234,12 +1232,12 @@ int main(int argc, char *argv[])
                        rv = Manage_ro(devlist->devname, mdfd, c.readonly);
                if (!rv && devs_found>1)
                        rv = Manage_subdevs(devlist->devname, mdfd,
-                                           devlist->next, c.verbose-c.quiet, c.test,
+                                           devlist->next, c.verbose, c.test,
                                            c.update, c.force);
                if (!rv && c.readonly < 0)
                        rv = Manage_ro(devlist->devname, mdfd, c.readonly);
                if (!rv && c.runstop)
-                       rv = Manage_runstop(devlist->devname, mdfd, c.runstop, c.quiet);
+                       rv = Manage_runstop(devlist->devname, mdfd, c.runstop, c.verbose, 0);
                break;
        case ASSEMBLE:
                if (devs_found == 1 && ident.uuid_set == 0 &&
@@ -1256,19 +1254,11 @@ int main(int argc, char *argv[])
                                if (array_ident->autof == 0)
                                        array_ident->autof = c.autof;
                                rv |= Assemble(ss, devlist->devname, array_ident,
-                                              NULL, c.backup_file, c.invalid_backup,
-                                              c.readonly, c.runstop, c.update,
-                                              c.homehost, c.require_homehost,
-                                              c.verbose-c.quiet, c.force,
-                                              c.freeze_reshape);
+                                              NULL, &c);
                        }
                } else if (!c.scan)
                        rv = Assemble(ss, devlist->devname, &ident,
-                                     devlist->next, c.backup_file, c.invalid_backup,
-                                     c.readonly, c.runstop, c.update,
-                                     c.homehost, c.require_homehost,
-                                     c.verbose-c.quiet, c.force,
-                                     c.freeze_reshape);
+                                     devlist->next, &c);
                else if (devs_found > 0) {
                        if (c.update && devs_found > 1) {
                                pr_err("can only update a single array at a time\n");
@@ -1289,11 +1279,7 @@ int main(int argc, char *argv[])
                                if (array_ident->autof == 0)
                                        array_ident->autof = c.autof;
                                rv |= Assemble(ss, dv->devname, array_ident,
-                                              NULL, c.backup_file, c.invalid_backup,
-                                              c.readonly, c.runstop, c.update,
-                                              c.homehost, c.require_homehost,
-                                              c.verbose-c.quiet, c.force,
-                                              c.freeze_reshape);
+                                              NULL, &c);
                        }
                } else {
                        if (c.update) {
@@ -1304,11 +1290,7 @@ int main(int argc, char *argv[])
                                pr_err("--backup_file not meaningful with a --scan assembly.\n");
                                exit(1);
                        }
-                       rv = scan_assemble(c.autof, ss, c.readonly, c.runstop,
-                                          &ident, c.homehost,
-                                          c.require_homehost,
-                                          c.verbose - c.quiet,
-                                          c.force, c.freeze_reshape);
+                       rv = scan_assemble(ss, &c, &ident);
                }
 
                break;
@@ -1336,7 +1318,7 @@ int main(int argc, char *argv[])
                rv = Build(devlist->devname, chunk, level, layout,
                           raiddisks, devlist->next, assume_clean,
                           bitmap_file, bitmap_chunk, write_behind,
-                          c.delay, c.verbose-c.quiet, c.autof, size);
+                          &c, size);
                break;
        case CREATE:
                if (c.delay == 0)
@@ -1353,11 +1335,11 @@ int main(int argc, char *argv[])
                }
 
                rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size,
-                           raiddisks, sparedisks, ident.name, c.homehost,
+                           raiddisks, sparedisks, ident.name,
                            ident.uuid_set ? ident.uuid : NULL,
-                           devs_found-1, devlist->next, c.runstop,
-                           c.readonly, c.verbose-c.quiet, c.force, assume_clean,
-                           bitmap_file, bitmap_chunk, write_behind, c.delay, c.autof);
+                           devs_found-1, devlist->next,
+                           assume_clean,
+                           bitmap_file, bitmap_chunk, write_behind, &c);
                break;
        case MISC:
                if (devmode == 'E') {
@@ -1371,19 +1353,14 @@ int main(int argc, char *argv[])
                                pr_err("No devices listed in %s\n", configfile?configfile:DefaultConfFile);
                                exit(1);
                        }
-                       if (c.brief && c.verbose)
-                               c.brief = 2;
-                       rv = Examine(devlist, c.scan?(c.verbose>1?0:c.verbose+1):c.brief,
-                                    c.export, c.scan,
-                                    c.SparcAdjust, ss, c.homehost);
+                       rv = Examine(devlist, &c, ss);
                } else if (devmode == DetailPlatform) {
                        rv = Detail_Platform(ss ? ss->ss : NULL, ss ? c.scan : 1, c.verbose);
                } else if (devlist == NULL) {
                        if (devmode == 'S' && c.scan)
-                               rv = stop_scan(c.quiet);
+                               rv = stop_scan(c.verbose);
                        else if ((devmode == 'D' || devmode == Waitclean) && c.scan)
-                               rv = misc_scan(devmode, c.verbose, c.export,
-                                              c.test, c.homehost, c.prefer);
+                               rv = misc_scan(devmode, &c);
                        else if (devmode == UdevRules)
                                rv = Write_rules(udev_filename);
                        else {
@@ -1391,10 +1368,7 @@ int main(int argc, char *argv[])
                                exit(2);
                        }
                } else
-                       rv = misc_list(devlist, c.brief, c.verbose, c.export, c.test,
-                                      c.homehost, c.prefer, c.subarray, c.update,
-                                      &ident,
-                                      ss, c.force, c.quiet);
+                       rv = misc_list(devlist, &ident, ss, &c);
                break;
        case MONITOR:
                if (!devlist && !c.scan) {
@@ -1414,10 +1388,12 @@ int main(int argc, char *argv[])
                        else
                                c.delay = 60;
                }
+               if (c.delay == 0)
+                       c.delay = 60;
                rv= Monitor(devlist, mailaddr, program,
-                           c.delay?c.delay:60, daemonise, c.scan, oneshot,
-                           dosyslog, c.test, pidfile, increments,
-                           spare_sharing, c.prefer);
+                           &c, daemonise, oneshot,
+                           dosyslog, pidfile, increments,
+                           spare_sharing);
                break;
 
        case GROW:
@@ -1485,7 +1461,7 @@ int main(int argc, char *argv[])
                                                   c.verbose);
                else if (size >= 0 || raiddisks != 0 || layout_str != NULL
                         || chunk != 0 || level != UnSet) {
-                       rv = Grow_reshape(devlist->devname, mdfd, c.quiet, c.backup_file,
+                       rv = Grow_reshape(devlist->devname, mdfd, c.verbose, c.backup_file,
                                          size, level, layout_str, chunk, raiddisks,
                                          devlist->next,
                                          assume_clean, c.force);
@@ -1521,12 +1497,9 @@ int main(int argc, char *argv[])
                }
                if (devmode == 'f')
                        rv = IncrementalRemove(devlist->devname, remove_path,
-                                              c.verbose-c.quiet);
+                                              c.verbose);
                else
-                       rv = Incremental(devlist->devname, c.verbose-c.quiet,
-                                        c.runstop, ss, c.homehost,
-                                        c.require_homehost, c.autof,
-                                        c.freeze_reshape);
+                       rv = Incremental(devlist->devname, &c, ss);
                break;
        case AUTODETECT:
                autodetect();
@@ -1535,12 +1508,9 @@ int main(int argc, char *argv[])
        exit(rv);
 }
 
-static int scan_assemble(int autof, struct supertype *ss,
-                        int readonly, int runstop,
-                        struct mddev_ident *ident,
-                        char *homehost, int require_homehost,
-                        int verbose, int force,
-                        int freeze_reshape)
+static int scan_assemble(struct supertype *ss,
+                        struct context *c,
+                        struct mddev_ident *ident)
 {
        struct mddev_ident *a, *array_list =  conf_get_ident(NULL);
        struct mddev_dev *devlist = conf_get_devs();
@@ -1561,7 +1531,7 @@ static int scan_assemble(int autof, struct supertype *ss,
        for (a = array_list; a ; a = a->next) {
                a->assembled = 0;
                if (a->autof == 0)
-                       a->autof = autof;
+                       a->autof = c->autof;
        }
        if (map_lock(&map))
                pr_err("%s: failed to get "
@@ -1580,12 +1550,7 @@ static int scan_assemble(int autof, struct supertype *ss,
                                continue;
                                
                        r = Assemble(ss, a->devname,
-                                    a,
-                                    NULL, NULL, 0,
-                                    readonly, runstop, NULL,
-                                    homehost, require_homehost,
-                                    verbose, force,
-                                    freeze_reshape);
+                                    a, NULL, c);
                        if (r == 0) {
                                a->assembled = 1;
                                successes++;
@@ -1595,28 +1560,21 @@ static int scan_assemble(int autof, struct supertype *ss,
                        cnt++;
                }
        } while (failures && successes);
-       if (homehost && cnt == 0) {
+       if (c->homehost && cnt == 0) {
                /* Maybe we can auto-assemble something.
                 * Repeatedly call Assemble in auto-assemble mode
                 * until it fails
                 */
                int rv2;
                int acnt;
-               ident->autof = autof;
+               ident->autof = c->autof;
                do {
                        struct mddev_dev *devlist = conf_get_devs();
                        acnt = 0;
                        do {
                                rv2 = Assemble(ss, NULL,
                                               ident,
-                                              devlist, NULL, 0,
-                                              readonly,
-                                              runstop, NULL,
-                                              homehost,
-                                              require_homehost,
-                                              verbose,
-                                              force,
-                                              freeze_reshape);
+                                              devlist, c);
                                if (rv2==0) {
                                        cnt++;
                                        acnt++;
@@ -1637,8 +1595,7 @@ static int scan_assemble(int autof, struct supertype *ss,
        return rv;
 }
 
-static int misc_scan(char devmode, int verbose, int export, int test,
-                    char *homehost, char *prefer)
+static int misc_scan(char devmode, struct context *c)
 {
        /* apply --detail or --wait-clean to
         * all devices in /proc/mdstat
@@ -1647,7 +1604,6 @@ static int misc_scan(char devmode, int verbose, int export, int test,
        struct mdstat_ent *e;
        struct map_ent *map = NULL;
        int members;
-       int v = verbose>1?0:verbose+1;
        int rv = 0;
 
        for (members = 0; members <= 1; members++) {
@@ -1672,11 +1628,9 @@ static int misc_scan(char devmode, int verbose, int export, int test,
                                continue;
                        }
                        if (devmode == 'D')
-                               rv |= Detail(name, v,
-                                            export, test,
-                                            homehost, prefer);
+                               rv |= Detail(name, c);
                        else
-                               rv |= WaitClean(name, -1, v);
+                               rv |= WaitClean(name, -1, c->verbose);
                        put_md_name(name);
                }
        }
@@ -1684,7 +1638,7 @@ static int misc_scan(char devmode, int verbose, int export, int test,
        return rv;
 }
 
-static int stop_scan(int quiet)
+static int stop_scan(int verbose)
 {
        /* apply --stop to all devices in /proc/mdstat */
        /* Due to possible stacking of devices, repeat until
@@ -1710,7 +1664,7 @@ static int stop_scan(int quiet)
                        }
                        mdfd = open_mddev(name, 1);
                        if (mdfd >= 0) {
-                               if (Manage_runstop(name, mdfd, -1, quiet?1:last?0:-1))
+                               if (Manage_runstop(name, mdfd, -1, verbose, !last))
                                        err = 1;
                                else
                                        progress = 1;
@@ -1727,10 +1681,8 @@ static int stop_scan(int quiet)
 }
 
 static int misc_list(struct mddev_dev *devlist,
-                    int brief, int verbose, int export, int test,
-                    char *homehost, char *prefer, char *subarray,
-                    char *update, struct mddev_ident *ident,
-                    struct supertype *ss, int force, int quiet)
+                    struct mddev_ident *ident,
+                    struct supertype *ss, struct context *c)
 {
        struct mddev_dev *dv;
        int rv = 0;
@@ -1740,18 +1692,16 @@ static int misc_list(struct mddev_dev *devlist,
 
                switch(dv->disposition) {
                case 'D':
-                       rv |= Detail(dv->devname,
-                                    brief?1+verbose:0,
-                                    export, test, homehost, prefer);
+                       rv |= Detail(dv->devname, c);
                        continue;
                case KillOpt: /* Zero superblock */
                        if (ss)
-                               rv |= Kill(dv->devname, ss, force, quiet,0);
+                               rv |= Kill(dv->devname, ss, c->force, c->verbose,0);
                        else {
-                               int q = quiet;
+                               int v = c->verbose;
                                do {
-                                       rv |= Kill(dv->devname, NULL, force, q, 0);
-                                       q = 1;
+                                       rv |= Kill(dv->devname, NULL, c->force, v, 0);
+                                       v = -1;
                                } while (rv == 0);
                                rv &= ~2;
                        }
@@ -1759,32 +1709,32 @@ static int misc_list(struct mddev_dev *devlist,
                case 'Q':
                        rv |= Query(dv->devname); continue;
                case 'X':
-                       rv |= ExamineBitmap(dv->devname, brief, ss); continue;
+                       rv |= ExamineBitmap(dv->devname, c->brief, ss); continue;
                case 'W':
                case WaitOpt:
                        rv |= Wait(dv->devname); continue;
                case Waitclean:
-                       rv |= WaitClean(dv->devname, -1, verbose-quiet); continue;
+                       rv |= WaitClean(dv->devname, -1, c->verbose); continue;
                case KillSubarray:
-                       rv |= Kill_subarray(dv->devname, subarray, quiet);
+                       rv |= Kill_subarray(dv->devname, c->subarray, c->verbose);
                        continue;
                case UpdateSubarray:
-                       if (update == NULL) {
+                       if (c->update == NULL) {
                                pr_err("-U/--update must be specified with --update-subarray\n");
                                rv |= 1;
                                continue;
                        }
-                       rv |= Update_subarray(dv->devname, subarray,
-                                             update, ident, quiet);
+                       rv |= Update_subarray(dv->devname, c->subarray,
+                                             c->update, ident, c->verbose);
                        continue;
                }
                mdfd = open_mddev(dv->devname, 1);
                if (mdfd>=0) {
                        switch(dv->disposition) {
                        case 'R':
-                               rv |= Manage_runstop(dv->devname, mdfd, 1, quiet); break;
+                               rv |= Manage_runstop(dv->devname, mdfd, 1, c->verbose, 0); break;
                        case 'S':
-                               rv |= Manage_runstop(dv->devname, mdfd, -1, quiet); break;
+                               rv |= Manage_runstop(dv->devname, mdfd, -1, c->verbose, 0); break;
                        case 'o':
                                rv |= Manage_ro(dv->devname, mdfd, 1); break;
                        case 'w':