]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
recreate journal in mdadm
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index 2ab006ab6bc1ac786f5f15dc6cc7f18f5e291470..feec3b70e4c9d0c65d946816d4c59572189dbc34 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -74,6 +74,7 @@ int main(int argc, char *argv[])
                .require_homehost = 1,
        };
        struct shape s = {
+               .journaldisks   = 0,
                .level          = UnSet,
                .layout         = UnSet,
                .bitmap_chunk   = UnSet,
@@ -189,6 +190,7 @@ int main(int argc, char *argv[])
                case 'a':
                case Add:
                case AddSpare:
+               case AddJournal:
                case 'r':
                case Remove:
                case Replace:
@@ -196,6 +198,7 @@ int main(int argc, char *argv[])
                case 'f':
                case Fail:
                case ReAdd: /* re-add */
+               case ClusterConfirm:
                        if (!mode) {
                                newmode = MANAGE;
                                shortopt = short_bitmap_options;
@@ -588,6 +591,7 @@ int main(int argc, char *argv[])
                        }
                        ident.raid_disks = s.raiddisks;
                        continue;
+               case O(ASSEMBLE, Nodes):
                case O(CREATE, Nodes):
                        c.nodes = parse_num(optarg);
                        if (c.nodes <= 0) {
@@ -596,6 +600,14 @@ int main(int argc, char *argv[])
                                exit(2);
                        }
                        continue;
+               case O(CREATE, ClusterName):
+               case O(ASSEMBLE, ClusterName):
+                       c.homecluster = optarg;
+                       if (strlen(c.homecluster) > 64) {
+                               pr_err("Cluster name too big.\n");
+                               exit(ERANGE);
+                       }
+                       continue;
                case O(CREATE,'x'): /* number of spare (eXtra) disks */
                        if (s.sparedisks) {
                                pr_err("spare-devices set twice: %d and %s\n",
@@ -733,6 +745,10 @@ int main(int argc, char *argv[])
                                continue;
                        if (strcmp(c.update, "homehost")==0)
                                continue;
+                       if (strcmp(c.update, "home-cluster")==0)
+                               continue;
+                       if (strcmp(c.update, "nodes")==0)
+                               continue;
                        if (strcmp(c.update, "devicesize")==0)
                                continue;
                        if (strcmp(c.update, "no-bitmap")==0)
@@ -771,8 +787,8 @@ int main(int argc, char *argv[])
                                        Name, c.update);
                        }
                        fprintf(outf, "Valid --update options are:\n"
-               "     'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
-               "     'summaries', 'homehost', 'byteorder', 'devicesize',\n"
+               "     'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n"
+               "     'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
                "     'no-bitmap', 'metadata', 'revert-reshape'\n"
                "     'bbl', 'no-bbl'\n"
                                );
@@ -910,6 +926,13 @@ int main(int argc, char *argv[])
                case O(MANAGE,AddSpare): /* add drive - never re-add */
                        devmode = 'S';
                        continue;
+               case O(MANAGE,AddJournal): /* add journal */
+                       if (s.journaldisks && (s.level < 4 || s.level > 6)) {
+                               pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
+                               exit(2);
+                       }
+                       devmode = 'j';
+                       continue;
                case O(MANAGE,ReAdd):
                        devmode = 'A';
                        continue;
@@ -926,6 +949,9 @@ int main(int argc, char *argv[])
                                           * remove the device */
                        devmode = 'f';
                        continue;
+               case O(MANAGE, ClusterConfirm):
+                       devmode = 'c';
+                       continue;
                case O(MANAGE,Replace):
                        /* Mark these devices for replacement */
                        devmode = 'R';
@@ -1153,6 +1179,23 @@ int main(int argc, char *argv[])
                case O(INCREMENTAL, IncrementalPath):
                        remove_path = optarg;
                        continue;
+               case O(CREATE, WriteJournal):
+                       if (s.journaldisks) {
+                               pr_err("Please specify only one journal device for the array.\n");
+                               pr_err("Ignoring --write-journal %s...\n", optarg);
+                               continue;
+                       }
+                       dv = xmalloc(sizeof(*dv));
+                       dv->devname = optarg;
+                       dv->disposition = 'j';  /* WriteJournal */
+                       dv->used = 0;
+                       dv->next = NULL;
+                       *devlistend = dv;
+                       devlistend = &dv->next;
+                       devs_found++;
+
+                       s.journaldisks = 1;
+                       continue;
                }
                /* We have now processed all the valid options. Anything else is
                 * an error
@@ -1180,6 +1223,11 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
+       if (s.journaldisks && (s.level < 4 || s.level > 6)) {
+               pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
+               exit(2);
+       }
+
        if (!mode && devs_found) {
                mode = MISC;
                devmode = 'Q';
@@ -1263,7 +1311,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (c.homehost == NULL)
+       if (c.homehost == NULL && c.require_homehost)
                c.homehost = conf_get_homehost(&c.require_homehost);
        if (c.homehost == NULL || strcasecmp(c.homehost, "<system>")==0) {
                if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
@@ -1276,6 +1324,20 @@ int main(int argc, char *argv[])
                c.require_homehost = 0;
        }
 
+       rv = 0;
+
+       set_hooks(); /* set hooks from libs */
+
+       if (c.homecluster == NULL && (c.nodes > 0)) {
+               c.homecluster = conf_get_homecluster();
+               if (c.homecluster == NULL)
+                       rv = get_cluster_name(&c.homecluster);
+               if (rv) {
+                       pr_err("The md can't get cluster name\n");
+                       exit(1);
+               }
+       }
+
        if (c.backup_file && data_offset != INVALID_SECTORS) {
                pr_err("--backup-file and --data-offset are incompatible\n");
                exit(2);
@@ -1295,7 +1357,6 @@ int main(int argc, char *argv[])
                /* --scan implied --brief unless -vv */
                c.brief = 1;
 
-       rv = 0;
        switch(mode) {
        case MANAGE:
                /* readonly, add/remove, readwrite, runstop */
@@ -1382,8 +1443,9 @@ int main(int argc, char *argv[])
                }
 
                if (s.bitmap_file) {
-                       if (strcmp(s.bitmap_file, "internal")==0) {
-                               pr_err("'internal' bitmaps not supported with --build\n");
+                       if (strcmp(s.bitmap_file, "internal")==0 ||
+                           strcmp(s.bitmap_file, "clustered") == 0) {
+                               pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
                                rv |= 1;
                                break;
                        }
@@ -1473,8 +1535,6 @@ int main(int argc, char *argv[])
                        else
                                c.delay = 60;
                }
-               if (c.delay == 0)
-                       c.delay = 60;
                rv= Monitor(devlist, mailaddr, program,
                            &c, daemonise, oneshot,
                            dosyslog, pidfile, increments,
@@ -1706,7 +1766,7 @@ static int misc_scan(char devmode, struct context *c)
 
                        if (!name) {
                                pr_err("cannot find device file for %s\n",
-                                       e->dev);
+                                       e->devnm);
                                continue;
                        }
                        if (devmode == 'D')
@@ -1741,7 +1801,7 @@ static int stop_scan(int verbose)
 
                        if (!name) {
                                pr_err("cannot find device file for %s\n",
-                                       e->dev);
+                                       e->devnm);
                                continue;
                        }
                        mdfd = open_mddev(name, 1);