Ignore:
Timestamp:
Jan 28, 2007, 11:20:07 PM (12 years ago)
Author:
bruno
Message:

merge -r1078:1080 $SVN_M/branches/stable

File:
1 edited

Legend:

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

    r900 r1081  
    11/***************************************************************************
    2  * $Id
    3 **/
     2 * $Id$
     3*/
    44
    55/**
     
    6161    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
    6262    {
    63         drivelist = malloc(sizeof(struct list_of_disks));
     63        drivelist = mr_malloc(sizeof(struct list_of_disks));
    6464        make_list_of_drives_in_mountlist(mountlist, drivelist);
    6565        for (lino = 0; lino < drivelist->entries; lino++) {
     
    522522        }
    523523    }
    524 
    525524    return (0);
    526525}
     
    544543
    545544  /** buffers ***********************************************************/
    546     char *devices = NULL;
    547     char *strtmp = NULL;
    548     char *level = NULL;
    549     char *program = NULL;
    550 
    551     // leave straight away if raidlist is initial or has no entries
    552     if (!raidlist || raidlist->entries == 0) {
    553         log_msg(1, "No RAID arrays found.");
    554         return 1;
    555     } else {
    556         log_msg(1, "%d RAID arrays found.", raidlist->entries);
    557     }
    558     // find raidlist entry for requested device
    559     for (i = 0; i < raidlist->entries; i++) {
    560         if (!strcmp(raidlist->el[i].raid_device, device))
    561             break;
    562     }
    563     // check whether RAID device was found in raidlist
    564     if (i == raidlist->entries) {
    565         log_msg(1, "RAID device %s not found in list.", device);
    566         return 1;
    567     }
    568     // create device list from normal disks followed by spare ones
    569     mr_asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
    570     for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    571         mr_asprintf(&strtmp, "%s", devices);
    572         mr_free(devices);
    573         mr_asprintf(&devices, "%s %s", strtmp,
    574                  raidlist->el[i].data_disks.el[j].device);
    575         mr_free(strtmp);
    576     }
    577     for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    578         mr_asprintf(&strtmp, "%s", devices);
    579         mr_free(devices);
    580         mr_asprintf(&devices, "%s %s", strtmp,
    581                  raidlist->el[i].spare_disks.el[j].device);
    582         mr_free(strtmp);
    583     }
    584     // translate RAID level
    585     if (raidlist->el[i].raid_level == -2) {
    586         mr_asprintf(&level, "multipath");
    587     } else if (raidlist->el[i].raid_level == -1) {
    588         mr_asprintf(&level, "linear");
    589     } else {
    590         mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
    591     }
    592     // create RAID device:
    593     // - RAID device, number of devices and devices mandatory
    594     // - parity algorithm, chunk size and spare devices optional
    595     // - faulty devices ignored
    596     // - persistent superblock always used as this is recommended
    597     mr_asprintf(&program,
    598              "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
    599              raidlist->el[i].raid_device, level,
    600              raidlist->el[i].data_disks.entries);
    601     if (raidlist->el[i].parity != -1) {
    602         mr_asprintf(&strtmp, "%s", program);
    603         mr_free(program);
    604         switch (raidlist->el[i].parity) {
    605         case 0:
    606             mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
    607             break;
    608         case 1:
    609             mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
    610             break;
    611         case 2:
    612             mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
    613             break;
    614         case 3:
    615             mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
    616             break;
    617         default:
    618             fatal_error("Unknown RAID parity algorithm.");
    619             break;
    620         }
    621         mr_free(strtmp);
    622     }
    623     if (raidlist->el[i].chunk_size != -1) {
    624         mr_asprintf(&strtmp, "%s", program);
    625         mr_free(program);
    626         mr_asprintf(&program, "%s --chunk=%d", strtmp,
    627                  raidlist->el[i].chunk_size);
    628         mr_free(strtmp);
    629     }
    630     if (raidlist->el[i].spare_disks.entries > 0) {
    631         mr_asprintf(&strtmp, "%s", program);
    632         mr_free(program);
    633         mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
    634                  raidlist->el[i].spare_disks.entries);
    635         mr_free(strtmp);
    636     }
    637     mr_asprintf(&strtmp, "%s", program);
    638     mr_free(program);
    639     mr_asprintf(&program, "%s %s", strtmp, devices);
    640     mr_free(strtmp);
    641     res = run_program_and_log_output(program, 1);
    642     // free memory
    643     mr_free(devices);
    644     mr_free(level);
    645     mr_free(program);
    646     // return to calling instance
    647     return res;
     545  char *devices = NULL;
     546  char *strtmp  = NULL;
     547  char *level   = NULL;
     548  char *program = NULL;
     549 
     550  // leave straight away if raidlist is initial or has no entries
     551  if (!raidlist || raidlist->entries == 0) {
     552    log_msg(1, "No RAID arrays found.");
     553    return 1;
     554  } else {
     555    log_msg(1, "%d RAID arrays found.", raidlist->entries);
     556  }
     557  // find raidlist entry for requested device
     558  for (i = 0; i < raidlist->entries; i++) {
     559    if (!strcmp(raidlist->el[i].raid_device, device)) break;
     560  }
     561  // check whether RAID device was found in raidlist
     562  if (i == raidlist->entries) {
     563    log_msg(1, "RAID device %s not found in list.", device);
     564    return 1;
     565  }
     566  // create device list from normal disks followed by spare ones
     567  mr_asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
     568  for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
     569    mr_asprintf(&strtmp, "%s", devices);
     570    mr_free(devices);
     571    mr_asprintf(&devices, "%s %s", strtmp,
     572         raidlist->el[i].data_disks.el[j].device);
     573    mr_free(strtmp);
     574  }
     575  for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
     576    mr_asprintf(&strtmp, "%s", devices);
     577    mr_free(devices);
     578    mr_asprintf(&devices, "%s %s", strtmp,
     579         raidlist->el[i].spare_disks.el[j].device);
     580    mr_free(strtmp);
     581  }
     582  // translate RAID level
     583  if (raidlist->el[i].raid_level == -2) {
     584    mr_asprintf(&level, "multipath");
     585  } else if (raidlist->el[i].raid_level == -1) {
     586    mr_asprintf(&level, "linear");
     587  } else {
     588    mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     589  }
     590  // create RAID device:
     591  // - RAID device, number of devices and devices mandatory
     592  // - parity algorithm, chunk size and spare devices optional
     593  // - faulty devices ignored
     594  // - persistent superblock always used as this is recommended
     595  mr_asprintf(&program,
     596       "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
     597       raidlist->el[i].raid_device, level,
     598       raidlist->el[i].data_disks.entries);
     599  if (raidlist->el[i].parity != -1) {
     600    asprintf(&strtmp, "%s", program);
     601    mr_free(program);
     602    switch(raidlist->el[i].parity) {
     603    case 0:
     604      mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
     605      break;
     606    case 1:
     607      mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
     608      break;
     609    case 2:
     610      mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
     611      break;
     612    case 3:
     613      mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
     614      break;
     615    default:
     616      fatal_error("Unknown RAID parity algorithm.");
     617      break;
     618    }
     619    mr_free(strtmp);
     620  }
     621  if (raidlist->el[i].chunk_size != -1) {
     622    mr_asprintf(&strtmp, "%s", program);
     623    mr_free(program);
     624    mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
     625    mr_free(strtmp);
     626  }
     627  if (raidlist->el[i].spare_disks.entries > 0) {
     628    mr_asprintf(&strtmp, "%s", program);
     629    mr_free(program);
     630    mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
     631         raidlist->el[i].spare_disks.entries);
     632    mr_free(strtmp);
     633  }
     634  mr_asprintf(&strtmp, "%s", program);
     635  mr_free(program);
     636  mr_asprintf(&program, "%s %s", strtmp, devices);
     637  mr_free(strtmp);
     638  res = run_program_and_log_output(program, 1);
     639  // free memory
     640  mr_free(devices);
     641  mr_free(level);
     642  mr_free(program);
     643  // return to calling instance
     644  return res;
    648645}
    649646
     
    15511548                    mr_free(command);
    15521549                    mr_free(device_str);
    1553 
    15541550                    return r;
    15551551                }
     
    16431639            mr_free(device_str);
    16441640            mr_free(format);
    1645 
    16461641            return (1);
    16471642        }
     
    19551950    /** end ************************************************************/
    19561951
    1957     drivelist = malloc(sizeof(struct list_of_disks));
     1952    drivelist = mr_malloc(sizeof(struct list_of_disks));
    19581953    assert(mountlist != NULL);
    19591954
     
    21682163    mr_free(partcode);
    21692164
    2170 
    21712165    return (res);
    21722166}
     
    25182512    mr_free(tmp);
    25192513
    2520     drivemntlist = malloc(sizeof(struct mountlist_reference));
     2514    drivemntlist = mr_malloc(sizeof(struct mountlist_reference));
    25212515    drivemntlist->el =
    2522         malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
    2523 
    2524     if (!drivemntlist) {
    2525         fatal_error("Cannot malloc temporary mountlist\n");
    2526     }
     2516        mr_malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
     2517
    25272518    create_mountlist_for_drive(mountlist, drive_name, drivemntlist);
    25282519
     
    25952586    /** end *************************************************************/
    25962587
    2597     drivelist = malloc(sizeof(struct list_of_disks));
    2598     assert(mountlist != NULL);
     2588    drivelist = mr_malloc(sizeof(struct list_of_disks));
    25992589
    26002590    if (g_mountlist_fname == NULL) {
Note: See TracChangeset for help on using the changeset viewer.