Commit 21cbba97 authored by David Johnson's avatar David Johnson

Fixup kill and do some better checking of vnode state...

parent 5a76cdee
......@@ -12,7 +12,7 @@ use Exporter;
@EXPORT = qw( vz_init vz_setDebug
vz_rootPreConfig vz_rootPreConfigNetwork vz_rootPostConfig
vz_vnodeCreate vz_vnodeDestroy vz_vnodeState
vz_vnodeBoot vz_vnodeHalt vz_vnodeReboot vz_vnodeKill
vz_vnodeBoot vz_vnodeHalt vz_vnodeReboot
vz_vnodePreConfig
vz_vnodePreConfigControlNetwork vz_vnodePreConfigExpNetwork
vz_vnodeConfigResources vz_vnodeConfigDevices
......@@ -30,7 +30,6 @@ use Exporter;
'vnodeBoot' => \&vz_vnodeBoot,
'vnodeHalt' => \&vz_vnodeHalt,
'vnodeReboot' => \&vz_vnodeReboot,
'vnodeKill' => \&vz_vnodeKill,
'vnodePreConfig' => \&vz_vnodePreConfig,
'vnodePreConfigControlNetwork' => \&vz_vnodePreConfigControlNetwork,
'vnodePreConfigExpNetwork' => \&vz_vnodePreConfigExpNetwork,
......@@ -424,11 +423,6 @@ sub vz_vnodeReboot {
return 0;
}
# XXX ps axwww | grep -v ' init ' | sed -n -r -e 's/^\s*([0-9]+).*$/\1/p' | xargs
sub vz_vnodeKill {
return vz_vnodeHalt(@_);
}
sub vz_vnodePreConfig {
my ($vnode_id,$vmid) = @_;
......
......@@ -25,7 +25,7 @@ sub usage()
" -c Reconfigure listed vnodes (or all vnodes if unspecified).\n" .
"Actions:\n" .
" -r Reboot listed vnodes (or all vnodes if unspecified).\n" .
" -k Kill listed vnodes (or all vnodes if unspecified).\n" .
" -k Destroy listed vnodes (or all vnodes if unspecified).\n" .
" -h Halt listed vnodes (or all vnodes if unspecified).\n" .
" -b Boot listed vnodes (or all vnodes if unspecified).\n" .
"";
......@@ -200,10 +200,19 @@ if ($debug) {
# Make sure we have nodes that we've already created if they were supplied on
# the command line. Yes, this restriction is somewhat arbitrary.
#
foreach my $vnode (@vnodes) {
if (!exists($vndb{$vnode})) {
fatal("Unknown vnode $vnode!\n");
for (my $i = 0; $i < @vnodes; ++$i) {
if (!exists($vndb{$vnodes[$i]})) {
fatal("Unknown vnode $vnodes[$i]!\n");
}
if ($vnodes[$i] =~ /^([-\w\d]+)/) {
$vnodes[$i] = $1;
}
else {
fatal("Malformed vnode named '$vnodes[$i]' specified on command line!");
}
# tag that this vnode was specifed on command line
$vndb{$vnodes[$i]}{'__CMDLINE'} = 1;
}
my @tmccvnodes = ();
......@@ -300,23 +309,29 @@ if ($BOSSIP !~ /^\d+\.\d+\.\d+\.\d+$/) {
# Ok, handle various actions!
#
my @errors = ();
if ($action eq 'reboot' || $action eq 'halt' || $action eq 'kill') {
if ($action eq 'reboot' || $action eq 'halt') {
my $op;
if ($action eq 'reboot') {
$op = 'vnodeReboot';
}
if ($action eq 'halt') {
elsif ($action eq 'halt') {
$op = 'vnodeHalt';
}
if ($action eq 'kill') {
$op = 'vnodeKill';
}
if (@vnodes == 0) {
@vnodes = keys(%vndb);
}
foreach my $vnode (@vnodes) {
if (!exists($vndb{$vnode}) || !exists($vndb{$vnode}{'type'})) {
# this is a node that is not fully configured according to the db.
# we only make noise if it is one of the ones the user asked for.
if (exists($vndb{$vnode}{'__CMDLINE'})) {
print STDERR "*** ERROR: $vnode has not yet been created!\n";
}
next;
}
safeLibOp($vnode,$op,1,1,$vnode,$vndb{$vnode}{'id'});
}
......@@ -327,6 +342,53 @@ if ($action eq 'reboot' || $action eq 'halt' || $action eq 'kill') {
teardownOldVnodes();
}
}
elsif ($action eq 'kill') {
if (@vnodes == 0) {
@vnodes = keys(%vndb);
}
foreach my $vnode (@vnodes) {
if (!exists($vndb{$vnode}) || !exists($vndb{$vnode}{'type'})) {
# this is a node that is not fully configured according to the db.
# we only make noise if it is one of the ones the user asked for.
if (exists($vndb{$vnode}{'__CMDLINE'})) {
print STDERR "*** ERROR: $vnode has not yet been created!\n";
}
next;
}
# if not halted, try that first
my ($ret,$err);
($ret,$err) = safeLibOp($vnode,'vnodeState',1,0,
$vnode,$vndb{$vnode}{'id'});
if ($err) {
print STDERR "*** ERROR: failed to get state for $vnode: $err\n";
next;
}
if ($ret ne VNODE_STATUS_STOPPED()) {
warn("kill: vnode $vnode not stopped, trying halt before kill!");
($ret,$err) = safeLibOp($vnode,'vnodeHalt',1,0,
$vnode,$vndb{$vnode}{'id'});
if ($err) {
print STDERR "*** ERROR: failed to halt $vnode before kill: $err\n";
next;
}
}
# now destroy
($ret,$err) = safeLibOp($vnode,'vnodeDestroy',1,1,
$vnode,$vndb{$vnode}{'id'});
if ($err) {
print STDERR "*** ERROR: failed to kill $vnode: $err\n";
next;
}
# else we're good, so remove the node from the db
delete $vndb{$vnode};
# flush now, just in case!
putvmmap(\%vndb);
}
}
elsif ($action eq 'boot') {
my @newvnodes = ();
my @oldvnodes = ();
......
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