[pve-devel] [PATCH ha-manager] wrap possible problematic cfs_read_file calls in eval

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Nov 8 14:41:40 CET 2017


Wrap those calls to the cfs_read_file method, which may now also die
if there was a grave problem reading the file, into eval in all
methods which are used by the ha services.

The ones only used by API calls or CLI helpers are not wrapped, as
there it can be handled more gracefull (i.e., no watchdog is
running) and further, this is more intended to temporarily workaround
until we handle such an exception explicitly in the services - which
is a bit bigger change, so let's just go back to the old behavior for
now.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

This replaces the "catch problems when updating cluster FS" series
for now.

 src/PVE/HA/Config.pm  | 13 +++++++------
 src/PVE/HA/Manager.pm |  3 ++-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index bf37b04..e7e8b88 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -81,13 +81,13 @@ sub parse_resources_config {
 
 sub read_resources_config {
 
-    return cfs_read_file($ha_resources_config);
+    return eval { cfs_read_file($ha_resources_config) };
 }
 
 # checks if resource exists and sets defaults for unset values
 sub read_and_check_resources_config {
 
-    my $res = cfs_read_file($ha_resources_config);
+    my $res = eval { cfs_read_file($ha_resources_config) };
 
     my $vmlist = PVE::Cluster::get_vmlist();
     my $conf = {};
@@ -122,7 +122,7 @@ sub read_and_check_resources_config {
 
 sub read_group_config {
 
-    return cfs_read_file($ha_groups_config);
+    return eval { cfs_read_file($ha_groups_config) };
 }
 
 sub write_group_config {
@@ -140,7 +140,7 @@ sub write_resources_config {
 sub read_manager_status {
     my () = @_;
 
-    return cfs_read_file($manager_status_filename);
+    return eval { cfs_read_file($manager_status_filename) };
 }
 
 sub write_manager_status {
@@ -152,7 +152,7 @@ sub write_manager_status {
 sub read_fence_config {
     my () = @_;
 
-    cfs_read_file($ha_fence_config);
+    return eval { cfs_read_file($ha_fence_config) };
 }
 
 sub write_fence_config {
@@ -189,7 +189,8 @@ sub queue_crm_commands {
 sub read_crm_commands {
 
     my $code = sub {
-	my $data = cfs_read_file($crm_commands_filename);
+	my $data = eval { cfs_read_file($crm_commands_filename) };
+	return undef if !$data;
 	cfs_write_file($crm_commands_filename, '');
 	return $data;
     };
diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index 25a7398..2933926 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -328,7 +328,8 @@ sub update_crm_commands {
     my ($haenv, $ms, $ns, $ss) = ($self->{haenv}, $self->{ms}, $self->{ns}, $self->{ss});
 
     my $cmdlist = $haenv->read_crm_commands();
-    
+    return if !defined($cmdlist);
+
     foreach my $cmd (split(/\n/, $cmdlist)) {
 	chomp $cmd;
 
-- 
2.11.0





More information about the pve-devel mailing list