[pve-devel] [RFC ha-manager v2 2/7] Env: add 'read_fence_config' and 'fencing_mode'

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Mar 11 16:57:11 CET 2016


read_fence_config allows to create a common code base between the
real world and the test/sim world regarding fencing a bit easier.

The fencing_mode method checks respective to the callee's
environment if hardware fencing is enabled and returns the wanted
mode if:

* PVE2: the datacenter cfg key must be set and not be equal to
        'watchdog' and at least one device must be configured.

* Sim: at least one device must be configured.

For the simulator we should make also a option to turn HW fencing
off and on independent if devices are configured when we implement
HW fencing for it, but that is not really needs for now.
---
 src/PVE/HA/Env.pm          | 12 ++++++++++++
 src/PVE/HA/Env/PVE2.pm     | 24 ++++++++++++++++++++++++
 src/PVE/HA/Sim/Env.pm      | 16 ++++++++++++++++
 src/PVE/HA/Sim/Hardware.pm | 18 +++++++++++++++++-
 4 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index f6be7b2..83774a6 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -87,6 +87,18 @@ sub read_service_config {
     return $self->{plug}->read_service_config();
 }
 
+sub read_fence_config {
+    my ($self) = @_;
+
+    return $self->{plug}->read_fence_config();
+}
+
+sub fencing_mode {
+    my ($self) = @_;
+
+    return $self->{plug}->fencing_mode();
+}
+
 # this is normally only allowed by the master to recover a _fenced_ service
 sub steal_service {
     my ($self, $sid, $current_node, $new_node) = @_;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 8638786..220f77c 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -144,6 +144,30 @@ sub read_service_config {
     return $conf;
 }
 
+sub read_fence_config {
+    my ($self) = @_;
+
+    return PVE::HA::Config::read_fence_config();
+}
+
+sub fencing_mode {
+    my ($self) = @_;
+
+    my $datacenterconfig = cfs_read_file('datacenter.cfg');
+    return 'watchdog' if !$datacenterconfig->{fencing} ||
+	$datacenterconfig->{fencing} eq 'watchdog';
+
+    my $cfg = $self->read_fence_config();
+
+    if (!%$cfg) {
+	$self->log('warn', "HW fencing enabled but no device configured!");
+	return 'watchdog';
+    }
+
+    return $datacenterconfig->{fencing};
+}
+
+
 # this is only allowed by the master to recover a _fenced_ service
 sub steal_service {
     my ($self, $sid, $current_node, $new_node) = @_;
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index 5ce174a..2c4b0bc 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -167,6 +167,22 @@ sub read_service_config {
     return $self->{hardware}->read_service_config();
 }
 
+sub read_fence_config {
+    my ($self) = @_;
+
+    return $self->{hardware}->read_fence_config();
+}
+
+# the test/sim framework has hardware enabled fencing if
+# it has devices configured
+sub fencing_mode {
+    my ($self) = @_;
+
+    my $cfg = $self->read_fence_config();
+
+    return (defined($cfg) && %$cfg) ? 'hardware' : 'watchdog';
+}
+
 sub read_group_config {
     my ($self) = @_;
 
diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 652f11d..8bb3fe3 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -114,7 +114,20 @@ sub write_service_config {
 
     my $filename = "$self->{statusdir}/service_config";
     return PVE::HA::Tools::write_json_to_file($filename, $conf);
-} 
+}
+
+sub read_fence_config {
+    my ($self) = @_;
+
+    my $raw = undef;
+
+    my $filename = "$self->{statusdir}/fence.cfg";
+    if (-e $filename) {
+	$raw = PVE::Tools::file_get_contents($filename);
+    }
+
+    return PVE::HA::FenceConfig::parse_config($filename, $raw);
+}
 
 sub set_service_state {
     my ($self, $sid, $state) = @_;
@@ -306,6 +319,9 @@ sub new {
 	$self->write_hardware_status_nolock($cstatus);
     }
 
+    if (-f "$testdir/fence.cfg") {
+	copy("$testdir/fence.cfg", "$statusdir/fence.cfg");
+    }
 
     my $cstatus = $self->read_hardware_status_nolock();
 
-- 
2.1.4





More information about the pve-devel mailing list