Changeset 561 in MondoRescue for trunk/mondo/mondo/mondorestore
- Timestamp:
- May 20, 2006, 5:51:21 PM (18 years ago)
- Location:
- trunk/mondo/mondo/mondorestore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/mondorestore/mondo-prep.c
r507 r561 695 695 696 696 /** 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 */ 704 int 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 /** 697 816 * Format @p device as a @p format filesystem. 698 817 * This will use the format command returned by which_format_command_do_i_need(). … … 704 823 * @return 0 for success, nonzero for failure. 705 824 */ 706 int format_device(char *device, char *format )825 int format_device(char *device, char *format, struct raidlist_itself *raidlist) 707 826 { 708 827 /** int **************************************************************/ … … 836 955 837 956 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 } 846 971 } 847 972 system("sync"); 848 973 sleep(2); 849 850 974 // log_to_screen("Starting %s", device); 851 975 // sprintf(program, "raidstart %s", device); … … 853 977 // log_msg(1, "%s returned %d", program, res); 854 978 // system("sync"); sleep(1); 855 if (g_fprep) {856 fprintf(g_fprep, "%s\n", program);857 }858 979 #endif 859 980 system("sync"); … … 923 1044 * @return The number of errors encountered (0 for success). 924 1045 */ 925 int format_everything(struct mountlist_itself *mountlist, 926 bool interactively)1046 int format_everything(struct mountlist_itself *mountlist, bool interactively, 1047 struct raidlist_itself *raidlist) 927 1048 { 928 1049 /** int **************************************************************/ … … 983 1104 if (do_it) { 984 1105 // 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); 986 1107 } 987 1108 g_current_progress += progress_step; … … 1000 1121 log_msg(1, "Creating LVMs"); 1001 1122 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); 1003 1124 log_to_screen(_("Configuring LVM")); 1004 1125 if (!g_text_mode) { … … 1076 1197 1077 1198 if (do_it) 1078 retval += format_device(me->device, me->format );1199 retval += format_device(me->device, me->format, raidlist); 1079 1200 } 1080 1201 … … 2246 2367 sprintf(program, "vinum stop -f %s", raid_device); 2247 2368 #else 2248 sprintf(program, "raidstop %s", raid_device); 2249 // sprintf (program, "raidstop " RAID_DEVICE_STUB "*"); 2369 // use raidstop if it exists, otherwise use mdadm 2370 if (run_program_and_log_output("which raidstop", FALSE)) { 2371 sprintf(program, "mdadm -S %s", raid_device); 2372 } else { 2373 sprintf(program, "raidstop %s", raid_device); 2374 } 2250 2375 #endif 2251 2376 log_msg(1, "program = %s", program); -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r507 r561 839 839 } 840 840 841 fmt_errs = format_everything(mountlist, FALSE );841 fmt_errs = format_everything(mountlist, FALSE, raidlist); 842 842 if (!fmt_errs) { 843 843 log_to_screen … … 857 857 if (ask_me_yes_or_no 858 858 (_("Do you want to format your hard drives?"))) { 859 fmt_errs = format_everything(mountlist, TRUE );859 fmt_errs = format_everything(mountlist, TRUE, raidlist); 860 860 if (!fmt_errs) { 861 861 done = TRUE; … … 1164 1164 system("sync"); 1165 1165 log_to_screen(_("Please wait. This may take a few minutes.")); 1166 res += format_everything(mountlist, FALSE );1166 res += format_everything(mountlist, FALSE, raidlist); 1167 1167 } 1168 1168 paranoid_fclose(g_fprep); … … 3425 3425 } 3426 3426 3427 if (argc == 4&& strcmp(argv[1], "--mdconv") == 0) {3428 finish(create_raidtab_from_mdstat(argv[2] , argv[3]));3427 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) { 3428 finish(create_raidtab_from_mdstat(argv[2])); 3429 3429 } 3430 3430 … … 3525 3525 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3526 3526 load_mountlist(mountlist, g_mountlist_fname); 3527 res = format_everything(mountlist, FALSE );3527 res = format_everything(mountlist, FALSE, raidlist); 3528 3528 finish(res); 3529 3529 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
r507 r561 1 /*************************************************************************** 2 mondo-rstr-tools.c - description 3 ----------------- 4 5 begin: Sun Sep 21 16:40:35 EDT 2003 6 copyright : (C) 2002 Mondo Hugo Rabson 7 email : Hugo Rabson <hugorabson@msn.com> 8 edited by : by Stan Benoit ?/2003 9 email : troff@nakedsoul.org 10 cvsid : $Id: mondo-rstr-tools.c 11 ***************************************************************************/ 12 13 /*************************************************************************** 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 ***************************************************************************/ 21 /* mondo-rstr-tools.c Hugo Rabson 22 23 24 07/27 25 - if the user is foolish enough to use /dev/md0 as boot device, 26 call lilo -M /dev/hda to make sure lilo does its job properly 27 - better NFS+nuke support 28 29 07/20 30 - use backup's i-want-my-lvm file 31 - be sure to use archives' raidtab when restoring 32 33 07/18 34 - use /tmp/isodir for NFS if DR mode 35 - better support of users who boot from LVM CD and nuke-restore non-LVM backups 36 37 07/12 38 - bugfix to allow user to burn ISOs to CDs and restore from CDs (not original src) 39 40 06/29 41 - mount ext3 partitions as ext2, just in case :) 42 43 06/26 44 - delete make_relevant_partition_bootable() 45 46 06/19 47 - futzed with the call to mount floppy, to stop it from locking up on my AMD64 system 48 49 06/14 50 - shell out to /mnt/RESTORING chroot in order to let user install GRUB 51 manually if automatic GRUB installation fails 52 53 06/15 54 - Added check for different 'isodir' chosen by user than stored in the archive 55 Conor Daly <conor.daly@met.ie> 56 57 04/17 58 - replaced INTERNAL_TAPE_BLK_SIZE with bkpinfo->internal_tape_block_size 59 60 04/09 61 - don't try to mount CD if tape bkp 62 63 04/03 64 - trying to copy tmp/mondo-restore.cfg to itself - silly! - fixed 65 66 04/02 67 - when extracting cfg file and mountlist from all.tar.gz (tape copy), 68 use block size of INTERNAL_TAPE_BLK_SIZE, not TAPE_BLOCK_SIZE 69 70 02/21 71 - don't use 'mv -v' cos Busybox won't support it 72 73 02/09 74 - make hole for cfg file before moving it (line 2094 or so) 75 76 02/03 77 - changed a couple of refs to filelist.full, to filelist.full.gz 78 79 01/16/2004 80 - instead of copying filelist, use 'ln -sf' to link to original; 81 saves space 82 83 11/20/2003 84 - also retrieve /tmp/mountlist.txt if user wants 85 86 11/16 87 - fixed NFS path bug affecting the extractions of filelist/biggielist 88 during selective restore 89 90 11/02 91 - fixed mount_cdrom() to run properly w/ nfs restores 92 - mount_device() returns 0 if swap mount fails cos swap isn't crucial 93 94 10/17 95 - run_grub() uses MNT_RESTORING instead of "/mnt/RESTORING" 96 97 10/26 98 - cleaned up run_grub() 99 100 10/25 101 - fixed mount_cdrom() to run properly w/ nfs restores 102 103 10/21 104 - mount_device() returns 0 if swap mount fails cos swap isn't crucial 105 106 10/15 107 - run_grub() now uses its initiative instead 108 of calling grub-install 109 110 10/10 111 - don't leave copies of filelist.full lying around, clogging up 112 the ramdisk, there's a good fellow :-) 113 114 10/02 115 - added 'dvd' to the range of media types I'll understand 116 - fixed iso->cdr problem (thanks, Stan Benoit & Fred Beondo) 117 118 09/24 119 - try lots of tape devs if /dev/st0 fails 120 121 09/23/2003 122 - first incarnation 1 /* 2 * $Id$ 123 3 */ 124 4 … … 2569 2449 int wait_for_percentage) 2570 2450 { 2571 struct s_mdstat *mdstat;2451 struct raidlist_itself *raidlist; 2572 2452 int unfinished_mdstat_devices = 9999, i; 2573 2453 char *screen_message; 2574 2454 2575 2455 malloc_string(screen_message); 2576 mdstat = malloc(sizeof(struct s_mdstat));2456 raidlist = malloc(sizeof(struct raidlist_itself)); 2577 2457 2578 2458 assert(wait_for_percentage <= 100); 2579 2459 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)"); 2580 2460 while (unfinished_mdstat_devices > 0) { 2581 if (read_mdstat(mdstat, mdstat_file)) { 2582 log_to_screen(_("Sorry, cannot read %s"), mdstat_file); 2461 if (parse_mdstat(raidlist, "/dev/")) { 2462 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE); 2463 log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE); 2583 2464 return; 2584 2465 } 2585 for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) {2586 if ( mdstat->el[i].progress < wait_for_percentage) {2466 for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) { 2467 if (raidlist->el[i].progress < wait_for_percentage) { 2587 2468 unfinished_mdstat_devices++; 2588 sprintf(screen_message, _("Sync'ing /dev/md%d"), 2589 mdstat->el[i].md); 2469 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i); 2470 sprintf(screen_message, "Sync'ing %s", 2471 raidlist->el[i].raid_device); 2590 2472 open_evalcall_form(screen_message); 2591 if ( mdstat->el[i].progress == -1) // delayed while another partition inits2473 if (raidlist->el[i].progress == -1) // delayed while another partition inits 2592 2474 { 2593 2475 continue; 2594 2476 } 2595 while (mdstat->el[i].progress < wait_for_percentage) { 2596 update_evalcall_form(mdstat->el[i].progress); 2477 while (raidlist->el[i].progress < wait_for_percentage) { 2478 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress); 2479 update_evalcall_form(raidlist->el[i].progress); 2597 2480 sleep(2); 2598 if (read_mdstat(mdstat, mdstat_file)) { 2481 // FIXME: Prefix '/dev/' should really be dynamic! 2482 if (parse_mdstat(raidlist, "/dev/")) { 2599 2483 break; 2600 2484 } … … 2605 2489 } 2606 2490 paranoid_free(screen_message); 2607 paranoid_free( mdstat);2608 } 2491 paranoid_free(raidlist); 2492 } -
trunk/mondo/mondo/mondorestore/mondoprep.h
r59 r561 58 58 int start_all_raid_devices(struct mountlist_itself *); 59 59 int stop_all_raid_devices(struct mountlist_itself *); 60 int format_everything(struct mountlist_itself *, bool );60 int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *); 61 61 int partition_device(FILE *, const char *, int, int, const char *, 62 62 long long); … … 65 65 int partition_device_with_fdisk(FILE *, const char *, int, int, 66 66 const char *, long long); 67 int format_device(char *, char * );67 int format_device(char *, char *, struct raidlist_itself *); 68 68 int partition_drive(struct mountlist_itself *, char *); 69 69 int partition_everything(struct mountlist_itself *); -
trunk/mondo/mondo/mondorestore/mr-externs.h
r127 r561 27 27 extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *, 28 28 struct raidlist_itself *); 29 extern int format_everything(struct mountlist_itself *, bool );30 extern int format_device(char *, char * );29 extern int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *); 30 extern int format_device(char *, char *, struct raidlist_itself *); 31 31 extern void finish(int); 32 32 extern void free_filelist(struct s_node *);
Note:
See TracChangeset
for help on using the changeset viewer.