Ignore:
Timestamp:
Sep 29, 2013, 9:31:34 AM (7 years ago)
Author:
Bruno Cornec
Message:
  • Finish with backports from 3.1 for now. Still some work to do, but we will now make that version compile and work again and serve as a base

so the gettext patch can be added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.1/mondo/src/mondorestore/mondo-prep.c

    r3161 r3193  
    4343extern char *MONDO_LOGFILE;
    4444
     45// FIXME: is it really usefull - maps to /tmp/prep.sh ??
    4546FILE *g_fprep = NULL;
    4647extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
     
    108109            sync();
    109110            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.");
    112112            paranoid_system("reboot");
    113113        }
    114114    }
    115 // Still here? Cool!
     115    // Still here? Cool!
    116116    log_msg(1, "Cool. I didn't have to wipe anything.");
    117117}
     
    218218    }
    219219
     220    // TODO: FIXME
    220221    command = malloc(1024);
    221222
     
    390391        }
    391392        mr_asprintf(tmp1, "echo \"%s\" >> /tmp/out.sh", command);
    392         if (system(tmp1)) {
    393             //FIXME
    394         }
     393        paranoid_system(tmp1);
    395394        mr_free(tmp1);
    396395        sleep(1);
     
    515514        }
    516515    }
    517     paranoid_free(incoming);
    518516
    519517    return (0);
     
    539537    char *level   = NULL;
    540538    char *program = NULL;
    541     char *strtmp = NULL;
    542539    char *oldmd = NULL;
    543540
    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;
    633660}
    634661
     
    759786        sync();
    760787        sleep(1);
     788        if (g_fprep) {
     789            fprintf(g_fprep, "%s\n", program);
     790        }
    761791
    762792        log_msg(1, "Making %s", device);
     
    845875    return (retval);
    846876}
    847 
    848 
    849 
    850877
    851878
     
    10061033    if (g_partition_table_locked_up > 0) {
    10071034        if (retval > 0 && !interactively) {
    1008 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
     1035                //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    10091036            log_to_screen("Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up);
    10101037            log_to_screen("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
     
    10151042                sync();
    10161043                sync();
    1017                 if (system("reboot")) {
    1018                     // FIXME
    1019                 }
     1044                paranoid_system("reboot");
    10201045            }
    10211046        } else {
     
    15581583
    15591584    if (pout_to_fdisk) {
    1560         // mark relevant partition as bootable
    1561         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 
    15681585        // close fdisk
     1586        fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    15691587        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    1570         sync();
    15711588        paranoid_pclose(pout_to_fdisk);
    15721589        sync();
    15731590        log_msg(0,"------------------- fdisk.log looks like this ------------------");
    15741591        mr_asprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    1575         if (system(tmp)) {
    1576             // FIXME
    1577         }
     1592        paranoid_system(tmp);
    15781593        mr_free(tmp);
    15791594
    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
    15821602        mr_asprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
    15831603        if (!run_program_and_log_output(tmp, 5)) {
     
    19471967#endif
    19481968    }
    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);
    19501970    mr_free(partition);
    19511971
     
    20092029        }
    20102030    }
    2011 
    20122031    mr_free(partcode);
     2032
    20132033    return (res);
    20142034}
     
    20802100    mr_asprintf(program, "vinum stop -f %s", raid_device);
    20812101#else
    2082         // use raidstop if it exists, otherwise use mdadm
    2083         if (run_program_and_log_output("which raidstop", FALSE)) {
     2102    // use raidstop if it exists, otherwise use mdadm
     2103    if (run_program_and_log_output("which raidstop", FALSE)) {
    20842104        mr_asprintf(program, "mdadm -S %s", raid_device);
    20852105    } else {
     
    22012221 * @return 0 for success, nonzero for failure.
    22022222 */
    2203 char *which_format_command_do_i_need(char *format)
     2223static char *which_format_command_do_i_need(char *format)
    22042224{
    22052225    /** buffers *********************************************************/
     
    22292249    } else if (strcmp(format, "ext4") == 0) {
    22302250        mr_asprintf(program, "mkfs -t ext4 -F -q");
    2231     } else if (strcmp(format, "btrfs") == 0) {
    2232               strcpy(program, "mkfs.btrfs");
    22332251    } else if (strcmp(format, "btrfs") == 0) {
    22342252              strcpy(program, "mkfs.btrfs");
Note: See TracChangeset for help on using the changeset viewer.