Changeset 2990


Ignore:
Timestamp:
Apr 5, 2012, 12:55:31 AM (7 years ago)
Author:
bruno
Message:
  • Improve test environment to debug #473 and #500, in link with #595 and #596 in order to have a working md support with UUIDs and metadata versions
  • create_raid_device_via_mdadm now has a thid test parameter to support that
Location:
branches/3.0/mondo
Files:
3 added
2 edited

Legend:

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

    r2989 r2990  
    178178
    179179int do_my_funky_lvm_stuff(bool just_erase_existing_volumes,
    180                           bool vacuum_pack)
     180                            bool vacuum_pack)
    181181{
    182     /**  buffers **********************************************/
     182    /** buffers **********************************************/
    183183    char *tmp;
    184184    char *tmp1 = NULL;
     
    192192    char *vgchange_sz;
    193193    char *vgremove_sz;
    194 //  char *do_this_last;
     194//  char *do_this_last;
    195195
    196196    /** char **************************************************/
     
    232232    malloc_string(vgchange_sz);
    233233    malloc_string(vgremove_sz);
    234 //  malloc_string(do_this_last); // postpone lvcreate call if necessary
     234//  malloc_string(do_this_last); // postpone lvcreate call if necessary
    235235    command = malloc(512);
    236236
    237 //  do_this_last[0] = '\0';
     237//  do_this_last[0] = '\0';
    238238    log_it("STARTING");
    239239    log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes...");
     
    303303            *q = '\0';
    304304            log_msg(1, "Deleting old entries at /dev/%s", tmp);
    305 //             sprintf(command, "%s -f %s", vgremove_sz, tmp);
    306 //             run_program_and_log_output(command, 1);
     305//             sprintf(command, "%s -f %s", vgremove_sz, tmp);
     306//             run_program_and_log_output(command, 1);
    307307            sprintf(command, "rm -Rf /dev/%s", tmp);
    308308            run_program_and_log_output(command, 1);
     
    398398    paranoid_fclose(fin);
    399399    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
    400   end_of_i_want_my_lvm:
     400    end_of_i_want_my_lvm:
    401401    paranoid_free(tmp);
    402402    paranoid_free(incoming);
     
    409409    paranoid_free(vgchange_sz);
    410410    paranoid_free(vgremove_sz);
    411 //  paranoid_free(do_this_last);
     411//  paranoid_free(do_this_last);
    412412    system("sync");
    413413    system("sync");
     
    504504                        if (j >= new_mountlist->entries) {
    505505                            strcpy(new_mountlist->
    506                                   el[new_mountlist->entries].device, p);
     506                                    el[new_mountlist->entries].device, p);
    507507                            strcpy(new_mountlist->
    508                                   el[new_mountlist->entries].mountpoint,
    509                                   "raid");
     508                                    el[new_mountlist->entries].mountpoint,
     509                                    "raid");
    510510                            strcpy(new_mountlist->
    511                                   el[new_mountlist->entries].format,
    512                                   "raid");
     511                                    el[new_mountlist->entries].format,
     512                                    "raid");
    513513                            new_mountlist->el[new_mountlist->entries].
    514514                                size = old_mountlist->el[lino].size;
     
    526526        } else {
    527527            strcpy(new_mountlist->el[new_mountlist->entries].device,
    528                   old_mountlist->el[lino].device);
     528                    old_mountlist->el[lino].device);
    529529            strcpy(new_mountlist->el[new_mountlist->entries].mountpoint,
    530                   old_mountlist->el[lino].mountpoint);
     530                    old_mountlist->el[lino].mountpoint);
    531531            strcpy(new_mountlist->el[new_mountlist->entries].format,
    532                   old_mountlist->el[lino].format);
     532                    old_mountlist->el[lino].format);
    533533            new_mountlist->el[new_mountlist->entries].size =
    534534                old_mountlist->el[lino].size;
     
    551551 * @return 0 for success, nonzero for failure.
    552552 */
    553 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device)
    554 {
    555   /** int **************************************************************/
    556   int i   = 0;
    557   int j   = 0;
    558   int v   = 0;
    559   int res = 0;
    560  
    561   /** buffers ***********************************************************/
    562   char *devices = NULL;
    563   char *level   = NULL;
    564   char *program = NULL;
    565   char *tmp = NULL;
    566   char *tmp1 = NULL;
    567 
    568   // leave straight away if raidlist is initial or has no entries
    569   if (!raidlist || raidlist->entries == 0) {
    570     log_msg(1, "No RAID arrays found.");
    571     return 1;
    572   } else {
    573     log_msg(1, "%d RAID arrays found.", raidlist->entries);
    574   }
    575   // find raidlist entry for requested device
    576   for (i = 0; i < raidlist->entries; i++) {
    577     if (!strcmp(raidlist->el[i].raid_device, device)) break;
    578   }
    579   // check whether RAID device was found in raidlist
    580   if (i == raidlist->entries) {
    581     log_msg(1, "RAID device %s not found in list.", device);
    582     return 1;
    583   } else {
    584     log_msg(1, "RAID device %s found in list (%d).", device, i);
    585   }
    586 
    587   // create device list from normal disks followed by spare ones
    588   if (raidlist->el[i].data_disks.el[0].device != NULL) {
     553int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device, bool test) {
     554    /** int **************************************************************/
     555    int i   = 0;
     556    int j   = 0;
     557    int v   = 0;
     558    int res = 0;
     559   
     560    /** buffers ***********************************************************/
     561    char *devices = NULL;
     562    char *level   = NULL;
     563    char *program = NULL;
     564    char *tmp = NULL;
     565    char *tmp1 = NULL;
     566
     567    // leave straight away if raidlist is initial or has no entries
     568    if (!raidlist || raidlist->entries == 0) {
     569      log_msg(1, "No RAID arrays found.");
     570      return 1;
     571    } else {
     572      log_msg(1, "%d RAID arrays found.", raidlist->entries);
     573    }
     574    // find raidlist entry for requested device
     575    for (i = 0; i < raidlist->entries; i++) {
     576      if (!strcmp(raidlist->el[i].raid_device, device)) break;
     577    }
     578    // check whether RAID device was found in raidlist
     579    if (i == raidlist->entries) {
     580      log_msg(1, "RAID device %s not found in list.", device);
     581      return 1;
     582    } else {
     583      log_msg(1, "RAID device %s found in list (%d).", device, i);
     584    }
     585
     586    // create device list from normal disks followed by spare ones
     587    if (raidlist->el[i].data_disks.el[0].device != NULL) {
    589588    mr_asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);
    590         log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[0].device);
    591   } else {
    592     log_msg(1, "Strange, there are entries but no device");
    593   }
    594   for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    595     mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device);
    596     log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[j].device);
    597   }
    598   for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    599     mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device);
    600     log_msg(4, "Adding spare device %s to list", raidlist->el[i].spare_disks.el[j].device);
    601   }
    602     log_msg(4, "RAID devices: %s", devices);
    603   // translate RAID level
    604   if (raidlist->el[i].raid_level == -2) {
    605     mr_asprintf(&level, "multipath");
    606   } else if (raidlist->el[i].raid_level == -1) {
    607     mr_asprintf(&level, "linear");
    608   } else {
    609     mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
    610   }
    611   // create RAID device:
    612   // - RAID device, number of devices and devices mandatory
    613   // - parity algorithm, chunk size and spare devices optional
    614   // - faulty devices ignored
    615   // - persistent superblock always used as this is recommended
    616 
    617   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);
    618   mr_free(level);
    619         log_msg(4, "cmd built: %s", program);
    620   // Restoring the UUID and Version stored at backup time of present
    621   for (v = 0; v < raidlist->el[i].additional_vars.entries ; v++ ) {
    622       log_msg(4,"Working on additional param #%d (Label: %s)",v,raidlist->el[i].additional_vars.el[v].label);
    623     if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"UUID") == 0)) {
    624         // We have a UUID to handle
    625         if (raidlist->el[i].additional_vars.el[v].value != NULL) {
    626             // force its restoration in order to avoid modifying all conf files using it
    627             log_it("Managing previous UUID %s", raidlist->el[i].additional_vars.el[v].value);
    628             mr_strcat(program, " --uuid %s",raidlist->el[i].additional_vars.el[v].value);
    629             break;
    630         } else {
    631             log_msg(1,"Unable to manage previous NULL UUID");
    632         }
    633     }
    634     if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"Version") == 0)) {
    635         // We have a Version to handle
    636         if (raidlist->el[i].additional_vars.el[v].value != NULL) {
    637             // force its restoration in order to support all complex boot loader + md format cases
    638             // Also see bug #473
    639             log_it("Managing previous Version %s", raidlist->el[i].additional_vars.el[v].value);
    640             mr_strcat(program, " -e %s",raidlist->el[i].additional_vars.el[v].value);
    641             break;
    642         } else {
    643             log_msg(1,"Unable to manage previous NULL Version");
    644         }
    645     }
    646   }
    647         log_msg(4, "cmd built: %s", program);
    648   if (raidlist->el[i].parity != -1) {
    649     switch(raidlist->el[i].parity) {
    650     case 0:
    651       mr_strcat(program, " --parity=%s", "la");
    652       break;
    653     case 1:
    654       mr_strcat(program, " --parity=%s", "ra");
    655       break;
    656     case 2:
    657       mr_strcat(program, " --parity=%s", "ls");
    658       break;
    659     case 3:
    660       mr_strcat(program, " --parity=%s", "rs");
    661       break;
    662     default:
    663       fatal_error("Unknown RAID parity algorithm.");
    664       break;
    665     }
    666   }
    667         log_msg(4, "cmd built: %s", program);
    668   if (raidlist->el[i].chunk_size != -1) {
    669     mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size);
    670   }
    671   if (raidlist->el[i].spare_disks.entries > 0) {
    672     mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries);
    673   }
    674         log_msg(4, "cmd built: %s", program);
    675   mr_strcat(program, " %s", devices);
    676     log_msg(2, "RAID device re-created with the following command:\n%s\n", program);
    677   res = run_program_and_log_output(program, 1);
    678   // free memory
    679   mr_free(devices);
    680   mr_free(program);
    681   // return to calling instance
    682   return res;
     589        log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[0].device);
     590    } else {
     591        log_msg(1, "Strange, there are entries but no device");
     592    }
     593    for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
     594      mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device);
     595      log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[j].device);
     596    }
     597    for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
     598      mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device);
     599      log_msg(4, "Adding spare device %s to list", raidlist->el[i].spare_disks.el[j].device);
     600    }
     601    log_msg(4, "RAID devices: %s", devices);
     602    // translate RAID level
     603    if (raidlist->el[i].raid_level == -2) {
     604      mr_asprintf(&level, "multipath");
     605    } else if (raidlist->el[i].raid_level == -1) {
     606      mr_asprintf(&level, "linear");
     607    } else {
     608      mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     609    }
     610    // create RAID device:
     611    // - RAID device, number of devices and devices mandatory
     612    // - parity algorithm, chunk size and spare devices optional
     613    // - faulty devices ignored
     614    // - persistent superblock always used as this is recommended
     615
     616    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);
     617    mr_free(level);
     618    log_msg(4, "cmd built: %s", program);
     619    // Restoring the UUID and Version stored at backup time of present
     620    for (v = 0; v < raidlist->el[i].additional_vars.entries ; v++ ) {
     621        log_msg(4,"Working on additional param #%d (Label: %s)",v,raidlist->el[i].additional_vars.el[v].label);
     622        if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"UUID") == 0)) {
     623            // We have a UUID to handle
     624            if (raidlist->el[i].additional_vars.el[v].value != NULL) {
     625                // force its restoration in order to avoid modifying all conf files using it
     626                log_it("Managing previous UUID %s", raidlist->el[i].additional_vars.el[v].value);
     627                mr_strcat(program, " --uuid %s",raidlist->el[i].additional_vars.el[v].value);
     628                break;
     629            } else {
     630                log_msg(1,"Unable to manage previous NULL UUID");
     631            }
     632        }
     633        if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"Version") == 0)) {
     634            // We have a Version to handle
     635            if (raidlist->el[i].additional_vars.el[v].value != NULL) {
     636                // force its restoration in order to support all complex boot loader + md format cases
     637                // Also see bug #473
     638                log_it("Managing previous Version %s", raidlist->el[i].additional_vars.el[v].value);
     639                mr_strcat(program, " -e %s",raidlist->el[i].additional_vars.el[v].value);
     640                break;
     641            } else {
     642                log_msg(1,"Unable to manage previous NULL Version");
     643            }
     644        }
     645    }
     646        log_msg(4, "cmd built: %s", program);
     647    if (raidlist->el[i].parity != -1) {
     648      switch(raidlist->el[i].parity) {
     649      case 0:
     650        mr_strcat(program, " --parity=%s", "la");
     651        break;
     652      case 1:
     653        mr_strcat(program, " --parity=%s", "ra");
     654        break;
     655      case 2:
     656        mr_strcat(program, " --parity=%s", "ls");
     657        break;
     658      case 3:
     659        mr_strcat(program, " --parity=%s", "rs");
     660        break;
     661      default:
     662        fatal_error("Unknown RAID parity algorithm.");
     663        break;
     664      }
     665    }
     666    log_msg(4, "cmd built: %s", program);
     667    if (raidlist->el[i].chunk_size != -1) {
     668        mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size);
     669    }
     670    if (raidlist->el[i].spare_disks.entries > 0) {
     671        mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries);
     672    }
     673    log_msg(4, "cmd built: %s", program);
     674    mr_strcat(program, " %s", devices);
     675    log_msg(2, "RAID device re-created with the following command:\n%s\n", program);
     676    if (test == TRUE) {
     677        res = run_program_and_log_output(program, 1);
     678    } else {
     679        // test mode, always returns TRUE without executing the mdadm command
     680        res = TRUE;
     681    }
     682    // free memory
     683    mr_free(devices);
     684    mr_free(program);
     685    // return to calling instance
     686    return res;
    683687}
    684688
     
    736740    }
    737741    if (is_this_device_mounted(device)) {
    738         mr_asprintf(&tmp, "%s is mounted - cannot format it       ", device);
     742        mr_asprintf(&tmp, "%s is mounted - cannot format it      ", device);
    739743        log_to_screen(tmp);
    740744        paranoid_free(tmp);
     
    772776
    773777            /* format raid partition */
    774             //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
     778            //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
    775779            sprintf(program,
    776780                    "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
     
    829833        log_msg(1, "Making %s", device);
    830834        // use mkraid if it exists, otherwise use mdadm
    831         if (run_program_and_log_output("which mkraid", FALSE)) {
    832             res = create_raid_device_via_mdadm(raidlist, device);
    833             log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
     835            if (run_program_and_log_output("which mkraid", FALSE)) {
     836                res = create_raid_device_via_mdadm(raidlist, device, TRUE);
     837                log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
    834838        } else {
    835839            sprintf(program, "mkraid --really-force %s", device);
     
    845849        system("sync");
    846850        sleep(2);
    847 //      log_to_screen("Starting %s", device);
    848 //      sprintf(program, "raidstart %s", device);
    849 //      res = run_program_and_log_output(program, 1);
    850 //      log_msg(1, "%s returned %d", program, res);
    851 //      system("sync"); sleep(1);
     851//      log_to_screen("Starting %s", device);
     852//      sprintf(program, "raidstart %s", device);
     853//      res = run_program_and_log_output(program, 1);
     854//      log_msg(1, "%s returned %d", program, res);
     855//      system("sync"); sleep(1);
    852856#endif
    853857        system("sync");
     
    931935 */
    932936int format_everything(struct mountlist_itself *mountlist, bool interactively,
    933                           struct raidlist_itself *raidlist)
     937                            struct raidlist_itself *raidlist)
    934938{
    935939    /** int **************************************************************/
     
    937941    int lino;
    938942    int res;
    939 //  int i;
    940 //  struct list_of_disks *drivelist;
     943//  int i;
     944//  struct list_of_disks *drivelist;
    941945
    942946    /** long *************************************************************/
     
    958962            (interactively) ? "true" : "false");
    959963    log_it(tmp);
    960     mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
     964    mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions      ");
    961965    open_progress_form("Formatting partitions",
    962                       "I am now formatting your hard disk partitions.",
    963                       "This may take up to five minutes.", "",
    964                       mountlist->entries + 1);
     966                        "I am now formatting your hard disk partitions.",
     967                        "This may take up to five minutes.", "",
     968                        mountlist->entries + 1);
    965969
    966970    progress_step =
     
    10001004    sleep(2);
    10011005// This last step is probably necessary
    1002 //  log_to_screen("Re-starting software RAIDs...");
    1003 //  start_all_raid_devices(mountlist);
    1004 //  system("sync"); system("sync"); system("sync");
    1005 //  sleep(5);
     1006//  log_to_screen("Re-starting software RAIDs...");
     1007//  start_all_raid_devices(mountlist);
     1008//  system("sync"); system("sync"); system("sync");
     1009//  sleep(5);
    10061010// do LVMs now
    10071011    log_msg(1, "Creating LVMs");
     
    10141018/*
    10151019        for(i=0; i<3; i++)
    1016           {
    1017             res = do_my_funky_lvm_stuff(FALSE, FALSE);
    1018             if (!res) { break; }
    1019             sleep(3);
    1020             res = do_my_funky_lvm_stuff(TRUE, FALSE);
    1021             sleep(3);
    1022           }
     1020            {
     1021              res = do_my_funky_lvm_stuff(FALSE, FALSE);
     1022              if (!res) { break; }
     1023              sleep(3);
     1024              res = do_my_funky_lvm_stuff(TRUE, FALSE);
     1025              sleep(3);
     1026            }
    10231027        if (res) {
    10241028            log_msg(1, "Vacuum-packing...");
     
    10651069            continue;
    10661070        } else if (!does_file_exist(me->device)
    1067                   && strncmp(me->device, "/dev/hd", 7)
    1068                   && strncmp(me->device, "/dev/sd", 7)) {
     1071                    && strncmp(me->device, "/dev/hd", 7)
     1072                    && strncmp(me->device, "/dev/sd", 7)) {
    10691073            sprintf(tmp,
    10701074                    "Not formatting %s yet - doesn't exist - probably an LVM",
     
    11541158 */
    11551159int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename,
    1156                           int devno_we_must_allow_for)
     1160                            int devno_we_must_allow_for)
    11571161{
    11581162    /** int **************************************************************/
     
    12741278    fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions);
    12751279    fprintf(f,
    1276             "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
     1280            "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
    12771281    pp = lp->d_partitions;
    12781282    for (i = 0; i < lp->d_npartitions; i++, pp++) {
    12791283        if (pp->p_size) {
    1280             fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
     1284            fprintf(f, "    %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
    12811285                    (u_long) pp->p_offset);
    12821286            if (pp->p_fstype < FSMAXTYPES)
     
    12871291
    12881292            case FS_UNUSED: /* XXX */
    1289                 fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
     1293                fprintf(f, "      %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
    12901294                        (u_long) (pp->p_fsize * pp->p_frag), "");
    12911295                break;
    12921296
    12931297            case FS_BSDFFS:
    1294                 fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize,
     1298                fprintf(f, "      %5lu %5lu %5u ", (u_long) pp->p_fsize,
    12951299                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    12961300                break;
    12971301
    12981302            case FS_BSDLFS:
    1299                 fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize,
     1303                fprintf(f, "      %5lu %5lu %5d", (u_long) pp->p_fsize,
    13001304                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    13011305                break;
     
    13131317            fprintf(f, "- %lu",
    13141318                    (u_long) ((pp->p_offset + pp->p_size +
    1315                               lp->d_secpercyl - 1) / lp->d_secpercyl -
    1316                               1));
     1319                                lp->d_secpercyl - 1) / lp->d_secpercyl -
     1320                                1));
    13171321            if (pp->p_size % lp->d_secpercyl)
    13181322                putc('*', f);
     
    13521356    /*
    13531357     * Nobody in these enligthened days uses the CHS geometry for
    1354      * anything, but nontheless try to get it right.  If we fail
     1358     * anything, but nontheless try to get it right.    If we fail
    13551359     * to get any good ideas from the device, construct something
    13561360     * which is IBM-PC friendly.
     
    14361440                lp->d_partitions[c - 'a'].p_cpg = 64;
    14371441            } else if (!strcasecmp(mountlist->el[idx].format, "raid")
    1438                       || !strcasecmp(mountlist->el[idx].format, "vinum")) {
     1442                        || !strcasecmp(mountlist->el[idx].format, "vinum")) {
    14391443                lp->d_partitions[c - 'a'].p_fstype = FS_VINUM;
    14401444            } else if (!strcmp(mountlist->el[idx].format, "swap")) {
     
    16071611
    16081612        /* OK, we've found partition /dev/hdxN in mountlist; let's prep it */
    1609         /* For FreeBSD, that is      /dev/adXsY */
     1613        /* For FreeBSD, that is     /dev/adXsY */
    16101614
    16111615        log_it("Found partition %s in mountlist", device_str);
     
    16151619#if __FreeBSD__
    16161620            // FreeBSD doesn't let you write to blk devices in <512byte chunks.
    1617 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1618 //          if (run_program_and_log_output(tmp, TRUE)) {
     1621//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1622//          if (run_program_and_log_output(tmp, TRUE)) {
    16191623            file = open(drivename, O_WRONLY);
    16201624            if (file != -1) {
     
    16391643                fflush(pout_to_fdisk);
    16401644            }
    1641 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1642 //          run_program_and_log_output(tmp, 1);
     1645//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1646//          run_program_and_log_output(tmp, 1);
    16431647#endif
    16441648            if (current_devno > 1) {
    16451649                previous_devno =
    16461650                    make_dummy_partitions(pout_to_fdisk, drivename,
    1647                                           current_devno);
     1651                                            current_devno);
    16481652            }
    16491653        }
     
    17261730 * Create partition number @p partno on @p drive with @p fdisk.
    17271731 * @param drive The drive to create the partition on.
    1728 //  * @param partno The partition number of the new partition (1-4 are primary, >=5 is logical).
     1732//  * @param partno The partition number of the new partition (1-4 are primary, >=5 is logical).
    17291733 * @param prev_partno The partition number of the most recently prepped partition.
    17301734 * @param format The filesystem type of this partition (used to set the type).
     
    17631767
    17641768    log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting",
    1765           drive, partno, prev_partno, format, partsize);
     1769            drive, partno, prev_partno, format, partsize);
    17661770
    17671771    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     
    18021806
    18031807
    1804     /*  sprintf(tmp,"Partitioning %s  ",partition_name); */
    1805     /*  mvaddstr_and_log_it(g_currentY+1,30,tmp); */
     1808    /*  sprintf(tmp,"Partitioning %s  ",partition_name); */
     1809    /*  mvaddstr_and_log_it(g_currentY+1,30,tmp); */
    18061810    p = (char *) strrchr(partition_name, '/');
    18071811    sprintf(logfile, "/tmp/fdisk.log.%s", ++p);
     
    18761880            retval =
    18771881                set_partition_type(pout_to_fdisk, drive, partno, format,
    1878                                   partsize);
     1882                                    partsize);
    18791883            if (retval) {
    18801884                log_msg(1, "Failed. Trying again...");
    18811885                retval =
    18821886                    set_partition_type(pout_to_fdisk, drive, partno,
    1883                                       format, partsize);
     1887                                        format, partsize);
    18841888            }
    18851889        }
     
    19161920            retval =
    19171921                set_partition_type(pout_to_fdisk, drive, partno, format,
    1918                                   partsize);
     1922                                    partsize);
    19191923            if (retval) {
    19201924                sprintf(tmp, "Partitioned %s but failed to set its type",
     
    19701974    /** buffer *********************************************************/
    19711975    struct list_of_disks *drivelist;
    1972     /*  struct mountlist_itself new_mtlist, *mountlist; */
     1976    /*  struct mountlist_itself new_mtlist, *mountlist; */
    19731977
    19741978    /** end ************************************************************/
     
    19781982
    19791983    log_it("partition_everything() --- starting");
    1980     mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives      ");
    1981     /*  mountlist=orig_mtlist; */
     1984    mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives        ");
     1985    /*  mountlist=orig_mtlist; */
    19821986    if (mountlist_contains_raid_devices(mountlist)) {
    1983         /*      mountlist=&new_mtlist; */
    1984         /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
     1987        /*      mountlist=&new_mtlist; */
     1988        /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
    19851989        log_msg(0,
    19861990                "Mountlist, including the partitions incorporated in RAID devices:-");
     
    20042008/* 
    20052009    if (does_file_exist("/tmp/i-want-my-lvm"))
    2006       {
    2007         wipe_MBRs_and_reboot_if_necessary(mountlist); // i.e. if it wasn't done recently
    2008       }
     2010        {
     2011          wipe_MBRs_and_reboot_if_necessary(mountlist); // i.e. if it wasn't done recently
     2012        }
    20092013*/
    20102014
    20112015    open_progress_form("Partitioning devices",
    2012                       "I am now going to partition all your drives.",
    2013                       "This should not take more than five minutes.", "",
    2014                       mountlist->entries);
     2016                        "I am now going to partition all your drives.",
     2017                        "This should not take more than five minutes.", "",
     2018                        mountlist->entries);
    20152019
    20162020    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    20522056 */
    20532057int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno,
    2054                       const char *format, long long partsize)
     2058                        const char *format, long long partsize)
    20552059{
    20562060    /** buffers *********************************************************/
     
    20922096        }
    20932097    } else if (strcmp(format, "ext2") == 0
    2094               || strcmp(format, "reiserfs") == 0
    2095               || strcmp(format, "ext3") == 0
    2096               || strcmp(format, "ext4") == 0
    2097               || strcmp(format, "xfs") == 0
    2098               || strcmp(format, "jfs") == 0
    2099                    || strcmp(format, "btrfs") == 0) {
     2098                || strcmp(format, "reiserfs") == 0
     2099                || strcmp(format, "ext3") == 0
     2100                || strcmp(format, "ext4") == 0
     2101                || strcmp(format, "xfs") == 0
     2102                || strcmp(format, "jfs") == 0
     2103                     || strcmp(format, "btrfs") == 0) {
    21002104        strcpy(partcode, "83");
    21012105    } else if (strcmp(format, "minix") == 0) {
     
    21102114        strcpy(partcode, "7");
    21112115    } else if ((strcmp(format, "ufs") == 0)
    2112               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
     2116                || (strcmp(format, "ffs") == 0)) { /* raid autodetect */
    21132117        strcpy(partcode, "a5");
    21142118    } else if (strcmp(format, "lvm") == 0) {
     
    22602264    sprintf(program, "vinum stop -f %s", raid_device);
    22612265#else
    2262     // use raidstop if it exists, otherwise use mdadm
    2263     if (run_program_and_log_output("which raidstop", FALSE)) {
     2266        // use raidstop if it exists, otherwise use mdadm
     2267        if (run_program_and_log_output("which raidstop", FALSE)) {
    22642268        sprintf(program, "mdadm -S %s", raid_device);
    22652269    } else {
     
    24272431        strcpy(program, "mkfs -t ext4 -F -q");
    24282432    } else if (strcmp(format, "btrfs") == 0) {
    2429             strcpy(program, "mkfs.btrfs");
     2433              strcpy(program, "mkfs.btrfs");
    24302434    } else if (strcmp(format, "minix") == 0) {
    24312435        strcpy(program, "mkfs.minix");
     
    24672471 * There are a few problems with this function:
    24682472 * - It won't work if there was any unallocated space on the user's hard drive
    2469  *  when it was backed up.
     2473 *  when it was backed up.
    24702474 * - It won't work if the user's hard drive lies about its size (more common
    2471  *  than you'd think).
     2475 *  than you'd think).
    24722476 *
    24732477 * @param mountlist The mountlist to use for resizing @p drive_name.
     
    24832487    /** int *************************************************************/
    24842488    int partno, lastpart;
    2485                /** remove driveno, noof_drives stan benoit apr 2002**/
    24862489
    24872490    /** float ***********************************************************/
  • branches/3.0/mondo/test/test-mountlist.c

    r2394 r2990  
    33 *
    44 * Test program for mountlist management at restore time
    5  * Cn be used on host system with valgrind easier than with mondorestore
     5 * Can be used on host system with valgrind easier than with mondorestore
    66 */
    77#include <stdio.h>
     
    1212#include "../mondorestore/mondorestore.h"
    1313#include "../mondorestore/mr-externs.h"
     14
     15#define RAIDTAB_TEST "/tmp/raidtab"
     16#define MOUNTLIST_TEST "/tmp/mountlist.txt"
    1417
    1518extern void twenty_seconds_til_yikes(void);
     
    6871
    6972setup_newt_stuff();
    70 mr_asprintf(&g_mountlist_fname, "/tmp/mountlist.txt");
     73mr_asprintf(&g_mountlist_fname, MOUNTLIST_TEST);
    7174log_it("before mountlist");
    7275load_mountlist(mountlist, g_mountlist_fname);
     
    7477resize_mountlist_proportionately_to_suit_new_drives(mountlist);
    7578log_it("after resize_mountlist_proportionately_to_suit_new_drives");
    76 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     79load_raidtab_into_raidlist(raidlist, RAIDTAB_TEST);
    7780log_it("after load_raidtab_into_raidlist");
    7881edit_mountlist(g_mountlist_fname, mountlist, raidlist);
     
    8386mr_free(flaws_str);
    8487
     88log_it("before check raidlist content");
     89log_it("after check raidlist content");
     90
     91log_it("before create mdadm dev");
     92create_raid_device_via_mdadm(raidlist,"/dev/md0",FALSE);
     93log_it("after create mdadm dev");
     94
    8595mr_free(MONDO_LOGFILE);
    8696exit(0);
Note: See TracChangeset for help on using the changeset viewer.