Revision: 2705
http://ipcop.svn.sourceforge.net/ipcop/?rev=2705&view=rev
Author: owes
Date: 2009-04-13 09:32:18 +0000 (Mon, 13 Apr 2009)
Log Message:
-----------
Add progress indicator for RAID creation and create the RAID in a single step.
Modified Paths:
--------------
ipcop/trunk/src/installer/partition.c
Modified: ipcop/trunk/src/installer/partition.c
===================================================================
--- ipcop/trunk/src/installer/partition.c 2009-04-13 09:08:40 UTC (rev
2704)
+++ ipcop/trunk/src/installer/partition.c 2009-04-13 09:32:18 UTC (rev
2705)
@@ -72,7 +72,7 @@
*/
static int raid;
static char arch[STRING_SIZE]; // alpha,
powerpc, sparc, x86
-static char install_type[STRING_SIZE]; // onedisk,
raid, flash
+static char install_type[STRING_SIZE]; // onedisk,
raid, flash
static char partition_label[NR_PARTITIONS][STRING_SIZE]; // add 1
string for terminator mark
static char partition_mount[NR_PARTITIONS][STRING_SIZE]; // mountpoints
for partitions
static char partition_uuidenc[NR_PARTITIONS][STRING_SIZE]; // UUIDs
@@ -95,6 +95,8 @@
char command[STRING_SIZE];
char device[STRING_SIZE];
char device2[STRING_SIZE];
+ newtComponent *f;
+ newtComponent scale;
snprintf(device, STRING_SIZE, "/dev/%s", dev);
snprintf(device2, STRING_SIZE, "/dev/%s", dev2);
@@ -122,7 +124,7 @@
if ((*swap_file != -1) && (ROOT_MINIMUM + *swap_file >= disk_size)) {
/* The wanted swapfilesize does not fit */
- fprintf(flog, "Not enough space for %ld MB swapfile\n",
*swap_file);
+ fprintf(flog, "Not enough space for %ld MiB swapfile\n",
*swap_file);
*swap_file = -1;
}
@@ -160,7 +162,7 @@
log_partition = disk_size - root_partition;
/*
- We now have auto-partition data (in MB)
+ We now have auto-partition data (in MiB)
start: end:
start_p root_p
root_p disk_size
@@ -201,12 +203,12 @@
if (partition_index[PART_INDEX_ROOT] == -1) {
/* Can't be, probably because of non-supported arch. */
fprintf(flog, "Partition# for / is not set, non-supported arch?\n");
- goto PARTITION_EXIT;
+ return FAILURE; /* exit immediately */
}
if (partition_index[PART_INDEX_VARLOG] == -1) {
/* Can't be, probably because of non-supported arch. */
fprintf(flog, "Partition# for /var/log is 0, non-supported arch?\n");
- goto PARTITION_EXIT;
+ return FAILURE; /* exit immediately */
}
if (medium_target == flash) {
@@ -223,6 +225,8 @@
/* OK, user thinks he's smart enough to do by himself */
newtWinMessage(ipcop_gettext("TR_TITLE_DISK"), ipcop_gettext("TR_OK"),
"Do your thing with parted now!");
+
+ /* TODO: some verification? */
return SUCCESS;
}
@@ -237,63 +241,100 @@
arch, dev, root_partition, disk_size, install_type);
if (mysystem(command)) {
fprintf(flog, "error partitioning %s\n", device);
- return FAILURE;
+ goto PARTITION_EXIT;
}
- if (!raid) {
- goto PARTITION_NORAID;
+
+ if (raid) {
+ /* Repeat partitioning for 2nd disk */
+ snprintf(command, STRING_SIZE, "/usr/bin/disk-partition %s %s %ld %ld
%s",
+ arch, dev2, root_partition, disk_size, install_type);
+ if (mysystem(command)) {
+ fprintf(flog, "error partitioning %s\n", device2);
+ goto PARTITION_EXIT;
+ }
}
- snprintf(command, STRING_SIZE, "/usr/bin/disk-partition %s %s %ld %ld %s",
- arch, dev2, root_partition, disk_size, install_type);
- if (mysystem(command)) {
- fprintf(flog, "error partitioning %s\n", device2);
- return FAILURE;
- }
- PARTITION_NORAID:
retcode = SUCCESS;
PARTITION_EXIT:
- if (retcode) {
+ /* Remove status window */
+ newtPopWindow();
+
+ if (retcode == FAILURE) {
fprintf(flog, "Make partitions failed ...\n");
+ return FAILURE;
}
- else {
- fprintf(flog, "Make partitions done ...\n");
+
+ fprintf(flog, "Make partitions done ...\n");
+
+ if (!raid) {
+ return SUCCESS;
}
- if ((retcode == SUCCESS) && raid) {
- newtComponent *f;
- newtComponent scale;
- newtPopWindow();
+ /* Create RAID and wait for the drives to be synchronised */
- f = (newtComponent *) statuswindow_progress(72, 5,
ipcop_gettext("TR_TITLE_DISK"),
-
ipcop_gettext("TR_CREATING_RAID"));
- scale = newtScale(1, 3, 70, 100);
- newtFormAddComponent(*f, scale);
- newtDrawForm(*f);
- newtRefresh();
+ f = (newtComponent *) statuswindow_progress(72, 5,
ipcop_gettext("TR_TITLE_DISK"),
+
ipcop_gettext("TR_CREATING_RAID"));
+ scale = newtScale(1, 3, 70, 100);
+ newtFormAddComponent(*f, scale);
+ newtDrawForm(*f);
+ newtScaleSet(scale, 0);
+ newtRefresh();
- mysystem("/sbin/modprobe md-mod");
- mysystem("/sbin/modprobe raid1");
- system("echo y > /tmp/yes");
- newtScaleSet(scale, 10);
+ mysystem("/sbin/modprobe md-mod");
+ mysystem("/sbin/modprobe raid1");
+ system("echo y > /tmp/yes");
+
+ for (i = 0; i < IPCOP_PARTITIONS; i++) {
+ FILE *pipe;
+ char string[STRING_SIZE];
+ char *ptr;
+ int percentage;
+
+ snprintf(command, STRING_SIZE,
+ "/sbin/mdadm --create /dev/md%d --homehost=ipcop --level=1
--raid-devices=2 %s%d %s%d < /tmp/yes",
+ i, device, partition_index[i]+1, device2, partition_index[i]+1);
+ if (mysystem(command)) {
+ newtPopWindow();
+ fprintf(flog, "Make RAID failed ...\n");
+ return FAILURE;
+ }
+
+ newtScaleSet(scale, (i * 100) / IPCOP_PARTITIONS);
newtRefresh();
+ sleep(1);
- for (i = 0; i < IPCOP_PARTITIONS; i++) {
- snprintf(command, STRING_SIZE, "/sbin/mdadm --zero-superblock
%s%d", device, partition_index[i]+1);
- mysystem(command);
- snprintf(command, STRING_SIZE,
- "/sbin/mdadm --create /dev/md%d --homehost=ipcop --level=1
--raid-devices=2 missing %s%d < /tmp/yes",
- i, device, partition_index[i]+1);
- mysystem(command);
- newtScaleSet(scale, 10 + (((i+1) * 90) / IPCOP_PARTITIONS));
- newtRefresh();
- sleep(1);
+ while(system("cat /proc/mdstat | grep resync > /dev/null") == 0) {
+ if ((pipe = popen("cat /proc/mdstat | grep resync", "r")) != NULL)
{
+ if(fgets(string, STRING_SIZE, pipe) == NULL) {
+ pclose(pipe);
+ continue;
+ }
+
+ /* Something like this:
+ * [====>.....] resync = 35.5% (x/y) etc... */
+
+ ptr = strstr(string, "resync = ");
+ if (ptr == NULL) {
+ pclose(pipe);
+ continue;
+ }
+
+ ptr += strlen("resync = ");
+ percentage = atoi(ptr);
+ newtScaleSet(scale, percentage/IPCOP_PARTITIONS +
(i*100)/IPCOP_PARTITIONS);
+ newtRefresh();
+
+ pclose(pipe);
+ sleep(1);
+ }
}
}
+ fprintf(flog, "Make RAID done ...\n");
newtPopWindow();
- return retcode;
+ return SUCCESS;
} /* End of int autopart() */
@@ -343,10 +384,12 @@
const char *uuid;
#endif
- snprintf(devname, STRING_SIZE, "/dev/%s%d", dev, pindex+1);
if (raid) {
snprintf(devname, STRING_SIZE, "/dev/md%d", i);
}
+ else {
+ snprintf(devname, STRING_SIZE, "/dev/%s%d", dev, pindex+1);
+ }
partition_uuidenc[pindex][0] = 0;
snprintf(command, STRING_SIZE, "/usr/bin/mke2fs -L %s -q -j %s",
partition_label[pindex], devname);
if (mysystem(command)) {
@@ -488,51 +531,36 @@
statuswindow(72, 5, ipcop_gettext("TR_TITLE_DISK"),
ipcop_gettext("TR_MAKING_SWAPSPACE"));
snprintf(command, STRING_SIZE, "/bin/dd if=/dev/zero
of=/harddisk/swapfile bs=1024k count=%ld", swap_file);
if (mysystem(command)) {
+ newtPopWindow();
errorbox(ipcop_gettext("TR_UNABLE_TO_MAKE_SWAPSPACE"));
return FAILURE;
}
- if (mysystem("/bin/mkswap /harddisk/swapfile")) {
- newtPopWindow();
+ retcode = mysystem("/bin/mkswap /harddisk/swapfile");
+ newtPopWindow();
+ if (retcode) {
errorbox(ipcop_gettext("TR_UNABLE_TO_MAKE_SWAPSPACE"));
return FAILURE;
}
- newtPopWindow();
-
/* TODO: do we really need to activate swap ? */
statuswindow(72, 5, ipcop_gettext("TR_TITLE_DISK"),
ipcop_gettext("TR_MOUNTING_SWAP_PARTITION"));
- if (mysystem("/bin/swapon /harddisk/swapfile")) {
- newtPopWindow();
+ retcode = mysystem("/bin/swapon /harddisk/swapfile");
+ newtPopWindow();
+ if (retcode) {
errorbox(ipcop_gettext("TR_UNABLE_TO_MOUNT_SWAP_PARTITION"));
return FAILURE;
}
-
- newtPopWindow();
}
/* Now is a good time to move temp. fstab to final location */
mysystem("mv /tmp/tmpfstab /harddisk/etc/fstab");
if (raid) {
- statuswindow(72, 5, ipcop_gettext("TR_TITLE_DISK"),
ipcop_gettext("TR_WAITING_RAID"));
-
- for (i = 0; i < IPCOP_PARTITIONS; i++) {
- snprintf(command, STRING_SIZE, "/sbin/mdadm /dev/md%d --add
/dev/%s%d", i, dev2, partition_index[i]+1);
- mysystem(command);
- }
-
- /* TODO: make a better test with progress indicator here */
- while(system("cat /proc/mdstat | grep recovery > /dev/null") == 0) {
- sleep(2);
- }
-
/* Create mdadm.conf, also for inclusion in initramfs */
mysystem("mkdir -p /harddisk/etc/mdadm");
system("echo DEVICE partitions > /harddisk/etc/mdadm/mdadm.conf");
system("/sbin/mdadm --examine --scan >>
/harddisk/etc/mdadm/mdadm.conf");
-
- newtPopWindow();
}
return SUCCESS;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Ipcop-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ipcop-svn