Commit c30b122e authored by Mike Hibler's avatar Mike Hibler

Change the semantics of "reset".

"reset" now just unmounts blockstores, it does not destroy them.
Need this so that people can include a SYSVOL blockstore in a custom image
(the only place where "reset" is used). Also, destroying blockstores would
have come as an unpleasant surprise to anyone who created a custom image
and then expected their data to still be around afterward!

Also work around a bizzare bug in BSD sed that happens in the prepare script.
That script does:

     sed -e '/# next line is swap device/,+1d' /etc/fstab

which should remove the matched comment and the line after it (the swapdev
entry). But if there are EXACTLY two additional lines after the matched line,
it would remove both of them (effectively "+2")! So if there was a mount for
a blockstore device after the swap device, prepare would remove that line too.

So in the finest tradition of "if it hurts, don't do it", the blockstore code
makes sure that it adds at least two additional lines.
parent f730b322
...@@ -102,7 +102,21 @@ SWITCH: for ($action) { ...@@ -102,7 +102,21 @@ SWITCH: for ($action) {
last SWITCH; last SWITCH;
}; };
/^reset$/i && do { /^reset$/i && do {
docleanup(1); #
# XXX this should be docleanup(3), but we have not implemented
# the nasty temporary removal of LVM/ZFS/etc state from the
# imageable filesystems.
#
# So for now we just do a shutdown. This is correct in the SYSVOL
# case where you want that blockstore to be included in the image.
# It is not correct for other blockstores, where you will get
# partial state in the image (e.g., in /etc/lvm or /etc/zfs).
#
# The moral is: if you are going to do a custom image, you should
# only create a SYSVOL blockstore and you should take a whole-disk
# image!
#
docleanup(0);
last SWITCH; last SWITCH;
}; };
# XXX non-standard, for debugging # XXX non-standard, for debugging
...@@ -259,15 +273,34 @@ sub doshutdown() ...@@ -259,15 +273,34 @@ sub doshutdown()
# #
# Node Reconfig Action (without rebooting). # Node Reconfig Action (without rebooting).
# XXX don't do anything til we figure out what would be correct.
# #
sub doreconfig() sub doreconfig()
{ {
# Tear down existing config
docleanup(1);
# Setup new config
doboot();
} }
# #
# Node cleanup action (node is reset to clean state, as if just allocated). # Node cleanup action (node is reset to clean state, as if just allocated).
# #
# $doteardown == 0 is for shutdown.
# This means just unmount local filesystems and cleanly detach
# from remote blockstores.
# $doteardown == 1 is for reconfig and full reset.
# This means destroying all existing blockstores, wiping out all
# on-disk data structures (MBR partitions, BSD partitions,
# LVM/ZFS metadata) as well.
# $doteardown == 2 is for cleaning up after any partial or failed setups.
# This means terminating with extreme prejudice. It destroys all
# existing blockstores but ignores any errors along the way.
# $doteardown == 3 is (rather, will be) for taking an image.
# This means also removing entries from /etc/fstab and removing
# other ZFS/LVM/gvinum state stored in the imagable filesystems.
# Not implemented yet.
#
sub docleanup($) sub docleanup($)
{ {
my ($doteardown) = @_; my ($doteardown) = @_;
...@@ -304,6 +337,7 @@ sub docleanup($) ...@@ -304,6 +337,7 @@ sub docleanup($)
# #
# Process each command in turn. Already sorted. # Process each command in turn. Already sorted.
# XXX do we need to reverse the order for teardown?
# #
my $so = os_init_storage($cmdref); my $so = os_init_storage($cmdref);
if (!$so) { if (!$so) {
......
...@@ -1077,6 +1077,7 @@ sub os_create_storage($$) ...@@ -1077,6 +1077,7 @@ sub os_create_storage($$)
warn("*** $lv: could not add mount to /etc/fstab\n"); warn("*** $lv: could not add mount to /etc/fstab\n");
return 0; return 0;
} }
print FD "# $mdev added by $BINDIR/rc/rc.storage\n";
print FD "$mdev\t$mpoint\tufs\trw\t2\t2\n"; print FD "$mdev\t$mpoint\tufs\trw\t2\t2\n";
close(FD); close(FD);
if (mysystem("$MOUNT $mpoint $redir")) { if (mysystem("$MOUNT $mpoint $redir")) {
...@@ -1684,7 +1685,7 @@ sub os_remove_storage_slice($$$) ...@@ -1684,7 +1685,7 @@ sub os_remove_storage_slice($$$)
if ($teardown) { if ($teardown) {
my $tdev = "/dev/$dev"; my $tdev = "/dev/$dev";
$tdev =~ s/\//\\\//g; $tdev =~ s/\//\\\//g;
if (mysystem("sed -E -i -e '/^$tdev/d' /etc/fstab")) { if (mysystem("sed -E -i -e '/^(# )?$tdev/d' /etc/fstab")) {
warn("*** $lv: could not remove mount from /etc/fstab\n"); warn("*** $lv: could not remove mount from /etc/fstab\n");
} }
} }
......
...@@ -775,6 +775,7 @@ sub os_create_storage($$) ...@@ -775,6 +775,7 @@ sub os_create_storage($$)
warn("*** $lv: could not add mount to /etc/fstab\n"); warn("*** $lv: could not add mount to /etc/fstab\n");
return 0; return 0;
} }
print FD "# $mdev added by $BINDIR/rc/rc.storage\n";
print FD "$mdev\t$mpoint\t$fstype\tdefaults\t0\t0\n"; print FD "$mdev\t$mpoint\t$fstype\tdefaults\t0\t0\n";
close(FD); close(FD);
if (mysystem("$MOUNT $mpoint $redir")) { if (mysystem("$MOUNT $mpoint $redir")) {
...@@ -1107,7 +1108,7 @@ sub os_remove_storage_slice($$$) ...@@ -1107,7 +1108,7 @@ sub os_remove_storage_slice($$$)
if ($teardown) { if ($teardown) {
my $tdev = "/dev/$dev"; my $tdev = "/dev/$dev";
$tdev =~ s/\//\\\//g; $tdev =~ s/\//\\\//g;
if (mysystem("sed -E -i -e '/^$tdev/d' /etc/fstab")) { if (mysystem("sed -E -i -e '/^(# )?$tdev/d' /etc/fstab")) {
warn("*** $lv: could not remove mount from /etc/fstab\n"); warn("*** $lv: could not remove mount from /etc/fstab\n");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment