Commit 35b362ea authored by Mike Hibler's avatar Mike Hibler

Make more robust to failure, add option to removed ophaned blockstores.

parent 655e8181
......@@ -847,7 +847,7 @@ sub volumeDestroy($$$$) {
# Volume must not have snapshots
if (exists($vref->{'snapshots'})) {
warn("*** ERROR: $tag: ".
"Volume '$volname' has clones, cannot destroy");
"Volume '$volname' has clones and/or snapshots, cannot destroy");
return -1;
}
......
#!/usr/bin/perl -w
#
# Copyright (c) 2013-2015 University of Utah and the Flux Group.
# Copyright (c) 2013-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -82,7 +82,7 @@ sub usage()
print STDERR " info For each server, show all extant volumes\n";
exit(-1);
}
my $optlist = "hds:t:l:S:P:Ff:";
my $optlist = "hds:t:l:S:P:Ff:I";
my $debug = 0;
my $server;
my $pool;
......@@ -91,6 +91,7 @@ my $type = "stdataset";
my $leaseidx = 0;
my $fstype = "";
my $fakeit = 0;
my $ignoredb = 0;
# Protos
sub fatal($);
......@@ -194,6 +195,9 @@ if (defined($options{f})) {
if (defined($options{F})) {
$fakeit = 1;
}
if (defined($options{I})) {
$ignoredb = 1;
}
if (@ARGV < 1) {
usage();
}
......@@ -504,6 +508,9 @@ sub getpools($$)
if (bsserver_cmd($srv, "$PROXYCMD pools", \$outref) == 0) {
foreach my $pstr (@$outref) {
my $attrs = parseattrs($pstr);
# XXX ignore bogus lines that don't include pool=...
next
if (!exists($attrs->{'pool'}));
my $pool = $attrs->{'pool'};
if (!defined($dpool) || $dpool eq $pool) {
$attrs->{'server'} = $srv;
......@@ -535,6 +542,9 @@ sub getvolumes($$)
if (bsserver_cmd($srv, "$PROXYCMD volumes", \$outref) == 0) {
foreach my $vstr (@$outref) {
my $attrs = parseattrs($vstr);
# XXX ignore bogus lines that don't include volume=...
next
if (!exists($attrs->{'volume'}));
my $pool = $attrs->{'pool'};
if (!defined($dpool) || $dpool eq $pool) {
$attrs->{'server'} = $srv;
......@@ -566,6 +576,9 @@ sub getblockstores($$)
if (bsserver_cmd($srv, "$PROXYCMD volumes", \$outref) == 0) {
foreach my $vstr (@$outref) {
my $attrs = get_bsattrs(parseattrs($vstr));
# XXX ignore bogus lines that don't include volume=...
next
if (!exists($attrs->{'volume'}));
if (!defined($dpool) || $dpool eq $attrs->{'pool'}) {
$attrs->{'server'} = $srv;
......@@ -953,13 +966,13 @@ sub bs_destroy($$$@)
# Delete the blockstore object
#
my $bstore = Blockstore->Lookup($srv, $name);
if (!$bstore) {
if (!$bstore && !$ignoredb) {
fatal("destroy: no blockstore '$srv/$name' in DB");
}
if ($bstore->role() ne "partition") {
if ($bstore && $bstore->role() ne "partition") {
fatal("destroy: wrong type of blockstore '$srv/$name'");
}
if ($bstore->Delete()) {
if ($bstore && $bstore->Delete()) {
fatal("destroy: could not delete blockstore '$srv/$name' from DB");
}
......@@ -975,10 +988,7 @@ sub bs_destroy($$$@)
bsserver_cmd($srv, "$PROXYCMD desnapshot $pool $name", \$outref)) {
print STDERR "*** destroy: ".
"could not destroy snapshots for '$name' on $srv/$pool:";
foreach my $str (@$outref) {
print STDERR " $str\n";
}
exit(-1);
goto fail;
}
#
......@@ -990,13 +1000,19 @@ sub bs_destroy($$$@)
if (bsserver_cmd($srv, "$PROXYCMD destroy $pool $name", \$outref)) {
print STDERR "*** destroy: ".
"could not deallocate storage for '$name' on $srv/$pool:";
foreach my $str (@$outref) {
print STDERR " $str\n";
}
exit(-1);
goto fail;
}
return 0;
fail:
foreach my $str (@$outref) {
print STDERR " $str\n";
}
print STDERR "*** blockstore has been removed from DB, ".
"to remove residual state do:\n".
" $0 -I -S srv -P $pool destroy $name\n";
exit(-1);
}
sub fatal($)
......
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