Changeset 3193 in MondoRescue for branches/3.1/mondo/src/mondorestore/mondo-prep.c
- Timestamp:
- Sep 29, 2013, 9:31:34 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.1/mondo/src/mondorestore/mondo-prep.c
r3161 r3193 43 43 extern char *MONDO_LOGFILE; 44 44 45 // FIXME: is it really usefull - maps to /tmp/prep.sh ?? 45 46 FILE *g_fprep = NULL; 46 47 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored … … 108 109 sync(); 109 110 sync(); 110 popup_and_OK 111 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 111 popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 112 112 paranoid_system("reboot"); 113 113 } 114 114 } 115 // Still here? Cool!115 // Still here? Cool! 116 116 log_msg(1, "Cool. I didn't have to wipe anything."); 117 117 } … … 218 218 } 219 219 220 // TODO: FIXME 220 221 command = malloc(1024); 221 222 … … 390 391 } 391 392 mr_asprintf(tmp1, "echo \"%s\" >> /tmp/out.sh", command); 392 if (system(tmp1)) { 393 //FIXME 394 } 393 paranoid_system(tmp1); 395 394 mr_free(tmp1); 396 395 sleep(1); … … 515 514 } 516 515 } 517 paranoid_free(incoming);518 516 519 517 return (0); … … 539 537 char *level = NULL; 540 538 char *program = NULL; 541 char *strtmp = NULL;542 539 char *oldmd = NULL; 543 540 544 // leave straight away if raidlist is initial or has no entries 545 if (!raidlist || raidlist->entries == 0) { 546 log_msg(1, "No RAID arrays found."); 547 return 1; 548 } else { 549 log_msg(1, "%d RAID arrays found.", raidlist->entries); 550 } 551 // find raidlist entry for requested device 552 for (i = 0; i < raidlist->entries; i++) { 553 if (!strcmp(raidlist->el[i].raid_device, device)) break; 554 } 555 // check whether RAID device was found in raidlist 556 if (i == raidlist->entries) { 557 log_msg(1, "RAID device %s not found in list.", device); 558 return 1; 559 } 560 // create device list from normal disks followed by spare ones 561 mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device); 562 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 563 mr_asprintf(strtmp, "%s", devices); 564 mr_free(devices); 565 mr_asprintf(devices, "%s %s", strtmp, raidlist->el[i].data_disks.el[j].device); 566 mr_free(strtmp); 567 } 568 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 569 mr_asprintf(strtmp, "%s", devices); 570 mr_free(devices); 571 mr_asprintf(devices, "%s %s", strtmp, raidlist->el[i].spare_disks.el[j].device); 572 mr_free(strtmp); 573 } 574 // translate RAID level 575 if (raidlist->el[i].raid_level == -2) { 576 mr_asprintf(level, "multipath"); 577 } else if (raidlist->el[i].raid_level == -1) { 578 mr_asprintf(level, "linear"); 579 } else { 580 mr_asprintf(level, "raid%d", raidlist->el[i].raid_level); 581 } 582 // create RAID device: 583 // - RAID device, number of devices and devices mandatory 584 // - parity algorithm, chunk size and spare devices optional 585 // - faulty devices ignored 586 // - persistent superblock always used as this is recommended 587 588 mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d %s", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries, oldmd); 589 mr_free(oldmd); 590 if (raidlist->el[i].parity != -1) { 591 mr_asprintf(strtmp, "%s", program); 592 mr_free(program); 593 switch(raidlist->el[i].parity) { 594 case 0: 595 mr_asprintf(program, "%s --parity=%s", strtmp, "la"); 596 break; 597 case 1: 598 mr_asprintf(program, "%s --parity=%s", strtmp, "ra"); 599 break; 600 case 2: 601 mr_asprintf(program, "%s --parity=%s", strtmp, "ls"); 602 break; 603 case 3: 604 mr_asprintf(program, "%s --parity=%s", strtmp, "rs"); 605 break; 606 default: 607 fatal_error("Unknown RAID parity algorithm."); 608 break; 609 } 610 mr_free(strtmp); 611 } 612 if (raidlist->el[i].chunk_size != -1) { 613 mr_asprintf(strtmp, "%s", program); 614 mr_free(program); 615 mr_asprintf(program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 616 mr_free(strtmp); 617 } 618 if (raidlist->el[i].spare_disks.entries > 0) { 619 mr_asprintf(strtmp, "%s", program); 620 mr_free(program); 621 mr_asprintf(program, "%s --spare-devices=%d", strtmp, raidlist->el[i].spare_disks.entries); 622 mr_free(strtmp); 623 } 624 mr_asprintf(strtmp, "%s", program); 625 mr_free(program); 626 mr_asprintf(program, "%s %s", strtmp, devices); 627 mr_free(strtmp); 628 res = run_program_and_log_output(program, 1); 629 mr_free(devices); 630 mr_free(level); 631 mr_free(program); 632 return res; 541 // leave straight away if raidlist is initial or has no entries 542 if (!raidlist || raidlist->entries == 0) { 543 log_msg(1, "No RAID arrays found."); 544 return 1; 545 } else { 546 log_msg(1, "%d RAID arrays found.", raidlist->entries); 547 } 548 // find raidlist entry for requested device 549 for (i = 0; i < raidlist->entries; i++) { 550 if (!strcmp(raidlist->el[i].raid_device, device)) break; 551 } 552 // check whether RAID device was found in raidlist 553 if (i == raidlist->entries) { 554 log_msg(1, "RAID device %s not found in list.", device); 555 return 1; 556 } else { 557 log_msg(1, "RAID device %s found in list (%d).", device, i); 558 } 559 560 // create device list from normal disks followed by spare ones 561 if (raidlist->el[i].data_disks.el[0].device != NULL) { 562 mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device); 563 log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[0].device); 564 } else { 565 log_msg(1, "Strange, there are entries but no device"); 566 } 567 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 568 mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device); 569 log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[j].device); 570 } 571 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 572 mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device); 573 log_msg(4, "Adding spare device %s to list", raidlist->el[i].spare_disks.el[j].device); 574 } 575 log_msg(4, "RAID devices: %s", devices); 576 // translate RAID level 577 if (raidlist->el[i].raid_level == -2) { 578 mr_asprintf(level, "multipath"); 579 } else if (raidlist->el[i].raid_level == -1) { 580 mr_asprintf(level, "linear"); 581 } else { 582 mr_asprintf(level, "raid%d", raidlist->el[i].raid_level); 583 } 584 // create RAID device: 585 // - RAID device, number of devices and devices mandatory 586 // - parity algorithm, chunk size and spare devices optional 587 // - faulty devices ignored 588 // - persistent superblock always used as this is recommended 589 590 mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries); 591 mr_free(level); 592 log_msg(4, "cmd built: %s", program); 593 // Restoring the UUID and Version stored at backup time of present 594 for (v = 0; v < raidlist->el[i].additional_vars.entries ; v++ ) { 595 log_msg(4,"Working on additional param #%d (Label: %s)",v,raidlist->el[i].additional_vars.el[v].label); 596 if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"UUID") == 0)) { 597 // We have a UUID to handle 598 if (raidlist->el[i].additional_vars.el[v].value != NULL) { 599 // force its restoration in order to avoid modifying all conf files using it 600 log_it("Managing previous UUID %s", raidlist->el[i].additional_vars.el[v].value); 601 mr_strcat(program, " --uuid %s",raidlist->el[i].additional_vars.el[v].value); 602 continue; 603 } else { 604 log_msg(1,"Unable to manage previous NULL UUID"); 605 } 606 } 607 if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"Version") == 0)) { 608 // We have a Version to handle 609 if (raidlist->el[i].additional_vars.el[v].value != NULL) { 610 // force its restoration in order to support all complex boot loader + md format cases 611 // Also see bug #473 612 log_it("Managing previous Version %s", raidlist->el[i].additional_vars.el[v].value); 613 mr_strcat(program, " -e %s",raidlist->el[i].additional_vars.el[v].value); 614 continue; 615 } else { 616 log_msg(1,"Unable to manage previous NULL Version"); 617 } 618 } 619 } 620 log_msg(4, "cmd built: %s", program); 621 if (raidlist->el[i].parity != -1) { 622 switch(raidlist->el[i].parity) { 623 case 0: 624 mr_strcat(program, " --parity=%s", "la"); 625 break; 626 case 1: 627 mr_strcat(program, " --parity=%s", "ra"); 628 break; 629 case 2: 630 mr_strcat(program, " --parity=%s", "ls"); 631 break; 632 case 3: 633 mr_strcat(program, " --parity=%s", "rs"); 634 break; 635 default: 636 fatal_error("Unknown RAID parity algorithm."); 637 break; 638 } 639 } 640 log_msg(4, "cmd built: %s", program); 641 if (raidlist->el[i].chunk_size != -1) { 642 mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size); 643 } 644 if (raidlist->el[i].spare_disks.entries > 0) { 645 mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries); 646 } 647 log_msg(4, "cmd built: %s", program); 648 mr_strcat(program, " %s", devices); 649 log_msg(2, "RAID device re-created with the following command:\n%s\n", program); 650 if (test == TRUE) { 651 res = run_program_and_log_output(program, 1); 652 } else { 653 // test mode, always returns TRUE without executing the mdadm command 654 res = TRUE; 655 } 656 // free memory 657 mr_free(devices); 658 mr_free(program); 659 return res; 633 660 } 634 661 … … 759 786 sync(); 760 787 sleep(1); 788 if (g_fprep) { 789 fprintf(g_fprep, "%s\n", program); 790 } 761 791 762 792 log_msg(1, "Making %s", device); … … 845 875 return (retval); 846 876 } 847 848 849 850 877 851 878 … … 1006 1033 if (g_partition_table_locked_up > 0) { 1007 1034 if (retval > 0 && !interactively) { 1008 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567891035 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1009 1036 log_to_screen("Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up); 1010 1037 log_to_screen("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); … … 1015 1042 sync(); 1016 1043 sync(); 1017 if (system("reboot")) { 1018 // FIXME 1019 } 1044 paranoid_system("reboot"); 1020 1045 } 1021 1046 } else { … … 1558 1583 1559 1584 if (pout_to_fdisk) { 1560 // mark relevant partition as bootable1561 tmp1 = call_program_and_get_last_line_of_output ("make-me-bootable "MINDI_CACHE"/mountlist.txt dummy",TRUE);1562 mr_asprintf(tmp, "a\n%s\n", tmp1);1563 mr_free(tmp1);1564 1565 fput_string_one_char_at_a_time(pout_to_fdisk, tmp);1566 mr_free(tmp);1567 1568 1585 // close fdisk 1586 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 1569 1587 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1570 sync();1571 1588 paranoid_pclose(pout_to_fdisk); 1572 1589 sync(); 1573 1590 log_msg(0,"------------------- fdisk.log looks like this ------------------"); 1574 1591 mr_asprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1575 if (system(tmp)) { 1576 // FIXME 1577 } 1592 paranoid_system(tmp); 1578 1593 mr_free(tmp); 1579 1594 1580 log_msg(0, 1581 "------------------- end of fdisk.log... word! ------------------"); 1595 // mark relevant partition as bootable 1596 mr_asprintf(tmp1,"make-me-bootable /tmp/mountlist.txt %s",drivename); 1597 call_program_and_get_last_line_of_output(tmp1); 1598 mr_free(tmp1); 1599 log_msg(0,"------------------- end of fdisk.log... ------------------"); 1600 sync(); 1601 1582 1602 mr_asprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG); 1583 1603 if (!run_program_and_log_output(tmp, 5)) { … … 1947 1967 #endif 1948 1968 } 1949 log_msg(1, tmp,"Setting %s's type to %s (%s)", partition, format, partcode);1969 log_msg(1, "Setting %s's type to %s (%s)", partition, format, partcode); 1950 1970 mr_free(partition); 1951 1971 … … 2009 2029 } 2010 2030 } 2011 2012 2031 mr_free(partcode); 2032 2013 2033 return (res); 2014 2034 } … … 2080 2100 mr_asprintf(program, "vinum stop -f %s", raid_device); 2081 2101 #else 2082 2083 2102 // use raidstop if it exists, otherwise use mdadm 2103 if (run_program_and_log_output("which raidstop", FALSE)) { 2084 2104 mr_asprintf(program, "mdadm -S %s", raid_device); 2085 2105 } else { … … 2201 2221 * @return 0 for success, nonzero for failure. 2202 2222 */ 2203 char *which_format_command_do_i_need(char *format)2223 static char *which_format_command_do_i_need(char *format) 2204 2224 { 2205 2225 /** buffers *********************************************************/ … … 2229 2249 } else if (strcmp(format, "ext4") == 0) { 2230 2250 mr_asprintf(program, "mkfs -t ext4 -F -q"); 2231 } else if (strcmp(format, "btrfs") == 0) {2232 strcpy(program, "mkfs.btrfs");2233 2251 } else if (strcmp(format, "btrfs") == 0) { 2234 2252 strcpy(program, "mkfs.btrfs");
Note:
See TracChangeset
for help on using the changeset viewer.