Changeset 576 in MondoRescue for branches/2.0.8/mondo/mondo/mondorestore


Ignore:
Timestamp:
May 25, 2006, 2:00:37 PM (18 years ago)
Author:
bcornec
Message:

2.08 synced with stable as of r575
VERSION files updated

Location:
branches/2.0.8/mondo/mondo/mondorestore
Files:
5 edited

Legend:

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

    r196 r576  
    695695
    696696/**
     697 * Create @p RAID device using information from @p structure.
     698 * This will create the specified RAID devive using information provided in
     699 * raidlist by means of the mdadm tool.
     700 * @param raidlist The structure containing all RAID information
     701 * @param device The RAID device to create.
     702 * @return 0 for success, nonzero for failure.
     703 */
     704int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device)
     705{
     706  /** int **************************************************************/
     707  int i   = 0;
     708  int j   = 0;
     709  int res = 0;
     710 
     711  /** buffers ***********************************************************/
     712  char *devices = NULL;
     713  char *strtmp  = NULL;
     714  char *level   = NULL;
     715  char *program = NULL;
     716 
     717  // leave straight away if raidlist is initial or has no entries
     718  if (!raidlist || raidlist->entries == 0) {
     719    log_msg(1, "No RAID arrays found.");
     720    return 1;
     721  } else {
     722    log_msg(1, "%d RAID arrays found.", raidlist->entries);
     723  }
     724  // find raidlist entry for requested device
     725  for (i = 0; i < raidlist->entries; i++) {
     726    if (!strcmp(raidlist->el[i].raid_device, device)) break;
     727  }
     728  // check whether RAID device was found in raidlist
     729  if (i == raidlist->entries) {
     730    log_msg(1, "RAID device %s not found in list.", device);
     731    return 1;
     732  }
     733  // create device list from normal disks followed by spare ones
     734  asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
     735  for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
     736    asprintf(&strtmp, "%s", devices);
     737    paranoid_free(devices);
     738    asprintf(&devices, "%s %s", strtmp,
     739         raidlist->el[i].data_disks.el[j].device);
     740    paranoid_free(strtmp);
     741  }
     742  for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
     743    asprintf(&strtmp, "%s", devices);
     744    paranoid_free(devices);
     745    asprintf(&devices, "%s %s", strtmp,
     746         raidlist->el[i].spare_disks.el[j].device);
     747    paranoid_free(strtmp);
     748  }
     749  // translate RAID level
     750  if (raidlist->el[i].raid_level == -2) {
     751    asprintf(&level, "multipath");
     752  } else if (raidlist->el[i].raid_level == -1) {
     753    asprintf(&level, "linear");
     754  } else {
     755    asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     756  }
     757  // create RAID device:
     758  // - RAID device, number of devices and devices mandatory
     759  // - parity algorithm, chunk size and spare devices optional
     760  // - faulty devices ignored
     761  // - persistent superblock always used as this is recommended
     762  asprintf(&program,
     763       "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
     764       raidlist->el[i].raid_device, level,
     765       raidlist->el[i].data_disks.entries);
     766  if (raidlist->el[i].parity != -1) {
     767    asprintf(&strtmp, "%s", program);
     768    paranoid_free(program);
     769    switch(raidlist->el[i].parity) {
     770    case 0:
     771      asprintf(&program, "%s --parity=%s", strtmp, "la");
     772      break;
     773    case 1:
     774      asprintf(&program, "%s --parity=%s", strtmp, "ra");
     775      break;
     776    case 2:
     777      asprintf(&program, "%s --parity=%s", strtmp, "ls");
     778      break;
     779    case 3:
     780      asprintf(&program, "%s --parity=%s", strtmp, "rs");
     781      break;
     782    default:
     783      fatal_error("Unknown RAID parity algorithm.");
     784      break;
     785    }
     786    paranoid_free(strtmp);
     787  }
     788  if (raidlist->el[i].chunk_size != -1) {
     789    asprintf(&strtmp, "%s", program);
     790    paranoid_free(program);
     791    asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
     792    paranoid_free(strtmp);
     793  }
     794  if (raidlist->el[i].spare_disks.entries > 0) {
     795    asprintf(&strtmp, "%s", program);
     796    paranoid_free(program);
     797    asprintf(&program, "%s --spare-devices=%d", strtmp,
     798         raidlist->el[i].spare_disks.entries);
     799    paranoid_free(strtmp);
     800  }
     801  asprintf(&strtmp, "%s", program);
     802  paranoid_free(program);
     803  asprintf(&program, "%s %s", strtmp, devices);
     804  paranoid_free(strtmp);
     805  res = run_program_and_log_output(program, 1);
     806  // free memory
     807  paranoid_free(devices);
     808  paranoid_free(level);
     809  paranoid_free(program);
     810  // return to calling instance
     811  return res;
     812}
     813
     814
     815/**
    697816 * Format @p device as a @p format filesystem.
    698817 * This will use the format command returned by which_format_command_do_i_need().
     
    704823 * @return 0 for success, nonzero for failure.
    705824 */
    706 int format_device(char *device, char *format)
     825int format_device(char *device, char *format, struct raidlist_itself *raidlist)
    707826{
    708827    /** int **************************************************************/
     
    836955
    837956        log_msg(1, "Making %s", device);
    838         sprintf(program, "mkraid --really-force %s", device);
    839         res = run_program_and_log_output(program, 1);
    840         log_msg(1, "%s returned %d", program, res);
    841         system("sync");
    842         sleep(3);
    843         start_raid_device(device);
    844         if (g_fprep) {
    845             fprintf(g_fprep, "%s\n", program);
     957        // use mkraid if it exists, otherwise use mdadm
     958        if (run_program_and_log_output("which mkraid", FALSE)) {
     959            res = create_raid_device_via_mdadm(raidlist, device);
     960            log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
     961        } else {
     962            sprintf(program, "mkraid --really-force %s", device);
     963            res = run_program_and_log_output(program, 1);
     964            log_msg(1, "%s returned %d", program, res);
     965            system("sync");
     966            sleep(3);
     967            start_raid_device(device);
     968            if (g_fprep) {
     969                fprintf(g_fprep, "%s\n", program);
     970            }
    846971        }
    847972        system("sync");
    848973        sleep(2);
    849 
    850974//      log_to_screen("Starting %s", device);
    851975//      sprintf(program, "raidstart %s", device);
     
    853977//      log_msg(1, "%s returned %d", program, res);
    854978//      system("sync"); sleep(1);
    855         if (g_fprep) {
    856             fprintf(g_fprep, "%s\n", program);
    857         }
    858979#endif
    859980        system("sync");
     
    9231044 * @return The number of errors encountered (0 for success).
    9241045 */
    925 int format_everything(struct mountlist_itself *mountlist,
    926                       bool interactively)
     1046int format_everything(struct mountlist_itself *mountlist, bool interactively,
     1047                          struct raidlist_itself *raidlist)
    9271048{
    9281049    /** int **************************************************************/
     
    9831104            if (do_it) {
    9841105                // NB: format_device() also stops/starts RAID device if necessary
    985                 retval += format_device(me->device, me->format);
     1106                retval += format_device(me->device, me->format, raidlist);
    9861107            }
    9871108            g_current_progress += progress_step;
     
    10001121    log_msg(1, "Creating LVMs");
    10011122    if (does_file_exist("/tmp/i-want-my-lvm")) {
    1002         wait_until_software_raids_are_prepped("/proc/mdstat", 10);
     1123        wait_until_software_raids_are_prepped("/proc/mdstat", 100);
    10031124        log_to_screen("Configuring LVM");
    10041125        if (!g_text_mode) {
     
    10761197
    10771198            if (do_it)
    1078                 retval += format_device(me->device, me->format);
     1199                retval += format_device(me->device, me->format, raidlist);
    10791200        }
    10801201
     
    22472368    sprintf(program, "vinum stop -f %s", raid_device);
    22482369#else
    2249     sprintf(program, "raidstop %s", raid_device);
    2250 //      sprintf (program, "raidstop " RAID_DEVICE_STUB "*");
     2370    // use raidstop if it exists, otherwise use mdadm
     2371    if (run_program_and_log_output("which raidstop", FALSE)) {
     2372        sprintf(program, "mdadm -S %s", raid_device);
     2373    } else {
     2374        sprintf(program, "raidstop %s", raid_device);
     2375    }
    22512376#endif
    22522377    log_msg(1, "program = %s", program);
  • branches/2.0.8/mondo/mondo/mondorestore/mondo-restore.c

    r519 r576  
    837837                    }
    838838
    839                     fmt_errs = format_everything(mountlist, FALSE);
     839                    fmt_errs = format_everything(mountlist, FALSE, raidlist);
    840840                    if (!fmt_errs) {
    841841                        log_to_screen
     
    855855                if (ask_me_yes_or_no
    856856                    ("Do you want to format your hard drives?")) {
    857                     fmt_errs = format_everything(mountlist, TRUE);
     857                    fmt_errs = format_everything(mountlist, TRUE, raidlist);
    858858                    if (!fmt_errs) {
    859859                        done = TRUE;
     
    11621162                system("sync");
    11631163                log_to_screen("Please wait. This may take a few minutes.");
    1164                 res += format_everything(mountlist, FALSE);
     1164                res += format_everything(mountlist, FALSE, raidlist);
    11651165            }
    11661166            paranoid_fclose(g_fprep);
     
    34153415    }
    34163416
    3417     if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) {
    3418         finish(create_raidtab_from_mdstat(argv[2], argv[3]));
     3417    if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
     3418        finish(create_raidtab_from_mdstat(argv[2]));
    34193419    }
    34203420
     
    35153515            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    35163516            load_mountlist(mountlist, g_mountlist_fname);
    3517             res = format_everything(mountlist, FALSE);
     3517            res = format_everything(mountlist, FALSE, raidlist);
    35183518            finish(res);
    35193519        }
  • branches/2.0.8/mondo/mondo/mondorestore/mondo-rstr-tools.c

    r425 r576  
    25852585                                           int wait_for_percentage)
    25862586{
    2587     struct s_mdstat *mdstat;
     2587    struct raidlist_itself *raidlist;
    25882588    int unfinished_mdstat_devices = 9999, i;
    25892589    char *screen_message;
    25902590
    25912591    malloc_string(screen_message);
    2592     mdstat = malloc(sizeof(struct s_mdstat));
     2592    raidlist = malloc(sizeof(struct raidlist_itself));
    25932593
    25942594    assert(wait_for_percentage <= 100);
    25952595    iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
    25962596    while (unfinished_mdstat_devices > 0) {
    2597         if (read_mdstat(mdstat, mdstat_file)) {
    2598             log_to_screen("Sorry, cannot read %s", mdstat_file);
     2597            // FIXME: Prefix '/dev/' should really be dynamic!
     2598        if (parse_mdstat(raidlist, "/dev/")) {
     2599            log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
     2600            log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
    25992601            return;
    26002602        }
    2601         for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) {
    2602             if (mdstat->el[i].progress < wait_for_percentage) {
     2603        for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) {
     2604            if (raidlist->el[i].progress < wait_for_percentage) {
    26032605                unfinished_mdstat_devices++;
    2604                 sprintf(screen_message, "Sync'ing /dev/md%d",
    2605                         mdstat->el[i].md);
     2606                log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
     2607                sprintf(screen_message, "Sync'ing %s",
     2608                        raidlist->el[i].raid_device);
    26062609                open_evalcall_form(screen_message);
    2607                 if (mdstat->el[i].progress == -1)   // delayed while another partition inits
     2610                if (raidlist->el[i].progress == -1) // delayed while another partition inits
    26082611                {
    26092612                    continue;
    26102613                }
    2611                 while (mdstat->el[i].progress < wait_for_percentage) {
    2612                     update_evalcall_form(mdstat->el[i].progress);
     2614                while (raidlist->el[i].progress < wait_for_percentage) {
     2615                    log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
     2616                    update_evalcall_form(raidlist->el[i].progress);
    26132617                    sleep(2);
    2614                     if (read_mdstat(mdstat, mdstat_file)) {
     2618                    // FIXME: Prefix '/dev/' should really be dynamic!
     2619                    if (parse_mdstat(raidlist, "/dev/")) {
    26152620                        break;
    26162621                    }
     
    26212626    }
    26222627    paranoid_free(screen_message);
    2623     paranoid_free(mdstat);
    2624 }
     2628    paranoid_free(raidlist);
     2629}
  • branches/2.0.8/mondo/mondo/mondorestore/mondoprep.h

    r128 r576  
    5858int start_all_raid_devices(struct mountlist_itself *);
    5959int stop_all_raid_devices(struct mountlist_itself *);
    60 int format_everything(struct mountlist_itself *, bool);
     60int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *);
    6161int partition_device(FILE *, const char *, int, int, const char *,
    6262                     long long);
     
    6565int partition_device_with_fdisk(FILE *, const char *, int, int,
    6666                                const char *, long long);
    67 int format_device(char *, char *);
     67int format_device(char *, char *, struct raidlist_itself *);
    6868int partition_drive(struct mountlist_itself *, char *);
    6969int partition_everything(struct mountlist_itself *);
  • branches/2.0.8/mondo/mondo/mondorestore/mr-externs.h

    r128 r576  
    2727extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *,
    2828                          struct raidlist_itself *);
    29 extern int format_everything(struct mountlist_itself *, bool);
    30 extern int format_device(char *, char *);
     29extern int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *);
     30extern int format_device(char *, char *, struct raidlist_itself *);
    3131extern void finish(int);
    3232extern void free_filelist(struct s_node *);
Note: See TracChangeset for help on using the changeset viewer.