[pve-devel] [PATCH 3/7] ceph/rbd: has a pretty strange error handling - install custom run_command function
Stefan Priebe
s.priebe at profihost.ag
Thu Feb 6 14:04:53 CET 2014
Always use a custom error sub to get the real errors out of rbd command instead of the typical:
2014-02-06 11:20:20.187190 7f3b6c37c760 -1 librbd: removing snapshot from header failed: (16) Device or resource busy
before:
rbd: snapshot 'abc' is protected from removal.
TASK ERROR: rbd snapshot vm-173-disk-1' error: 2014-02-06 11:06:02.438336 7f6f4ac92760 -1 librbd: removing snapshot from header failed: (16) Device or resource busy
now:
TASK ERROR: rbd: snapshot 'abc' is protected from removal.
Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
---
PVE/Storage/RBDPlugin.pm | 61 ++++++++++++++++++++++++++++++++++------------
1 file changed, 46 insertions(+), 15 deletions(-)
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 7e67fd8..0e94e13 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -79,6 +79,35 @@ my $rados_cmd = sub {
return $cmd;
};
+sub run_rbd_command {
+ my ($cmd, %args) = @_;
+
+ my $err = "";
+ my $errmsg = $args{errmsg} . ": " || "";
+ if (!exists $args{errfunc}) {
+ # ' error: 2014-02-06 11:51:59.839135 7f09f94d0760 -1 librbd: snap_unprotect: can't unprotect;
+ # at least 1 child(ren) in pool cephstor1
+ $args{errfunc} = sub {
+ my $line = shift;
+ if ($line =~ m/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [0-9a-f]+ [\-\d]+ librbd: (.*)$/) {
+ $err .= $1 . "\n";
+ } else {
+ $err .= $line;
+ }
+ };
+ }
+
+ my $r;
+ eval {
+ $r = run_command($cmd, %args);
+ };
+
+ die $errmsg . $err if $@ && length $err;
+ die $@ if $@;
+
+ return $r;
+}
+
sub rbd_ls {
my ($scfg, $storeid) = @_;
@@ -103,7 +132,7 @@ sub rbd_ls {
};
eval {
- run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
+ run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
};
my $err = $@;
@@ -143,7 +172,7 @@ sub rbd_volume_info {
};
- run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
+ run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
return ($size, $parent, $format, $protected);
}
@@ -293,7 +322,7 @@ sub create_base {
my $newvolname = $basename ? "$basename/$newname" : "$newname";
my $cmd = &$rbd_cmd($scfg, $storeid, 'rename', &$add_pool_to_disk($scfg, $name), &$add_pool_to_disk($scfg, $newname));
- run_command($cmd, errmsg => "rbd rename '$name' error");
+ run_rbd_command($cmd, errmsg => "rbd rename '$name' error");
my $running = undef; #fixme : is create_base always offline ?
@@ -303,7 +332,7 @@ sub create_base {
if (!$protected){
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $newname, '--snap', $snap);
- run_command($cmd, errmsg => "rbd protect $newname snap $snap' error");
+ run_rbd_command($cmd, errmsg => "rbd protect $newname snap $snap' error");
}
return $newvolname;
@@ -330,7 +359,7 @@ sub clone_image {
if (!$protected){
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
- run_command($cmd, errmsg => "rbd protect $volname snap $snapname error");
+ run_rbd_command($cmd, errmsg => "rbd protect $volname snap $snapname error");
}
}
@@ -338,7 +367,7 @@ sub clone_image {
$newvol = $name if length $snapname;
my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name));
- run_command($cmd, errmsg => "rbd clone $basename' error");
+ run_rbd_command($cmd, errmsg => "rbd clone $basename' error");
return $newvol;
}
@@ -353,7 +382,7 @@ sub alloc_image {
$name = &$find_free_diskname($storeid, $scfg, $vmid);
my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--image-format' , 2, '--size', int(($size+1023)/1024), $name);
- run_command($cmd, errmsg => "rbd create $name' error");
+ run_rbd_command($cmd, errmsg => "rbd create $name' error");
return $name;
}
@@ -369,15 +398,15 @@ sub free_image {
my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $name, $snap);
if ($protected){
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
- run_command($cmd, errmsg => "rbd unprotect $name snap $snap' error");
+ run_rbd_command($cmd, errmsg => "rbd unprotect $name snap $snap' error");
}
}
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'purge', $name);
- run_command($cmd, errmsg => "rbd snap purge $volname' error");
+ run_rbd_command($cmd, errmsg => "rbd snap purge '$volname' error");
$cmd = &$rbd_cmd($scfg, $storeid, 'rm', $name);
- run_command($cmd, errmsg => "rbd rm $volname' error");
+ run_rbd_command($cmd, errmsg => "rbd rm '$volname' error");
return undef;
}
@@ -431,7 +460,7 @@ sub status {
};
eval {
- run_command($cmd, errmsg => "rados error", errfunc => sub {}, outfunc => $parser);
+ run_rbd_command($cmd, errmsg => "rados error", errfunc => sub {}, outfunc => $parser);
};
my $total = $stats->{space} ? $stats->{space}*1024 : 0;
@@ -478,7 +507,7 @@ sub volume_resize {
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
my $cmd = &$rbd_cmd($scfg, $storeid, 'resize', '--size', ($size/1024/1024), $name);
- run_command($cmd, errmsg => "rbd resize $volname' error");
+ run_rbd_command($cmd, errmsg => "rbd resize '$volname' error");
return undef;
}
@@ -490,7 +519,7 @@ sub volume_snapshot {
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'create', '--snap', $snap, $name);
- run_command($cmd, errmsg => "rbd snapshot $volname' error");
+ run_rbd_command($cmd, errmsg => "rbd snapshot '$volname' error");
return undef;
}
@@ -500,7 +529,7 @@ sub volume_snapshot_rollback {
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'rollback', '--snap', $snap, $name);
- run_command($cmd, errmsg => "rbd snapshot $volname to $snap' error");
+ run_rbd_command($cmd, errmsg => "rbd snapshot $volname to $snap' error");
}
sub volume_snapshot_delete {
@@ -511,7 +540,9 @@ sub volume_snapshot_delete {
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'rm', '--snap', $snap, $name);
- run_command($cmd, errmsg => "rbd snapshot $volname' error");
+
+ run_rbd_command($cmd, errmsg => "rbd snapshot '$volname' error");
+
return undef;
}
--
1.7.10.4
More information about the pve-devel
mailing list